From ab23fd8dea02b9e525771ed8ec6cca1ff6d414e4 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 15 May 2024 14:17:30 +0200 Subject: [PATCH] non_local_defs: improve main without a trait note --- compiler/rustc_lint/messages.ftl | 2 +- tests/ui/lint/non-local-defs/consts.stderr | 6 +++--- tests/ui/lint/non-local-defs/exhaustive.stderr | 6 +++--- tests/ui/lint/non-local-defs/weird-exprs.stderr | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 13f6d116b81..f1273b8bf4b 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -548,7 +548,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho [one] `{$body_name}` *[other] `{$body_name}` and up {$depth} bodies } - .without_trait = methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + .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 .exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr index 820e3a2d6e0..0528f63ac9c 100644 --- a/tests/ui/lint/non-local-defs/consts.stderr +++ b/tests/ui/lint/non-local-defs/consts.stderr @@ -56,7 +56,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl Test { | ^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current function `main` --> $DIR/consts.rs:43:5 | @@ -73,7 +73,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl Test { | ^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current inline constant `` and up 2 bodies --> $DIR/consts.rs:50:9 | @@ -90,7 +90,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl Test { | ^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current constant `_` and up 2 bodies --> $DIR/consts.rs:59:9 | diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index c6b8dc26e31..29f5f14ef0d 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -4,7 +4,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl Test { | ^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current function `main` --> $DIR/exhaustive.rs:10:5 | @@ -42,7 +42,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl dyn Trait {} | ^^^^^^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current function `main` --> $DIR/exhaustive.rs:22:5 | @@ -313,7 +313,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl InsideMain { | ^^^^^^^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current function `inside_inside` and up 2 bodies --> $DIR/exhaustive.rs:79:9 | diff --git a/tests/ui/lint/non-local-defs/weird-exprs.stderr b/tests/ui/lint/non-local-defs/weird-exprs.stderr index e8cd4ffef09..cced1171903 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.stderr +++ b/tests/ui/lint/non-local-defs/weird-exprs.stderr @@ -35,7 +35,7 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam LL | impl Test { | ^^^^^^^^^ | - = note: methods and assoc const are still usable outside the current expression, only `impl Local` and `impl dyn Local` are local and only if the `Local` type is at the same nesting as the `impl` block + = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` help: move this `impl` block outside of the current constant expression `` and up 2 bodies --> $DIR/weird-exprs.rs:25:9 |