From cb58668748db01570eed059710e8a825f9dd917f Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 29 Jun 2024 12:10:33 +0200 Subject: [PATCH 1/5] Revert "Switch back `non_local_definitions` lint to allow-by-default" This reverts commit 0c0dfb88eeefbbaa4c10cfa4a7f0e16541e086eb. --- compiler/rustc_lint/src/non_local_def.rs | 2 +- tests/rustdoc-ui/doctest/non_local_defs.rs | 2 - .../rustdoc-ui/doctest/non_local_defs.stderr | 8 +-- .../rustdoc-ui/doctest/non_local_defs.stdout | 2 +- tests/ui/lint/non-local-defs/cargo-update.rs | 2 - .../lint/non-local-defs/cargo-update.stderr | 8 +-- tests/ui/lint/non-local-defs/consts.rs | 2 - tests/ui/lint/non-local-defs/consts.stderr | 22 +++---- .../lint/non-local-defs/exhaustive-trait.rs | 2 - .../non-local-defs/exhaustive-trait.stderr | 18 +++--- tests/ui/lint/non-local-defs/exhaustive.rs | 2 - .../ui/lint/non-local-defs/exhaustive.stderr | 58 +++++++++---------- .../non-local-defs/from-local-for-global.rs | 2 - .../from-local-for-global.stderr | 24 ++++---- tests/ui/lint/non-local-defs/generics.rs | 2 - tests/ui/lint/non-local-defs/generics.stderr | 36 +++++------- .../lint/non-local-defs/inside-macro_rules.rs | 2 - .../non-local-defs/inside-macro_rules.stderr | 8 +-- tests/ui/lint/non-local-defs/local.rs | 2 - tests/ui/lint/non-local-defs/macro_rules.rs | 2 - .../ui/lint/non-local-defs/macro_rules.stderr | 14 ++--- .../non-local-defs/suggest-moving-inner.rs | 2 - .../suggest-moving-inner.stderr | 10 +--- .../trait-solver-overflow-123573.rs | 2 - .../trait-solver-overflow-123573.stderr | 10 +--- tests/ui/lint/non-local-defs/weird-exprs.rs | 2 - .../ui/lint/non-local-defs/weird-exprs.stderr | 18 +++--- 27 files changed, 95 insertions(+), 169 deletions(-) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index ef7ab7efd5444..3177a3c6749ef 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -49,7 +49,7 @@ declare_lint! { /// All nested bodies (functions, enum discriminant, array length, consts) (expect for /// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked. pub NON_LOCAL_DEFINITIONS, - Allow, + Warn, "checks for non-local definitions", report_in_external_macro } diff --git a/tests/rustdoc-ui/doctest/non_local_defs.rs b/tests/rustdoc-ui/doctest/non_local_defs.rs index 83327eb1e3f49..a2f66c392231a 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.rs +++ b/tests/rustdoc-ui/doctest/non_local_defs.rs @@ -4,8 +4,6 @@ //@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR" //@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME" -#![doc(test(attr(warn(non_local_definitions))))] - //! ``` //! #[macro_export] //! macro_rules! a_macro { () => {} } diff --git a/tests/rustdoc-ui/doctest/non_local_defs.stderr b/tests/rustdoc-ui/doctest/non_local_defs.stderr index 13cd2558793f8..2b47e6b5bc4d5 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.stderr +++ b/tests/rustdoc-ui/doctest/non_local_defs.stderr @@ -1,5 +1,5 @@ warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/non_local_defs.rs:11:1 + --> $DIR/non_local_defs.rs:9:1 | LL | macro_rules! a_macro { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,11 +7,7 @@ LL | macro_rules! a_macro { () => {} } = help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/non_local_defs.rs:8:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(non_local_definitions)]` on by default warning: 1 warning emitted diff --git a/tests/rustdoc-ui/doctest/non_local_defs.stdout b/tests/rustdoc-ui/doctest/non_local_defs.stdout index 61b4074886e4b..bee195fcdd772 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.stdout +++ b/tests/rustdoc-ui/doctest/non_local_defs.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/non_local_defs.rs - (line 9) ... ok +test $DIR/non_local_defs.rs - (line 7) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/tests/ui/lint/non-local-defs/cargo-update.rs b/tests/ui/lint/non-local-defs/cargo-update.rs index 3c62a655a9f61..8b8c15795d376 100644 --- a/tests/ui/lint/non-local-defs/cargo-update.rs +++ b/tests/ui/lint/non-local-defs/cargo-update.rs @@ -10,8 +10,6 @@ // of the `cargo update` suggestion we assert it here. //@ error-pattern: `cargo update -p non_local_macro` -#![warn(non_local_definitions)] - extern crate non_local_macro; struct LocalStruct; diff --git a/tests/ui/lint/non-local-defs/cargo-update.stderr b/tests/ui/lint/non-local-defs/cargo-update.stderr index 4dd41519455c6..bccf8622bac66 100644 --- a/tests/ui/lint/non-local-defs/cargo-update.stderr +++ b/tests/ui/lint/non-local-defs/cargo-update.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/cargo-update.rs:19:1 + --> $DIR/cargo-update.rs:17:1 | LL | non_local_macro::non_local_impl!(LocalStruct); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,11 +14,7 @@ LL | non_local_macro::non_local_impl!(LocalStruct); = 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/cargo-update.rs:13:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(non_local_definitions)]` on by default = note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/consts.rs b/tests/ui/lint/non-local-defs/consts.rs index e7ee611529b96..d8a497e43e502 100644 --- a/tests/ui/lint/non-local-defs/consts.rs +++ b/tests/ui/lint/non-local-defs/consts.rs @@ -2,8 +2,6 @@ //@ edition:2021 //@ rustc-env:CARGO_CRATE_NAME=non_local_def -#![warn(non_local_definitions)] - struct Test; trait Uto {} diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr index ed7bd56fe4a54..9f70119e0f8c9 100644 --- a/tests/ui/lint/non-local-defs/consts.stderr +++ b/tests/ui/lint/non-local-defs/consts.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:15:5 + --> $DIR/consts.rs:13:5 | LL | const Z: () = { | ----------- @@ -17,14 +17,10 @@ LL | impl Uto for &Test {} = 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/consts.rs:5:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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/consts.rs:26:5 + --> $DIR/consts.rs:24:5 | LL | static A: u32 = { | ------------- move the `impl` block outside of this static `A` @@ -40,7 +36,7 @@ LL | impl Uto2 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:34:5 + --> $DIR/consts.rs:32:5 | LL | const B: u32 = { | ------------ move the `impl` block outside of this constant `B` @@ -56,7 +52,7 @@ LL | impl Uto3 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:45:5 + --> $DIR/consts.rs:43:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -69,7 +65,7 @@ LL | impl Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:52:9 + --> $DIR/consts.rs:50:9 | LL | const { | ___________- @@ -88,7 +84,7 @@ LL | | }; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:61:9 + --> $DIR/consts.rs:59:9 | LL | const _: u32 = { | ------------ move the `impl` block outside of this constant `_` and up 2 bodies @@ -102,7 +98,7 @@ LL | impl Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:74:9 + --> $DIR/consts.rs:72:9 | LL | let _a = || { | -- move the `impl` block outside of this closure `` and up 2 bodies @@ -117,7 +113,7 @@ LL | impl Uto9 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:81:9 + --> $DIR/consts.rs:79:9 | LL | type A = [u32; { | ____________________- diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.rs b/tests/ui/lint/non-local-defs/exhaustive-trait.rs index 79f8cc4620b97..40d2314460f86 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.rs +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - struct Dog; fn main() { diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr index 24c9a6b4f01e2..67df0e31d5bdf 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:9:5 + --> $DIR/exhaustive-trait.rs:7:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -12,14 +12,10 @@ 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/exhaustive-trait.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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:16:5 + --> $DIR/exhaustive-trait.rs:14:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -35,7 +31,7 @@ LL | impl PartialEq<()> for &Dog { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:23:5 + --> $DIR/exhaustive-trait.rs:21:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -51,7 +47,7 @@ LL | impl PartialEq for () { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:30:5 + --> $DIR/exhaustive-trait.rs:28:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -67,7 +63,7 @@ LL | impl PartialEq<&Dog> for () { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:37:5 + --> $DIR/exhaustive-trait.rs:35:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -83,7 +79,7 @@ LL | impl PartialEq for &Dog { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:44:5 + --> $DIR/exhaustive-trait.rs:42:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` diff --git a/tests/ui/lint/non-local-defs/exhaustive.rs b/tests/ui/lint/non-local-defs/exhaustive.rs index f59a85c7ed94f..2fb30f4344abb 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.rs +++ b/tests/ui/lint/non-local-defs/exhaustive.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - use std::fmt::Display; trait Trait {} diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index 6d8c2ec0bc7cf..1e0d5caec3830 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:12:5 + --> $DIR/exhaustive.rs:10:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -10,14 +10,10 @@ LL | impl Test { | = 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 -note: the lint level is defined here - --> $DIR/exhaustive.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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:17:5 + --> $DIR/exhaustive.rs:15:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -33,7 +29,7 @@ LL | impl Display for Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:24:5 + --> $DIR/exhaustive.rs:22:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -47,7 +43,7 @@ LL | impl dyn Trait {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:27:5 + --> $DIR/exhaustive.rs:25:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -63,7 +59,7 @@ LL | impl Trait for Vec { } = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:30:5 + --> $DIR/exhaustive.rs:28:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -79,7 +75,7 @@ LL | impl Trait for &dyn Trait {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:33:5 + --> $DIR/exhaustive.rs:31:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -95,7 +91,7 @@ LL | impl Trait for *mut Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:36:5 + --> $DIR/exhaustive.rs:34:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -111,7 +107,7 @@ LL | impl Trait for *mut [Test] {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:39:5 + --> $DIR/exhaustive.rs:37:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -127,7 +123,7 @@ LL | impl Trait for [Test; 8] {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:42:5 + --> $DIR/exhaustive.rs:40:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -143,7 +139,7 @@ LL | impl Trait for (Test,) {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:45:5 + --> $DIR/exhaustive.rs:43:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -159,7 +155,7 @@ LL | impl Trait for fn(Test) -> () {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:48:5 + --> $DIR/exhaustive.rs:46:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -175,7 +171,7 @@ LL | impl Trait for fn() -> Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:52:9 + --> $DIR/exhaustive.rs:50:9 | LL | let _a = || { | -- move the `impl` block outside of this closure `` and up 2 bodies @@ -190,7 +186,7 @@ LL | impl Trait for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:60:5 + --> $DIR/exhaustive.rs:58:5 | LL | impl Trait for *mut InsideMain {} | ^^^^^-----^^^^^--------------- @@ -202,7 +198,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -212,7 +208,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:62:5 + --> $DIR/exhaustive.rs:60:5 | LL | impl Trait for *mut [InsideMain] {} | ^^^^^-----^^^^^----------------- @@ -223,7 +219,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -233,7 +229,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:64:5 + --> $DIR/exhaustive.rs:62:5 | LL | impl Trait for [InsideMain; 8] {} | ^^^^^-----^^^^^--------------- @@ -244,7 +240,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -254,7 +250,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:66:5 + --> $DIR/exhaustive.rs:64:5 | LL | impl Trait for (InsideMain,) {} | ^^^^^-----^^^^^------------- @@ -265,7 +261,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -275,7 +271,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:68:5 + --> $DIR/exhaustive.rs:66:5 | LL | impl Trait for fn(InsideMain) -> () {} | ^^^^^-----^^^^^-------------------- @@ -286,7 +282,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -296,7 +292,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:70:5 + --> $DIR/exhaustive.rs:68:5 | LL | impl Trait for fn() -> InsideMain {} | ^^^^^-----^^^^^------------------ @@ -307,7 +303,7 @@ 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:11:1 + --> $DIR/exhaustive.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -317,7 +313,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:74:9 + --> $DIR/exhaustive.rs:72:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies @@ -332,7 +328,7 @@ LL | impl Display for InsideMain { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:81:9 + --> $DIR/exhaustive.rs:79:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.rs b/tests/ui/lint/non-local-defs/from-local-for-global.rs index 1d8f4845c2860..fea9679d7375d 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.rs +++ b/tests/ui/lint/non-local-defs/from-local-for-global.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - struct Cat; struct Wrap(T); diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.stderr b/tests/ui/lint/non-local-defs/from-local-for-global.stderr index 04eba8435fc04..67fd937d134cc 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.stderr +++ b/tests/ui/lint/non-local-defs/from-local-for-global.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:10:5 + --> $DIR/from-local-for-global.rs:8:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -12,14 +12,10 @@ LL | impl From 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/from-local-for-global.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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/from-local-for-global.rs:20:5 + --> $DIR/from-local-for-global.rs:18:5 | LL | impl From>> for () { | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^-- @@ -29,7 +25,7 @@ LL | impl From>> 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 the `impl` block outside of this function `main` - --> $DIR/from-local-for-global.rs:9:1 + --> $DIR/from-local-for-global.rs:7:1 | LL | fn main() { | ^^^^^^^^^ @@ -39,7 +35,7 @@ LL | struct Elephant; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:34:5 + --> $DIR/from-local-for-global.rs:32:5 | LL | impl StillNonLocal for &Foo {} | ^^^^^-------------^^^^^---- @@ -51,7 +47,7 @@ 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 the `impl` block outside of this function `only_global` - --> $DIR/from-local-for-global.rs:32:1 + --> $DIR/from-local-for-global.rs:30:1 | LL | fn only_global() { | ^^^^^^^^^^^^^^^^ @@ -60,7 +56,7 @@ LL | struct Foo; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:42:5 + --> $DIR/from-local-for-global.rs:40:5 | LL | impl From for GlobalSameFunction { | ^^^^^----^^^^^^^^^^^^^------------------ @@ -71,7 +67,7 @@ LL | impl From 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 the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:40:1 + --> $DIR/from-local-for-global.rs:38:1 | LL | fn same_function() { | ^^^^^^^^^^^^^^^^^^ @@ -80,7 +76,7 @@ LL | struct Local1(GlobalSameFunction); = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:50:5 + --> $DIR/from-local-for-global.rs:48:5 | LL | impl From for GlobalSameFunction { | ^^^^^----^^^^^^^^^^^^^------------------ @@ -91,7 +87,7 @@ LL | impl From 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 the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:40:1 + --> $DIR/from-local-for-global.rs:38:1 | LL | fn same_function() { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/generics.rs b/tests/ui/lint/non-local-defs/generics.rs index 13e392c510c64..0f526526dba21 100644 --- a/tests/ui/lint/non-local-defs/generics.rs +++ b/tests/ui/lint/non-local-defs/generics.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - trait Global {} fn main() { diff --git a/tests/ui/lint/non-local-defs/generics.stderr b/tests/ui/lint/non-local-defs/generics.stderr index 35366ed8ecf94..ed2f87a4ed2d2 100644 --- a/tests/ui/lint/non-local-defs/generics.stderr +++ b/tests/ui/lint/non-local-defs/generics.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:11:5 + --> $DIR/generics.rs:9:5 | LL | impl Global for Vec { } | ^^^^^^^^^^^^^^^------^^^^^---^^^ @@ -10,21 +10,17 @@ LL | impl Global for Vec { } = 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 the `impl` block outside of this function `main` - --> $DIR/generics.rs:8:1 + --> $DIR/generics.rs:6:1 | 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 -note: the lint level is defined here - --> $DIR/generics.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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/generics.rs:22:5 + --> $DIR/generics.rs:20:5 | LL | impl Uto7 for Test where Local: std::any::Any {} | ^^^^^----^^^^^---- @@ -35,7 +31,7 @@ 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 the `impl` block outside of this function `bad` - --> $DIR/generics.rs:20:1 + --> $DIR/generics.rs:18:1 | LL | fn bad() { | ^^^^^^^^ @@ -44,7 +40,7 @@ LL | struct Local; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:25:5 + --> $DIR/generics.rs:23:5 | LL | fn bad() { | -------- move the `impl` block outside of this function `bad` @@ -60,7 +56,7 @@ LL | impl Uto8 for T {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:34:5 + --> $DIR/generics.rs:32:5 | LL | impl Default for UwU { | ^^^^^-------^^^^^---^^^^^ @@ -71,7 +67,7 @@ LL | impl Default for UwU { = 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 the `impl` block outside of this function `fun` - --> $DIR/generics.rs:31:1 + --> $DIR/generics.rs:29:1 | LL | fn fun() { | ^^^^^^^^ @@ -81,7 +77,7 @@ LL | struct OwO; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:45:5 + --> $DIR/generics.rs:43:5 | LL | impl AsRef for () { | ^^^^^-----^^^^^^^^^^-- @@ -92,7 +88,7 @@ LL | impl AsRef 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 the `impl` block outside of this function `meow` - --> $DIR/generics.rs:42:1 + --> $DIR/generics.rs:40:1 | LL | fn meow() { | ^^^^^^^^^ @@ -102,7 +98,7 @@ LL | struct Cat; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:56:5 + --> $DIR/generics.rs:54:5 | LL | impl PartialEq for G { | ^^^^^---------^^^^^^^^- @@ -113,7 +109,7 @@ LL | impl PartialEq 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 the `impl` block outside of this function `fun2` - --> $DIR/generics.rs:53:1 + --> $DIR/generics.rs:51:1 | LL | fn fun2() { | ^^^^^^^^^ @@ -123,7 +119,7 @@ LL | struct B; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:71:5 + --> $DIR/generics.rs:69:5 | LL | impl From>> for () { | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^-- @@ -133,7 +129,7 @@ LL | impl From>> 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 the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:68:1 + --> $DIR/generics.rs:66:1 | LL | fn rawr() { | ^^^^^^^^^ @@ -142,7 +138,7 @@ LL | struct Lion; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:78:5 + --> $DIR/generics.rs:76:5 | LL | impl From<()> for Wrap { | ^^^^^----^^^^^^^^^----^^^^^^ @@ -153,7 +149,7 @@ LL | impl From<()> for Wrap { = 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 the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:68:1 + --> $DIR/generics.rs:66:1 | LL | fn rawr() { | ^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/inside-macro_rules.rs b/tests/ui/lint/non-local-defs/inside-macro_rules.rs index 744a1f7a6f1ab..9f21cc89852e2 100644 --- a/tests/ui/lint/non-local-defs/inside-macro_rules.rs +++ b/tests/ui/lint/non-local-defs/inside-macro_rules.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - macro_rules! m { () => { trait MacroTrait {} diff --git a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr index 89835372c8a53..fa9ba2cb785d9 100644 --- a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr +++ b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/inside-macro_rules.rs:11:13 + --> $DIR/inside-macro_rules.rs:9:13 | LL | fn my_func() { | ------------ move the `impl` block outside of this function `my_func` @@ -16,11 +16,7 @@ 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/inside-macro_rules.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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) warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/local.rs b/tests/ui/lint/non-local-defs/local.rs index e9dbff1300f28..166ee88c0210c 100644 --- a/tests/ui/lint/non-local-defs/local.rs +++ b/tests/ui/lint/non-local-defs/local.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - use std::fmt::Debug; trait GlobalTrait {} diff --git a/tests/ui/lint/non-local-defs/macro_rules.rs b/tests/ui/lint/non-local-defs/macro_rules.rs index 20672cf0a3225..ed30a24903d01 100644 --- a/tests/ui/lint/non-local-defs/macro_rules.rs +++ b/tests/ui/lint/non-local-defs/macro_rules.rs @@ -3,8 +3,6 @@ //@ aux-build:non_local_macro.rs //@ rustc-env:CARGO_CRATE_NAME=non_local_def -#![warn(non_local_definitions)] - extern crate non_local_macro; const B: u32 = { diff --git a/tests/ui/lint/non-local-defs/macro_rules.stderr b/tests/ui/lint/non-local-defs/macro_rules.stderr index f9995bf82183c..4e86fc7b987e6 100644 --- a/tests/ui/lint/non-local-defs/macro_rules.stderr +++ b/tests/ui/lint/non-local-defs/macro_rules.stderr @@ -1,5 +1,5 @@ warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:12:5 + --> $DIR/macro_rules.rs:10:5 | LL | macro_rules! m0 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,14 +7,10 @@ LL | macro_rules! m0 { () => { } }; = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `B` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/macro_rules.rs:6:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(non_local_definitions)]` on by default warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:18:1 + --> $DIR/macro_rules.rs:16:1 | LL | non_local_macro::non_local_macro_rules!(my_macro); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +22,7 @@ LL | non_local_macro::non_local_macro_rules!(my_macro); = note: this warning originates in the macro `non_local_macro::non_local_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:23:5 + --> $DIR/macro_rules.rs:21:5 | LL | macro_rules! m { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +32,7 @@ LL | macro_rules! m { () => { } }; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:31:13 + --> $DIR/macro_rules.rs:29:13 | LL | macro_rules! m2 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs b/tests/ui/lint/non-local-defs/suggest-moving-inner.rs index 9360ace4d805b..61b32e5bad9fe 100644 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs +++ b/tests/ui/lint/non-local-defs/suggest-moving-inner.rs @@ -1,7 +1,5 @@ //@ check-pass -#![warn(non_local_definitions)] - trait Trait {} fn main() { diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr b/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr index a214415316f84..f0de0f72e74f6 100644 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr +++ b/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/suggest-moving-inner.rs:14:5 + --> $DIR/suggest-moving-inner.rs:12:5 | LL | impl Trait for &Vec> | ^^^^^^^^-----^^^^^^^^^^^^^^^^^---------------------------------- @@ -10,7 +10,7 @@ LL | impl Trait for &Vec> = 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 the `impl` block outside of this function `main` - --> $DIR/suggest-moving-inner.rs:7:1 + --> $DIR/suggest-moving-inner.rs:5:1 | LL | fn main() { | ^^^^^^^^^ @@ -23,11 +23,7 @@ LL | struct InsideMain; 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 -note: the lint level is defined here - --> $DIR/suggest-moving-inner.rs:3:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(non_local_definitions)]` on by default warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs index b726398bf9c9a..4291426e046a8 100644 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs +++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs @@ -3,8 +3,6 @@ // https://github.com/rust-lang/rust/issues/123573#issue-2229428739 -#![warn(non_local_definitions)] - pub trait Test {} impl<'a, T: 'a> Test for &[T] where &'a T: Test {} diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr index 2eb71cecacaaf..80930ce1bcdf3 100644 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr +++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/trait-solver-overflow-123573.rs:14:5 + --> $DIR/trait-solver-overflow-123573.rs:12:5 | LL | impl Test for &Local {} | ^^^^^----^^^^^------ @@ -11,18 +11,14 @@ 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 the `impl` block outside of this function `main` - --> $DIR/trait-solver-overflow-123573.rs:12:1 + --> $DIR/trait-solver-overflow-123573.rs:10:1 | 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 -note: the lint level is defined here - --> $DIR/trait-solver-overflow-123573.rs:6:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(non_local_definitions)]` on by default warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/weird-exprs.rs b/tests/ui/lint/non-local-defs/weird-exprs.rs index fbf1fd941eecb..1d9cecea0c971 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.rs +++ b/tests/ui/lint/non-local-defs/weird-exprs.rs @@ -1,8 +1,6 @@ //@ check-pass //@ edition:2021 -#![warn(non_local_definitions)] - trait Uto {} struct Test; diff --git a/tests/ui/lint/non-local-defs/weird-exprs.stderr b/tests/ui/lint/non-local-defs/weird-exprs.stderr index 49aba904ebb0e..cd414d636d34b 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.stderr +++ b/tests/ui/lint/non-local-defs/weird-exprs.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:10:5 + --> $DIR/weird-exprs.rs:8:5 | LL | type A = [u32; { | ________________- @@ -16,14 +16,10 @@ LL | | }]; = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -note: the lint level is defined here - --> $DIR/weird-exprs.rs:4:9 - | -LL | #![warn(non_local_definitions)] - | ^^^^^^^^^^^^^^^^^^^^^ + = 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:18:9 + --> $DIR/weird-exprs.rs:16:9 | LL | Discr = { | _____________- @@ -42,7 +38,7 @@ LL | | } = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:27:9 + --> $DIR/weird-exprs.rs:25:9 | LL | let _array = [0i32; { | _________________________- @@ -61,7 +57,7 @@ LL | | }]; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:36:9 + --> $DIR/weird-exprs.rs:34:9 | LL | type A = [u32; { | ____________________- @@ -80,7 +76,7 @@ LL | | }]; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:43:9 + --> $DIR/weird-exprs.rs:41:9 | LL | fn a(_: [u32; { | ___________________- @@ -99,7 +95,7 @@ LL | | }]) {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:50:9 + --> $DIR/weird-exprs.rs:48:9 | LL | fn b() -> [u32; { | _____________________- From 00a6ebfbf56d4d785f1950a1c342085963932794 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 9 Jul 2024 18:33:37 +0200 Subject: [PATCH 2/5] Rework `non_local_definitions` lint to only be a syntactic heuristic --- compiler/rustc_lint/messages.ftl | 3 - compiler/rustc_lint/src/lints.rs | 21 -- compiler/rustc_lint/src/non_local_def.rs | 239 ++---------------- tests/ui/lint/non-local-defs/exhaustive.rs | 7 +- .../ui/lint/non-local-defs/exhaustive.stderr | 133 +--------- .../non-local-defs/from-local-for-global.rs | 8 - .../from-local-for-global.stderr | 84 +----- tests/ui/lint/non-local-defs/generics.rs | 5 - tests/ui/lint/non-local-defs/generics.stderr | 124 +-------- ...suggest-moving-inner.rs => ref-complex.rs} | 1 - .../suggest-moving-inner.stderr | 29 --- .../trait-solver-overflow-123573.rs | 1 - .../trait-solver-overflow-123573.stderr | 24 -- 13 files changed, 36 insertions(+), 643 deletions(-) rename tests/ui/lint/non-local-defs/{suggest-moving-inner.rs => ref-complex.rs} (85%) delete mode 100644 tests/ui/lint/non-local-defs/suggest-moving-inner.stderr delete mode 100644 tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index e71c5676ce4f5..e17cb75d0269a 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -592,7 +592,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 lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks should be written at the same level as their item - .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` .bounds = `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 @@ -617,8 +616,6 @@ lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `# remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}` .non_local = a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute -lint_non_local_definitions_may_move = may need to be moved as well - lint_non_local_definitions_of_trait_not_local = `{$of_trait_str}` is not local lint_non_local_definitions_self_ty_not_local = `{$self_ty_str}` is not local diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 76002cc842581..1f54505f87313 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1375,9 +1375,7 @@ pub(crate) enum NonLocalDefinitionsDiag { body_name: String, cargo_update: Option, const_anon: Option>, - move_to: Option<(Span, Vec)>, doctest: bool, - may_remove: Option<(Span, String)>, has_trait: bool, self_ty_str: String, of_trait_str: Option, @@ -1401,9 +1399,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { body_name, cargo_update, const_anon, - move_to, doctest, - may_remove, has_trait, self_ty_str, of_trait_str, @@ -1434,27 +1430,10 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { diag.note(fluent::lint_without_trait); } - 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); - } if doctest { diag.help(fluent::lint_doctest); } - if let Some((span, part)) = may_remove { - diag.arg("may_remove_part", part); - diag.span_suggestion( - span, - fluent::lint_remove_help, - "", - Applicability::MaybeIncorrect, - ); - } - if let Some(const_anon) = const_anon { diag.note(fluent::lint_exception); if let Some(const_anon) = const_anon { diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 3177a3c6749ef..5fe39e8be4690 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -2,19 +2,11 @@ use rustc_errors::MultiSpan; use rustc_hir::def::DefKind; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, QPath, TyKind}; -use rustc_infer::infer::InferCtxt; -use rustc_infer::traits::{Obligation, ObligationCause}; -use rustc_middle::ty::{ - self, Binder, EarlyBinder, TraitRef, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, -}; +use rustc_middle::ty::TyCtxt; use rustc_session::{declare_lint, impl_lint_pass}; use rustc_span::def_id::{DefId, LOCAL_CRATE}; use rustc_span::symbol::kw; -use rustc_span::{ExpnKind, MacroKind, Span, Symbol, sym}; -use rustc_trait_selection::error_reporting::traits::ambiguity::{ - CandidateSource, compute_applicable_impls_for_diagnostics, -}; -use rustc_trait_selection::infer::TyCtxtInferExt; +use rustc_span::{ExpnKind, MacroKind, Span, Symbol, sym, sym}; use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag}; use crate::{LateContext, LateLintPass, LintContext, fluent_generated as fluent}; @@ -142,42 +134,22 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { None }; - // Part 1: Is the Self type local? - let self_ty_has_local_parent = - ty_has_local_parent(&impl_.self_ty.kind, cx, parent, parent_parent); - - if self_ty_has_local_parent { - return; - } - - // Part 2: Is the Trait local? - let of_trait_has_local_parent = impl_ - .of_trait - .map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent)) - .unwrap_or(false); - - if of_trait_has_local_parent { - return; + // 1. We collect all the `hir::Path` from the `Self` type and `Trait` ref + // of the `impl` definition + let mut collector = PathCollector { paths: Vec::new() }; + collector.visit_ty(&impl_.self_ty); + if let Some(of_trait) = &impl_.of_trait { + collector.visit_trait_ref(of_trait); } - // Part 3: Is the impl definition leaking outside it's defining scope? - // - // We always consider inherent impls to be leaking. - let impl_has_enough_non_local_candidates = cx - .tcx - .impl_trait_ref(def_id) - .map(|binder| { - impl_trait_ref_has_enough_non_local_candidates( - cx.tcx, - item.span, - def_id, - binder, - |did| did_has_local_parent(did, cx.tcx, parent, parent_parent), - ) - }) - .unwrap_or(false); - - if impl_has_enough_non_local_candidates { + // 2. We check if any of path reference a "local" parent and if that the case + // we bail out as asked by T-lang, even though this isn't correct from a + // type-system point of view, as inference exists and could still leak the impl. + if collector + .paths + .iter() + .any(|path| path_has_local_parent(path, cx, parent, parent_parent)) + { return; } @@ -199,18 +171,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { let const_anon = matches!(parent_def_kind, DefKind::Const | DefKind::Static { .. }) .then_some(span_for_const_anon_suggestion); - let may_remove = match &impl_.self_ty.kind { - TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) - if ty_has_local_parent(&mut_ty.ty.kind, cx, parent, parent_parent) => - { - let type_ = - if matches!(impl_.self_ty.kind, TyKind::Ptr(_)) { "*" } else { "&" }; - let part = format!("{}{}", type_, mut_ty.mutbl.prefix_str()); - Some((impl_.self_ty.span.shrink_to_lo().until(mut_ty.ty.span), part)) - } - _ => None, - }; - let impl_span = item.span.shrink_to_lo().to(impl_.self_ty.span); let mut ms = MultiSpan::from_span(impl_span); @@ -221,6 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { self_ty_span, fluent::lint_non_local_definitions_self_ty_not_local, ); + let of_trait_str = if let Some(of_trait) = &impl_.of_trait { ms.push_span_label( path_span_without_args(&of_trait.path), @@ -231,44 +192,14 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { None }; - let (doctest, move_to) = if is_at_toplevel_doctest() { - (true, None) - } else { - let mut collector = PathCollector { paths: Vec::new() }; - collector.visit_ty(&impl_.self_ty); - if let Some(of_trait) = &impl_.of_trait { - collector.visit_trait_ref(of_trait); - } - collector.visit_generics(&impl_.generics); - - let mut may_move: Vec = collector - .paths - .into_iter() - .filter_map(|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 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)) - }; + let doctest = is_at_toplevel_doctest(); - (false, move_to) - }; + if !doctest { + ms.push_span_label( + cx.tcx.def_span(parent), + fluent::lint_non_local_definitions_impl_move_help, + ); + } let macro_to_change = if let ExpnKind::Macro(kind, name) = item.span.ctxt().outer_expn_data().kind { @@ -287,9 +218,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { const_anon, self_ty_str, of_trait_str, - move_to, doctest, - may_remove, has_trait: impl_.of_trait.is_some(), macro_to_change, }) @@ -316,90 +245,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { } } -// Detecting if the impl definition is leaking outside of its defining scope. -// -// Rule: for each impl, instantiate all local types with inference vars and -// then assemble candidates for that goal, if there are more than 1 (non-private -// impls), it does not leak. -// -// https://github.com/rust-lang/rust/issues/121621#issuecomment-1976826895 -fn impl_trait_ref_has_enough_non_local_candidates<'tcx>( - tcx: TyCtxt<'tcx>, - infer_span: Span, - trait_def_id: DefId, - binder: EarlyBinder<'tcx, TraitRef<'tcx>>, - mut did_has_local_parent: impl FnMut(DefId) -> bool, -) -> bool { - let infcx = tcx - .infer_ctxt() - // We use the new trait solver since the obligation we are trying to - // prove here may overflow and those are fatal in the old trait solver. - // Which is unacceptable for a lint. - // - // Thanksfully the part we use here are very similar to the - // new-trait-solver-as-coherence, which is in stabilization. - // - // https://github.com/rust-lang/rust/issues/123573 - .with_next_trait_solver(true) - .build(); - - let trait_ref = binder.instantiate(tcx, infcx.fresh_args_for_item(infer_span, trait_def_id)); - - let trait_ref = trait_ref.fold_with(&mut ReplaceLocalTypesWithInfer { - infcx: &infcx, - infer_span, - did_has_local_parent: &mut did_has_local_parent, - }); - - let poly_trait_obligation = Obligation::new( - tcx, - ObligationCause::dummy(), - ty::ParamEnv::empty(), - Binder::dummy(trait_ref), - ); - - let ambiguities = compute_applicable_impls_for_diagnostics(&infcx, &poly_trait_obligation); - - let mut it = ambiguities.iter().filter(|ambi| match ambi { - CandidateSource::DefId(did) => !did_has_local_parent(*did), - CandidateSource::ParamEnv(_) => unreachable!(), - }); - - let _ = it.next(); - it.next().is_some() -} - -/// Replace every local type by inference variable. -/// -/// ```text -/// as std::cmp::PartialEq>> -/// to -/// as std::cmp::PartialEq>> -/// ``` -struct ReplaceLocalTypesWithInfer<'a, 'tcx, F: FnMut(DefId) -> bool> { - infcx: &'a InferCtxt<'tcx>, - did_has_local_parent: F, - infer_span: Span, -} - -impl<'a, 'tcx, F: FnMut(DefId) -> bool> TypeFolder> - for ReplaceLocalTypesWithInfer<'a, 'tcx, F> -{ - fn cx(&self) -> TyCtxt<'tcx> { - self.infcx.tcx - } - - fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let Some(def) = t.ty_adt_def() - && (self.did_has_local_parent)(def.did()) - { - self.infcx.next_ty_var(self.infer_span) - } else { - t.super_fold_with(self) - } - } -} - /// Simple hir::Path collector struct PathCollector<'tcx> { paths: Vec>, @@ -412,42 +257,6 @@ impl<'tcx> Visitor<'tcx> for PathCollector<'tcx> { } } -/// Given a `Ty` we check if the (outermost) type is local. -fn ty_has_local_parent( - ty_kind: &TyKind<'_>, - cx: &LateContext<'_>, - impl_parent: DefId, - impl_parent_parent: Option, -) -> bool { - match ty_kind { - TyKind::Path(QPath::Resolved(_, ty_path)) => { - path_has_local_parent(ty_path, cx, impl_parent, impl_parent_parent) - } - TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => path_has_local_parent( - principle_poly_trait_ref.0.trait_ref.path, - cx, - impl_parent, - impl_parent_parent, - ), - TyKind::TraitObject([], _, _) - | TyKind::InferDelegation(_, _) - | TyKind::Slice(_) - | TyKind::Array(_, _) - | TyKind::Ptr(_) - | TyKind::Ref(_, _) - | TyKind::BareFn(_) - | TyKind::Never - | TyKind::Tup(_) - | TyKind::Path(_) - | TyKind::Pat(..) - | TyKind::AnonAdt(_) - | TyKind::OpaqueDef(_, _, _) - | TyKind::Typeof(_) - | TyKind::Infer - | TyKind::Err(_) => false, - } -} - /// Given a path and a parent impl def id, this checks if the if parent resolution /// def id correspond to the def id of the parent impl definition. /// diff --git a/tests/ui/lint/non-local-defs/exhaustive.rs b/tests/ui/lint/non-local-defs/exhaustive.rs index 2fb30f4344abb..5036e427060fc 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.rs +++ b/tests/ui/lint/non-local-defs/exhaustive.rs @@ -55,18 +55,13 @@ fn main() { struct InsideMain; + impl Trait for &InsideMain {} impl Trait for *mut InsideMain {} - //~^ WARN non-local `impl` definition impl Trait for *mut [InsideMain] {} - //~^ WARN non-local `impl` definition impl Trait for [InsideMain; 8] {} - //~^ WARN non-local `impl` definition impl Trait for (InsideMain,) {} - //~^ WARN non-local `impl` definition impl Trait for fn(InsideMain) -> () {} - //~^ WARN non-local `impl` definition impl Trait for fn() -> InsideMain {} - //~^ WARN non-local `impl` definition fn inside_inside() { impl Display for InsideMain { diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index 1e0d5caec3830..6dff48e9a3654 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -186,134 +186,7 @@ LL | impl Trait for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:58:5 - | -LL | impl Trait for *mut InsideMain {} - | ^^^^^-----^^^^^--------------- - | | | - | | `*mut InsideMain` is not local - | | help: remove `*mut ` to make the `impl` local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:60:5 - | -LL | impl Trait for *mut [InsideMain] {} - | ^^^^^-----^^^^^----------------- - | | | - | | `*mut [InsideMain]` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:62:5 - | -LL | impl Trait for [InsideMain; 8] {} - | ^^^^^-----^^^^^--------------- - | | | - | | `[InsideMain; 8]` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:64:5 - | -LL | impl Trait for (InsideMain,) {} - | ^^^^^-----^^^^^------------- - | | | - | | `(InsideMain,)` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:66:5 - | -LL | impl Trait for fn(InsideMain) -> () {} - | ^^^^^-----^^^^^-------------------- - | | | - | | `fn(: InsideMain) -> ()` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:68:5 - | -LL | impl Trait for fn() -> InsideMain {} - | ^^^^^-----^^^^^------------------ - | | | - | | `fn() -> InsideMain` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:72:9 + --> $DIR/exhaustive.rs:67:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies @@ -328,7 +201,7 @@ LL | impl Display for InsideMain { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:79:9 + --> $DIR/exhaustive.rs:74:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies @@ -341,5 +214,5 @@ LL | impl InsideMain { = 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 -warning: 20 warnings emitted +warning: 14 warnings emitted diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.rs b/tests/ui/lint/non-local-defs/from-local-for-global.rs index fea9679d7375d..6654fcc4f23d7 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.rs +++ b/tests/ui/lint/non-local-defs/from-local-for-global.rs @@ -16,7 +16,6 @@ fn main() { struct Elephant; impl From>> for () { - //~^ WARN non-local `impl` definition fn from(_: Wrap>) -> Self { todo!() } @@ -30,7 +29,6 @@ impl StillNonLocal for &str {} fn only_global() { struct Foo; impl StillNonLocal for &Foo {} - //~^ WARN non-local `impl` definition } struct GlobalSameFunction; @@ -38,7 +36,6 @@ struct GlobalSameFunction; fn same_function() { struct Local1(GlobalSameFunction); impl From for GlobalSameFunction { - //~^ WARN non-local `impl` definition fn from(x: Local1) -> GlobalSameFunction { x.0 } @@ -46,7 +43,6 @@ fn same_function() { struct Local2(GlobalSameFunction); impl From for GlobalSameFunction { - //~^ WARN non-local `impl` definition fn from(x: Local2) -> GlobalSameFunction { x.0 } @@ -59,8 +55,6 @@ fn diff_function_1() { struct Local(GlobalDifferentFunction); impl From for GlobalDifferentFunction { - // FIXME(Urgau): Should warn but doesn't since we currently consider - // the other impl to be "global", but that's not the case for the type-system fn from(x: Local) -> GlobalDifferentFunction { x.0 } @@ -71,8 +65,6 @@ fn diff_function_2() { struct Local(GlobalDifferentFunction); impl From for GlobalDifferentFunction { - // FIXME(Urgau): Should warn but doesn't since we currently consider - // the other impl to be "global", but that's not the case for the type-system fn from(x: Local) -> GlobalDifferentFunction { x.0 } diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.stderr b/tests/ui/lint/non-local-defs/from-local-for-global.stderr index 67fd937d134cc..0d6e29d43cd93 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.stderr +++ b/tests/ui/lint/non-local-defs/from-local-for-global.stderr @@ -14,87 +14,5 @@ LL | impl From for () { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = 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/from-local-for-global.rs:18:5 - | -LL | impl From>> for () { - | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^-- - | | | - | `From` is not local `()` is not 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 the `impl` block outside of this function `main` - --> $DIR/from-local-for-global.rs:7:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:32:5 - | -LL | impl StillNonLocal for &Foo {} - | ^^^^^-------------^^^^^---- - | | | - | | `&'_ Foo` is not local - | | help: remove `&` to make the `impl` local - | `StillNonLocal` is not 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 the `impl` block outside of this function `only_global` - --> $DIR/from-local-for-global.rs:30:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:40:5 - | -LL | impl From for GlobalSameFunction { - | ^^^^^----^^^^^^^^^^^^^------------------ - | | | - | | `GlobalSameFunction` is not local - | `From` is not 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 the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:38:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:48:5 - | -LL | impl From for GlobalSameFunction { - | ^^^^^----^^^^^^^^^^^^^------------------ - | | | - | | `GlobalSameFunction` is not local - | `From` is not 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 the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:38:1 - | -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 - -warning: 5 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/generics.rs b/tests/ui/lint/non-local-defs/generics.rs index 0f526526dba21..381b3caacb6b5 100644 --- a/tests/ui/lint/non-local-defs/generics.rs +++ b/tests/ui/lint/non-local-defs/generics.rs @@ -30,7 +30,6 @@ fn fun() { #[derive(Debug)] struct OwO; impl Default for UwU { - //~^ WARN non-local `impl` definition fn default() -> Self { UwU(OwO) } @@ -41,7 +40,6 @@ fn meow() { #[derive(Debug)] struct Cat; impl AsRef for () { - //~^ WARN non-local `impl` definition fn as_ref(&self) -> &Cat { &Cat } } } @@ -52,7 +50,6 @@ fn fun2() { #[derive(Debug, Default)] struct B; impl PartialEq for G { - //~^ WARN non-local `impl` definition fn eq(&self, _: &B) -> bool { true } @@ -67,14 +64,12 @@ fn rawr() { struct Lion; impl From>> for () { - //~^ WARN non-local `impl` definition fn from(_: Wrap>) -> Self { todo!() } } impl From<()> for Wrap { - //~^ WARN non-local `impl` definition fn from(_: ()) -> Self { todo!() } diff --git a/tests/ui/lint/non-local-defs/generics.stderr b/tests/ui/lint/non-local-defs/generics.stderr index ed2f87a4ed2d2..32324c3ab1606 100644 --- a/tests/ui/lint/non-local-defs/generics.stderr +++ b/tests/ui/lint/non-local-defs/generics.stderr @@ -1,6 +1,9 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> $DIR/generics.rs:9:5 | +LL | fn main() { + | --------- move the `impl` block outside of this function `main` +... LL | impl Global for Vec { } | ^^^^^^^^^^^^^^^------^^^^^---^^^ | | | @@ -9,19 +12,15 @@ LL | impl Global for Vec { } | = 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 the `impl` block outside of this function `main` - --> $DIR/generics.rs:6:1 - | -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 = 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/generics.rs:20:5 | +LL | fn bad() { + | -------- move the `impl` block outside of this function `bad` +LL | struct Local; LL | impl Uto7 for Test where Local: std::any::Any {} | ^^^^^----^^^^^---- | | | @@ -30,13 +29,6 @@ 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 the `impl` block outside of this function `bad` - --> $DIR/generics.rs:18:1 - | -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 warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item @@ -55,107 +47,5 @@ LL | impl Uto8 for T {} = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:32:5 - | -LL | impl Default for UwU { - | ^^^^^-------^^^^^---^^^^^ - | | | - | | `UwU` is not local - | `Default` is not 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 the `impl` block outside of this function `fun` - --> $DIR/generics.rs:29:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:43:5 - | -LL | impl AsRef for () { - | ^^^^^-----^^^^^^^^^^-- - | | | - | | `()` is not local - | `AsRef` is not 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 the `impl` block outside of this function `meow` - --> $DIR/generics.rs:40:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:54:5 - | -LL | impl PartialEq for G { - | ^^^^^---------^^^^^^^^- - | | | - | | `G` is not local - | `PartialEq` is not 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 the `impl` block outside of this function `fun2` - --> $DIR/generics.rs:51:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:69:5 - | -LL | impl From>> for () { - | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^-- - | | | - | `From` is not local `()` is not 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 the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:66:1 - | -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 - -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:76:5 - | -LL | impl From<()> for Wrap { - | ^^^^^----^^^^^^^^^----^^^^^^ - | | | - | | `Wrap` is not local - | `From` is not 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 the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:66:1 - | -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 - -warning: 8 warnings emitted +warning: 3 warnings emitted diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs b/tests/ui/lint/non-local-defs/ref-complex.rs similarity index 85% rename from tests/ui/lint/non-local-defs/suggest-moving-inner.rs rename to tests/ui/lint/non-local-defs/ref-complex.rs index 61b32e5bad9fe..ce4e0a3dc0a19 100644 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs +++ b/tests/ui/lint/non-local-defs/ref-complex.rs @@ -10,7 +10,6 @@ fn main() { trait HasFoo {} impl Trait for &Vec> - //~^ WARN non-local `impl` definition where T: HasFoo {} diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr b/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr deleted file mode 100644 index f0de0f72e74f6..0000000000000 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr +++ /dev/null @@ -1,29 +0,0 @@ -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/suggest-moving-inner.rs:12:5 - | -LL | impl Trait for &Vec> - | ^^^^^^^^-----^^^^^^^^^^^^^^^^^---------------------------------- - | | | - | | `&'_ Vec>` is not local - | `Trait` is not 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 the `impl` block outside of this function `main` - --> $DIR/suggest-moving-inner.rs:5:1 - | -LL | fn main() { - | ^^^^^^^^^ -LL | mod below { -LL | pub struct Type(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 - = note: `#[warn(non_local_definitions)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs index 4291426e046a8..6e8014f10f85a 100644 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs +++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs @@ -10,5 +10,4 @@ impl<'a, T: 'a> Test for &[T] where &'a T: Test {} fn main() { struct Local {} impl Test for &Local {} - //~^ WARN non-local `impl` definition } diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr deleted file mode 100644 index 80930ce1bcdf3..0000000000000 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr +++ /dev/null @@ -1,24 +0,0 @@ -warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/trait-solver-overflow-123573.rs:12:5 - | -LL | impl Test for &Local {} - | ^^^^^----^^^^^------ - | | | - | | `&'_ Local` is not local - | | help: remove `&` to make the `impl` local - | `Test` is not 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 the `impl` block outside of this function `main` - --> $DIR/trait-solver-overflow-123573.rs:10:1 - | -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 - = note: `#[warn(non_local_definitions)]` on by default - -warning: 1 warning emitted - From 0f665e2bf329aafdfe4b4152be86680929b9abf0 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 28 Jun 2024 14:00:14 +0200 Subject: [PATCH 3/5] Point to every relevant types in the main diag --- compiler/rustc_lint/messages.ftl | 4 -- compiler/rustc_lint/src/lints.rs | 8 --- compiler/rustc_lint/src/non_local_def.rs | 72 +++++-------------- tests/ui/lint/non-local-defs/consts.stderr | 6 +- .../non-local-defs/exhaustive-trait.stderr | 32 +++++---- .../ui/lint/non-local-defs/exhaustive.stderr | 42 +++++------ .../from-local-for-global.stderr | 6 +- tests/ui/lint/non-local-defs/generics.stderr | 5 +- .../ui/lint/non-local-defs/weird-exprs.stderr | 25 +++---- 9 files changed, 76 insertions(+), 124 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index e17cb75d0269a..d329deff2ba6e 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -616,10 +616,6 @@ lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `# remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}` .non_local = a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute -lint_non_local_definitions_of_trait_not_local = `{$of_trait_str}` is not local - -lint_non_local_definitions_self_ty_not_local = `{$self_ty_str}` is not local - lint_non_snake_case = {$sort} `{$name}` should have a snake case name .rename_or_convert_suggestion = rename the identifier or convert it to a snake case raw identifier .cannot_convert_note = `{$sc}` cannot be used as a raw identifier diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 1f54505f87313..dc53349cdf2b3 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1377,8 +1377,6 @@ pub(crate) enum NonLocalDefinitionsDiag { const_anon: Option>, doctest: bool, has_trait: bool, - self_ty_str: String, - of_trait_str: Option, macro_to_change: Option<(String, &'static str)>, }, MacroRules { @@ -1401,18 +1399,12 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { const_anon, doctest, has_trait, - self_ty_str, - of_trait_str, macro_to_change, } => { diag.primary_message(fluent::lint_non_local_definitions_impl); diag.arg("depth", depth); diag.arg("body_kind_descr", body_kind_descr); diag.arg("body_name", body_name); - diag.arg("self_ty_str", self_ty_str); - if let Some(of_trait_str) = of_trait_str { - diag.arg("of_trait_str", of_trait_str); - } if let Some((macro_to_change, macro_kind)) = macro_to_change { diag.arg("macro_to_change", macro_to_change); diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 5fe39e8be4690..48246598452d5 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -1,12 +1,12 @@ use rustc_errors::MultiSpan; -use rustc_hir::def::DefKind; +use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, QPath, TyKind}; +use rustc_hir::{Body, HirId, Item, ItemKind, Node, Path, TyKind}; use rustc_middle::ty::TyCtxt; use rustc_session::{declare_lint, impl_lint_pass}; use rustc_span::def_id::{DefId, LOCAL_CRATE}; use rustc_span::symbol::kw; -use rustc_span::{ExpnKind, MacroKind, Span, Symbol, sym, sym}; +use rustc_span::{ExpnKind, MacroKind, Span, sym}; use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag}; use crate::{LateContext, LateLintPass, LintContext, fluent_generated as fluent}; @@ -142,6 +142,12 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { collector.visit_trait_ref(of_trait); } + // 1.5. Remove any path that doesn't resolve to a `DefId` or if it resolve to a + // type-param (e.g. `T`). + collector.paths.retain( + |p| matches!(p.res, Res::Def(def_kind, _) if def_kind != DefKind::TyParam), + ); + // 2. We check if any of path reference a "local" parent and if that the case // we bail out as asked by T-lang, even though this isn't correct from a // type-system point of view, as inference exists and could still leak the impl. @@ -174,23 +180,16 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { let impl_span = item.span.shrink_to_lo().to(impl_.self_ty.span); let mut ms = MultiSpan::from_span(impl_span); - let (self_ty_span, self_ty_str) = - self_ty_kind_for_diagnostic(&impl_.self_ty, cx.tcx); - - ms.push_span_label( - self_ty_span, - fluent::lint_non_local_definitions_self_ty_not_local, - ); - - let of_trait_str = if let Some(of_trait) = &impl_.of_trait { + for path in &collector.paths { + // FIXME: While a translatable diagnostic message can have an argument + // we (currently) have no way to set different args per diag msg with + // `MultiSpan::push_span_label`. + #[allow(rustc::untranslatable_diagnostic)] ms.push_span_label( - path_span_without_args(&of_trait.path), - fluent::lint_non_local_definitions_of_trait_not_local, + path_span_without_args(path), + format!("`{}` is not local", path_name_to_string(path)), ); - Some(path_name_to_string(&of_trait.path)) - } else { - None - }; + } let doctest = is_at_toplevel_doctest(); @@ -216,8 +215,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { .unwrap_or_else(|| "".to_string()), cargo_update: cargo_update(), const_anon, - self_ty_str, - of_trait_str, doctest, has_trait: impl_.of_trait.is_some(), macro_to_change, @@ -312,38 +309,3 @@ fn path_span_without_args(path: &Path<'_>) -> Span { fn path_name_to_string(path: &Path<'_>) -> String { path.segments.last().unwrap().ident.name.to_ident_string() } - -/// Compute the `Span` and visual representation for the `Self` we want to point at; -/// It follows part of the actual logic of non-local, and if possible return the least -/// amount possible for the span and representation. -fn self_ty_kind_for_diagnostic(ty: &rustc_hir::Ty<'_>, tcx: TyCtxt<'_>) -> (Span, String) { - match ty.kind { - TyKind::Path(QPath::Resolved(_, ty_path)) => ( - path_span_without_args(ty_path), - ty_path - .res - .opt_def_id() - .map(|did| tcx.opt_item_name(did)) - .flatten() - .as_ref() - .map(|s| Symbol::as_str(s)) - .unwrap_or("") - .to_string(), - ), - TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => { - let path = &principle_poly_trait_ref.0.trait_ref.path; - ( - path_span_without_args(path), - path.res - .opt_def_id() - .map(|did| tcx.opt_item_name(did)) - .flatten() - .as_ref() - .map(|s| Symbol::as_str(s)) - .unwrap_or("") - .to_string(), - ) - } - _ => (ty.span, rustc_hir_pretty::ty_to_string(&tcx, ty)), - } -} diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr index 9f70119e0f8c9..2b70d1e9f3205 100644 --- a/tests/ui/lint/non-local-defs/consts.stderr +++ b/tests/ui/lint/non-local-defs/consts.stderr @@ -8,9 +8,9 @@ LL | const Z: () = { | move the `impl` block outside of this constant `Z` ... LL | impl Uto for &Test {} - | ^^^^^---^^^^^----- - | | | - | | `&'_ Test` is not local + | ^^^^^---^^^^^^---- + | | | + | | `Test` is not local | `Uto` is not 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 diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr index 67df0e31d5bdf..3b198f9b52a17 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr @@ -21,9 +21,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl PartialEq<()> for &Dog { - | ^^^^^---------^^^^^^^^^---- - | | | - | | `&'_ Dog` is not local + | ^^^^^---------^^^^^^^^^^--- + | | | + | | `Dog` is not local | `PartialEq` is not 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 @@ -37,9 +37,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl PartialEq for () { - | ^^^^^---------^^^^^^^^^^-- - | | | - | | `()` is not local + | ^^^^^---------^---^^^^^^^^ + | | | + | | `Dog` is not local | `PartialEq` is not 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 @@ -53,9 +53,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl PartialEq<&Dog> for () { - | ^^^^^---------^^^^^^^^^^^-- - | | | - | | `()` is not local + | ^^^^^---------^^---^^^^^^^^ + | | | + | | `Dog` is not local | `PartialEq` is not 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 @@ -69,9 +69,10 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl PartialEq for &Dog { - | ^^^^^---------^^^^^^^^^^---- - | | | - | | `&'_ Dog` is not local + | ^^^^^---------^---^^^^^^^--- + | | | | + | | | `Dog` is not local + | | `Dog` is not local | `PartialEq` is not 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 @@ -85,9 +86,10 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl PartialEq<&Dog> for &Dog { - | ^^^^^---------^^^^^^^^^^^---- - | | | - | | `&'_ Dog` is not local + | ^^^^^---------^^---^^^^^^^--- + | | | | + | | | `Dog` is not local + | | `Dog` is not local | `PartialEq` is not 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 diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index 6dff48e9a3654..c545d975014dc 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -65,9 +65,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for &dyn Trait {} - | ^^^^^-----^^^^^---------- - | | | - | | `&'_ dyn Trait` is not local + | ^^^^^-----^^^^^^^^^^----- + | | | + | | `Trait` is not local | `Trait` is not 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 @@ -81,9 +81,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for *mut Test {} - | ^^^^^-----^^^^^--------- - | | | - | | `*mut Test` is not local + | ^^^^^-----^^^^^^^^^^---- + | | | + | | `Test` is not local | `Trait` is not 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 @@ -97,9 +97,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for *mut [Test] {} - | ^^^^^-----^^^^^----------- - | | | - | | `*mut [Test]` is not local + | ^^^^^-----^^^^^^^^^^^----^ + | | | + | | `Test` is not local | `Trait` is not 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 @@ -113,9 +113,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for [Test; 8] {} - | ^^^^^-----^^^^^--------- - | | | - | | `[Test; 8]` is not local + | ^^^^^-----^^^^^^----^^^^ + | | | + | | `Test` is not local | `Trait` is not 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 @@ -129,9 +129,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for (Test,) {} - | ^^^^^-----^^^^^------- - | | | - | | `(Test,)` is not local + | ^^^^^-----^^^^^^----^^ + | | | + | | `Test` is not local | `Trait` is not 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 @@ -145,9 +145,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for fn(Test) -> () {} - | ^^^^^-----^^^^^-------------- - | | | - | | `fn(: Test) -> ()` is not local + | ^^^^^-----^^^^^^^^----^^^^^^^ + | | | + | | `Test` is not local | `Trait` is not 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 @@ -161,9 +161,9 @@ LL | fn main() { | --------- move the `impl` block outside of this function `main` ... LL | impl Trait for fn() -> Test {} - | ^^^^^-----^^^^^------------ - | | | - | | `fn() -> Test` is not local + | ^^^^^-----^^^^^^^^^^^^^---- + | | | + | | `Test` is not local | `Trait` is not 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 diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.stderr b/tests/ui/lint/non-local-defs/from-local-for-global.stderr index 0d6e29d43cd93..355cd6fbdcc44 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.stderr +++ b/tests/ui/lint/non-local-defs/from-local-for-global.stderr @@ -4,9 +4,9 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | fn main() { | --------- move the `impl` block outside of this function `main` LL | impl From for () { - | ^^^^^----^^^^^^^^^^-- - | | | - | | `()` is not local + | ^^^^^----^---^^^^^^^^ + | | | + | | `Cat` is not local | `From` is not 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 diff --git a/tests/ui/lint/non-local-defs/generics.stderr b/tests/ui/lint/non-local-defs/generics.stderr index 32324c3ab1606..a4ceae4ed31a6 100644 --- a/tests/ui/lint/non-local-defs/generics.stderr +++ b/tests/ui/lint/non-local-defs/generics.stderr @@ -38,9 +38,8 @@ LL | fn bad() { | -------- move the `impl` block outside of this function `bad` ... LL | impl Uto8 for T {} - | ^^^^^^^^----^^^^^- - | | | - | | `T` is not local + | ^^^^^^^^----^^^^^^ + | | | `Uto8` is not 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 diff --git a/tests/ui/lint/non-local-defs/weird-exprs.stderr b/tests/ui/lint/non-local-defs/weird-exprs.stderr index cd414d636d34b..2441ca41895d9 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.stderr +++ b/tests/ui/lint/non-local-defs/weird-exprs.stderr @@ -4,9 +4,9 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | type A = [u32; { | ________________- LL | | impl Uto for *mut Test {} - | | ^^^^^---^^^^^--------- - | | | | - | | | `*mut Test` is not local + | | ^^^^^---^^^^^^^^^^---- + | | | | + | | | `Test` is not local | | `Uto` is not local LL | | ... | @@ -62,9 +62,9 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | type A = [u32; { | ____________________- LL | | impl Uto for &Test {} - | | ^^^^^---^^^^^----- - | | | | - | | | `&'_ Test` is not local + | | ^^^^^---^^^^^^---- + | | | | + | | | `Test` is not local | | `Uto` is not local LL | | ... | @@ -81,9 +81,9 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | fn a(_: [u32; { | ___________________- LL | | impl Uto for &(Test,) {} - | | ^^^^^---^^^^^-------- - | | | | - | | | `&'_ (Test,)` is not local + | | ^^^^^---^^^^^^^----^^ + | | | | + | | | `Test` is not local | | `Uto` is not local LL | | ... | @@ -100,9 +100,10 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | fn b() -> [u32; { | _____________________- LL | | impl Uto for &(Test,Test) {} - | | ^^^^^---^^^^^------------ - | | | | - | | | `&'_ (Test, Test)` is not local + | | ^^^^^---^^^^^^^----^----^ + | | | | | + | | | | `Test` is not local + | | | `Test` is not local | | `Uto` is not local LL | | ... | From 9195d65725139f8415e223ee2488ae7347305e56 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 28 Jun 2024 14:28:50 +0200 Subject: [PATCH 4/5] Remove with/without trait and bounds consideration --- compiler/rustc_lint/messages.ftl | 4 +--- compiler/rustc_lint/src/lints.rs | 9 +-------- compiler/rustc_lint/src/non_local_def.rs | 1 - .../ui/lint/non-local-defs/cargo-update.stderr | 1 - tests/ui/lint/non-local-defs/consts.stderr | 11 +++-------- .../lint/non-local-defs/exhaustive-trait.stderr | 6 ------ tests/ui/lint/non-local-defs/exhaustive.stderr | 17 +++-------------- .../non-local-defs/from-local-for-global.stderr | 1 - tests/ui/lint/non-local-defs/generics.stderr | 3 --- .../non-local-defs/inside-macro_rules.stderr | 1 - tests/ui/lint/non-local-defs/weird-exprs.stderr | 7 +------ 11 files changed, 9 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index d329deff2ba6e..4ba3b079bd565 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -592,9 +592,7 @@ 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 lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks should be written at the same level as their item - .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` - .bounds = `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 + .non_local = 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` .doctest = make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}` .exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint .const_anon = use a const-anon item to suppress this lint diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index dc53349cdf2b3..ba287e0e69898 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1376,7 +1376,6 @@ pub(crate) enum NonLocalDefinitionsDiag { cargo_update: Option, const_anon: Option>, doctest: bool, - has_trait: bool, macro_to_change: Option<(String, &'static str)>, }, MacroRules { @@ -1398,7 +1397,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { cargo_update, const_anon, doctest, - has_trait, macro_to_change, } => { diag.primary_message(fluent::lint_non_local_definitions_impl); @@ -1415,12 +1413,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { diag.subdiagnostic(cargo_update); } - if has_trait { - diag.note(fluent::lint_bounds); - diag.note(fluent::lint_with_trait); - } else { - diag.note(fluent::lint_without_trait); - } + diag.note(fluent::lint_non_local); if doctest { diag.help(fluent::lint_doctest); diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 48246598452d5..56f930ea7f62e 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -216,7 +216,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { cargo_update: cargo_update(), const_anon, doctest, - has_trait: impl_.of_trait.is_some(), macro_to_change, }) } diff --git a/tests/ui/lint/non-local-defs/cargo-update.stderr b/tests/ui/lint/non-local-defs/cargo-update.stderr index bccf8622bac66..77ee28b48cc7f 100644 --- a/tests/ui/lint/non-local-defs/cargo-update.stderr +++ b/tests/ui/lint/non-local-defs/cargo-update.stderr @@ -10,7 +10,6 @@ LL | non_local_macro::non_local_impl!(LocalStruct); | = note: the macro `non_local_macro::non_local_impl` defines the non-local `impl`, and may need to be changed = 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: `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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr index 2b70d1e9f3205..7f76056c0210c 100644 --- a/tests/ui/lint/non-local-defs/consts.stderr +++ b/tests/ui/lint/non-local-defs/consts.stderr @@ -13,7 +13,6 @@ LL | impl Uto for &Test {} | | `Test` is not local | `Uto` is not 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -30,7 +29,6 @@ LL | impl Uto2 for Test {} | | `Test` is not local | `Uto2` is not 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -46,7 +44,6 @@ LL | impl Uto3 for Test {} | | `Test` is not local | `Uto3` is not 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -61,7 +58,7 @@ 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` + = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item @@ -80,7 +77,7 @@ LL | | 1 LL | | }; | |_____- move the `impl` block outside of this inline constant `` 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: 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item @@ -93,7 +90,7 @@ 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` + = 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` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -108,7 +105,6 @@ LL | impl Uto9 for Test {} | | `Test` is not local | `Uto9` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -127,7 +123,6 @@ LL | | LL | | }]; | |_____- move the `impl` block outside of this constant expression `` 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr index 3b198f9b52a17..c58ec12aaacaa 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr @@ -9,7 +9,6 @@ LL | impl PartialEq<()> for Dog { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default @@ -26,7 +25,6 @@ LL | impl PartialEq<()> for &Dog { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -42,7 +40,6 @@ LL | impl PartialEq for () { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -58,7 +55,6 @@ LL | impl PartialEq<&Dog> for () { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -75,7 +71,6 @@ LL | impl PartialEq for &Dog { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -92,7 +87,6 @@ LL | impl PartialEq<&Dog> for &Dog { | | `Dog` is not local | `PartialEq` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index c545d975014dc..dd41b2206d842 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -8,7 +8,7 @@ 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` + = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default @@ -24,7 +24,6 @@ LL | impl Display for Test { | | `Test` is not local | `Display` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -39,7 +38,7 @@ 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` + = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item @@ -54,7 +53,6 @@ LL | impl Trait for Vec { } | | `Vec` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -70,7 +68,6 @@ LL | impl Trait for &dyn Trait {} | | `Trait` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -86,7 +83,6 @@ LL | impl Trait for *mut Test {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -102,7 +98,6 @@ LL | impl Trait for *mut [Test] {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -118,7 +113,6 @@ LL | impl Trait for [Test; 8] {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -134,7 +128,6 @@ LL | impl Trait for (Test,) {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -150,7 +143,6 @@ LL | impl Trait for fn(Test) -> () {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -166,7 +158,6 @@ LL | impl Trait for fn() -> Test {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -181,7 +172,6 @@ LL | impl Trait for Test {} | | `Test` is not local | `Trait` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -196,7 +186,6 @@ LL | impl Display for InsideMain { | | `InsideMain` is not local | `Display` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -211,7 +200,7 @@ 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` + = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: 14 warnings emitted diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.stderr b/tests/ui/lint/non-local-defs/from-local-for-global.stderr index 355cd6fbdcc44..6839ebd2c8a3e 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.stderr +++ b/tests/ui/lint/non-local-defs/from-local-for-global.stderr @@ -9,7 +9,6 @@ LL | impl From for () { | | `Cat` is not local | `From` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default diff --git a/tests/ui/lint/non-local-defs/generics.stderr b/tests/ui/lint/non-local-defs/generics.stderr index a4ceae4ed31a6..aefe8921fe2c7 100644 --- a/tests/ui/lint/non-local-defs/generics.stderr +++ b/tests/ui/lint/non-local-defs/generics.stderr @@ -10,7 +10,6 @@ LL | impl Global for Vec { } | | `Vec` is not local | `Global` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default @@ -27,7 +26,6 @@ LL | impl Uto7 for Test where Local: std::any::Any {} | | `Test` is not local | `Uto7` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -42,7 +40,6 @@ LL | impl Uto8 for T {} | | | `Uto8` is not 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue diff --git a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr index fa9ba2cb785d9..faab6aea2b318 100644 --- a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr +++ b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr @@ -13,7 +13,6 @@ LL | m!(); | ---- in this macro invocation | = note: the macro `m` defines the non-local `impl`, and may need to be changed - = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default diff --git a/tests/ui/lint/non-local-defs/weird-exprs.stderr b/tests/ui/lint/non-local-defs/weird-exprs.stderr index 2441ca41895d9..f6ce063929e8f 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.stderr +++ b/tests/ui/lint/non-local-defs/weird-exprs.stderr @@ -13,7 +13,6 @@ LL | | LL | | }]; | |_- move the `impl` block outside of this constant expression `` | - = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default @@ -33,7 +32,6 @@ LL | | LL | | } | |_____- move the `impl` block outside of this constant expression `` | - = 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -53,7 +51,7 @@ LL | | 1 LL | | }]; | |_____- move the `impl` block outside of this constant expression `` 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: 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item @@ -71,7 +69,6 @@ LL | | LL | | }]; | |_____- move the `impl` block outside of this constant expression `` 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -90,7 +87,6 @@ LL | | LL | | }]) {} | |_____- move the `impl` block outside of this constant expression `` 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue @@ -110,7 +106,6 @@ LL | | LL | | }] { todo!() } | |_____- move the `impl` block outside of this constant expression `` 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` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue From 2423e9e2441dec751588220c2f0047880c0bcb32 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 28 Jun 2024 17:25:20 +0200 Subject: [PATCH 5/5] Update rustdoc doctest non_local_defs impl test --- .../rustdoc-ui/doctest/non-local-defs-impl.rs | 5 ++++- .../doctest/non-local-defs-impl.stdout | 19 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/rustdoc-ui/doctest/non-local-defs-impl.rs b/tests/rustdoc-ui/doctest/non-local-defs-impl.rs index 37c80bc1f2728..b1ab5323a2bc8 100644 --- a/tests/rustdoc-ui/doctest/non-local-defs-impl.rs +++ b/tests/rustdoc-ui/doctest/non-local-defs-impl.rs @@ -15,7 +15,10 @@ /// # use pub_trait::Trait; /// /// struct Local; -/// impl Trait for &Local {} +/// +/// fn foo() { +/// impl Trait for &Local {} +/// } /// ``` /// /// But this shoudln't produce a warning: diff --git a/tests/rustdoc-ui/doctest/non-local-defs-impl.stdout b/tests/rustdoc-ui/doctest/non-local-defs-impl.stdout index 27797e22f8ecb..f39d2c2608b88 100644 --- a/tests/rustdoc-ui/doctest/non-local-defs-impl.stdout +++ b/tests/rustdoc-ui/doctest/non-local-defs-impl.stdout @@ -1,24 +1,23 @@ running 2 tests test $DIR/non-local-defs-impl.rs - doctest (line 13) - compile ... FAILED -test $DIR/non-local-defs-impl.rs - doctest (line 22) - compile ... ok +test $DIR/non-local-defs-impl.rs - doctest (line 25) - compile ... ok failures: ---- $DIR/non-local-defs-impl.rs - doctest (line 13) stdout ---- error: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/non-local-defs-impl.rs:18:1 + --> $DIR/non-local-defs-impl.rs:20:5 | -LL | impl Trait for &Local {} - | ^^^^^-----^^^^^------ - | | | - | | `&'_ Local` is not local - | | help: remove `&` to make the `impl` local - | `Trait` is not local +LL | fn foo() { + | -------- move the `impl` block outside of this function `foo` and up 3 bodies +LL | impl Trait for &Local {} + | ^^^^^-----^^^^^^----- + | | | + | | `Local` is not local + | `Trait` is not 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: make this doc-test a standalone test with its own `fn main() { ... }` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue note: the lint level is defined here --> $DIR/non-local-defs-impl.rs:11:9