You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `expect(C)` attributecreatesalintexpectationforlint `C`.Theexpectationwillbefulfilled, ifa `warn(C)` attributeatthesamelocationwouldresultinalintemission.Iftheexpectationisunfulfilled, becauselint `C` wouldnotbeemitted, the `unfulfilled_lint_expectations` lintwillbeemittedattheattribute.
161
161
162
-
```rust
163
-
fnmain() {
164
-
// This `#[expect]` attribute creates a lint expectation, that the `unused_variables`
165
-
// lint would be emitted by the following statement. This expectation is
166
-
// unfulfilled, since the `question` variable is used by the `println!` macro.
167
-
// Therefore, the `unfulfilled_lint_expectations` lint will be emitted at the
168
-
// attribute.
169
-
#[expect(unused_variables)]
170
-
letquestion="who lives in a pineapple under the sea?";
171
-
println!("{question}");
172
-
173
-
// This `#[expect]` attribute creates a lint expectation that will be fulfilled, since
174
-
// the `answer` variable is never used. The `unused_variables` lint, that would usually
175
-
// be emitted, is suppressed. No warning will be issued for the statement or attribute.
176
-
#[expect(unused_variables)]
177
-
letanswer="SpongeBob SquarePants!";
178
-
}
179
-
```
162
+
> [!EXAMPLE]
163
+
> ```rust
164
+
> fnmain() {
165
+
> // This `#[expect]` attribute creates a lint expectation, that the `unused_variables`
166
+
> // lint would be emitted by the following statement. This expectation is
167
+
> // unfulfilled, since the `question` variable is used by the `println!` macro.
168
+
> // Therefore, the `unfulfilled_lint_expectations` lint will be emitted at the
169
+
> // attribute.
170
+
> #[expect(unused_variables)]
171
+
> letquestion="who lives in a pineapple under the sea?";
172
+
> println!("{question}");
173
+
>
174
+
> // This `#[expect]` attribute creates a lint expectation that will be fulfilled, since
175
+
> // the `answer` variable is never used. The `unused_variables` lint, that would usually
176
+
> // be emitted, is suppressed. No warning will be issued for the statement or attribute.
177
+
> #[expect(unused_variables)]
178
+
> letanswer="SpongeBob SquarePants!";
179
+
> }
180
+
> ```
180
181
181
182
r[attributes.diagnostics.expect.fulfillment]
182
183
Thelintexpectationisonlyfulfilledbylintemissionswhichhavebeensuppressedbythe `expect` attribute.Ifthelintlevelismodifiedinthescopewithotherlevelattributeslike `allow` or `warn`, thelintemissionwillbehandledaccordinglyandtheexpectationwillremainunfulfilled.
183
184
184
-
```rust
185
-
#[expect(unused_variables)]
186
-
fnselect_song() {
187
-
// This will emit the `unused_variables` lint at the warn level
188
-
// as defined by the `warn` attribute. This will not fulfill the
189
-
// expectation above the function.
190
-
#[warn(unused_variables)]
191
-
letsong_name="Crab Rave";
192
-
193
-
// The `allow` attribute suppresses the lint emission. This will not
194
-
// fulfill the expectation as it has been suppressed by the `allow`
195
-
// attribute and not the `expect` attribute above the function.
196
-
#[allow(unused_variables)]
197
-
letsong_creator="Noisestorm";
198
-
199
-
// This `expect` attribute will suppress the `unused_variables` lint emission
200
-
// at the variable. The `expect` attribute above the function will still not
201
-
// be fulfilled, since this lint emission has been suppressed by the local
202
-
// expect attribute.
203
-
#[expect(unused_variables)]
204
-
letsong_version="Monstercat Release";
205
-
}
206
-
```
185
+
> [!EXAMPLE]
186
+
> ```rust
187
+
> #[expect(unused_variables)]
188
+
> fnselect_song() {
189
+
> // This will emit the `unused_variables` lint at the warn level
190
+
> // as defined by the `warn` attribute. This will not fulfill the
191
+
> // expectation above the function.
192
+
> #[warn(unused_variables)]
193
+
> letsong_name="Crab Rave";
194
+
>
195
+
> // The `allow` attribute suppresses the lint emission. This will not
196
+
> // fulfill the expectation as it has been suppressed by the `allow`
197
+
> // attribute and not the `expect` attribute above the function.
198
+
> #[allow(unused_variables)]
199
+
> letsong_creator="Noisestorm";
200
+
>
201
+
> // This `expect` attribute will suppress the `unused_variables` lint emission
202
+
> // at the variable. The `expect` attribute above the function will still not
203
+
> // be fulfilled, since this lint emission has been suppressed by the local
204
+
> // expect attribute.
205
+
> #[expect(unused_variables)]
206
+
> letsong_version="Monstercat Release";
207
+
> }
208
+
> ```
207
209
208
210
r[attributes.diagnostics.expect.independent]
209
-
If the `expect` attribute contains several lints, each one is expected separately. For a lint group it's enough if one lint inside the group has been emitted:
210
-
211
-
```rust
212
-
// This expectation will be fulfilled by the unused value inside the function
213
-
// since the emitted `unused_variables` lint is inside the `unused` lint group.
214
-
#[expect(unused)]
215
-
pubfnthoughts() {
216
-
letunused="I'm running out of examples";
217
-
}
218
-
219
-
pubfnanother_example() {
220
-
// This attribute creates two lint expectations. The `unused_mut` lint will be
221
-
// suppressed and with that fulfill the first expectation. The `unused_variables`
222
-
// wouldn't be emitted, since the variable is used. That expectation will therefore
0 commit comments