Skip to content

Commit

Permalink
Use spanned help and put less emphasis on it
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 14, 2024
1 parent ec7bf5b commit ed1ed42
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 57 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ pub enum NonLocalDefinitionsDiag {
body_name: String,
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
const_anon: Option<Option<Span>>,
move_help: Span,
has_trait: bool,
},
MacroRules {
Expand All @@ -1361,19 +1362,20 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
body_name,
cargo_update,
const_anon,
move_help,
has_trait,
} => {
diag.arg("depth", depth);
diag.arg("body_kind_descr", body_kind_descr);
diag.arg("body_name", body_name);

diag.help(fluent::lint_help);
if has_trait {
diag.note(fluent::lint_bounds);
diag.note(fluent::lint_with_trait);
} else {
diag.note(fluent::lint_without_trait);
}
diag.span_help(move_help, fluent::lint_help);

if let Some(cargo_update) = cargo_update {
diag.subdiagnostic(&diag.dcx, cargo_update);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
item.span.shrink_to_lo().to(impl_.self_ty.span),
NonLocalDefinitionsDiag::Impl {
depth: self.body_depth,
move_help: item.span,
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
body_name: parent_opt_item_name
.map(|s| s.to_ident_string())
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/lint/non-local-defs/cargo-update.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | non_local_macro::non_local_impl!(LocalStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `_IMPL_DEBUG`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current constant `_IMPL_DEBUG`
--> $DIR/cargo-update.rs:17:1
|
LL | non_local_macro::non_local_impl!(LocalStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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`
= 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
= 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>
Expand Down
57 changes: 49 additions & 8 deletions tests/ui/lint/non-local-defs/consts.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ LL | const Z: () = {
LL | impl Uto for &Test {}
| ^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `Z`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current constant `Z`
--> $DIR/consts.rs:13:5
|
LL | impl Uto for &Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= 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
= 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>
= note: `#[warn(non_local_definitions)]` on by default
Expand All @@ -20,9 +24,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Uto2 for Test {}
| ^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current static `A`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current static `A`
--> $DIR/consts.rs:24:5
|
LL | impl Uto2 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= 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
= 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>

Expand All @@ -32,9 +40,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Uto3 for Test {}
| ^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `B`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current constant `B`
--> $DIR/consts.rs:32:5
|
LL | impl Uto3 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= 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
= 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>

Expand All @@ -44,8 +56,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Test {
| ^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/consts.rs:43:5
|
LL | / impl Test {
LL | |
LL | | fn foo() {}
LL | | }
| |_____^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -54,8 +73,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Test {
| ^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current inline constant `<unnameable>` and up 2 bodies
= 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
help: move this `impl` block and all the necessary types/traits outside the of the current inline constant `<unnameable>` and up 2 bodies
--> $DIR/consts.rs:50:9
|
LL | / impl Test {
LL | |
LL | | fn hoo() {}
LL | | }
| |_________^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -64,8 +90,15 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Test {
| ^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current constant `_` and up 2 bodies
= 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
help: move this `impl` block and all the necessary types/traits outside the of the current constant `_` and up 2 bodies
--> $DIR/consts.rs:59:9
|
LL | / impl Test {
LL | |
LL | | fn foo2() {}
LL | | }
| |_________^
= 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
= 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>

Expand All @@ -75,9 +108,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Uto9 for Test {}
| ^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current closure `<unnameable>` and up 2 bodies
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current closure `<unnameable>` and up 2 bodies
--> $DIR/consts.rs:72:9
|
LL | impl Uto9 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -86,9 +123,13 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl Uto10 for Test {}
| ^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current constant expression `<unnameable>` and up 2 bodies
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current constant expression `<unnameable>` and up 2 bodies
--> $DIR/consts.rs:79:9
|
LL | impl Uto10 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^^
= 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>

warning: 8 warnings emitted
Expand Down
66 changes: 60 additions & 6 deletions tests/ui/lint/non-local-defs/exhaustive-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<()> for Dog {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:7:5
|
LL | / impl PartialEq<()> for Dog {
LL | |
LL | | fn eq(&self, _: &()) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>
= note: `#[warn(non_local_definitions)]` on by default

Expand All @@ -16,9 +25,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<()> for &Dog {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:14:5
|
LL | / impl PartialEq<()> for &Dog {
LL | |
LL | | fn eq(&self, _: &()) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -27,9 +45,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<Dog> for () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:21:5
|
LL | / impl PartialEq<Dog> for () {
LL | |
LL | | fn eq(&self, _: &Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -38,9 +65,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<&Dog> for () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:28:5
|
LL | / impl PartialEq<&Dog> for () {
LL | |
LL | | fn eq(&self, _: &&Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -49,9 +85,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<Dog> for &Dog {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:35:5
|
LL | / impl PartialEq<Dog> for &Dog {
LL | |
LL | | fn eq(&self, _: &Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
Expand All @@ -60,9 +105,18 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
LL | impl PartialEq<&Dog> for &Dog {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
= 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
= 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`
help: move this `impl` block and all the necessary types/traits outside the of the current function `main`
--> $DIR/exhaustive-trait.rs:42:5
|
LL | / impl PartialEq<&Dog> for &Dog {
LL | |
LL | | fn eq(&self, _: &&Dog) -> bool {
LL | | todo!()
LL | | }
LL | | }
| |_____^
= 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>

warning: 6 warnings emitted
Expand Down
Loading

0 comments on commit ed1ed42

Please sign in to comment.