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 4148ec1b7abd7..96707487d3b64 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -37,7 +37,7 @@ use crate::ref_mut::CmCell; use crate::{ BindingKey, Decl, DeclData, DeclKind, ExternModule, ExternPreludeEntry, Finalize, IdentKey, LocalModule, MacroData, Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, Res, - ResolutionError, Resolver, Segment, Used, VisResolutionError, errors, + Resolver, Segment, Used, VisResolutionError, errors, }; impl<'ra, 'tcx> Resolver<'ra, 'tcx> { @@ -531,18 +531,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { self.r.indeterminate_imports.push(import); match import.kind { - ImportKind::Single { target, type_ns_only, .. } => { + ImportKind::Single { target, .. } => { // Don't add underscore imports to `single_imports` // because they cannot define any usable names. if target.name != kw::Underscore { self.r.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let key = BindingKey::new(IdentKey::new(target), ns); - this.resolution_or_default(current_module, key, target.span) - .borrow_mut(this) - .single_imports - .insert(import); - } + let key = BindingKey::new(IdentKey::new(target), ns); + this.resolution_or_default(current_module, key, target.span) + .borrow_mut(this) + .single_imports + .insert(import); }); } } @@ -611,30 +609,8 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { let mut module_path = prefix; let source = module_path.pop().unwrap(); - // `true` for `...::{self [as target]}` imports, `false` otherwise. - let type_ns_only = nested && source.ident.name == kw::SelfLower; - - // Suggest `use prefix::{self};` for `use prefix::self;` - if source.ident.name == kw::SelfLower - && let Some(parent) = module_path.last() - && !type_ns_only - && (parent.ident.name != kw::PathRoot - || self.r.path_root_is_crate_root(parent.ident)) - { - 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, - }, - ); - } - + // If the identifier is `self` without a rename, + // then it is replaced with the parent identifier. let ident = if source.ident.name == kw::SelfLower && rename.is_none() && let Some(parent) = module_path.last() @@ -688,22 +664,29 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { self.r.dcx().span_err(use_tree.span(), "extern prelude cannot be imported"); return; } - _ => {} + _ => (), + } + + // Deny `use ...::self::source [as target];` or `use ...::self::self [as target];`, + // but allow `use self::source [as target];` and `use self::self as target;`. + if let Some(parent) = module_path.last() + && parent.ident.name == kw::SelfLower + && module_path.len() > 1 + { + self.r.dcx().span_err( + parent.ident.span, + "`self` in paths can only be used in start position or last 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; } @@ -711,7 +694,6 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { source: source.ident, target: ident, decls: Default::default(), - type_ns_only, nested, id, }; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index bf260d823b765..8b61c1d5ccab1 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -386,9 +386,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) @@ -913,29 +910,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 8c7bf61949a29..9f26fc076e57f 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -301,40 +301,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> { @@ -998,7 +964,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 33e9ac1d430a4..acc1ec3bfec0d 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1836,8 +1836,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } + let allow_trailing_self = is_last && name == kw::SelfLower; + // Report special messages for path segment keywords in wrong positions. - if ident.is_path_segment_keyword() && segment_idx != 0 { + if ident.is_path_segment_keyword() && segment_idx != 0 && !allow_trailing_self { return PathResult::failed( ident, false, @@ -1857,6 +1859,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { format!("global paths cannot start with {name_str}"), "cannot start with this".to_string(), ) + } else if name == kw::SelfLower { + ( + format!( + "`self` in paths can only be used in start position or last position" + ), + "can only be used in path start position or last position" + .to_string(), + ) } else { ( format!("{name_str} in paths can only be used in start position"), diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 9df075561b3f2..c965ff8a97443 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -71,8 +71,6 @@ pub(crate) enum ImportKind<'ra> { target: Ident, /// Name declarations introduced by the import. decls: PerNS>>, - /// `true` for `...::{self [as target]}` imports, `false` otherwise. - type_ns_only: bool, /// Did this import result from a nested import? i.e. `use foo::{bar, baz};` nested: bool, /// The ID of the `UseTree` that imported this `Import`. @@ -113,7 +111,7 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ImportKind::*; match self { - Single { source, target, decls, type_ns_only, nested, id, .. } => f + Single { source, target, decls, nested, id, .. } => f .debug_struct("Single") .field("source", source) .field("target", target) @@ -122,7 +120,6 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> { "decls", &decls.clone().map(|b| b.into_inner().decl().map(|_| format_args!(".."))), ) - .field("type_ns_only", type_ns_only) .field("nested", nested) .field("id", id) .finish(), @@ -1004,10 +1001,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }; import.imported_module.set_unchecked(Some(module)); - let (source, target, bindings, type_ns_only) = match import.kind { - ImportKind::Single { source, target, ref decls, type_ns_only, .. } => { - (source, target, decls, type_ns_only) - } + let (source, target, bindings) = match import.kind { + ImportKind::Single { source, target, ref decls, .. } => (source, target, decls), ImportKind::Glob { .. } => { self.get_mut_unchecked().resolve_glob_import(import); return 0; @@ -1017,64 +1012,62 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut indeterminate_count = 0; self.per_ns_cm(|mut this, ns| { - if !type_ns_only || ns == TypeNS { - if bindings[ns].get() != PendingDecl::Pending { - return; - }; - let binding_result = this.reborrow().maybe_resolve_ident_in_module( - module, - source, - ns, - &import.parent_scope, - Some(import), - ); - let parent = import.parent_scope.module; - let binding = match binding_result { - Ok(binding) => { - if binding.is_assoc_item() - && !this.tcx.features().import_trait_associated_functions() - { - feature_err( - this.tcx.sess, - sym::import_trait_associated_functions, - import.span, - "`use` associated items of traits is unstable", - ) - .emit(); - } - // We need the `target`, `source` can be extracted. - let import_decl = this.new_import_decl(binding, import); - this.get_mut_unchecked().plant_decl_into_local_module( - IdentKey::new(target), + if bindings[ns].get() != PendingDecl::Pending { + return; + }; + let binding_result = this.reborrow().maybe_resolve_ident_in_module( + module, + source, + ns, + &import.parent_scope, + Some(import), + ); + let parent = import.parent_scope.module; + let binding = match binding_result { + Ok(binding) => { + if binding.is_assoc_item() + && !this.tcx.features().import_trait_associated_functions() + { + feature_err( + this.tcx.sess, + sym::import_trait_associated_functions, + import.span, + "`use` associated items of traits is unstable", + ) + .emit(); + } + // We need the `target`, `source` can be extracted. + let import_decl = this.new_import_decl(binding, import); + this.get_mut_unchecked().plant_decl_into_local_module( + IdentKey::new(target), + target.span, + ns, + import_decl, + ); + PendingDecl::Ready(Some(import_decl)) + } + Err(Determinacy::Determined) => { + // Don't remove underscores from `single_imports`, they were never added. + if target.name != kw::Underscore { + let key = BindingKey::new(IdentKey::new(target), ns); + this.get_mut_unchecked().update_local_resolution( + parent.expect_local(), + key, target.span, - ns, - import_decl, + false, + |_, resolution| { + resolution.single_imports.swap_remove(&import); + }, ); - PendingDecl::Ready(Some(import_decl)) } - Err(Determinacy::Determined) => { - // Don't remove underscores from `single_imports`, they were never added. - if target.name != kw::Underscore { - let key = BindingKey::new(IdentKey::new(target), ns); - this.get_mut_unchecked().update_local_resolution( - parent.expect_local(), - key, - target.span, - false, - |_, resolution| { - resolution.single_imports.swap_remove(&import); - }, - ); - } - PendingDecl::Ready(None) - } - Err(Determinacy::Undetermined) => { - indeterminate_count += 1; - PendingDecl::Pending - } - }; - bindings[ns].set_unchecked(binding); - } + PendingDecl::Ready(None) + } + Err(Determinacy::Undetermined) => { + indeterminate_count += 1; + PendingDecl::Pending + } + }; + bindings[ns].set_unchecked(binding); }); indeterminate_count @@ -1213,10 +1206,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { PathResult::Indeterminate => unreachable!(), }; - let (ident, target, bindings, type_ns_only, import_id) = match import.kind { - ImportKind::Single { source, target, ref decls, type_ns_only, id, .. } => { - (source, target, decls, type_ns_only, id) - } + let (ident, target, bindings, import_id) = match import.kind { + ImportKind::Single { source, target, ref decls, id, .. } => (source, target, decls, id), ImportKind::Glob { ref max_vis, id } => { if import.module_path.len() <= 1 { // HACK(eddyb) `lint_if_path_starts_with_module` needs at least @@ -1284,86 +1275,82 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut all_ns_err = true; self.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let binding = this.cm().resolve_ident_in_module( - module, - ident, - ns, - &import.parent_scope, - Some(Finalize { - report_private: false, - import: Some(import.summary()), - ..finalize - }), - bindings[ns].get().decl(), - Some(import), - ); + let binding = this.cm().resolve_ident_in_module( + module, + ident, + ns, + &import.parent_scope, + Some(Finalize { + report_private: false, + import: Some(import.summary()), + ..finalize + }), + bindings[ns].get().decl(), + Some(import), + ); - match binding { - Ok(binding) => { - // Consistency checks, analogous to `finalize_macro_resolutions`. - let initial_res = bindings[ns].get().decl().map(|binding| { - let initial_binding = binding.import_source(); - all_ns_err = false; - if target.name == kw::Underscore - && initial_binding.is_extern_crate() - && !initial_binding.is_import() - { - let used = if import.module_path.is_empty() { - Used::Scope - } else { - Used::Other - }; - this.record_use(ident, binding, used); - } - initial_binding.res() - }); - let res = binding.res(); - let has_ambiguity_error = - this.ambiguity_errors.iter().any(|error| error.warning.is_none()); - if res == Res::Err || has_ambiguity_error { - this.dcx() - .span_delayed_bug(import.span, "some error happened for an import"); - return; - } - if let Some(initial_res) = initial_res { - if res != initial_res && !this.issue_145575_hack_applied { - span_bug!(import.span, "inconsistent resolution for an import"); - } - } else if this.privacy_errors.is_empty() { - this.dcx() - .create_err(CannotDetermineImportResolution { span: import.span }) - .emit(); + match binding { + Ok(binding) => { + // Consistency checks, analogous to `finalize_macro_resolutions`. + let initial_res = bindings[ns].get().decl().map(|binding| { + let initial_binding = binding.import_source(); + all_ns_err = false; + if target.name == kw::Underscore + && initial_binding.is_extern_crate() + && !initial_binding.is_import() + { + let used = if import.module_path.is_empty() { + Used::Scope + } else { + Used::Other + }; + this.record_use(ident, binding, used); } + initial_binding.res() + }); + let res = binding.res(); + let has_ambiguity_error = + this.ambiguity_errors.iter().any(|error| error.warning.is_none()); + if res == Res::Err || has_ambiguity_error { + this.dcx() + .span_delayed_bug(import.span, "some error happened for an import"); + return; } - Err(..) => { - // FIXME: This assert may fire if public glob is later shadowed by a private - // single import (see test `issue-55884-2.rs`). In theory single imports should - // always block globs, even if they are not yet resolved, so that this kind of - // self-inconsistent resolution never happens. - // Re-enable the assert when the issue is fixed. - // assert!(result[ns].get().is_err()); + if let Some(initial_res) = initial_res { + if res != initial_res && !this.issue_145575_hack_applied { + span_bug!(import.span, "inconsistent resolution for an import"); + } + } else if this.privacy_errors.is_empty() { + this.dcx() + .create_err(CannotDetermineImportResolution { span: import.span }) + .emit(); } } + Err(..) => { + // FIXME: This assert may fire if public glob is later shadowed by a private + // single import (see test `issue-55884-2.rs`). In theory single imports should + // always block globs, even if they are not yet resolved, so that this kind of + // self-inconsistent resolution never happens. + // Re-enable the assert when the issue is fixed. + // assert!(result[ns].get().is_err()); + } } }); if all_ns_err { let mut all_ns_failed = true; self.per_ns(|this, ns| { - if !type_ns_only || ns == TypeNS { - let binding = this.cm().resolve_ident_in_module( - module, - ident, - ns, - &import.parent_scope, - Some(finalize), - None, - None, - ); - if binding.is_ok() { - all_ns_failed = false; - } + let binding = this.cm().resolve_ident_in_module( + module, + ident, + ns, + &import.parent_scope, + Some(finalize), + None, + None, + ); + if binding.is_ok() { + all_ns_failed = false; } }); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a44a7b30b4e60..a72eafac0bd5b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -270,8 +270,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, diff --git a/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index 79acaec021a66..3604269a4a421 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -42,5 +42,6 @@ impl Trait for S { mod prefix {} reuse unresolved_prefix::{a, b, c}; //~ ERROR cannot find module or crate `unresolved_prefix` reuse prefix::{self, super, crate}; //~ ERROR `crate` in paths can only be used in start position +//~^ ERROR expected function, found module `prefix::self` fn main() {} diff --git a/tests/ui/delegation/bad-resolve.stderr b/tests/ui/delegation/bad-resolve.stderr index 6fde0bb13877a..de75aeaf329ef 100644 --- a/tests/ui/delegation/bad-resolve.stderr +++ b/tests/ui/delegation/bad-resolve.stderr @@ -82,6 +82,12 @@ LL - reuse Trait::foo2 { self.0 } LL + reuse Trait::foo { self.0 } | +error[E0423]: expected function, found module `prefix::self` + --> $DIR/bad-resolve.rs:44:7 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^^^ not a function + error[E0046]: not all trait items implemented, missing: `Type` --> $DIR/bad-resolve.rs:22:1 | @@ -105,7 +111,7 @@ error[E0433]: `crate` in paths can only be used in start position LL | reuse prefix::{self, super, crate}; | ^^^^^ can only be used in path start position -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576. For more information about an error, try `rustc --explain E0046`. 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.rs b/tests/ui/imports/absolute-paths-in-nested-use-groups.rs index 9a8c9aab72828..9f6799ce7eff5 100644 --- a/tests/ui/imports/absolute-paths-in-nested-use-groups.rs +++ b/tests/ui/imports/absolute-paths-in-nested-use-groups.rs @@ -8,7 +8,7 @@ use foo::{ super::bar, //~^ ERROR: `super` in paths can only be used in start position self::bar, - //~^ ERROR: `self` in paths can only be used in start position + //~^ ERROR: `self` in paths can only be used in start position or last position }; fn main() {} 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..48ea0ad32400f 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 or last 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/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 458bad618754c..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 | @@ -51,7 +35,7 @@ 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 @@ -64,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/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 03284298c16f7..8039450702552 100644 --- a/tests/ui/use/use-mod/use-mod-4.stderr +++ b/tests/ui/use/use-mod/use-mod-4.stderr @@ -1,35 +1,3 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-mod-4.rs:1:15 - | -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 - | -LL | use std::mem::self; - | ^^^^^^ - | -help: consider importing the module directly - | -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:12 | @@ -41,7 +9,6 @@ help: you might be missing a crate named `foo`, add it to your project and impor LL + extern crate foo; | -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..040b592e3748d 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,9 +7,7 @@ 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 bar::drop(); } 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..b11b1f17aa1e2 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,9 +7,7 @@ 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 abc::drop(); } 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 dce3071f789bc..a63cce80896ab 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 + --> $DIR/use-path-segment-kw.rs:178: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:181: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:194: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:196: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:200: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:202: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:206: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:208: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}; | ^^^^ @@ -936,7 +753,7 @@ LL | use $crate::{self as name}; | +++++++ error[E0433]: cannot find module or crate `foobar` in the crate root - --> $DIR/use-path-segment-kw.rs:187:17 + --> $DIR/use-path-segment-kw.rs:186:17 | LL | pub use foobar::qux::self; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -947,7 +764,7 @@ LL + extern crate foobar; | error[E0433]: cannot find module or crate `foobar` in the crate root - --> $DIR/use-path-segment-kw.rs:191:17 + --> $DIR/use-path-segment-kw.rs:190:17 | LL | pub use foobar::baz::{self}; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -958,7 +775,7 @@ LL + extern crate foobar; | error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:189:17 + --> $DIR/use-path-segment-kw.rs:188:17 | LL | pub use foobar::self as _self3; | ^^^^^^ @@ -969,7 +786,7 @@ LL | pub use self::foobar::self as _self3; | ++++++ error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:192:17 + --> $DIR/use-path-segment-kw.rs:191:17 | LL | pub use foobar::{self as _nested_self3}; | ^^^^^^ @@ -979,12 +796,6 @@ help: a similar path exists LL | pub use self::foobar::{self as _nested_self3}; | ++++++ -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[E0573]: expected type, found module `$crate` --> $DIR/use-path-segment-kw.rs:10:19 | @@ -996,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:185:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:193:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:199:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:205: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:211: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 | @@ -1114,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..3f1b01a27de54 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,13 +257,18 @@ 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 + --> $DIR/use-path-segment-kw.rs:178:13 | LL | use ::self; | ^^^^^^ @@ -275,89 +280,30 @@ 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:181:16 | LL | use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:184:20 + --> $DIR/use-path-segment-kw.rs:183: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:194: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:196: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:200: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:202: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:206: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:208: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:237:15 | LL | foo::bar::_nested_self2::outer(); | ^^^^^^^^^^^^^ could not find `_nested_self2` in `bar` @@ -953,36 +771,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[E0425]: cannot find crate `self` in the list of imported crates + --> $DIR/use-path-segment-kw.rs:175:21 + | +LL | type D2 = ::self; + | ^^^^ not found in the list of imported crates + +error[E0573]: expected type, found module `foobar::self` + --> $DIR/use-path-segment-kw.rs:185:19 + | +LL | type D3 = foobar::self; + | ^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-path-segment-kw.rs:193:19 + | +LL | type D4 = crate::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-path-segment-kw.rs:199:19 + | +LL | type D5 = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `self::self` + --> $DIR/use-path-segment-kw.rs:205: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:211: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 +936,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 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: E0425, E0433, E0573. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index c9b404887e605..583f07d9a81fb 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,45 @@ pub 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; + //[e2015]~^ ERROR expected type, found module `::self` + //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates 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; //~ ERROR `self` imports are only allowed within a { } list + pub use foobar::self as _self3; //[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-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr index a7e458831feb4..a0f834bda1052 100644 --- a/tests/ui/use/use-self-at-end.e2015.stderr +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -1,43 +1,16 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:14:22 - | -LL | pub use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::self; -LL + pub use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-self-at-end.rs:14:24 | LL | pub use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:16:22 - | -LL | pub use crate::self as crate1; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use crate::self as crate1; -LL + pub use crate as crate1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as crate1}; - | + + +LL | pub use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:17:25 + --> $DIR/use-self-at-end.rs:16:25 | LL | pub use crate::{self}; | ^^^^ @@ -48,13 +21,18 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:21:17 + --> $DIR/use-self-at-end.rs:20: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:23:18 + --> $DIR/use-self-at-end.rs:22:18 | LL | pub use {self}; | ^^^^ @@ -64,46 +42,19 @@ help: try renaming it with a name LL | pub use {self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:27:21 - | -LL | pub use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self; -LL + pub use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:27:23 + --> $DIR/use-self-at-end.rs:26:23 | LL | pub use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:29:21 | -LL | pub use self::self as self3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self as self3; -LL + pub use self as self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as self3}; - | + + +LL | pub use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:30:24 + --> $DIR/use-self-at-end.rs:29:24 | LL | pub use self::{self}; | ^^^^ @@ -113,46 +64,19 @@ help: try renaming it with a name LL | pub use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:34:22 - | -LL | pub use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self; -LL + pub use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:34:24 + --> $DIR/use-self-at-end.rs:33:24 | LL | pub use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:36:22 - | -LL | pub use super::self as super1; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use super::self as super1; -LL + pub use super as super1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as super1}; - | + + +LL | pub use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:37:25 + --> $DIR/use-self-at-end.rs:36:25 | LL | pub use super::{self}; | ^^^^ @@ -162,55 +86,16 @@ help: try renaming it with a name LL | pub use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:41:25 - | -LL | pub use crate::x::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self; -LL + pub use crate::x; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:42:25 - | -LL | pub use crate::x::self as x3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self as x3; -LL + pub use crate::x as x3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self as x3}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:47:17 - | -LL | pub use ::self; - | ^^^^^^ - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:47:19 + --> $DIR/use-self-at-end.rs:48:19 | LL | pub use ::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:50:17 | -LL | pub use ::self as crate4; - | ^^^^^^ +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:52:20 @@ -223,153 +108,32 @@ help: try renaming it with a name LL | pub use ::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:57:24 - | -LL | pub use z::self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self; -LL + pub use z::self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self}; - | + + - -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:57:26 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; - | ^^^^ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:59:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self as z1; -LL + pub use z::self as z1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self as z1}; - | + + + | ^^^^ -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:61:28 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; - | ^^^^ - | -help: try renaming it with a name - | -LL | pub use z::{self::{self as name}}; - | +++++++ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:65:30 - | -LL | pub use super::Struct::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self; -LL + pub use super::Struct; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:67:30 - | -LL | pub use super::Struct::self as Struct1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self as Struct1; -LL + pub use super::Struct as Struct1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self as Struct1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:73:28 - | -LL | pub use super::Enum::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self; -LL + pub use super::Enum; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:74:28 - | -LL | pub use super::Enum::self as Enum1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self as Enum1; -LL + pub use super::Enum as Enum1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self as Enum1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:79:29 - | -LL | pub use super::Trait::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self; -LL + pub use super::Trait; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:80:29 - | -LL | pub use super::Trait::self as Trait1; - | ^^^^^^ +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:60:21 | -help: consider importing the module directly - | -LL - pub use super::Trait::self as Trait1; -LL + pub use super::Trait as Trait1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self as Trait1}; - | + + +LL | pub use z::{self::{self as z2}}; + | ^^^^ error[E0252]: the name `x` is defined multiple times - --> $DIR/use-self-at-end.rs:43:28 + --> $DIR/use-self-at-end.rs:42:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -383,7 +147,7 @@ LL | pub use crate::x::{self}; = note: `x` must be defined only once in the type namespace of this module error[E0252]: the name `Enum` is defined multiple times - --> $DIR/use-self-at-end.rs:75:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -397,7 +161,7 @@ LL | pub use super::Enum::{self}; = note: `Enum` must be defined only once in the type namespace of this module error[E0252]: the name `Trait` is defined multiple times - --> $DIR/use-self-at-end.rs:81:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -410,84 +174,104 @@ LL | pub use super::Trait::{self}; | = note: `Trait` must be defined only once in the type namespace of this module -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:59:20 - | -LL | pub use z::self::self as z1; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:62:21 - | -LL | pub use z::{self::{self as z2}}; - | ^^^^ can only be used in path start position - error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:63:24 | LL | pub use super::Struct::self; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:67:24 + --> $DIR/use-self-at-end.rs:64:24 | LL | pub use super::Struct::self as Struct1; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:69:24 + --> $DIR/use-self-at-end.rs:65:24 | LL | pub use super::Struct::{self}; | ^^^^^^ `Struct` is a struct, not a module +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:83:24 + | +LL | pub use super::self::y::z; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:84:24 + | +LL | pub use super::self::y::z as z3; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:85:24 + | +LL | pub use super::self::y::{z}; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:86:24 + | +LL | pub use super::self::y::{z as z4}; + | ^^^^ can only be used in path start position or last position + error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:70:24 + --> $DIR/use-self-at-end.rs:66:24 | LL | pub use super::Struct::{self as Struct2}; | ^^^^^^ `Struct` is a struct, not a module -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-self-at-end.rs:56:21 | LL | type G = z::self::self; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:72:31 +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:82:25 | -LL | type I = super::Enum::self; - | ^^^^ can only be used in path start position +LL | type K = super::self::y::z; + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:78:32 +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:13:18 | -LL | type J = super::Trait::self; - | ^^^^ can only be used in path start position +LL | type A = crate::self; + | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:20:18 + --> $DIR/use-self-at-end.rs:19:18 | LL | type B = self; | ^^^^ not a type -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:40:28 - | -LL | type E = crate::x::self; - | ^^^^ can only be used in path start position +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 | -help: consider importing this module - | -LL + use x; +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 | -help: if you import `x`, refer to it directly +LL | type D = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::x::self` + --> $DIR/use-self-at-end.rs:39:18 | -LL - type E = crate::x::self; -LL + type E = x::self; +LL | type E = crate::x::self; + | ^^^^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `::self` + --> $DIR/use-self-at-end.rs:45:18 | +LL | type F = ::self; + | ^^^^^^ not a type error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -498,31 +282,21 @@ LL - type H = super::Struct::self; LL + type H = ::self; | -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:13:25 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/use-self-at-end.rs:74:18 | -LL | type A = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:26:24 - | -LL | type C = self::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:33:25 +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ | -LL | type D = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: global paths cannot start with `self` - --> $DIR/use-self-at-end.rs:46:20 + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` | -LL | type F = ::self; - | ^^^^ cannot start with this +LL | type J = dyn super::Trait::self; + | +++ -error: aborting due to 49 previous errors +error: aborting due to 34 previous errors; 1 warning emitted -Some errors have detailed explanations: E0223, E0252, E0429, E0432, E0433, E0573. +Some errors have detailed explanations: E0223, E0252, E0432, E0433, E0573. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/use/use-self-at-end.e2018.stderr b/tests/ui/use/use-self-at-end.e2018.stderr index 5d56f4058069f..6d82c061d9247 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -1,43 +1,16 @@ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:14:22 - | -LL | pub use crate::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::self; -LL + pub use crate; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::{self}; - | + + - error: imports need to be explicitly named --> $DIR/use-self-at-end.rs:14:24 | LL | pub use crate::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:16:22 - | -LL | pub use crate::self as crate1; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use crate::self as crate1; -LL + pub use crate as crate1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use crate::{self as crate1}; - | + + +LL | pub use crate::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:17:25 + --> $DIR/use-self-at-end.rs:16:25 | LL | pub use crate::{self}; | ^^^^ @@ -48,13 +21,18 @@ LL | pub use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:21:17 + --> $DIR/use-self-at-end.rs:20: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:23:18 + --> $DIR/use-self-at-end.rs:22:18 | LL | pub use {self}; | ^^^^ @@ -64,46 +42,19 @@ help: try renaming it with a name LL | pub use {self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:27:21 - | -LL | pub use self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use self::self; -LL + pub use self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use self::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:27:23 + --> $DIR/use-self-at-end.rs:26:23 | LL | pub use self::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:29:21 - | -LL | pub use self::self as self3; - | ^^^^^^ - | -help: consider importing the module directly | -LL - pub use self::self as self3; -LL + pub use self as self3; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use self::{self as self3}; - | + + +LL | pub use self::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:30:24 + --> $DIR/use-self-at-end.rs:29:24 | LL | pub use self::{self}; | ^^^^ @@ -113,46 +64,19 @@ help: try renaming it with a name LL | pub use self::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:34:22 - | -LL | pub use super::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::self; -LL + pub use super; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::{self}; - | + + - error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:34:24 + --> $DIR/use-self-at-end.rs:33:24 | LL | pub use super::self; | ^^^^ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:36:22 - | -LL | pub use super::self as super1; - | ^^^^^^ | -help: consider importing the module directly - | -LL - pub use super::self as super1; -LL + pub use super as super1; - | -help: alternatively, use the multi-path `use` syntax to import `self` +help: try renaming it with a name | -LL | pub use super::{self as super1}; - | + + +LL | pub use super::self as name; + | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:37:25 + --> $DIR/use-self-at-end.rs:36:25 | LL | pub use super::{self}; | ^^^^ @@ -162,46 +86,14 @@ help: try renaming it with a name LL | pub use super::{self as name}; | +++++++ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:41:25 - | -LL | pub use crate::x::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self; -LL + pub use crate::x; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:42:25 - | -LL | pub use crate::x::self as x3; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use crate::x::self as x3; -LL + pub use crate::x as x3; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use crate::x::{self as x3}; - | + + - error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:47:17 + --> $DIR/use-self-at-end.rs:48:17 | LL | pub use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:50:17 + --> $DIR/use-self-at-end.rs:51:17 | LL | pub use ::self as crate4; | ^^^^^^^^^^^^^^^^ @@ -218,153 +110,32 @@ error: extern prelude cannot be imported LL | pub use ::{self as crate5}; | ^^^^^^^^^^^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:57:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self; -LL + pub use z::self; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self}; - | + + - -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:57:26 - | -LL | pub use z::self::self; - | ^^^^ + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:59:24 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use z::self::self as z1; -LL + pub use z::self as z1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use z::self::{self as z1}; - | + + + | ^^^^ -error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:61:28 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; - | ^^^^ - | -help: try renaming it with a name - | -LL | pub use z::{self::{self as name}}; - | +++++++ - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:65:30 - | -LL | pub use super::Struct::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self; -LL + pub use super::Struct; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:67:30 - | -LL | pub use super::Struct::self as Struct1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Struct::self as Struct1; -LL + pub use super::Struct as Struct1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Struct::{self as Struct1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:73:28 - | -LL | pub use super::Enum::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self; -LL + pub use super::Enum; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:74:28 - | -LL | pub use super::Enum::self as Enum1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Enum::self as Enum1; -LL + pub use super::Enum as Enum1; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Enum::{self as Enum1}; - | + + - -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:79:29 - | -LL | pub use super::Trait::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self; -LL + pub use super::Trait; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self}; - | + + + | ^^^^ -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/use-self-at-end.rs:80:29 - | -LL | pub use super::Trait::self as Trait1; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - pub use super::Trait::self as Trait1; -LL + pub use super::Trait as Trait1; +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:60:21 | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | pub use super::Trait::{self as Trait1}; - | + + +LL | pub use z::{self::{self as z2}}; + | ^^^^ error[E0252]: the name `x` is defined multiple times - --> $DIR/use-self-at-end.rs:43:28 + --> $DIR/use-self-at-end.rs:42:28 | LL | pub use crate::x::self; | -------------- previous import of the module `x` here @@ -378,7 +149,7 @@ LL | pub use crate::x::{self}; = note: `x` must be defined only once in the type namespace of this module error[E0252]: the name `Enum` is defined multiple times - --> $DIR/use-self-at-end.rs:75:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -392,7 +163,7 @@ LL | pub use super::Enum::{self}; = note: `Enum` must be defined only once in the type namespace of this module error[E0252]: the name `Trait` is defined multiple times - --> $DIR/use-self-at-end.rs:81:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -405,84 +176,104 @@ LL | pub use super::Trait::{self}; | = note: `Trait` must be defined only once in the type namespace of this module -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:59:20 - | -LL | pub use z::self::self as z1; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:62:21 - | -LL | pub use z::{self::{self as z2}}; - | ^^^^ can only be used in path start position - error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:65:24 + --> $DIR/use-self-at-end.rs:63:24 | LL | pub use super::Struct::self; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:67:24 + --> $DIR/use-self-at-end.rs:64:24 | LL | pub use super::Struct::self as Struct1; | ^^^^^^ `Struct` is a struct, not a module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:69:24 + --> $DIR/use-self-at-end.rs:65:24 | LL | pub use super::Struct::{self}; | ^^^^^^ `Struct` is a struct, not a module +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:83:24 + | +LL | pub use super::self::y::z; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:84:24 + | +LL | pub use super::self::y::z as z3; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:85:24 + | +LL | pub use super::self::y::{z}; + | ^^^^ can only be used in path start position or last position + +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:86:24 + | +LL | pub use super::self::y::{z as z4}; + | ^^^^ can only be used in path start position or last position + error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:70:24 + --> $DIR/use-self-at-end.rs:66:24 | LL | pub use super::Struct::{self as Struct2}; | ^^^^^^ `Struct` is a struct, not a module -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-self-at-end.rs:56:21 | LL | type G = z::self::self; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:72:31 +error[E0433]: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:82:25 | -LL | type I = super::Enum::self; - | ^^^^ can only be used in path start position +LL | type K = super::self::y::z; + | ^^^^ can only be used in path start position or last position -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:78:32 +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:13:18 | -LL | type J = super::Trait::self; - | ^^^^ can only be used in path start position +LL | type A = crate::self; + | ^^^^^^^^^^^ not a type error[E0573]: expected type, found module `self` - --> $DIR/use-self-at-end.rs:20:18 + --> $DIR/use-self-at-end.rs:19:18 | LL | type B = self; | ^^^^ not a type -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:40:28 +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 | -LL | type E = crate::x::self; - | ^^^^ can only be used in path start position - | -help: consider importing this module - | -LL + use crate::x; +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 | -help: if you import `x`, refer to it directly +LL | type D = super::self; + | ^^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `crate::x::self` + --> $DIR/use-self-at-end.rs:39:18 | -LL - type E = crate::x::self; -LL + type E = x::self; +LL | type E = crate::x::self; + | ^^^^^^^^^^^^^^ not a type + +error[E0425]: cannot find crate `self` in the list of imported crates + --> $DIR/use-self-at-end.rs:45:20 | +LL | type F = ::self; + | ^^^^ not found in the list of imported crates error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -493,31 +284,21 @@ LL - type H = super::Struct::self; LL + type H = ::self; | -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:13:25 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/use-self-at-end.rs:74:18 | -LL | type A = crate::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:26:24 - | -LL | type C = self::self; - | ^^^^ can only be used in path start position - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:33:25 +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ | -LL | type D = super::self; - | ^^^^ can only be used in path start position - -error[E0433]: global paths cannot start with `self` - --> $DIR/use-self-at-end.rs:46:20 + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` | -LL | type F = ::self; - | ^^^^ cannot start with this +LL | type J = dyn super::Trait::self; + | +++ -error: aborting due to 49 previous errors +error: aborting due to 36 previous errors; 1 warning emitted -Some errors have detailed explanations: E0223, E0252, E0429, E0432, E0433, E0573. +Some errors have detailed explanations: E0223, E0252, E0425, E0432, E0433, E0573. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/use/use-self-at-end.rs b/tests/ui/use/use-self-at-end.rs index 84337dc9e5031..64b17483445a3 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -10,10 +10,9 @@ pub mod x { pub mod y { pub mod z {} - type A = crate::self; //~ ERROR `self` in paths can only be used in start position - pub use crate::self; //~ ERROR `self` imports are only allowed within a { } list - //~^ ERROR imports need to be explicitly named - pub use crate::self as crate1; //~ ERROR `self` imports are only allowed within a { } list + type A = crate::self; //~ ERROR expected type, found module `crate::self` + 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}; @@ -23,63 +22,68 @@ pub mod x { pub use {self}; //~ ERROR imports need to be explicitly named pub use {self as self2}; - type C = self::self; //~ ERROR `self` in paths can only be used in start position - pub use self::self; //~ ERROR `self` imports are only allowed within a { } list + type C = self::self; //~ ERROR expected type, found module `self::self` + pub use self::self; //~^ ERROR imports need to be explicitly named - pub use self::self as self3; //~ ERROR `self` imports are only allowed within a { } list + pub use self::self as self3; pub use self::{self}; //~ ERROR imports need to be explicitly named pub use self::{self as self4}; - type D = super::self; //~ ERROR `self` in paths can only be used in start position - pub use super::self; //~ ERROR `self` imports are only allowed within a { } list + type D = super::self; //~ ERROR expected type, found module `super::self` + pub use super::self; //~^ ERROR imports need to be explicitly named - pub use super::self as super1; //~ ERROR `self` imports are only allowed within a { } list + pub use super::self as super1; pub use super::{self}; //~ ERROR imports need to be explicitly named pub use super::{self as super2}; - type E = crate::x::self; //~ ERROR `self` in paths can only be used in start position - pub use crate::x::self; //~ ERROR `self` imports are only allowed within a { } list - pub use crate::x::self as x3; //~ ERROR `self` imports are only allowed within a { } list + type E = crate::x::self; //~ ERROR expected type, found module `crate::x::self` + 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}; - type F = ::self; //~ ERROR global paths cannot start with `self` - pub use ::self; //[e2018]~ ERROR extern prelude cannot be imported + type F = ::self; + //[e2015]~^ ERROR expected type, found module `::self` + //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates + pub use ::self; //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list + //[e2018]~^^ ERROR extern prelude cannot be imported pub use ::self as crate4; //[e2018]~ ERROR extern prelude cannot be imported - //[e2015]~^ ERROR `self` imports are only allowed within a { } list 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 type G = z::self::self; //~ ERROR `self` in paths can only be used in start position - pub use z::self::self; //~ ERROR imports need to be explicitly named - //~^ ERROR `self` imports are only allowed within a { } list + pub use z::self::self; //~ ERROR `self` in paths can only be used in start position or last position pub use z::self::self as z1; //~ ERROR `self` in paths can only be used in start position - //~^ ERROR `self` imports are only allowed within a { } list - pub use z::{self::{self}}; //~ ERROR imports need to be explicitly named + pub use z::{self::{self}}; //~ ERROR `self` in paths can only be used in start position or last position pub use z::{self::{self as z2}}; //~ ERROR `self` in paths can only be used in start position type H = super::Struct::self; //~ ERROR ambiguous associated type pub use super::Struct::self; //~ ERROR unresolved import `super::Struct` - //~^ ERROR `self` imports are only allowed within a { } list pub use super::Struct::self as Struct1; //~ ERROR unresolved import `super::Struct` - //~^ ERROR `self` imports are only allowed within a { } list pub use super::Struct::{self}; //~ ERROR unresolved import `super::Struct` pub use super::Struct::{self as Struct2}; //~ ERROR unresolved import `super::Struct` - type I = super::Enum::self; //~ ERROR `self` in paths can only be used in start position - pub use super::Enum::self; //~ ERROR `self` imports are only allowed within a { } list - pub use super::Enum::self as Enum1; //~ ERROR `self` imports are only allowed within a { } list + type I = super::Enum::self; + pub use super::Enum::self; + pub use super::Enum::self as Enum1; pub use super::Enum::{self}; //~ ERROR the name `Enum` is defined multiple times pub use super::Enum::{self as Enum2}; - type J = super::Trait::self; //~ ERROR `self` in paths can only be used in start position - pub use super::Trait::self; //~ ERROR `self` imports are only allowed within a { } list - pub use super::Trait::self as Trait1; //~ ERROR `self` imports are only allowed within a { } list + type J = super::Trait::self; + //~^ WARN trait objects without an explicit `dyn` are deprecated + //~^^ WARN this is accepted in the current edition + pub use super::Trait::self; + pub use super::Trait::self as Trait1; pub use super::Trait::{self}; //~ ERROR the name `Trait` is defined multiple times pub use super::Trait::{self as Trait2}; + + type K = super::self::y::z; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::z; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::z as z3; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::{z}; //~ ERROR `self` in paths can only be used in start position or last position + pub use super::self::y::{z as z4}; //~ ERROR `self` in paths can only be used in start position or last position } } diff --git a/tests/ui/use/use-super-in-middle.stderr b/tests/ui/use/use-super-in-middle.stderr index af28edd48b44e..d33f49f5d599f 100644 --- a/tests/ui/use/use-super-in-middle.stderr +++ b/tests/ui/use/use-super-in-middle.stderr @@ -4,11 +4,11 @@ error[E0433]: `super` in paths can only be used in start position LL | pub use crate::x::super::{self as crate1}; | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-super-in-middle.rs:3:23 | LL | pub use crate::x::self::super::{self as crate2}; - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position error[E0433]: `super` in paths can only be used in start position --> $DIR/use-super-in-middle.rs:12:15 @@ -16,11 +16,11 @@ error[E0433]: `super` in paths can only be used in start position LL | crate::x::super::x::foo(); | ^^^^^ can only be used in path start position -error[E0433]: `self` in paths can only be used in start position +error[E0433]: `self` in paths can only be used in start position or last position --> $DIR/use-super-in-middle.rs:13:15 | LL | crate::x::self::super::x::foo(); - | ^^^^ can only be used in path start position + | ^^^^ can only be used in path start position or last position error: aborting due to 4 previous errors