From ce967cd2ea9c08bbc30e49ab5433ea1e417475ab Mon Sep 17 00:00:00 2001 From: mu001999 Date: Wed, 25 Feb 2026 23:55:39 +0800 Subject: [PATCH 1/4] Support trailing self in paths --- .../src/error_codes/E0429.md | 4 +- .../rustc_resolve/src/build_reduced_graph.rs | 93 +++++++++---------- compiler/rustc_resolve/src/diagnostics.rs | 26 ------ compiler/rustc_resolve/src/errors.rs | 36 +------ compiler/rustc_resolve/src/ident.rs | 29 ++++-- compiler/rustc_resolve/src/imports.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 2 - 7 files changed, 73 insertions(+), 119 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0429.md b/compiler/rustc_error_codes/src/error_codes/E0429.md index 8c5fd8624fdea..26986564722f5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0429.md +++ b/compiler/rustc_error_codes/src/error_codes/E0429.md @@ -1,9 +1,11 @@ +#### Note: this error code is no longer emitted by the compiler. + The `self` keyword cannot appear alone as the last segment in a `use` declaration. Erroneous code example: -```compile_fail,E0429 +```ignore (error is no longer emitted) use std::fmt::self; // error: `self` imports are only allowed within a { } list ``` diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 9fbc73618ce80..c4e794081ff67 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -37,8 +37,8 @@ use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef}; use crate::ref_mut::CmCell; use crate::{ BindingKey, Decl, DeclData, DeclKind, ExternPreludeEntry, Finalize, IdentKey, MacroData, - Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, ResolutionError, Resolver, - Segment, Used, VisResolutionError, errors, + Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, Resolver, Segment, Used, + VisResolutionError, errors, }; type Res = def::Res; @@ -622,41 +622,27 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { match use_tree.kind { ast::UseTreeKind::Simple(rename) => { - let mut ident = use_tree.ident(); let mut module_path = prefix; - let mut source = module_path.pop().unwrap(); + let source = module_path.pop().unwrap(); - // `true` for `...::{self [as target]}` imports, `false` otherwise. - let type_ns_only = nested && source.ident.name == kw::SelfLower; - - if source.ident.name == kw::SelfLower - && let Some(parent) = module_path.pop() - { - // Suggest `use prefix::{self};` for `use prefix::self;` - if !type_ns_only - && (parent.ident.name != kw::PathRoot - || self.r.path_root_is_crate_root(parent.ident)) + // normalize `self::self` to `self` + if source.ident.name == kw::SelfLower { + while let Some(parent) = module_path.last() + && parent.ident.name == kw::SelfLower { - let span_with_rename = match rename { - Some(rename) => source.ident.span.to(rename.span), - None => source.ident.span, - }; - - self.r.report_error( - parent.ident.span.shrink_to_hi().to(source.ident.span), - ResolutionError::SelfImportsOnlyAllowedWithin { - root: parent.ident.name == kw::PathRoot, - span_with_rename, - }, - ); + module_path.pop(); } + } + let ident = if source.ident.name == kw::SelfLower + && rename.is_none() + && let Some(parent) = module_path.last() + { let self_span = source.ident.span; - source = parent; - if rename.is_none() { - ident = Ident::new(source.ident.name, self_span); - } - } + Ident::new(parent.ident.name, self_span) + } else { + use_tree.ident() + }; match source.ident.name { kw::DollarCrate => { @@ -693,27 +679,40 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { return; } } - // Deny `use ::{self};` after edition 2015 - kw::PathRoot if !self.r.path_root_is_crate_root(source.ident) => { - self.r.dcx().span_err(use_tree.span, "extern prelude cannot be imported"); - return; + kw::SelfLower => { + // Deny `use ::{self};` after edition 2015 + if let Some(parent) = module_path.last() + && parent.ident.name == kw::PathRoot + && !self.r.path_root_is_crate_root(parent.ident) + { + self.r + .dcx() + .span_err(use_tree.span, "extern prelude cannot be imported"); + return; + } + } + _ => { + // Deny `use ...::self::foo [as name];` + if module_path.len() > 1 + && let Some(parent) = module_path.last() + && parent.ident.name == kw::SelfLower + { + self.r.dcx().span_err( + parent.ident.span, + "`self` in paths can only be used in start position", + ); + return; + } } - _ => {} } // Deny importing path-kw without renaming if rename.is_none() && ident.is_path_segment_keyword() { let ident = use_tree.ident(); - - // Don't suggest `use xx::self as name;` for `use xx::self;` - // But it's OK to suggest `use xx::{self as name};` for `use xx::{self};` - let sugg = if !type_ns_only && ident.name == kw::SelfLower { - None - } else { - Some(errors::UnnamedImportSugg { span: ident.span, ident }) - }; - - self.r.dcx().emit_err(errors::UnnamedImport { span: ident.span, sugg }); + self.r.dcx().emit_err(errors::UnnamedImport { + span: ident.span, + sugg: errors::UnnamedImportSugg { span: ident.span, ident }, + }); return; } @@ -721,7 +720,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { source: source.ident, target: ident, decls: Default::default(), - type_ns_only, + type_ns_only: source.ident.is_path_segment_keyword(), nested, id, }; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index f1beae0eaf78d..b324e1674c01d 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -369,9 +369,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut suggestion = None; let mut span = binding_span; match import.kind { - ImportKind::Single { type_ns_only: true, .. } => { - suggestion = Some(format!("self as {suggested_name}")) - } ImportKind::Single { source, .. } => { if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0) && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span) @@ -870,29 +867,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { sub_unreachable, }) } - ResolutionError::SelfImportsOnlyAllowedWithin { root, span_with_rename } => { - // None of the suggestions below would help with a case like `use self`. - let (suggestion, mpart_suggestion) = if root { - (None, None) - } else { - // use foo::bar::self -> foo::bar - // use foo::bar::self as abc -> foo::bar as abc - let suggestion = errs::SelfImportsOnlyAllowedWithinSuggestion { span }; - - // use foo::bar::self -> foo::bar::{self} - // use foo::bar::self as abc -> foo::bar::{self as abc} - let mpart_suggestion = errs::SelfImportsOnlyAllowedWithinMultipartSuggestion { - multipart_start: span_with_rename.shrink_to_lo(), - multipart_end: span_with_rename.shrink_to_hi(), - }; - (Some(suggestion), Some(mpart_suggestion)) - }; - self.dcx().create_err(errs::SelfImportsOnlyAllowedWithin { - span, - suggestion, - mpart_suggestion, - }) - } ResolutionError::FailedToResolve { segment, label, suggestion, module, message } => { let mut err = struct_span_code_err!(self.dcx(), span, E0433, "{message}"); err.span_label(span, label); diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index c107f15bdad51..4ae58d9084261 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -300,40 +300,6 @@ pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> { pub(crate) suggestion: &'a str, } -#[derive(Diagnostic)] -#[diag("`self` imports are only allowed within a {\"{\"} {\"}\"} list", code = E0429)] -pub(crate) struct SelfImportsOnlyAllowedWithin { - #[primary_span] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) suggestion: Option, - #[subdiagnostic] - pub(crate) mpart_suggestion: Option, -} - -#[derive(Subdiagnostic)] -#[suggestion( - "consider importing the module directly", - code = "", - applicability = "machine-applicable" -)] -pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion { - #[primary_span] - pub(crate) span: Span, -} - -#[derive(Subdiagnostic)] -#[multipart_suggestion( - "alternatively, use the multi-path `use` syntax to import `self`", - applicability = "machine-applicable" -)] -pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion { - #[suggestion_part(code = "{{")] - pub(crate) multipart_start: Span, - #[suggestion_part(code = "}}")] - pub(crate) multipart_end: Span, -} - #[derive(Diagnostic)] #[diag("{$shadowing_binding}s cannot shadow {$shadowed_binding}s", code = E0530)] pub(crate) struct BindingShadowsSomethingUnacceptable<'a> { @@ -978,7 +944,7 @@ pub(crate) struct UnnamedImport { #[primary_span] pub(crate) span: Span, #[subdiagnostic] - pub(crate) sugg: Option, + pub(crate) sugg: UnnamedImportSugg, } #[derive(Diagnostic)] diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 7cfd5b5f861a4..9e7705f877b5e 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -953,12 +953,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ) -> Result, Determinacy> { match module { ModuleOrUniformRoot::Module(module) => { - if ns == TypeNS - && ident.name == kw::Super - && let Some(module) = - self.resolve_super_in_module(ident, Some(module), parent_scope) - { - return Ok(module.self_decl.unwrap()); + if ns == TypeNS { + if ident.name == kw::SelfLower { + return Ok(module.self_decl.unwrap()); + } + if ident.name == kw::Super + && let Some(module) = + self.resolve_super_in_module(ident, Some(module), parent_scope) + { + return Ok(module.self_decl.unwrap()); + } } let (ident_key, def) = IdentKey::new_adjusted(ident, module.expansion); @@ -1018,7 +1022,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { { let module = self.resolve_crate_root(ident); return Ok(module.self_decl.unwrap()); - } else if ident.name == kw::Super || ident.name == kw::SelfLower { + } else if ident.name == kw::Super { // FIXME: Implement these with renaming requirements so that e.g. // `use super;` doesn't work, but `use super as name;` does. // Fall through here to get an error from `early_resolve_...`. @@ -1827,6 +1831,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }, ); } + if segment_idx == 0 { if name == kw::SelfLower { let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0(); @@ -1860,6 +1865,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { continue; } } + + // Support `...::self`, but deny `::self` after edition 2018 + if is_last + && name == kw::SelfLower + && segment_idx > 0 + && (path[segment_idx - 1].ident.name != kw::PathRoot + || self.path_root_is_crate_root(path[segment_idx - 1].ident)) + { + continue; + } } // Report special messages for path segment keywords in wrong positions. diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 704c316bce650..22a6503046850 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -68,7 +68,7 @@ pub(crate) enum ImportKind<'ra> { target: Ident, /// Name declarations introduced by the import. decls: PerNS>>, - /// `true` for `...::{self [as target]}` imports, `false` otherwise. + /// `true` for `crate`/`$crate`/`super`/`self` imports, `false` otherwise. type_ns_only: bool, /// Did this import result from a nested import? ie. `use foo::{bar, baz};` nested: bool, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 45cbc0b3c828d..8d8a0f9f5e6c3 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -272,8 +272,6 @@ enum ResolutionError<'ra> { IdentifierBoundMoreThanOnceInSamePattern(Ident), /// Error E0426: use of undeclared label. UndeclaredLabel { name: Symbol, suggestion: Option }, - /// Error E0429: `self` imports are only allowed within a `{ }` list. - SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span }, /// Error E0433: failed to resolve. FailedToResolve { segment: Symbol, From be898c503f7c1e7b70669c2309a4b9827d2cca8a Mon Sep 17 00:00:00 2001 From: mu001999 Date: Tue, 24 Feb 2026 22:59:13 +0800 Subject: [PATCH 2/4] Add test for trailing self in import paths --- tests/ui/use/use-self-at-end.e2015.stderr | 116 +++++++++++++++++++++ tests/ui/use/use-self-at-end.e2018.stderr | 118 ++++++++++++++++++++++ tests/ui/use/use-self-at-end.rs | 39 +++++++ 3 files changed, 273 insertions(+) create mode 100644 tests/ui/use/use-self-at-end.e2015.stderr create mode 100644 tests/ui/use/use-self-at-end.e2018.stderr create mode 100644 tests/ui/use/use-self-at-end.rs diff --git a/tests/ui/use/use-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr new file mode 100644 index 0000000000000..9a11bf0f30998 --- /dev/null +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -0,0 +1,116 @@ +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:7:24 + | +LL | pub use crate::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:9:25 + | +LL | pub use crate::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:12:17 + | +LL | pub use self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:14:18 + | +LL | pub use {self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use {self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:17:24 + | +LL | pub use self::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:20:24 + | +LL | pub use super::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:22:25 + | +LL | pub use super::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:30:19 + | +LL | pub use ::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use ::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:33:20 + | +LL | pub use ::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use ::{self as name}; + | +++++++ + +error[E0252]: the name `x` is defined multiple times + --> $DIR/use-self-at-end.rs:27:28 + | +LL | pub use crate::x::self; + | -------------- previous import of the module `x` here +LL | pub use crate::x::self as x3; +LL | pub use crate::x::{self}; + | -------------------^^^^-- + | | | + | | `x` reimported here + | help: remove unnecessary import + | + = note: `x` must be defined only once in the type namespace of this module + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0252`. diff --git a/tests/ui/use/use-self-at-end.e2018.stderr b/tests/ui/use/use-self-at-end.e2018.stderr new file mode 100644 index 0000000000000..0688c3c6222aa --- /dev/null +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -0,0 +1,118 @@ +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:7:24 + | +LL | pub use crate::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:9:25 + | +LL | pub use crate::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use crate::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:12:17 + | +LL | pub use self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:14:18 + | +LL | pub use {self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use {self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:17:24 + | +LL | pub use self::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use self::{self as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:20:24 + | +LL | pub use super::self; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::self as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-self-at-end.rs:22:25 + | +LL | pub use super::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | pub use super::{self as name}; + | +++++++ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:30:17 + | +LL | pub use ::self; + | ^^^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:32:17 + | +LL | pub use ::self as crate4; + | ^^^^^^^^^^^^^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:33:20 + | +LL | pub use ::{self}; + | ^^^^ + +error: extern prelude cannot be imported + --> $DIR/use-self-at-end.rs:35:20 + | +LL | pub use ::{self as crate5}; + | ^^^^^^^^^^^^^^ + +error[E0252]: the name `x` is defined multiple times + --> $DIR/use-self-at-end.rs:27:28 + | +LL | pub use crate::x::self; + | -------------- previous import of the module `x` here +LL | pub use crate::x::self as x3; +LL | pub use crate::x::{self}; + | -------------------^^^^-- + | | | + | | `x` reimported here + | help: remove unnecessary import + | + = note: `x` must be defined only once in the type namespace of this module + +error: aborting due to 12 previous errors + +For more information about this error, try `rustc --explain E0252`. diff --git a/tests/ui/use/use-self-at-end.rs b/tests/ui/use/use-self-at-end.rs new file mode 100644 index 0000000000000..0c9a826349673 --- /dev/null +++ b/tests/ui/use/use-self-at-end.rs @@ -0,0 +1,39 @@ +//@ revisions: e2015 e2018 +//@ [e2015] edition: 2015 +//@ [e2018] edition: 2018.. + +pub mod x { + pub mod y { + pub use crate::self; //~ ERROR imports need to be explicitly named + pub use crate::self as crate1; + pub use crate::{self}; //~ ERROR imports need to be explicitly named + pub use crate::{self as crate2}; + + pub use self; //~ ERROR imports need to be explicitly named + pub use self as self1; + pub use {self}; //~ ERROR imports need to be explicitly named + pub use {self as self2}; + pub use self::self as self3; + pub use self::{self}; //~ ERROR imports need to be explicitly named + pub use self::{self as self4}; + + pub use super::self; //~ ERROR imports need to be explicitly named + pub use super::self as super1; + pub use super::{self}; //~ ERROR imports need to be explicitly named + pub use super::{self as super2}; + + pub use crate::x::self; + pub use crate::x::self as x3; + pub use crate::x::{self}; //~ ERROR the name `x` is defined multiple times + pub use crate::x::{self as x4}; + + pub use ::self; //[e2018]~ ERROR extern prelude cannot be imported + //[e2015]~^ ERROR imports need to be explicitly named + pub use ::self as crate4; //[e2018]~ ERROR extern prelude cannot be imported + pub use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported + //[e2015]~^ ERROR imports need to be explicitly named + pub use ::{self as crate5}; //[e2018]~ ERROR extern prelude cannot be imported + } +} + +fn main() {} From cd94176b706f9894ec4be8e22ab939e48f037571 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Tue, 24 Feb 2026 22:57:05 +0800 Subject: [PATCH 3/4] Bless rest tests --- tests/ui/error-codes/E0429.rs | 4 +- tests/ui/error-codes/E0429.stderr | 19 - ...absolute-paths-in-nested-use-groups.stderr | 12 +- tests/ui/imports/cycle-import-in-std-1.stderr | 10 +- tests/ui/imports/cycle-import-in-std-2.stderr | 10 +- tests/ui/imports/issue-28388-1.stderr | 7 +- tests/ui/imports/issue-38293.stderr | 4 +- tests/ui/imports/issue-45829/import-self.rs | 1 - .../ui/imports/issue-45829/import-self.stderr | 27 +- tests/ui/imports/issue-47623.stderr | 5 + tests/ui/privacy/private-variant-reexport.rs | 2 +- .../privacy/private-variant-reexport.stderr | 10 +- tests/ui/resolve/resolve-bad-import-prefix.rs | 2 +- .../resolve/resolve-bad-import-prefix.stderr | 15 +- tests/ui/use/use-mod/use-mod-3.stderr | 2 + tests/ui/use/use-mod/use-mod-4.rs | 2 - tests/ui/use/use-mod/use-mod-4.stderr | 42 +- tests/ui/use/use-mod/use-mod-5.rs | 3 +- tests/ui/use/use-mod/use-mod-5.stderr | 19 - tests/ui/use/use-mod/use-mod-6.rs | 3 +- tests/ui/use/use-mod/use-mod-6.stderr | 19 - tests/ui/use/use-path-segment-kw.e2015.stderr | 479 ++++++------------ tests/ui/use/use-path-segment-kw.e2018.stderr | 426 +++++----------- tests/ui/use/use-path-segment-kw.rs | 43 +- tests/ui/use/use-super-in-middle.rs | 6 +- tests/ui/use/use-super-in-middle.stderr | 24 +- 26 files changed, 377 insertions(+), 819 deletions(-) delete mode 100644 tests/ui/error-codes/E0429.stderr delete mode 100644 tests/ui/use/use-mod/use-mod-5.stderr delete mode 100644 tests/ui/use/use-mod/use-mod-6.stderr diff --git a/tests/ui/error-codes/E0429.rs b/tests/ui/error-codes/E0429.rs index e74b27a78b67d..234ff52cff709 100644 --- a/tests/ui/error-codes/E0429.rs +++ b/tests/ui/error-codes/E0429.rs @@ -1,4 +1,6 @@ -use std::fmt::self; //~ ERROR E0429 +//@ check-pass + +use std::fmt::self; fn main () { } diff --git a/tests/ui/error-codes/E0429.stderr b/tests/ui/error-codes/E0429.stderr deleted file mode 100644 index d2d9ba209f745..0000000000000 --- a/tests/ui/error-codes/E0429.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/E0429.rs:1:13 - | -LL | use std::fmt::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use std::fmt::self; -LL + use std::fmt; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use std::fmt::{self}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr b/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr index ff951ad7489c7..e72490b5f40f1 100644 --- a/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr +++ b/tests/ui/imports/absolute-paths-in-nested-use-groups.stderr @@ -1,3 +1,9 @@ +error: `self` in paths can only be used in start position + --> $DIR/absolute-paths-in-nested-use-groups.rs:10:5 + | +LL | self::bar, + | ^^^^ + error[E0433]: the crate root in paths can only be used in start position --> $DIR/absolute-paths-in-nested-use-groups.rs:6:5 | @@ -10,12 +16,6 @@ error[E0433]: `super` in paths can only be used in start position LL | super::bar, | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/absolute-paths-in-nested-use-groups.rs:10:5 - | -LL | self::bar, - | ^^^^ can only be used in path start position - error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/imports/cycle-import-in-std-1.stderr b/tests/ui/imports/cycle-import-in-std-1.stderr index a7dfc6231bace..6071cd66846bb 100644 --- a/tests/ui/imports/cycle-import-in-std-1.stderr +++ b/tests/ui/imports/cycle-import-in-std-1.stderr @@ -1,11 +1,13 @@ error[E0432]: unresolved import `ops` - --> $DIR/cycle-import-in-std-1.rs:5:11 + --> $DIR/cycle-import-in-std-1.rs:5:5 | LL | use ops::{self as std}; - | ^^^^^^^^^^^ no external crate `ops` + | ^^^ | - = help: consider importing this module instead: - std::ops +help: a similar path exists + | +LL | use core::ops::{self as std}; + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/imports/cycle-import-in-std-2.stderr b/tests/ui/imports/cycle-import-in-std-2.stderr index 8d94693cd51d4..75712be18177e 100644 --- a/tests/ui/imports/cycle-import-in-std-2.stderr +++ b/tests/ui/imports/cycle-import-in-std-2.stderr @@ -1,11 +1,13 @@ error[E0432]: unresolved import `ops` - --> $DIR/cycle-import-in-std-2.rs:5:11 + --> $DIR/cycle-import-in-std-2.rs:5:5 | LL | use ops::{self as std}; - | ^^^^^^^^^^^ no external crate `ops` + | ^^^ | - = help: consider importing this module instead: - std::ops +help: a similar path exists + | +LL | use core::ops::{self as std}; + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/imports/issue-28388-1.stderr b/tests/ui/imports/issue-28388-1.stderr index 0fc4777434af7..4f46d05275555 100644 --- a/tests/ui/imports/issue-28388-1.stderr +++ b/tests/ui/imports/issue-28388-1.stderr @@ -2,7 +2,12 @@ error[E0432]: unresolved import `foo` --> $DIR/issue-28388-1.rs:4:5 | LL | use foo::{}; - | ^^^^^^^ no `foo` in the root + | ^^^ use of unresolved module or unlinked crate `foo` + | +help: you might be missing a crate named `foo`, add it to your project and import it in your code + | +LL + extern crate foo; + | error: aborting due to 1 previous error diff --git a/tests/ui/imports/issue-38293.stderr b/tests/ui/imports/issue-38293.stderr index a6f0032bc735a..348bb07f203cf 100644 --- a/tests/ui/imports/issue-38293.stderr +++ b/tests/ui/imports/issue-38293.stderr @@ -1,8 +1,8 @@ error[E0432]: unresolved import `foo::f` - --> $DIR/issue-38293.rs:7:14 + --> $DIR/issue-38293.rs:7:10 | LL | use foo::f::{self}; - | ^^^^ no `f` in `foo` + | ^ expected type, found function `f` in `foo` error[E0423]: expected function, found module `baz` --> $DIR/issue-38293.rs:16:5 diff --git a/tests/ui/imports/issue-45829/import-self.rs b/tests/ui/imports/issue-45829/import-self.rs index 2dc4331ced775..deff8dcbeacc6 100644 --- a/tests/ui/imports/issue-45829/import-self.rs +++ b/tests/ui/imports/issue-45829/import-self.rs @@ -10,7 +10,6 @@ use foo as self; //~^ ERROR expected identifier use foo::self; //~ ERROR is defined multiple times -//~^ ERROR `self` imports are only allowed within a { } list use foo::A; use foo::{self as A}; diff --git a/tests/ui/imports/issue-45829/import-self.stderr b/tests/ui/imports/issue-45829/import-self.stderr index 5094a50635d53..978d20490b282 100644 --- a/tests/ui/imports/issue-45829/import-self.stderr +++ b/tests/ui/imports/issue-45829/import-self.stderr @@ -4,22 +4,6 @@ error: expected identifier, found keyword `self` LL | use foo as self; | ^^^^ expected identifier, found keyword -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/import-self.rs:12:8 - | -LL | use foo::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::self; -LL + use foo; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::{self}; - | + + - error[E0255]: the name `foo` is defined multiple times --> $DIR/import-self.rs:6:11 | @@ -47,12 +31,11 @@ LL | use foo::self; = note: `foo` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | -LL - use foo::self; -LL + use foo as other_foo; - | +LL | use foo::self as other_foo; + | ++++++++++++ error[E0252]: the name `A` is defined multiple times - --> $DIR/import-self.rs:16:11 + --> $DIR/import-self.rs:15:11 | LL | use foo::A; | ------ previous import of the type `A` here @@ -65,7 +48,7 @@ help: you can use `as` to change the binding name of the import LL | use foo::{self as OtherA}; | +++++ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0252, E0255, E0429. +Some errors have detailed explanations: E0252, E0255. For more information about an error, try `rustc --explain E0252`. diff --git a/tests/ui/imports/issue-47623.stderr b/tests/ui/imports/issue-47623.stderr index 64f443bf69e48..21baf29bd9521 100644 --- a/tests/ui/imports/issue-47623.stderr +++ b/tests/ui/imports/issue-47623.stderr @@ -3,6 +3,11 @@ error: imports need to be explicitly named | LL | use self; | ^^^^ + | +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: aborting due to 1 previous error diff --git a/tests/ui/privacy/private-variant-reexport.rs b/tests/ui/privacy/private-variant-reexport.rs index b371a0e76adc0..537e0fa6c198f 100644 --- a/tests/ui/privacy/private-variant-reexport.rs +++ b/tests/ui/privacy/private-variant-reexport.rs @@ -8,7 +8,7 @@ mod m2 { } mod m3 { - pub use ::E::V::{self}; //~ ERROR `V` is only public within the crate, and cannot be re-exported outside + pub use ::E::V::{self}; //~ ERROR unresolved import `E::V` } #[deny(unused_imports)] diff --git a/tests/ui/privacy/private-variant-reexport.stderr b/tests/ui/privacy/private-variant-reexport.stderr index 68e7d653fb132..aaa42d8d30dc5 100644 --- a/tests/ui/privacy/private-variant-reexport.stderr +++ b/tests/ui/privacy/private-variant-reexport.stderr @@ -22,13 +22,11 @@ note: consider marking `V` as `pub` in the imported module LL | pub use ::E::{V}; | ^ -error[E0365]: `V` is only public within the crate, and cannot be re-exported outside - --> $DIR/private-variant-reexport.rs:11:22 +error[E0432]: unresolved import `E::V` + --> $DIR/private-variant-reexport.rs:11:18 | LL | pub use ::E::V::{self}; - | ^^^^ re-export of crate public `V` - | - = note: consider declaring type or module `V` with `pub` + | ^ `V` is a variant, not a module error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough --> $DIR/private-variant-reexport.rs:16:13 @@ -56,5 +54,5 @@ LL | pub use ::E::*; error: aborting due to 5 previous errors -Some errors have detailed explanations: E0364, E0365. +Some errors have detailed explanations: E0364, E0432. For more information about an error, try `rustc --explain E0364`. diff --git a/tests/ui/resolve/resolve-bad-import-prefix.rs b/tests/ui/resolve/resolve-bad-import-prefix.rs index 290330bee818c..70e104881ebad 100644 --- a/tests/ui/resolve/resolve-bad-import-prefix.rs +++ b/tests/ui/resolve/resolve-bad-import-prefix.rs @@ -8,7 +8,7 @@ use {}; // OK use ::{}; // OK use m::{}; // OK use E::{}; // OK -use S::{}; // FIXME, this and `use S::{self};` should be an error +use S::{}; //~ ERROR unresolved import `S` use Tr::{}; // FIXME, this and `use Tr::{self};` should be an error use Nonexistent::{}; //~ ERROR unresolved import `Nonexistent` diff --git a/tests/ui/resolve/resolve-bad-import-prefix.stderr b/tests/ui/resolve/resolve-bad-import-prefix.stderr index b532d3a4a6e3b..7c8b08beb7d1a 100644 --- a/tests/ui/resolve/resolve-bad-import-prefix.stderr +++ b/tests/ui/resolve/resolve-bad-import-prefix.stderr @@ -1,9 +1,20 @@ +error[E0432]: unresolved import `S` + --> $DIR/resolve-bad-import-prefix.rs:11:5 + | +LL | use S::{}; + | ^ `S` is a struct, not a module + error[E0432]: unresolved import `Nonexistent` --> $DIR/resolve-bad-import-prefix.rs:13:5 | LL | use Nonexistent::{}; - | ^^^^^^^^^^^^^^^ no `Nonexistent` in the root + | ^^^^^^^^^^^ use of unresolved module or unlinked crate `Nonexistent` + | +help: you might be missing a crate named `Nonexistent`, add it to your project and import it in your code + | +LL + extern crate Nonexistent; + | -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0432`. diff --git a/tests/ui/use/use-mod/use-mod-3.stderr b/tests/ui/use/use-mod/use-mod-3.stderr index 1b12b3c6fa09a..049b50e5b3b0f 100644 --- a/tests/ui/use/use-mod/use-mod-3.stderr +++ b/tests/ui/use/use-mod/use-mod-3.stderr @@ -3,6 +3,8 @@ error[E0603]: module `bar` is private | LL | use foo::bar::{ | ^^^ private module +LL | self + | ---- module `self` is not publicly re-exported | note: the module `bar` is defined here --> $DIR/use-mod-3.rs:9:5 diff --git a/tests/ui/use/use-mod/use-mod-4.rs b/tests/ui/use/use-mod/use-mod-4.rs index 34ce7c7195758..570731e1896d2 100644 --- a/tests/ui/use/use-mod/use-mod-4.rs +++ b/tests/ui/use/use-mod/use-mod-4.rs @@ -1,7 +1,5 @@ use crate::foo::self; //~ ERROR unresolved import `crate::foo` -//~^ ERROR `self` imports are only allowed within a { } list use std::mem::self; -//~^ ERROR `self` imports are only allowed within a { } list fn main() {} diff --git a/tests/ui/use/use-mod/use-mod-4.stderr b/tests/ui/use/use-mod/use-mod-4.stderr index d4621296c0d18..8039450702552 100644 --- a/tests/ui/use/use-mod/use-mod-4.stderr +++ b/tests/ui/use/use-mod/use-mod-4.stderr @@ -1,42 +1,14 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-4.rs:1:15 +error[E0432]: unresolved import `crate::foo` + --> $DIR/use-mod-4.rs:1:12 | LL | use crate::foo::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::self; -LL + use crate::foo; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-4.rs:4:13 + | ^^^ use of unresolved module or unlinked crate `foo` | -LL | use std::mem::self; - | ^^^^^^ +help: you might be missing a crate named `foo`, add it to your project and import it in your code | -help: consider importing the module directly +LL + extern crate foo; | -LL - use std::mem::self; -LL + use std::mem; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use std::mem::{self}; - | + + - -error[E0432]: unresolved import `crate::foo` - --> $DIR/use-mod-4.rs:1:5 - | -LL | use crate::foo::self; - | ^^^^^^^^^^^^^^^^ no `foo` in the root -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0429, E0432. -For more information about an error, try `rustc --explain E0429`. +For more information about this error, try `rustc --explain E0432`. diff --git a/tests/ui/use/use-mod/use-mod-5.rs b/tests/ui/use/use-mod/use-mod-5.rs index df5b423ec57e6..b2eada7e28694 100644 --- a/tests/ui/use/use-mod/use-mod-5.rs +++ b/tests/ui/use/use-mod/use-mod-5.rs @@ -1,3 +1,5 @@ +//@ check-pass + mod foo { pub mod bar { pub fn drop() {} @@ -5,7 +7,6 @@ mod foo { } use foo::bar::self; -//~^ ERROR `self` imports are only allowed within a { } list fn main() { // Because of error recovery this shouldn't error diff --git a/tests/ui/use/use-mod/use-mod-5.stderr b/tests/ui/use/use-mod/use-mod-5.stderr deleted file mode 100644 index 22201361c584f..0000000000000 --- a/tests/ui/use/use-mod/use-mod-5.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-5.rs:7:13 - | -LL | use foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::bar::self; -LL + use foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::bar::{self}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/use/use-mod/use-mod-6.rs b/tests/ui/use/use-mod/use-mod-6.rs index 1f8777daca491..96f6fe74e4e68 100644 --- a/tests/ui/use/use-mod/use-mod-6.rs +++ b/tests/ui/use/use-mod/use-mod-6.rs @@ -1,3 +1,5 @@ +//@ check-pass + mod foo { pub mod bar { pub fn drop() {} @@ -5,7 +7,6 @@ mod foo { } use foo::bar::self as abc; -//~^ ERROR `self` imports are only allowed within a { } list fn main() { // Because of error recovery this shouldn't error diff --git a/tests/ui/use/use-mod/use-mod-6.stderr b/tests/ui/use/use-mod/use-mod-6.stderr deleted file mode 100644 index f9ab346f8c36e..0000000000000 --- a/tests/ui/use/use-mod/use-mod-6.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-6.rs:7:13 - | -LL | use foo::bar::self as abc; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::bar::self as abc; -LL + use foo::bar as abc; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::bar::{self as abc}; - | + + - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0429`. diff --git a/tests/ui/use/use-path-segment-kw.e2015.stderr b/tests/ui/use/use-path-segment-kw.e2015.stderr index 908e739ec520f..91b5a68d672fb 100644 --- a/tests/ui/use/use-path-segment-kw.e2015.stderr +++ b/tests/ui/use/use-path-segment-kw.e2015.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:97:13 + --> $DIR/use-path-segment-kw.rs:96:13 | LL | use crate; | ^^^^^ @@ -10,127 +10,127 @@ LL | use crate as name; | +++++++ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:101:15 + --> $DIR/use-path-segment-kw.rs:100:15 | LL | use ::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:102:15 + --> $DIR/use-path-segment-kw.rs:101:15 | LL | use ::crate as _crate2; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:103:16 + --> $DIR/use-path-segment-kw.rs:102:16 | LL | use ::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:104:16 + --> $DIR/use-path-segment-kw.rs:103:16 | LL | use ::{crate as _nested_crate2}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:107:21 + --> $DIR/use-path-segment-kw.rs:106:21 | LL | use foobar::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:108:21 + --> $DIR/use-path-segment-kw.rs:107:21 | LL | use foobar::crate as _crate3; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:109:22 + --> $DIR/use-path-segment-kw.rs:108:22 | LL | use foobar::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:110:22 + --> $DIR/use-path-segment-kw.rs:109:22 | LL | use foobar::{crate as _nested_crate3}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:113:20 + --> $DIR/use-path-segment-kw.rs:112:20 | LL | use crate::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:114:20 + --> $DIR/use-path-segment-kw.rs:113:20 | LL | use crate::crate as _crate4; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:115:21 + --> $DIR/use-path-segment-kw.rs:114:21 | LL | use crate::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:116:21 + --> $DIR/use-path-segment-kw.rs:115:21 | LL | use crate::{crate as _nested_crate4}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:119:20 + --> $DIR/use-path-segment-kw.rs:118:20 | LL | use super::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:120:20 + --> $DIR/use-path-segment-kw.rs:119:20 | LL | use super::crate as _crate5; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:121:21 + --> $DIR/use-path-segment-kw.rs:120:21 | LL | use super::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:122:21 + --> $DIR/use-path-segment-kw.rs:121:21 | LL | use super::{crate as _nested_crate5}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:125:19 + --> $DIR/use-path-segment-kw.rs:124:19 | LL | use self::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:126:19 + --> $DIR/use-path-segment-kw.rs:125:19 | LL | use self::crate as _crate6; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:127:20 + --> $DIR/use-path-segment-kw.rs:126:20 | LL | use self::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:128:20 + --> $DIR/use-path-segment-kw.rs:127:20 | LL | use self::{crate as _nested_crate6}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:135:13 + --> $DIR/use-path-segment-kw.rs:134:13 | LL | use super; | ^^^^^ @@ -141,79 +141,79 @@ LL | use super as name; | +++++++ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:139:15 + --> $DIR/use-path-segment-kw.rs:138:15 | LL | use ::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:140:15 + --> $DIR/use-path-segment-kw.rs:139:15 | LL | use ::super as _super2; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:141:16 + --> $DIR/use-path-segment-kw.rs:140:16 | LL | use ::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:142:16 + --> $DIR/use-path-segment-kw.rs:141:16 | LL | ... use ::{super as _nested_super2}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:145:21 + --> $DIR/use-path-segment-kw.rs:144:21 | LL | use foobar::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:146:21 + --> $DIR/use-path-segment-kw.rs:145:21 | LL | ... use foobar::super as _super3; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:147:22 + --> $DIR/use-path-segment-kw.rs:146:22 | LL | use foobar::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:148:22 + --> $DIR/use-path-segment-kw.rs:147:22 | LL | ... use foobar::{super as _nested_super3}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:151:20 + --> $DIR/use-path-segment-kw.rs:150:20 | LL | use crate::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:152:20 + --> $DIR/use-path-segment-kw.rs:151:20 | LL | ... use crate::super as _super4; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:153:21 + --> $DIR/use-path-segment-kw.rs:152:21 | LL | use crate::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:154:21 + --> $DIR/use-path-segment-kw.rs:153:21 | LL | ... use crate::{super as _nested_super4}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:157:20 + --> $DIR/use-path-segment-kw.rs:156:20 | LL | use super::super; | ^^^^^ @@ -224,7 +224,7 @@ LL | use super::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:159:21 + --> $DIR/use-path-segment-kw.rs:158:21 | LL | use super::{super}; | ^^^^^ @@ -235,7 +235,7 @@ LL | use super::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:163:19 + --> $DIR/use-path-segment-kw.rs:162:19 | LL | use self::super; | ^^^^^ @@ -246,7 +246,7 @@ LL | use self::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:165:20 + --> $DIR/use-path-segment-kw.rs:164:20 | LL | use self::{super}; | ^^^^^ @@ -257,31 +257,29 @@ LL | use self::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:173:13 + --> $DIR/use-path-segment-kw.rs:172:13 | LL | use self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:177:13 | -LL | use ::self; - | ^^^^^^ +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:177:15 | LL | use ::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:180:13 | -LL | use ::self as _self2; - | ^^^^^^ +help: try renaming it with a name + | +LL | use ::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:182:16 + --> $DIR/use-path-segment-kw.rs:180:16 | LL | use ::{self}; | ^^^^ @@ -291,78 +289,19 @@ help: try renaming it with a name LL | use ::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:187:28 - | -LL | pub use foobar::qux::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::qux::self; -LL + pub use foobar::qux; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::qux::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:189:23 - | -LL | pub use foobar::self as _self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::self as _self3; -LL + pub use foobar as _self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::{self as _self3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:195:18 - | -LL | use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::self; -LL + use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:195:20 + --> $DIR/use-path-segment-kw.rs:193:20 | LL | use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:197:22 - | -LL | pub use crate::self as _self4; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use crate::self as _self4; -LL + pub use crate as _self4; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as _self4}; - | + + +LL | use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:21 + --> $DIR/use-path-segment-kw.rs:195:21 | LL | use crate::{self}; | ^^^^ @@ -372,46 +311,19 @@ help: try renaming it with a name LL | use crate::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:202:18 - | -LL | use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use super::self; -LL + use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:202:20 + --> $DIR/use-path-segment-kw.rs:199:20 | LL | use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:204:22 | -LL | pub use super::self as _self5; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self as _self5; -LL + pub use super as _self5; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as _self5}; - | + + +LL | use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:205:21 + --> $DIR/use-path-segment-kw.rs:201:21 | LL | use super::{self}; | ^^^^ @@ -421,46 +333,19 @@ help: try renaming it with a name LL | use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:209:17 - | -LL | use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use self::self; -LL + use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:209:19 + --> $DIR/use-path-segment-kw.rs:205:19 | LL | use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:211:21 - | -LL | pub use self::self as _self6; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self as _self6; -LL + pub use self as _self6; | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as _self6}; - | + + +LL | use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:212:20 + --> $DIR/use-path-segment-kw.rs:207:20 | LL | use self::{self}; | ^^^^ @@ -470,38 +355,6 @@ help: try renaming it with a name LL | use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:216:28 - | -LL | use crate::foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self; -LL + use crate::foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:217:28 - | -LL | use crate::foo::bar::self as _self7; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self as _self7; -LL + use crate::foo::bar as _self7; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self as _self7}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:11:13 | @@ -869,26 +722,6 @@ LL | ... macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:63:19 - | -LL | use $crate::self; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - use $crate::self; -LL + use $crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use $crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:63:21 | @@ -899,29 +732,13 @@ LL | macro_dollar_crate!(); | --------------------- in this macro invocation | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:65:23 - | -LL | pub use $crate::self as _m_self8; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - pub use $crate::self as _m_self8; -LL + pub use $crate as _m_self8; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use $crate::{self as _m_self8}; - | + + +LL | use $crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:66:22 + --> $DIR/use-path-segment-kw.rs:65:22 | LL | use $crate::{self}; | ^^^^ @@ -935,45 +752,49 @@ help: try renaming it with a name LL | use $crate::{self as name}; | +++++++ -error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:187:17 +error[E0433]: cannot find module or crate `foobar` in the crate root + --> $DIR/use-path-segment-kw.rs:185:17 | LL | pub use foobar::qux::self; - | ^^^^^^ + | ^^^^^^ use of unresolved module or unlinked crate `foobar` | -help: a similar path exists +help: you might be missing a crate named `foobar`, add it to your project and import it in your code + | +LL + extern crate foobar; | -LL | pub use self::foobar::qux::self; - | ++++++ -error[E0432]: unresolved import `foobar` +error[E0433]: cannot find module or crate `foobar` in the crate root --> $DIR/use-path-segment-kw.rs:189:17 | -LL | pub use foobar::self as _self3; - | ^^^^^^^^^^^^^^^^^^^^^^ no `foobar` in the root +LL | pub use foobar::baz::{self}; + | ^^^^^^ use of unresolved module or unlinked crate `foobar` + | +help: you might be missing a crate named `foobar`, add it to your project and import it in your code + | +LL + extern crate foobar; + | error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:191:17 + --> $DIR/use-path-segment-kw.rs:187:17 | -LL | pub use foobar::baz::{self}; +LL | pub use foobar::self as _self3; | ^^^^^^ | help: a similar path exists | -LL | pub use self::foobar::baz::{self}; +LL | pub use self::foobar::self as _self3; | ++++++ error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:192:26 + --> $DIR/use-path-segment-kw.rs:190:17 | LL | pub use foobar::{self as _nested_self3}; - | ^^^^^^^^^^^^^^^^^^^^^ no `foobar` in the root - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:215:36 + | ^^^^^^ | -LL | type D7 = crate::foo::bar::self; - | ^^^^ can only be used in path start position +help: a similar path exists + | +LL | pub use self::foobar::{self as _nested_self3}; + | ++++++ error[E0573]: expected type, found module `$crate` --> $DIR/use-path-segment-kw.rs:10:19 @@ -986,36 +807,83 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0573]: expected type, found module `$crate::self` + --> $DIR/use-path-segment-kw.rs:62:20 + | +LL | type A10 = $crate::self; + | ^^^^^^^^^^^^ not a type +... +LL | macro_dollar_crate!(); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0573]: expected type, found module `crate` - --> $DIR/use-path-segment-kw.rs:96:19 + --> $DIR/use-path-segment-kw.rs:95:19 | LL | type B1 = crate; | ^^^^^ not a type error[E0573]: expected type, found module `super` - --> $DIR/use-path-segment-kw.rs:134:19 + --> $DIR/use-path-segment-kw.rs:133:19 | LL | type C1 = super; | ^^^^^ not a type error[E0573]: expected type, found module `super::super` - --> $DIR/use-path-segment-kw.rs:156:19 + --> $DIR/use-path-segment-kw.rs:155:19 | LL | type C5 = super::super; | ^^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self::super` - --> $DIR/use-path-segment-kw.rs:162:19 + --> $DIR/use-path-segment-kw.rs:161:19 | LL | type C6 = self::super; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-path-segment-kw.rs:172:19 + --> $DIR/use-path-segment-kw.rs:171:19 | LL | type D1 = self; | ^^^^ not a type +error[E0573]: expected type, found module `self` + --> $DIR/use-path-segment-kw.rs:175:19 + | +LL | type D2 = ::self; + | ^^^^^^ not a type + +error[E0573]: expected type, found module `foobar::self` + --> $DIR/use-path-segment-kw.rs:184:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:192:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:198:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:204:19 + | +LL | type D6 = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::foo::bar::self` + --> $DIR/use-path-segment-kw.rs:210:19 + | +LL | type D7 = crate::foo::bar::self; + | ^^^^^^^^^^^^^^^^^^^^^ not a type + error[E0433]: global paths cannot start with `$crate` --> $DIR/use-path-segment-kw.rs:14:21 | @@ -1104,96 +972,55 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:62:28 - | -LL | type A10 = $crate::self; - | ^^^^ can only be used in path start position -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0433]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position -error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 - | -LL | type D2 = ::self; - | ^^^^ cannot start with this - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 - | -LL | type D3 = foobar::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:194:26 - | -LL | type D4 = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:201:26 - | -LL | type D5 = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:208:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - -error: aborting due to 129 previous errors +error: aborting due to 115 previous errors -Some errors have detailed explanations: E0429, E0432, E0433, E0573. -For more information about an error, try `rustc --explain E0429`. +Some errors have detailed explanations: E0432, E0433, E0573. +For more information about an error, try `rustc --explain E0432`. diff --git a/tests/ui/use/use-path-segment-kw.e2018.stderr b/tests/ui/use/use-path-segment-kw.e2018.stderr index 878fd166b845d..a115cece5b310 100644 --- a/tests/ui/use/use-path-segment-kw.e2018.stderr +++ b/tests/ui/use/use-path-segment-kw.e2018.stderr @@ -1,5 +1,5 @@ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:97:13 + --> $DIR/use-path-segment-kw.rs:96:13 | LL | use crate; | ^^^^^ @@ -10,127 +10,127 @@ LL | use crate as name; | +++++++ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:101:15 + --> $DIR/use-path-segment-kw.rs:100:15 | LL | use ::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:102:15 + --> $DIR/use-path-segment-kw.rs:101:15 | LL | use ::crate as _crate2; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:103:16 + --> $DIR/use-path-segment-kw.rs:102:16 | LL | use ::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:104:16 + --> $DIR/use-path-segment-kw.rs:103:16 | LL | use ::{crate as _nested_crate2}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:107:21 + --> $DIR/use-path-segment-kw.rs:106:21 | LL | use foobar::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:108:21 + --> $DIR/use-path-segment-kw.rs:107:21 | LL | use foobar::crate as _crate3; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:109:22 + --> $DIR/use-path-segment-kw.rs:108:22 | LL | use foobar::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:110:22 + --> $DIR/use-path-segment-kw.rs:109:22 | LL | use foobar::{crate as _nested_crate3}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:113:20 + --> $DIR/use-path-segment-kw.rs:112:20 | LL | use crate::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:114:20 + --> $DIR/use-path-segment-kw.rs:113:20 | LL | use crate::crate as _crate4; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:115:21 + --> $DIR/use-path-segment-kw.rs:114:21 | LL | use crate::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:116:21 + --> $DIR/use-path-segment-kw.rs:115:21 | LL | use crate::{crate as _nested_crate4}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:119:20 + --> $DIR/use-path-segment-kw.rs:118:20 | LL | use super::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:120:20 + --> $DIR/use-path-segment-kw.rs:119:20 | LL | use super::crate as _crate5; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:121:21 + --> $DIR/use-path-segment-kw.rs:120:21 | LL | use super::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:122:21 + --> $DIR/use-path-segment-kw.rs:121:21 | LL | use super::{crate as _nested_crate5}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:125:19 + --> $DIR/use-path-segment-kw.rs:124:19 | LL | use self::crate; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:126:19 + --> $DIR/use-path-segment-kw.rs:125:19 | LL | use self::crate as _crate6; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:127:20 + --> $DIR/use-path-segment-kw.rs:126:20 | LL | use self::{crate}; | ^^^^^ error: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:128:20 + --> $DIR/use-path-segment-kw.rs:127:20 | LL | use self::{crate as _nested_crate6}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:135:13 + --> $DIR/use-path-segment-kw.rs:134:13 | LL | use super; | ^^^^^ @@ -141,79 +141,79 @@ LL | use super as name; | +++++++ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:139:15 + --> $DIR/use-path-segment-kw.rs:138:15 | LL | use ::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:140:15 + --> $DIR/use-path-segment-kw.rs:139:15 | LL | use ::super as _super2; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:141:16 + --> $DIR/use-path-segment-kw.rs:140:16 | LL | use ::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:142:16 + --> $DIR/use-path-segment-kw.rs:141:16 | LL | ... use ::{super as _nested_super2}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:145:21 + --> $DIR/use-path-segment-kw.rs:144:21 | LL | use foobar::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:146:21 + --> $DIR/use-path-segment-kw.rs:145:21 | LL | ... use foobar::super as _super3; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:147:22 + --> $DIR/use-path-segment-kw.rs:146:22 | LL | use foobar::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:148:22 + --> $DIR/use-path-segment-kw.rs:147:22 | LL | ... use foobar::{super as _nested_super3}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:151:20 + --> $DIR/use-path-segment-kw.rs:150:20 | LL | use crate::super; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:152:20 + --> $DIR/use-path-segment-kw.rs:151:20 | LL | ... use crate::super as _super4; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:153:21 + --> $DIR/use-path-segment-kw.rs:152:21 | LL | use crate::{super}; | ^^^^^ error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-path-segment-kw.rs:154:21 + --> $DIR/use-path-segment-kw.rs:153:21 | LL | ... use crate::{super as _nested_super4}; | ^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:157:20 + --> $DIR/use-path-segment-kw.rs:156:20 | LL | use super::super; | ^^^^^ @@ -224,7 +224,7 @@ LL | use super::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:159:21 + --> $DIR/use-path-segment-kw.rs:158:21 | LL | use super::{super}; | ^^^^^ @@ -235,7 +235,7 @@ LL | use super::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:163:19 + --> $DIR/use-path-segment-kw.rs:162:19 | LL | use self::super; | ^^^^^ @@ -246,7 +246,7 @@ LL | use self::super as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:165:20 + --> $DIR/use-path-segment-kw.rs:164:20 | LL | use self::{super}; | ^^^^^ @@ -257,10 +257,15 @@ LL | use self::{super as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:173:13 + --> $DIR/use-path-segment-kw.rs:172:13 | LL | use self; | ^^^^ + | +help: try renaming it with a name + | +LL | use self as name; + | +++++++ error: extern prelude cannot be imported --> $DIR/use-path-segment-kw.rs:177:13 @@ -269,95 +274,36 @@ LL | use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:180:13 + --> $DIR/use-path-segment-kw.rs:179:13 | LL | use ::self as _self2; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:182:16 + --> $DIR/use-path-segment-kw.rs:180:16 | LL | use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:184:20 + --> $DIR/use-path-segment-kw.rs:182:20 | LL | pub use ::{self as _nested_self2}; | ^^^^^^^^^^^^^^^^^^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:187:28 - | -LL | pub use foobar::qux::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::qux::self; -LL + pub use foobar::qux; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::qux::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:189:23 - | -LL | pub use foobar::self as _self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use foobar::self as _self3; -LL + pub use foobar as _self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use foobar::{self as _self3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:195:18 - | -LL | use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::self; -LL + use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:195:20 + --> $DIR/use-path-segment-kw.rs:193:20 | LL | use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:197:22 - | -LL | pub use crate::self as _self4; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use crate::self as _self4; -LL + pub use crate as _self4; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as _self4}; - | + + +LL | use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:21 + --> $DIR/use-path-segment-kw.rs:195:21 | LL | use crate::{self}; | ^^^^ @@ -367,46 +313,19 @@ help: try renaming it with a name LL | use crate::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:202:18 - | -LL | use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use super::self; -LL + use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:202:20 + --> $DIR/use-path-segment-kw.rs:199:20 | LL | use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:204:22 | -LL | pub use super::self as _self5; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self as _self5; -LL + pub use super as _self5; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as _self5}; - | + + +LL | use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:205:21 + --> $DIR/use-path-segment-kw.rs:201:21 | LL | use super::{self}; | ^^^^ @@ -416,46 +335,19 @@ help: try renaming it with a name LL | use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:209:17 - | -LL | use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use self::self; -LL + use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:209:19 + --> $DIR/use-path-segment-kw.rs:205:19 | LL | use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:211:21 - | -LL | pub use self::self as _self6; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use self::self as _self6; -LL + pub use self as _self6; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as _self6}; - | + + +LL | use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:212:20 + --> $DIR/use-path-segment-kw.rs:207:20 | LL | use self::{self}; | ^^^^ @@ -465,38 +357,6 @@ help: try renaming it with a name LL | use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:216:28 - | -LL | use crate::foo::bar::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self; -LL + use crate::foo::bar; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:217:28 - | -LL | use crate::foo::bar::self as _self7; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use crate::foo::bar::self as _self7; -LL + use crate::foo::bar as _self7; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use crate::foo::bar::{self as _self7}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:11:13 | @@ -864,26 +724,6 @@ LL | ... macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:63:19 - | -LL | use $crate::self; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - use $crate::self; -LL + use $crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use $crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-path-segment-kw.rs:63:21 | @@ -894,29 +734,13 @@ LL | macro_dollar_crate!(); | --------------------- in this macro invocation | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-path-segment-kw.rs:65:23 - | -LL | pub use $crate::self as _m_self8; - | ^^^^^^ -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider importing the module directly - | -LL - pub use $crate::self as _m_self8; -LL + pub use $crate as _m_self8; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use $crate::{self as _m_self8}; - | + + +LL | use $crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:66:22 + --> $DIR/use-path-segment-kw.rs:65:22 | LL | use $crate::{self}; | ^^^^ @@ -930,14 +754,8 @@ help: try renaming it with a name LL | use $crate::{self as name}; | +++++++ -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:215:36 - | -LL | type D7 = crate::foo::bar::self; - | ^^^^ can only be used in path start position - error[E0433]: cannot find `_nested_self2` in `bar` - --> $DIR/use-path-segment-kw.rs:241:15 + --> $DIR/use-path-segment-kw.rs:236:15 | LL | foo::bar::_nested_self2::outer(); | ^^^^^^^^^^^^^ could not find `_nested_self2` in `bar` @@ -953,36 +771,77 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0573]: expected type, found module `$crate::self` + --> $DIR/use-path-segment-kw.rs:62:20 + | +LL | type A10 = $crate::self; + | ^^^^^^^^^^^^ not a type +... +LL | macro_dollar_crate!(); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0573]: expected type, found module `crate` - --> $DIR/use-path-segment-kw.rs:96:19 + --> $DIR/use-path-segment-kw.rs:95:19 | LL | type B1 = crate; | ^^^^^ not a type error[E0573]: expected type, found module `super` - --> $DIR/use-path-segment-kw.rs:134:19 + --> $DIR/use-path-segment-kw.rs:133:19 | LL | type C1 = super; | ^^^^^ not a type error[E0573]: expected type, found module `super::super` - --> $DIR/use-path-segment-kw.rs:156:19 + --> $DIR/use-path-segment-kw.rs:155:19 | LL | type C5 = super::super; | ^^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self::super` - --> $DIR/use-path-segment-kw.rs:162:19 + --> $DIR/use-path-segment-kw.rs:161:19 | LL | type C6 = self::super; | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-path-segment-kw.rs:172:19 + --> $DIR/use-path-segment-kw.rs:171:19 | LL | type D1 = self; | ^^^^ not a type +error[E0573]: expected type, found module `foobar::self` + --> $DIR/use-path-segment-kw.rs:184:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:192:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:198:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:204:19 + | +LL | type D6 = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::foo::bar::self` + --> $DIR/use-path-segment-kw.rs:210:19 + | +LL | type D7 = crate::foo::bar::self; + | ^^^^^^^^^^^^^^^^^^^^^ not a type + error[E0433]: global paths cannot start with `$crate` --> $DIR/use-path-segment-kw.rs:14:21 | @@ -1071,96 +930,61 @@ LL | macro_dollar_crate!(); | = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:62:28 - | -LL | type A10 = $crate::self; - | ^^^^ can only be used in path start position -... -LL | macro_dollar_crate!(); - | --------------------- in this macro invocation - | - = note: this error originates in the macro `macro_dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0433]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 + --> $DIR/use-path-segment-kw.rs:175:21 | LL | type D2 = ::self; | ^^^^ cannot start with this -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 - | -LL | type D3 = foobar::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:194:26 - | -LL | type D4 = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:201:26 - | -LL | type D5 = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:208:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - -error: aborting due to 126 previous errors +error: aborting due to 114 previous errors -Some errors have detailed explanations: E0429, E0433, E0573. -For more information about an error, try `rustc --explain E0429`. +Some errors have detailed explanations: E0433, E0573. +For more information about an error, try `rustc --explain E0433`. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index be64f239b9fc3..d72c4e2c40c37 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -59,10 +59,9 @@ macro_rules! macro_dollar_crate { use $crate::{super}; //~ ERROR `super` in paths can only be used in start position, after `self`, or after another `super` use $crate::{super as _m_nested_super8}; //~ ERROR `super` in paths can only be used in start position, after `self`, or after another `super` - type A10 = $crate::self; //~ ERROR `self` in paths can only be used in start position + type A10 = $crate::self; //~ ERROR expected type, found module `$crate::self` use $crate::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use $crate::self as _m_self8; //~ ERROR `self` imports are only allowed within a { } list + pub use $crate::self as _m_self8; use $crate::{self}; //~ ERROR imports need to be explicitly named pub use $crate::{self as _m_nested_self8}; // Good } @@ -173,48 +172,44 @@ mod foo { use self; //~ ERROR imports need to be explicitly named pub use self as _self; - type D2 = ::self; //~ ERROR global paths cannot start with `self` + type D2 = ::self; //[e2018]~ ERROR global paths cannot start with `self` + //[e2015]~^ ERROR expected type, found module `self` use ::self; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported - //[e2015]~^ ERROR `self` imports are only allowed within a { } list use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named pub use ::{self as _nested_self2}; //[e2018]~ ERROR extern prelude cannot be imported - type D3 = foobar::self; //~ ERROR `self` in paths can only be used in start position - pub use foobar::qux::self; //~ ERROR `self` imports are only allowed within a { } list + type D3 = foobar::self; //~ ERROR expected type, found module `foobar::self` + pub use foobar::qux::self; + //[e2015]~^ ERROR cannot find module or crate `foobar` in the crate root + pub use foobar::self as _self3; //[e2015]~^ ERROR unresolved import `foobar` - pub use foobar::self as _self3; //~ ERROR `self` imports are only allowed within a { } list - //[e2015]~^ ERROR unresolved import `foobar` - pub use foobar::baz::{self}; //[e2015]~ ERROR unresolved import `foobar` + pub use foobar::baz::{self}; //[e2015]~ ERROR cannot find module or crate `foobar` in the crate root pub use foobar::{self as _nested_self3}; //[e2015]~ ERROR unresolved import `foobar` - type D4 = crate::self; //~ ERROR `self` in paths can only be used in start position + type D4 = crate::self; //~ ERROR expected type, found module `crate::self` use crate::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use crate::self as _self4; //~ ERROR `self` imports are only allowed within a { } list + pub use crate::self as _self4; use crate::{self}; //~ ERROR imports need to be explicitly named pub use crate::{self as _nested_self4}; // Good - type D5 = super::self; //~ ERROR `self` in paths can only be used in start position + type D5 = super::self; //~ ERROR expected type, found module `super::self` use super::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list - pub use super::self as _self5; //~ ERROR `self` imports are only allowed within a { } list + pub use super::self as _self5; use super::{self}; //~ ERROR imports need to be explicitly named pub use super::{self as _nested_self5}; - type D6 = self::self; //~ ERROR `self` in paths can only be used in start position - use self::self; //~ ERROR `self` imports are only allowed within a { } list - //~^ ERROR imports need to be explicitly named - pub use self::self as _self6; //~ ERROR `self` imports are only allowed within a { } list + type D6 = self::self; //~ ERROR expected type, found module `self::self` + use self::self; //~ ERROR imports need to be explicitly named + pub use self::self as _self6; use self::{self}; //~ ERROR imports need to be explicitly named pub use self::{self as _nested_self6}; - type D7 = crate::foo::bar::self; //~ ERROR `self` in paths can only be used in start position - use crate::foo::bar::self; //~ ERROR `self` imports are only allowed within a { } list - use crate::foo::bar::self as _self7; //~ ERROR `self` imports are only allowed within a { } list + type D7 = crate::foo::bar::self; //~ ERROR expected type, found module `crate::foo::bar::self` + use crate::foo::bar::self; + use crate::foo::bar::self as _self7; use crate::foo::{bar::foobar::quxbaz::self}; use crate::foo::{bar::foobar::quxbaz::self as _nested_self7}; } diff --git a/tests/ui/use/use-super-in-middle.rs b/tests/ui/use/use-super-in-middle.rs index be9f3675c323f..2e964b09f6b7c 100644 --- a/tests/ui/use/use-super-in-middle.rs +++ b/tests/ui/use/use-super-in-middle.rs @@ -1,13 +1,13 @@ pub mod x { pub use crate::x::super::{self as crate1}; //~ ERROR `super` in paths can only be used in start position - pub use crate::x::self::super::{self as crate2}; //~ ERROR `super` in paths can only be used in start position + pub use crate::x::self::super::{self as crate2}; //~ ERROR `self` in paths can only be used in start position pub fn foo() {} } fn main() { - x::crate1::x::foo(); //~ ERROR cannot find `crate1` in `x` - x::crate2::x::foo(); //~ ERROR cannot find `crate2` in `x` + x::crate1::x::foo(); + x::crate2::x::foo(); crate::x::super::x::foo(); //~ ERROR `super` in paths can only be used in start position crate::x::self::super::x::foo(); //~ ERROR `self` in paths can only be used in start position diff --git a/tests/ui/use/use-super-in-middle.stderr b/tests/ui/use/use-super-in-middle.stderr index 276b1274f6a89..af28edd48b44e 100644 --- a/tests/ui/use/use-super-in-middle.stderr +++ b/tests/ui/use/use-super-in-middle.stderr @@ -1,26 +1,14 @@ -error: `super` in paths can only be used in start position, after `self`, or after another `super` +error[E0433]: `super` in paths can only be used in start position --> $DIR/use-super-in-middle.rs:2:23 | LL | pub use crate::x::super::{self as crate1}; - | ^^^^^ + | ^^^^^ can only be used in path start position -error: `super` in paths can only be used in start position, after `self`, or after another `super` - --> $DIR/use-super-in-middle.rs:3:29 +error[E0433]: `self` in paths can only be used in start position + --> $DIR/use-super-in-middle.rs:3:23 | LL | pub use crate::x::self::super::{self as crate2}; - | ^^^^^ - -error[E0433]: cannot find `crate1` in `x` - --> $DIR/use-super-in-middle.rs:9:8 - | -LL | x::crate1::x::foo(); - | ^^^^^^ could not find `crate1` in `x` - -error[E0433]: cannot find `crate2` in `x` - --> $DIR/use-super-in-middle.rs:10:8 - | -LL | x::crate2::x::foo(); - | ^^^^^^ could not find `crate2` in `x` + | ^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position --> $DIR/use-super-in-middle.rs:12:15 @@ -34,6 +22,6 @@ error[E0433]: `self` in paths can only be used in start position LL | crate::x::self::super::x::foo(); | ^^^^ can only be used in path start position -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0433`. From 1d43b7d565d8205d875b6eccdcceeb5485d4cb3e Mon Sep 17 00:00:00 2001 From: mu001999 Date: Thu, 26 Feb 2026 10:27:33 +0800 Subject: [PATCH 4/4] Print leading :: --- compiler/rustc_resolve/src/lib.rs | 6 +++++- .../resolve/dot-notation-type-namespace-suggest-path-sep.rs | 6 +++--- .../dot-notation-type-namespace-suggest-path-sep.stderr | 6 +++--- tests/ui/resolve/issue-100365.rs | 4 ++-- tests/ui/resolve/issue-100365.stderr | 4 ++-- tests/ui/resolve/resolve-bad-visibility.rs | 4 ++-- tests/ui/resolve/resolve-bad-visibility.stderr | 4 ++-- .../rfcs/rfc-2126-extern-absolute-paths/single-segment.rs | 2 +- .../rfc-2126-extern-absolute-paths/single-segment.stderr | 2 +- tests/ui/use/use-path-segment-kw.e2015.stderr | 2 +- tests/ui/use/use-path-segment-kw.rs | 2 +- 11 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 8d8a0f9f5e6c3..c001227b979e8 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2502,7 +2502,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { fn names_to_string(names: impl Iterator) -> String { let mut result = String::new(); - for (i, name) in names.filter(|name| *name != kw::PathRoot).enumerate() { + for (i, name) in names.enumerate() { + if name == kw::PathRoot { + continue; + } + if i > 0 { result.push_str("::"); } diff --git a/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.rs b/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.rs index 432e3c0b77efc..e9ff6306e16c2 100644 --- a/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.rs +++ b/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.rs @@ -35,9 +35,9 @@ fn main() { macro_rules! Type { () => { ::std::cell::Cell - //~^ ERROR expected value, found struct `std::cell::Cell` - //~| ERROR expected value, found struct `std::cell::Cell` - //~| ERROR expected value, found struct `std::cell::Cell` + //~^ ERROR expected value, found struct `::std::cell::Cell` + //~| ERROR expected value, found struct `::std::cell::Cell` + //~| ERROR expected value, found struct `::std::cell::Cell` }; (alias) => { Alias diff --git a/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.stderr b/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.stderr index d74814dd876c2..e0e2c3a5fd822 100644 --- a/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.stderr +++ b/tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.stderr @@ -70,7 +70,7 @@ LL - let _ = foo.bar; LL + let _ = foo::bar; | -error[E0423]: expected value, found struct `std::cell::Cell` +error[E0423]: expected value, found struct `::std::cell::Cell` --> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:37:9 | LL | ::std::cell::Cell @@ -86,7 +86,7 @@ LL - Type!().get(); LL + ::get(); | -error[E0423]: expected value, found struct `std::cell::Cell` +error[E0423]: expected value, found struct `::std::cell::Cell` --> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:37:9 | LL | ::std::cell::Cell @@ -166,7 +166,7 @@ LL - Vec.new LL + Vec::new | -error[E0423]: expected value, found struct `std::cell::Cell` +error[E0423]: expected value, found struct `::std::cell::Cell` --> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:37:9 | LL | ::std::cell::Cell diff --git a/tests/ui/resolve/issue-100365.rs b/tests/ui/resolve/issue-100365.rs index 1d8835036065b..2ecaf93601013 100644 --- a/tests/ui/resolve/issue-100365.rs +++ b/tests/ui/resolve/issue-100365.rs @@ -15,8 +15,8 @@ fn main() { macro_rules! Trait { () => { ::std::iter::Iterator - //~^ ERROR expected value, found trait `std::iter::Iterator` - //~| ERROR expected value, found trait `std::iter::Iterator` + //~^ ERROR expected value, found trait `::std::iter::Iterator` + //~| ERROR expected value, found trait `::std::iter::Iterator` }; } diff --git a/tests/ui/resolve/issue-100365.stderr b/tests/ui/resolve/issue-100365.stderr index 7a880c6f31acd..7dea31713df2f 100644 --- a/tests/ui/resolve/issue-100365.stderr +++ b/tests/ui/resolve/issue-100365.stderr @@ -34,7 +34,7 @@ LL - let _ = Into::<()>.into; LL + let _ = Into::<()>::into; | -error[E0423]: expected value, found trait `std::iter::Iterator` +error[E0423]: expected value, found trait `::std::iter::Iterator` --> $DIR/issue-100365.rs:17:9 | LL | ::std::iter::Iterator @@ -45,7 +45,7 @@ LL | Trait!().map(std::convert::identity); // no `help` here! | = note: this error originates in the macro `Trait` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0423]: expected value, found trait `std::iter::Iterator` +error[E0423]: expected value, found trait `::std::iter::Iterator` --> $DIR/issue-100365.rs:17:9 | LL | ::std::iter::Iterator diff --git a/tests/ui/resolve/resolve-bad-visibility.rs b/tests/ui/resolve/resolve-bad-visibility.rs index 55e381e8be1a1..bfc5e90c31e71 100644 --- a/tests/ui/resolve/resolve-bad-visibility.rs +++ b/tests/ui/resolve/resolve-bad-visibility.rs @@ -2,8 +2,8 @@ enum E {} trait Tr {} -pub(in E) struct S; //~ ERROR expected module, found enum `E` -pub(in Tr) struct Z; //~ ERROR expected module, found trait `Tr` +pub(in E) struct S; //~ ERROR expected module, found enum `::E` +pub(in Tr) struct Z; //~ ERROR expected module, found trait `::Tr` pub(in std::vec) struct F; //~ ERROR visibilities can only be restricted to ancestor modules pub(in nonexistent) struct G; //~ ERROR cannot find pub(in too_soon) struct H; //~ ERROR cannot find diff --git a/tests/ui/resolve/resolve-bad-visibility.stderr b/tests/ui/resolve/resolve-bad-visibility.stderr index 4530757c3de55..d9fd4400b8e0e 100644 --- a/tests/ui/resolve/resolve-bad-visibility.stderr +++ b/tests/ui/resolve/resolve-bad-visibility.stderr @@ -1,10 +1,10 @@ -error[E0577]: expected module, found enum `E` +error[E0577]: expected module, found enum `::E` --> $DIR/resolve-bad-visibility.rs:5:8 | LL | pub(in E) struct S; | ^ not a module -error[E0577]: expected module, found trait `Tr` +error[E0577]: expected module, found trait `::Tr` --> $DIR/resolve-bad-visibility.rs:6:8 | LL | pub(in Tr) struct Z; diff --git a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.rs b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.rs index 0828927a3976e..b773e419b16dd 100644 --- a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.rs +++ b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.rs @@ -6,6 +6,6 @@ use crate; //~ ERROR imports need to be explicitly named use *; //~ ERROR cannot glob-import all possible crates fn main() { - let s = ::xcrate; //~ ERROR expected value, found crate `xcrate` + let s = ::xcrate; //~ ERROR expected value, found crate `::xcrate` //~^ NOTE not a value } diff --git a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.stderr b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.stderr index 13eb4e25ed6bb..fcd18a847d910 100644 --- a/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.stderr +++ b/tests/ui/rfcs/rfc-2126-extern-absolute-paths/single-segment.stderr @@ -15,7 +15,7 @@ error: cannot glob-import all possible crates LL | use *; | ^ -error[E0423]: expected value, found crate `xcrate` +error[E0423]: expected value, found crate `::xcrate` --> $DIR/single-segment.rs:9:13 | LL | let s = ::xcrate; diff --git a/tests/ui/use/use-path-segment-kw.e2015.stderr b/tests/ui/use/use-path-segment-kw.e2015.stderr index 91b5a68d672fb..1ce5477e5d08a 100644 --- a/tests/ui/use/use-path-segment-kw.e2015.stderr +++ b/tests/ui/use/use-path-segment-kw.e2015.stderr @@ -848,7 +848,7 @@ error[E0573]: expected type, found module `self` LL | type D1 = self; | ^^^^ not a type -error[E0573]: expected type, found module `self` +error[E0573]: expected type, found module `::self` --> $DIR/use-path-segment-kw.rs:175:19 | LL | type D2 = ::self; diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index d72c4e2c40c37..9dacc6ec9ccb4 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -173,7 +173,7 @@ mod foo { pub use self as _self; type D2 = ::self; //[e2018]~ ERROR global paths cannot start with `self` - //[e2015]~^ ERROR expected type, found module `self` + //[e2015]~^ ERROR expected type, found module `::self` use ::self; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported