non_local_defs: point the parent item when appropriate

This commit is contained in:
Urgau 2024-05-18 15:07:28 +02:00
parent 98273ec612
commit c7d300442f
13 changed files with 330 additions and 481 deletions

View File

@ -543,11 +543,6 @@ lint_non_local_definitions_cargo_update = the {$macro_kind} `{$macro_name}` may
lint_non_local_definitions_deprecation = 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>
lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks should be written at the same level as their item
.move_help =
move this `impl` block outside of the current {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies
}
.remove_help = remove `{$may_remove_part}` to make the `impl` local
.without_trait = methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
.with_trait = 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`
@ -555,6 +550,12 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho
.exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration
.const_anon = use a const-anon item to suppress this lint
lint_non_local_definitions_impl_move_help =
move the `impl` block outside of this {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies
}
lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
.help =
remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->

View File

@ -1336,8 +1336,7 @@ pub enum NonLocalDefinitionsDiag {
body_name: String,
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
const_anon: Option<Option<Span>>,
move_help: Span,
may_move: Vec<Span>,
move_to: Option<(Span, Vec<Span>)>,
may_remove: Option<(Span, String)>,
has_trait: bool,
self_ty_str: String,
@ -1362,8 +1361,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
body_name,
cargo_update,
const_anon,
move_help,
may_move,
move_to,
may_remove,
has_trait,
self_ty_str,
@ -1385,11 +1383,13 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
diag.note(fluent::lint_without_trait);
}
let mut ms = MultiSpan::from_span(move_help);
for sp in may_move {
ms.push_span_label(sp, fluent::lint_non_local_definitions_may_move);
if let Some((move_help, may_move)) = move_to {
let mut ms = MultiSpan::from_span(move_help);
for sp in may_move {
ms.push_span_label(sp, fluent::lint_non_local_definitions_may_move);
}
diag.span_help(ms, fluent::lint_non_local_definitions_impl_move_help);
}
diag.span_help(ms, fluent::lint_move_help);
if let Some((span, part)) = may_remove {
diag.arg("may_remove_part", part);

View File

@ -198,17 +198,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
}
collector.visit_generics(&impl_.generics);
let may_move: Vec<Span> = collector
let mut may_move: Vec<Span> = collector
.paths
.into_iter()
.filter_map(|path| {
if path_has_local_parent(&path, cx, parent, parent_parent) {
Some(path_span_without_args(&path))
if let Some(did) = path.res.opt_def_id()
&& did_has_local_parent(did, cx.tcx, parent, parent_parent)
{
Some(cx.tcx.def_span(did))
} else {
None
}
})
.collect();
may_move.sort();
may_move.dedup();
let const_anon = matches!(parent_def_kind, DefKind::Const | DefKind::Static { .. })
.then_some(span_for_const_anon_suggestion);
@ -244,13 +248,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
} else {
None
};
let move_to = if may_move.is_empty() {
ms.push_span_label(
cx.tcx.def_span(parent),
fluent::lint_non_local_definitions_impl_move_help,
);
None
} else {
Some((cx.tcx.def_span(parent), may_move))
};
cx.emit_span_lint(
NON_LOCAL_DEFINITIONS,
ms,
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())
@ -259,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
const_anon,
self_ty_str,
of_trait_str,
may_move,
move_to,
may_remove,
has_trait: impl_.of_trait.is_some(),
},

View File

@ -6,14 +6,10 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
| |
| `LocalStruct` is not local
| `Debug` is not local
| move the `impl` block outside of this 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 outside 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: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
= 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>

View File

@ -2,7 +2,10 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
--> $DIR/consts.rs:13:5
|
LL | const Z: () = {
| - help: use a const-anon item to suppress this lint: `_`
| -----------
| | |
| | help: use a const-anon item to suppress this lint: `_`
| move the `impl` block outside of this constant `Z`
...
LL | impl Uto for &Test {}
| ^^^^^---^^^^^-----
@ -12,11 +15,6 @@ LL | impl Uto for &Test {}
|
= 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 outside of the current constant `Z`
--> $DIR/consts.rs:13:5
|
LL | impl Uto for &Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
= 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
@ -24,6 +22,8 @@ LL | impl Uto for &Test {}
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:24:5
|
LL | static A: u32 = {
| ------------- move the `impl` block outside of this static `A`
LL | impl Uto2 for Test {}
| ^^^^^----^^^^^----
| | |
@ -32,17 +32,14 @@ LL | impl Uto2 for Test {}
|
= 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 outside of the current static `A`
--> $DIR/consts.rs:24:5
|
LL | impl Uto2 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
= 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
--> $DIR/consts.rs:32:5
|
LL | const B: u32 = {
| ------------ move the `impl` block outside of this constant `B`
LL | impl Uto3 for Test {}
| ^^^^^----^^^^^----
| | |
@ -51,75 +48,60 @@ LL | impl Uto3 for Test {}
|
= 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 outside of the current constant `B`
--> $DIR/consts.rs:32:5
|
LL | impl Uto3 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
= 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
--> $DIR/consts.rs:43:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
LL | impl Test {
| ^^^^^----
| |
| `Test` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside 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
--> $DIR/consts.rs:50:9
|
LL | impl Test {
| ^^^^^----
| |
| `Test` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current inline constant `<unnameable>` and up 2 bodies
--> $DIR/consts.rs:50:9
|
LL | / impl Test {
LL | const {
| ___________-
LL | | impl Test {
| | ^^^^^----
| | |
| | `Test` is not local
LL | |
LL | | fn hoo() {}
LL | | }
| |_________^
... |
LL | | 1
LL | | };
| |_____- move the `impl` block outside of this inline constant `<unnameable>` and up 2 bodies
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
= 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
--> $DIR/consts.rs:59:9
|
LL | const _: u32 = {
| ------------ move the `impl` block outside of this constant `_` and up 2 bodies
LL | impl Test {
| ^^^^^----
| |
| `Test` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current constant `_` and up 2 bodies
--> $DIR/consts.rs:59:9
|
LL | / impl Test {
LL | |
LL | | fn foo2() {}
LL | | }
| |_________^
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
= 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
--> $DIR/consts.rs:72:9
|
LL | let _a = || {
| -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
LL | impl Uto9 for Test {}
| ^^^^^----^^^^^----
| | |
@ -128,29 +110,25 @@ LL | impl Uto9 for Test {}
|
= 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 outside 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
--> $DIR/consts.rs:79:9
|
LL | impl Uto10 for Test {}
| ^^^^^-----^^^^^----
| | |
| | `Test` is not local
| `Uto10` is not local
LL | type A = [u32; {
| ____________________-
LL | | impl Uto10 for Test {}
| | ^^^^^-----^^^^^----
| | | |
| | | `Test` is not local
| | `Uto10` is not local
LL | |
... |
LL | | }];
| |_____- move the `impl` block outside of this 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 outside 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

View File

@ -1,6 +1,8 @@
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:7:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
LL | impl PartialEq<()> for Dog {
| ^^^^^---------^^^^^^^^^---
| | |
@ -9,22 +11,15 @@ LL | impl PartialEq<()> for Dog {
|
= 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 outside 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
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:14:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl PartialEq<()> for &Dog {
| ^^^^^---------^^^^^^^^^----
| | |
@ -33,21 +28,14 @@ LL | impl PartialEq<()> for &Dog {
|
= 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 outside 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
--> $DIR/exhaustive-trait.rs:21:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl PartialEq<Dog> for () {
| ^^^^^---------^^^^^^^^^^--
| | |
@ -56,21 +44,14 @@ LL | impl PartialEq<Dog> for () {
|
= 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 outside 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
--> $DIR/exhaustive-trait.rs:28:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl PartialEq<&Dog> for () {
| ^^^^^---------^^^^^^^^^^^--
| | |
@ -79,21 +60,14 @@ LL | impl PartialEq<&Dog> for () {
|
= 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 outside 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
--> $DIR/exhaustive-trait.rs:35:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl PartialEq<Dog> for &Dog {
| ^^^^^---------^^^^^^^^^^----
| | |
@ -102,21 +76,14 @@ LL | impl PartialEq<Dog> for &Dog {
|
= 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 outside 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
--> $DIR/exhaustive-trait.rs:42:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl PartialEq<&Dog> for &Dog {
| ^^^^^---------^^^^^^^^^^^----
| | |
@ -125,16 +92,6 @@ LL | impl PartialEq<&Dog> for &Dog {
|
= 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 outside 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

View File

@ -1,26 +1,23 @@
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive.rs:10:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
LL | impl Test {
| ^^^^^----
| |
| `Test` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current function `main`
--> $DIR/exhaustive.rs:10: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>
= note: `#[warn(non_local_definitions)]` on by default
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive.rs:15:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Display for Test {
| ^^^^^-------^^^^^----
| | |
@ -29,37 +26,28 @@ LL | impl Display for Test {
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:15:5
|
LL | / impl Display for Test {
LL | |
LL | | fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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
--> $DIR/exhaustive.rs:22:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl dyn Trait {}
| ^^^^^^^^^-----
| |
| `Trait` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current function `main`
--> $DIR/exhaustive.rs:22:5
|
LL | impl dyn Trait {}
| ^^^^^^^^^^^^^^^^^
= 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
--> $DIR/exhaustive.rs:25:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl<T: Trait> Trait for Vec<T> { }
| ^^^^^^^^^^^^^^^-----^^^^^---^^^
| | |
@ -68,16 +56,14 @@ LL | impl<T: Trait> Trait for Vec<T> { }
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:25:5
|
LL | impl<T: Trait> Trait for Vec<T> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
--> $DIR/exhaustive.rs:28:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for &dyn Trait {}
| ^^^^^-----^^^^^----------
| | |
@ -86,16 +72,14 @@ LL | impl Trait for &dyn Trait {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:28:5
|
LL | impl Trait for &dyn Trait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
--> $DIR/exhaustive.rs:31:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for *mut Test {}
| ^^^^^-----^^^^^---------
| | |
@ -104,16 +88,14 @@ LL | impl Trait for *mut Test {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:31:5
|
LL | impl Trait for *mut 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
--> $DIR/exhaustive.rs:34:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for *mut [Test] {}
| ^^^^^-----^^^^^-----------
| | |
@ -122,16 +104,14 @@ LL | impl Trait for *mut [Test] {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:34:5
|
LL | impl Trait for *mut [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
--> $DIR/exhaustive.rs:37:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for [Test; 8] {}
| ^^^^^-----^^^^^---------
| | |
@ -140,16 +120,14 @@ LL | impl Trait for [Test; 8] {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:37:5
|
LL | impl Trait for [Test; 8] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
--> $DIR/exhaustive.rs:40:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for (Test,) {}
| ^^^^^-----^^^^^-------
| | |
@ -158,16 +136,14 @@ LL | impl Trait for (Test,) {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:40:5
|
LL | impl Trait 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
--> $DIR/exhaustive.rs:43:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for fn(Test) -> () {}
| ^^^^^-----^^^^^--------------
| | |
@ -176,16 +152,14 @@ LL | impl Trait for fn(Test) -> () {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:43:5
|
LL | impl Trait for fn(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
--> $DIR/exhaustive.rs:46:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
...
LL | impl Trait for fn() -> Test {}
| ^^^^^-----^^^^^------------
| | |
@ -194,16 +168,13 @@ LL | impl Trait for fn() -> Test {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:46:5
|
LL | impl Trait for fn() -> 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
--> $DIR/exhaustive.rs:50:9
|
LL | let _a = || {
| -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
LL | impl Trait for Test {}
| ^^^^^-----^^^^^----
| | |
@ -212,11 +183,6 @@ LL | impl Trait for Test {}
|
= 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 outside of the current closure `<unnameable>` and up 2 bodies
--> $DIR/exhaustive.rs:50:9
|
LL | impl Trait 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
@ -231,13 +197,14 @@ LL | impl Trait for *mut InsideMain {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:58:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for *mut InsideMain {}
| ^^^^^^^^^^^^^^^^^^^^----------^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
@ -251,13 +218,14 @@ LL | impl Trait for *mut [InsideMain] {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:60:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for *mut [InsideMain] {}
| ^^^^^^^^^^^^^^^^^^^^^----------^^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
@ -271,13 +239,14 @@ LL | impl Trait for [InsideMain; 8] {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:62:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for [InsideMain; 8] {}
| ^^^^^^^^^^^^^^^^----------^^^^^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
@ -291,13 +260,14 @@ LL | impl Trait for (InsideMain,) {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:64:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for (InsideMain,) {}
| ^^^^^^^^^^^^^^^^----------^^^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
@ -311,13 +281,14 @@ LL | impl Trait for fn(InsideMain) -> () {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:66:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for fn(InsideMain) -> () {}
| ^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
@ -331,18 +302,21 @@ LL | impl Trait for fn() -> InsideMain {}
|
= 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 outside of the current function `main`
--> $DIR/exhaustive.rs:68:5
help: move the `impl` block outside of this function `main`
--> $DIR/exhaustive.rs:9:1
|
LL | impl Trait for fn() -> InsideMain {}
| ^^^^^^^^^^^^^^^^^^^^^^^----------^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
...
LL | struct InsideMain;
| ----------------- may need to be moved as well
= 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
--> $DIR/exhaustive.rs:72:9
|
LL | fn inside_inside() {
| ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies
LL | impl Display for InsideMain {
| ^^^^^-------^^^^^----------
| | |
@ -351,35 +325,20 @@ LL | impl Display for InsideMain {
|
= 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 outside of the current function `inside_inside` and up 2 bodies
--> $DIR/exhaustive.rs:72:9
|
LL | / impl Display for InsideMain {
LL | |
LL | | fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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
--> $DIR/exhaustive.rs:79:9
|
LL | fn inside_inside() {
| ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies
...
LL | impl InsideMain {
| ^^^^^----------
| |
| `InsideMain` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current function `inside_inside` and up 2 bodies
--> $DIR/exhaustive.rs:79:9
|
LL | / impl InsideMain {
LL | |
LL | | fn bar() {}
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: 20 warnings emitted

View File

@ -1,6 +1,8 @@
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/from-local-for-global.rs:8:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
LL | impl From<Cat> for () {
| ^^^^^----^^^^^^^^^^--
| | |
@ -9,16 +11,6 @@ LL | impl From<Cat> for () {
|
= 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 outside of the current function `main`
--> $DIR/from-local-for-global.rs:8:5
|
LL | / impl From<Cat> for () {
LL | |
LL | | fn from(_: Cat) -> () {
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
@ -32,19 +24,14 @@ LL | impl From<Wrap<Wrap<Elephant>>> for () {
|
= 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 outside of the current function `main`
--> $DIR/from-local-for-global.rs:18:5
help: move the `impl` block outside of this function `main`
--> $DIR/from-local-for-global.rs:7:1
|
LL | impl From<Wrap<Wrap<Elephant>>> for () {
| ^ -------- may need to be moved as well
| _____|
| |
LL | |
LL | | fn from(_: Wrap<Wrap<Elephant>>) -> Self {
LL | | todo!()
LL | | }
LL | | }
| |_____^
LL | fn main() {
| ^^^^^^^^^
...
LL | struct Elephant;
| --------------- may need to be moved as well
= 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
@ -59,13 +46,13 @@ LL | impl StillNonLocal for &Foo {}
|
= 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 outside of the current function `only_global`
--> $DIR/from-local-for-global.rs:32:5
help: move the `impl` block outside of this function `only_global`
--> $DIR/from-local-for-global.rs:30:1
|
LL | impl StillNonLocal for &Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^---^^^
| |
| may need to be moved as well
LL | fn only_global() {
| ^^^^^^^^^^^^^^^^
LL | struct Foo;
| ---------- may need to be moved as well
= 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
@ -79,19 +66,13 @@ LL | impl From<Local1> for GlobalSameFunction {
|
= 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 outside of the current function `same_function`
--> $DIR/from-local-for-global.rs:40:5
help: move the `impl` block outside of this function `same_function`
--> $DIR/from-local-for-global.rs:38:1
|
LL | impl From<Local1> for GlobalSameFunction {
| ^ ------ may need to be moved as well
| _____|
| |
LL | |
LL | | fn from(x: Local1) -> GlobalSameFunction {
LL | | x.0
LL | | }
LL | | }
| |_____^
LL | fn same_function() {
| ^^^^^^^^^^^^^^^^^^
LL | struct Local1(GlobalSameFunction);
| ------------- may need to be moved as well
= 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
@ -105,19 +86,14 @@ LL | impl From<Local2> for GlobalSameFunction {
|
= 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 outside of the current function `same_function`
--> $DIR/from-local-for-global.rs:48:5
help: move the `impl` block outside of this function `same_function`
--> $DIR/from-local-for-global.rs:38:1
|
LL | impl From<Local2> for GlobalSameFunction {
| ^ ------ may need to be moved as well
| _____|
| |
LL | |
LL | | fn from(x: Local2) -> GlobalSameFunction {
LL | | x.0
LL | | }
LL | | }
| |_____^
LL | fn same_function() {
| ^^^^^^^^^^^^^^^^^^
...
LL | struct Local2(GlobalSameFunction);
| ------------- may need to be moved as well
= 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: 5 warnings emitted

View File

@ -9,13 +9,13 @@ LL | impl<T: Local> Global for Vec<T> { }
|
= 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 outside of the current function `main`
--> $DIR/generics.rs:9:5
help: move the `impl` block outside of this function `main`
--> $DIR/generics.rs:6:1
|
LL | impl<T: Local> Global for Vec<T> { }
| ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
LL | trait Local {};
| ----------- may need to be moved as well
= 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
@ -30,18 +30,21 @@ LL | impl Uto7 for Test where Local: std::any::Any {}
|
= 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 outside of the current function `bad`
--> $DIR/generics.rs:20:5
help: move the `impl` block outside of this function `bad`
--> $DIR/generics.rs:18:1
|
LL | impl Uto7 for Test where Local: std::any::Any {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
| |
| may need to be moved as well
LL | fn bad() {
| ^^^^^^^^
LL | struct Local;
| ------------ may need to be moved as well
= 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
--> $DIR/generics.rs:23:5
|
LL | fn bad() {
| -------- move the `impl` block outside of this function `bad`
...
LL | impl<T> Uto8 for T {}
| ^^^^^^^^----^^^^^-
| | |
@ -50,11 +53,6 @@ LL | impl<T> Uto8 for T {}
|
= 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 outside of the current function `bad`
--> $DIR/generics.rs:23:5
|
LL | impl<T> Uto8 for T {}
| ^^^^^^^^^^^^^^^^^^^^^
= 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
@ -68,19 +66,14 @@ LL | impl Default for UwU<OwO> {
|
= 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 outside of the current function `fun`
--> $DIR/generics.rs:32:5
help: move the `impl` block outside of this function `fun`
--> $DIR/generics.rs:29:1
|
LL | impl Default for UwU<OwO> {
| ^ --- may need to be moved as well
| _____|
| |
LL | |
LL | | fn default() -> Self {
LL | | UwU(OwO)
LL | | }
LL | | }
| |_____^
LL | fn fun() {
| ^^^^^^^^
LL | #[derive(Debug)]
LL | struct OwO;
| ---------- may need to be moved as well
= 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
@ -94,17 +87,14 @@ LL | impl AsRef<Cat> for () {
|
= 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 outside of the current function `meow`
--> $DIR/generics.rs:43:5
help: move the `impl` block outside of this function `meow`
--> $DIR/generics.rs:40:1
|
LL | impl AsRef<Cat> for () {
| ^ --- may need to be moved as well
| _____|
| |
LL | |
LL | | fn as_ref(&self) -> &Cat { &Cat }
LL | | }
| |_____^
LL | fn meow() {
| ^^^^^^^^^
LL | #[derive(Debug)]
LL | struct Cat;
| ---------- may need to be moved as well
= 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
@ -118,19 +108,14 @@ LL | impl PartialEq<B> for G {
|
= 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 outside of the current function `fun2`
--> $DIR/generics.rs:54:5
help: move the `impl` block outside of this function `fun2`
--> $DIR/generics.rs:51:1
|
LL | impl PartialEq<B> for G {
| ^ - may need to be moved as well
| _____|
| |
LL | |
LL | | fn eq(&self, _: &B) -> bool {
LL | | true
LL | | }
LL | | }
| |_____^
LL | fn fun2() {
| ^^^^^^^^^
LL | #[derive(Debug, Default)]
LL | struct B;
| -------- may need to be moved as well
= 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
@ -143,19 +128,13 @@ LL | impl From<Wrap<Wrap<Lion>>> for () {
|
= 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 outside of the current function `rawr`
--> $DIR/generics.rs:69:5
help: move the `impl` block outside of this function `rawr`
--> $DIR/generics.rs:66:1
|
LL | impl From<Wrap<Wrap<Lion>>> for () {
| ^ ---- may need to be moved as well
| _____|
| |
LL | |
LL | | fn from(_: Wrap<Wrap<Lion>>) -> Self {
LL | | todo!()
LL | | }
LL | | }
| |_____^
LL | fn rawr() {
| ^^^^^^^^^
LL | struct Lion;
| ----------- may need to be moved as well
= 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
@ -169,19 +148,13 @@ LL | impl From<()> for Wrap<Lion> {
|
= 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 outside of the current function `rawr`
--> $DIR/generics.rs:76:5
help: move the `impl` block outside of this function `rawr`
--> $DIR/generics.rs:66:1
|
LL | impl From<()> for Wrap<Lion> {
| ^ ---- may need to be moved as well
| _____|
| |
LL | |
LL | | fn from(_: ()) -> Self {
LL | | todo!()
LL | | }
LL | | }
| |_____^
LL | fn rawr() {
| ^^^^^^^^^
LL | struct Lion;
| ----------- may need to be moved as well
= 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

View File

@ -1,6 +1,8 @@
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/inside-macro_rules.rs:9:13
|
LL | fn my_func() {
| ------------ move the `impl` block outside of this function `my_func`
LL | impl MacroTrait for OutsideStruct {}
| ^^^^^----------^^^^^-------------
| | |
@ -12,14 +14,6 @@ LL | m!();
|
= 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 outside of the current function `my_func`
--> $DIR/inside-macro_rules.rs:9:13
|
LL | impl MacroTrait for OutsideStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | m!();
| ---- in this macro invocation
= 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
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -9,21 +9,19 @@ LL | impl<T> Trait<InsideMain> for &Vec<below::Type<(InsideMain, T)>>
|
= 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 outside of the current function `main`
--> $DIR/suggest-moving-inner.rs:12:5
help: move the `impl` block outside of this function `main`
--> $DIR/suggest-moving-inner.rs:5:1
|
LL | impl<T> Trait<InsideMain> for &Vec<below::Type<(InsideMain, T)>>
| ^ ---------- ----------- ---------- may need to be moved as well
| | | |
| | | may need to be moved as well
| _____| may need to be moved as well
| |
LL | |
LL | | where
LL | | T: HasFoo
| | ------ may need to be moved as well
LL | | {}
| |______^
LL | fn main() {
| ^^^^^^^^^
LL | mod below {
LL | pub struct Type<T>(T);
| ------------------ may need to be moved as well
LL | }
LL | struct InsideMain;
| ----------------- may need to be moved as well
LL | trait HasFoo {}
| ------------ may need to be moved as well
= 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

View File

@ -10,13 +10,13 @@ LL | impl Test for &Local {}
|
= 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 outside of the current function `main`
--> $DIR/trait-solver-overflow-123573.rs:12:5
help: move the `impl` block outside of this function `main`
--> $DIR/trait-solver-overflow-123573.rs:10:1
|
LL | impl Test for &Local {}
| ^^^^^^^^^^^^^^^-----^^^
| |
| may need to be moved as well
LL | fn main() {
| ^^^^^^^^^
LL | struct Local {}
| ------------ may need to be moved as well
= 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

View File

@ -1,111 +1,116 @@
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/weird-exprs.rs:8:5
|
LL | impl Uto for *mut Test {}
| ^^^^^---^^^^^---------
| | |
| | `*mut Test` is not local
| `Uto` is not local
LL | type A = [u32; {
| ________________-
LL | | impl Uto for *mut Test {}
| | ^^^^^---^^^^^---------
| | | |
| | | `*mut Test` is not local
| | `Uto` is not local
LL | |
... |
LL | | }];
| |_- move the `impl` block outside of this constant expression `<unnameable>`
|
= 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 outside of the current constant expression `<unnameable>`
--> $DIR/weird-exprs.rs:8:5
|
LL | impl Uto for *mut 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>
= note: `#[warn(non_local_definitions)]` on by default
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
--> $DIR/weird-exprs.rs:16:9
|
LL | impl Uto for Test {}
| ^^^^^---^^^^^----
| | |
| | `Test` is not local
| `Uto` is not local
LL | Discr = {
| _____________-
LL | | impl Uto for Test {}
| | ^^^^^---^^^^^----
| | | |
| | | `Test` is not local
| | `Uto` is not local
LL | |
... |
LL | | }
| |_____- move the `impl` block outside of this constant expression `<unnameable>`
|
= 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 outside of the current constant expression `<unnameable>`
--> $DIR/weird-exprs.rs:16:9
|
LL | impl Uto 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
--> $DIR/weird-exprs.rs:25:9
|
LL | impl Test {
| ^^^^^----
| |
| `Test` is not local
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
--> $DIR/weird-exprs.rs:25:9
|
LL | / impl Test {
LL | let _array = [0i32; {
| _________________________-
LL | | impl Test {
| | ^^^^^----
| | |
| | `Test` is not local
LL | |
LL | | fn bar() {}
LL | | }
| |_________^
... |
LL | | 1
LL | | }];
| |_____- move the `impl` block outside of this constant expression `<unnameable>` and up 2 bodies
|
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
= 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
--> $DIR/weird-exprs.rs:34:9
|
LL | impl Uto for &Test {}
| ^^^^^---^^^^^-----
| | |
| | `&'_ Test` is not local
| `Uto` is not local
LL | type A = [u32; {
| ____________________-
LL | | impl Uto for &Test {}
| | ^^^^^---^^^^^-----
| | | |
| | | `&'_ Test` is not local
| | `Uto` is not local
LL | |
... |
LL | | }];
| |_____- move the `impl` block outside of this 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 outside of the current constant expression `<unnameable>` and up 2 bodies
--> $DIR/weird-exprs.rs:34:9
|
LL | impl Uto 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
--> $DIR/weird-exprs.rs:41:9
|
LL | impl Uto for &(Test,) {}
| ^^^^^---^^^^^--------
| | |
| | `&'_ (Test,)` is not local
| `Uto` is not local
LL | fn a(_: [u32; {
| ___________________-
LL | | impl Uto for &(Test,) {}
| | ^^^^^---^^^^^--------
| | | |
| | | `&'_ (Test,)` is not local
| | `Uto` is not local
LL | |
... |
LL | | }]) {}
| |_____- move the `impl` block outside of this 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 outside of the current constant expression `<unnameable>` and up 2 bodies
--> $DIR/weird-exprs.rs:41:9
|
LL | impl Uto 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
--> $DIR/weird-exprs.rs:48:9
|
LL | impl Uto for &(Test,Test) {}
| ^^^^^---^^^^^------------
| | |
| | `&'_ (Test, Test)` is not local
| `Uto` is not local
LL | fn b() -> [u32; {
| _____________________-
LL | | impl Uto for &(Test,Test) {}
| | ^^^^^---^^^^^------------
| | | |
| | | `&'_ (Test, Test)` is not local
| | `Uto` is not local
LL | |
... |
LL | | }] { todo!() }
| |_____- move the `impl` block outside of this 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 outside of the current constant expression `<unnameable>` and up 2 bodies
--> $DIR/weird-exprs.rs:48:9
|
LL | impl Uto for &(Test,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: 6 warnings emitted