Skip to content

Commit 9c6bcbd

Browse files
authored
Merge pull request #1917 from ehuss/type_length_limit
Update `type_length_limit` to use the attribute template
2 parents ff45844 + ff65b3d commit 9c6bcbd

File tree

10 files changed

+153
-65
lines changed

10 files changed

+153
-65
lines changed

docs/attribute-template.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ When an attribute (or a new attribute position in the grammar) is added, be sure
66

77
----
88

9+
<!-- template:attributes -->
910
r[PARENT.example]
1011
## The `example` attribute
1112

@@ -14,7 +15,8 @@ The *`example` [attribute][attributes]* ...give a high level description.
1415

1516
> [!EXAMPLE]
1617
> ```rust
17-
> // This should be a very basic example showing the attribute used in some way.
18+
> // This should be a very basic example showing the attribute
19+
> // used in some way.
1820
> #[example]
1921
> fn some_meaningful_name() {}
2022
> ```
@@ -24,19 +26,70 @@ Describe the accepted syntax of this attribute. You can either explain that it u
2426
2527
----
2628
27-
The `example` attribute uses the [MetaWord] syntax and thus does not take any inputs.
29+
The `example` attribute uses the [MetaWord] syntax.
2830
2931
----
3032
3133
The `example` attribute uses the [MetaListPaths] syntax to specify a list of ...
3234
3335
----
3436
37+
The `example` attribute uses the [MetaWord] and [MetaNameValueStr] syntaxes.
38+
39+
----
40+
41+
The `example` attribute uses the [MetaWord], [MetaListPaths], and [MetaNameValueStr] syntaxes.
42+
43+
----
44+
45+
The `example` attribute uses the [MetaNameValueStr] syntax. Accepted values are `"X"` and `"Y"`.
46+
47+
----
48+
49+
The `example` attribute uses the [MetaNameValueStr] syntax. The value in the string must be ...
50+
51+
----
52+
53+
The `example` attribute has these forms:
54+
55+
- [MetaWord]
56+
> [!EXAMPLE]
57+
> ```rust
58+
> #[example]
59+
> fn f() {}
60+
> ```
61+
62+
- [MetaNameValueStr] --- The given string must ...
63+
> [!EXAMPLE]
64+
> ```rust
65+
> #[example = "example"]
66+
> fn f() {}
67+
> ```
68+
69+
- [MetaListNameValueStr] --- As with the [MetaNameValueStr] syntax, the given string must ...
70+
> [!EXAMPLE]
71+
> ```rust
72+
> #[example(inner = "example")]
73+
> fn f() {}
74+
> ```
75+
76+
----
77+
3578
The syntax for the `example` attribute is:
3679
3780
```grammar,attributes
3881
@root ExampleAttribute -> `example` `(` ... `)`
3982
```
83+
----
84+
85+
r[PARENT.example.syntax.foo]
86+
The [MetaNameValueStr] form of the `example` attribute provides a way to specify the foo.
87+
88+
> [!EXAMPLE]
89+
> ```rust
90+
> #[example = "example"]
91+
> fn some_meaningful_name() {}
92+
> ```
4093
4194
r[PARENT.example.allowed-positions]
4295
Explain the valid positions where this attribute may be used.
@@ -60,10 +113,7 @@ The `example` attribute is allowed anywhere attributes are allowed.
60113
If there are unused attribute warnings, or if rustc is incorrectly accepting some positions, include a note about these.
61114
62115
> [!NOTE]
63-
> `rustc` currently warns in other positions, but this may be rejected in the future.
64-
65-
> [!NOTE]
66-
> `rustc` currently warns on some positions where it is ignored, but this may become an error in the future.
116+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
67117
68118
----
69119
@@ -72,29 +122,40 @@ Explain the behavior if the attribute is specified multiple times on an element.
72122
73123
----
74124
75-
Duplicate instances of the `example` attribute on the same ... have no effect.
125+
The `example` attribute may be used any number of times on a form.
76126
77127
----
78128
79-
The `example` attribute may only be specified once on a [THING].
129+
Using `example` more than once on a form has the same effect as using it once.
80130
81131
----
82132
83-
Only the first instance of `example` on an item is honored. Subsequent `example` attributes are ignored.
133+
The `example` attribute may be used only once on ...
134+
135+
----
136+
137+
Only the first use of `example` on an item has effect.
138+
139+
> [!NOTE]
140+
> `rustc` lints against any use following the first. This may become an error in the future.
84141
85142
> [!NOTE]
86-
> `rustc` currently warns on subsequent duplicate `example` attributes. This may become an error in the future.
143+
> `rustc` lints against any use following the first with a future-compatibility warning. This may become an error in the future.
87144
88145
----
89146
90-
Only the last instance of `example` on an item is honored. Previous `example` attributes are ignored.
147+
Only the last use of `example` on an item has effect.
91148
92149
> [!NOTE]
93-
> `rustc` currently warns on preceding duplicate `example` attributes. This may become an error in the future.
150+
> `rustc` lints against any use preceding the last. This may become an error in the future.
94151
95-
---
152+
----
153+
154+
Only the last use of `example` on an item is used to ...
155+
156+
----
96157
97-
If the `example` attribute is specified multiple times on an item, then the combination of all the specified values is used as ...explain how they are merged.
158+
If the `example` attribute is used more than once on an item, then the combination of all the specified values is used as ...explain how they are merged.
98159
99160
----
100161

src/attributes/codegen.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ The [`track_caller`](#the-track_caller-attribute) attribute cannot be applied to
8282
r[attributes.codegen.naked.testing]
8383
The [testing attributes](testing.md) cannot be applied to a naked function.
8484

85+
<!-- template:attributes -->
8586
r[attributes.codegen.no_builtins]
8687
## The `no_builtins` attribute
8788

@@ -105,7 +106,7 @@ r[attributes.codegen.no_builtins.duplicates]
105106
Only the first use of the `no_builtins` attribute has effect.
106107
107108
> [!NOTE]
108-
> `rustc` currently lints against uses following the first.
109+
> `rustc` lints against any use following the first.
109110
110111
r[attributes.codegen.target_feature]
111112
## The `target_feature` attribute

src/attributes/derive.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- template:attributes -->
12
r[attributes.derive]
23
# Derive
34

@@ -36,10 +37,10 @@ r[attributes.derive.syntax]
3637
The `derive` attribute uses the [MetaListPaths] syntax to specify a list of paths to [derive macros] to invoke.
3738
3839
r[attributes.derive.allowed-positions]
39-
The `derive` attribute may be applied to [structs][items.struct], [enums][items.enum], and [unions][items.union].
40+
The `derive` attribute may only be applied to [structs][items.struct], [enums][items.enum], and [unions][items.union].
4041
4142
r[attributes.derive.duplicates]
42-
The `derive` attribute may be specified multiple times on an item, with all derive macros listed in all attributes being invoked.
43+
The `derive` attribute may be used any number of times on an item. All derive macros listed in all attributes are invoked.
4344
4445
r[attributes.derive.stdlib]
4546
The `derive` attribute is exported in the standard library prelude as [`core::prelude::v1::derive`].
@@ -63,6 +64,7 @@ The built-in derives include the [`automatically_derived` attribute][attributes.
6364
r[attributes.derive.behavior]
6465
During macro expansion, for each element in the list of derives, the corresponding derive macro expands to zero or more [items].
6566
67+
<!-- template:attributes -->
6668
r[attributes.derive.automatically_derived]
6769
## The `automatically_derived` attribute
6870
@@ -84,19 +86,19 @@ The *`automatically_derived` [attribute][attributes]* is used to annotate an [im
8486
> ```
8587
8688
r[attributes.derive.automatically_derived.syntax]
87-
The `automatically_derived` attribute uses the [MetaWord] syntax and so does not accept any arguments.
89+
The `automatically_derived` attribute uses the [MetaWord] syntax.
8890
8991
r[attributes.derive.automatically_derived.allowed-positions]
90-
The `automatically_derived` attribute may be placed on an [implementation].
92+
The `automatically_derived` attribute may only be applied to an [implementation].
9193
9294
> [!NOTE]
93-
> `rustc` currently accepts the attribute in other positions but lints against it.
95+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
9496
9597
r[attributes.derive.automatically_derived.duplicates]
96-
Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect.
98+
Using `automatically_derived` more than once on an implementation has the same effect as using it once.
9799
98100
> [!NOTE]
99-
> `rustc` lints against duplicate use of this attribute on uses following the first.
101+
> `rustc` lints against any use following the first.
100102
101103
r[attributes.derive.automatically_derived.behavior]
102104
The `automatically_derived` attribute has no behavior.

src/attributes/limits.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,48 @@ a!{}
4040
(|_: &u8| {})(&&&1);
4141
```
4242

43+
<!-- template:attributes -->
4344
r[attributes.limits.type_length_limit]
4445
## The `type_length_limit` attribute
4546

47+
r[attributes.limits.type_length_limit.intro]
48+
The *`type_length_limit` [attribute][attributes]* sets the maximum number of type substitutions allowed when constructing a concrete type during monomorphization.
49+
4650
> [!NOTE]
47-
> This limit is only enforced when the nightly `-Zenforce-type-length-limit` flag is active.
51+
> `rustc` only enforces the limit when the nightly `-Zenforce-type-length-limit` flag is active.
4852
>
49-
> For more information, see <https://github.com/rust-lang/rust/pull/127670>.
53+
> For more information, see [Rust PR #127670](https://github.com/rust-lang/rust/pull/127670).
5054
51-
r[attributes.limits.type_length_limit.intro]
52-
The *`type_length_limit` attribute* limits the maximum number of type
53-
substitutions made when constructing a concrete type during monomorphization.
55+
> [!EXAMPLE]
56+
> <!-- ignore: not enforced without nightly flag -->
57+
> ```rust,ignore
58+
> #![type_length_limit = "4"]
59+
>
60+
> fn f<T>(x: T) {}
61+
>
62+
> // This fails to compile because monomorphizing to
63+
> // `f::<((((i32,), i32), i32), i32)>` requires more
64+
> // than 4 type elements.
65+
> f(((((1,), 2), 3), 4));
66+
> ```
67+
68+
> [!NOTE]
69+
> The default value in `rustc` is `1048576`.
5470
5571
r[attributes.limits.type_length_limit.syntax]
56-
It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax
57-
to set the limit based on the number of type substitutions.
72+
The `type_length_limit` attribute uses the [MetaNameValueStr] syntax. The value in the string must be a non-negative number.
5873
59-
> [!NOTE]
60-
> The default in `rustc` is 1048576.
74+
r[attributes.limits.type_length_limit.allowed-positions]
75+
The `type_length_limit` attribute may only be applied to the crate root.
6176
62-
```rust,ignore
63-
#![type_length_limit = "4"]
77+
> [!NOTE]
78+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
6479
65-
fn f<T>(x: T) {}
80+
r[attributes.limits.type_length_limit.duplicates]
81+
Only the first use of `type_length_limit` on an item has effect.
6682
67-
// This fails to compile because monomorphizing to
68-
// `f::<((((i32,), i32), i32), i32)>` requires more than 4 type elements.
69-
f(((((1,), 2), 3), 4));
70-
```
83+
> [!NOTE]
84+
> `rustc` lints against any use following the first. This may become an error in the future.
7185
7286
[attributes]: ../attributes.md
7387
[crate]: ../crates-and-source-files.md

src/attributes/testing.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tests. Compiling a crate in "test" mode enables building the test functions
66
along with a test harness for executing the tests. Enabling the test mode also
77
enables the [`test` conditional compilation option].
88

9+
<!-- template:attributes -->
910
r[attributes.testing.test]
1011
## The `test` attribute
1112

@@ -23,7 +24,7 @@ The *`test` [attribute][attributes]* marks a function to be executed as a test.
2324
> ```
2425
2526
r[attributes.testing.test.syntax]
26-
The `test` attribute uses the [MetaWord] syntax and thus does not take any inputs.
27+
The `test` attribute uses the [MetaWord] syntax.
2728
2829
r[attributes.testing.test.allowed-positions]
2930
The `test` attribute may only be applied to [free functions] that are monomorphic, that take no arguments, and where the return type implements the [`Termination`] trait.
@@ -34,10 +35,10 @@ The `test` attribute may only be applied to [free functions] that are monomorphi
3435
> * `Result<T, E> where T: Termination, E: Debug`
3536
3637
r[attributes.testing.test.duplicates]
37-
Only the first instance of `test` on a function is honored.
38+
Only the first use of `test` on a function has effect.
3839
3940
> [!NOTE]
40-
> Subsequent `test` attributes are currently ignored and `rustc` warns about these.
41+
> `rustc` lints against any use following the first. This may become an error in the future.
4142
4243
<!-- TODO: This is a minor lie. Currently rustc warns that duplicates are ignored, but it then generates multiple test entries with the same name. I would vote for rejecting this in the future. -->
4344
@@ -71,6 +72,7 @@ In particular:
7172
> }
7273
> ```
7374
75+
<!-- template:attributes -->
7476
r[attributes.testing.ignore]
7577
## The `ignore` attribute
7678
@@ -90,7 +92,7 @@ The *`ignore` [attribute][attributes]* can be used with the [`test` attribute][a
9092
> The `rustc` test harness supports the `--include-ignored` flag to force ignored tests to be run.
9193
9294
r[attributes.testing.ignore.syntax]
93-
The `ignore` attribute uses either the [MetaWord] or [MetaNameValueStr] syntax.
95+
The `ignore` attribute uses the [MetaWord] and [MetaNameValueStr] syntaxes.
9496
9597
r[attributes.testing.ignore.reason]
9698
The [MetaNameValueStr] form of the `ignore` attribute provides a way to specify a reason why the test is ignored.
@@ -105,20 +107,21 @@ The [MetaNameValueStr] form of the `ignore` attribute provides a way to specify
105107
> ```
106108
107109
r[attributes.testing.ignore.allowed-positions]
108-
The `ignore` attribute may be applied to functions annotated with the `test` attribute.
110+
The `ignore` attribute may only be applied to functions annotated with the `test` attribute.
109111
110112
> [!NOTE]
111-
> `rustc` currently warns when `ignore` is used in some other situations. This may become an error in the future.
113+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
112114
113115
r[attributes.testing.ignore.duplicates]
114-
Only the first instance of `ignore` on a function is honored.
116+
Only the first use of `ignore` on a function has effect.
115117
116118
> [!NOTE]
117-
> `rustc` currently ignores duplicate `ignore` attributes. This may become an error in the future.
119+
> `rustc` lints against any use following the first. This may become an error in the future.
118120
119121
r[attributes.testing.ignore.behavior]
120122
Ignored tests are still compiled when in test mode, but they are not executed.
121123
124+
<!-- template:attributes -->
122125
r[attributes.testing.should_panic]
123126
## The `should_panic` attribute
124127
@@ -135,7 +138,7 @@ The *`should_panic` [attribute][attributes]* causes a test to pass only if the [
135138
> ```
136139
137140
r[attributes.testing.should_panic.syntax]
138-
The `should_panic` attribute has one of the following forms:
141+
The `should_panic` attribute has these forms:
139142
140143
- [MetaWord]
141144
> [!EXAMPLE]
@@ -165,13 +168,13 @@ r[attributes.testing.should_panic.allowed-positions]
165168
The `should_panic` attribute may only be applied to functions annotated with the `test` attribute.
166169
167170
> [!NOTE]
168-
> `rustc` currently accepts this attribute in other positions with a warning. This may become a hard error in the future.
171+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
169172
170173
r[attributes.testing.should_panic.duplicates]
171-
Only the first instance of `should_panic` on a function is honored.
174+
Only the first use of `should_panic` on a function has effect.
172175
173176
> [!NOTE]
174-
> `rustc` currently ignores subsequent `should_panic` attributes and emits a future-compatibility warning. This may become a hard error in the future.
177+
> `rustc` lints against any use following the first with a future-compatibility warning. This may become an error in the future.
175178
176179
r[attributes.testing.should_panic.expected]
177180
When the [MetaNameValueStr] form or the [MetaListNameValueStr] form with the `expected` key is used, the given string must appear somewhere within the panic message for the test to pass.

0 commit comments

Comments
 (0)