diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 64c96281ed983..6eb1761946aed 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -32,8 +32,8 @@ use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::subst::{SubstsRef, UserSubsts}; use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{ - self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic, - OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, + self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueHiddenType, + OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, }; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::{Span, DUMMY_SP}; @@ -1928,7 +1928,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // // apply them to prove that the source type `Foo` implements `Clone` etc let (existential_predicates, region) = match ty.kind() { - Dynamic(predicates, region, ty::DynStar) => (predicates, region), + ty::DynStar(predicates, region) => (predicates, region), _ => panic!("Invalid dyn* cast_ty"), }; diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 3c34585d4191e..9aa36413415bd 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -578,7 +578,7 @@ pub(crate) fn codegen_drop<'tcx>( // we don't actually need to drop anything } else { match ty.kind() { - ty::Dynamic(_, _, ty::Dyn) => { + ty::Dynamic(_, _) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn Trait) // which is: exists ( *mut T, Vtable ) @@ -608,7 +608,7 @@ pub(crate) fn codegen_drop<'tcx>( let sig = fx.bcx.import_signature(sig); fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); } - ty::Dynamic(_, _, ty::DynStar) => { + ty::DynStar(_, _) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn* Trait) // which is: *mut exists (T, Vtable) diff --git a/compiler/rustc_codegen_cranelift/src/unsize.rs b/compiler/rustc_codegen_cranelift/src/unsize.rs index 9c88f7dbcda33..24d405efa649f 100644 --- a/compiler/rustc_codegen_cranelift/src/unsize.rs +++ b/compiler/rustc_codegen_cranelift/src/unsize.rs @@ -25,12 +25,8 @@ pub(crate) fn unsized_info<'tcx>( .bcx .ins() .iconst(fx.pointer_type, len.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64), - ( - &ty::Dynamic(ref data_a, _, src_dyn_kind), - &ty::Dynamic(ref data_b, _, target_dyn_kind), - ) => { - assert_eq!(src_dyn_kind, target_dyn_kind); - + (&ty::Dynamic(ref data_a, _), &ty::Dynamic(ref data_b, _)) + | (&ty::DynStar(ref data_a, _), &ty::DynStar(ref data_b, _)) => { let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); if data_a.principal_def_id() == data_b.principal_def_id() { @@ -114,10 +110,7 @@ pub(crate) fn cast_to_dyn_star<'tcx>( dst_ty: Ty<'tcx>, old_info: Option, ) -> (Value, Value) { - assert!( - matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "destination type must be a dyn*" - ); + assert!(matches!(dst_ty.kind(), ty::DynStar(..)), "destination type must be a dyn*"); (src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info)) } @@ -172,7 +165,7 @@ pub(crate) fn coerce_dyn_star<'tcx>( src: CValue<'tcx>, dst: CPlace<'tcx>, ) { - let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() { + let (data, extra) = if let ty::DynStar(_, _) = src.layout().ty.kind() { let (data, vtable) = src.load_scalar_pair(fx); (data, Some(vtable)) } else { diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs index 320eecaee008e..157f4c64f0238 100644 --- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs +++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs @@ -875,7 +875,7 @@ pub(crate) fn assert_assignable<'tcx>( ); // fn(&T) -> for<'l> fn(&'l T) is allowed } - (&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => { + (&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => { // FIXME(dyn-star): Do the right thing with DynKinds for (from, to) in from_traits.iter().zip(to_traits) { let from = @@ -889,6 +889,8 @@ pub(crate) fn assert_assignable<'tcx>( } // dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed } + // FIXME(dyn-star) + (&ty::DynStar(_from_traits, _), &ty::DynStar(_to_traits, _)) => unimplemented!(), (&ty::Tuple(types_a), &ty::Tuple(types_b)) => { let mut types_a = types_a.iter(); let mut types_b = types_b.iter(); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 02b502d948c2c..bbb827c5f9764 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -40,6 +40,7 @@ use rustc_span::symbol::sym; use rustc_span::Symbol; use rustc_span::{DebuggerVisualizerFile, DebuggerVisualizerType}; use rustc_target::abi::{Align, Size, VariantIdx}; +use rustc_type_ir::DynKind; use std::collections::BTreeSet; use std::time::{Duration, Instant}; @@ -150,10 +151,8 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( (&ty::Array(_, len), &ty::Slice(_)) => { cx.const_usize(len.eval_usize(cx.tcx(), ty::ParamEnv::reveal_all())) } - ( - &ty::Dynamic(ref data_a, _, src_dyn_kind), - &ty::Dynamic(ref data_b, _, target_dyn_kind), - ) if src_dyn_kind == target_dyn_kind => { + (&ty::Dynamic(ref data_a, _), &ty::Dynamic(ref data_b, _)) + | (&ty::DynStar(ref data_a, _), &ty::DynStar(ref data_b, _)) => { let old_info = old_info.expect("unsized_info: missing old info for trait upcasting coercion"); if data_a.principal_def_id() == data_b.principal_def_id() { @@ -169,7 +168,15 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( if let Some(entry_idx) = vptr_entry_idx { let ptr_ty = cx.type_i8p(); let ptr_align = cx.tcx().data_layout.pointer_align.abi; - let vtable_ptr_ty = vtable_ptr_ty(cx, target, target_dyn_kind); + let vtable_ptr_ty = vtable_ptr_ty( + cx, + target, + match target.kind() { + ty::Dynamic(..) => DynKind::Dyn, + ty::DynStar(..) => DynKind::DynStar, + _ => unreachable!(), + }, + ); let llvtable = bx.pointercast(old_info, bx.type_ptr_to(ptr_ty)); let gep = bx.inbounds_gep( ptr_ty, @@ -185,8 +192,12 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( old_info } } - (_, &ty::Dynamic(ref data, _, target_dyn_kind)) => { - let vtable_ptr_ty = vtable_ptr_ty(cx, target, target_dyn_kind); + (_, &ty::Dynamic(ref data, _)) => { + let vtable_ptr_ty = vtable_ptr_ty(cx, target, DynKind::Dyn); + cx.const_ptrcast(meth::get_vtable(cx, source, data.principal()), vtable_ptr_ty) + } + (_, &ty::DynStar(ref data, _)) => { + let vtable_ptr_ty = vtable_ptr_ty(cx, target, DynKind::DynStar); cx.const_ptrcast(meth::get_vtable(cx, source, data.principal()), vtable_ptr_ty) } _ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target), @@ -202,9 +213,9 @@ fn vtable_ptr_ty<'tcx, Cx: CodegenMethods<'tcx>>( cx.scalar_pair_element_backend_type( cx.layout_of(match kind { // vtable is the second field of `*mut dyn Trait` - ty::Dyn => cx.tcx().mk_mut_ptr(target), + DynKind::Dyn => cx.tcx().mk_mut_ptr(target), // vtable is the second field of `dyn* Trait` - ty::DynStar => target, + DynKind::DynStar => target, }), 1, true, @@ -269,10 +280,7 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( old_info: Option, ) -> (Bx::Value, Bx::Value) { debug!("cast_to_dyn_star: {:?} => {:?}", src_ty_and_layout.ty, dst_ty); - assert!( - matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "destination type must be a dyn*" - ); + assert!(matches!(dst_ty.kind(), ty::DynStar(_, _)), "destination type must be a dyn*"); // FIXME(dyn-star): this is probably not the best way to check if this is // a pointer, and really we should ensure that the value is a suitable // pointer earlier in the compilation process. diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index b0e007ce0097b..5264af1ca7f62 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -209,19 +209,21 @@ fn push_debuginfo_type_name<'tcx>( output.push(']'); } } - ty::Dynamic(ref trait_data, ..) => { + // ty::DynStar(..) => unimplemented!(), + ty::Dynamic(ref trait_data, ..) | ty::DynStar(ref trait_data, ..) => { let auto_traits: SmallVec<[DefId; 4]> = trait_data.auto_traits().collect(); + let is_dyn_star = t.is_dyn_star(); let has_enclosing_parens = if cpp_like_debuginfo { - output.push_str("dyn$<"); + output.push_str(if is_dyn_star { "dyns$<" } else { "dyn$<" }); false } else { if trait_data.len() > 1 && auto_traits.len() != 0 { // We need enclosing parens because there is more than one trait - output.push_str("(dyn "); + output.push_str(if is_dyn_star { "(dyn* " } else { "(dyn " }); true } else { - output.push_str("dyn "); + output.push_str(if is_dyn_star { "dyn* " } else { "dyn " }); false } }; diff --git a/compiler/rustc_codegen_ssa/src/meth.rs b/compiler/rustc_codegen_ssa/src/meth.rs index 2421acab4715d..588c89cfe744f 100644 --- a/compiler/rustc_codegen_ssa/src/meth.rs +++ b/compiler/rustc_codegen_ssa/src/meth.rs @@ -68,7 +68,7 @@ impl<'a, 'tcx> VirtualIndex { fn expect_dyn_trait_in_self(ty: Ty<'_>) -> ty::PolyExistentialTraitRef<'_> { for arg in ty.peel_refs().walk() { if let GenericArgKind::Type(ty) = arg.unpack() { - if let ty::Dynamic(data, _, _) = ty.kind() { + if let ty::Dynamic(data, _) | ty::DynStar(data, _) = ty.kind() { return data.principal().expect("expected principal trait object"); } } diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 2623a650e07b2..e3eb9bb76def7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -455,7 +455,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let (drop_fn, fn_abi) = match ty.kind() { // FIXME(eddyb) perhaps move some of this logic into // `Instance::resolve_drop_in_place`? - ty::Dynamic(_, _, ty::Dyn) => { + ty::Dynamic(_, _) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn Trait) // which is: exists ( *mut T, Vtable ) @@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { fn_abi, ) } - ty::Dynamic(_, _, ty::DynStar) => { + ty::DynStar(..) => { // IN THIS ARM, WE HAVE: // ty = *mut (dyn* Trait) // which is: *mut exists (T, Vtable) diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index c52886b77e64b..ae60020c50ae6 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -118,7 +118,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>( // resolving their backing type, even if we can do that at const eval time. We may // hypothetically be able to allow `dyn StructuralEq` trait objects in the future, // but it is unclear if this is useful. - ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType), + ty::Dynamic(..) | ty::DynStar(..) => Err(ValTreeCreationError::NonSupportedType), ty::Tuple(elem_tys) => { branches(ecx, place, elem_tys.len(), None, num_nodes) @@ -319,7 +319,8 @@ pub fn valtree_to_const_value<'tcx>( | ty::RawPtr(_) | ty::Str | ty::Slice(_) - | ty::Dynamic(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()), + | ty::Dynamic(..) + | ty::DynStar(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()), } } diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index fc8e0c67ae09a..0e5611eaae13c 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -121,7 +121,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } DynStar => { - if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() { + if let ty::DynStar(data, _) = cast_ty.kind() { // Initial cast from sized to dyn trait let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?; let vtable = Scalar::from_maybe_pointer(vtable, self); @@ -347,7 +347,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?; self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest) } - (_, &ty::Dynamic(data, _, ty::Dyn)) => { + (_, &ty::Dynamic(data, _)) => { // Initial cast from sized to dyn trait let vtable = self.get_vtable_ptr(src_pointee_ty, data.principal())?; let ptr = self.read_scalar(src)?; diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 907f014dfb518..38e4c15f5813f 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -97,7 +97,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( | ty::Ref(_, _, _) | ty::FnDef(_, _) | ty::FnPtr(_) - | ty::Dynamic(_, _, _) + | ty::Dynamic(_, _) + | ty::DynStar(_, _) | ty::Closure(_, _) | ty::Generator(_, _, _) | ty::GeneratorWitness(_) diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index aa539516d5e50..918a0bb93b06e 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -592,6 +592,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | ty::Slice(..) | ty::Str | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(..) | ty::Generator(..) => Ok(false), // Some types only occur during typechecking, they have no layout. diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 4e80a28518668..e2ed9afc30da0 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -47,7 +47,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { | ty::FnPtr(_) | ty::Never | ty::Tuple(_) - | ty::Dynamic(_, _, _) => self.pretty_print_type(ty), + | ty::Dynamic(_, _) + | ty::DynStar(_, _) => self.pretty_print_type(ty), // Placeholders (all printed as `_` to uniformize them). ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => { diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f121979be715f..78a9573da484e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -30,9 +30,9 @@ use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; +use rustc_middle::ty::EarlyBinder; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable}; -use rustc_middle::ty::{DynKind, EarlyBinder}; use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS}; use rustc_span::edition::Edition; use rustc_span::lev_distance::find_best_match_for_name; @@ -46,6 +46,7 @@ use rustc_trait_selection::traits::error_reporting::{ }; use rustc_trait_selection::traits::wf::object_region_bounds; +use rustc_type_ir::DynKind; use smallvec::{smallvec, SmallVec}; use std::collections::BTreeSet; use std::slice; @@ -1628,7 +1629,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }; debug!("region_bound: {:?}", region_bound); - let ty = tcx.mk_dynamic(existential_predicates, region_bound, representation); + let ty = match representation { + DynKind::Dyn => tcx.mk_dynamic(existential_predicates, region_bound), + DynKind::DynStar => tcx.mk_dyn_star(existential_predicates, region_bound), + }; + debug!("trait_object_type: {:?}", ty); ty } @@ -2879,8 +2884,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { hir::TyKind::TraitObject(bounds, lifetime, repr) => { self.maybe_lint_bare_trait(ast_ty, in_path); let repr = match repr { - TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn, - TraitObjectSyntax::DynStar => ty::DynStar, + TraitObjectSyntax::Dyn | TraitObjectSyntax::None => DynKind::Dyn, + TraitObjectSyntax::DynStar => DynKind::DynStar, }; self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr) } diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index c1b0237b2d1f1..9ca5b25f16e89 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -197,7 +197,7 @@ impl<'tcx> InherentCollect<'tcx> { ty::Dynamic(data, ..) if data.principal_def_id().is_some() => { self.check_def_id(item, self_ty, data.principal_def_id().unwrap()); } - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..) => { struct_span_err!( self.tcx.sess, ty.span, diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 7d381d8902ac2..d3250a846fdbb 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -181,7 +181,7 @@ fn do_orphan_check_impl<'tcx>( ), // impl AutoTrait for dyn Trait {} - ty::Dynamic(..) => ( + ty::Dynamic(..) | ty::DynStar(..) => ( LocalImpl::Disallow { problematic_kind: "trait object" }, NonlocalImpl::DisallowOther, ), diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index b0cf0387f87a9..20b6f6afc6237 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -256,7 +256,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_invariant_substs(current, data.substs, variance); } - ty::Dynamic(data, r, _) => { + ty::Dynamic(data, r) | ty::DynStar(data, r) => { // The type `dyn Trait +'a` is covariant w/r/t `'a`: self.add_constraints_from_region(current, r, variance); diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 8e21c084841d0..90e697c1e171a 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Ok(match *t.kind() { ty::Slice(_) | ty::Str => Some(PointerKind::Length), - ty::Dynamic(ref tty, _, ty::Dyn) => Some(PointerKind::VTable(tty.principal_def_id())), + ty::Dynamic(ref tty, _) => Some(PointerKind::VTable(tty.principal_def_id())), ty::Adt(def, substs) if def.is_struct() => match def.non_enum_variant().fields.last() { None => Some(PointerKind::Thin), Some(f) => { @@ -139,7 +139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::Generator(..) | ty::Adt(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) + | ty::DynStar(_, _) | ty::Error(_) => { let reported = self .tcx @@ -218,9 +218,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // cases now. We do a more thorough check at the end, once // inference is more completely known. match cast_ty.kind() { - ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => { - Err(check.report_cast_to_unsized_type(fcx)) - } + ty::Dynamic(_, _) | ty::Slice(..) => Err(check.report_cast_to_unsized_type(fcx)), _ => Ok(check), } } diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index 1c70c1b71e763..5a57e3dcbc99d 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -105,7 +105,7 @@ pub(super) fn check_fn<'a, 'tcx>( fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); - if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() { + if let ty::Dynamic(_, _) = declared_ret_ty.kind() { // FIXME: We need to verify that the return type is `Sized` after the return expression has // been evaluated so that we have types available for all the nodes being returned, but that // requires the coerced evaluated type to be stored. Moving `check_return_expr` before this diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 7173239ba619a..4f77b97702224 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -214,7 +214,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { ty::Ref(r_b, _, mutbl_b) => { return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b); } - ty::Dynamic(predicates, region, ty::DynStar) if self.tcx.features().dyn_star => { + ty::DynStar(predicates, region) if self.tcx.features().dyn_star => { return self.coerce_dyn_star(a, b, predicates, region); } _ => {} @@ -727,9 +727,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { return Err(TypeError::Mismatch); } - if let ty::Dynamic(a_data, _, _) = a.kind() - && let ty::Dynamic(b_data, _, _) = b.kind() - && a_data.principal_def_id() == b_data.principal_def_id() + if let (ty::Dynamic(a_data, _), ty::Dynamic(b_data, _)) | (ty::DynStar(a_data, _), ty::DynStar(b_data, _)) = (a.kind(), b.kind()) + && a_data.principal_def_id() == b_data.principal_def_id() { return self.unify_and(a, b, |_| vec![]); } diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 7af5260538568..0b77140b1370b 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -595,7 +595,7 @@ fn check_must_not_suspend_ty<'tcx>( } has_emitted } - ty::Dynamic(binder, _, _) => { + ty::Dynamic(binder, _) | ty::DynStar(binder, _) => { let mut has_emitted = false; for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 54890489f8b8f..ecbb50b505af2 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -549,7 +549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Point at the type that couldn't satisfy the bound. ty::Adt(def, _) => bound_spans.push((self.tcx.def_span(def.did()), msg)), // Point at the trait object that couldn't satisfy the bound. - ty::Dynamic(preds, _, _) => { + ty::Dynamic(preds, _) | ty::DynStar(preds, _) => { for pred in preds.iter() { match pred.skip_binder() { ty::ExistentialPredicate::Trait(tr) => { diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index f1b32cd941ed1..059deca57b904 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -450,6 +450,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { | ty::FnDef(..) | ty::FnPtr(_) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Never | ty::Tuple(..) | ty::Alias(..) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 6a463583dfb0f..857f5e9a2ed04 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -542,7 +542,7 @@ pub struct TraitObjectVisitor(pub FxIndexSet); impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { - ty::Dynamic(preds, re, _) if re.is_static() => { + ty::Dynamic(preds, re) | ty::DynStar(preds, re) if re.is_static() => { if let Some(def_id) = preds.principal_def_id() { self.0.insert(def_id); } diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index e3d9566917125..c261669247770 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -176,6 +176,7 @@ fn compute_components<'tcx>( ty::Tuple(..) | // ... ty::FnPtr(_) | // OutlivesFunction (*) ty::Dynamic(..) | // OutlivesObject, OutlivesFragment (*) + ty::DynStar(..) | // OutlivesObject, OutlivesFragment (*) ty::Placeholder(..) | ty::Bound(..) | ty::Error(_) => { diff --git a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs index dff5a645c175e..08e096d0cf96b 100644 --- a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs +++ b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs @@ -63,11 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait { && let opt_did @ Some(did) = trait_.trait_def_id() && opt_did == cx.tcx.lang_items().deref_trait() // `t` is `dyn t_principal` - && let ty::Dynamic(data, _, ty::Dyn) = t.kind() + && let ty::Dynamic(data, _) = t.kind() && let Some(t_principal) = data.principal() // `::Target` is `dyn target_principal` && let Some(target) = cx.get_associated_type(t, did, "Target") - && let ty::Dynamic(data, _, ty::Dyn) = target.kind() + && let ty::Dynamic(data, _) = target.kind() && let Some(target_principal) = data.principal() // `target_principal` is a supertrait of `t_principal` && supertraits(cx.tcx, t_principal.with_self_ty(cx.tcx, cx.tcx.types.trait_object_dummy_self)) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index b0a5d3674ad27..14b9ae9f50851 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1013,7 +1013,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { help: Some(fluent::lint_improper_ctypes_slice_help), }, - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..) => { FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_dyn, help: None } } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 88ea293444c17..de94e4cf5e0d5 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -273,16 +273,19 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { }) .map(|inner| MustUsePath::Opaque(Box::new(inner))) } - ty::Dynamic(binders, _, _) => binders.iter().find_map(|predicate| { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() - { - let def_id = trait_ref.def_id; - is_def_must_use(cx, def_id, span) - .map(|inner| MustUsePath::TraitObject(Box::new(inner))) - } else { - None - } - }), + ty::Dynamic(binders, _) | ty::DynStar(binders, _) => { + binders.iter().find_map(|predicate| { + if let ty::ExistentialPredicate::Trait(ref trait_ref) = + predicate.skip_binder() + { + let def_id = trait_ref.def_id; + is_def_must_use(cx, def_id, span) + .map(|inner| MustUsePath::TraitObject(Box::new(inner))) + } else { + None + } + }) + } ty::Tuple(tys) => { let elem_exprs = if let hir::ExprKind::Tup(elem_exprs) = expr.kind { debug_assert_eq!(elem_exprs.len(), tys.len()); diff --git a/compiler/rustc_middle/src/ty/cast.rs b/compiler/rustc_middle/src/ty/cast.rs index e65585955199f..0b5cfdb390bdb 100644 --- a/compiler/rustc_middle/src/ty/cast.rs +++ b/compiler/rustc_middle/src/ty/cast.rs @@ -71,7 +71,7 @@ impl<'tcx> CastTy<'tcx> { ty::Adt(d, _) if d.is_enum() && d.is_payloadfree() => Some(CastTy::Int(IntTy::CEnum)), ty::RawPtr(mt) => Some(CastTy::Ptr(mt)), ty::FnPtr(..) => Some(CastTy::FnPtr), - ty::Dynamic(_, _, ty::DynStar) => Some(CastTy::DynStar), + ty::DynStar(..) => Some(CastTy::DynStar), _ => None, } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 01f18e8158a33..b60137b599a50 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -67,7 +67,7 @@ use rustc_target::abi::{Layout, LayoutS, TargetDataLayout, VariantIdx}; use rustc_target::spec::abi; use rustc_type_ir::sty::TyKind::*; use rustc_type_ir::WithCachedTypeInfo; -use rustc_type_ir::{DynKind, InternAs, InternIteratorElement, Interner, TypeFlags}; +use rustc_type_ir::{InternAs, InternIteratorElement, Interner, TypeFlags}; use std::any::Any; use std::borrow::Borrow; @@ -1353,6 +1353,7 @@ impl<'tcx> TyCtxt<'tcx> { GeneratorWitness, GeneratorWitnessMIR, Dynamic, + DynStar, Closure, Tuple, Bound, @@ -1819,9 +1820,17 @@ impl<'tcx> TyCtxt<'tcx> { self, obj: &'tcx List>, reg: ty::Region<'tcx>, - repr: DynKind, ) -> Ty<'tcx> { - self.mk_ty(Dynamic(obj, reg, repr)) + self.mk_ty(Dynamic(obj, reg)) + } + + #[inline] + pub fn mk_dyn_star( + self, + obj: &'tcx List>, + reg: ty::Region<'tcx>, + ) -> Ty<'tcx> { + self.mk_ty(DynStar(obj, reg)) } #[inline] diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index bd78705cdb59b..d4d7ce02614aa 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -310,6 +310,7 @@ impl<'tcx> Ty<'tcx> { }, ty::FnPtr(_) => "fn pointer".into(), ty::Dynamic(..) => "trait object".into(), + ty::DynStar(..) => "dyn* trait object".into(), ty::Closure(..) => "closure".into(), ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(), ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => "generator witness".into(), diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 9afa37e9ef3ee..a11ed4fd8926d 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -99,12 +99,14 @@ pub fn simplify_type<'tcx>( ty::Array(..) => Some(ArraySimplifiedType), ty::Slice(..) => Some(SliceSimplifiedType), ty::RawPtr(ptr) => Some(PtrSimplifiedType(ptr.mutbl)), - ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() { - Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => { - Some(TraitSimplifiedType(principal_def_id)) + ty::Dynamic(trait_info, ..) | ty::DynStar(trait_info, ..) => { + match trait_info.principal_def_id() { + Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => { + Some(TraitSimplifiedType(principal_def_id)) + } + _ => Some(MarkerTraitObjectSimplifiedType), } - _ => Some(MarkerTraitObjectSimplifiedType), - }, + } ty::Ref(_, _, mutbl) => Some(RefSimplifiedType(mutbl)), ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(ClosureSimplifiedType(def_id)), ty::Generator(def_id, _, _) => Some(GeneratorSimplifiedType(def_id)), @@ -202,6 +204,7 @@ impl DeepRejectCtxt { | ty::Slice(..) | ty::RawPtr(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Ref(..) | ty::Never | ty::Tuple(..) @@ -271,6 +274,14 @@ impl DeepRejectCtxt { obl_preds.principal_def_id() == impl_preds.principal_def_id() ) } + ty::DynStar(obl_preds, ..) => { + // Ideally we would walk the existential predicates here or at least + // compare their length. But considering that the relevant `Relate` impl + // actually sorts and deduplicates these, that doesn't work. + matches!(k, ty::DynStar(impl_preds, ..) if + obl_preds.principal_def_id() == impl_preds.principal_def_id() + ) + } ty::FnPtr(obl_sig) => match k { ty::FnPtr(impl_sig) => { let ty::FnSig { inputs_and_output, c_variadic, unsafety, abi } = diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index dc6f5851b7d88..fcded4e1cffb3 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -186,7 +186,7 @@ impl FlagComputation { self.add_substs(substs); } - &ty::Dynamic(obj, r, _) => { + &ty::Dynamic(obj, r) | &ty::DynStar(obj, r) => { for predicate in obj.iter() { self.bound_computation(predicate, |computation, predicate| match predicate { ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs), diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 4c2855821384b..d82430ccbd79b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -647,7 +647,7 @@ where | ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) | ty::Foreign(..) - | ty::Dynamic(_, _, ty::Dyn) => { + | ty::Dynamic(..) => { bug!("TyAndLayout::field({:?}): not applicable", this) } @@ -714,7 +714,7 @@ where } else { match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind() { ty::Slice(_) | ty::Str => tcx.types.usize, - ty::Dynamic(_, _, ty::Dyn) => mk_dyn_vtable(), + ty::Dynamic(_, _) => mk_dyn_vtable(), _ => bug!("TyAndLayout::field({:?}): not applicable", this), } }; @@ -768,7 +768,7 @@ where } } - ty::Dynamic(_, _, ty::DynStar) => { + ty::DynStar(_, _) => { if i == 0 { TyMaybeWithLayout::Ty(tcx.types.usize) } else if i == 1 { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 09c3d5b736cf1..c3749f34abfbb 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -63,7 +63,6 @@ use std::{fmt, str}; pub use crate::ty::diagnostics::*; pub use rustc_type_ir::AliasKind::*; -pub use rustc_type_ir::DynKind::*; pub use rustc_type_ir::InferTy::*; pub use rustc_type_ir::RegionKind::*; pub use rustc_type_ir::TyKind::*; diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 90bf3288ccf54..581e63e8c8887 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -245,7 +245,7 @@ fn characteristic_def_id_of_type_cached<'a>( match *ty.kind() { ty::Adt(adt_def, _) => Some(adt_def.did()), - ty::Dynamic(data, ..) => data.principal_def_id(), + ty::Dynamic(data, ..) | ty::DynStar(data, ..) => data.principal_def_id(), ty::Array(subty, _) | ty::Slice(subty) => { characteristic_def_id_of_type_cached(subty, visited) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index a8b23e64e8209..28947f38f9ebe 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -710,16 +710,22 @@ pub trait PrettyPrinter<'tcx>: ty::Adt(def, substs) => { p!(print_def_path(def.did(), substs)); } - ty::Dynamic(data, r, repr) => { + ty::Dynamic(data, r) => { let print_r = self.should_print_region(r); if print_r { p!("("); } - match repr { - ty::Dyn => p!("dyn "), - ty::DynStar => p!("dyn* "), + p!("dyn ", print(data)); + if print_r { + p!(" + ", print(r), ")"); + } + } + ty::DynStar(data, r) => { + let print_r = self.should_print_region(r); + if print_r { + p!("("); } - p!(print(data)); + p!("dyn* ", print(data)); if print_r { p!(" + ", print(r), ")"); } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 890dabde1f73d..65775c2d6f1ce 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -439,13 +439,17 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( (&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk_foreign(a_id)), - (&ty::Dynamic(a_obj, a_region, a_repr), &ty::Dynamic(b_obj, b_region, b_repr)) - if a_repr == b_repr => - { + (&ty::Dynamic(a_obj, a_region), &ty::Dynamic(b_obj, b_region)) => { + let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| { + relation.relate(a_region, b_region) + })?; + Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound)) + } + (&ty::DynStar(a_obj, a_region), &ty::DynStar(b_obj, b_region)) => { let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| { relation.relate(a_region, b_region) })?; - Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound, a_repr)) + Ok(tcx.mk_dyn_star(relation.relate(a_obj, b_obj)?, region_bound)) } (&ty::Generator(a_id, a_substs, movability), &ty::Generator(b_id, b_substs, _)) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 8df639750c701..ee00b5766ee77 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -642,11 +642,12 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?), ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?), ty::Adt(tid, substs) => ty::Adt(tid, substs.try_fold_with(folder)?), - ty::Dynamic(trait_ty, region, representation) => ty::Dynamic( - trait_ty.try_fold_with(folder)?, - region.try_fold_with(folder)?, - representation, - ), + ty::Dynamic(trait_ty, region) => { + ty::Dynamic(trait_ty.try_fold_with(folder)?, region.try_fold_with(folder)?) + } + ty::DynStar(trait_ty, region) => { + ty::DynStar(trait_ty.try_fold_with(folder)?, region.try_fold_with(folder)?) + } ty::Tuple(ts) => ty::Tuple(ts.try_fold_with(folder)?), ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.try_fold_with(folder)?), ty::FnPtr(f) => ty::FnPtr(f.try_fold_with(folder)?), @@ -692,7 +693,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> { } ty::Slice(typ) => typ.visit_with(visitor), ty::Adt(_, substs) => substs.visit_with(visitor), - ty::Dynamic(ref trait_ty, ref reg, _) => { + ty::Dynamic(ref trait_ty, ref reg) | ty::DynStar(ref trait_ty, ref reg) => { trait_ty.visit_with(visitor)?; reg.visit_with(visitor) } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index b3b2a4fd0e5da..deba848e82dfe 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1964,12 +1964,12 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn is_trait(self) -> bool { - matches!(self.kind(), Dynamic(_, _, ty::Dyn)) + matches!(self.kind(), Dynamic(..)) } #[inline] pub fn is_dyn_star(self) -> bool { - matches!(self.kind(), Dynamic(_, _, ty::DynStar)) + matches!(self.kind(), DynStar(..)) } #[inline] @@ -2211,6 +2211,7 @@ impl<'tcx> Ty<'tcx> { | ty::FnDef(..) | ty::FnPtr(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(..) | ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) @@ -2264,7 +2265,7 @@ impl<'tcx> Ty<'tcx> { | ty::Tuple(..) => (tcx.types.unit, false), ty::Str | ty::Slice(_) => (tcx.types.usize, false), - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..)=> { let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None); (tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false) }, @@ -2339,6 +2340,7 @@ impl<'tcx> Ty<'tcx> { | ty::GeneratorWitnessMIR(..) | ty::Array(..) | ty::Closure(..) + | ty::DynStar(..) | ty::Never | ty::Error(_) => true, @@ -2373,7 +2375,7 @@ impl<'tcx> Ty<'tcx> { ty::Bool | ty::Char | ty::Never => true, // These aren't even `Clone` - ty::Str | ty::Slice(..) | ty::Foreign(..) | ty::Dynamic(..) => false, + ty::Str | ty::Slice(..) | ty::Foreign(..) | ty::Dynamic(..) | ty::DynStar(..) => false, ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_)) | ty::Int(..) diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 796164b0d6af3..4fb55d5bb1743 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -962,6 +962,7 @@ impl<'tcx> Ty<'tcx> { | ty::Bound(..) | ty::Closure(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Foreign(_) | ty::Generator(..) | ty::GeneratorWitness(_) @@ -1002,6 +1003,7 @@ impl<'tcx> Ty<'tcx> { | ty::Bound(..) | ty::Closure(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Foreign(_) | ty::Generator(..) | ty::GeneratorWitness(_) @@ -1123,7 +1125,11 @@ impl<'tcx> Ty<'tcx> { // Conservatively return `false` for all others... // Anonymous function types - ty::FnDef(..) | ty::Closure(..) | ty::Dynamic(..) | ty::Generator(..) => false, + ty::FnDef(..) + | ty::Closure(..) + | ty::Dynamic(..) + | ty::DynStar(..) + | ty::Generator(..) => false, // Generic or inferred types // @@ -1240,7 +1246,7 @@ pub fn needs_drop_components<'tcx>( // Foreign types can never have destructors. ty::Foreign(..) => Ok(SmallVec::new()), - ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop), + ty::Dynamic(..) | ty::DynStar(..) | ty::Error(_) => Err(AlwaysRequiresDrop), ty::Slice(ty) => needs_drop_components(*ty, target_layout), ty::Array(elem_ty, size) => { @@ -1295,6 +1301,7 @@ pub fn is_trivially_const_drop(ty: Ty<'_>) -> bool { ty::Alias(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 182945b9c3db1..14f7438608df9 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -168,7 +168,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) ty::Alias(_, data) => { stack.extend(data.substs.iter().rev()); } - ty::Dynamic(obj, lt, _) => { + ty::Dynamic(obj, lt) | ty::DynStar(obj, lt) => { stack.push(lt.into()); stack.extend(obj.iter().rev().flat_map(|predicate| { let (substs, opt_ty) = match predicate.skip_binder() { diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 7836ae2e7b76f..7c4bebee772c2 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -888,7 +888,7 @@ where self.open_drop_for_adt(*def, substs) } } - ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind), + ty::Dynamic(..) | ty::DynStar(..) => self.complete_drop(self.succ, self.unwind), ty::Array(ety, size) => { let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env()); self.open_drop_for_array(*ety, size) diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 47f9d35a4f7ec..83d4d17c45ed0 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -1801,7 +1801,7 @@ fn check_must_not_suspend_ty<'tcx>( } has_emitted } - ty::Dynamic(binder, _, _) => { + ty::Dynamic(binder, _) | ty::DynStar(binder, _) => { let mut has_emitted = false; for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 31a3ffbb1d891..7f9808f8f3cd2 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1072,7 +1072,7 @@ fn find_vtable_types_for_unsizing<'tcx>( let tail = tcx.struct_tail_erasing_lifetimes(ty, param_env); match tail.kind() { ty::Foreign(..) => false, - ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, + ty::Str | ty::Slice(..) | ty::Dynamic(..) | ty::DynStar(..) => true, _ => bug!("unexpected unsized tail: {:?}", tail), } }; @@ -1093,7 +1093,7 @@ fn find_vtable_types_for_unsizing<'tcx>( } // T as dyn* Trait - (_, &ty::Dynamic(_, _, ty::DynStar)) => ptr_vtable(source_ty, target_ty), + (_, &ty::DynStar(..)) => ptr_vtable(source_ty, target_ty), (&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => { assert_eq!(source_adt_def, target_adt_def); @@ -1147,7 +1147,7 @@ fn create_mono_items_for_vtable_methods<'tcx>( ) { assert!(!trait_ty.has_escaping_bound_vars() && !impl_ty.has_escaping_bound_vars()); - if let ty::Dynamic(ref trait_ty, ..) = trait_ty.kind() { + if let ty::Dynamic(ref trait_ty, ..) | ty::DynStar(ref trait_ty, ..) = trait_ty.kind() { if let Some(principal) = trait_ty.principal() { let poly_trait_ref = principal.with_self_ty(tcx, impl_ty); assert!(!poly_trait_ref.has_escaping_bound_vars()); diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 4355286153223..3b6968dc33951 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -223,7 +223,7 @@ where // This will also visit substs if necessary, so we don't need to recurse. return self.visit_projection_ty(proj); } - ty::Dynamic(predicates, ..) => { + ty::Dynamic(predicates, ..) | ty::DynStar(predicates, ..) => { // All traits in the list are considered the "primary" part of the type // and are visited by shallow visitors. for predicate in predicates { diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 710f38264036c..894df04445df7 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -623,13 +623,20 @@ fn encode_ty<'tcx>( } // Trait types - ty::Dynamic(predicates, region, kind) => { + ty::Dynamic(predicates, region) => { // u3dynIE, where is , as // vendor extended type. - let mut s = String::from(match kind { - ty::Dyn => "u3dynI", - ty::DynStar => "u7dynstarI", - }); + let mut s = String::from("u3dynI"); + s.push_str(&encode_predicates(tcx, predicates, dict, options)); + s.push_str(&encode_region(tcx, *region, dict, options)); + s.push('E'); + compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); + typeid.push_str(&s); + } + ty::DynStar(predicates, region) => { + // u3dynstarIE, where is , as + // vendor extended type. + let mut s = String::from("u7dynstarI"); s.push_str(&encode_predicates(tcx, predicates, dict, options)); s.push_str(&encode_region(tcx, *region, dict, options)); s.push('E'); @@ -669,7 +676,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio | ty::Str | ty::Never | ty::Foreign(..) - | ty::Dynamic(..) => {} + | ty::Dynamic(..) + | ty::DynStar(..) => {} _ if ty.is_unit() => {} diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 00d1ff5ceedf7..d2b5a5fbb9075 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -479,12 +479,13 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { })?; } - ty::Dynamic(predicates, r, kind) => { - self.push(match kind { - ty::Dyn => "D", - // FIXME(dyn-star): need to update v0 mangling docs - ty::DynStar => "D*", - }); + ty::Dynamic(predicates, r) => { + self.push("D"); + self = self.print_dyn_existential(predicates)?; + self = r.print(self)?; + } + ty::DynStar(predicates, r) => { + self.push("D*"); self = self.print_dyn_existential(predicates)?; self = r.print(self)?; } diff --git a/compiler/rustc_trait_selection/src/solve/assembly.rs b/compiler/rustc_trait_selection/src/solve/assembly.rs index 126ec60b3d68a..f9313c7c0f852 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly.rs @@ -385,6 +385,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::FnDef(_, _) | ty::FnPtr(_) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(_) @@ -445,7 +446,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { | ty::Error(_) => return, ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"), - ty::Dynamic(bounds, ..) => bounds, + ty::Dynamic(bounds, ..) | ty::DynStar(bounds, ..) => bounds, }; let tcx = self.tcx(); diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 4fea49893a6c6..08e57e4137565 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -386,7 +386,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ty::Str | ty::Slice(_) => tcx.types.usize, - ty::Dynamic(_, _, _) => { + ty::Dynamic(..) | ty::DynStar(..) => { let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None); tcx.bound_type_of(dyn_metadata) .subst(tcx, &[ty::GenericArg::from(goal.predicate.self_ty())]) diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index 6554c739b3f0c..a97bb5bac416f 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -267,14 +267,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ecx.infcx.probe(|_| { match (a_ty.kind(), b_ty.kind()) { // Trait upcasting, or `dyn Trait + Auto + 'a` -> `dyn Trait + 'b` - (&ty::Dynamic(_, _, ty::Dyn), &ty::Dynamic(_, _, ty::Dyn)) => { + (&ty::Dynamic(_, _), &ty::Dynamic(_, _)) => { // Dyn upcasting is handled separately, since due to upcasting, // when there are two supertraits that differ by substs, we // may return more than one query response. return Err(NoSolution); } // `T` -> `dyn Trait` unsizing - (_, &ty::Dynamic(data, region, ty::Dyn)) => { + (_, &ty::Dynamic(data, region)) => { // Can only unsize to an object-safe type if data .principal_def_id() @@ -385,10 +385,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { let a_ty = goal.predicate.self_ty(); let b_ty = goal.predicate.trait_ref.substs.type_at(1); - let ty::Dynamic(a_data, a_region, ty::Dyn) = *a_ty.kind() else { + let (ty::Dynamic(a_data, a_region) | ty::DynStar(a_data, a_region)) = *a_ty.kind() else { return vec![]; }; - let ty::Dynamic(b_data, b_region, ty::Dyn) = *b_ty.kind() else { + let (ty::Dynamic(b_data, b_region) | ty::DynStar(b_data, b_region)) = *b_ty.kind() else { return vec![]; }; @@ -417,7 +417,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { .map(ty::Binder::dummy), ); let new_a_data = tcx.mk_poly_existential_predicates(new_a_data); - let new_a_ty = tcx.mk_dynamic(new_a_data, b_region, ty::Dyn); + let new_a_ty = tcx.mk_dynamic(new_a_data, b_region); // We also require that A's lifetime outlives B's lifetime. let mut nested_obligations = ecx.infcx.eq(goal.param_env, new_a_ty, b_ty)?; diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs index 1ee35a86e6264..9b02d6e1cd649 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs @@ -25,6 +25,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>( | ty::Char => Ok(vec![]), ty::Dynamic(..) + | ty::DynStar(..) | ty::Param(..) | ty::Foreign(..) | ty::Alias(ty::Projection, ..) @@ -94,7 +95,7 @@ pub(super) fn instantiate_constituent_tys_for_sized_trait<'tcx>( | ty::Array(..) | ty::Closure(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) + | ty::DynStar(..) | ty::Error(_) => Ok(vec![]), ty::Str @@ -145,6 +146,7 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( | ty::Array(..) => Err(NoSolution), ty::Dynamic(..) + | ty::DynStar(..) | ty::Str | ty::Slice(_) | ty::Generator(_, _, Movability::Static) @@ -217,7 +219,8 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>( | ty::Slice(_) | ty::RawPtr(_) | ty::Ref(_, _, _) - | ty::Dynamic(_, _, _) + | ty::Dynamic(..) + | ty::DynStar(..) | ty::Generator(_, _, _) | ty::GeneratorWitness(_) | ty::GeneratorWitnessMIR(..) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 61f508a7a0750..1f2d5681d33c6 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -677,7 +677,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { self.found_non_local_ty(ty) } } - ty::Dynamic(tt, ..) => { + ty::Dynamic(tt, ..) | ty::DynStar(tt, ..) => { let principal = tt.principal().map(|p| p.def_id()); if principal.map_or(false, |p| self.def_id_is_local(p)) { ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index cf1e05ada4713..2b934d5b90d41 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1915,7 +1915,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Ref(..) | ty::RawPtr(..) => Some(5), ty::Array(..) | ty::Slice(..) => Some(6), ty::FnDef(..) | ty::FnPtr(..) => Some(7), - ty::Dynamic(..) => Some(8), + ty::Dynamic(..) | ty::DynStar(..) => Some(8), ty::Closure(..) => Some(9), ty::Tuple(..) => Some(10), ty::Param(..) => Some(11), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index a3209d35e58be..82c289f9aa551 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -282,7 +282,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } } - if let ty::Dynamic(traits, _, _) = self_ty.kind() { + if let ty::Dynamic(traits, _) | ty::DynStar(traits, _) = self_ty.kind() { for t in traits.iter() { if let ty::ExistentialPredicate::Trait(trait_ref) = t.skip_binder() { flags.push((sym::_Self, Some(self.tcx.def_path_str(trait_ref.def_id)))) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 2b543520198fb..8c339265cc841 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1141,7 +1141,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } }) } - ty::Dynamic(data, _, ty::Dyn) => { + ty::Dynamic(data, _) => { data.iter().find_map(|pred| { if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder() && Some(proj.def_id) == self.tcx.lang_items().fn_once_output() @@ -1387,7 +1387,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self_ty: Ty<'tcx>, object_ty: Ty<'tcx>, ) { - let ty::Dynamic(predicates, _, ty::Dyn) = object_ty.kind() else { return; }; + let ty::Dynamic(predicates, _) = object_ty.kind() else { return; }; let self_ref_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, self_ty); for predicate in predicates.iter() { @@ -1745,7 +1745,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let trait_pred = self.resolve_vars_if_possible(trait_pred); let ty = trait_pred.skip_binder().self_ty(); let is_object_safe = match ty.kind() { - ty::Dynamic(predicates, _, ty::Dyn) => { + ty::Dynamic(predicates, _) => { // If the `dyn Trait` is not object safe, do not suggest `Box`. predicates .principal_def_id() @@ -1805,7 +1805,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let mut spans_and_needs_box = vec![]; match liberated_sig.output().kind() { - ty::Dynamic(predicates, _, ty::Dyn) => { + ty::Dynamic(predicates, _) => { let cause = ObligationCause::misc(ret_ty.span, obligation.cause.body_id); let param_env = ty::ParamEnv::empty(); @@ -2864,7 +2864,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if let Some(span) = sp { if let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() && let ty::Clause::Trait(trait_pred) = clause - && let ty::Dynamic(..) = trait_pred.self_ty().kind() + && let ty::Dynamic(..) | ty::DynStar(..) = trait_pred.self_ty().kind() { let span = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) && snippet.starts_with("dyn ") diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index bafa2981a8739..1b3ecd96c5b18 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -662,7 +662,7 @@ fn object_ty_for_trait<'tcx>( .mk_poly_existential_predicates(iter::once(trait_predicate).chain(elaborated_predicates)); debug!(?existential_predicates); - tcx.mk_dynamic(existential_predicates, lifetime, ty::Dyn) + tcx.mk_dynamic(existential_predicates, lifetime) } /// Checks the method's receiver (the `self` argument) can be dispatched on when `Self` is a diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index aa81bc640aa6c..e66674fbd39a2 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1416,7 +1416,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>( let self_ty = obligation.predicate.self_ty(); let object_ty = selcx.infcx.shallow_resolve(self_ty); let data = match object_ty.kind() { - ty::Dynamic(data, ..) => data, + ty::Dynamic(data, ..) | ty::DynStar(data, ..) => data, ty::Infer(ty::TyVar(_)) => { // If the self-type is an inference variable, then it MAY wind up // being an object type, so induce an ambiguity. @@ -1602,6 +1602,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( | ty::FnDef(..) | ty::FnPtr(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(..) @@ -1652,6 +1653,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( | ty::FnDef(..) | ty::FnPtr(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 455b53bfb7d8f..681c25b70645c 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -63,6 +63,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { // The following *might* require a destructor: needs deeper inspection. ty::Dynamic(..) + | ty::DynStar(..) | ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index e9f7c3bc4cca2..3cd8b75f82a7e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -384,7 +384,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if self.tcx().trait_is_auto(def_id) { match self_ty.kind() { - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..) => { // For object types, we don't know what the closed // over types are. This means we conservatively // say nothing; a candidate may be added by @@ -453,7 +453,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // any LBR. let self_ty = self.tcx().erase_late_bound_regions(obligation.self_ty()); let poly_trait_ref = match self_ty.kind() { - ty::Dynamic(ref data, ..) => { + ty::Dynamic(ref data, ..) | ty::DynStar(ref data, ..) => { if data.auto_traits().any(|did| did == obligation.predicate.def_id()) { debug!( "assemble_candidates_from_object_ty: matched builtin bound, \ @@ -548,7 +548,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .ty() .unwrap(); - if let ty::Dynamic(data, ..) = ty.kind() { data.principal() } else { None } + if let ty::Dynamic(data, ..) | ty::DynStar(data, ..) = ty.kind() { + data.principal() + } else { + None + } }) } @@ -582,7 +586,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (upcasts). - (&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => { + (&ty::Dynamic(ref data_a, _), &ty::Dynamic(ref data_b, _)) => { // Upcast coercions permit several things: // // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo` @@ -631,7 +635,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `T` -> `Trait` - (_, &ty::Dynamic(_, _, ty::Dyn)) => { + (_, &ty::Dynamic(_, _)) => { candidates.vec.push(BuiltinUnsizeCandidate); } @@ -738,6 +742,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match self_ty.skip_binder().kind() { ty::Alias(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) @@ -823,7 +828,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Ref(_, _, _) | ty::FnDef(_, _) | ty::FnPtr(_) - | ty::Dynamic(_, _, _) + | ty::Dynamic(..) + | ty::DynStar(..) | ty::Closure(_, _) | ty::Generator(_, _, _) | ty::GeneratorWitness(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index fcc4820c2a6b6..923fa144034b4 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -430,7 +430,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let trait_predicate = self.infcx.instantiate_binder_with_placeholders(obligation.predicate); let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty()); let obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref); - let ty::Dynamic(data, ..) = *self_ty.kind() else { + let (ty::Dynamic(data, ..) | ty::DynStar(data, ..)) = *self_ty.kind() else { span_bug!(obligation.cause.span, "object candidate with non-object"); }; @@ -850,10 +850,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let upcast_trait_ref; match (source.kind(), target.kind()) { // TraitA+Kx+'a -> TraitB+Ky+'b (trait upcasting coercion). - ( - &ty::Dynamic(ref data_a, r_a, repr_a @ ty::Dyn), - &ty::Dynamic(ref data_b, r_b, ty::Dyn), - ) => { + (&ty::Dynamic(ref data_a, r_a), &ty::Dynamic(ref data_b, r_b)) => { // See `assemble_candidates_for_unsizing` for more info. // We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`. let principal_a = data_a.principal().unwrap(); @@ -879,7 +876,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::Binder::dummy), ); let existential_predicates = tcx.mk_poly_existential_predicates(iter); - let source_trait = tcx.mk_dynamic(existential_predicates, r_b, repr_a); + let source_trait = tcx.mk_dynamic(existential_predicates, r_b); // Require that the traits involved in this upcast are **equal**; // only the **lifetime bound** is changed. @@ -957,9 +954,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let mut nested = vec![]; match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping). - (&ty::Dynamic(ref data_a, r_a, dyn_a), &ty::Dynamic(ref data_b, r_b, dyn_b)) - if dyn_a == dyn_b => - { + (&ty::Dynamic(ref data_a, r_a), &ty::Dynamic(ref data_b, r_b)) + | (&ty::DynStar(ref data_a, r_a), &ty::DynStar(ref data_b, r_b)) => { // See `assemble_candidates_for_unsizing` for more info. // We already checked the compatibility of auto traits within `assemble_candidates_for_unsizing`. let iter = data_a @@ -978,7 +974,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::Binder::dummy), ); let existential_predicates = tcx.mk_poly_existential_predicates(iter); - let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a); + let source_trait = match source.kind() { + ty::Dynamic(..) => tcx.mk_dynamic(existential_predicates, r_b), + ty::DynStar(..) => tcx.mk_dyn_star(existential_predicates, r_b), + _ => unreachable!(), + }; // Require that the traits involved in this upcast are **equal**; // only the **lifetime bound** is changed. @@ -1006,7 +1006,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `T` -> `Trait` - (_, &ty::Dynamic(ref data, r, ty::Dyn)) => { + (_, &ty::Dynamic(ref data, r)) => { let mut object_dids = data.auto_traits().chain(data.principal_def_id()); if let Some(did) = object_dids.find(|did| !tcx.check_is_object_safe(*did)) { return Err(TraitNotObjectSafe(did)); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 984d6fde2686c..9135605cf4478 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2070,7 +2070,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Array(..) | ty::Closure(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) + | ty::DynStar(..) | ty::Error(_) => { // safe for everything Where(ty::Binder::dummy(Vec::new())) @@ -2135,6 +2135,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::Dynamic(..) + | ty::DynStar(..) | ty::Str | ty::Slice(..) | ty::Generator(_, _, hir::Movability::Static) @@ -2255,6 +2256,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Placeholder(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Param(..) | ty::Foreign(..) | ty::Alias(ty::Projection, ..) diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index 69b965f3a389a..2204a6993ce27 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -89,7 +89,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> { ty::Param(_) => { return ControlFlow::Break(ty); } - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..) => { return ControlFlow::Break(ty); } ty::Foreign(_) => { diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 64daca714c32d..c451c34732d77 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -353,8 +353,8 @@ pub(crate) fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>( ), ) -> Option { let (source, target) = key; - assert!(matches!(&source.kind(), &ty::Dynamic(..)) && !source.needs_infer()); - assert!(matches!(&target.kind(), &ty::Dynamic(..)) && !target.needs_infer()); + assert!(matches!(&source.kind(), &ty::Dynamic(..) | &ty::DynStar(..)) && !source.needs_infer()); + assert!(matches!(&target.kind(), &ty::Dynamic(..) | &ty::DynStar(..)) && !target.needs_infer()); // this has been typecked-before, so diagnostics is not really needed. let unsize_trait_did = tcx.require_lang_item(LangItem::Unsize, None); diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 7c5e147a950f1..471278ba101f6 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -689,7 +689,7 @@ impl<'tcx> WfPredicates<'tcx> { } } - ty::Dynamic(data, r, _) => { + ty::Dynamic(data, r) | ty::DynStar(data, r) => { // WfObject // // Here, we defer WF checking due to higher-ranked diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 65ed3105d10bc..f5e58b2c1d13e 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -330,11 +330,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { )), }) } - // FIXME(dyn-star): handle the dynamic kind (dyn or dyn*) - ty::Dynamic(predicates, region, _kind) => chalk_ir::TyKind::Dyn(chalk_ir::DynTy { - bounds: predicates.lower_into(interner), - lifetime: region.lower_into(interner), - }), + ty::Dynamic(predicates, region) | ty::DynStar(predicates, region) => { + chalk_ir::TyKind::Dyn(chalk_ir::DynTy { + bounds: predicates.lower_into(interner), + lifetime: region.lower_into(interner), + }) + } ty::Closure(def_id, substs) => { chalk_ir::TyKind::Closure(chalk_ir::ClosureId(def_id), substs.lower_into(interner)) } diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index 8b7f8033bface..7db8dd8d068ac 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -264,7 +264,7 @@ fn dtorck_constraint_for_ty<'tcx>( // Objects must be alive in order for their destructor // to be called. - ty::Dynamic(..) => { + ty::Dynamic(..) | ty::DynStar(..) => { constraints.outlives.push(ty.into()); } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 8d46ba320fc03..e290ebec9b1d0 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -71,6 +71,7 @@ fn inner_resolve_instance<'tcx>( | ty::Tuple(..) | ty::Adt(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Array(..) | ty::Slice(..) => {} // Drop shims can only be built from ADTs. diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 2aeb255c1641c..633e9fb931da0 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -192,7 +192,7 @@ fn layout_of_uncached<'tcx>( tcx.intern_layout(cx.scalar_pair(data_ptr, metadata)) } - ty::Dynamic(_, _, ty::DynStar) => { + ty::DynStar(_, _) => { let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false)); data.valid_range_mut().start = 0; let mut vtable = scalar_unit(Pointer(AddressSpace::DATA)); @@ -252,7 +252,7 @@ fn layout_of_uncached<'tcx>( // Odd unit types. ty::FnDef(..) => univariant(&[], &ReprOptions::default(), StructKind::AlwaysSized)?, - ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => { + ty::Dynamic(_, _) | ty::Foreign(..) => { let mut unit = univariant_uninterned( cx, ty, diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 41e837e8b754e..9f97fa3628cb5 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -28,6 +28,8 @@ fn sized_constraint_for_ty<'tcx>( vec![ty] } + DynStar(..) => todo!(), + Tuple(ref tys) => match tys.last() { None => vec![], Some(&ty) => sized_constraint_for_ty(tcx, adtdef, ty), @@ -388,7 +390,9 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { let self_ty = trait_ref.self_ty(); let self_ty_matches = match self_ty.kind() { - ty::Dynamic(ref data, re, _) if re.is_static() => data.principal().is_none(), + ty::Dynamic(ref data, re) | ty::DynStar(ref data, re) if re.is_static() => { + data.principal().is_none() + } _ => false, }; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 61557fdc0eda4..59360570e68e6 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -119,7 +119,17 @@ pub enum TyKind { FnPtr(I::PolyFnSig), /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`. - Dynamic(I::ListBinderExistentialPredicate, I::Region, DynKind), + Dynamic(I::ListBinderExistentialPredicate, I::Region), + + /// A dyn* trait object. Written as `dyn* for<'b> Trait<'b, Assoc = u32> + Send + 'a`. + /// + /// These objects are represented as a `(data, vtable)` pair where `data` is a ptr-sized value + /// (often a pointer to the real object, but not necessarily) and `vtable` is a pointer to + /// the vtable for `dyn* Trait`. The representation is essentially the same as `&dyn Trait` + /// or similar, but the drop function included in the vtable is responsible for freeing the + /// underlying storage if needed. This allows a `dyn*` object to be treated agnostically with + /// respect to whether it points to a `Box`, `Rc`, etc. + DynStar(I::ListBinderExistentialPredicate, I::Region), /// The anonymous type of a closure. Used to represent the type of `|a| a`. /// @@ -268,6 +278,7 @@ const fn tykind_discriminant(value: &TyKind) -> usize { Infer(_) => 24, Error(_) => 25, GeneratorWitnessMIR(_, _) => 26, + DynStar(..) => 27, } } @@ -289,7 +300,8 @@ impl Clone for TyKind { Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()), FnDef(d, s) => FnDef(d.clone(), s.clone()), FnPtr(s) => FnPtr(s.clone()), - Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), *repr), + Dynamic(p, r) => Dynamic(p.clone(), r.clone()), + DynStar(p, r) => DynStar(p.clone(), r.clone()), Closure(d, s) => Closure(d.clone(), s.clone()), Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()), GeneratorWitness(g) => GeneratorWitness(g.clone()), @@ -328,8 +340,8 @@ impl PartialEq for TyKind { (Ref(a_r, a_t, a_m), Ref(b_r, b_t, b_m)) => a_r == b_r && a_t == b_t && a_m == b_m, (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d == b_d && a_s == b_s, (FnPtr(a_s), FnPtr(b_s)) => a_s == b_s, - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { - a_p == b_p && a_r == b_r && a_repr == b_repr + (Dynamic(a_p, a_r), Dynamic(b_p, b_r)) | (DynStar(a_p, a_r), DynStar(b_p, b_r)) => { + a_p == b_p && a_r == b_r } (Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s, (Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => { @@ -388,8 +400,8 @@ impl Ord for TyKind { } (FnDef(a_d, a_s), FnDef(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), (FnPtr(a_s), FnPtr(b_s)) => a_s.cmp(b_s), - (Dynamic(a_p, a_r, a_repr), Dynamic(b_p, b_r, b_repr)) => { - a_p.cmp(b_p).then_with(|| a_r.cmp(b_r).then_with(|| a_repr.cmp(b_repr))) + (Dynamic(a_p, a_r), Dynamic(b_p, b_r)) | (DynStar(a_p, a_r), DynStar(b_p, b_r))=> { + a_p.cmp(b_p).then_with(|| a_r.cmp(b_r)) } (Closure(a_p, a_s), Closure(b_p, b_s)) => a_p.cmp(b_p).then_with(|| a_s.cmp(b_s)), (Generator(a_d, a_s, a_m), Generator(b_d, b_s, b_m)) => { @@ -449,10 +461,9 @@ impl hash::Hash for TyKind { s.hash(state) } FnPtr(s) => s.hash(state), - Dynamic(p, r, repr) => { + Dynamic(p, r) | DynStar(p, r) => { p.hash(state); - r.hash(state); - repr.hash(state) + r.hash(state) } Closure(d, s) => { d.hash(state); @@ -504,7 +515,8 @@ impl fmt::Debug for TyKind { Ref(r, t, m) => f.debug_tuple_field3_finish("Ref", r, t, m), FnDef(d, s) => f.debug_tuple_field2_finish("FnDef", d, s), FnPtr(s) => f.debug_tuple_field1_finish("FnPtr", s), - Dynamic(p, r, repr) => f.debug_tuple_field3_finish("Dynamic", p, r, repr), + Dynamic(p, r) => f.debug_tuple_field2_finish("Dynamic", p, r), + DynStar(p, r) => f.debug_tuple_field2_finish("DynStar", p, r), Closure(d, s) => f.debug_tuple_field2_finish("Closure", d, s), Generator(d, s, m) => f.debug_tuple_field3_finish("Generator", d, s, m), GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g), @@ -590,10 +602,9 @@ where FnPtr(polyfnsig) => e.emit_enum_variant(disc, |e| { polyfnsig.encode(e); }), - Dynamic(l, r, repr) => e.emit_enum_variant(disc, |e| { + Dynamic(l, r) | DynStar(l, r) => e.emit_enum_variant(disc, |e| { l.encode(e); - r.encode(e); - repr.encode(e); + r.encode(e) }), Closure(def_id, substs) => e.emit_enum_variant(disc, |e| { def_id.encode(e); @@ -681,7 +692,7 @@ where 11 => Ref(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), 12 => FnDef(Decodable::decode(d), Decodable::decode(d)), 13 => FnPtr(Decodable::decode(d)), - 14 => Dynamic(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), + 14 => Dynamic(Decodable::decode(d), Decodable::decode(d)), 15 => Closure(Decodable::decode(d), Decodable::decode(d)), 16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), 17 => GeneratorWitness(Decodable::decode(d)), @@ -694,11 +705,12 @@ where 24 => Infer(Decodable::decode(d)), 25 => Error(Decodable::decode(d)), 26 => GeneratorWitnessMIR(Decodable::decode(d), Decodable::decode(d)), + 27 => DynStar(Decodable::decode(d), Decodable::decode(d)), _ => panic!( "{}", format!( "invalid enum variant tag while decoding `{}`, expected 0..{}", - "TyKind", 27, + "TyKind", 28, ) ), } @@ -778,10 +790,9 @@ where FnPtr(polyfnsig) => { polyfnsig.hash_stable(__hcx, __hasher); } - Dynamic(l, r, repr) => { + Dynamic(l, r) | DynStar(l, r) => { l.hash_stable(__hcx, __hasher); r.hash_stable(__hcx, __hasher); - repr.hash_stable(__hcx, __hasher); } Closure(def_id, substs) => { def_id.hash_stable(__hcx, __hasher); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5bda3620dd0fd..c57c9547a2b56 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1745,7 +1745,7 @@ pub(crate) fn clean_middle_ty<'tcx>( ); Type::Path { path } } - ty::Dynamic(obj, ref reg, _) => { + ty::Dynamic(obj, ref reg) | ty::DynStar(obj, ref reg) => { // HACK: pick the first `did` as the `did` of the trait object. Someone // might want to implement "native" support for marker-trait-only // trait objects. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 8435972bb11f2..7b3188ae14878 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -544,6 +544,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { | ty::GeneratorWitness(_) | ty::GeneratorWitnessMIR(..) | ty::Dynamic(..) + | ty::DynStar(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index d88409c356e91..d1b7a7c8d3987 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -1,19 +1,23 @@ //! Checks for usage of `&Vec[_]` and `&String`. -use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; +use clippy_utils::diagnostics::{ + span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then, +}; use clippy_utils::source::snippet_opt; use clippy_utils::ty::expr_sig; use clippy_utils::visitors::contains_unsafe_block; -use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths}; +use clippy_utils::{ + get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths, +}; use if_chain::if_chain; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirIdMap; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ - self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, - ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, TraitItem, TraitItemKind, - TyKind, Unsafety, + self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, + GenericArg, ImplItemKind, ItemKind, Lifetime, Mutability, Node, Param, PatKind, QPath, TraitFn, + TraitItem, TraitItemKind, TyKind, Unsafety, }; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{Obligation, ObligationCause}; @@ -170,14 +174,21 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { ) .filter(|arg| arg.mutability() == Mutability::Not) { - span_lint_hir_and_then(cx, PTR_ARG, arg.emission_id, arg.span, &arg.build_msg(), |diag| { - diag.span_suggestion( - arg.span, - "change this to", - format!("{}{}", arg.ref_prefix, arg.deref_ty.display(cx)), - Applicability::Unspecified, - ); - }); + span_lint_hir_and_then( + cx, + PTR_ARG, + arg.emission_id, + arg.span, + &arg.build_msg(), + |diag| { + diag.span_suggestion( + arg.span, + "change this to", + format!("{}{}", arg.ref_prefix, arg.deref_ty.display(cx)), + Applicability::Unspecified, + ); + }, + ); } } } @@ -192,7 +203,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } else { return; } - }, + } Some((_, Node::ImplItem(i))) => { if !matches!(parents.next(), Some((_, Node::Item(i))) if matches!(&i.kind, ItemKind::Impl(i) if i.of_trait.is_none()) @@ -204,14 +215,14 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } else { return; } - }, + } Some((_, Node::TraitItem(i))) => { if let TraitItemKind::Fn(sig, _) = &i.kind { (i.owner_id, sig, true) } else { return; } - }, + } _ => return, }; @@ -224,26 +235,42 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { let results = check_ptr_arg_usage(cx, body, &lint_args); for (result, args) in results.iter().zip(lint_args.iter()).filter(|(r, _)| !r.skip) { - span_lint_hir_and_then(cx, PTR_ARG, args.emission_id, args.span, &args.build_msg(), |diag| { - diag.multipart_suggestion( - "change this to", - iter::once((args.span, format!("{}{}", args.ref_prefix, args.deref_ty.display(cx)))) + span_lint_hir_and_then( + cx, + PTR_ARG, + args.emission_id, + args.span, + &args.build_msg(), + |diag| { + diag.multipart_suggestion( + "change this to", + iter::once(( + args.span, + format!("{}{}", args.ref_prefix, args.deref_ty.display(cx)), + )) .chain(result.replacements.iter().map(|r| { ( r.expr_span, - format!("{}{}", snippet_opt(cx, r.self_span).unwrap(), r.replacement), + format!( + "{}{}", + snippet_opt(cx, r.self_span).unwrap(), + r.replacement + ), ) })) .collect(), - Applicability::Unspecified, - ); - }); + Applicability::Unspecified, + ); + }, + ); } } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, l, r) = expr.kind { - if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(cx, l) || is_null_path(cx, r)) { + if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) + && (is_null_path(cx, l) || is_null_path(cx, r)) + { span_lint( cx, CMP_NULL, @@ -372,7 +399,7 @@ impl fmt::Display for DerefTyDisplay<'_, '_> { None => ty.fmt(f)?, } f.write_char(']') - }, + } } } } @@ -413,92 +440,89 @@ fn check_fn_args<'cx, 'tcx: 'cx>( hir_tys: &'tcx [hir::Ty<'tcx>], params: &'tcx [Param<'tcx>], ) -> impl Iterator> + 'cx { - tys.iter() - .zip(hir_tys.iter()) - .enumerate() - .filter_map(|(i, (ty, hir_ty))| { - if_chain! { - if let ty::Ref(_, ty, mutability) = *ty.kind(); - if let ty::Adt(adt, substs) = *ty.kind(); - - if let TyKind::Ref(lt, ref ty) = hir_ty.kind; - if let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind; - - // Check that the name as typed matches the actual name of the type. - // e.g. `fn foo(_: &Foo)` shouldn't trigger the lint when `Foo` is an alias for `Vec` - if let [.., name] = path.segments; - if cx.tcx.item_name(adt.did()) == name.ident.name; - - then { - let emission_id = params.get(i).map_or(hir_ty.hir_id, |param| param.hir_id); - let (method_renames, deref_ty) = match cx.tcx.get_diagnostic_name(adt.did()) { - Some(sym::Vec) => ( - [("clone", ".to_owned()")].as_slice(), - DerefTy::Slice( - name.args - .and_then(|args| args.args.first()) - .and_then(|arg| if let GenericArg::Type(ty) = arg { - Some(ty.span) - } else { - None - }), - substs.type_at(0), - ), - ), - _ if Some(adt.did()) == cx.tcx.lang_items().string() => ( - [("clone", ".to_owned()"), ("as_str", "")].as_slice(), - DerefTy::Str, + tys.iter().zip(hir_tys.iter()).enumerate().filter_map(|(i, (ty, hir_ty))| { + if_chain! { + if let ty::Ref(_, ty, mutability) = *ty.kind(); + if let ty::Adt(adt, substs) = *ty.kind(); + + if let TyKind::Ref(lt, ref ty) = hir_ty.kind; + if let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind; + + // Check that the name as typed matches the actual name of the type. + // e.g. `fn foo(_: &Foo)` shouldn't trigger the lint when `Foo` is an alias for `Vec` + if let [.., name] = path.segments; + if cx.tcx.item_name(adt.did()) == name.ident.name; + + then { + let emission_id = params.get(i).map_or(hir_ty.hir_id, |param| param.hir_id); + let (method_renames, deref_ty) = match cx.tcx.get_diagnostic_name(adt.did()) { + Some(sym::Vec) => ( + [("clone", ".to_owned()")].as_slice(), + DerefTy::Slice( + name.args + .and_then(|args| args.args.first()) + .and_then(|arg| if let GenericArg::Type(ty) = arg { + Some(ty.span) + } else { + None + }), + substs.type_at(0), ), - Some(sym::PathBuf) => ( - [("clone", ".to_path_buf()"), ("as_path", "")].as_slice(), - DerefTy::Path, - ), - Some(sym::Cow) if mutability == Mutability::Not => { - let ty_name = name.args - .and_then(|args| { - args.args.iter().find_map(|a| match a { - GenericArg::Type(x) => Some(x), - _ => None, - }) + ), + _ if Some(adt.did()) == cx.tcx.lang_items().string() => ( + [("clone", ".to_owned()"), ("as_str", "")].as_slice(), + DerefTy::Str, + ), + Some(sym::PathBuf) => ( + [("clone", ".to_path_buf()"), ("as_path", "")].as_slice(), + DerefTy::Path, + ), + Some(sym::Cow) if mutability == Mutability::Not => { + let ty_name = name.args + .and_then(|args| { + args.args.iter().find_map(|a| match a { + GenericArg::Type(x) => Some(x), + _ => None, }) - .and_then(|arg| snippet_opt(cx, arg.span)) - .unwrap_or_else(|| substs.type_at(1).to_string()); - span_lint_hir_and_then( - cx, - PTR_ARG, - emission_id, - hir_ty.span, - "using a reference to `Cow` is not recommended", - |diag| { - diag.span_suggestion( - hir_ty.span, - "change this to", - format!("&{}{ty_name}", mutability.prefix_str()), - Applicability::Unspecified, - ); - } - ); - return None; - }, - _ => return None, - }; - return Some(PtrArg { - idx: i, - emission_id, - span: hir_ty.span, - ty_did: adt.did(), - ty_name: name.ident.name, - method_renames, - ref_prefix: RefPrefix { - lt: *lt, - mutability, - }, - deref_ty, - }); - } + }) + .and_then(|arg| snippet_opt(cx, arg.span)) + .unwrap_or_else(|| substs.type_at(1).to_string()); + span_lint_hir_and_then( + cx, + PTR_ARG, + emission_id, + hir_ty.span, + "using a reference to `Cow` is not recommended", + |diag| { + diag.span_suggestion( + hir_ty.span, + "change this to", + format!("&{}{ty_name}", mutability.prefix_str()), + Applicability::Unspecified, + ); + } + ); + return None; + }, + _ => return None, + }; + return Some(PtrArg { + idx: i, + emission_id, + span: hir_ty.span, + ty_did: adt.did(), + ty_name: name.ident.name, + method_renames, + ref_prefix: RefPrefix { + lt: *lt, + mutability, + }, + deref_ty, + }); } - None - }) + } + None + }) } fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) { @@ -535,7 +559,11 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio } #[expect(clippy::too_many_lines)] -fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec { +fn check_ptr_arg_usage<'tcx>( + cx: &LateContext<'tcx>, + body: &'tcx Body<'_>, + args: &[PtrArg<'tcx>], +) -> Vec { struct V<'cx, 'tcx> { cx: &'cx LateContext<'tcx>, /// Map from a local id to which argument it came from (index into `Self::args` and @@ -585,13 +613,16 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: } else { set_skip_flag(); } - }, + } Some((Node::Expr(e), child_id)) => match e.kind { ExprKind::Call(f, expr_args) => { - let i = expr_args.iter().position(|arg| arg.hir_id == child_id).unwrap_or(0); + let i = + expr_args.iter().position(|arg| arg.hir_id == child_id).unwrap_or(0); if expr_sig(self.cx, f).and_then(|sig| sig.input(i)).map_or(true, |ty| { match *ty.skip_binder().peel_refs().kind() { - ty::Dynamic(preds, _, _) => !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds), + ty::Dynamic(preds, _) | ty::DynStar(preds, _) => { + !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) + } ty::Param(_) => true, ty::Adt(def, _) => def.did() == args.ty_did, _ => false, @@ -600,7 +631,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: // Passed to a function taking the non-dereferenced type. set_skip_flag(); } - }, + } ExprKind::MethodCall(name, self_arg, expr_args, _) => { let i = std::iter::once(self_arg) .chain(expr_args.iter()) @@ -609,7 +640,9 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: if i == 0 { // Check if the method can be renamed. let name = name.ident.as_str(); - if let Some((_, replacement)) = args.method_renames.iter().find(|&&(x, _)| x == name) { + if let Some((_, replacement)) = + args.method_renames.iter().find(|&&(x, _)| x == name) + { result.replacements.push(PtrArgReplacement { expr_span: e.span, self_span: self_arg.span, @@ -628,20 +661,22 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: .peel_refs() .kind() { - ty::Dynamic(preds, _, _) if !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) => { + ty::Dynamic(preds, _) | ty::DynStar(preds, _) + if !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) => + { set_skip_flag(); - }, + } ty::Param(_) => { set_skip_flag(); - }, + } // If the types match check for methods which exist on both types. e.g. `Vec::len` and // `slice::len` ty::Adt(def, _) if def.did() == args.ty_did => { set_skip_flag(); - }, + } _ => (), } - }, + } // Indexing is fine for currently supported types. ExprKind::Index(e, _) if e.hir_id == child_id => (), _ => set_skip_flag(), @@ -665,12 +700,12 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: if !is_lint_allowed(cx, PTR_ARG, param.hir_id) => { Some((id, i)) - }, + } _ => { skip_count += 1; results[i].skip = true; None - }, + } } }) .collect(), @@ -690,29 +725,30 @@ fn matches_preds<'tcx>( let infcx = cx.tcx.infer_ctxt().build(); preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) { ExistentialPredicate::Trait(p) => infcx - .type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.substs.iter()), cx.param_env) + .type_implements_trait( + p.def_id, + [ty.into()].into_iter().chain(p.substs.iter()), + cx.param_env, + ) .must_apply_modulo_regions(), - ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new( - cx.tcx, - ObligationCause::dummy(), - cx.param_env, - cx.tcx - .mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Projection( + ExistentialPredicate::Projection(p) => { + infcx.predicate_must_hold_modulo_regions(&Obligation::new( + cx.tcx, + ObligationCause::dummy(), + cx.param_env, + cx.tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Projection( p.with_self_ty(cx.tcx, ty), )))), - )), - ExistentialPredicate::AutoTrait(p) => infcx - .type_implements_trait(p, [ty], cx.param_env) - .must_apply_modulo_regions(), + )) + } + ExistentialPredicate::AutoTrait(p) => { + infcx.type_implements_trait(p, [ty], cx.param_env).must_apply_modulo_regions() + } }) } fn get_ref_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> { - if let TyKind::Ref(lt, ref m) = ty.kind { - Some((lt, m.mutbl, ty.span)) - } else { - None - } + if let TyKind::Ref(lt, ref m) = ty.kind { Some((lt, m.mutbl, ty.span)) } else { None } } fn is_null_path(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 727058780752e..e43407fb1f836 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -86,7 +86,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); }, - ty::Dynamic(preds, _, _) => { + ty::Dynamic(preds, _) | ty::DynStar(preds, _) => { for pred in preds.iter() { match pred.skip_binder() { ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index c48d27b05f045..09c5575465296 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -276,7 +276,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } false }, - ty::Dynamic(binder, _, _) => { + ty::Dynamic(binder, _) | ty::DynStar(binder, _) => { for predicate in binder.iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) { @@ -654,7 +654,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(sig, None)), - ty::Dynamic(bounds, _, _) => { + ty::Dynamic(bounds, _) |ty::DynStar(bounds, _) => { let lang_items = cx.tcx.lang_items(); match bounds.principal() { Some(bound) diff --git a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs index bf655510a5ad8..1b2711e1046d7 100644 --- a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs +++ b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs @@ -28,6 +28,7 @@ fn main() { TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::DynStar(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::` diff --git a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr index 9f8c0bea0eeff..08d430d9f7e84 100644 --- a/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr +++ b/tests/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -103,83 +103,89 @@ LL | TyKind::Dynamic(..) => (), error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:31:9 | -LL | TyKind::Closure(..) => (), +LL | TyKind::DynStar(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:32:9 | -LL | TyKind::Generator(..) => (), +LL | TyKind::Closure(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:33:9 | -LL | TyKind::GeneratorWitness(..) => (), +LL | TyKind::Generator(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:34:9 | -LL | TyKind::GeneratorWitnessMIR(..) => (), +LL | TyKind::GeneratorWitness(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:35:9 | -LL | TyKind::Never => (), +LL | TyKind::GeneratorWitnessMIR(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:36:9 | -LL | TyKind::Tuple(..) => (), +LL | TyKind::Never => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:37:9 | -LL | TyKind::Alias(..) => (), +LL | TyKind::Tuple(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:38:9 | -LL | TyKind::Param(..) => (), +LL | TyKind::Alias(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:39:9 | -LL | TyKind::Bound(..) => (), +LL | TyKind::Param(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:40:9 | -LL | TyKind::Placeholder(..) => (), +LL | TyKind::Bound(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:41:9 | -LL | TyKind::Infer(..) => (), +LL | TyKind::Placeholder(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:42:9 | +LL | TyKind::Infer(..) => (), + | ^^^^^^ help: try using `ty::` directly: `ty` + +error: usage of `ty::TyKind::` + --> $DIR/ty_tykind_usage.rs:43:9 + | LL | TyKind::Error(_) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:47:12 + --> $DIR/ty_tykind_usage.rs:48:12 | LL | if let TyKind::Int(int_ty) = kind {} | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:49:24 + --> $DIR/ty_tykind_usage.rs:50:24 | LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} | ^^^^^^^^^^ @@ -187,7 +193,7 @@ LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} = help: try using `Ty` instead error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:51:37 + --> $DIR/ty_tykind_usage.rs:52:37 | LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { | ^^^^^^^^^^^ @@ -195,7 +201,7 @@ LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { = help: try using `Ty` instead error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:51:53 + --> $DIR/ty_tykind_usage.rs:52:53 | LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { | ^^^^^^^^^^^ @@ -203,12 +209,12 @@ LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { = help: try using `Ty` instead error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:54:9 + --> $DIR/ty_tykind_usage.rs:55:9 | LL | IrTyKind::Bool | --------^^^^^^ | | | help: try using `ty::` directly: `ty` -error: aborting due to 33 previous errors +error: aborting due to 34 previous errors diff --git a/tests/ui/dyn-star/no-implicit-dyn-star.stderr b/tests/ui/dyn-star/no-implicit-dyn-star.stderr index 66e1b9a092c36..8e18714d357ad 100644 --- a/tests/ui/dyn-star/no-implicit-dyn-star.stderr +++ b/tests/ui/dyn-star/no-implicit-dyn-star.stderr @@ -2,12 +2,12 @@ error[E0308]: mismatched types --> $DIR/no-implicit-dyn-star.rs:6:48 | LL | dyn_star_foreign::require_dyn_star_display(1usize); - | ------------------------------------------ ^^^^^^ expected `dyn Display`, found `usize` + | ------------------------------------------ ^^^^^^ expected `dyn* Display`, found `usize` | | | arguments to this function are incorrect | - = note: expected trait object `(dyn* std::fmt::Display + 'static)` - found type `usize` + = note: expected dyn* trait object `(dyn* std::fmt::Display + 'static)` + found type `usize` note: function defined here --> $DIR/auxiliary/dyn-star-foreign.rs:6:8 | diff --git a/tests/ui/symbol-names/basic.legacy.stderr b/tests/ui/symbol-names/basic.legacy.stderr index fe490a6000d7b..262d2e2abba59 100644 --- a/tests/ui/symbol-names/basic.legacy.stderr +++ b/tests/ui/symbol-names/basic.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN5basic4main17he9f658e438f1cac0E) +error: symbol-name(_ZN5basic4main17h3e65e1d718c4ae5dE) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(basic::main::he9f658e438f1cac0) +error: demangling(basic::main::h3e65e1d718c4ae5d) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] diff --git a/tests/ui/symbol-names/issue-60925.legacy.stderr b/tests/ui/symbol-names/issue-60925.legacy.stderr index 29b42f48d803a..d8bd3d9d1d5f5 100644 --- a/tests/ui/symbol-names/issue-60925.legacy.stderr +++ b/tests/ui/symbol-names/issue-60925.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h13209029be24b923E) +error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h1b7e17f9a390a4d8E) --> $DIR/issue-60925.rs:21:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(issue_60925::foo::Foo::foo::h13209029be24b923) +error: demangling(issue_60925::foo::Foo::foo::h1b7e17f9a390a4d8) --> $DIR/issue-60925.rs:21:9 | LL | #[rustc_symbol_name]