diff --git a/compiler/rustc_const_eval/src/const_eval/type_info.rs b/compiler/rustc_const_eval/src/const_eval/type_info.rs index 3fcf6f94b5bf3..f757070b0c426 100644 --- a/compiler/rustc_const_eval/src/const_eval/type_info.rs +++ b/compiler/rustc_const_eval/src/const_eval/type_info.rs @@ -3,7 +3,8 @@ use rustc_ast::Mutability; use rustc_hir::LangItem; use rustc_middle::span_bug; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{self, Const, ScalarInt, Ty}; +use rustc_middle::ty::{self, Const, Region, ScalarInt, Ty}; +use rustc_span::def_id::DefId; use rustc_span::{Symbol, sym}; use crate::const_eval::CompileTimeMachine; @@ -129,13 +130,18 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { variant } + ty::Dynamic(predicates, region) => { + let (variant, variant_place) = downcast(sym::DynTrait)?; + let dyn_place = self.project_field(&variant_place, FieldIdx::ZERO)?; + self.write_dyn_trait_type_info(dyn_place, *predicates, *region)?; + variant + } ty::Adt(_, _) | ty::Foreign(_) | ty::Pat(_, _) | ty::FnDef(..) | ty::FnPtr(..) | ty::UnsafeBinder(..) - | ty::Dynamic(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) @@ -174,6 +180,175 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> { interp_ok(()) } + fn write_dyn_trait_type_info( + &mut self, + dyn_place: impl Writeable<'tcx, CtfeProvenance>, + data: &'tcx ty::List>>, + region: Region<'tcx>, + ) -> InterpResult<'tcx> { + let tcx = self.tcx.tcx; + + // Find the principal trait ref (for super trait collection), collect auto traits, + // and collect all projection predicates (used when computing TypeId for each supertrait). + let mut principal: Option>> = None; + let mut auto_traits_def_ids: Vec> = Vec::new(); + let mut projections: Vec>> = Vec::new(); + + for b in data.iter() { + match b.skip_binder() { + ty::ExistentialPredicate::Trait(tr) => principal = Some(b.rebind(tr)), + ty::ExistentialPredicate::AutoTrait(did) => auto_traits_def_ids.push(b.rebind(did)), + ty::ExistentialPredicate::Projection(p) => projections.push(b.rebind(p)), + } + } + + // This is to make principal dyn type include Trait and projection predicates, excluding auto traits. + let principal_ty: Option> = principal.map(|_tr| { + let preds = tcx + .mk_poly_existential_predicates_from_iter(data.iter().filter(|b| { + !matches!(b.skip_binder(), ty::ExistentialPredicate::AutoTrait(_)) + })); + Ty::new_dynamic(tcx, preds, region) + }); + + // DynTrait { predicates: &'static [Trait] } + for (field_idx, field) in + dyn_place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated() + { + let field_place = self.project_field(&dyn_place, field_idx)?; + match field.name { + sym::predicates => { + self.write_dyn_trait_predicates_slice( + &field_place, + principal_ty, + &auto_traits_def_ids, + region, + )?; + } + other => { + span_bug!(self.tcx.def_span(field.did), "unimplemented DynTrait field {other}") + } + } + } + + interp_ok(()) + } + + fn mk_dyn_principal_auto_trait_ty( + &self, + auto_trait_def_id: ty::Binder<'tcx, DefId>, + region: Region<'tcx>, + ) -> Ty<'tcx> { + let tcx = self.tcx.tcx; + + // Preserve the binder vars from the original auto-trait predicate. + let pred_inner = ty::ExistentialPredicate::AutoTrait(auto_trait_def_id.skip_binder()); + let pred = ty::Binder::bind_with_vars(pred_inner, auto_trait_def_id.bound_vars()); + + let preds = tcx.mk_poly_existential_predicates_from_iter([pred].into_iter()); + Ty::new_dynamic(tcx, preds, region) + } + + fn write_dyn_trait_predicates_slice( + &mut self, + slice_place: &impl Writeable<'tcx, CtfeProvenance>, + principal_ty: Option>, + auto_trait_def_ids: &[ty::Binder<'tcx, DefId>], + region: Region<'tcx>, + ) -> InterpResult<'tcx> { + let tcx = self.tcx.tcx; + + // total entries in DynTrait predicates + let total_len = principal_ty.map(|_| 1).unwrap_or(0) + auto_trait_def_ids.len(); + + // element type = DynTraitPredicate + let slice_ty = slice_place.layout().ty.builtin_deref(false).unwrap(); // [DynTraitPredicate] + let elem_ty = slice_ty.sequence_element_type(tcx); // DynTraitPredicate + + let arr_layout = self.layout_of(Ty::new_array(tcx, elem_ty, total_len as u64))?; + let arr_place = self.allocate(arr_layout, MemoryKind::Stack)?; + let mut elems = self.project_array_fields(&arr_place)?; + + // principal entry (if any) - NOT an auto trait + if let Some(principal_ty) = principal_ty { + let Some((_i, elem_place)) = elems.next(self)? else { + span_bug!(self.tcx.span, "DynTrait.predicates length computed wrong (principal)"); + }; + self.write_dyn_trait_predicate(elem_place, principal_ty, false)?; + } + + // auto trait entries - these ARE auto traits + for auto in auto_trait_def_ids { + let Some((_i, elem_place)) = elems.next(self)? else { + span_bug!(self.tcx.span, "DynTrait.predicates length computed wrong (auto)"); + }; + let auto_ty = self.mk_dyn_principal_auto_trait_ty(*auto, region); + self.write_dyn_trait_predicate(elem_place, auto_ty, true)?; + } + + let arr_place = arr_place.map_provenance(CtfeProvenance::as_immutable); + let imm = Immediate::new_slice(arr_place.ptr(), total_len as u64, self); + self.write_immediate(imm, slice_place) + } + + fn write_dyn_trait_predicate( + &mut self, + predicate_place: MPlaceTy<'tcx>, + trait_ty: Ty<'tcx>, + is_auto: bool, + ) -> InterpResult<'tcx> { + // DynTraitPredicate { trait_ty: Trait } + for (field_idx, field) in predicate_place + .layout + .ty + .ty_adt_def() + .unwrap() + .non_enum_variant() + .fields + .iter_enumerated() + { + let field_place = self.project_field(&predicate_place, field_idx)?; + match field.name { + sym::trait_ty => { + // Now write the Trait struct + self.write_trait(field_place, trait_ty, is_auto)?; + } + other => { + span_bug!( + self.tcx.def_span(field.did), + "unimplemented DynTraitPredicate field {other}" + ) + } + } + } + interp_ok(()) + } + fn write_trait( + &mut self, + trait_place: MPlaceTy<'tcx>, + trait_ty: Ty<'tcx>, + is_auto: bool, + ) -> InterpResult<'tcx> { + // Trait { ty: TypeId, is_auto: bool } + for (field_idx, field) in + trait_place.layout.ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated() + { + let field_place = self.project_field(&trait_place, field_idx)?; + match field.name { + sym::ty => { + self.write_type_id(trait_ty, &field_place)?; + } + sym::is_auto => { + self.write_scalar(Scalar::from_bool(is_auto), &field_place)?; + } + other => { + span_bug!(self.tcx.def_span(field.did), "unimplemented Trait field {other}") + } + } + } + interp_ok(()) + } + pub(crate) fn write_tuple_fields( &mut self, tuple_place: impl Writeable<'tcx, CtfeProvenance>, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5767444025ec2..e8b805e03b631 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -186,6 +186,7 @@ symbols! { AtomicU64, AtomicU128, AtomicUsize, + AutoTrait, BTreeEntry, BTreeMap, BTreeSet, @@ -231,6 +232,7 @@ symbols! { Display, DoubleEndedIterator, Duration, + DynTrait, Encodable, Encoder, Enumerate, @@ -1295,6 +1297,7 @@ symbols! { io_stdout, irrefutable_let_patterns, is, + is_auto, is_val_statically_known, isa_attribute, isize, @@ -1748,6 +1751,7 @@ symbols! { precise_capturing_in_traits, precise_pointer_size_matching, precision, + predicates, pref_align_of, prefetch_read_data, prefetch_read_instruction, @@ -2293,6 +2297,7 @@ symbols! { trace_macros, track_caller, trait_alias, + trait_ty, trait_upcasting, transmute, transmute_generic_consts, diff --git a/library/core/src/mem/type_info.rs b/library/core/src/mem/type_info.rs index 30a70165b095f..8b30803c97c98 100644 --- a/library/core/src/mem/type_info.rs +++ b/library/core/src/mem/type_info.rs @@ -47,6 +47,8 @@ pub enum TypeKind { Array(Array), /// Slices. Slice(Slice), + /// Dynamic Traits. + DynTrait(DynTrait), /// Primitive boolean type. Bool(Bool), /// Primitive character type. @@ -105,6 +107,36 @@ pub struct Slice { pub element_ty: TypeId, } +/// Compile-time type information about dynamic traits. +/// FIXME(#146922): Add super traits and generics +#[derive(Debug)] +#[non_exhaustive] +#[unstable(feature = "type_info", issue = "146922")] +pub struct DynTrait { + /// The predicates of a dynamic trait. + pub predicates: &'static [DynTraitPredicate], +} + +/// Compile-time type information about a dynamic trait predicate. +#[derive(Debug)] +#[non_exhaustive] +#[unstable(feature = "type_info", issue = "146922")] +pub struct DynTraitPredicate { + /// The type of the trait as a dynamic trait type. + pub trait_ty: Trait, +} + +/// Compile-time type information about a trait. +#[derive(Debug)] +#[non_exhaustive] +#[unstable(feature = "type_info", issue = "146922")] +pub struct Trait { + /// The TypeId of the trait as a dynamic type + pub ty: TypeId, + /// Whether the trait is an auto trait + pub is_auto: bool, +} + /// Compile-time type information about `bool`. #[derive(Debug)] #[non_exhaustive] diff --git a/library/coretests/tests/mem/type_info.rs b/library/coretests/tests/mem/type_info.rs index 0820e4f839930..87f2d5dd8289c 100644 --- a/library/coretests/tests/mem/type_info.rs +++ b/library/coretests/tests/mem/type_info.rs @@ -163,3 +163,132 @@ fn test_pointers() { _ => unreachable!(), } } + +#[test] +fn test_dynamic_traits() { + use std::collections::HashSet; + use std::mem::type_info::DynTraitPredicate; + trait A {} + + trait B { + type Foo; + } + + trait FooTrait<'a, 'b, const CONST_NUM: i32> {} + + trait ProjectorTrait<'a, 'b> {} + + fn preds_of() -> &'static [DynTraitPredicate] { + match const { Type::of::() }.kind { + TypeKind::DynTrait(d) => d.predicates, + _ => unreachable!(), + } + } + + fn pred<'a>(preds: &'a [DynTraitPredicate], want: TypeId) -> &'a DynTraitPredicate { + preds + .iter() + .find(|p| p.trait_ty.ty == want) + .unwrap_or_else(|| panic!("missing predicate for {want:?}")) + } + + fn assert_typeid_set_eq(actual: &[TypeId], expected: &[TypeId]) { + let actual_set: HashSet = actual.iter().copied().collect(); + let expected_set: HashSet = expected.iter().copied().collect(); + assert_eq!(actual.len(), actual_set.len(), "duplicates present: {actual:?}"); + assert_eq!( + actual_set, expected_set, + "unexpected ids.\nactual: {actual:?}\nexpected: {expected:?}" + ); + } + + fn assert_predicates_exact(preds: &[DynTraitPredicate], expected_pred_ids: &[TypeId]) { + let actual_pred_ids: Vec = preds.iter().map(|p| p.trait_ty.ty).collect(); + assert_typeid_set_eq(&actual_pred_ids, expected_pred_ids); + } + + // dyn Send + { + let preds = preds_of::(); + assert_predicates_exact(preds, &[TypeId::of::()]); + + let p = pred(preds, TypeId::of::()); + assert!(p.trait_ty.is_auto); + } + + // dyn A + { + let preds = preds_of::>(); + assert_predicates_exact(preds, &[TypeId::of::>()]); + + let p = pred(preds, TypeId::of::>()); + assert!(!p.trait_ty.is_auto); + } + + // dyn B<5, Foo = i32> + { + let preds = preds_of::>(); + assert_predicates_exact(preds, &[TypeId::of::>()]); + + let e = pred(preds, TypeId::of::>()); + assert!(!e.trait_ty.is_auto); + } + + // dyn for<'a> FooTrait<'a, 'a, 7> + { + let preds = preds_of:: FooTrait<'a, 'a, 7>>(); + assert_predicates_exact(preds, &[TypeId::of:: FooTrait<'a, 'a, 7>>()]); + + let foo = pred(preds, TypeId::of:: FooTrait<'a, 'a, 7>>()); + assert!(!foo.trait_ty.is_auto); + } + + // dyn FooTrait<'static, 'static, 7> + { + let preds = preds_of::>(); + assert_predicates_exact(preds, &[TypeId::of::>()]); + + let foo = pred(preds, TypeId::of::>()); + assert!(!foo.trait_ty.is_auto); + } + + // dyn for<'a, 'b> FooTrait<'a, 'b, 7> + { + let preds = preds_of:: FooTrait<'a, 'b, 7>>(); + assert_predicates_exact(preds, &[TypeId::of:: FooTrait<'a, 'b, 7>>()]); + + let foo = pred(preds, TypeId::of:: FooTrait<'a, 'b, 7>>()); + assert!(!foo.trait_ty.is_auto); + } + + // dyn for<'a, 'b> ProjectorTrait<'a, 'b> + { + let preds = preds_of:: ProjectorTrait<'a, 'b>>(); + assert_predicates_exact(preds, &[TypeId::of:: ProjectorTrait<'a, 'b>>()]); + + let proj = pred(preds, TypeId::of:: ProjectorTrait<'a, 'b>>()); + assert!(!proj.trait_ty.is_auto); + } + + // dyn for<'a> FooTrait<'a, 'a, 7> + Send + Sync + { + let preds = preds_of:: FooTrait<'a, 'a, 7> + Send + Sync>(); + assert_predicates_exact( + preds, + &[ + TypeId::of:: FooTrait<'a, 'a, 7>>(), + TypeId::of::(), + TypeId::of::(), + ], + ); + + let foo = pred(preds, TypeId::of:: FooTrait<'a, 'a, 7>>()); + assert!(!foo.trait_ty.is_auto); + + let send = pred(preds, TypeId::of::()); + assert!(send.trait_ty.is_auto); + + let sync = pred(preds, TypeId::of::()); + assert!(sync.trait_ty.is_auto); + } +} diff --git a/tests/run-make/crate-loading/multiple-dep-versions.stderr b/tests/run-make/crate-loading/multiple-dep-versions.stderr index f8f8bfaaff6f5..ef7fb70822665 100644 --- a/tests/run-make/crate-loading/multiple-dep-versions.stderr +++ b/tests/run-make/crate-loading/multiple-dep-versions.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied +error[E0277]: the trait bound `dep_2_reexport::Type: dependency::Trait` is not satisfied --> replaced | LL | do_something(Type); - | ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type` + | ------------ ^^^^ the trait `dependency::Trait` is not implemented for `dep_2_reexport::Type` | | | required by a bound introduced by this call | @@ -17,7 +17,7 @@ LL | pub trait Trait { LL | pub trait Trait { | --------------- this is the found trait = help: you can use `cargo tree` to explore your dependency tree -help: the trait `Trait` is implemented for `dependency::Type` +help: the trait `dependency::Trait` is implemented for `dependency::Type` --> replaced | LL | impl Trait for Type { @@ -64,11 +64,11 @@ LL | pub trait Trait { | --------------- this is the trait that was imported = help: you can use `cargo tree` to explore your dependency tree -error[E0277]: the trait bound `OtherType: Trait` is not satisfied +error[E0277]: the trait bound `OtherType: dependency::Trait` is not satisfied --> replaced | LL | do_something(OtherType); - | ------------ ^^^^^^^^^ the trait `Trait` is not implemented for `OtherType` + | ------------ ^^^^^^^^^ the trait `dependency::Trait` is not implemented for `OtherType` | | | required by a bound introduced by this call | @@ -83,7 +83,7 @@ LL | pub trait Trait { LL | pub trait Trait { | --------------- this is the found trait = help: you can use `cargo tree` to explore your dependency tree -help: the trait `Trait` is implemented for `dependency::Type` +help: the trait `dependency::Trait` is implemented for `dependency::Type` --> replaced | LL | impl Trait for Type { diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.not-diag-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.not-diag-in-deps.stderr index 234e251b2ad8d..08c850cd8e24e 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.not-diag-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.not-diag-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> $DIR/auxiliary/trait.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.only-debuginfo-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.only-debuginfo-in-deps.stderr index 3b0d66e75e86e..ebd7606815d07 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.only-debuginfo-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.only-debuginfo-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> $DIR/auxiliary/trait-debuginfo.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.only-diag-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.only-diag-in-deps.stderr index 86c1140573e3c..c21d49e325e22 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.only-diag-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.only-diag-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> remapped/errors/auxiliary/trait-diag.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.only-macro-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.only-macro-in-deps.stderr index 91c9cd90152bf..9a0676ca0ea94 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.only-macro-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.only-macro-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> $DIR/auxiliary/trait-macro.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.with-debuginfo-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.with-debuginfo-in-deps.stderr index 3b0d66e75e86e..ebd7606815d07 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.with-debuginfo-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.with-debuginfo-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> $DIR/auxiliary/trait-debuginfo.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.with-diag-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.with-diag-in-deps.stderr index 00a647df61f9f..688db94a97535 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.with-diag-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.with-diag-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> remapped/errors/auxiliary/trait-diag.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/errors/remap-path-prefix-diagnostics.with-macro-in-deps.stderr b/tests/ui/errors/remap-path-prefix-diagnostics.with-macro-in-deps.stderr index 91c9cd90152bf..9a0676ca0ea94 100644 --- a/tests/ui/errors/remap-path-prefix-diagnostics.with-macro-in-deps.stderr +++ b/tests/ui/errors/remap-path-prefix-diagnostics.with-macro-in-deps.stderr @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `A` | LL | struct A; | ^^^^^^^^ -note: required by a bound in `Trait` +note: required by a bound in `r#trait::Trait` --> $DIR/auxiliary/trait-macro.rs:LL:COL | LL | pub trait Trait: std::fmt::Display {} diff --git a/tests/ui/privacy/private-inferred-type.rs b/tests/ui/privacy/private-inferred-type.rs index 8c07226fe0e4d..ed22ad44c4497 100644 --- a/tests/ui/privacy/private-inferred-type.rs +++ b/tests/ui/privacy/private-inferred-type.rs @@ -115,11 +115,11 @@ fn main() { m::m!(); - m::leak_anon1(); //~ ERROR trait `Trait` is private + m::leak_anon1(); //~ ERROR trait `m::Trait` is private m::leak_anon2(); //~ ERROR type `Priv` is private m::leak_anon3(); //~ ERROR type `Priv` is private - m::leak_dyn1(); //~ ERROR trait `Trait` is private + m::leak_dyn1(); //~ ERROR trait `m::Trait` is private m::leak_dyn2(); //~ ERROR type `Priv` is private m::leak_dyn3(); //~ ERROR type `Priv` is private diff --git a/tests/ui/privacy/private-inferred-type.stderr b/tests/ui/privacy/private-inferred-type.stderr index fc3f9ab62bfa9..0dfa799a4d95d 100644 --- a/tests/ui/privacy/private-inferred-type.stderr +++ b/tests/ui/privacy/private-inferred-type.stderr @@ -172,7 +172,7 @@ LL | m::m!(); | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) -error: trait `Trait` is private +error: trait `m::Trait` is private --> $DIR/private-inferred-type.rs:118:5 | LL | m::leak_anon1(); @@ -190,7 +190,7 @@ error: type `Priv` is private LL | m::leak_anon3(); | ^^^^^^^^^^^^^^^ private type -error: trait `Trait` is private +error: trait `m::Trait` is private --> $DIR/private-inferred-type.rs:122:5 | LL | m::leak_dyn1(); diff --git a/tests/ui/trait-bounds/suggest-maybe-sized-bound.stderr b/tests/ui/trait-bounds/suggest-maybe-sized-bound.stderr index 4ce936582f43d..b459ad47e067a 100644 --- a/tests/ui/trait-bounds/suggest-maybe-sized-bound.stderr +++ b/tests/ui/trait-bounds/suggest-maybe-sized-bound.stderr @@ -22,7 +22,7 @@ LL | type P = [u8]; | ^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: required by a bound in `Trait::P` +note: required by a bound in `main::Trait::P` --> $DIR/suggest-maybe-sized-bound.rs:13:9 | LL | type P; diff --git a/tests/ui/traits/bound/on-structs-and-enums-xc.stderr b/tests/ui/traits/bound/on-structs-and-enums-xc.stderr index 5064b60bfd579..472ac187a9666 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-xc.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-xc.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `usize: Trait` is not satisfied +error[E0277]: the trait bound `usize: on_structs_and_enums_xc::Trait` is not satisfied --> $DIR/on-structs-and-enums-xc.rs:7:15 | LL | fn explode(x: Foo) {} - | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize` + | ^^^^^^^^^^ the trait `on_structs_and_enums_xc::Trait` is not implemented for `usize` | note: required by a bound in `Foo` --> $DIR/auxiliary/on_structs_and_enums_xc.rs:5:18 @@ -10,11 +10,11 @@ note: required by a bound in `Foo` LL | pub struct Foo { | ^^^^^ required by this bound in `Foo` -error[E0277]: the trait bound `f32: Trait` is not satisfied +error[E0277]: the trait bound `f32: on_structs_and_enums_xc::Trait` is not satisfied --> $DIR/on-structs-and-enums-xc.rs:10:14 | LL | fn kaboom(y: Bar) {} - | ^^^^^^^^ the trait `Trait` is not implemented for `f32` + | ^^^^^^^^ the trait `on_structs_and_enums_xc::Trait` is not implemented for `f32` | note: required by a bound in `Bar` --> $DIR/auxiliary/on_structs_and_enums_xc.rs:9:16 diff --git a/tests/ui/traits/bound/on-structs-and-enums-xc1.stderr b/tests/ui/traits/bound/on-structs-and-enums-xc1.stderr index 1f46415e24369..5cf682a5045e8 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-xc1.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-xc1.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `{integer}: Trait` is not satisfied +error[E0277]: the trait bound `{integer}: on_structs_and_enums_xc::Trait` is not satisfied --> $DIR/on-structs-and-enums-xc1.rs:9:12 | LL | x: 3 - | ^ the trait `Trait` is not implemented for `{integer}` + | ^ the trait `on_structs_and_enums_xc::Trait` is not implemented for `{integer}` | note: required by a bound in `Foo` --> $DIR/auxiliary/on_structs_and_enums_xc.rs:5:18 @@ -10,11 +10,11 @@ note: required by a bound in `Foo` LL | pub struct Foo { | ^^^^^ required by this bound in `Foo` -error[E0277]: the trait bound `f64: Trait` is not satisfied +error[E0277]: the trait bound `f64: on_structs_and_enums_xc::Trait` is not satisfied --> $DIR/on-structs-and-enums-xc1.rs:12:14 | LL | let bar: Bar = return; - | ^^^^^^^^ the trait `Trait` is not implemented for `f64` + | ^^^^^^^^ the trait `on_structs_and_enums_xc::Trait` is not implemented for `f64` | note: required by a bound in `Bar` --> $DIR/auxiliary/on_structs_and_enums_xc.rs:9:16 diff --git a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs index ec6bb7bbcc594..35465183001a1 100644 --- a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs +++ b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs @@ -5,8 +5,8 @@ // Issue #148892. //@ aux-crate:crate1=crate1.rs -struct MyStruct; //~ HELP the trait `Trait` is not implemented for `MyStruct` +struct MyStruct; //~ HELP the trait `crate1::Trait` is not implemented for `MyStruct` fn main() { - crate1::foo(MyStruct); //~ ERROR the trait bound `MyStruct: Trait` is not satisfied + crate1::foo(MyStruct); //~ ERROR the trait bound `MyStruct: crate1::Trait` is not satisfied } diff --git a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr index 7fec237f54d43..5bcda9f2a95b8 100644 --- a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr +++ b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `MyStruct: Trait` is not satisfied +error[E0277]: the trait bound `MyStruct: crate1::Trait` is not satisfied --> $DIR/wrong-multiple-different-versions-of-a-crate.rs:11:17 | LL | crate1::foo(MyStruct); @@ -6,7 +6,7 @@ LL | crate1::foo(MyStruct); | | | required by a bound introduced by this call | -help: the trait `Trait` is not implemented for `MyStruct` +help: the trait `crate1::Trait` is not implemented for `MyStruct` --> $DIR/wrong-multiple-different-versions-of-a-crate.rs:8:1 | LL | struct MyStruct; diff --git a/tests/ui/unresolved/unresolved-candidates.stderr b/tests/ui/unresolved/unresolved-candidates.stderr index 55b9d8ec6e8fc..7d8e894a55826 100644 --- a/tests/ui/unresolved/unresolved-candidates.stderr +++ b/tests/ui/unresolved/unresolved-candidates.stderr @@ -4,8 +4,10 @@ error[E0432]: unresolved import `Trait` LL | use Trait; | ^^^^^ no `Trait` in the root | -help: consider importing this trait instead +help: consider importing one of these items instead | +LL | use std::mem::type_info::Trait; + | +++++++++++++++++++++ LL | use a::Trait; | +++ diff --git a/tests/ui/unstable-feature-bound/unstable_impl_coherence.disabled.stderr b/tests/ui/unstable-feature-bound/unstable_impl_coherence.disabled.stderr index afef024e1b9c1..60bb2117df24c 100644 --- a/tests/ui/unstable-feature-bound/unstable_impl_coherence.disabled.stderr +++ b/tests/ui/unstable-feature-bound/unstable_impl_coherence.disabled.stderr @@ -1,11 +1,11 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `LocalTy` +error[E0119]: conflicting implementations of trait `aux::Trait` for type `LocalTy` --> $DIR/unstable_impl_coherence.rs:14:1 | LL | impl aux::Trait for LocalTy {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: conflicting implementation in crate `unstable_impl_coherence_aux`: - - impl Trait for T + - impl aux::Trait for T where feature(foo) is enabled; error: aborting due to 1 previous error diff --git a/tests/ui/unstable-feature-bound/unstable_impl_coherence.enabled.stderr b/tests/ui/unstable-feature-bound/unstable_impl_coherence.enabled.stderr index afef024e1b9c1..60bb2117df24c 100644 --- a/tests/ui/unstable-feature-bound/unstable_impl_coherence.enabled.stderr +++ b/tests/ui/unstable-feature-bound/unstable_impl_coherence.enabled.stderr @@ -1,11 +1,11 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `LocalTy` +error[E0119]: conflicting implementations of trait `aux::Trait` for type `LocalTy` --> $DIR/unstable_impl_coherence.rs:14:1 | LL | impl aux::Trait for LocalTy {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: conflicting implementation in crate `unstable_impl_coherence_aux`: - - impl Trait for T + - impl aux::Trait for T where feature(foo) is enabled; error: aborting due to 1 previous error diff --git a/tests/ui/unstable-feature-bound/unstable_impl_coherence.rs b/tests/ui/unstable-feature-bound/unstable_impl_coherence.rs index 22100f85f715b..c36316dc5fa1b 100644 --- a/tests/ui/unstable-feature-bound/unstable_impl_coherence.rs +++ b/tests/ui/unstable-feature-bound/unstable_impl_coherence.rs @@ -12,6 +12,6 @@ use aux::Trait; struct LocalTy; impl aux::Trait for LocalTy {} -//~^ ERROR: conflicting implementations of trait `Trait` for type `LocalTy` +//~^ ERROR: conflicting implementations of trait `aux::Trait` for type `LocalTy` fn main(){} diff --git a/tests/ui/unstable-feature-bound/unstable_impl_method_selection.stderr b/tests/ui/unstable-feature-bound/unstable_impl_method_selection.stderr index 840af730154d9..b2e4eb730d84e 100644 --- a/tests/ui/unstable-feature-bound/unstable_impl_method_selection.stderr +++ b/tests/ui/unstable-feature-bound/unstable_impl_method_selection.stderr @@ -4,9 +4,9 @@ error[E0283]: type annotations needed LL | vec![].foo(); | ^^^ cannot infer type for struct `Vec<_>` | - = note: multiple `impl`s satisfying `Vec<_>: Trait` found in the `unstable_impl_method_selection_aux` crate: - - impl Trait for Vec; - - impl Trait for Vec + = note: multiple `impl`s satisfying `Vec<_>: aux::Trait` found in the `unstable_impl_method_selection_aux` crate: + - impl aux::Trait for Vec; + - impl aux::Trait for Vec where feature(bar) is enabled; error: aborting due to 1 previous error diff --git a/tests/ui/use/issue-18986.stderr b/tests/ui/use/issue-18986.stderr index 350cb18f95272..084fa80c3b6d3 100644 --- a/tests/ui/use/issue-18986.stderr +++ b/tests/ui/use/issue-18986.stderr @@ -3,6 +3,11 @@ error[E0574]: expected struct, variant or union type, found trait `Trait` | LL | Trait { x: 42 } => () | ^^^^^ not a struct, variant or union type + | +help: consider importing this struct instead + | +LL + use std::mem::type_info::Trait; + | error: aborting due to 1 previous error