Skip to content

Commit ed1ed42

Browse files
committed
Use spanned help and put less emphasis on it
1 parent ec7bf5b commit ed1ed42

11 files changed

+388
-57
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ pub enum NonLocalDefinitionsDiag {
13401340
body_name: String,
13411341
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13421342
const_anon: Option<Option<Span>>,
1343+
move_help: Span,
13431344
has_trait: bool,
13441345
},
13451346
MacroRules {
@@ -1361,19 +1362,20 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13611362
body_name,
13621363
cargo_update,
13631364
const_anon,
1365+
move_help,
13641366
has_trait,
13651367
} => {
13661368
diag.arg("depth", depth);
13671369
diag.arg("body_kind_descr", body_kind_descr);
13681370
diag.arg("body_name", body_name);
13691371

1370-
diag.help(fluent::lint_help);
13711372
if has_trait {
13721373
diag.note(fluent::lint_bounds);
13731374
diag.note(fluent::lint_with_trait);
13741375
} else {
13751376
diag.note(fluent::lint_without_trait);
13761377
}
1378+
diag.span_help(move_help, fluent::lint_help);
13771379

13781380
if let Some(cargo_update) = cargo_update {
13791381
diag.subdiagnostic(&diag.dcx, cargo_update);

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
222222
item.span.shrink_to_lo().to(impl_.self_ty.span),
223223
NonLocalDefinitionsDiag::Impl {
224224
depth: self.body_depth,
225+
move_help: item.span,
225226
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
226227
body_name: parent_opt_item_name
227228
.map(|s| s.to_ident_string())

tests/ui/lint/non-local-defs/cargo-update.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
44
LL | non_local_macro::non_local_impl!(LocalStruct);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `_IMPL_DEBUG`
87
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
98
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
9+
help: move this `impl` block and all the necessary types/traits outside the of the current constant `_IMPL_DEBUG`
10+
--> $DIR/cargo-update.rs:17:1
11+
|
12+
LL | non_local_macro::non_local_impl!(LocalStruct);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1014
= note: the macro `non_local_macro::non_local_impl` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
1115
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
1216
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

tests/ui/lint/non-local-defs/consts.stderr

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ LL | const Z: () = {
77
LL | impl Uto for &Test {}
88
| ^^^^^^^^^^^^^^^^^^
99
|
10-
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `Z`
1110
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
1211
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12+
help: move this `impl` block and all the necessary types/traits outside the of the current constant `Z`
13+
--> $DIR/consts.rs:13:5
14+
|
15+
LL | impl Uto for &Test {}
16+
| ^^^^^^^^^^^^^^^^^^^^^
1317
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
1418
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
1519
= note: `#[warn(non_local_definitions)]` on by default
@@ -20,9 +24,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
2024
LL | impl Uto2 for Test {}
2125
| ^^^^^^^^^^^^^^^^^^
2226
|
23-
= help: move this `impl` block and all the necessary types/traits outside the of the current static `A`
2427
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
2528
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
29+
help: move this `impl` block and all the necessary types/traits outside the of the current static `A`
30+
--> $DIR/consts.rs:24:5
31+
|
32+
LL | impl Uto2 for Test {}
33+
| ^^^^^^^^^^^^^^^^^^^^^
2634
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
2735
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
2836

@@ -32,9 +40,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
3240
LL | impl Uto3 for Test {}
3341
| ^^^^^^^^^^^^^^^^^^
3442
|
35-
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `B`
3643
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
3744
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
45+
help: move this `impl` block and all the necessary types/traits outside the of the current constant `B`
46+
--> $DIR/consts.rs:32:5
47+
|
48+
LL | impl Uto3 for Test {}
49+
| ^^^^^^^^^^^^^^^^^^^^^
3850
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
3951
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
4052

@@ -44,8 +56,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
4456
LL | impl Test {
4557
| ^^^^^^^^^
4658
|
47-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
4859
= note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block
60+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
61+
--> $DIR/consts.rs:43:5
62+
|
63+
LL | / impl Test {
64+
LL | |
65+
LL | | fn foo() {}
66+
LL | | }
67+
| |_____^
4968
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
5069

5170
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -54,8 +73,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
5473
LL | impl Test {
5574
| ^^^^^^^^^
5675
|
57-
= help: move this `impl` block and all the necessary types/traits outside the of the current inline constant `<unnameable>` and up 2 bodies
5876
= note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block
77+
help: move this `impl` block and all the necessary types/traits outside the of the current inline constant `<unnameable>` and up 2 bodies
78+
--> $DIR/consts.rs:50:9
79+
|
80+
LL | / impl Test {
81+
LL | |
82+
LL | | fn hoo() {}
83+
LL | | }
84+
| |_________^
5985
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
6086

6187
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -64,8 +90,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
6490
LL | impl Test {
6591
| ^^^^^^^^^
6692
|
67-
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `_` and up 2 bodies
6893
= note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block
94+
help: move this `impl` block and all the necessary types/traits outside the of the current constant `_` and up 2 bodies
95+
--> $DIR/consts.rs:59:9
96+
|
97+
LL | / impl Test {
98+
LL | |
99+
LL | | fn foo2() {}
100+
LL | | }
101+
| |_________^
69102
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
70103
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
71104

@@ -75,9 +108,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
75108
LL | impl Uto9 for Test {}
76109
| ^^^^^^^^^^^^^^^^^^
77110
|
78-
= help: move this `impl` block and all the necessary types/traits outside the of the current closure `<unnameable>` and up 2 bodies
79111
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
80112
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
113+
help: move this `impl` block and all the necessary types/traits outside the of the current closure `<unnameable>` and up 2 bodies
114+
--> $DIR/consts.rs:72:9
115+
|
116+
LL | impl Uto9 for Test {}
117+
| ^^^^^^^^^^^^^^^^^^^^^
81118
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
82119

83120
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -86,9 +123,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
86123
LL | impl Uto10 for Test {}
87124
| ^^^^^^^^^^^^^^^^^^^
88125
|
89-
= help: move this `impl` block and all the necessary types/traits outside the of the current constant expression `<unnameable>` and up 2 bodies
90126
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
91127
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
128+
help: move this `impl` block and all the necessary types/traits outside the of the current constant expression `<unnameable>` and up 2 bodies
129+
--> $DIR/consts.rs:79:9
130+
|
131+
LL | impl Uto10 for Test {}
132+
| ^^^^^^^^^^^^^^^^^^^^^^
92133
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
93134

94135
warning: 8 warnings emitted

tests/ui/lint/non-local-defs/exhaustive-trait.stderr

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
44
LL | impl PartialEq<()> for Dog {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
87
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
98
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
9+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
10+
--> $DIR/exhaustive-trait.rs:7:5
11+
|
12+
LL | / impl PartialEq<()> for Dog {
13+
LL | |
14+
LL | | fn eq(&self, _: &()) -> bool {
15+
LL | | todo!()
16+
LL | | }
17+
LL | | }
18+
| |_____^
1019
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
1120
= note: `#[warn(non_local_definitions)]` on by default
1221

@@ -16,9 +25,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
1625
LL | impl PartialEq<()> for &Dog {
1726
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1827
|
19-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
2028
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
2129
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
30+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
31+
--> $DIR/exhaustive-trait.rs:14:5
32+
|
33+
LL | / impl PartialEq<()> for &Dog {
34+
LL | |
35+
LL | | fn eq(&self, _: &()) -> bool {
36+
LL | | todo!()
37+
LL | | }
38+
LL | | }
39+
| |_____^
2240
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
2341

2442
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -27,9 +45,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
2745
LL | impl PartialEq<Dog> for () {
2846
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2947
|
30-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
3148
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
3249
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
50+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
51+
--> $DIR/exhaustive-trait.rs:21:5
52+
|
53+
LL | / impl PartialEq<Dog> for () {
54+
LL | |
55+
LL | | fn eq(&self, _: &Dog) -> bool {
56+
LL | | todo!()
57+
LL | | }
58+
LL | | }
59+
| |_____^
3360
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
3461

3562
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -38,9 +65,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
3865
LL | impl PartialEq<&Dog> for () {
3966
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4067
|
41-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
4268
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
4369
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
70+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
71+
--> $DIR/exhaustive-trait.rs:28:5
72+
|
73+
LL | / impl PartialEq<&Dog> for () {
74+
LL | |
75+
LL | | fn eq(&self, _: &&Dog) -> bool {
76+
LL | | todo!()
77+
LL | | }
78+
LL | | }
79+
| |_____^
4480
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
4581

4682
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -49,9 +85,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
4985
LL | impl PartialEq<Dog> for &Dog {
5086
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5187
|
52-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
5388
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
5489
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
90+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
91+
--> $DIR/exhaustive-trait.rs:35:5
92+
|
93+
LL | / impl PartialEq<Dog> for &Dog {
94+
LL | |
95+
LL | | fn eq(&self, _: &Dog) -> bool {
96+
LL | | todo!()
97+
LL | | }
98+
LL | | }
99+
| |_____^
55100
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
56101

57102
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -60,9 +105,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
60105
LL | impl PartialEq<&Dog> for &Dog {
61106
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62107
|
63-
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
64108
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
65109
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
110+
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
111+
--> $DIR/exhaustive-trait.rs:42:5
112+
|
113+
LL | / impl PartialEq<&Dog> for &Dog {
114+
LL | |
115+
LL | | fn eq(&self, _: &&Dog) -> bool {
116+
LL | | todo!()
117+
LL | | }
118+
LL | | }
119+
| |_____^
66120
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
67121

68122
warning: 6 warnings emitted

0 commit comments

Comments
 (0)