From d3a782dfab91411eaeaf0f7a4f98b120554562eb Mon Sep 17 00:00:00 2001 From: WANG Rui Date: Fri, 27 Mar 2026 17:15:27 +0800 Subject: [PATCH 01/12] Partially stabilize LoongArch target features This PR stabilizes the following target features: - div32 - lam-bh - lamcas - ld-seq-sa - scq --- compiler/rustc_target/src/target_features.rs | 10 +++++----- library/std_detect/src/detect/arch/loongarch.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 161bb31c664e7..693e2b388d0f1 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -816,18 +816,18 @@ static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // tidy-alphabetical-start ("32s", Unstable(sym::loongarch_target_feature), &[]), ("d", Stable, &["f"]), - ("div32", Unstable(sym::loongarch_target_feature), &[]), + ("div32", Stable, &[]), ("f", Stable, &[]), ("frecipe", Stable, &[]), - ("lam-bh", Unstable(sym::loongarch_target_feature), &[]), - ("lamcas", Unstable(sym::loongarch_target_feature), &[]), + ("lam-bh", Stable, &[]), + ("lamcas", Stable, &[]), ("lasx", Stable, &["lsx"]), ("lbt", Stable, &[]), - ("ld-seq-sa", Unstable(sym::loongarch_target_feature), &[]), + ("ld-seq-sa", Stable, &[]), ("lsx", Stable, &["d"]), ("lvz", Stable, &[]), ("relax", Unstable(sym::loongarch_target_feature), &[]), - ("scq", Unstable(sym::loongarch_target_feature), &[]), + ("scq", Stable, &[]), ("ual", Unstable(sym::loongarch_target_feature), &[]), // tidy-alphabetical-end ]; diff --git a/library/std_detect/src/detect/arch/loongarch.rs b/library/std_detect/src/detect/arch/loongarch.rs index 6299627738111..2e021cb4352fe 100644 --- a/library/std_detect/src/detect/arch/loongarch.rs +++ b/library/std_detect/src/detect/arch/loongarch.rs @@ -35,19 +35,19 @@ features! { /// D @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] frecipe: "frecipe"; /// Frecipe - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] div32: "div32"; + @FEATURE: #[stable(feature = "stdarch_loongarch_div32", since = "CURRENT_RUSTC_VERSION")] div32: "div32"; /// Div32 @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lsx: "lsx"; /// LSX @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lasx: "lasx"; /// LASX - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lam_bh: "lam-bh"; + @FEATURE: #[stable(feature = "stdarch_loongarch_lam_bh", since = "CURRENT_RUSTC_VERSION")] lam_bh: "lam-bh"; /// LAM-BH - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lamcas: "lamcas"; + @FEATURE: #[stable(feature = "stdarch_loongarch_lamcas", since = "CURRENT_RUSTC_VERSION")] lamcas: "lamcas"; /// LAM-CAS - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ld_seq_sa: "ld-seq-sa"; + @FEATURE: #[stable(feature = "stdarch_loongarch_ld_seq_sa", since = "CURRENT_RUSTC_VERSION")] ld_seq_sa: "ld-seq-sa"; /// LD-SEQ-SA - @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] scq: "scq"; + @FEATURE: #[stable(feature = "stdarch_loongarch_scq", since = "CURRENT_RUSTC_VERSION")] scq: "scq"; /// SCQ @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] lbt: "lbt"; /// LBT From 510f709c6dffc68803b13a653276a83aeb43987b Mon Sep 17 00:00:00 2001 From: Makai Date: Sun, 19 Apr 2026 15:46:15 +0800 Subject: [PATCH 02/12] rustc_public: implement `Pattern` type --- compiler/rustc_public/src/ty.rs | 4 +- .../src/unstable/convert/internal.rs | 8 ++- .../src/unstable/convert/stable/ty.rs | 11 ++-- .../src/unstable/internal_cx/mod.rs | 8 +++ compiler/rustc_public/src/unstable/mod.rs | 5 ++ .../rustc_public/check_fmt_macro.rs | 60 +++++++++++++++++++ 6 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 tests/ui-fulldeps/rustc_public/check_fmt_macro.rs diff --git a/compiler/rustc_public/src/ty.rs b/compiler/rustc_public/src/ty.rs index 7ec8b688402ad..ef485cb69aa6a 100644 --- a/compiler/rustc_public/src/ty.rs +++ b/compiler/rustc_public/src/ty.rs @@ -109,7 +109,9 @@ impl Ty { /// Represents a pattern in the type system #[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub enum Pattern { - Range { start: Option, end: Option, include_end: bool }, + Range { start: TyConst, end: TyConst, include_end: bool }, + NotNull, + Or(Vec), } /// Represents a constant in the type system diff --git a/compiler/rustc_public/src/unstable/convert/internal.rs b/compiler/rustc_public/src/unstable/convert/internal.rs index 4f3e9f94c599b..770f4c80fc90e 100644 --- a/compiler/rustc_public/src/unstable/convert/internal.rs +++ b/compiler/rustc_public/src/unstable/convert/internal.rs @@ -125,9 +125,13 @@ impl RustcInternal for Pattern { ) -> Self::T<'tcx> { tcx.mk_pat(match self { Pattern::Range { start, end, include_end: _ } => rustc_ty::PatternKind::Range { - start: start.as_ref().unwrap().internal(tables, tcx), - end: end.as_ref().unwrap().internal(tables, tcx), + start: start.internal(tables, tcx), + end: end.internal(tables, tcx), }, + Pattern::NotNull => rustc_ty::PatternKind::NotNull, + Pattern::Or(patterns) => rustc_ty::PatternKind::Or( + tcx.mk_patterns_from_iter(patterns.iter().map(|p| p.internal(tables, tcx))), + ), }) } } diff --git a/compiler/rustc_public/src/unstable/convert/stable/ty.rs b/compiler/rustc_public/src/unstable/convert/stable/ty.rs index 9a9576d47efd2..3ae968fd0dc06 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/ty.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/ty.rs @@ -503,13 +503,14 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { ) -> Self::T { match **self { ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range { - // FIXME(SMIR): update data structures to not have an Option here anymore - start: Some(start.stable(tables, cx)), - end: Some(end.stable(tables, cx)), + start: start.stable(tables, cx), + end: end.stable(tables, cx), include_end: true, }, - ty::PatternKind::NotNull => todo!(), - ty::PatternKind::Or(_) => todo!(), + ty::PatternKind::NotNull => crate::ty::Pattern::NotNull, + ty::PatternKind::Or(pats) => { + crate::ty::Pattern::Or(pats.iter().map(|pat| pat.stable(tables, cx)).collect()) + } } } } diff --git a/compiler/rustc_public/src/unstable/internal_cx/mod.rs b/compiler/rustc_public/src/unstable/internal_cx/mod.rs index 4da86b9442f1d..161f2754bed87 100644 --- a/compiler/rustc_public/src/unstable/internal_cx/mod.rs +++ b/compiler/rustc_public/src/unstable/internal_cx/mod.rs @@ -93,4 +93,12 @@ impl<'tcx> InternalCx<'tcx> for TyCtxt<'tcx> { fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx> { self.adt_def(def_id) } + + fn mk_patterns_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: ty::CollectAndApply, &'tcx List>>, + { + TyCtxt::mk_patterns_from_iter(self, iter) + } } diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index fa5ef5a9ca6d6..ec979eef40cd1 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -55,6 +55,11 @@ pub trait InternalCx<'tcx>: Copy + Clone { fn mk_place_elems(self, v: &[mir::PlaceElem<'tcx>]) -> &'tcx List>; fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx>; + + fn mk_patterns_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: ty::CollectAndApply, &'tcx List>>; } /// Trait used to convert between an internal MIR type to a rustc_public's IR type. diff --git a/tests/ui-fulldeps/rustc_public/check_fmt_macro.rs b/tests/ui-fulldeps/rustc_public/check_fmt_macro.rs new file mode 100644 index 0000000000000..ae20797855b7f --- /dev/null +++ b/tests/ui-fulldeps/rustc_public/check_fmt_macro.rs @@ -0,0 +1,60 @@ +//@ run-pass +//! Test that users are able to use rustc_public to consume formatting macros. +//@ ignore-stage1 +//@ ignore-cross-compile +//@ ignore-remote +//@ edition: 2021 + +#![feature(rustc_private)] + +extern crate rustc_middle; + +extern crate rustc_driver; +extern crate rustc_interface; +extern crate rustc_public; +use std::io::Write; +use std::ops::ControlFlow; +use rustc_public::run; + +const CRATE_NAME: &str = "fmt_macro"; + +/// Test if we can pass the compilation. +fn test_fmt_macro() -> ControlFlow<()> { + let entry_fn = rustc_public::entry_fn().unwrap().body().unwrap(); + for bb in &entry_fn.blocks { + for stmt in &bb.statements { + let _ = stmt; + } + } + ControlFlow::Continue(()) +} + +/// This test will generate and analyze a dummy crate using the stable mir. +/// For that, it will first write the dummy crate into a file. +/// Then it will create a `RustcPublic` using custom arguments and then +/// it will run the compiler. +fn main() { + let path = "fmt_macro_input.rs"; + generate_input(&path).unwrap(); + let args = &[ + "rustc".to_string(), + "-Cpanic=abort".to_string(), + "--crate-name".to_string(), + CRATE_NAME.to_string(), + path.to_string(), + ]; + run!(args, test_fmt_macro).unwrap(); +} + +fn generate_input(path: &str) -> std::io::Result<()> { + let mut file = std::fs::File::create(path)?; + write!( + file, + r#" + fn main() {{ + println!("hello world!"); + }} + "# + )?; + Ok(()) +} From dface0a9cfd90aa6a1f8d72229bca8803dd0fd82 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Tue, 21 Apr 2026 21:29:56 +0800 Subject: [PATCH 03/12] Fix ICE: Scalar layout for non-primitive non-enum type unsafe binder --- .../rustc_ty_utils/src/layout/invariant.rs | 10 +++++++++- tests/ui/unsafe-binders/layout-invariant.rs | 17 +++++++++++++++++ .../ui/unsafe-binders/layout-invariant.stderr | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/ui/unsafe-binders/layout-invariant.rs create mode 100644 tests/ui/unsafe-binders/layout-invariant.stderr diff --git a/compiler/rustc_ty_utils/src/layout/invariant.rs b/compiler/rustc_ty_utils/src/layout/invariant.rs index 03ac1674dbd50..a9edaa7371a88 100644 --- a/compiler/rustc_ty_utils/src/layout/invariant.rs +++ b/compiler/rustc_ty_utils/src/layout/invariant.rs @@ -1,8 +1,8 @@ use std::assert_matches; use rustc_abi::{BackendRepr, FieldsShape, Scalar, Size, TagEncoding, Variants}; -use rustc_middle::bug; use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout}; +use rustc_middle::{bug, ty}; /// Enforce some basic invariants on layouts. pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) { @@ -52,6 +52,14 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou } fn skip_newtypes<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) -> TyAndLayout<'tcx> { + match *layout.ty.kind() { + ty::UnsafeBinder(bound_ty) => { + let ty = cx.tcx().instantiate_bound_regions_with_erased(bound_ty.into()); + return skip_newtypes(cx, &TyAndLayout { ty, ..*layout }); + } + _ => {} + } + if matches!(layout.layout.variants(), Variants::Multiple { .. }) { // Definitely not a newtype of anything. return *layout; diff --git a/tests/ui/unsafe-binders/layout-invariant.rs b/tests/ui/unsafe-binders/layout-invariant.rs new file mode 100644 index 0000000000000..46fb2e2839eae --- /dev/null +++ b/tests/ui/unsafe-binders/layout-invariant.rs @@ -0,0 +1,17 @@ +// Regression test for https://github.com/rust-lang/rust/issues/154426 +#![feature(unsafe_binders)] + +#[derive(Copy, Clone)] +struct Adt<'a> { + a: &'a String, +} + +const None: Option Option Adt<'a>>> = None; +//~^ ERROR the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied +//~| ERROR the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + +fn main() { + match None { + _ => {} + }; +} diff --git a/tests/ui/unsafe-binders/layout-invariant.stderr b/tests/ui/unsafe-binders/layout-invariant.stderr new file mode 100644 index 0000000000000..8eb00897c8520 --- /dev/null +++ b/tests/ui/unsafe-binders/layout-invariant.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + --> $DIR/layout-invariant.rs:9:13 + | +LL | const None: Option Option Adt<'a>>> = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `unsafe<'a> Adt<'a>` + | + = note: required for `Option Adt<'a>>` to implement `Copy` + +error[E0277]: the trait bound `unsafe<'a> Adt<'a>: Copy` is not satisfied + --> $DIR/layout-invariant.rs:9:59 + | +LL | const None: Option Option Adt<'a>>> = None; + | ^^^^ the trait `Copy` is not implemented for `unsafe<'a> Adt<'a>` + | + = note: required for `Option Adt<'a>>` to implement `Copy` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From 9515f52d61c8819e0b205aec1ef87b1e4e4a6ba5 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:03:16 +0200 Subject: [PATCH 04/12] Change `ItemKind::Trait` to have named fields. --- compiler/rustc_ast_lowering/src/item.rs | 6 ++--- compiler/rustc_hir/src/hir.rs | 26 +++++++++---------- compiler/rustc_hir/src/intravisit.rs | 16 ++++++------ compiler/rustc_hir/src/target.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 4 +-- compiler/rustc_hir_analysis/src/collect.rs | 2 +- .../src/collect/generics_of.rs | 4 +-- .../src/collect/predicates_of.rs | 10 +++---- .../src/collect/resolve_bound_vars.rs | 4 +-- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 6 ++--- .../rustc_hir_typeck/src/method/suggest.rs | 6 ++--- .../rustc_incremental/src/persist/clean.rs | 2 +- .../src/multiple_supertrait_upcastable.rs | 2 +- .../rustc_lint/src/types/improper_ctypes.rs | 2 +- compiler/rustc_middle/src/hir/map.rs | 6 ++--- compiler/rustc_passes/src/check_attr.rs | 4 +-- compiler/rustc_passes/src/dead.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- .../src/error_reporting/traits/mod.rs | 5 ++-- .../src/error_reporting/traits/suggestions.rs | 10 +++---- compiler/rustc_trait_selection/src/errors.rs | 2 +- .../src/traits/dyn_compatibility.rs | 2 +- compiler/rustc_ty_utils/src/assoc.rs | 4 +-- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/render/span_map.rs | 2 +- src/librustdoc/visit_ast.rs | 4 +-- .../src/arbitrary_source_item_ordering.rs | 20 +++++++------- src/tools/clippy/clippy_lints/src/doc/mod.rs | 2 +- .../src/doc/too_long_first_doc_paragraph.rs | 2 +- .../clippy_lints/src/item_name_repetitions.rs | 2 +- .../clippy_lints/src/len_without_is_empty.rs | 2 +- .../clippy_lints/src/missing_const_for_fn.rs | 2 +- .../clippy/clippy_lints/src/missing_doc.rs | 2 +- .../clippy/clippy_lints/src/missing_inline.rs | 2 +- .../src/needless_pass_by_ref_mut.rs | 2 +- .../src/needless_pass_by_value.rs | 2 +- .../clippy_lints/src/pass_by_ref_or_value.rs | 2 +- .../clippy/clippy_lints/src/trait_bounds.rs | 4 +-- .../clippy_lints/src/unnecessary_wraps.rs | 2 +- .../clippy_lints/src/upper_case_acronyms.rs | 2 +- .../clippy_utils/src/check_proc_macro.rs | 6 ++--- src/tools/clippy/clippy_utils/src/paths.rs | 2 +- 43 files changed, 98 insertions(+), 97 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index e8ddf5bea1795..ac3930e6a8eb1 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -585,16 +585,16 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { (safety, items, bounds) }, ); - hir::ItemKind::Trait( + hir::ItemKind::Trait { impl_restriction, constness, - *is_auto, + is_auto: *is_auto, safety, ident, generics, bounds, items, - ) + } } ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => { let constness = self.lower_constness(*constness); diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5608bd82fdacd..5c1d964d74989 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -4466,7 +4466,7 @@ impl<'hir> Item<'hir> { GenericBounds<'hir>, &'hir [TraitItemId] ), - ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items), + ItemKind::Trait { impl_restriction, constness, is_auto, safety, ident, generics, bounds, items }, (impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items); expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>), @@ -4658,16 +4658,16 @@ pub enum ItemKind<'hir> { /// A union definition, e.g., `union Foo {x: A, y: B}`. Union(Ident, &'hir Generics<'hir>, VariantData<'hir>), /// A trait definition. - Trait( - &'hir ImplRestriction<'hir>, - Constness, - IsAuto, - Safety, - Ident, - &'hir Generics<'hir>, - GenericBounds<'hir>, - &'hir [TraitItemId], - ), + Trait { + impl_restriction: &'hir ImplRestriction<'hir>, + constness: Constness, + is_auto: IsAuto, + safety: Safety, + ident: Ident, + generics: &'hir Generics<'hir>, + bounds: GenericBounds<'hir>, + items: &'hir [TraitItemId], + }, /// A trait alias. TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>), @@ -4713,7 +4713,7 @@ impl ItemKind<'_> { | ItemKind::Enum(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Union(ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, .. } | ItemKind::TraitAlias(_, ident, ..) => Some(ident), ItemKind::Use(_, UseKind::Glob | UseKind::ListStem) @@ -4731,7 +4731,7 @@ impl ItemKind<'_> { | ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) | ItemKind::Union(_, generics, _) - | ItemKind::Trait(_, _, _, _, _, generics, _, _) + | ItemKind::Trait { generics, .. } | ItemKind::TraitAlias(_, _, generics, _) | ItemKind::Impl(Impl { generics, .. }) => generics, _ => return None, diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index b77b5cfbc0953..e93059f752223 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -618,16 +618,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V:: try_visit!(visitor.visit_generics(generics)); try_visit!(visitor.visit_variant_data(struct_definition)); } - ItemKind::Trait( - ref impl_restriction, - _constness, - _is_auto, - _safety, + ItemKind::Trait { + impl_restriction, + constness: _, + is_auto: _, + safety: _, ident, - ref generics, + generics, bounds, - trait_item_refs, - ) => { + items: trait_item_refs, + } => { if let RestrictionKind::Restricted(path) = &impl_restriction.kind { walk_list!(visitor, visit_path_segment, path.segments); } diff --git a/compiler/rustc_hir/src/target.rs b/compiler/rustc_hir/src/target.rs index 07c33eb935f21..6a1218e4ed10b 100644 --- a/compiler/rustc_hir/src/target.rs +++ b/compiler/rustc_hir/src/target.rs @@ -132,7 +132,7 @@ impl Target { ItemKind::Enum(..) => Target::Enum, ItemKind::Struct(..) => Target::Struct, ItemKind::Union(..) => Target::Union, - ItemKind::Trait(..) => Target::Trait, + ItemKind::Trait { .. } => Target::Trait, ItemKind::TraitAlias(..) => Target::TraitAlias, ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() }, } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 32610619fe713..b4d045c81dc98 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -326,7 +326,7 @@ pub(super) fn check_item<'tcx>( hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false), hir::ItemKind::Union(..) => check_type_defn(tcx, item, true), hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true), - hir::ItemKind::Trait(..) => check_trait(tcx, item), + hir::ItemKind::Trait { .. } => check_trait(tcx, item), hir::ItemKind::TraitAlias(..) => check_trait(tcx, item), _ => Ok(()), } @@ -1188,7 +1188,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant }); // Only check traits, don't check trait aliases - if let hir::ItemKind::Trait(..) = item.kind { + if let hir::ItemKind::Trait { .. } = item.kind { check_gat_where_clauses(tcx, item.owner_id.def_id); } res diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 978af77497b02..2a09962789a52 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -895,7 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { let item = tcx.hir_expect_item(def_id); let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind { - hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => ( + hir::ItemKind::Trait { impl_restriction, constness, is_auto, safety, .. } => ( constness, false, is_auto == hir::IsAuto::Yes, diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 3647c91fb7f15..f5935a4742eea 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -221,7 +221,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { // Add in the self type parameter. let opt_self = if let Node::Item(item) = node - && let ItemKind::Trait(..) | ItemKind::TraitAlias(..) = item.kind + && let ItemKind::Trait { .. } | ItemKind::TraitAlias(..) = item.kind { // Something of a hack: We reuse the node ID of the trait for the self type parameter. Some(ty::GenericParamDef { @@ -402,7 +402,7 @@ fn param_default_policy(node: Node<'_>) -> Option { Some(match node { Node::Item(item) => match item.kind { - ItemKind::Trait(..) + ItemKind::Trait { .. } | ItemKind::TraitAlias(..) | ItemKind::TyAlias(..) | ItemKind::Enum(..) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index bd1faded7587a..ad46f011a79cb 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -172,7 +172,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen )); } } - ItemKind::Trait(_, _, _, _, _, _, self_bounds, ..) + ItemKind::Trait { bounds: self_bounds, .. } | ItemKind::TraitAlias(_, _, _, self_bounds) => { is_trait = Some((self_bounds, item.span)); } @@ -669,7 +669,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( }; let (generics, superbounds) = match item.kind { - hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits), + hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits), hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits), _ => span_bug!(item.span, "super_predicates invoked on non-trait"), }; @@ -934,7 +934,7 @@ pub(super) fn type_param_predicates<'tcx>( }; if let Node::Item(item) = hir_node - && let hir::ItemKind::Trait(..) = item.kind + && let hir::ItemKind::Trait { .. } = item.kind // Implied `Self: Trait` and supertrait bounds. && param_id == item_hir_id { @@ -1073,7 +1073,7 @@ pub(super) fn const_conditions<'tcx>( Node::Item(item) => match item.kind { hir::ItemKind::Impl(impl_) => (impl_.generics, None, false), hir::ItemKind::Fn { generics, .. } => (generics, None, false), - hir::ItemKind::Trait(_, _, _, _, _, generics, supertraits, _) => { + hir::ItemKind::Trait { generics, bounds: supertraits, .. } => { (generics, Some((Some(item.owner_id.def_id), supertraits)), false) } hir::ItemKind::TraitAlias(_, _, generics, supertraits) => { @@ -1194,7 +1194,7 @@ pub(super) fn explicit_implied_const_bounds<'tcx>( } None => match tcx.hir_node_by_def_id(def_id) { Node::Item(hir::Item { - kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..), + kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..), .. }) => implied_predicates_with_filter( tcx, diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 2aebe267dc4bc..3a2f3948f0abc 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -647,7 +647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::TraitAlias(_, _, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) => { // These kinds of items have only early-bound lifetime parameters. @@ -2258,7 +2258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { // we already do that in `BoundVarContext::supertrait_hrtb_vars`. if let Res::SelfTyParam { trait_: _ } = expected_res && let hir::Node::Item(item) = node - && let hir::ItemKind::Trait(..) = item.kind + && let hir::ItemKind::Trait { .. } = item.kind { // Yield the trait's def id. Supertraits will be // elaborated from that. diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index aeb9be39c3143..41b1ec91e0e75 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -171,7 +171,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ Ty::new_adt(tcx, def, args) } ItemKind::GlobalAsm { .. } => tcx.typeck(def_id).node_type(hir_id), - ItemKind::Trait(..) + ItemKind::Trait { .. } | ItemKind::TraitAlias(..) | ItemKind::Macro(..) | ItemKind::Mod(..) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 484fe6395173c..1a401af1d328d 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -757,7 +757,7 @@ impl<'a> State<'a> { } self.bclose(item.span, cb); } - hir::ItemKind::Trait( + hir::ItemKind::Trait { impl_restriction, constness, is_auto, @@ -765,8 +765,8 @@ impl<'a> State<'a> { ident, generics, bounds, - trait_items, - ) => { + items: trait_items, + } => { let (cb, ib) = self.head(""); self.print_impl_restriction(impl_restriction); self.print_constness(constness); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index c0613eef52c37..11d536907c283 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1900,7 +1900,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { entry.1.insert((self_ty.span, String::new())); } Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, rustc_ast::ast::IsAuto::Yes, ..), + kind: hir::ItemKind::Trait { is_auto: rustc_ast::ast::IsAuto::Yes, .. }, span: item_span, .. })) => { @@ -1912,7 +1912,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some( Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, _, _, ident, ..) + hir::ItemKind::Trait { ident, .. } | hir::ItemKind::TraitAlias(_, ident, ..), .. }) @@ -4571,7 +4571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, ident, _, bounds, _), + kind: hir::ItemKind::Trait { ident, bounds, .. }, .. }) => { let (sp, sep, article) = if bounds.is_empty() { diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index e999404c6cc8a..51e65573a3566 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -267,7 +267,7 @@ impl<'tcx> CleanVisitor<'tcx> { HirItem::Union(..) => ("ItemUnion", LABELS_ADT), // Represents a Trait Declaration - HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT), + HirItem::Trait { .. } => ("ItemTrait", LABELS_TRAIT), // An implementation, eg `impl Trait for Foo { .. }` HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL), diff --git a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs index 9f2c2058998e1..be6bd68c8140f 100644 --- a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs +++ b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable { let def_id = item.owner_id.to_def_id(); // NOTE(nbdd0121): use `dyn_compatibility_violations` instead of `is_dyn_compatible` because // the latter will report `where_clause_object_safety` lint. - if let hir::ItemKind::Trait(_, _, _, _, ident, ..) = item.kind + if let hir::ItemKind::Trait { ident, .. } = item.kind && cx.tcx.is_dyn_compatible(def_id) { let direct_super_traits_iter = cx diff --git a/compiler/rustc_lint/src/types/improper_ctypes.rs b/compiler/rustc_lint/src/types/improper_ctypes.rs index eddc3f628ae63..bb047e9782d44 100644 --- a/compiler/rustc_lint/src/types/improper_ctypes.rs +++ b/compiler/rustc_lint/src/types/improper_ctypes.rs @@ -1145,7 +1145,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint { // Doesn't define something that can contain a external type to be checked. hir::ItemKind::Impl(..) | hir::ItemKind::TraitAlias(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::GlobalAsm { .. } | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Mod(..) diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 4cc0ab6304162..07dd0b390d4d2 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -654,7 +654,7 @@ impl<'tcx> TyCtxt<'tcx> { | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::Impl { .. }, .. }) @@ -705,7 +705,7 @@ impl<'tcx> TyCtxt<'tcx> { ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", - ItemKind::Trait(..) => "trait", + ItemKind::Trait { .. } => "trait", ItemKind::TraitAlias(..) => "trait alias", ItemKind::Impl { .. } => "impl", }; @@ -955,7 +955,7 @@ impl<'tcx> TyCtxt<'tcx> { }) => until_within(*outer_span, ty.span), // With generics and bounds. Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, _, generics, bounds, _), + kind: ItemKind::Trait { generics, bounds, .. }, span: outer_span, .. }) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d11825016baf3..861c460c28f84 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -497,7 +497,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_diagnostic_on_unimplemented(&self, hir_id: HirId, directive: Option<&Directive>) { if let Some(directive) = directive { if let Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, trait_name, generics, _, _), + kind: ItemKind::Trait { ident: trait_name, generics, .. }, .. }) = self.tcx.hir_node(hir_id) { @@ -931,7 +931,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item.kind { ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) if generics.params.len() != 0 => {} - ItemKind::Trait(_, _, _, _, _, generics, _, items) + ItemKind::Trait { generics, items, .. } if generics.params.len() != 0 || items.iter().any(|item| { matches!(self.tcx.def_kind(item.owner_id), DefKind::AssocTy) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index e229559ae9e5d..7eb484b1d57a7 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -486,7 +486,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { intravisit::walk_item(self, item) } hir::ItemKind::ForeignMod { .. } => ControlFlow::Continue(()), - hir::ItemKind::Trait(.., trait_item_refs) => { + hir::ItemKind::Trait { items: trait_item_refs, .. } => { // mark assoc ty live if the trait is live for trait_item in trait_item_refs { if self.tcx.def_kind(trait_item.owner_id) == DefKind::AssocTy { diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 41ec056217210..6b5457daf4a27 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -256,7 +256,7 @@ impl<'tcx> ReachableContext<'tcx> { | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 67bd3dc63afb1..990a703409d17 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -577,8 +577,9 @@ pub fn report_dyn_incompatibility<'tcx>( let trait_str = tcx.def_path_str(trait_def_id); let trait_span = tcx.hir_get_if_local(trait_def_id).and_then(|node| match node { hir::Node::Item(item) => match item.kind { - hir::ItemKind::Trait(_, _, _, _, ident, ..) - | hir::ItemKind::TraitAlias(_, ident, _, _) => Some(ident.span), + hir::ItemKind::Trait { ident, .. } | hir::ItemKind::TraitAlias(_, ident, _, _) => { + Some(ident.span) + } _ => unreachable!(), }, _ => None, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 98504d2e0553d..16be35cf28f8a 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -494,7 +494,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let node = self.tcx.hir_node_by_def_id(body_id); match node { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, ident, generics, bounds, _), + kind: hir::ItemKind::Trait { ident, generics, bounds, .. }, .. }) if self_ty == self.tcx.types.self_param => { assert!(param_ty); @@ -557,7 +557,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } hir::Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }), .. }) if projection.is_some() => { @@ -581,7 +581,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } | hir::ItemKind::TyAlias(_, generics, _) @@ -661,7 +661,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::ItemKind::Struct(_, generics, _) | hir::ItemKind::Enum(_, generics, _) | hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Trait(_, _, _, _, _, generics, ..) + | hir::ItemKind::Trait { generics, .. } | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } | hir::ItemKind::TyAlias(_, generics, _) @@ -4142,7 +4142,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let mut is_auto_trait = false; match tcx.hir_get_if_local(data.impl_or_alias_def_id) { Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, is_auto, _, ident, _, _, _), + kind: hir::ItemKind::Trait { is_auto, ident, .. }, .. })) => { // FIXME: we should do something else so that it works even on crate foreign diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 1271233d26e18..3610ffbb30c3b 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -623,7 +623,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope)) { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, _, generics, ..), + kind: hir::ItemKind::Trait { generics, .. }, .. }) | hir::Node::Item(hir::Item { diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 4e8ee9ed426c7..d1522ec89a016 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -141,7 +141,7 @@ fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> tcx.hir_get_if_local(trait_def_id) .and_then(|node| match node { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(.., generics, bounds, _), + kind: hir::ItemKind::Trait { generics, bounds, .. }, .. }) => Some( generics diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 1d24a207103c8..78095533a41ba 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -25,7 +25,7 @@ pub(crate) fn provide(providers: &mut Providers) { fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { let item = tcx.hir_expect_item(def_id); match item.kind { - hir::ItemKind::Trait(.., trait_item_refs) => { + hir::ItemKind::Trait { items: trait_item_refs, .. } => { // We collect RPITITs for each trait method's return type and create a corresponding // associated item using the associated_types_for_impl_traits_in_trait_or_impl // query. @@ -153,7 +153,7 @@ fn associated_types_for_impl_traits_in_trait_or_impl<'tcx>( let item = tcx.hir_expect_item(def_id); let disambiguators = &mut Default::default(); match item.kind { - ItemKind::Trait(.., trait_item_refs) => trait_item_refs + ItemKind::Trait { items: trait_item_refs, .. } => trait_item_refs .iter() .filter_map(move |item| { if !matches!(tcx.def_kind(item.owner_id), DefKind::AssocFn) { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 81e348f96e569..c59bd016b5e36 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2942,7 +2942,7 @@ fn clean_maybe_renamed_item<'tcx>( clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } // FIXME: rustdoc will need to handle `impl` restrictions at some point - ItemKind::Trait(_impl_restriction, _, _, _, _, generics, bounds, item_ids) => { + ItemKind::Trait { generics, bounds, items: item_ids, .. } => { let items = item_ids .iter() .map(|&ti| clean_trait_item(cx.tcx.hir_trait_item(ti), cx)) diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index 47cda92066282..ff214bad59f1d 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -349,7 +349,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> { | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::TraitAlias(..) => self.extract_info_from_hir_id(item.hir_id()), ItemKind::Impl(_) | ItemKind::Use(..) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index fda03563c79f2..8746253d6ebba 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -537,7 +537,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { | hir::ItemKind::Union(..) | hir::ItemKind::TyAlias(..) | hir::ItemKind::Static(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..) => { self.add_to_current_mod(item, renamed, import_id); } @@ -607,7 +607,7 @@ impl<'tcx> Visitor<'tcx> for RustdocVisitor<'_, 'tcx> { hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl(..) - | hir::ItemKind::Trait(..) + | hir::ItemKind::Trait { .. } ); let prev = mem::replace(&mut self.is_importable_from_parent, new_value); walk_item(self, i); diff --git a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs index 4a6c024cac9a6..21cb3c5d0443c 100644 --- a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -306,16 +306,16 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { cur_f = Some(field); } }, - ItemKind::Trait( - _impl_restriction, - _constness, + ItemKind::Trait { + impl_restriction:_, + constness:_, is_auto, - _safety, - _ident, - _generics, - _generic_bounds, - item_ref, - ) if self.enable_ordering_for_trait && *is_auto == IsAuto::No => { + safety:_, + ident:_, + generics: _, + bounds: _, + items: item_ref} + if self.enable_ordering_for_trait && *is_auto == IsAuto::No => { let mut cur_t: Option<(TraitItemId, Ident)> = None; for &item in *item_ref { @@ -510,7 +510,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte ItemKind::Enum(..) => Enum, ItemKind::Struct(..) => Struct, ItemKind::Union(..) => Union, - ItemKind::Trait(..) => Trait, + ItemKind::Trait { .. } => Trait, ItemKind::TraitAlias(..) => TraitAlias, ItemKind::Impl(..) => Impl, } diff --git a/src/tools/clippy/clippy_lints/src/doc/mod.rs b/src/tools/clippy/clippy_lints/src/doc/mod.rs index 81812880a743a..e772c20abf94d 100644 --- a/src/tools/clippy/clippy_lints/src/doc/mod.rs +++ b/src/tools/clippy/clippy_lints/src/doc/mod.rs @@ -769,7 +769,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { { missing_headers::check(cx, item.owner_id, sig, headers, Some(body), self.check_private_items); }, - ItemKind::Trait(_, _, _, unsafety, ..) => match (headers.safety, unsafety) { + ItemKind::Trait { safety, .. } => match (headers.safety, safety) { (false, Safety::Unsafe) => span_lint( cx, MISSING_SAFETY_DOC, diff --git a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 674690e7e31d8..8ba6e9d332ba8 100644 --- a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -33,7 +33,7 @@ pub(super) fn check( | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) - | ItemKind::Trait(..) + | ItemKind::Trait { .. } | ItemKind::TraitAlias(..) ) { diff --git a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs index 06bea4ba1ffd8..5ded0efacb815 100644 --- a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs +++ b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs @@ -528,7 +528,7 @@ impl LateLintPass<'_> for ItemNameRepetitions { | ItemKind::Fn { ident, .. } | ItemKind::Macro(ident, ..) | ItemKind::Static(_, ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, ..} | ItemKind::TraitAlias(_, ident, ..) | ItemKind::TyAlias(ident, ..) | ItemKind::Union(ident, ..) diff --git a/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs b/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs index 1f019531f602b..9bf06dbf452d6 100644 --- a/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs +++ b/src/tools/clippy/clippy_lints/src/len_without_is_empty.rs @@ -44,7 +44,7 @@ declare_lint_pass!(LenWithoutIsEmpty => [LEN_WITHOUT_IS_EMPTY]); impl<'tcx> LateLintPass<'tcx> for LenWithoutIsEmpty { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Trait(_, _, _, _, ident, _, _, trait_items) = item.kind + if let ItemKind::Trait { ident, items: trait_items, .. } = item.kind && !item.span.from_expansion() { check_trait_items(cx, item, ident, trait_items); diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs index 0839219c5b613..b9378d2cdd8cc 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs @@ -141,7 +141,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { let parent = cx.tcx.hir_get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID && let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) - && let hir::ItemKind::Trait(..) = &item.kind + && let hir::ItemKind::Trait { .. } = &item.kind { return; } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 35e75d34a5d3a..694a473ff5a97 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | ItemKind::Macro(ident, ..) | ItemKind::Static(_, ident, ..) | ItemKind::Struct(ident, ..) - | ItemKind::Trait(_, _, _, _, ident, ..) + | ItemKind::Trait { ident, .. } | ItemKind::TraitAlias(_, ident, ..) | ItemKind::TyAlias(ident, ..) | ItemKind::Union(ident, ..) => ident.span, diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 16dae67c29865..93cfed38c43ed 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let attrs = cx.tcx.hir_attrs(it.hir_id()); check_missing_inline_attrs(cx, attrs, it.span, desc, None); }, - hir::ItemKind::Trait(.., trait_items) => { + hir::ItemKind::Trait { items: trait_items, .. } => { // note: we need to check if the trait is exported so we can't use // `LateLintPass::check_trait_item` here. for &tit in trait_items { diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs index 74a37077b0a1d..91358ef77fa1e 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 593eff6a9bbd1..4ff5b0b0b3c39 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index b4a1713222123..6b81b9d117a37 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -292,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs index 4cd3707854c48..e4faf8e82a8e6 100644 --- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs +++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs @@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { // special handling for self trait bounds as these are not considered generics // i.e. trait Foo: Display {} if let Item { - kind: ItemKind::Trait(_, _, _, _, _, _, bounds, ..), + kind: ItemKind::Trait { bounds, .. }, .. } = item { @@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { .. }) = segments.first() && let Some(Node::Item(Item { - kind: ItemKind::Trait(_, _, _, _, _, _, self_bounds, _), + kind: ItemKind::Trait {bounds: self_bounds,..}, .. })) = cx.tcx.hir_get_if_local(*def_id) { diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs index 17e05db644b06..cecffaae69704 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs @@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) && matches!( item.kind, - ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait { .. } ) { return; diff --git a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs index 52dfcab363dbd..0b95468436127 100644 --- a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs +++ b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs @@ -131,7 +131,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms { return; } match it.kind { - ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, _, _, ident, ..) => { + ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait { ident, .. }=> { check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive); }, ItemKind::Enum(ident, _, ref enumdef) => { diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 44b9084cd4f69..e1382f5b706c0 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -265,15 +265,15 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), - ItemKind::Trait(_, _, _, Safety::Unsafe, ..) + ItemKind::Trait { safety: Safety::Unsafe, .. } | ItemKind::Impl(Impl { of_trait: Some(TraitImplHeader { safety: Safety::Unsafe, .. }), .. }) => (Pat::Str("unsafe"), Pat::Str("}")), - ItemKind::Trait(_, _, IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")), - ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")), + ItemKind::Trait { is_auto: IsAuto::Yes, .. } => (Pat::Str("auto"), Pat::Str("}")), + ItemKind::Trait { .. } => (Pat::Str("trait"), Pat::Str("}")), ItemKind::Impl(_) => (Pat::Str("impl"), Pat::Str("}")), ItemKind::Mod(..) => (Pat::Str("mod"), Pat::Str("")), ItemKind::Macro(_, def, _) => ( diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index c5fd66eeb93cd..f27c92f0d4921 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -332,7 +332,7 @@ fn local_item_child_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, ns: PathNS, n None } }), - ItemKind::Impl(..) | ItemKind::Trait(..) => tcx + ItemKind::Impl(..) | ItemKind::Trait { .. } => tcx .associated_items(local_id) .filter_by_name_unhygienic(name) .find(|assoc_item| ns.matches(Some(assoc_item.namespace()))) From 33a1ed1f4b0e8d0f15eedae6d73fc1e081b3486f Mon Sep 17 00:00:00 2001 From: zedddie Date: Mon, 20 Apr 2026 04:26:10 +0200 Subject: [PATCH 05/12] disallow non_exhaustive structs and enums with non_exhaustive variants from implementing `ConstParamTy` --- .../rustc_hir_analysis/src/check/wfcheck.rs | 1 + .../src/coherence/builtin.rs | 6 ++++ compiler/rustc_hir_analysis/src/errors.rs | 10 +++++++ .../rustc_trait_selection/src/traits/misc.rs | 17 ++++++++++- ...d-non_exhaustive-const-param-ty.min.stderr | 23 ++++++++++++++ .../forbid-non_exhaustive-const-param-ty.rs | 30 +++++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr create mode 100644 tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 07ad2a79dc7ad..4a559e7fdd839 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -911,6 +911,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er // Can never implement `ConstParamTy`, don't suggest anything. Err( ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed + | ConstParamTyImplementationError::NonExhaustive(..) | ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..), ) => None, Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => { diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index d1ce29b703eea..f23656c609e5e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -221,6 +221,12 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnNonAdt { span })) } + Err(ConstParamTyImplementationError::NonExhaustive(attr_span)) => { + let defn_span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; + Err(tcx + .dcx() + .emit_err(errors::ConstParamTyImplOnNonExhaustive { defn_span, attr_span })) + } Err(ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(infringing_tys)) => { let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span; Err(infringing_fields_error( diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index f353ace0b3886..1bb54f27dcbdd 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -317,6 +317,16 @@ pub(crate) struct ConstParamTyImplOnNonAdt { pub span: Span, } +#[derive(Diagnostic)] +#[diag("the trait `ConstParamTy` may not be implemented for this type")] +pub(crate) struct ConstParamTyImplOnNonExhaustive { + #[primary_span] + #[label("non exhaustive const params are forbidden")] + pub defn_span: Span, + #[label("caused by this attribute")] + pub attr_span: Span, +} + #[derive(Diagnostic)] #[diag("the trait `ConstParamTy` may not be implemented for this struct")] pub(crate) struct ConstParamTyFieldVisMismatch { diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index bd0068c19886f..7a0062c503685 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -4,8 +4,9 @@ use hir::LangItem; use rustc_ast::Mutability; use rustc_hir as hir; use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt}; +use rustc_middle::bug; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized}; -use rustc_span::sym; +use rustc_span::{Span, sym}; use crate::regions::InferCtxtRegionExt; use crate::traits::{self, FulfillmentError, Obligation, ObligationCause}; @@ -22,6 +23,7 @@ pub enum ConstParamTyImplementationError<'tcx> { InvalidInnerTyOfBuiltinTy(Vec<(Ty<'tcx>, InfringingFieldsReason<'tcx>)>), InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), NotAnAdtOrBuiltinAllowed, + NonExhaustive(Span), } pub enum InfringingFieldsReason<'tcx> { @@ -124,6 +126,19 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( ty::Tuple(inner_tys) => inner_tys.into_iter().collect(), ty::Adt(adt, args) if adt.is_enum() || adt.is_struct() => { + if !tcx.features().adt_const_params() { + for variant in adt.variants() { + if variant.is_field_list_non_exhaustive() { + let attr_span = match hir::find_attr!(tcx, variant.def_id, hir::attrs::AttributeKind::NonExhaustive(span) => *span) + { + Some(sp) => sp, + None => bug!("non_exhaustive variant missing NonExhaustive attribute"), + }; + return Err(ConstParamTyImplementationError::NonExhaustive(attr_span)); + } + } + } + all_fields_implement_trait( tcx, param_env, diff --git a/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr new file mode 100644 index 0000000000000..196c3397742fe --- /dev/null +++ b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.min.stderr @@ -0,0 +1,23 @@ +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/forbid-non_exhaustive-const-param-ty.rs:13:12 + | +LL | #[non_exhaustive] + | ----------------- caused by this attribute +LL | #[derive(PartialEq, Eq, ConstParamTy)] + | ------------ in this derive macro expansion +LL | pub struct Miow; + | ^^^^ non exhaustive const params are forbidden + +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/forbid-non_exhaustive-const-param-ty.rs:17:10 + | +LL | #[derive(PartialEq, Eq, ConstParamTy)] + | ------------ in this derive macro expansion +LL | pub enum Enumiow { + | ^^^^^^^ non exhaustive const params are forbidden +LL | +LL | #[non_exhaustive] NonExhaustiveThingie, + | ----------------- caused by this attribute + +error: aborting due to 2 previous errors + diff --git a/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs new file mode 100644 index 0000000000000..978f6951b12e7 --- /dev/null +++ b/tests/ui/const-generics/min_adt_const_params/forbid-non_exhaustive-const-param-ty.rs @@ -0,0 +1,30 @@ +//! Ensure that non exhaustive structs and enums with non exhaustive variants +//! aren't allowed to implement ConstParamTy under min_adt_const_params feature +//@ revisions: full min +//@[full] check-pass +#![cfg_attr(min, feature(min_adt_const_params))] +#![cfg_attr(full, feature(adt_const_params))] +#![allow(incomplete_features)] + +use std::marker::ConstParamTy; + +#[non_exhaustive] +#[derive(PartialEq, Eq, ConstParamTy)] +pub struct Miow; + //[min]~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + +#[derive(PartialEq, Eq, ConstParamTy)] +pub enum Enumiow { + //[min]~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + #[non_exhaustive] NonExhaustiveThingie, + ExhaustiveThingie, +} + +#[non_exhaustive] +#[derive(PartialEq, Eq, ConstParamTy)] +pub enum EnumiowButFine { + ExhaustiveThingie, + AlsoExhaustiveThingie, +} + +fn main() {} From d5a26d811b23359ce495ad62f13c84c0a3f63557 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 11 Apr 2026 09:47:52 +0800 Subject: [PATCH 06/12] Support trailing self in import paths --- .../src/error_codes/E0429.md | 4 +- .../rustc_resolve/src/build_reduced_graph.rs | 68 ++-- compiler/rustc_resolve/src/diagnostics.rs | 23 -- compiler/rustc_resolve/src/errors.rs | 36 +- compiler/rustc_resolve/src/lib.rs | 2 - tests/ui/error-codes/E0429.rs | 4 +- tests/ui/error-codes/E0429.stderr | 19 - tests/ui/imports/issue-45829/import-self.rs | 1 - .../ui/imports/issue-45829/import-self.stderr | 27 +- tests/ui/imports/issue-47623.stderr | 5 + tests/ui/use/use-mod/use-mod-4.rs | 2 - tests/ui/use/use-mod/use-mod-4.stderr | 37 +- tests/ui/use/use-mod/use-mod-5.rs | 4 +- tests/ui/use/use-mod/use-mod-5.stderr | 19 - tests/ui/use/use-mod/use-mod-6.rs | 4 +- tests/ui/use/use-mod/use-mod-6.stderr | 19 - tests/ui/use/use-path-segment-kw.e2015.stderr | 371 +++++------------ tests/ui/use/use-path-segment-kw.e2018.stderr | 356 ++++------------ tests/ui/use/use-path-segment-kw.rs | 24 +- tests/ui/use/use-self-at-end.e2015.stderr | 384 +++--------------- tests/ui/use/use-self-at-end.e2018.stderr | 373 +++-------------- tests/ui/use/use-self-at-end.rs | 35 +- 22 files changed, 381 insertions(+), 1436 deletions(-) delete mode 100644 tests/ui/error-codes/E0429.stderr delete mode 100644 tests/ui/use/use-mod/use-mod-5.stderr delete mode 100644 tests/ui/use/use-mod/use-mod-6.stderr diff --git a/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 cf234080e100a..e1cc094910d68 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> { @@ -613,28 +613,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { 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, - }, - ); - } + let type_ns_only = source.ident.name == kw::SelfLower; let ident = if source.ident.name == kw::SelfLower && rename.is_none() @@ -680,31 +659,36 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { return; } } - // Deny `use ::{self};` after edition 2015 - kw::SelfLower - if let Some(parent) = module_path.last() - && parent.ident.name == kw::PathRoot - && !self.r.path_root_is_crate_root(parent.ident) => - { - self.r.dcx().span_err(use_tree.span(), "extern prelude cannot be imported"); - return; + kw::SelfLower if let Some(parent) = module_path.last() => { + // Deny `use ::{self};` after edition 2015 + if parent.ident.name == kw::PathRoot + && !self.r.path_root_is_crate_root(parent.ident) + { + self.r + .dcx() + .span_err(use_tree.span(), "extern prelude cannot be imported"); + return; + } + + // Deny `use ...::self::self [as name];` but allow `use self::self as name;` + if 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; } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index cbec647bdc95e..a3bba230a2584 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -913,29 +913,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/lib.rs b/compiler/rustc_resolve/src/lib.rs index 6e15f055c6aca..3b8f3c4a24c90 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/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/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..51590a2a0117e 100644 --- a/tests/ui/imports/issue-45829/import-self.stderr +++ b/tests/ui/imports/issue-45829/import-self.stderr @@ -4,22 +4,6 @@ error: expected identifier, found keyword `self` LL | use foo as self; | ^^^^ expected identifier, found keyword -error[E0429]: `self` imports are only allowed within a { } list - --> $DIR/import-self.rs:12:8 - | -LL | use foo::self; - | ^^^^^^ - | -help: consider importing the module directly - | -LL - use foo::self; -LL + use foo; - | -help: alternatively, use the multi-path `use` syntax to import `self` - | -LL | use foo::{self}; - | + + - error[E0255]: the name `foo` is defined multiple times --> $DIR/import-self.rs:6:11 | @@ -47,11 +31,12 @@ LL | use foo::self; = note: `foo` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | -LL | use foo::self as other_foo; - | ++++++++++++ +LL - use foo::self; +LL + use 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 +49,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-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..486c8c73b7371 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:176: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:179: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:192: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:194: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:198: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:200: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:204: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:206: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:184: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:188: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:186: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:189:17 | LL | pub use foobar::{self as _nested_self3}; | ^^^^^^ @@ -980,7 +797,7 @@ 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 + --> $DIR/use-path-segment-kw.rs:209:36 | LL | type D7 = crate::foo::bar::self; | ^^^^ can only be used in path start position @@ -997,31 +814,31 @@ 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` - --> $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 @@ -1126,84 +943,84 @@ 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]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 + --> $DIR/use-path-segment-kw.rs:175:21 | LL | type D2 = ::self; | ^^^^ cannot start with this error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 + --> $DIR/use-path-segment-kw.rs:183: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 + --> $DIR/use-path-segment-kw.rs:191: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 + --> $DIR/use-path-segment-kw.rs:197: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 + --> $DIR/use-path-segment-kw.rs:203: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..5d2e0d518cefb 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,107 +257,53 @@ 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:176:13 | LL | use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:180:13 + --> $DIR/use-path-segment-kw.rs:178:13 | LL | use ::self as _self2; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:182:16 + --> $DIR/use-path-segment-kw.rs:179:16 | LL | use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:184:20 + --> $DIR/use-path-segment-kw.rs:181: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:192: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:194: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:198: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:200: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:204: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:206: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}; | ^^^^ @@ -931,13 +755,13 @@ 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 + --> $DIR/use-path-segment-kw.rs:209: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:235:15 | LL | foo::bar::_nested_self2::outer(); | ^^^^^^^^^^^^^ could not find `_nested_self2` in `bar` @@ -954,31 +778,31 @@ 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` - --> $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 @@ -1083,84 +907,84 @@ 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]: global paths cannot start with `crate` - --> $DIR/use-path-segment-kw.rs:100:21 + --> $DIR/use-path-segment-kw.rs:99:21 | LL | type B2 = ::crate; | ^^^^^ cannot start with this error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:106:27 + --> $DIR/use-path-segment-kw.rs:105:27 | LL | type B3 = foobar::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:112:26 + --> $DIR/use-path-segment-kw.rs:111:26 | LL | type B4 = crate::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:118:26 + --> $DIR/use-path-segment-kw.rs:117:26 | LL | type B5 = super::crate; | ^^^^^ can only be used in path start position error[E0433]: `crate` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:124:25 + --> $DIR/use-path-segment-kw.rs:123:25 | LL | type B6 = self::crate; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `super` - --> $DIR/use-path-segment-kw.rs:138:21 + --> $DIR/use-path-segment-kw.rs:137:21 | LL | type C2 = ::super; | ^^^^^ cannot start with this error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:144:27 + --> $DIR/use-path-segment-kw.rs:143:27 | LL | type C3 = foobar::super; | ^^^^^ can only be used in path start position error[E0433]: `super` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:150:26 + --> $DIR/use-path-segment-kw.rs:149:26 | LL | type C4 = crate::super; | ^^^^^ can only be used in path start position error[E0433]: global paths cannot start with `self` - --> $DIR/use-path-segment-kw.rs:176:21 + --> $DIR/use-path-segment-kw.rs:175:21 | LL | type D2 = ::self; | ^^^^ cannot start with this error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:186:27 + --> $DIR/use-path-segment-kw.rs:183: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 + --> $DIR/use-path-segment-kw.rs:191: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 + --> $DIR/use-path-segment-kw.rs:197: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 + --> $DIR/use-path-segment-kw.rs:203:25 | LL | type D6 = self::self; | ^^^^ can only be used in path start position -error: aborting due to 126 previous errors +error: aborting due to 114 previous errors -Some errors have detailed explanations: E0429, E0433, E0573. -For more information about an error, try `rustc --explain E0429`. +Some errors have detailed explanations: E0433, E0573. +For more information about an error, try `rustc --explain E0433`. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index c9b404887e605..4c07f9b96fc36 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -61,8 +61,7 @@ macro_rules! macro_dollar_crate { type A10 = $crate::self; //~ ERROR `self` in paths can only be used in start position 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 } @@ -176,45 +175,40 @@ pub mod foo { type D2 = ::self; //~ ERROR global paths cannot start with `self` use ::self; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported - //[e2015]~^ ERROR `self` imports are only allowed within a { } list use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named pub use ::{self as _nested_self2}; //[e2018]~ ERROR extern prelude cannot be imported type D3 = foobar::self; //~ ERROR `self` in paths can only be used in start position - pub use foobar::qux::self; //~ ERROR `self` imports are only allowed within a { } list + 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 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 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 + 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 + 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..3c9f7c5af88f9 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,58 +86,19 @@ 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:46: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 + --> $DIR/use-self-at-end.rs:49:20 | LL | pub use ::{self}; | ^^^^ @@ -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 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:54: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:55: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:56: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 +error: `self` in paths can only be used in start position or last position + --> $DIR/use-self-at-end.rs:57:21 | -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:68: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:74:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -410,84 +174,62 @@ 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:60: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:61: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:62: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:70:24 + --> $DIR/use-self-at-end.rs:63: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 - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:39:28 + | +LL | type E = crate::x::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:53:21 | LL | type G = z::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:72:31 + --> $DIR/use-self-at-end.rs:65:31 | LL | type I = super::Enum::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:78:32 + --> $DIR/use-self-at-end.rs:71:32 | LL | type J = super::Trait::self; | ^^^^ can only be used in path start position 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 - | -help: consider importing this module - | -LL + use x; - | -help: if you import `x`, refer to it directly - | -LL - type E = crate::x::self; -LL + type E = x::self; - | - error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:59:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -505,24 +247,24 @@ 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 + --> $DIR/use-self-at-end.rs:25: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 + --> $DIR/use-self-at-end.rs:32:25 | 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 + --> $DIR/use-self-at-end.rs:45:20 | LL | type F = ::self; | ^^^^ cannot start with this -error: aborting due to 49 previous errors +error: aborting due to 31 previous errors -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..9bd01e9c257d6 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,209 +86,56 @@ 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:46: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:48:17 | LL | pub use ::self as crate4; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:52:20 + --> $DIR/use-self-at-end.rs:49:20 | LL | pub use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:54:20 + --> $DIR/use-self-at-end.rs:51:20 | LL | pub use ::{self as crate5}; | ^^^^^^^^^^^^^^ -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:54: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:55: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:56: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:57: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:68: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:74:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -405,84 +176,62 @@ 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:60: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:61: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:62: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:70:24 + --> $DIR/use-self-at-end.rs:63: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 - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:39:28 + | +LL | type E = crate::x::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:53:21 | LL | type G = z::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:72:31 + --> $DIR/use-self-at-end.rs:65:31 | LL | type I = super::Enum::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:78:32 + --> $DIR/use-self-at-end.rs:71:32 | LL | type J = super::Trait::self; | ^^^^ can only be used in path start position 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 - | -help: consider importing this module - | -LL + use crate::x; - | -help: if you import `x`, refer to it directly - | -LL - type E = crate::x::self; -LL + type E = x::self; - | - error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:64:18 + --> $DIR/use-self-at-end.rs:59:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -500,24 +249,24 @@ 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 + --> $DIR/use-self-at-end.rs:25: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 + --> $DIR/use-self-at-end.rs:32:25 | 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 + --> $DIR/use-self-at-end.rs:45:20 | LL | type F = ::self; | ^^^^ cannot start with this -error: aborting due to 49 previous errors +error: aborting due to 33 previous errors -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.rs b/tests/ui/use/use-self-at-end.rs index 84337dc9e5031..c570c3bb12962 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -11,9 +11,8 @@ pub mod x { 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 + 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}; @@ -24,60 +23,54 @@ pub mod x { 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 + 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 + 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 + 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 //[e2015]~^ ERROR imports need to be explicitly named - //[e2015]~^^ ERROR `self` imports are only allowed within a { } list 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 + 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 + 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}; } From 44679405551b53327e83af09120841d1802cdbf2 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 11 Apr 2026 10:47:11 +0800 Subject: [PATCH 07/12] Support trailing self in normal paths --- .../rustc_resolve/src/build_reduced_graph.rs | 42 ++++--- compiler/rustc_resolve/src/ident.rs | 17 ++- tests/ui/delegation/bad-resolve.rs | 1 + tests/ui/delegation/bad-resolve.stderr | 8 +- .../absolute-paths-in-nested-use-groups.rs | 2 +- ...absolute-paths-in-nested-use-groups.stderr | 12 +- tests/ui/use/use-mod/use-mod-3.stderr | 2 + tests/ui/use/use-path-segment-kw.e2015.stderr | 118 +++++++++--------- tests/ui/use/use-path-segment-kw.e2018.stderr | 104 +++++++-------- tests/ui/use/use-path-segment-kw.rs | 16 +-- tests/ui/use/use-self-at-end.e2015.stderr | 108 ++++++++-------- tests/ui/use/use-self-at-end.e2018.stderr | 100 +++++++-------- tests/ui/use/use-self-at-end.rs | 21 ++-- tests/ui/use/use-super-in-middle.stderr | 8 +- 14 files changed, 299 insertions(+), 260 deletions(-) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index e1cc094910d68..5f3264d8cd3a2 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -615,6 +615,8 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { // `true` for `...::{self [as target]}` imports, `false` otherwise. let type_ns_only = source.ident.name == kw::SelfLower; + // 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() @@ -659,29 +661,31 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { return; } } - kw::SelfLower if let Some(parent) = module_path.last() => { - // Deny `use ::{self};` after edition 2015 - if parent.ident.name == kw::PathRoot - && !self.r.path_root_is_crate_root(parent.ident) - { - self.r - .dcx() - .span_err(use_tree.span(), "extern prelude cannot be imported"); - return; - } - - // Deny `use ...::self::self [as name];` but allow `use self::self as name;` - if 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 `use ::{self};` after edition 2015 + kw::SelfLower + if let Some(parent) = module_path.last() + && parent.ident.name == kw::PathRoot + && !self.r.path_root_is_crate_root(parent.ident) => + { + self.r.dcx().span_err(use_tree.span(), "extern prelude cannot be imported"); + return; } _ => (), } + // Deny `use ...::self::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(); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 35ed1c772a328..db4f551a38b26 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1837,8 +1837,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } + // Support `...::self`, but deny `::self` after edition 2018 + let allow_trailing_self = is_last + && name == kw::SelfLower + && segment_idx > 0 + && (path[segment_idx - 1].ident.name != kw::PathRoot + || self.path_root_is_crate_root(path[segment_idx - 1].ident)); + // 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, @@ -1858,6 +1865,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/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index 5744bd1f994c8..2c2c622e09006 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -41,5 +41,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 f79eaa5bfc28f..d1b3974e77081 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:43:7 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^^^ not a function + error[E0046]: not all trait items implemented, missing: `Type` --> $DIR/bad-resolve.rs:21: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/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/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-path-segment-kw.e2015.stderr b/tests/ui/use/use-path-segment-kw.e2015.stderr index 486c8c73b7371..a63cce80896ab 100644 --- a/tests/ui/use/use-path-segment-kw.e2015.stderr +++ b/tests/ui/use/use-path-segment-kw.e2015.stderr @@ -268,7 +268,7 @@ LL | use self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:176:15 + --> $DIR/use-path-segment-kw.rs:178:15 | LL | use ::self; | ^^^^ @@ -279,7 +279,7 @@ LL | use ::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:179:16 + --> $DIR/use-path-segment-kw.rs:181:16 | LL | use ::{self}; | ^^^^ @@ -290,7 +290,7 @@ LL | use ::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:192:20 + --> $DIR/use-path-segment-kw.rs:194:20 | LL | use crate::self; | ^^^^ @@ -301,7 +301,7 @@ LL | use crate::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:194:21 + --> $DIR/use-path-segment-kw.rs:196:21 | LL | use crate::{self}; | ^^^^ @@ -312,7 +312,7 @@ LL | use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:20 + --> $DIR/use-path-segment-kw.rs:200:20 | LL | use super::self; | ^^^^ @@ -323,7 +323,7 @@ LL | use super::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:200:21 + --> $DIR/use-path-segment-kw.rs:202:21 | LL | use super::{self}; | ^^^^ @@ -334,7 +334,7 @@ LL | use super::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:204:19 + --> $DIR/use-path-segment-kw.rs:206:19 | LL | use self::self; | ^^^^ @@ -345,7 +345,7 @@ LL | use self::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:206:20 + --> $DIR/use-path-segment-kw.rs:208:20 | LL | use self::{self}; | ^^^^ @@ -753,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:184:17 + --> $DIR/use-path-segment-kw.rs:186:17 | LL | pub use foobar::qux::self; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -764,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:188:17 + --> $DIR/use-path-segment-kw.rs:190:17 | LL | pub use foobar::baz::{self}; | ^^^^^^ use of unresolved module or unlinked crate `foobar` @@ -775,7 +775,7 @@ LL + extern crate foobar; | error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:186:17 + --> $DIR/use-path-segment-kw.rs:188:17 | LL | pub use foobar::self as _self3; | ^^^^^^ @@ -786,7 +786,7 @@ LL | pub use self::foobar::self as _self3; | ++++++ error[E0432]: unresolved import `foobar` - --> $DIR/use-path-segment-kw.rs:189:17 + --> $DIR/use-path-segment-kw.rs:191:17 | LL | pub use foobar::{self as _nested_self3}; | ^^^^^^ @@ -796,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:209: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 | @@ -813,6 +807,17 @@ 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:95:19 | @@ -843,6 +848,42 @@ error[E0573]: expected type, found module `self` 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 | @@ -931,17 +972,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[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:99:21 | @@ -990,36 +1020,6 @@ error[E0433]: `super` in paths can only be used in start position 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:175:21 - | -LL | type D2 = ::self; - | ^^^^ cannot start with this - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-path-segment-kw.rs:183: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:191: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:197: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:203:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - error: aborting due to 115 previous errors Some errors have detailed explanations: E0432, E0433, E0573. diff --git a/tests/ui/use/use-path-segment-kw.e2018.stderr b/tests/ui/use/use-path-segment-kw.e2018.stderr index 5d2e0d518cefb..eb80405232e14 100644 --- a/tests/ui/use/use-path-segment-kw.e2018.stderr +++ b/tests/ui/use/use-path-segment-kw.e2018.stderr @@ -268,31 +268,31 @@ LL | use self as name; | +++++++ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:176:13 + --> $DIR/use-path-segment-kw.rs:178:13 | LL | use ::self; | ^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:178:13 + --> $DIR/use-path-segment-kw.rs:180:13 | LL | use ::self as _self2; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:179:16 + --> $DIR/use-path-segment-kw.rs:181:16 | LL | use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-path-segment-kw.rs:181:20 + --> $DIR/use-path-segment-kw.rs:183:20 | LL | pub use ::{self as _nested_self2}; | ^^^^^^^^^^^^^^^^^^^^^ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:192:20 + --> $DIR/use-path-segment-kw.rs:194:20 | LL | use crate::self; | ^^^^ @@ -303,7 +303,7 @@ LL | use crate::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:194:21 + --> $DIR/use-path-segment-kw.rs:196:21 | LL | use crate::{self}; | ^^^^ @@ -314,7 +314,7 @@ LL | use crate::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:198:20 + --> $DIR/use-path-segment-kw.rs:200:20 | LL | use super::self; | ^^^^ @@ -325,7 +325,7 @@ LL | use super::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:200:21 + --> $DIR/use-path-segment-kw.rs:202:21 | LL | use super::{self}; | ^^^^ @@ -336,7 +336,7 @@ LL | use super::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:204:19 + --> $DIR/use-path-segment-kw.rs:206:19 | LL | use self::self; | ^^^^ @@ -347,7 +347,7 @@ LL | use self::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-path-segment-kw.rs:206:20 + --> $DIR/use-path-segment-kw.rs:208:20 | LL | use self::{self}; | ^^^^ @@ -754,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:209: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:235:15 + --> $DIR/use-path-segment-kw.rs:237:15 | LL | foo::bar::_nested_self2::outer(); | ^^^^^^^^^^^^^ could not find `_nested_self2` in `bar` @@ -777,6 +771,17 @@ 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:95:19 | @@ -807,6 +812,36 @@ error[E0573]: expected type, found module `self` LL | type D1 = 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 | @@ -895,17 +930,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[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:99:21 | @@ -960,30 +984,6 @@ error[E0433]: global paths cannot start with `self` 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:183: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:191: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:197: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:203:25 - | -LL | type D6 = self::self; - | ^^^^ can only be used in path start position - error: aborting due to 114 previous errors Some errors have detailed explanations: E0433, E0573. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index 4c07f9b96fc36..739aba007c697 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -59,7 +59,7 @@ 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 pub use $crate::self as _m_self8; use $crate::{self}; //~ ERROR imports need to be explicitly named @@ -172,7 +172,9 @@ 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 global paths cannot start with `self` use ::self; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported @@ -180,7 +182,7 @@ pub mod foo { //[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 + 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; @@ -188,25 +190,25 @@ pub mod foo { 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 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 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 + 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 + 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}; diff --git a/tests/ui/use/use-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr index 3c9f7c5af88f9..812b39aef70d4 100644 --- a/tests/ui/use/use-self-at-end.e2015.stderr +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -87,7 +87,7 @@ LL | pub use super::{self as name}; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:46:19 + --> $DIR/use-self-at-end.rs:48:19 | LL | pub use ::self; | ^^^^ @@ -98,7 +98,7 @@ LL | pub use ::self as name; | +++++++ error: imports need to be explicitly named - --> $DIR/use-self-at-end.rs:49:20 + --> $DIR/use-self-at-end.rs:52:20 | LL | pub use ::{self}; | ^^^^ @@ -109,25 +109,25 @@ LL | pub use ::{self as name}; | +++++++ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:54:20 + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:55:20 + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:57:21 + --> $DIR/use-self-at-end.rs:60:21 | LL | pub use z::{self::{self as z2}}; | ^^^^ @@ -147,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:68:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -161,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:74:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -175,52 +175,40 @@ LL | pub use super::Trait::{self}; = note: `Trait` must be defined only once in the type namespace of this module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:60: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:61: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:62:24 + --> $DIR/use-self-at-end.rs:65: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:63: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 - --> $DIR/use-self-at-end.rs:39:28 - | -LL | type E = crate::x::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:53:21 +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 - -error[E0433]: `self` in paths can only be used in start position - --> $DIR/use-self-at-end.rs:65:31 - | -LL | type I = super::Enum::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:71: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:19:18 @@ -228,8 +216,32 @@ error[E0573]: expected type, found module `self` LL | type B = self; | ^^^^ not a type +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 + | +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 + | +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; + | ^^^^^^^^^^^^^^ 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:59:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -240,31 +252,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 - | -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:25:24 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/use-self-at-end.rs:74:18 | -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:32: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:45: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 31 previous errors +error: aborting due to 29 previous errors; 1 warning emitted 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 9bd01e9c257d6..b133a6c8c4ebc 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -87,49 +87,49 @@ LL | pub use super::{self as name}; | +++++++ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:46: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:48:17 + --> $DIR/use-self-at-end.rs:51:17 | LL | pub use ::self as crate4; | ^^^^^^^^^^^^^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:49:20 + --> $DIR/use-self-at-end.rs:52:20 | LL | pub use ::{self}; | ^^^^ error: extern prelude cannot be imported - --> $DIR/use-self-at-end.rs:51:20 + --> $DIR/use-self-at-end.rs:54:20 | LL | pub use ::{self as crate5}; | ^^^^^^^^^^^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:54:20 + --> $DIR/use-self-at-end.rs:57:20 | LL | pub use z::self::self; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:55:20 + --> $DIR/use-self-at-end.rs:58:20 | LL | pub use z::self::self as z1; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:56:21 + --> $DIR/use-self-at-end.rs:59:21 | LL | pub use z::{self::{self}}; | ^^^^ error: `self` in paths can only be used in start position or last position - --> $DIR/use-self-at-end.rs:57:21 + --> $DIR/use-self-at-end.rs:60:21 | LL | pub use z::{self::{self as z2}}; | ^^^^ @@ -149,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:68:31 + --> $DIR/use-self-at-end.rs:71:31 | LL | pub use super::Enum::self; | ----------------- previous import of the type `Enum` here @@ -163,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:74:32 + --> $DIR/use-self-at-end.rs:79:32 | LL | pub use super::Trait::self; | ------------------ previous import of the trait `Trait` here @@ -177,52 +177,40 @@ LL | pub use super::Trait::{self}; = note: `Trait` must be defined only once in the type namespace of this module error[E0432]: unresolved import `super::Struct` - --> $DIR/use-self-at-end.rs:60: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:61: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:62:24 + --> $DIR/use-self-at-end.rs:65: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:63: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 - --> $DIR/use-self-at-end.rs:39:28 - | -LL | type E = crate::x::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:53:21 +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:65:31 +error[E0573]: expected type, found module `crate::self` + --> $DIR/use-self-at-end.rs:13:18 | -LL | type I = super::Enum::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:71:32 - | -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:19:18 @@ -230,8 +218,26 @@ error[E0573]: expected type, found module `self` LL | type B = self; | ^^^^ not a type +error[E0573]: expected type, found module `self::self` + --> $DIR/use-self-at-end.rs:25:18 + | +LL | type C = self::self; + | ^^^^^^^^^^ not a type + +error[E0573]: expected type, found module `super::self` + --> $DIR/use-self-at-end.rs:32:18 + | +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; + | ^^^^^^^^^^^^^^ not a type + error[E0223]: ambiguous associated type - --> $DIR/use-self-at-end.rs:59:18 + --> $DIR/use-self-at-end.rs:62:18 | LL | type H = super::Struct::self; | ^^^^^^^^^^^^^^^^^^^ @@ -242,23 +248,19 @@ 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:25:24 +LL | type J = super::Trait::self; + | ^^^^^^^^^^^^^^^^^^ | -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:32:25 + = 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 D = super::self; - | ^^^^ can only be used in path start position +LL | type J = dyn super::Trait::self; + | +++ error[E0433]: global paths cannot start with `self` --> $DIR/use-self-at-end.rs:45:20 @@ -266,7 +268,7 @@ error[E0433]: global paths cannot start with `self` LL | type F = ::self; | ^^^^ cannot start with this -error: aborting due to 33 previous errors +error: aborting due to 31 previous errors; 1 warning emitted 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.rs b/tests/ui/use/use-self-at-end.rs index c570c3bb12962..5bb46585da9dc 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -10,7 +10,7 @@ pub mod x { pub mod y { pub mod z {} - type A = crate::self; //~ ERROR `self` in paths can only be used in start position + 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 @@ -22,29 +22,32 @@ 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 + 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; 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 + 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; 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 + 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 global paths cannot start with `self` + pub use ::self; //[e2015]~^ ERROR imports need to be explicitly named + //[e2018]~^^ ERROR extern prelude cannot be imported pub use ::self as crate4; //[e2018]~ ERROR extern prelude cannot be imported pub use ::{self}; //[e2018]~ ERROR extern prelude cannot be imported //[e2015]~^ ERROR imports need to be explicitly named @@ -62,13 +65,15 @@ pub mod x { 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 + 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 + 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 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 From 8b584ebcf6572c660b24fb4b79a5fcb2efd97f8f Mon Sep 17 00:00:00 2001 From: mu001999 Date: Sat, 11 Apr 2026 10:51:32 +0800 Subject: [PATCH 08/12] Remove type_ns_only --- .../rustc_resolve/src/build_reduced_graph.rs | 18 +- compiler/rustc_resolve/src/diagnostics.rs | 3 - compiler/rustc_resolve/src/imports.rs | 259 +++++++++--------- .../ui/imports/issue-45829/import-self.stderr | 5 +- 4 files changed, 131 insertions(+), 154 deletions(-) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 5f3264d8cd3a2..6310155154b95 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -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); }); } } @@ -612,9 +610,6 @@ 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 = source.ident.name == kw::SelfLower; - // If the identifier is `self` without a rename, // then it is replaced with the parent identifier. let ident = if source.ident.name == kw::SelfLower @@ -700,7 +695,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 a3bba230a2584..723890a2f1ca2 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) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index b6ba35f0f3db8..a3b80ae264da6 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -73,8 +73,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`. @@ -115,7 +113,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) @@ -124,7 +122,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 @@ -1215,10 +1208,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 @@ -1286,86 +1277,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/tests/ui/imports/issue-45829/import-self.stderr b/tests/ui/imports/issue-45829/import-self.stderr index 51590a2a0117e..978d20490b282 100644 --- a/tests/ui/imports/issue-45829/import-self.stderr +++ b/tests/ui/imports/issue-45829/import-self.stderr @@ -31,9 +31,8 @@ LL | use foo::self; = note: `foo` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | -LL - use foo::self; -LL + use self as other_foo; - | +LL | use foo::self as other_foo; + | ++++++++++++ error[E0252]: the name `A` is defined multiple times --> $DIR/import-self.rs:15:11 From ddb27210757c40f7622d4f0947d1889c9736df37 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Mon, 13 Apr 2026 22:44:24 +0800 Subject: [PATCH 09/12] Add test for middle self --- tests/ui/use/use-self-at-end.e2015.stderr | 32 ++++++++++++++++++++++- tests/ui/use/use-self-at-end.e2018.stderr | 32 ++++++++++++++++++++++- tests/ui/use/use-self-at-end.rs | 6 +++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/tests/ui/use/use-self-at-end.e2015.stderr b/tests/ui/use/use-self-at-end.e2015.stderr index 812b39aef70d4..a0f834bda1052 100644 --- a/tests/ui/use/use-self-at-end.e2015.stderr +++ b/tests/ui/use/use-self-at-end.e2015.stderr @@ -192,6 +192,30 @@ error[E0432]: unresolved import `super::Struct` 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:66:24 | @@ -204,6 +228,12 @@ error[E0433]: `self` in paths can only be used in start position or last positio LL | type G = z::self::self; | ^^^^ 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:82:25 + | +LL | type K = super::self::y::z; + | ^^^^ can only be used in path start position or last position + error[E0573]: expected type, found module `crate::self` --> $DIR/use-self-at-end.rs:13:18 | @@ -266,7 +296,7 @@ help: if this is a dyn-compatible trait, use `dyn` LL | type J = dyn super::Trait::self; | +++ -error: aborting due to 29 previous errors; 1 warning emitted +error: aborting due to 34 previous errors; 1 warning emitted 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 b133a6c8c4ebc..4032db9204d8e 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -194,6 +194,30 @@ error[E0432]: unresolved import `super::Struct` 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:66:24 | @@ -206,6 +230,12 @@ error[E0433]: `self` in paths can only be used in start position or last positio LL | type G = z::self::self; | ^^^^ 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:82:25 + | +LL | type K = super::self::y::z; + | ^^^^ can only be used in path start position or last position + error[E0573]: expected type, found module `crate::self` --> $DIR/use-self-at-end.rs:13:18 | @@ -268,7 +298,7 @@ error[E0433]: global paths cannot start with `self` LL | type F = ::self; | ^^^^ cannot start with this -error: aborting due to 31 previous errors; 1 warning emitted +error: aborting due to 36 previous errors; 1 warning emitted 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.rs b/tests/ui/use/use-self-at-end.rs index 5bb46585da9dc..2c966c16b8117 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -78,6 +78,12 @@ pub mod x { 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 } } From d93395c3ff482020469d429a79fb7d55b23dc196 Mon Sep 17 00:00:00 2001 From: mu001999 Date: Mon, 13 Apr 2026 22:45:57 +0800 Subject: [PATCH 10/12] Remove the special case of ::self after edition 2018 --- compiler/rustc_resolve/src/ident.rs | 7 +------ tests/ui/use/use-path-segment-kw.e2018.stderr | 16 ++++++++-------- tests/ui/use/use-path-segment-kw.rs | 2 +- tests/ui/use/use-self-at-end.e2018.stderr | 14 +++++++------- tests/ui/use/use-self-at-end.rs | 2 +- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index db4f551a38b26..a0f63a47f9b4e 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1837,12 +1837,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } - // Support `...::self`, but deny `::self` after edition 2018 - let allow_trailing_self = is_last - && name == kw::SelfLower - && segment_idx > 0 - && (path[segment_idx - 1].ident.name != kw::PathRoot - || self.path_root_is_crate_root(path[segment_idx - 1].ident)); + 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 && !allow_trailing_self { diff --git a/tests/ui/use/use-path-segment-kw.e2018.stderr b/tests/ui/use/use-path-segment-kw.e2018.stderr index eb80405232e14..3f1b01a27de54 100644 --- a/tests/ui/use/use-path-segment-kw.e2018.stderr +++ b/tests/ui/use/use-path-segment-kw.e2018.stderr @@ -812,6 +812,12 @@ error[E0573]: expected type, found module `self` 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 | @@ -978,13 +984,7 @@ error[E0433]: `super` in paths can only be used in start position 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:175:21 - | -LL | type D2 = ::self; - | ^^^^ cannot start with this - error: aborting due to 114 previous errors -Some errors have detailed explanations: E0433, E0573. -For more information about an error, try `rustc --explain E0433`. +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 739aba007c697..583f07d9a81fb 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -174,7 +174,7 @@ pub mod foo { type D2 = ::self; //[e2015]~^ ERROR expected type, found module `::self` - //[e2018]~^^ ERROR global paths cannot start with `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 use ::self as _self2; //[e2018]~ ERROR extern prelude cannot be imported diff --git a/tests/ui/use/use-self-at-end.e2018.stderr b/tests/ui/use/use-self-at-end.e2018.stderr index 4032db9204d8e..6d82c061d9247 100644 --- a/tests/ui/use/use-self-at-end.e2018.stderr +++ b/tests/ui/use/use-self-at-end.e2018.stderr @@ -266,6 +266,12 @@ error[E0573]: expected type, found module `crate::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:62:18 | @@ -292,13 +298,7 @@ help: if this is a dyn-compatible trait, use `dyn` LL | type J = dyn super::Trait::self; | +++ -error[E0433]: global paths cannot start with `self` - --> $DIR/use-self-at-end.rs:45:20 - | -LL | type F = ::self; - | ^^^^ cannot start with this - error: aborting due to 36 previous errors; 1 warning emitted -Some errors have detailed explanations: E0223, E0252, 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 2c966c16b8117..64b17483445a3 100644 --- a/tests/ui/use/use-self-at-end.rs +++ b/tests/ui/use/use-self-at-end.rs @@ -44,7 +44,7 @@ pub mod x { type F = ::self; //[e2015]~^ ERROR expected type, found module `::self` - //[e2018]~^^ ERROR global paths cannot start with `self` + //[e2018]~^^ ERROR cannot find crate `self` in the list of imported crates pub use ::self; //[e2015]~^ ERROR imports need to be explicitly named //[e2018]~^^ ERROR extern prelude cannot be imported From 7616881793995e2acbd22391bbae3defca8a2d3d Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 27 Apr 2026 18:57:50 +0800 Subject: [PATCH 11/12] Avoid misleading closure return type note --- compiler/rustc_hir_typeck/src/coercion.rs | 11 +++++---- .../closure-return-block-note-issue-155670.rs | 24 +++++++++++++++++++ ...sure-return-block-note-issue-155670.stderr | 14 ++++++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 4dac314b91812..1fa08bbde9a24 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1998,9 +1998,13 @@ impl<'tcx> CoerceMany<'tcx> { ); } - let ret_coercion_span = fcx.ret_coercion_span.get(); + let is_return_position = fcx + .tcx + .hir_get_fn_id_for_return_block(block_or_return_id) + .is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id)); - if let Some(sp) = ret_coercion_span + if is_return_position + && let Some(sp) = fcx.ret_coercion_span.get() // If the closure has an explicit return type annotation, or if // the closure's return type has been inferred from outside // requirements (such as an Fn* trait bound), then a type error @@ -2009,9 +2013,6 @@ impl<'tcx> CoerceMany<'tcx> { // note in this case, since it would be incorrect. && let Some(fn_sig) = fcx.body_fn_sig() && fn_sig.output().is_ty_var() - && fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| { - fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected - }) { err.span_note(sp, format!("return type inferred to be `{expected}` here")); } diff --git a/tests/ui/closures/closure-return-block-note-issue-155670.rs b/tests/ui/closures/closure-return-block-note-issue-155670.rs index fccce9ee54ca2..004d96aa04635 100644 --- a/tests/ui/closures/closure-return-block-note-issue-155670.rs +++ b/tests/ui/closures/closure-return-block-note-issue-155670.rs @@ -11,4 +11,28 @@ const _: fn() = || { }; }; +const _: fn() -> SmolStr = || { + match Some(()) { + Some(()) => (), + None => return SmolStr, + }; + let _: String = { + SmolStr + //~^ ERROR mismatched types + }; + SmolStr +}; + +const _: fn() -> String = || { + match Some(()) { + Some(()) => (), + None => return String::new(), + }; + let _: String = { + SmolStr + //~^ ERROR mismatched types + }; + String::new() +}; + fn main() {} diff --git a/tests/ui/closures/closure-return-block-note-issue-155670.stderr b/tests/ui/closures/closure-return-block-note-issue-155670.stderr index f38d2f14200d4..faacdcca8ab61 100644 --- a/tests/ui/closures/closure-return-block-note-issue-155670.stderr +++ b/tests/ui/closures/closure-return-block-note-issue-155670.stderr @@ -4,6 +4,18 @@ error[E0308]: mismatched types LL | SmolStr | ^^^^^^^ expected `String`, found `SmolStr` -error: aborting due to 1 previous error +error[E0308]: mismatched types + --> $DIR/closure-return-block-note-issue-155670.rs:20:9 + | +LL | SmolStr + | ^^^^^^^ expected `String`, found `SmolStr` + +error[E0308]: mismatched types + --> $DIR/closure-return-block-note-issue-155670.rs:32:9 + | +LL | SmolStr + | ^^^^^^^ expected `String`, found `SmolStr` + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. From 57008e9e3b8b4b52ff26decb1c7da8498c8b3c64 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 26 Apr 2026 20:05:49 +0200 Subject: [PATCH 12/12] CI: rfl: move job forward to Linux v7.1-rc1 Linux v7.1 will have our new MSRVs: Rust 1.85.0 and `bindgen` 0.71.1. Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index a959bc9da3ac5..54ede153f6153 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -2,7 +2,7 @@ set -euo pipefail -LINUX_VERSION=v7.0 +LINUX_VERSION=v7.1-rc1 # Build rustc, rustdoc, cargo, clippy-driver and rustfmt ../x.py build --stage 2 library rustdoc clippy rustfmt