@@ -14,9 +14,10 @@ to which the attribute applies.
14
14
For any lint check ` C ` :
15
15
16
16
* ` #[allow(C)] ` overrides the check for ` C ` so that violations will go
17
- unreported,
18
- * ` #[expect(C)] ` suppresses all lint emissions of ` C ` , but will issue
19
- a warning if the lint wasn't emitted in the expected scope.
17
+ unreported.
18
+ * ` #[expect(C)] ` indicates that lint ` C ` is expected to be emitted. The
19
+ attribute will suppres the emission of ` C ` or issue a warning, if the
20
+ expectation is unfillfilled.
20
21
* ` #[warn(C)] ` warns about violations of ` C ` but continues compilation.
21
22
* ` #[deny(C)] ` signals an error after encountering a violation of ` C ` ,
22
23
* ` #[forbid(C)] ` is the same as ` deny(C) ` , but also forbids changing the lint
@@ -104,14 +105,13 @@ message if the lint is emitted at the defined level.
104
105
fn dyn() {}
105
106
```
106
107
107
- Here we have another example, where the lint is allowed with a reason:
108
+ Here is another example, where the lint is allowed with a reason:
108
109
109
110
``` rust
110
111
use std :: path :: PathBuf ;
111
112
112
113
pub fn get_path () -> PathBuf {
113
- // Using `reason` with an `allow` attribute has no effect other than to
114
- // provide documentation to the reader.
114
+ // The `reason` parameter on `allow` attributes acts as documentation for the reader.
115
115
#[allow(unused_mut, reason = " this is only modified on some platforms" )]
116
116
let mut file_name = PathBuf :: from (" git" );
117
117
@@ -122,35 +122,37 @@ pub fn get_path() -> PathBuf {
122
122
}
123
123
```
124
124
125
- ### The ` expect ` attribute
125
+ ### The ` #[ expect] ` attribute
126
126
127
- The * ` expect ` attribute* is used to mark that a particular lint must be triggered
128
- within its scope. If this expectation is not fulfilled a new warning is emitted to
129
- the user.
127
+ The ` #[expect(C)] ` attribute creates a lint expectation for lint ` C ` . The
128
+ expectation will be fulfilled, if a ` #[warn(C)] ` attribute at the same location
129
+ would result in a lint emission. If the expectation is unfulfilled, because
130
+ lint ` C ` would not be emitted, the ` unfulfilled_lint_expectations ` lint will
131
+ be emitted at the attribute.
130
132
131
133
``` rust
132
134
fn main () {
133
- // This `expect` attribute creates an expectation, that the `unused_variables`
134
- // will be triggered by the following statement. This expectation will not be
135
- // fulfilled, since the `question` variable is used by the `println!` macro.
135
+ // This `#[expect]` attribute creates a lint expectation, that the `unused_variables`
136
+ // lint would be emitted by the following statement. This expectation is
137
+ // unfulfilled, since the `question` variable is used by the `println!` macro.
138
+ // Therefore, the `unfulfilled_lint_expectations` lint will be emitted at the
139
+ // attribute.
136
140
#[expect(unused_variables)]
137
141
let question = " who lives in a pineapple under the sea?" ;
138
142
println! (" {question}" );
139
143
140
- // This `expect` attribute creates an expectation that will be fulfilled, since
141
- // the `answer` variable is never used. It will therefore trigger the
142
- // `unused_variables` lint which will be suppressed by the expectation and fullfil
143
- // it as well.
144
+ // This `#[expect]` attribute creates a lint expectation that will be fulfilled, since
145
+ // the `answer` variable is never used. The `unused_variables` lint, that would usually
146
+ // be emitted, is supressed. No warning will be issued for the statement or attribute.
144
147
#[expect(unused_variables)]
145
148
let answer = " SpongeBob SquarePants!" ;
146
149
}
147
150
```
148
151
149
152
The lint expectation is only fulfilled by lint emissions which have been suppressed by
150
153
the ` expect ` attribute. If the lint level is modified in the scope with other level
151
- attributes like ` warn ` or ` deny ` , the lint will be emitted at the defined level and not
152
- satisdy the expectation. Lint suppressions via ` allow ` or ` expect ` attributes inside the
153
- scope will also not fulfill the expectation.
154
+ attributes like ` allow ` or ` warn ` , the lint emission will be handled accordingly and the
155
+ expectation will remain unfulfilled.
154
156
155
157
``` rust
156
158
#[expect(unused_variables)]
@@ -190,8 +192,8 @@ pub fn thoughts() {
190
192
pub fn another_example () {
191
193
// This attribute creates two lint expectations. The `unused_mut` lint will be
192
194
// suppressed and with that fulfill the first expectation. The `unused_variables`
193
- // won 't be emitted, since the variable is used. That expectation will therefore
194
- // not be satisfied , and a warning will be emitted.
195
+ // wouldn 't be emitted, since the variable is used. That expectation will therefore
196
+ // be unsatified , and a warning will be emitted.
195
197
#[expect(unused_mut, unused_variables)]
196
198
let mut link = " https://www.rust-lang.org/" ;
197
199
0 commit comments