From d2569702257a1180d37ffbfaa7778ea12bcec6ba Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sun, 26 Oct 2025 19:49:41 +0800 Subject: [PATCH 1/3] Rewrite build_reduced_graph_for_use_tree --- compiler/rustc_resolve/messages.ftl | 11 +- .../rustc_resolve/src/build_reduced_graph.rs | 160 ++-- compiler/rustc_resolve/src/diagnostics.rs | 6 - compiler/rustc_resolve/src/errors.rs | 37 +- compiler/rustc_resolve/src/ident.rs | 22 +- compiler/rustc_resolve/src/lib.rs | 4 - tests/ui/use/use-path-segment-kw.rs | 177 ++++ tests/ui/use/use-path-segment-kw.stderr | 754 ++++++++++++++++++ 8 files changed, 1053 insertions(+), 118 deletions(-) create mode 100644 tests/ui/use/use-path-segment-kw.rs create mode 100644 tests/ui/use/use-path-segment-kw.stderr diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index 5bf90d2637df5..a31c91029d636 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -373,14 +373,6 @@ resolve_remove_surrounding_derive = resolve_remove_unnecessary_import = remove unnecessary import -resolve_self_import_can_only_appear_once_in_the_list = - `self` import can only appear once in an import list - .label = can only appear once in an import list - -resolve_self_import_only_in_import_list_with_non_empty_prefix = - `self` import can only appear in an import list with a non-empty prefix - .label = can only appear in an import list with a non-empty prefix - resolve_self_imports_only_allowed_within = `self` imports are only allowed within a {"{"} {"}"} list @@ -463,6 +455,9 @@ resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg = resolve_unnamed_crate_root_import = crate root imports need to be explicitly named: `use crate as name;` +resolve_unnamed_super_or_self_import = imports need to be explicitly named +resolve_unnamed_super_or_self_sugg_import = try renaming it with a name + resolve_unreachable_label = use of unreachable label `{$name}` .label = unreachable label `{$name}` diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 88fbc6dcb6650..3e3aefece1a4b 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -572,63 +572,54 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { let mut ident = use_tree.ident(); let mut module_path = prefix; let mut source = module_path.pop().unwrap(); - let mut type_ns_only = false; - - if nested { - // Correctly handle `self` - if source.ident.name == kw::SelfLower { - type_ns_only = true; - - if empty_for_self(&module_path) { - self.r.report_error( - use_tree.span, - ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix, + let type_ns_only = nested + && source.ident.name == kw::SelfLower + && use_tree.prefix.segments.len() == 1; + + match source.ident.name { + kw::Crate => { + if !module_path.is_empty() { + self.r.dcx().span_err( + source.ident.span, + "`crate` in paths can only be used in start position", ); return; } - - // Replace `use foo::{ self };` with `use foo;` - let self_span = source.ident.span; - source = module_path.pop().unwrap(); - if rename.is_none() { - // Keep the span of `self`, but the name of `foo` - ident = Ident::new(source.ident.name, self_span); - } } - } else { - // Disallow `self` - if source.ident.name == kw::SelfLower { - let parent = module_path.last(); - - let span = match parent { - // only `::self` from `use foo::self as bar` - Some(seg) => seg.ident.span.shrink_to_hi().to(source.ident.span), - None => source.ident.span, - }; - let span_with_rename = match rename { - // only `self as bar` from `use foo::self as bar` - Some(rename) => source.ident.span.to(rename.span), - None => source.ident.span, - }; - self.r.report_error( - span, - ResolutionError::SelfImportsOnlyAllowedWithin { - root: parent.is_none(), - span_with_rename, - }, - ); - - // Error recovery: replace `use foo::self;` with `use foo;` + kw::SelfLower => { if let Some(parent) = module_path.pop() { + let span_with_rename = match rename { + Some(rename) => source.ident.span.to(rename.span), + None => source.ident.span, + }; + + // Suggest `use prefix::{self};` for `use prefix::self;` + if !type_ns_only && parent.ident.name != kw::PathRoot { + self.r.report_error( + parent.ident.span.shrink_to_hi().to(source.ident.span), + ResolutionError::SelfImportsOnlyAllowedWithin { + root: false, + span_with_rename, + }, + ); + } + + let self_span = source.ident.span; source = parent; if rename.is_none() { - ident = source.ident; + ident = Ident::new(source.ident.name, self_span); } } } + kw::DollarCrate => { + if !module_path.is_empty() { + self.r.dcx().span_err( + source.ident.span, + "`$crate` in paths can only be used in start position", + ); + return; + } - // Disallow `use $crate;` - if source.ident.name == kw::DollarCrate && module_path.is_empty() { let crate_root = self.r.resolve_crate_root(source.ident); let crate_name = match crate_root.kind { ModuleKind::Def(.., name) => name, @@ -645,16 +636,53 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { )); source.ident.name = crate_name; } - if rename.is_none() { - ident.name = sym::dummy; - } - - self.r.dcx().emit_err(errors::CrateImported { span: item.span }); } + _ => {} } - if ident.name == kw::Crate { - self.r.dcx().emit_err(errors::UnnamedCrateRootImport { span: ident.span }); + // Deny `use ::{self};` + if source.ident.name == kw::PathRoot { + self.r.dcx().span_err(use_tree.span, "crate root cannot be imported"); + return; + } + + if rename.is_none() { + match ident.name { + // Deny `use crate;` and `use crate::{self};` + kw::Crate => { + self.r + .dcx() + .emit_err(errors::UnnamedCrateRootImport { span: ident.span }); + return; + } + // Deny `use $crate;` and `use $crate::{self};` + kw::DollarCrate => { + self.r.dcx().emit_err(errors::CrateImported { span: ident.span }); + return; + } + // Deny `use super;`, `use super::{self};`, `use self;` and `use self::{self};` + kw::Super | kw::SelfLower => { + let ident = use_tree.ident(); + + // Don't suggest `use super::self as name;` for `use super::self;` + // But it's OK to suggest `use super::{self as name};` for `use super::{self};` + let sugg = if !type_ns_only && ident.name == kw::SelfLower { + None + } else { + Some(errors::UnnamedSuperOrSelfImportSugg { + span: ident.span, + ident, + }) + }; + + self.r.dcx().emit_err(errors::UnnamedSuperOrSelfImport { + span: ident.span, + sugg, + }); + return; + } + _ => (), + } } let kind = ImportKind::Single { @@ -684,32 +712,6 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { } } ast::UseTreeKind::Nested { ref items, .. } => { - // Ensure there is at most one `self` in the list - let self_spans = items - .iter() - .filter_map(|(use_tree, _)| { - if let ast::UseTreeKind::Simple(..) = use_tree.kind - && use_tree.ident().name == kw::SelfLower - { - return Some(use_tree.span); - } - - None - }) - .collect::>(); - if self_spans.len() > 1 { - let mut e = self.r.into_struct_error( - self_spans[0], - ResolutionError::SelfImportCanOnlyAppearOnceInTheList, - ); - - for other_span in self_spans.iter().skip(1) { - e.span_label(*other_span, "another `self` import appears here"); - } - - e.emit(); - } - for &(ref tree, id) in items { self.build_reduced_graph_for_use_tree( // This particular use tree diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 236ab1f09d35f..68b06ca9457b4 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -890,12 +890,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { mpart_suggestion, }) } - ResolutionError::SelfImportCanOnlyAppearOnceInTheList => { - self.dcx().create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span }) - } - ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => { - self.dcx().create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }) - } ResolutionError::FailedToResolve { segment, label, suggestion, module } => { let mut err = struct_span_code_err!(self.dcx(), span, E0433, "failed to resolve: {label}"); diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index f0ea97ba8a0c0..db88bd5e70401 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -204,22 +204,6 @@ pub(crate) struct UnreachableLabelWithSimilarNameExists { pub(crate) ident_span: Span, } -#[derive(Diagnostic)] -#[diag(resolve_self_import_can_only_appear_once_in_the_list, code = E0430)] -pub(crate) struct SelfImportCanOnlyAppearOnceInTheList { - #[primary_span] - #[label] - pub(crate) span: Span, -} - -#[derive(Diagnostic)] -#[diag(resolve_self_import_only_in_import_list_with_non_empty_prefix, code = E0431)] -pub(crate) struct SelfImportOnlyInImportListWithNonEmptyPrefix { - #[primary_span] - #[label] - pub(crate) span: Span, -} - #[derive(Diagnostic)] #[diag(resolve_cannot_capture_dynamic_environment_in_fn_item, code = E0434)] #[help] @@ -898,6 +882,27 @@ pub(crate) struct UnnamedCrateRootImport { pub(crate) span: Span, } +#[derive(Subdiagnostic)] +#[multipart_suggestion( + resolve_unnamed_super_or_self_sugg_import, + applicability = "maybe-incorrect", + style = "verbose" +)] +pub(crate) struct UnnamedSuperOrSelfImportSugg { + #[suggestion_part(code = "{ident} as name")] + pub(crate) span: Span, + pub(crate) ident: Ident, +} + +#[derive(Diagnostic)] +#[diag(resolve_unnamed_super_or_self_import)] +pub(crate) struct UnnamedSuperOrSelfImport { + #[primary_span] + pub(crate) span: Span, + #[subdiagnostic] + pub(crate) sugg: Option, +} + #[derive(Diagnostic)] #[diag(resolve_macro_expanded_extern_crate_cannot_shadow_extern_arguments)] pub(crate) struct MacroExpandedExternCrateCannotShadowExternArguments { diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 2a195c8068dac..50bda6da13c56 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -828,7 +828,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ignore_import: Option>, ) -> Result, (Determinacy, Weak)> { let module = match module { - ModuleOrUniformRoot::Module(module) => module, + ModuleOrUniformRoot::Module(module) => { + if ns == TypeNS { + if ident.name == kw::Super { + if let Some(parent) = module.parent { + return Ok(parent.self_binding.unwrap()); + } + } + } + + module + } ModuleOrUniformRoot::ModuleAndExternPrelude(module) => { assert_eq!(shadowing, Shadowing::Unrestricted); let binding = self.resolve_ident_in_scope_set( @@ -865,10 +875,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if ident.name == kw::Crate || ident.name == kw::DollarCrate { let module = self.resolve_crate_root(ident); return Ok(module.self_binding.unwrap()); - } else if ident.name == kw::Super || ident.name == kw::SelfLower { - // 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_...`. + } else if ident.name == kw::Super { + if let Some(parent) = parent_scope.module.parent { + return Ok(parent.self_binding.unwrap()); + } + } else if ident.name == kw::SelfLower { + return Ok(parent_scope.module.self_binding.unwrap()); } } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 1636605b234f4..e2c37c2d1b4b6 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -263,10 +263,6 @@ enum ResolutionError<'ra> { UndeclaredLabel { name: Symbol, suggestion: Option }, /// Error E0429: `self` imports are only allowed within a `{ }` list. SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span }, - /// Error E0430: `self` import can only appear once in the list. - SelfImportCanOnlyAppearOnceInTheList, - /// Error E0431: `self` import can only appear in an import list with a non-empty prefix. - SelfImportOnlyInImportListWithNonEmptyPrefix, /// Error E0433: failed to resolve. FailedToResolve { segment: Option, diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs new file mode 100644 index 0000000000000..f6108c67c8b44 --- /dev/null +++ b/tests/ui/use/use-path-segment-kw.rs @@ -0,0 +1,177 @@ +//@ edition: 2021 + +macro_rules! macro_dollar_crate { + ($m: ident) => { + use $crate; //~ ERROR `$crate` may not be imported + pub use $crate as _dollar_crate; // Good + + use ::$crate; //~ ERROR `$crate` in paths can only be used in start position + use ::$crate as _dollar_crate2; //~ ERROR `$crate` in paths can only be used in start position + use ::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use ::{$crate as _nested_dollar_crate2}; //~ ERROR `$crate` in paths can only be used in start position + + use $m::$crate; //~ ERROR `$crate` in paths can only be used in start position + use $m::$crate as _dollar_crate3; //~ ERROR `$crate` in paths can only be used in start position + use $m::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use $m::{$crate as _nested_dollar_crate3}; //~ ERROR `$crate` in paths can only be used in start position + + use crate::$crate; //~ ERROR `$crate` in paths can only be used in start position + use crate::$crate as _dollar_crate4; //~ ERROR `$crate` in paths can only be used in start position + use crate::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use crate::{$crate as _nested_dollar_crate4}; //~ ERROR `$crate` in paths can only be used in start position + + use super::$crate; //~ ERROR `$crate` in paths can only be used in start position + use super::$crate as _dollar_crate5; //~ ERROR `$crate` in paths can only be used in start position + use super::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use super::{$crate as _nested_dollar_crate5}; //~ ERROR `$crate` in paths can only be used in start position + + use self::$crate; //~ ERROR `$crate` in paths can only be used in start position + use self::$crate as _dollar_crate6; //~ ERROR `$crate` in paths can only be used in start position + use self::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use self::{$crate as _nested_dollar_crate6}; //~ ERROR `$crate` in paths can only be used in start position + + use $crate::$crate; //~ ERROR `$crate` in paths can only be used in start position + use $crate::$crate as _dollar_crate7; //~ ERROR `$crate` in paths can only be used in start position + use $crate::{$crate}; //~ ERROR `$crate` in paths can only be used in start position + use $crate::{$crate as _nested_dollar_crate7}; //~ ERROR `$crate` in paths can only be used in start position + } +} + +fn outer() {} + +mod foo { + pub mod bar { + pub mod foobar { + pub mod qux { + pub use super::inner; + } + + pub mod baz { + pub use super::inner; + } + + pub fn inner() {} + } + + // --- $crate --- + macro_dollar_crate!(foobar); + + // --- crate --- + use crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;` + pub use crate as _crate; // Good + + use ::crate; //~ ERROR `crate` in paths can only be used in start position + use ::crate as _crate2; //~ ERROR `crate` in paths can only be used in start position + use ::{crate}; //~ ERROR `crate` in paths can only be used in start position + use ::{crate as _nested_crate2}; //~ ERROR `crate` in paths can only be used in start position + + use foobar::crate; //~ ERROR `crate` in paths can only be used in start position + use foobar::crate as _crate3; //~ ERROR `crate` in paths can only be used in start position + use foobar::{crate}; //~ ERROR `crate` in paths can only be used in start position + use foobar::{crate as _nested_crate3}; //~ ERROR `crate` in paths can only be used in start position + + use crate::crate; //~ ERROR `crate` in paths can only be used in start position + use crate::crate as _crate4; //~ ERROR `crate` in paths can only be used in start position + use crate::{crate}; //~ ERROR `crate` in paths can only be used in start position + use crate::{crate as _nested_crate4}; //~ ERROR `crate` in paths can only be used in start position + + use super::crate; //~ ERROR `crate` in paths can only be used in start position + use super::crate as _crate5; //~ ERROR `crate` in paths can only be used in start position + use super::{crate}; //~ ERROR `crate` in paths can only be used in start position + use super::{crate as _nested_crate5}; //~ ERROR `crate` in paths can only be used in start position + + use self::crate; //~ ERROR `crate` in paths can only be used in start position + use self::crate as _crate6; //~ ERROR `crate` in paths can only be used in start position + use self::{crate}; //~ ERROR `crate` in paths can only be used in start position + use self::{crate as _nested_crate6}; //~ ERROR `crate` in paths can only be used in start position + + // --- super --- + use super; //~ ERROR imports need to be explicitly named + pub use super as _super; // Good + + use ::super; //~ ERROR imports need to be explicitly named + use ::super as _super2; //~ ERROR unresolved import `super` + use ::{super}; //~ ERROR imports need to be explicitly named + use ::{super as _nested_super2}; //~ ERROR unresolved import `super` + + use foobar::super; //~ ERROR imports need to be explicitly named + pub use foobar::super as _super3; // Good + use foobar::{super}; //~ ERROR imports need to be explicitly named + pub use foobar::{super as _nested_super3}; // Good + + use crate::super; //~ ERROR imports need to be explicitly named + use crate::super as _super4; //~ ERROR unresolved import `crate::super` + use crate::{super}; //~ ERROR imports need to be explicitly named + use crate::{super as _nested_super4}; //~ ERROR unresolved import `crate::super` + + use super::super; //~ ERROR imports need to be explicitly named + pub use super::super as _super5; // Good + use super::{super}; //~ ERROR imports need to be explicitly named + pub use super::{super as _nested_super5}; // Good + + use self::super; //~ ERROR imports need to be explicitly named + pub use self::super as _super6; // Good + use self::{super}; //~ ERROR imports need to be explicitly named + pub use self::{super as _nested_super6}; // Good + + // --- self --- + use self; //~ ERROR imports need to be explicitly named + pub use self as _self; // Good + + use ::self; //~ ERROR crate root cannot be imported + use ::self as _self2; //~ ERROR crate root cannot be imported + use ::{self}; //~ ERROR crate root cannot be imported + use ::{self as _nested_self2}; //~ ERROR crate root cannot be imported + + pub use foobar::qux::self; //~ ERROR `self` imports are only allowed within a { } list + pub use foobar::self as _self3; //~ ERROR `self` imports are only allowed within a { } list + pub use foobar::baz::{self}; // Good + pub use foobar::{self as _nested_self3}; // Good + + use crate::self; //~ ERROR crate root imports need to be explicitly named: `use crate as name;` + //~^ ERROR `self` imports are only allowed within a { } list + pub use crate::self as _self4; //~ ERROR `self` imports are only allowed within a { } list + use crate::{self}; //~ ERROR crate root imports need to be explicitly named: `use crate as name;` + pub use crate::{self as _nested_self4}; // Good + + 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 + use super::{self}; //~ ERROR imports need to be explicitly named + pub use super::{self as _nested_self5}; // Good + + use self::self; //~ ERROR imports need to be explicitly named + //~^ ERROR `self` imports are only allowed within a { } list + pub use self::self as _self6; //~ ERROR `self` imports are only allowed within a { } list + use self::{self}; //~ ERROR imports need to be explicitly named + pub use self::{self as _nested_self6}; // Good + } +} + +fn main() { + foo::bar::_dollar_crate::outer(); + foo::bar::_dollar_crate::foo::bar::foobar::inner(); + + foo::bar::_crate::outer(); + foo::bar::_crate::foo::bar::foobar::inner(); + + foo::bar::_super::bar::foobar::inner(); + foo::bar::_super3::foobar::inner(); + foo::bar::_nested_super3::foobar::inner(); + foo::bar::_super5::outer(); + foo::bar::_nested_super5::outer(); + foo::bar::_super6::bar::foobar::inner(); + foo::bar::_nested_super6::bar::foobar::inner(); + + foo::bar::_self::foobar::inner(); + foo::bar::qux::inner(); // Works after recovery + foo::bar::baz::inner(); + foo::bar::_self3::inner(); // Works after recovery + foo::bar::_nested_self3::inner(); + foo::bar::_self4::outer(); // Works after recovery + foo::bar::_nested_self4::outer(); + foo::bar::_self5::bar::foobar::inner(); // Works after recovery + foo::bar::_nested_self5::bar::foobar::inner(); + foo::bar::_self6::foobar::inner(); // Works after recovery + foo::bar::_nested_self6::foobar::inner(); +} diff --git a/tests/ui/use/use-path-segment-kw.stderr b/tests/ui/use/use-path-segment-kw.stderr new file mode 100644 index 0000000000000..4fc974053c7e1 --- /dev/null +++ b/tests/ui/use/use-path-segment-kw.stderr @@ -0,0 +1,754 @@ +error: crate root imports need to be explicitly named: `use crate as name;` + --> $DIR/use-path-segment-kw.rs:60:13 + | +LL | use crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:63:15 + | +LL | use ::crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:64:15 + | +LL | use ::crate as _crate2; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:65:16 + | +LL | use ::{crate}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:66:16 + | +LL | use ::{crate as _nested_crate2}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:68:21 + | +LL | use foobar::crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:69:21 + | +LL | use foobar::crate as _crate3; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:70:22 + | +LL | use foobar::{crate}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:71: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:73:20 + | +LL | use crate::crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:74:20 + | +LL | use crate::crate as _crate4; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:75:21 + | +LL | use crate::{crate}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:76: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:78:20 + | +LL | use super::crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:79:20 + | +LL | use super::crate as _crate5; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:80:21 + | +LL | use super::{crate}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:81: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:83:19 + | +LL | use self::crate; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:84:19 + | +LL | use self::crate as _crate6; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:85:20 + | +LL | use self::{crate}; + | ^^^^^ + +error: `crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:86:20 + | +LL | use self::{crate as _nested_crate6}; + | ^^^^^ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:89:13 + | +LL | use super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:92:15 + | +LL | use ::super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use ::super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:94:16 + | +LL | use ::{super}; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use ::{super as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:97:21 + | +LL | use foobar::super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use foobar::super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:99:22 + | +LL | use foobar::{super}; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use foobar::{super as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:102:20 + | +LL | use crate::super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use crate::super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:104:21 + | +LL | use crate::{super}; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use crate::{super as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:107:20 + | +LL | use super::super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use super::super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:109:21 + | +LL | use super::{super}; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use super::{super as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:112:19 + | +LL | use self::super; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use self::super as name; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:114:20 + | +LL | use self::{super}; + | ^^^^^ + | +help: try renaming it with a name + | +LL | use self::{super as name}; + | +++++++ + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:118:13 + | +LL | use self; + | ^^^^ + +error: crate root cannot be imported + --> $DIR/use-path-segment-kw.rs:121:13 + | +LL | use ::self; + | ^^^^^^ + +error: crate root cannot be imported + --> $DIR/use-path-segment-kw.rs:122:13 + | +LL | use ::self as _self2; + | ^^^^^^^^^^^^^^^^ + +error: crate root cannot be imported + --> $DIR/use-path-segment-kw.rs:123:16 + | +LL | use ::{self}; + | ^^^^ + +error: crate root cannot be imported + --> $DIR/use-path-segment-kw.rs:124:16 + | +LL | use ::{self as _nested_self2}; + | ^^^^^^^^^^^^^^^^^^^^^ + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-path-segment-kw.rs:126: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:127: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:131: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: crate root imports need to be explicitly named: `use crate as name;` + --> $DIR/use-path-segment-kw.rs:131:20 + | +LL | use crate::self; + | ^^^^ + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-path-segment-kw.rs:133: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` + | +LL | pub use crate::{self as _self4}; + | + + + +error: crate root imports need to be explicitly named: `use crate as name;` + --> $DIR/use-path-segment-kw.rs:134:21 + | +LL | use crate::{self}; + | ^^^^ + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-path-segment-kw.rs:137: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:137:20 + | +LL | use super::self; + | ^^^^ + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-path-segment-kw.rs:139: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` + | +LL | pub use super::{self as _self5}; + | + + + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:140:21 + | +LL | use super::{self}; + | ^^^^ + | +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:143: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:143:19 + | +LL | use self::self; + | ^^^^ + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-path-segment-kw.rs:145: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` + | +LL | pub use self::{self as _self6}; + | + + + +error: imports need to be explicitly named + --> $DIR/use-path-segment-kw.rs:146:20 + | +LL | use self::{self}; + | ^^^^ + | +help: try renaming it with a name + | +LL | use self::{self as name}; + | +++++++ + +error: `$crate` may not be imported + --> $DIR/use-path-segment-kw.rs:5:13 + | +LL | use $crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:8:15 + | +LL | use ::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:9:15 + | +LL | use ::$crate as _dollar_crate2; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:10:16 + | +LL | use ::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:11:16 + | +LL | use ::{$crate as _nested_dollar_crate2}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:13:17 + | +LL | use $m::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:14:17 + | +LL | use $m::$crate as _dollar_crate3; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:15:18 + | +LL | use $m::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:16:18 + | +LL | use $m::{$crate as _nested_dollar_crate3}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:18:20 + | +LL | use crate::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:19:20 + | +LL | use crate::$crate as _dollar_crate4; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:20:21 + | +LL | use crate::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:21:21 + | +LL | use crate::{$crate as _nested_dollar_crate4}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:23:20 + | +LL | use super::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:24:20 + | +LL | use super::$crate as _dollar_crate5; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:25:21 + | +LL | use super::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:26:21 + | +LL | use super::{$crate as _nested_dollar_crate5}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:28:19 + | +LL | use self::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:29:19 + | +LL | use self::$crate as _dollar_crate6; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:30:20 + | +LL | use self::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:31:20 + | +LL | use self::{$crate as _nested_dollar_crate6}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:33:21 + | +LL | use $crate::$crate; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:34:21 + | +LL | use $crate::$crate as _dollar_crate7; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:35:22 + | +LL | use $crate::{$crate}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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: `$crate` in paths can only be used in start position + --> $DIR/use-path-segment-kw.rs:36:22 + | +LL | use $crate::{$crate as _nested_dollar_crate7}; + | ^^^^^^ +... +LL | macro_dollar_crate!(foobar); + | --------------------------- 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[E0432]: unresolved import `super` + --> $DIR/use-path-segment-kw.rs:93:13 + | +LL | use ::super as _super2; + | ^^^^^^^^^^^^^^^^^^ no `super` in the root + +error[E0432]: unresolved import `super` + --> $DIR/use-path-segment-kw.rs:95:16 + | +LL | use ::{super as _nested_super2}; + | ^^^^^^^^^^^^^^^^^^^^^^^ no `super` in the root + +error[E0432]: unresolved import `crate::super` + --> $DIR/use-path-segment-kw.rs:103:13 + | +LL | use crate::super as _super4; + | ^^^^^^^^^^^^^^^^^^^^^^^ no `super` in the root + +error[E0432]: unresolved import `crate::super` + --> $DIR/use-path-segment-kw.rs:105:21 + | +LL | use crate::{super as _nested_super4}; + | ^^^^^^^^^^^^^^^^^^^^^^^ no `super` in the root + +error: aborting due to 80 previous errors + +Some errors have detailed explanations: E0429, E0432. +For more information about an error, try `rustc --explain E0429`. From 3edfefd50eb72ecd69ded6b3b80506fbfc480868 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 1 Nov 2025 21:27:31 +0800 Subject: [PATCH 2/3] Bless other tests --- tests/ui/delegation/target-expr-pass.rs | 2 +- .../dollar-crate/dollar-crate-is-keyword-2.rs | 2 +- .../dollar-crate-is-keyword-2.stderr | 19 ++++++------ .../dollar-crate/dollar-crate-is-keyword.rs | 1 - .../dollar-crate-is-keyword.stderr | 17 ++--------- tests/ui/error-codes/E0430.rs | 3 +- tests/ui/error-codes/E0430.stderr | 13 ++------- tests/ui/error-codes/E0431.rs | 2 +- tests/ui/error-codes/E0431.stderr | 10 +++++-- tests/ui/imports/issue-47623.rs | 2 +- tests/ui/imports/issue-47623.stderr | 3 +- tests/ui/use/use-keyword.rs | 8 +---- tests/ui/use/use-keyword.stderr | 22 -------------- tests/ui/use/use-mod/use-mod-2.rs | 6 ++-- tests/ui/use/use-mod/use-mod-2.stderr | 21 ++++++++++---- tests/ui/use/use-mod/use-mod.rs | 3 +- tests/ui/use/use-mod/use-mod.stderr | 29 ++++++++----------- 17 files changed, 58 insertions(+), 105 deletions(-) delete mode 100644 tests/ui/use/use-keyword.stderr diff --git a/tests/ui/delegation/target-expr-pass.rs b/tests/ui/delegation/target-expr-pass.rs index 9e326a19b8f1c..2d5cf7aace2bc 100644 --- a/tests/ui/delegation/target-expr-pass.rs +++ b/tests/ui/delegation/target-expr-pass.rs @@ -25,7 +25,7 @@ struct S(F); //~ WARN struct `S` is never constructed impl Trait for S { reuse ::bar { #[allow(unused_imports)] - use self::to_reuse::{foo, inner::self}; + use self::to_reuse::{foo, inner::{self}}; let x = foo(12); assert_eq!(x, 12); &self.0 diff --git a/tests/ui/dollar-crate/dollar-crate-is-keyword-2.rs b/tests/ui/dollar-crate/dollar-crate-is-keyword-2.rs index bbab6f8774876..880ec0a6c5508 100644 --- a/tests/ui/dollar-crate/dollar-crate-is-keyword-2.rs +++ b/tests/ui/dollar-crate/dollar-crate-is-keyword-2.rs @@ -2,7 +2,7 @@ mod a {} macro_rules! m { () => { - use a::$crate; //~ ERROR unresolved import `a::$crate` + use a::$crate; //~ ERROR `$crate` in paths can only be used in start position use a::$crate::b; //~ ERROR `$crate` in paths can only be used in start position type A = a::$crate; //~ ERROR `$crate` in paths can only be used in start position } diff --git a/tests/ui/dollar-crate/dollar-crate-is-keyword-2.stderr b/tests/ui/dollar-crate/dollar-crate-is-keyword-2.stderr index d46029710d6f7..6e79a04fddb4f 100644 --- a/tests/ui/dollar-crate/dollar-crate-is-keyword-2.stderr +++ b/tests/ui/dollar-crate/dollar-crate-is-keyword-2.stderr @@ -1,19 +1,19 @@ -error[E0433]: failed to resolve: `$crate` in paths can only be used in start position - --> $DIR/dollar-crate-is-keyword-2.rs:6:16 +error: `$crate` in paths can only be used in start position + --> $DIR/dollar-crate-is-keyword-2.rs:5:16 | -LL | use a::$crate::b; - | ^^^^^^ `$crate` in paths can only be used in start position +LL | use a::$crate; + | ^^^^^^ ... LL | m!(); | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0432]: unresolved import `a::$crate` - --> $DIR/dollar-crate-is-keyword-2.rs:5:13 +error[E0433]: failed to resolve: `$crate` in paths can only be used in start position + --> $DIR/dollar-crate-is-keyword-2.rs:6:16 | -LL | use a::$crate; - | ^^^^^^^^^ no `$crate` in `a` +LL | use a::$crate::b; + | ^^^^^^ `$crate` in paths can only be used in start position ... LL | m!(); | ---- in this macro invocation @@ -33,5 +33,4 @@ LL | m!(); error: aborting due to 3 previous errors -Some errors have detailed explanations: E0432, E0433. -For more information about an error, try `rustc --explain E0432`. +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/dollar-crate/dollar-crate-is-keyword.rs b/tests/ui/dollar-crate/dollar-crate-is-keyword.rs index d625163dc7e1c..e1a8eda948edb 100644 --- a/tests/ui/dollar-crate/dollar-crate-is-keyword.rs +++ b/tests/ui/dollar-crate/dollar-crate-is-keyword.rs @@ -8,7 +8,6 @@ macro_rules! m { use $crate; //~ ERROR `$crate` may not be imported use $crate as $crate; //~ ERROR expected identifier, found reserved identifier `$crate` - //~^ ERROR `$crate` may not be imported } } diff --git a/tests/ui/dollar-crate/dollar-crate-is-keyword.stderr b/tests/ui/dollar-crate/dollar-crate-is-keyword.stderr index b027822307417..1a7cfd6d1b713 100644 --- a/tests/ui/dollar-crate/dollar-crate-is-keyword.stderr +++ b/tests/ui/dollar-crate/dollar-crate-is-keyword.stderr @@ -21,26 +21,15 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: `$crate` may not be imported - --> $DIR/dollar-crate-is-keyword.rs:9:9 + --> $DIR/dollar-crate-is-keyword.rs:9:13 | LL | use $crate; - | ^^^^^^^^^^^ + | ^^^^^^ ... LL | m!(); | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `$crate` may not be imported - --> $DIR/dollar-crate-is-keyword.rs:10:9 - | -LL | use $crate as $crate; - | ^^^^^^^^^^^^^^^^^^^^^ -... -LL | m!(); - | ---- in this macro invocation - | - = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/error-codes/E0430.rs b/tests/ui/error-codes/E0430.rs index ba2f671d66cf1..0c13cddb5320f 100644 --- a/tests/ui/error-codes/E0430.rs +++ b/tests/ui/error-codes/E0430.rs @@ -1,5 +1,4 @@ -use std::fmt::{self, self}; //~ ERROR E0430 - //~^ ERROR E0252 +use std::fmt::{self, self}; //~ ERROR the name `fmt` is defined multiple times fn main () { } diff --git a/tests/ui/error-codes/E0430.stderr b/tests/ui/error-codes/E0430.stderr index 69a0d6e11b29d..a806b835a9732 100644 --- a/tests/ui/error-codes/E0430.stderr +++ b/tests/ui/error-codes/E0430.stderr @@ -1,11 +1,3 @@ -error[E0430]: `self` import can only appear once in an import list - --> $DIR/E0430.rs:1:16 - | -LL | use std::fmt::{self, self}; - | ^^^^ ---- another `self` import appears here - | | - | can only appear once in an import list - error[E0252]: the name `fmt` is defined multiple times --> $DIR/E0430.rs:1:22 | @@ -16,7 +8,6 @@ LL | use std::fmt::{self, self}; | = note: `fmt` must be defined only once in the type namespace of this module -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0252, E0430. -For more information about an error, try `rustc --explain E0252`. +For more information about this error, try `rustc --explain E0252`. diff --git a/tests/ui/error-codes/E0431.rs b/tests/ui/error-codes/E0431.rs index 2e2ccba171518..836cf560a456c 100644 --- a/tests/ui/error-codes/E0431.rs +++ b/tests/ui/error-codes/E0431.rs @@ -1,4 +1,4 @@ -use {self}; //~ ERROR E0431 +use {self}; //~ ERROR imports need to be explicitly named fn main () { } diff --git a/tests/ui/error-codes/E0431.stderr b/tests/ui/error-codes/E0431.stderr index f77c62bec6819..a9604efa0e41d 100644 --- a/tests/ui/error-codes/E0431.stderr +++ b/tests/ui/error-codes/E0431.stderr @@ -1,9 +1,13 @@ -error[E0431]: `self` import can only appear in an import list with a non-empty prefix +error: imports need to be explicitly named --> $DIR/E0431.rs:1:6 | LL | use {self}; - | ^^^^ can only appear in an import list with a non-empty prefix + | ^^^^ + | +help: try renaming it with a name + | +LL | use {self as name}; + | +++++++ error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0431`. diff --git a/tests/ui/imports/issue-47623.rs b/tests/ui/imports/issue-47623.rs index ad8aa4c1a2bd6..55c2a596d9dcb 100644 --- a/tests/ui/imports/issue-47623.rs +++ b/tests/ui/imports/issue-47623.rs @@ -1,3 +1,3 @@ -use self; //~ERROR `self` imports are only allowed within a { } list +use self; //~ERROR imports need to be explicitly named fn main() {} diff --git a/tests/ui/imports/issue-47623.stderr b/tests/ui/imports/issue-47623.stderr index be42a4a5b1d8d..64f443bf69e48 100644 --- a/tests/ui/imports/issue-47623.stderr +++ b/tests/ui/imports/issue-47623.stderr @@ -1,4 +1,4 @@ -error[E0429]: `self` imports are only allowed within a { } list +error: imports need to be explicitly named --> $DIR/issue-47623.rs:1:5 | LL | use self; @@ -6,4 +6,3 @@ LL | use 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-keyword.rs b/tests/ui/use/use-keyword.rs index 95f3036516760..03104407ed2f8 100644 --- a/tests/ui/use/use-keyword.rs +++ b/tests/ui/use/use-keyword.rs @@ -1,16 +1,10 @@ -// Check that imports with naked super and self don't fail during parsing -// FIXME: this shouldn't fail during name resolution either +//@ check-pass mod a { mod b { use self as A; - //~^ ERROR `self` imports are only allowed within a { } list use super as B; - //~^ ERROR unresolved import `super` [E0432] - //~| NOTE no `super` in the root use super::{self as C}; - //~^ ERROR unresolved import `super` [E0432] - //~| NOTE no `super` in the root } } diff --git a/tests/ui/use/use-keyword.stderr b/tests/ui/use/use-keyword.stderr deleted file mode 100644 index 501d14be52177..0000000000000 --- a/tests/ui/use/use-keyword.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-keyword.rs:6:13 - | -LL | use self as A; - | ^^^^ - -error[E0432]: unresolved import `super` - --> $DIR/use-keyword.rs:8:13 - | -LL | use super as B; - | ^^^^^^^^^^ no `super` in the root - -error[E0432]: unresolved import `super` - --> $DIR/use-keyword.rs:11:21 - | -LL | use super::{self as C}; - | ^^^^^^^^^ no `super` in the root - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0429, E0432. -For more information about an error, try `rustc --explain E0429`. diff --git a/tests/ui/use/use-mod/use-mod-2.rs b/tests/ui/use/use-mod/use-mod-2.rs index 57ff135c4d85a..f04d902336940 100644 --- a/tests/ui/use/use-mod/use-mod-2.rs +++ b/tests/ui/use/use-mod/use-mod-2.rs @@ -1,11 +1,9 @@ mod foo { use self::{self}; - //~^ ERROR unresolved import `self` [E0432] - //~| NOTE no `self` in the root + //~^ ERROR imports need to be explicitly named use super::{self}; - //~^ ERROR unresolved import `super` [E0432] - //~| NOTE no `super` in the root + //~^ ERROR imports need to be explicitly named } fn main() {} diff --git a/tests/ui/use/use-mod/use-mod-2.stderr b/tests/ui/use/use-mod/use-mod-2.stderr index 8437678497724..1609937bbbf49 100644 --- a/tests/ui/use/use-mod/use-mod-2.stderr +++ b/tests/ui/use/use-mod/use-mod-2.stderr @@ -1,15 +1,24 @@ -error[E0432]: unresolved import `self` +error: imports need to be explicitly named --> $DIR/use-mod-2.rs:2:16 | LL | use self::{self}; - | ^^^^ no `self` in the root + | ^^^^ + | +help: try renaming it with a name + | +LL | use self::{self as name}; + | +++++++ -error[E0432]: unresolved import `super` - --> $DIR/use-mod-2.rs:6:17 +error: imports need to be explicitly named + --> $DIR/use-mod-2.rs:5:17 | LL | use super::{self}; - | ^^^^ no `super` in the root + | ^^^^ + | +help: try renaming it with a name + | +LL | use super::{self as name}; + | +++++++ 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.rs b/tests/ui/use/use-mod/use-mod.rs index 87064c6a42b11..5e1149dba3a85 100644 --- a/tests/ui/use/use-mod/use-mod.rs +++ b/tests/ui/use/use-mod/use-mod.rs @@ -1,13 +1,12 @@ use foo::bar::{ self, -//~^ ERROR `self` import can only appear once in an import list Bar, self //~^ ERROR the name `bar` is defined multiple times }; use {self}; -//~^ ERROR `self` import can only appear in an import list with a non-empty prefix +//~^ ERROR imports need to be explicitly named mod foo { pub mod bar { diff --git a/tests/ui/use/use-mod/use-mod.stderr b/tests/ui/use/use-mod/use-mod.stderr index 0cae5eb14aeeb..385b3f3b6e616 100644 --- a/tests/ui/use/use-mod/use-mod.stderr +++ b/tests/ui/use/use-mod/use-mod.stderr @@ -1,24 +1,20 @@ -error[E0430]: `self` import can only appear once in an import list - --> $DIR/use-mod.rs:2:5 - | -LL | self, - | ^^^^ can only appear once in an import list -... -LL | self - | ---- another `self` import appears here - -error[E0431]: `self` import can only appear in an import list with a non-empty prefix - --> $DIR/use-mod.rs:9:6 +error: imports need to be explicitly named + --> $DIR/use-mod.rs:8:6 | LL | use {self}; - | ^^^^ can only appear in an import list with a non-empty prefix + | ^^^^ + | +help: try renaming it with a name + | +LL | use {self as name}; + | +++++++ error[E0252]: the name `bar` is defined multiple times - --> $DIR/use-mod.rs:5:5 + --> $DIR/use-mod.rs:4:5 | LL | self, | ---- previous import of the module `bar` here -... +LL | Bar, LL | self | ^^^^ | | @@ -27,7 +23,6 @@ LL | self | = note: `bar` must be defined only once in the type namespace of this module -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0252, E0430, E0431. -For more information about an error, try `rustc --explain E0252`. +For more information about this error, try `rustc --explain E0252`. From 42a9210441945acfc9e6f8ec51ff08abd87e1d42 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 1 Nov 2025 23:55:57 +0800 Subject: [PATCH 3/3] Document no-longer emitted E0430/E0431 --- compiler/rustc_error_codes/src/error_codes/E0430.md | 4 +++- compiler/rustc_error_codes/src/error_codes/E0431.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0430.md b/compiler/rustc_error_codes/src/error_codes/E0430.md index 8cca0f21e5943..83b2bebca11b9 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0430.md +++ b/compiler/rustc_error_codes/src/error_codes/E0430.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + The `self` import appears more than once in the list. Erroneous code example: -```compile_fail,E0430 +```ignore (error is no longer emitted) use something::{self, self}; // error: `self` import can only appear once in // the list ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0431.md b/compiler/rustc_error_codes/src/error_codes/E0431.md index 1b70f5f1d7b76..6689ed0ee4a52 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0431.md +++ b/compiler/rustc_error_codes/src/error_codes/E0431.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + An invalid `self` import was made. Erroneous code example: -```compile_fail,E0431 +```ignore (error is no longer emitted) use {self}; // error: `self` import can only appear in an import list with a // non-empty prefix ```