Skip to content

Commit 9e8f53d

Browse files
committed
Auto merge of rust-lang#101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
Move lint level source explanation to the bottom So, uhhhhh r? `@estebank` ## User-facing change "note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic: ```diff - = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue rust-lang#87678 <rust-lang#87678> + = note: `#[warn(unsupported_calling_conventions)]` on by default ``` Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO. ## Developer-facing change `struct_span_lint` and similar methods have a different signature. Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)` After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion. Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere. ## Subtle problem By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings... I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate. ## P.S. I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2 parents 8b59fe4 + 8dfbad9 commit 9e8f53d

File tree

207 files changed

+260
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+260
-267
lines changed

clippy_lints/src/module_style.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ impl EarlyLintPass for ModStyle {
117117
cx.struct_span_lint(
118118
SELF_NAMED_MODULE_FILES,
119119
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
120-
|build| {
121-
let mut lint =
122-
build.build(&format!("`mod.rs` files are required, found `{}`", path.display()));
123-
lint.help(&format!("move `{}` to `{}`", path.display(), correct.display(),));
124-
lint.emit();
120+
format!("`mod.rs` files are required, found `{}`", path.display()),
121+
|lint| {
122+
lint.help(format!(
123+
"move `{}` to `{}`",
124+
path.display(),
125+
correct.display(),
126+
))
125127
},
126128
);
127129
}
@@ -156,11 +158,8 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source
156158
cx.struct_span_lint(
157159
MOD_MODULE_FILES,
158160
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
159-
|build| {
160-
let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display()));
161-
lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),));
162-
lint.emit();
163-
},
161+
format!("`mod.rs` files are not allowed, found `{}`", path.display()),
162+
|lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())),
164163
);
165164
}
166165
}

clippy_utils/src/diagnostics.rs

+20-26
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
4747
/// | ^^^^^^^^^^^^^^^^^^^^^^^
4848
/// ```
4949
pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
50-
cx.struct_span_lint(lint, sp, |diag| {
51-
let mut diag = diag.build(msg);
52-
docs_link(&mut diag, lint);
53-
diag.emit();
50+
cx.struct_span_lint(lint, sp, msg, |diag| {
51+
docs_link(diag, lint);
52+
diag
5453
});
5554
}
5655

@@ -82,15 +81,14 @@ pub fn span_lint_and_help<'a, T: LintContext>(
8281
help_span: Option<Span>,
8382
help: &str,
8483
) {
85-
cx.struct_span_lint(lint, span, |diag| {
86-
let mut diag = diag.build(msg);
84+
cx.struct_span_lint(lint, span, msg, |diag| {
8785
if let Some(help_span) = help_span {
8886
diag.span_help(help_span, help);
8987
} else {
9088
diag.help(help);
9189
}
92-
docs_link(&mut diag, lint);
93-
diag.emit();
90+
docs_link(diag, lint);
91+
diag
9492
});
9593
}
9694

@@ -125,15 +123,14 @@ pub fn span_lint_and_note<'a, T: LintContext>(
125123
note_span: Option<Span>,
126124
note: &str,
127125
) {
128-
cx.struct_span_lint(lint, span, |diag| {
129-
let mut diag = diag.build(msg);
126+
cx.struct_span_lint(lint, span, msg, |diag| {
130127
if let Some(note_span) = note_span {
131128
diag.span_note(note_span, note);
132129
} else {
133130
diag.note(note);
134131
}
135-
docs_link(&mut diag, lint);
136-
diag.emit();
132+
docs_link(diag, lint);
133+
diag
137134
});
138135
}
139136

@@ -147,19 +144,17 @@ where
147144
S: Into<MultiSpan>,
148145
F: FnOnce(&mut Diagnostic),
149146
{
150-
cx.struct_span_lint(lint, sp, |diag| {
151-
let mut diag = diag.build(msg);
152-
f(&mut diag);
153-
docs_link(&mut diag, lint);
154-
diag.emit();
147+
cx.struct_span_lint(lint, sp, msg, |diag| {
148+
f(diag);
149+
docs_link(diag, lint);
150+
diag
155151
});
156152
}
157153

158154
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
159-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
160-
let mut diag = diag.build(msg);
161-
docs_link(&mut diag, lint);
162-
diag.emit();
155+
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
156+
docs_link(diag, lint);
157+
diag
163158
});
164159
}
165160

@@ -171,11 +166,10 @@ pub fn span_lint_hir_and_then(
171166
msg: &str,
172167
f: impl FnOnce(&mut Diagnostic),
173168
) {
174-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
175-
let mut diag = diag.build(msg);
176-
f(&mut diag);
177-
docs_link(&mut diag, lint);
178-
diag.emit();
169+
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
170+
f(diag);
171+
docs_link(diag, lint);
172+
diag
179173
});
180174
}
181175

tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: `std::string::String` may not be held across an `await` point per `clippy
44
LL | let _x = String::from("hello");
55
| ^^
66
|
7-
= note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
87
= note: strings are bad
8+
= note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
99

1010
error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml`
1111
--> $DIR/await_holding_invalid_type.rs:10:9

tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ error: the function has a cognitive complexity of (3/2)
88
LL | fn cognitive_complexity() {
99
| ^^^^^^^^^^^^^^^^^^^^
1010
|
11-
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
1211
= help: you could split it up into multiple smaller functions
12+
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
1313

1414
error: aborting due to previous error; 2 warnings emitted
1515

tests/ui-toml/expect_used/expect_used.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: used `expect()` on `an Option` value
44
LL | let _ = opt.expect("");
55
| ^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::expect-used` implied by `-D warnings`
87
= help: if this value is `None`, it will panic
8+
= note: `-D clippy::expect-used` implied by `-D warnings`
99

1010
error: used `expect()` on `a Result` value
1111
--> $DIR/expect_used.rs:11:13

tests/ui-toml/fn_params_excessive_bools/test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: more than 1 bools in function parameters
44
LL | fn g(_: bool, _: bool) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
87
= help: consider refactoring bools into two-variant enums
8+
= note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
99

1010
error: aborting due to previous error
1111

tests/ui-toml/large_include_file/large_include_file.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: attempted to include a large file
44
LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::large-include-file` implied by `-D warnings`
87
= note: the configuration allows a maximum size of 600 bytes
8+
= note: `-D clippy::large-include-file` implied by `-D warnings`
99
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
1010

1111
error: attempted to include a large file

tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error: use of irregular braces for `vec!` macro
44
LL | let _ = vec! {1, 2, 3};
55
| ^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings`
87
help: consider writing `vec![1, 2, 3]`
98
--> $DIR/conf_nonstandard_macro_braces.rs:43:13
109
|
1110
LL | let _ = vec! {1, 2, 3};
1211
| ^^^^^^^^^^^^^^
12+
= note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings`
1313

1414
error: use of irregular braces for `format!` macro
1515
--> $DIR/conf_nonstandard_macro_braces.rs:44:13

tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ error: some fields in `NoGeneric` are not safe to be sent to another thread
44
LL | unsafe impl Send for NoGeneric {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
87
note: it is not safe to send field `rc_is_not_send` to another thread
98
--> $DIR/test.rs:8:5
109
|
1110
LL | rc_is_not_send: Rc<String>,
1211
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1312
= help: use a thread-safe type that implements `Send`
13+
= note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
1414

1515
error: some fields in `MultiField<T>` are not safe to be sent to another thread
1616
--> $DIR/test.rs:19:1

tests/ui-toml/struct_excessive_bools/test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | | a: bool,
66
LL | | }
77
| |_^
88
|
9-
= note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
109
= help: consider using a state machine or refactoring bools into two-variant enums
10+
= note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
1111

1212
error: aborting due to previous error
1313

tests/ui-toml/unwrap_used/unwrap_used.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ error: used `unwrap()` on `an Option` value
1616
LL | let _ = boxed_slice.get(1).unwrap();
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
|
19-
= note: `-D clippy::unwrap-used` implied by `-D warnings`
2019
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
20+
= note: `-D clippy::unwrap-used` implied by `-D warnings`
2121

2222
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
2323
--> $DIR/unwrap_used.rs:36:17

tests/ui/absurd-extreme-comparisons.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: this comparison involving the minimum or maximum element for this type co
44
LL | u <= 0;
55
| ^^^^^^
66
|
7-
= note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
87
= help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead
8+
= note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
99

1010
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
1111
--> $DIR/absurd-extreme-comparisons.rs:15:5

tests/ui/allow_attributes_without_reason.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error: `allow` attribute without specifying a reason
44
LL | #[allow(dead_code)]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7+
= help: try adding a reason at the end with `, reason = ".."`
78
note: the lint level is defined here
89
--> $DIR/allow_attributes_without_reason.rs:2:9
910
|
1011
LL | #![deny(clippy::allow_attributes_without_reason)]
1112
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= help: try adding a reason at the end with `, reason = ".."`
1313

1414
error: `allow` attribute without specifying a reason
1515
--> $DIR/allow_attributes_without_reason.rs:6:1

tests/ui/approx_const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: approximate value of `f{32, 64}::consts::E` found
44
LL | let my_e = 2.7182;
55
| ^^^^^^
66
|
7-
= note: `-D clippy::approx-constant` implied by `-D warnings`
87
= help: consider using the constant directly
8+
= note: `-D clippy::approx-constant` implied by `-D warnings`
99

1010
error: approximate value of `f{32, 64}::consts::E` found
1111
--> $DIR/approx_const.rs:5:20

tests/ui/as_conversions.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: using a potentially dangerous silent `as` conversion
44
LL | let i = 0u32 as u64;
55
| ^^^^^^^^^^^
66
|
7-
= note: `-D clippy::as-conversions` implied by `-D warnings`
87
= help: consider using a safe wrapper for this conversion
8+
= note: `-D clippy::as-conversions` implied by `-D warnings`
99

1010
error: using a potentially dangerous silent `as` conversion
1111
--> $DIR/as_conversions.rs:17:13

tests/ui/asm_syntax.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: Intel x86 assembly syntax used
44
LL | asm!("");
55
| ^^^^^^^^
66
|
7-
= note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings`
87
= help: use AT&T x86 assembly syntax
8+
= note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings`
99

1010
error: Intel x86 assembly syntax used
1111
--> $DIR/asm_syntax.rs:9:9
@@ -29,8 +29,8 @@ error: AT&T x86 assembly syntax used
2929
LL | asm!("", options(att_syntax));
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
|
32-
= note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings`
3332
= help: use Intel x86 assembly syntax
33+
= note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings`
3434

3535
error: AT&T x86 assembly syntax used
3636
--> $DIR/asm_syntax.rs:24:9

tests/ui/assertions_on_constants.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: `assert!(true)` will be optimized out by the compiler
44
LL | assert!(true);
55
| ^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
87
= help: remove it
8+
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
99

1010
error: `assert!(false)` should probably be replaced
1111
--> $DIR/assertions_on_constants.rs:11:5

tests/ui/await_holding_lock.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ error: this `MutexGuard` is held across an `await` point
44
LL | let guard = x.lock().unwrap();
55
| ^^^^^
66
|
7-
= note: `-D clippy::await-holding-lock` implied by `-D warnings`
87
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
98
note: these are all the `await` points this lock is held through
109
--> $DIR/await_holding_lock.rs:9:9
@@ -13,6 +12,7 @@ LL | / let guard = x.lock().unwrap();
1312
LL | | baz().await
1413
LL | | }
1514
| |_____^
15+
= note: `-D clippy::await-holding-lock` implied by `-D warnings`
1616

1717
error: this `MutexGuard` is held across an `await` point
1818
--> $DIR/await_holding_lock.rs:24:13

tests/ui/await_holding_refcell_ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ error: this `RefCell` reference is held across an `await` point
44
LL | let b = x.borrow();
55
| ^
66
|
7-
= note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
87
= help: ensure the reference is dropped before calling `await`
98
note: these are all the `await` points this reference is held through
109
--> $DIR/await_holding_refcell_ref.rs:6:5
@@ -13,6 +12,7 @@ LL | / let b = x.borrow();
1312
LL | | baz().await
1413
LL | | }
1514
| |_^
15+
= note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
1616

1717
error: this `RefCell` reference is held across an `await` point
1818
--> $DIR/await_holding_refcell_ref.rs:11:9

tests/ui/blanket_clippy_restriction_lints.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: restriction lints are not meant to be all enabled
44
LL | #![warn(clippy::restriction)]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
87
= help: try enabling only the lints you really need
8+
= note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
99

1010
error: restriction lints are not meant to be all enabled
1111
--> $DIR/blanket_clippy_restriction_lints.rs:5:9

tests/ui/bool_to_int_with_if.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | | 0
88
LL | | };
99
| |_____^ help: replace with from: `i32::from(a)`
1010
|
11-
= note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
1211
= note: `a as i32` or `a.into()` can also be valid options
12+
= note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
1313

1414
error: boolean to int conversion using if
1515
--> $DIR/bool_to_int_with_if.rs:20:5

tests/ui/borrow_interior_mutable_const/enums.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
44
LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
55
| ^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
87
= help: assign this const to a local or static variable, and use the variable here
8+
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
99

1010
error: a `const` item with interior mutability should not be borrowed
1111
--> $DIR/enums.rs:37:18

tests/ui/borrow_interior_mutable_const/others.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
44
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
55
| ^^^^^^
66
|
7-
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
87
= help: assign this const to a local or static variable, and use the variable here
8+
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
99

1010
error: a `const` item with interior mutability should not be borrowed
1111
--> $DIR/others.rs:55:16

tests/ui/borrow_interior_mutable_const/traits.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
44
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
55
| ^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
87
= help: assign this const to a local or static variable, and use the variable here
8+
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
99

1010
error: a `const` item with interior mutability should not be borrowed
1111
--> $DIR/traits.rs:26:18

tests/ui/box_collection.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: you seem to be trying to use `Box<Vec<..>>`. Consider using just `Vec<..>
44
LL | fn test1(foo: Box<Vec<bool>>) {}
55
| ^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::box-collection` implied by `-D warnings`
87
= help: `Vec<..>` is already on the heap, `Box<Vec<..>>` makes an extra allocation
8+
= note: `-D clippy::box-collection` implied by `-D warnings`
99

1010
error: you seem to be trying to use `Box<String>`. Consider using just `String`
1111
--> $DIR/box_collection.rs:28:15

0 commit comments

Comments
 (0)