From 2e29d85f7e88e06bb780d74749c156f03b2ff5f2 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Wed, 2 Aug 2023 10:55:22 -0700 Subject: [PATCH 1/9] Avoid exporting symbols more than once. Exporting `__rust_alloc_error_handler_should_panic` multiple times causes ld.gold to balk with: `error: version script assignment of to symbol __rust_alloc_error_handler_should_panic failed: symbol not defined` Specifically this breaks builds on DragonFly and YoctoProject with ld.gold. Builds with ld.bfd should be unaffected. --- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index cbe7e5190791c..326b28ad1041e 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -233,15 +233,6 @@ fn exported_symbols_provider_local( )); } - symbols.push(( - ExportedSymbol::NoDefId(SymbolName::new(tcx, OomStrategy::SYMBOL)), - SymbolExportInfo { - level: SymbolExportLevel::Rust, - kind: SymbolExportKind::Text, - used: false, - }, - )); - let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, NO_ALLOC_SHIM_IS_UNSTABLE)); symbols.push(( From b47e4a46c62fc6f9048d457aa9636db1550f3eaa Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 5 Aug 2023 13:18:47 +0900 Subject: [PATCH 2/9] Revert "Auto merge of #98333 - SimonSapin:riscv-atomic, r=Amanieu" This reverts commit 90f0b24ad3e7fc0dc0e419c9da30d74629cd5736, reversing changes made to e173a8e6634d787a1529ff6ec5dc63273425ca34. --- compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs | 2 +- compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs | 2 +- compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs index 6389d68641a1d..75a65a268494c 100644 --- a/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs @@ -11,7 +11,7 @@ pub fn target() -> Target { linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), linker: Some("rust-lld".into()), cpu: "generic-rv32".into(), - max_atomic_width: Some(32), + max_atomic_width: Some(0), atomic_cas: false, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs index a177a73483fb0..f2242bbe08714 100644 --- a/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs @@ -11,7 +11,7 @@ pub fn target() -> Target { linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), linker: Some("rust-lld".into()), cpu: "generic-rv32".into(), - max_atomic_width: Some(32), + max_atomic_width: Some(0), atomic_cas: false, features: "+m".into(), panic_strategy: PanicStrategy::Abort, diff --git a/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs index fd620696cb2e1..01e773fae9734 100644 --- a/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs @@ -11,7 +11,7 @@ pub fn target() -> Target { linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), linker: Some("rust-lld".into()), cpu: "generic-rv32".into(), - max_atomic_width: Some(32), + max_atomic_width: Some(0), atomic_cas: false, features: "+m,+c".into(), panic_strategy: PanicStrategy::Abort, From dddd2190b9d3185cc3621847ffb5036501f1fcc9 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 5 Aug 2023 15:23:31 +0900 Subject: [PATCH 3/9] Remove arm crypto target feature --- compiler/rustc_codegen_ssa/src/target_features.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 98e561b0aef63..c370ba9be5626 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -29,7 +29,6 @@ const ARM_ALLOWED_FEATURES: &[(&str, Option)] = &[ ("aclass", Some(sym::arm_target_feature)), ("aes", Some(sym::arm_target_feature)), ("crc", Some(sym::arm_target_feature)), - ("crypto", Some(sym::arm_target_feature)), ("d32", Some(sym::arm_target_feature)), ("dotprod", Some(sym::arm_target_feature)), ("dsp", Some(sym::arm_target_feature)), From 5468336d6b11a56addc589cd24107915e3ba0d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 6 Aug 2023 23:02:27 +0200 Subject: [PATCH 4/9] Store the laziness of type aliases in the DefKind --- .../src/diagnostics/region_name.rs | 2 +- compiler/rustc_hir/src/def.rs | 10 +++++--- compiler/rustc_hir/src/target.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 18 +++++++------ .../rustc_hir_analysis/src/check/check.rs | 2 +- .../src/collect/resolve_bound_vars.rs | 4 +-- .../src/variance/constraints.rs | 9 +++---- .../rustc_hir_analysis/src/variance/mod.rs | 5 ++-- .../rustc_hir_analysis/src/variance/terms.rs | 5 ++-- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 5 +++- .../src/mem_categorization.rs | 5 +++- .../infer/error_reporting/need_type_info.rs | 4 +-- compiler/rustc_metadata/src/rmeta/encoder.rs | 25 +++++++++---------- compiler/rustc_metadata/src/rmeta/table.rs | 3 ++- compiler/rustc_middle/src/hir/map/mod.rs | 4 ++- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/adt.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/diagnostics.rs | 4 +-- compiler/rustc_middle/src/ty/print/pretty.rs | 6 ++--- compiler/rustc_middle/src/ty/sty.rs | 4 +-- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_middle/src/values.rs | 2 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 2 +- .../rustc_monomorphize/src/polymorphize.rs | 2 +- compiler/rustc_passes/src/dead.rs | 4 +-- compiler/rustc_passes/src/layout_test.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 6 ++--- compiler/rustc_query_system/src/query/job.rs | 5 +++- .../rustc_resolve/src/build_reduced_graph.rs | 7 ++++-- compiler/rustc_resolve/src/late.rs | 6 ++--- .../rustc_resolve/src/late/diagnostics.rs | 4 +-- .../src/solve/project_goals.rs | 2 +- compiler/rustc_ty_utils/src/implied_bounds.rs | 4 +-- compiler/rustc_ty_utils/src/opaque_types.rs | 8 +++--- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 6 ++--- src/librustdoc/clean/utils.rs | 18 +++++++++++-- src/librustdoc/formats/item_type.rs | 2 +- .../passes/collect_intra_doc_links.rs | 9 +++++-- .../clippy_lints/src/init_numbered_fields.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- .../clippy_utils/src/ty/type_certainty/mod.rs | 2 +- tests/ui/lazy-type-alias/auxiliary/eager.rs | 6 +++++ tests/ui/lazy-type-alias/auxiliary/lazy.rs | 4 +++ .../extern-crate-has-eager-type-aliases.rs | 23 +++++++++++++++++ ...has-lazy-type-aliases.locally_eager.stderr | 15 +++++++++++ ...-has-lazy-type-aliases.locally_lazy.stderr | 15 +++++++++++ .../extern-crate-has-lazy-type-aliases.rs | 16 ++++++++++++ 49 files changed, 208 insertions(+), 93 deletions(-) create mode 100644 tests/ui/lazy-type-alias/auxiliary/eager.rs create mode 100644 tests/ui/lazy-type-alias/auxiliary/lazy.rs create mode 100644 tests/ui/lazy-type-alias/extern-crate-has-eager-type-aliases.rs create mode 100644 tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_eager.stderr create mode 100644 tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_lazy.stderr create mode 100644 tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.rs diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index be6eb2d1d1219..337af89b21fe5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -516,7 +516,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { // be the same as those of the ADT. // FIXME: We should be able to do something similar to // match_adt_and_segment in this case. - Res::Def(DefKind::TyAlias, _) => (), + Res::Def(DefKind::TyAlias { .. }, _) => (), _ => { if let Some(last_segment) = path.segments.last() { if let Some(highlight) = self.match_adt_and_segment( diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 3a4eb90f7f963..64271309664ec 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -61,7 +61,9 @@ pub enum DefKind { Variant, Trait, /// Type alias: `type Foo = Bar;` - TyAlias, + TyAlias { + lazy: bool, + }, /// Type from an `extern` block. ForeignTy, /// Trait alias: `trait IntIterator = Iterator;` @@ -141,7 +143,7 @@ impl DefKind { DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct", DefKind::OpaqueTy => "opaque type", - DefKind::TyAlias => "type alias", + DefKind::TyAlias { .. } => "type alias", DefKind::TraitAlias => "trait alias", DefKind::AssocTy => "associated type", DefKind::Union => "union", @@ -197,7 +199,7 @@ impl DefKind { | DefKind::Variant | DefKind::Trait | DefKind::OpaqueTy - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -248,7 +250,7 @@ impl DefKind { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy diff --git a/compiler/rustc_hir/src/target.rs b/compiler/rustc_hir/src/target.rs index 0d65ddb5642af..644c4d8265dd5 100644 --- a/compiler/rustc_hir/src/target.rs +++ b/compiler/rustc_hir/src/target.rs @@ -101,7 +101,7 @@ impl Target { DefKind::Mod => Target::Mod, DefKind::ForeignMod => Target::ForeignMod, DefKind::GlobalAsm => Target::GlobalAsm, - DefKind::TyAlias => Target::TyAlias, + DefKind::TyAlias { .. } => Target::TyAlias, DefKind::OpaqueTy => Target::OpaqueTy, DefKind::Enum => Target::Enum, DefKind::Struct => Target::Struct, diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index b40e312352282..319573c85b44b 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -907,19 +907,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { did: DefId, item_segment: &hir::PathSegment<'_>, ) -> Ty<'tcx> { + let tcx = self.tcx(); let args = self.ast_path_args_for_ty(span, did, item_segment); - let ty = self.tcx().at(span).type_of(did); + let ty = tcx.at(span).type_of(did); - if matches!(self.tcx().def_kind(did), DefKind::TyAlias) - && (ty.skip_binder().has_opaque_types() || self.tcx().features().lazy_type_alias) + if let DefKind::TyAlias { lazy } = tcx.def_kind(did) + && (lazy || ty.skip_binder().has_opaque_types()) { // Type aliases referring to types that contain opaque types (but aren't just directly - // referencing a single opaque type) get encoded as a type alias that normalization will + // referencing a single opaque type) as well as those defined in crates that have the + // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will // then actually instantiate the where bounds of. - let alias_ty = self.tcx().mk_alias_ty(did, args); - Ty::new_alias(self.tcx(), ty::Weak, alias_ty) + let alias_ty = tcx.mk_alias_ty(did, args); + Ty::new_alias(tcx, ty::Weak, alias_ty) } else { - ty.instantiate(self.tcx(), args) + ty.instantiate(tcx, args) } } @@ -2158,7 +2160,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } Res::Def( DefKind::Enum - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::Struct | DefKind::Union | DefKind::ForeignTy, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 73627a818e5df..49307d96cc234 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -728,7 +728,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { check_opaque(tcx, id); } } - DefKind::TyAlias => { + DefKind::TyAlias { .. } => { let pty_ty = tcx.type_of(id.owner_id).instantiate_identity(); let generics = tcx.generics_of(id.owner_id); check_type_params_are_used(tcx, &generics, pty_ty); 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 3cc6f574aeccb..6dd0c840de632 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1480,7 +1480,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { DefKind::Struct | DefKind::Union | DefKind::Enum - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::Trait, def_id, ) if depth == 0 => Some(def_id), @@ -1990,7 +1990,7 @@ fn is_late_bound_map( hir::TyKind::Path(hir::QPath::Resolved( None, - hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span }, + hir::Path { res: Res::Def(DefKind::TyAlias { .. }, alias_def), segments, span }, )) => { // See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider // args to be unconstrained. diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 4a3d522e488c9..8a40509d7cc5f 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -78,9 +78,8 @@ pub fn add_constraints_from_crate<'a, 'tcx>( } } DefKind::Fn | DefKind::AssocFn => constraint_cx.build_constraints_for_item(def_id), - DefKind::TyAlias - if tcx.features().lazy_type_alias - || tcx.type_of(def_id).instantiate_identity().has_opaque_types() => + DefKind::TyAlias { lazy } + if lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types() => { constraint_cx.build_constraints_for_item(def_id) } @@ -111,8 +110,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // The type as returned by `type_of` is the underlying type and generally not a weak projection. // Therefore we need to check the `DefKind` first. - if let DefKind::TyAlias = tcx.def_kind(def_id) - && (tcx.features().lazy_type_alias || ty.has_opaque_types()) + if let DefKind::TyAlias { lazy } = tcx.def_kind(def_id) + && (lazy || ty.has_opaque_types()) { self.add_constraints_from_ty(current_item, ty, self.covariant); return; diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 2ef294c6793c5..d91d9fcbc8e11 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -56,9 +56,8 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] { let crate_map = tcx.crate_variances(()); return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]); } - DefKind::TyAlias - if tcx.features().lazy_type_alias - || tcx.type_of(item_def_id).instantiate_identity().has_opaque_types() => + DefKind::TyAlias { lazy } + if lazy || tcx.type_of(item_def_id).instantiate_identity().has_opaque_types() => { // These are inferred. let crate_map = tcx.crate_variances(()); diff --git a/compiler/rustc_hir_analysis/src/variance/terms.rs b/compiler/rustc_hir_analysis/src/variance/terms.rs index 1ef3d383bd8c0..1a8ec5f085333 100644 --- a/compiler/rustc_hir_analysis/src/variance/terms.rs +++ b/compiler/rustc_hir_analysis/src/variance/terms.rs @@ -97,9 +97,8 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>( } } DefKind::Fn | DefKind::AssocFn => terms_cx.add_inferreds_for_item(def_id), - DefKind::TyAlias - if tcx.features().lazy_type_alias - || tcx.type_of(def_id).instantiate_identity().has_opaque_types() => + DefKind::TyAlias { lazy } + if lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types() => { terms_cx.add_inferreds_for_item(def_id) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index c63dab631452e..40f9a95403497 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1359,7 +1359,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => bug!("unexpected type: {:?}", ty.normalized), }, - Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _) + Res::Def( + DefKind::Struct | DefKind::Union | DefKind::TyAlias { .. } | DefKind::AssocTy, + _, + ) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => match ty.normalized.ty_adt_def() { Some(adt) if !adt.is_enum() => { diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index e91103f213015..77c1a20c38a91 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -557,7 +557,10 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { Ok(adt_def.variant_index_with_ctor_id(variant_ctor_id)) } Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _) - | Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _) + | Res::Def( + DefKind::Struct | DefKind::Union | DefKind::TyAlias { .. } | DefKind::AssocTy, + _, + ) | Res::SelfCtor(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => { diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 9dfa45858a79b..f2a3c47bdfe8e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -951,7 +951,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { // // See the `need_type_info/issue-103053.rs` test for // a example. - if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => { + if !matches!(path.res, Res::Def(DefKind::TyAlias { .. }, _)) => { if let Some(ty) = self.opt_node_type(expr.hir_id) && let ty::Adt(_, args) = ty.kind() { @@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { ) => { if tcx.res_generics_def_id(path.res) != Some(def.did()) { match path.res { - Res::Def(DefKind::TyAlias, _) => { + Res::Def(DefKind::TyAlias { .. }, _) => { // FIXME: Ideally we should support this. For that // we have to map back from the self type to the // type alias though. That's difficult. diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index f12094a271f15..b34fead821f99 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -819,7 +819,7 @@ fn should_encode_span(def_kind: DefKind) -> bool { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -854,7 +854,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -895,7 +895,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool { | DefKind::Variant | DefKind::Trait | DefKind::Impl { .. } => true, - DefKind::TyAlias + DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -930,7 +930,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -974,7 +974,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool { | DefKind::Const | DefKind::Fn | DefKind::ForeignMod - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::OpaqueTy | DefKind::Enum | DefKind::Union @@ -1067,9 +1067,8 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def | DefKind::Closure | DefKind::Generator | DefKind::ExternCrate => false, - DefKind::TyAlias => { - tcx.features().lazy_type_alias - || tcx.type_of(def_id).instantiate_identity().has_opaque_types() + DefKind::TyAlias { lazy } => { + lazy || tcx.type_of(def_id).instantiate_identity().has_opaque_types() } } } @@ -1081,7 +1080,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool { | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy @@ -1121,7 +1120,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> | DefKind::Fn | DefKind::Const | DefKind::Static(..) - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::Impl { .. } | DefKind::AssocFn @@ -1181,7 +1180,7 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool { | DefKind::Const | DefKind::Static(..) | DefKind::Ctor(..) - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::OpaqueTy | DefKind::ForeignTy | DefKind::Impl { .. } @@ -1222,7 +1221,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool { | DefKind::AssocConst | DefKind::AnonConst | DefKind::Static(..) - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::OpaqueTy | DefKind::Impl { of_trait: false } | DefKind::ForeignTy @@ -1255,7 +1254,7 @@ fn should_encode_const(def_kind: DefKind) -> bool { | DefKind::Field | DefKind::Fn | DefKind::Static(..) - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::OpaqueTy | DefKind::ForeignTy | DefKind::Impl { .. } diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 4287799a8e66a..ea66c770b7742 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -126,7 +126,8 @@ fixed_size_enum! { ( Enum ) ( Variant ) ( Trait ) - ( TyAlias ) + ( TyAlias { lazy: false } ) + ( TyAlias { lazy: true } ) ( ForeignTy ) ( TraitAlias ) ( AssocTy ) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0256e09e4b553..168833bbf7291 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -196,7 +196,9 @@ impl<'hir> Map<'hir> { ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind), ItemKind::Mod(..) => DefKind::Mod, ItemKind::OpaqueTy(..) => DefKind::OpaqueTy, - ItemKind::TyAlias(..) => DefKind::TyAlias, + ItemKind::TyAlias(..) => { + DefKind::TyAlias { lazy: self.tcx.features().lazy_type_alias } + } ItemKind::Enum(..) => DefKind::Enum, ItemKind::Struct(..) => DefKind::Struct, ItemKind::Union(..) => DefKind::Union, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index a02f9a9f796c0..d6ae0c77bab3c 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -231,7 +231,7 @@ rustc_queries! { action = { use rustc_hir::def::DefKind; match tcx.def_kind(key) { - DefKind::TyAlias => "expanding type alias", + DefKind::TyAlias { .. } => "expanding type alias", DefKind::TraitAlias => "expanding trait alias", _ => "computing type of", } diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 6ba13a76563b3..b4c6e0d970a51 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -448,7 +448,7 @@ impl<'tcx> AdtDef<'tcx> { Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid), Res::Def(DefKind::Struct, _) | Res::Def(DefKind::Union, _) - | Res::Def(DefKind::TyAlias, _) + | Res::Def(DefKind::TyAlias { .. }, _) | Res::Def(DefKind::AssocTy, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 5eef3e45f327a..0b2d95506bf42 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1062,7 +1062,7 @@ impl<'tcx> TyCtxt<'tcx> { if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id) && let hir::TyKind::Path(hir::QPath::Resolved( None, - hir::Path { res: hir::def::Res::Def(DefKind::TyAlias, def_id), .. }, )) = hir_output.kind + hir::Path { res: hir::def::Res::Def(DefKind::TyAlias { .. }, def_id), .. }, )) = hir_output.kind && let Some(local_id) = def_id.as_local() && let Some(alias_ty) = self.hir().get_by_def_id(local_id).alias_ty() // it is type alias && let Some(alias_generics) = self.hir().get_by_def_id(local_id).generics() diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 8570f83dcc66b..e71482326da79 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -492,7 +492,7 @@ impl<'tcx> TypeVisitor> for IsSuggestableVisitor<'tcx> { Alias(Opaque, AliasTy { def_id, .. }) => { let parent = self.tcx.parent(def_id); let parent_ty = self.tcx.type_of(parent).instantiate_identity(); - if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) + if let DefKind::TyAlias { .. } | DefKind::AssocTy = self.tcx.def_kind(parent) && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind() && parent_opaque_def_id == def_id { @@ -576,7 +576,7 @@ impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { Alias(Opaque, AliasTy { def_id, .. }) => { let parent = self.tcx.parent(def_id); let parent_ty = self.tcx.type_of(parent).instantiate_identity(); - if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) + if let hir::def::DefKind::TyAlias { .. } | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind() && parent_opaque_def_id == def_id { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 6e68022031a07..8b4d73029f498 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -364,7 +364,7 @@ pub trait PrettyPrinter<'tcx>: self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?; self.write_str("::")?; } else if let DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait - | DefKind::TyAlias | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind + | DefKind::TyAlias { .. } | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind { } else { // If not covered above, like for example items out of `impl` blocks, fallback. @@ -766,7 +766,7 @@ pub trait PrettyPrinter<'tcx>: let parent = self.tcx().parent(def_id); match self.tcx().def_kind(parent) { - DefKind::TyAlias | DefKind::AssocTy => { + DefKind::TyAlias { .. } | DefKind::AssocTy => { // NOTE: I know we should check for NO_QUERIES here, but it's alright. // `type_of` on a type alias or assoc type should never cause a cycle. if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) = @@ -2982,7 +2982,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N match child.res { def::Res::Def(DefKind::AssocTy, _) => {} - def::Res::Def(DefKind::TyAlias, _) => {} + def::Res::Def(DefKind::TyAlias { .. }, _) => {} def::Res::Def(defkind, def_id) => { if let Some(ns) = defkind.ns() { collect_fn(&child.ident, ns, def_id); diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a695febf08741..e6baa62420522 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1223,7 +1223,7 @@ impl<'tcx> AliasTy<'tcx> { DefKind::AssocTy if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent, DefKind::AssocTy => ty::Projection, DefKind::OpaqueTy => ty::Opaque, - DefKind::TyAlias => ty::Weak, + DefKind::TyAlias { .. } => ty::Weak, kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), } } @@ -1945,7 +1945,7 @@ impl<'tcx> Ty<'tcx> { (kind, tcx.def_kind(alias_ty.def_id)), (ty::Opaque, DefKind::OpaqueTy) | (ty::Projection | ty::Inherent, DefKind::AssocTy) - | (ty::Weak, DefKind::TyAlias) + | (ty::Weak, DefKind::TyAlias { .. }) ); Ty::new(tcx, Alias(kind, alias_ty)) } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 90ecc8aa85781..564f982f842ed 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -156,7 +156,7 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::Enum | DefKind::Trait | DefKind::OpaqueTy - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index b0961d91787e6..384a368434a23 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -209,7 +209,7 @@ fn find_item_ty_spans( match ty.kind { hir::TyKind::Path(hir::QPath::Resolved(_, path)) => { if let Res::Def(kind, def_id) = path.res - && kind != DefKind::TyAlias { + && !matches!(kind, DefKind::TyAlias { .. }) { let check_params = def_id.as_local().map_or(true, |def_id| { if def_id == needle { spans.push(ty.span); diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 3c3cbbf36148d..c08fe54c39c4c 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -439,7 +439,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { DefKind::Struct | DefKind::Ctor(CtorOf::Struct, ..) | DefKind::Union - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::AssocTy, _, ) diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index d31bf2072b1bf..a8b7a0dbb681f 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -143,7 +143,7 @@ fn mark_used_by_default_parameters<'tcx>( | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index fbe6fc3bee49b..07b437f463fdf 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -87,7 +87,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { fn handle_res(&mut self, res: Res) { match res { - Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias, def_id) => { + Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias { .. }, def_id) => { self.check_def_id(def_id); } _ if self.in_pat => {} @@ -861,7 +861,7 @@ impl<'tcx> DeadVisitor<'tcx> { | DefKind::Fn | DefKind::Static(_) | DefKind::Const - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::Enum | DefKind::Union | DefKind::ForeignTy => self.warn_dead_code(def_id, "used"), diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 794dbda3688c3..0463ee2914bcd 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -16,7 +16,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) { for id in tcx.hir().items() { if matches!( tcx.def_kind(id.owner_id), - DefKind::TyAlias | DefKind::Enum | DefKind::Struct | DefKind::Union + DefKind::TyAlias { .. } | DefKind::Enum | DefKind::Struct | DefKind::Union ) { for attr in tcx.get_attrs(id.owner_id, sym::rustc_layout) { dump_layout_of(tcx, id.owner_id.def_id, attr); diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index af9efb82beb80..30a4235d37145 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -583,7 +583,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { self.update(def_id, macro_ev, Level::Reachable); match def_kind { // No type privacy, so can be directly marked as reachable. - DefKind::Const | DefKind::Static(_) | DefKind::TraitAlias | DefKind::TyAlias => { + DefKind::Const | DefKind::Static(_) | DefKind::TraitAlias | DefKind::TyAlias { .. } => { if vis.is_accessible_from(module, self.tcx) { self.update(def_id, macro_ev, Level::Reachable); } @@ -1992,8 +1992,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { let def_kind = tcx.def_kind(def_id); match def_kind { - DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias => { - if let DefKind::TyAlias = def_kind { + DefKind::Const | DefKind::Static(_) | DefKind::Fn | DefKind::TyAlias { .. } => { + if let DefKind::TyAlias { .. } = def_kind { self.check_unnameable(def_id, effective_vis); } self.check(def_id, item_visibility, effective_vis).generics().predicates().ty(); diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index d2140161f1d9f..82127b7d608a3 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -593,7 +593,10 @@ pub(crate) fn report_cycle<'a, D: DepKind>( }); } - let alias = if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TyAlias)) { + let alias = if stack + .iter() + .all(|entry| matches!(entry.query.def_kind, Some(DefKind::TyAlias { .. }))) + { Some(crate::error::Alias::Ty) } else if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TraitAlias)) { Some(crate::error::Alias::Trait) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 2f4327990224d..58ed54a703e4b 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -700,7 +700,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { // These items live in the type namespace. ItemKind::TyAlias(..) => { - let res = Res::Def(DefKind::TyAlias, def_id); + let res = Res::Def( + DefKind::TyAlias { lazy: self.r.tcx.features().lazy_type_alias }, + def_id, + ); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); } @@ -948,7 +951,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { DefKind::Struct | DefKind::Union | DefKind::Variant - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::OpaqueTy | DefKind::TraitAlias diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 0e9d74480a9a7..a3bf71b7d7b4c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -470,7 +470,7 @@ impl<'a> PathSource<'a> { | DefKind::Enum | DefKind::Trait | DefKind::TraitAlias - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::AssocTy | DefKind::TyParam | DefKind::OpaqueTy @@ -509,7 +509,7 @@ impl<'a> PathSource<'a> { DefKind::Struct | DefKind::Union | DefKind::Variant - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::AssocTy, _, ) | Res::SelfTyParam { .. } @@ -1734,7 +1734,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { Res::Def(DefKind::Struct, def_id) | Res::Def(DefKind::Union, def_id) | Res::Def(DefKind::Enum, def_id) - | Res::Def(DefKind::TyAlias, def_id) + | Res::Def(DefKind::TyAlias { .. }, def_id) | Res::Def(DefKind::Trait, def_id) if i + 1 == proj_start => { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 974580f815bd0..ebb240b691b53 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1422,7 +1422,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { (Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => { err.span_label(span, fallback_label.to_string()); } - (Res::Def(DefKind::TyAlias, def_id), PathSource::Trait(_)) => { + (Res::Def(DefKind::TyAlias { .. }, def_id), PathSource::Trait(_)) => { err.span_label(span, "type aliases cannot be used as traits"); if self.r.tcx.sess.is_nightly_build() { let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \ @@ -1591,7 +1591,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { err.span_label(span, fallback_label.to_string()); err.note("can't use `Self` as a constructor, you must use the implemented struct"); } - (Res::Def(DefKind::TyAlias | DefKind::AssocTy, _), _) if ns == ValueNS => { + (Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, _), _) if ns == ValueNS => { err.note("can't use a type alias as a constructor"); } _ => return false, diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 2ce5775174003..561e725223856 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -58,7 +58,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { } DefKind::AnonConst => self.normalize_anon_const(goal), DefKind::OpaqueTy => self.normalize_opaque_type(goal), - DefKind::TyAlias => self.normalize_weak_type(goal), + DefKind::TyAlias { .. } => self.normalize_weak_type(goal), kind => bug!("unknown DefKind {} in projection goal: {goal:#?}", kind.descr(def_id)), } } diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 7eb1042d2f8b5..aa49a5561d157 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -128,7 +128,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' }, DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)), DefKind::OpaqueTy => match tcx.def_kind(tcx.local_parent(def_id)) { - DefKind::TyAlias => ty::List::empty(), + DefKind::TyAlias { .. } => ty::List::empty(), DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)), // Nested opaque types only occur in associated types: // ` type Opaque = impl Trait<&'static T, AssocTy = impl Nested>; ` @@ -145,7 +145,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' | DefKind::Enum | DefKind::Variant | DefKind::Trait - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::TyParam diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 06a30677d2005..38768f0a05b6d 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -53,7 +53,9 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { fn parent(&self) -> Option { match self.tcx.def_kind(self.item) { - DefKind::AnonConst | DefKind::InlineConst | DefKind::Fn | DefKind::TyAlias => None, + DefKind::AnonConst | DefKind::InlineConst | DefKind::Fn | DefKind::TyAlias { .. } => { + None + } DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { Some(self.tcx.local_parent(self.item)) } @@ -116,7 +118,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { #[instrument(level = "trace", skip(self))] fn visit_nested_item(&mut self, id: rustc_hir::ItemId) { let id = id.owner_id.def_id; - if let DefKind::TyAlias = self.collector.tcx.def_kind(id) { + if let DefKind::TyAlias { .. } = self.collector.tcx.def_kind(id) { let items = self.collector.tcx.opaque_types_defined_by(id); self.collector.opaques.extend(items); } @@ -295,7 +297,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ collector.collect_body_and_predicate_taits(); } // We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds` - DefKind::TyAlias | DefKind::AssocTy => { + DefKind::TyAlias { .. } | DefKind::AssocTy => { tcx.type_of(item).instantiate_identity().visit_with(&mut collector); } DefKind::OpaqueTy => { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c31d104f8cbec..384010034e621 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -79,7 +79,7 @@ pub(crate) fn try_inline( build_impls(cx, did, attrs_without_docs, &mut ret); clean::UnionItem(build_union(cx, did)) } - Res::Def(DefKind::TyAlias, did) => { + Res::Def(DefKind::TyAlias { .. }, did) => { record_extern_fqn(cx, did, ItemType::Typedef); build_impls(cx, did, attrs_without_docs, &mut ret); clean::TypedefItem(build_type_alias(cx, did)) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a5efcc989f6e4..b6ba4c853d4cd 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1706,7 +1706,7 @@ fn maybe_expand_private_type_alias<'tcx>( cx: &mut DocContext<'tcx>, path: &hir::Path<'tcx>, ) -> Option { - let Res::Def(DefKind::TyAlias, def_id) = path.res else { return None }; + let Res::Def(DefKind::TyAlias { .. }, def_id) = path.res else { return None }; // Substitute private type aliases let def_id = def_id.as_local()?; let alias = if !cx.cache.effective_visibilities.is_exported(cx.tcx, def_id.to_def_id()) @@ -1970,7 +1970,7 @@ impl<'tcx> ContainerTy<'tcx> { let (DefKind::Struct | DefKind::Union | DefKind::Enum - | DefKind::TyAlias + | DefKind::TyAlias { .. } | DefKind::Trait | DefKind::AssocTy | DefKind::Variant) = tcx.def_kind(container) @@ -2709,7 +2709,7 @@ fn clean_impl<'tcx>( let for_ = clean_ty(impl_.self_ty, cx); let type_alias = for_.def_id(&cx.cache).and_then(|alias_def_id: DefId| match tcx.def_kind(alias_def_id) { - DefKind::TyAlias => Some(clean_middle_ty( + DefKind::TyAlias { .. } => Some(clean_middle_ty( ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity()), cx, Some(def_id.to_def_id()), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 944d0145de269..3c79ce5778222 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -504,8 +504,22 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { let (kind, did) = match res { Res::Def( - kind @ (AssocTy | AssocFn | AssocConst | Variant | Fn | TyAlias | Enum | Trait | Struct - | Union | Mod | ForeignTy | Const | Static(_) | Macro(..) | TraitAlias), + kind @ (AssocTy + | AssocFn + | AssocConst + | Variant + | Fn + | TyAlias { .. } + | Enum + | Trait + | Struct + | Union + | Mod + | ForeignTy + | Const + | Static(_) + | Macro(..) + | TraitAlias), did, ) => (kind.into(), did), diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index a3017201cb1fd..a788935581fa9 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -115,7 +115,7 @@ impl From for ItemType { DefKind::Struct => Self::Struct, DefKind::Union => Self::Union, DefKind::Trait => Self::Trait, - DefKind::TyAlias => Self::Typedef, + DefKind::TyAlias { .. } => Self::Typedef, DefKind::TraitAlias => Self::TraitAlias, DefKind::Macro(kind) => match kind { MacroKind::Bang => ItemType::Macro, diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 4de30e4ed9d28..1b8d999024c47 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -592,7 +592,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { .unwrap_or(Vec::new()) } } - Res::Def(DefKind::TyAlias, did) => { + Res::Def(DefKind::TyAlias { .. }, did) => { // Resolve the link on the type the alias points to. // FIXME: if the associated item is defined directly on the type alias, // it will show up on its documentation page, we should link there instead. @@ -1865,7 +1865,12 @@ fn resolution_failure( } return; } - Trait | TyAlias | ForeignTy | OpaqueTy | TraitAlias | TyParam + Trait + | TyAlias { .. } + | ForeignTy + | OpaqueTy + | TraitAlias + | TyParam | Static(_) => "associated item", Impl { .. } | GlobalAsm => unreachable!("not a path"), } diff --git a/src/tools/clippy/clippy_lints/src/init_numbered_fields.rs b/src/tools/clippy/clippy_lints/src/init_numbered_fields.rs index f95d2c2edb1ef..b00fa104f9825 100644 --- a/src/tools/clippy/clippy_lints/src/init_numbered_fields.rs +++ b/src/tools/clippy/clippy_lints/src/init_numbered_fields.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields { && fields .iter() .all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit)) - && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..)) + && !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias { .. }, ..)) { let expr_spans = fields .iter() diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index cf30930b76eac..aeef7499ee0b0 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -286,7 +286,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool { /// Checks if the given `QPath` belongs to a type alias. pub fn is_ty_alias(qpath: &QPath<'_>) -> bool { match *qpath { - QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)), + QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, ..)), QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) }, _ => false, } diff --git a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs index 45b5483e323d5..3e8e694a2ac4e 100644 --- a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs @@ -219,7 +219,7 @@ fn path_segment_certainty( // See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value. let certainty = lhs.join_clearing_def_ids(rhs); if resolves_to_type { - if cx.tcx.def_kind(def_id) == DefKind::TyAlias { + if let DefKind::TyAlias { .. } = cx.tcx.def_kind(def_id) { adt_def_id(cx.tcx.type_of(def_id).instantiate_identity()) .map_or(certainty, |def_id| certainty.with_def_id(def_id)) } else { diff --git a/tests/ui/lazy-type-alias/auxiliary/eager.rs b/tests/ui/lazy-type-alias/auxiliary/eager.rs new file mode 100644 index 0000000000000..8793a1701ec3e --- /dev/null +++ b/tests/ui/lazy-type-alias/auxiliary/eager.rs @@ -0,0 +1,6 @@ +// This crate does *not* have lazy type aliases enabled. + +#![allow(type_alias_bounds)] + +// The `Copy` bound is ignored both locally and externally for backward compatibility. +pub type Alias = Option; diff --git a/tests/ui/lazy-type-alias/auxiliary/lazy.rs b/tests/ui/lazy-type-alias/auxiliary/lazy.rs new file mode 100644 index 0000000000000..caa7999b4f71f --- /dev/null +++ b/tests/ui/lazy-type-alias/auxiliary/lazy.rs @@ -0,0 +1,4 @@ +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +pub type Alias = Option; diff --git a/tests/ui/lazy-type-alias/extern-crate-has-eager-type-aliases.rs b/tests/ui/lazy-type-alias/extern-crate-has-eager-type-aliases.rs new file mode 100644 index 0000000000000..07389961c4c68 --- /dev/null +++ b/tests/ui/lazy-type-alias/extern-crate-has-eager-type-aliases.rs @@ -0,0 +1,23 @@ +// This test serves as a regression test for issue #114468 and it also ensures that we consider +// type aliases from external crates that don't have `lazy_type_alias` enabled to be eager. + +// aux-crate:eager=eager.rs +// edition: 2021 +// check-pass + +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +// This used to crash when we were computing the variances of `Struct` since we would convert +// `eager::Alias` to a weak projection due to the presence of `#![feature(lazy_type_alias)]` in +// this (!) crate and subsequently attempt to obtain the variances of the type alias associated with +// the weak projection which would panic because we don't compute this information for eager type +// aliases at all. +struct Struct(eager::Alias); + +fn main() { + // We want to ignore (or rather “end up ignoring”) the bound `T: Copy` since `Alias` should be + // treated as an eager type alias not just inside the crate it is defined in but also in + // dependent crates (like this one). + let _: eager::Alias; +} diff --git a/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_eager.stderr b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_eager.stderr new file mode 100644 index 0000000000000..9e0e2bfa87288 --- /dev/null +++ b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_eager.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/extern-crate-has-lazy-type-aliases.rs:15:12 + | +LL | let _: lazy::Alias; + | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound on the type alias `Alias` + --> $DIR/auxiliary/lazy.rs:4:19 + | +LL | pub type Alias = Option; + | ^^^^ required by this bound + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_lazy.stderr b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_lazy.stderr new file mode 100644 index 0000000000000..9e0e2bfa87288 --- /dev/null +++ b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.locally_lazy.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/extern-crate-has-lazy-type-aliases.rs:15:12 + | +LL | let _: lazy::Alias; + | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound on the type alias `Alias` + --> $DIR/auxiliary/lazy.rs:4:19 + | +LL | pub type Alias = Option; + | ^^^^ required by this bound + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.rs b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.rs new file mode 100644 index 0000000000000..31a19161b6c96 --- /dev/null +++ b/tests/ui/lazy-type-alias/extern-crate-has-lazy-type-aliases.rs @@ -0,0 +1,16 @@ +// revisions: locally_eager locally_lazy +// aux-crate:lazy=lazy.rs +// edition: 2021 + +// Test that we treat lazy type aliases from external crates as lazy independently of whether the +// local crate enables `lazy_type_alias` or not. + +#![cfg_attr( + locally_lazy, + feature(lazy_type_alias), + allow(incomplete_features) +)] + +fn main() { + let _: lazy::Alias; //~ ERROR the trait bound `String: Copy` is not satisfied +} From fb9030d7ddf1fe8c9657af3f8361d38a1742a803 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 7 Aug 2023 19:05:59 +0000 Subject: [PATCH 5/9] Structurally normalize weak and inherent too --- compiler/rustc_hir_analysis/src/autoderef.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_trait_selection/src/traits/structural_normalize.rs | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index c07ac35cba367..39db295044ed0 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -74,7 +74,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> { // we have some type like `&::Assoc`, since users of // autoderef expect this type to have been structurally normalized. if self.infcx.next_trait_solver() - && let ty::Alias(ty::Projection, _) = ty.kind() + && let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind() { let (normalized_ty, obligations) = self.structurally_normalize(ty)?; self.state.obligations.extend(obligations); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 1433c67d55dc5..322d726a89d71 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1474,7 +1474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.resolve_vars_with_obligations(ty); if self.next_trait_solver() - && let ty::Alias(ty::Projection, _) = ty.kind() + && let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind() { match self .at(&self.misc(sp), self.param_env) diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 84746eba3ecf8..d3c4dc45923d9 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -22,7 +22,9 @@ impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> { assert!(!ty.is_ty_var(), "should have resolved vars before calling"); if self.infcx.next_trait_solver() { - while let ty::Alias(ty::Projection, projection_ty) = *ty.kind() { + while let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, projection_ty) = + *ty.kind() + { let new_infer_ty = self.infcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::NormalizeProjectionType, span: self.cause.span, From ba4a2f7cb72016613ac4b1fe66ee2f6704d9cd73 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 7 Aug 2023 18:51:38 +0000 Subject: [PATCH 6/9] Resolve target type of coercion --- compiler/rustc_hir_typeck/src/coercion.rs | 8 +++- tests/ui/for/issue-20605.next.stderr | 12 +++--- .../coerce-behind-lazy.current.stderr | 11 ++++++ .../coerce-behind-lazy.next.stderr | 11 ++++++ .../ui/lazy-type-alias/coerce-behind-lazy.rs | 16 ++++++++ .../new-solver/lazy-nested-obligations-2.rs | 2 +- .../lazy-nested-obligations-2.stderr | 39 ------------------- .../new-solver/more-object-bound.stderr | 4 +- 8 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr create mode 100644 tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr create mode 100644 tests/ui/lazy-type-alias/coerce-behind-lazy.rs delete mode 100644 tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index fa6bad8437696..b2b3f4355053f 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1012,6 +1012,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { cause: Option>, ) -> RelateResult<'tcx, Ty<'tcx>> { let source = self.try_structurally_resolve_type(expr.span, expr_ty); + let target = self.try_structurally_resolve_type( + cause.as_ref().map_or(expr.span, |cause| cause.span), + target, + ); debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target); let cause = @@ -1097,8 +1101,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { where E: AsCoercionSite, { - let prev_ty = self.resolve_vars_with_obligations(prev_ty); - let new_ty = self.resolve_vars_with_obligations(new_ty); + let prev_ty = self.try_structurally_resolve_type(cause.span, prev_ty); + let new_ty = self.try_structurally_resolve_type(new.span, new_ty); debug!( "coercion::try_find_coercion_lub({:?}, {:?}, exprs={:?} exprs)", prev_ty, diff --git a/tests/ui/for/issue-20605.next.stderr b/tests/ui/for/issue-20605.next.stderr index d55efedfcbeef..0955efdbb7379 100644 --- a/tests/ui/for/issue-20605.next.stderr +++ b/tests/ui/for/issue-20605.next.stderr @@ -34,12 +34,6 @@ error: the type `&mut as IntoIterator>::IntoIte LL | for item in *things { *item = 0 } | ^^^^^^^ -error[E0614]: type `< as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced - --> $DIR/issue-20605.rs:5:27 - | -LL | for item in *things { *item = 0 } - | ^^^^^ - error[E0277]: the size for values of type `< as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time --> $DIR/issue-20605.rs:5:9 | @@ -66,6 +60,12 @@ LL | for item in *things { *item = 0 } note: required by a bound in `None` --> $SRC_DIR/core/src/option.rs:LL:COL +error[E0614]: type `< as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced + --> $DIR/issue-20605.rs:5:27 + | +LL | for item in *things { *item = 0 } + | ^^^^^ + error: aborting due to 9 previous errors Some errors have detailed explanations: E0277, E0614. diff --git a/tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr b/tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr new file mode 100644 index 0000000000000..98b3921dec410 --- /dev/null +++ b/tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr @@ -0,0 +1,11 @@ +warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/coerce-behind-lazy.rs:5:12 + | +LL | #![feature(lazy_type_alias)] + | ^^^^^^^^^^^^^^^ + | + = note: see issue #112792 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr b/tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr new file mode 100644 index 0000000000000..98b3921dec410 --- /dev/null +++ b/tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr @@ -0,0 +1,11 @@ +warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/coerce-behind-lazy.rs:5:12 + | +LL | #![feature(lazy_type_alias)] + | ^^^^^^^^^^^^^^^ + | + = note: see issue #112792 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/lazy-type-alias/coerce-behind-lazy.rs b/tests/ui/lazy-type-alias/coerce-behind-lazy.rs new file mode 100644 index 0000000000000..745eadb9625ca --- /dev/null +++ b/tests/ui/lazy-type-alias/coerce-behind-lazy.rs @@ -0,0 +1,16 @@ +// check-pass +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +#![feature(lazy_type_alias)] +//~^ WARN the feature `lazy_type_alias` is incomplete + +use std::any::Any; + +type Coerce = Box; + +fn test() -> Coerce { + Box::new(1) +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs index fd91d81cdf0d7..20f504928c703 100644 --- a/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs @@ -1,5 +1,5 @@ // compile-flags: -Ztrait-solver=next -// known-bug: #95863 +// check-pass pub trait With { type F; diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr b/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr deleted file mode 100644 index d0a4cd661b386..0000000000000 --- a/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/lazy-nested-obligations-2.rs:15:23 - | -LL | let _: V = V(f); - | - ^ types differ - | | - | arguments to this struct are incorrect - | - = note: expected associated type `::F` - found fn item `for<'a> fn(&'a str) {f}` - = help: consider constraining the associated type `::F` to `for<'a> fn(&'a str) {f}` or calling a method that returns `::F` - = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html -note: tuple struct defined here - --> $DIR/lazy-nested-obligations-2.rs:16:16 - | -LL | pub struct V(::F); - | ^ - -error[E0308]: mismatched types - --> $DIR/lazy-nested-obligations-2.rs:21:30 - | -LL | let _: E3 = E3::Var(f); - | ------- ^ types differ - | | - | arguments to this enum variant are incorrect - | - = note: expected associated type `::F` - found fn item `for<'a> fn(&'a str) {f}` - = help: consider constraining the associated type `::F` to `for<'a> fn(&'a str) {f}` or calling a method that returns `::F` - = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html -note: tuple variant defined here - --> $DIR/lazy-nested-obligations-2.rs:19:9 - | -LL | Var(::F), - | ^^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/new-solver/more-object-bound.stderr b/tests/ui/traits/new-solver/more-object-bound.stderr index 4554b8c7473cb..54965dee184ab 100644 --- a/tests/ui/traits/new-solver/more-object-bound.stderr +++ b/tests/ui/traits/new-solver/more-object-bound.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `dyn Trait: Trait` is not satisfied - --> $DIR/more-object-bound.rs:12:17 + --> $DIR/more-object-bound.rs:12:5 | LL | foo::>(x) - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait` | note: required by a bound in `foo` --> $DIR/more-object-bound.rs:18:8 From f1776250eb6034569617007abcd0b518f67dc20c Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Wed, 2 Aug 2023 18:31:47 +0200 Subject: [PATCH 7/9] core: Remove #[macro_export] from `debug_assert_matches` The `debug_assert_matches` macro was marked with the `#[macro_export]` attribute, despite being a declarative macro/macro 2.0, for which the exporting rules are similar to items. In fact, `#[macro_export]` on a decl macro has no effect on its visibility. --- library/core/src/macros/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 45e5b76272e1d..14cc523b0c185 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -312,7 +312,6 @@ macro_rules! debug_assert_ne { /// let c = Ok("abc".to_string()); /// debug_assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); /// ``` -#[macro_export] #[unstable(feature = "assert_matches", issue = "82775")] #[allow_internal_unstable(assert_matches)] #[rustc_macro_transparency = "semitransparent"] From bdf4e3de9c4634af517c05c58f049eda0c28ea5f Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Wed, 2 Aug 2023 20:08:28 +0200 Subject: [PATCH 8/9] check_attrs: Warn when #[macro_export] is used on macros 2.0 The compiler should emit a more specific error when the `#[macro_export]` attribute is present on a decl macro, instead of silently ignoring it. This commit adds the required error message in rustc_passes/messages.ftl, as well as a note. A new variant is added to the `errors::MacroExport` enum, specifically for the case where the attribute is added to a macro 2.0. --- compiler/rustc_passes/messages.ftl | 4 ++++ compiler/rustc_passes/src/check_attr.rs | 14 ++++++++++++++ compiler/rustc_passes/src/errors.rs | 4 ++++ .../ui/attributes/macro_export_on_decl_macro.rs | 9 +++++++++ .../attributes/macro_export_on_decl_macro.stderr | 16 ++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 tests/ui/attributes/macro_export_on_decl_macro.rs create mode 100644 tests/ui/attributes/macro_export_on_decl_macro.stderr diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 5b3cc5d99cc78..6eacbebe75f41 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -428,6 +428,10 @@ passes_link_section = passes_macro_export = `#[macro_export]` only has an effect on macro definitions +passes_macro_export_on_decl_macro = + `#[macro_export]` has no effect on declarative macro definitions + .note = declarative macros follow the same exporting rules as regular items + passes_macro_use = `#[{$name}]` only has an effect on `extern crate` and modules diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index cbb030958c693..4f9b362e23796 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -2133,6 +2133,20 @@ impl CheckAttrVisitor<'_> { ); } } + } else { + // special case when `#[macro_export]` is applied to a macro 2.0 + let (macro_definition, _) = + self.tcx.hir().find(hir_id).unwrap().expect_item().expect_macro(); + let is_decl_macro = !macro_definition.macro_rules; + + if is_decl_macro { + self.tcx.emit_spanned_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr.span, + errors::MacroExport::OnDeclMacro, + ); + } } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 4f5514372d1ec..683717344cecc 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -690,6 +690,10 @@ pub enum MacroExport { #[diag(passes_macro_export)] Normal, + #[diag(passes_macro_export_on_decl_macro)] + #[note] + OnDeclMacro, + #[diag(passes_invalid_macro_export_arguments)] UnknownItem { name: Symbol }, diff --git a/tests/ui/attributes/macro_export_on_decl_macro.rs b/tests/ui/attributes/macro_export_on_decl_macro.rs new file mode 100644 index 0000000000000..e6fe66ac6c30e --- /dev/null +++ b/tests/ui/attributes/macro_export_on_decl_macro.rs @@ -0,0 +1,9 @@ +// Using #[macro_export] on a decl macro has no effect and should warn + +#![feature(decl_macro)] +#![deny(unused)] + +#[macro_export] //~ ERROR `#[macro_export]` has no effect on declarative macro definitions +pub macro foo() {} + +fn main() {} diff --git a/tests/ui/attributes/macro_export_on_decl_macro.stderr b/tests/ui/attributes/macro_export_on_decl_macro.stderr new file mode 100644 index 0000000000000..565e07919bc2c --- /dev/null +++ b/tests/ui/attributes/macro_export_on_decl_macro.stderr @@ -0,0 +1,16 @@ +error: `#[macro_export]` has no effect on declarative macro definitions + --> $DIR/macro_export_on_decl_macro.rs:6:1 + | +LL | #[macro_export] + | ^^^^^^^^^^^^^^^ + | + = note: declarative macros follow the same exporting rules as regular items +note: the lint level is defined here + --> $DIR/macro_export_on_decl_macro.rs:4:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]` + +error: aborting due to previous error + From 65e468f9c259749c210b1ae8972bfe14781f72f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 7 Aug 2023 23:10:57 +0200 Subject: [PATCH 9/9] Rename method in `opt-dist` This makes it clearer that the LLVM is the host one (it doesn't necessarily have to be downloaded). --- src/tools/opt-dist/src/environment/linux.rs | 2 +- src/tools/opt-dist/src/environment/mod.rs | 4 ++-- src/tools/opt-dist/src/environment/windows.rs | 2 +- src/tools/opt-dist/src/training.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/opt-dist/src/environment/linux.rs b/src/tools/opt-dist/src/environment/linux.rs index c2a328b1dbcdb..58b7e6d23067c 100644 --- a/src/tools/opt-dist/src/environment/linux.rs +++ b/src/tools/opt-dist/src/environment/linux.rs @@ -14,7 +14,7 @@ impl Environment for LinuxEnvironment { Utf8PathBuf::from("/checkout") } - fn downloaded_llvm_dir(&self) -> Utf8PathBuf { + fn host_llvm_dir(&self) -> Utf8PathBuf { Utf8PathBuf::from("/rustroot") } diff --git a/src/tools/opt-dist/src/environment/mod.rs b/src/tools/opt-dist/src/environment/mod.rs index d28983d289c72..a8650fad011d9 100644 --- a/src/tools/opt-dist/src/environment/mod.rs +++ b/src/tools/opt-dist/src/environment/mod.rs @@ -15,8 +15,8 @@ pub trait Environment { /// The rustc checkout, where the compiler source is located. fn checkout_path(&self) -> Utf8PathBuf; - /// Path to the downloaded host LLVM. - fn downloaded_llvm_dir(&self) -> Utf8PathBuf; + /// Path to the host LLVM used to compile LLVM in `src/llvm-project`. + fn host_llvm_dir(&self) -> Utf8PathBuf; /// Directory where the optimization artifacts (PGO/BOLT profiles, etc.) /// will be stored. diff --git a/src/tools/opt-dist/src/environment/windows.rs b/src/tools/opt-dist/src/environment/windows.rs index 12a63cbb03c46..8a9733d64965f 100644 --- a/src/tools/opt-dist/src/environment/windows.rs +++ b/src/tools/opt-dist/src/environment/windows.rs @@ -24,7 +24,7 @@ impl Environment for WindowsEnvironment { self.checkout_dir.clone() } - fn downloaded_llvm_dir(&self) -> Utf8PathBuf { + fn host_llvm_dir(&self) -> Utf8PathBuf { self.checkout_path().join("citools").join("clang-rust") } diff --git a/src/tools/opt-dist/src/training.rs b/src/tools/opt-dist/src/training.rs index e374af68a7f3b..59c73fbd6953e 100644 --- a/src/tools/opt-dist/src/training.rs +++ b/src/tools/opt-dist/src/training.rs @@ -81,7 +81,7 @@ fn merge_llvm_profiles( profdata: LlvmProfdata, ) -> anyhow::Result<()> { let llvm_profdata = match profdata { - LlvmProfdata::Host => env.downloaded_llvm_dir().join("bin/llvm-profdata"), + LlvmProfdata::Host => env.host_llvm_dir().join("bin/llvm-profdata"), LlvmProfdata::Target => env .build_artifacts() .join("llvm")