diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 292643d6d7510..8736ebb8aa179 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1477,15 +1477,12 @@ impl<'hir> LoweringContext<'_, 'hir> { ImplTraitContext::disallowed(), ), bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()), - bounds: this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| { - match *bound { - // Ignore `?Trait` bounds. - // They were copied into type parameters already. - GenericBound::Trait(_, TraitBoundModifier::Maybe) => None, - _ => Some( - this.lower_param_bound(bound, ImplTraitContext::disallowed()), - ), - } + bounds: this.arena.alloc_from_iter(bounds.iter().map(|bound| { + // We used to ignore `?Trait` bounds, as they were copied into type + // parameters already, but we need to keep them around only for + // diagnostics when we suggest removal of `?Sized` bounds. See + // `suggest_constraining_type_param`. + this.lower_param_bound(bound, ImplTraitContext::disallowed()) })), span, }) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fb762d2deba7c..39d6f0270681c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1428,6 +1428,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { secondary_span: Option<(Span, String)>, mut values: Option>, terr: &TypeError<'tcx>, + swap_secondary_and_primary: bool, ) { let span = cause.span(self.tcx); debug!("note_type_err cause={:?} values={:?}, terr={:?}", cause, values, terr); @@ -1582,9 +1583,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { match terr { TypeError::ObjectUnsafeCoercion(_) => {} _ => { - diag.span_label(span, terr.to_string()); if let Some((sp, msg)) = secondary_span { - diag.span_label(sp, msg); + if swap_secondary_and_primary { + let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound { + expected, + .. + })) = values + { + format!("expected this to be `{}`", expected) + } else { + terr.to_string() + }; + diag.span_label(sp, terr); + diag.span_label(span, msg); + } else { + diag.span_label(span, terr.to_string()); + diag.span_label(sp, msg); + } + } else { + diag.span_label(span, terr.to_string()); } } }; @@ -1971,7 +1988,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { struct_span_err!(self.tcx.sess, span, E0644, "{}", failure_str) } }; - self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr); + self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false); diag } diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index 2710debea9478..cde9b82df503b 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -27,14 +27,10 @@ pub trait TraitEngine<'tcx>: 'tcx { cause: ObligationCause<'tcx>, ) { let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }; + let predicate = trait_ref.without_const().to_predicate(infcx.tcx); self.register_predicate_obligation( infcx, - Obligation { - cause, - recursion_depth: 0, - param_env, - predicate: trait_ref.without_const().to_predicate(infcx.tcx), - }, + Obligation { cause, recursion_depth: 0, param_env, predicate }, ); } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 1cde4802a40b0..fe6db395a8e87 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -124,7 +124,7 @@ impl Elaborator<'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index e632f29e672c0..96a92965a34e5 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { let predicates = cx.tcx.explicit_predicates_of(item.def_id); for &(predicate, span) in predicates.predicates { let trait_predicate = match predicate.kind().skip_binder() { - Trait(trait_predicate, _constness) => trait_predicate, + Trait(trait_predicate, _constness, _) => trait_predicate, _ => continue, }; let def_id = trait_predicate.trait_ref.def_id; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 44c2a550c30e2..befebeca731c0 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -202,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { let mut has_emitted = false; for &(predicate, _) in cx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _, _) = predicate.kind().skip_binder() { let def_id = poly_trait_predicate.trait_ref.def_id; diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index c9b73c682098b..de560e31eb458 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -195,6 +195,9 @@ pub enum ObligationCauseCode<'tcx> { /// Like `ItemObligation`, but with extra detail on the source of the obligation. BindingObligation(DefId, Span), + /// Like `ItemObligation`, but with extra detail on the source of the obligation. + ImplicitSizedObligation(DefId, Span), + /// A type like `&'a T` is WF only if `T: 'a`. ReferenceOutlivesReferent(Ty<'tcx>), diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index d005f63ed4383..045b5ae96092e 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -58,9 +58,44 @@ impl AssocItem { // regions just fine, showing `fn(&MyType)`. tcx.fn_sig(self.def_id).skip_binder().to_string() } - ty::AssocKind::Type => format!("type {};", self.ident), + ty::AssocKind::Type => { + let default = match tcx.hir().get_if_local(self.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(_, Some(ty)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(ty), + .. + }), + ) => { + format!(" = {:?}", ty) + } + _ => String::new(), + }; + format!("type {}{};", self.ident, default) + } ty::AssocKind::Const => { - format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id)) + let default = match tcx.hir().get_if_local(self.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Const(_, Some(body_id)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Const(_, body_id), + .. + }), + ) => match tcx.hir().find(body_id.hir_id) { + Some(value) => { + format!(" = {:?}", value) + } + None => String::new(), + }, + _ => String::new(), + }; + format!("const {}: {:?}{};", self.ident, tcx.type_of(self.def_id), default) } } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d13cbdd122854..20052ff2861e8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2097,7 +2097,7 @@ impl<'tcx> TyCtxt<'tcx> { let generic_predicates = self.super_predicates_of(trait_did); for (predicate, _) in generic_predicates.predicates { - if let ty::PredicateKind::Trait(data, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(data, ..) = predicate.kind().skip_binder() { if set.insert(data.def_id()) { stack.push(data.def_id()); } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 982c8a354b4ab..b02f8847e337a 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -2,6 +2,7 @@ use crate::ty::TyKind::*; use crate::ty::{InferTy, TyCtxt, TyS}; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -130,6 +131,121 @@ pub fn suggest_constraining_type_param( if def_id == tcx.lang_items().sized_trait() { // Type parameters are already `Sized` by default. err.span_label(param.span, &format!("this type parameter needs to be `{}`", constraint)); + // See if there's a `?Sized` bound that can be removed to suggest that. + match param.bounds { + [] => {} + bounds => { + // First look at the `where` clause because we can have `where T: ?Sized`, but that + // `?Sized` bound is *also* included in the `GenericParam` as a bound, which breaks + // the spans. Hence the somewhat involved logic that follows. + let mut where_unsized_bounds = FxHashSet::default(); + for (where_pos, predicate) in generics.where_clause.predicates.iter().enumerate() { + match predicate { + WherePredicate::BoundPredicate(WhereBoundPredicate { + bounded_ty: + hir::Ty { + kind: + hir::TyKind::Path(hir::QPath::Resolved( + None, + hir::Path { + segments: [segment], + res: + hir::def::Res::Def(hir::def::DefKind::TyParam, _), + .. + }, + )), + .. + }, + bounds, + span, + .. + }) if segment.ident.as_str() == param_name => { + for (pos, bound) in bounds.iter().enumerate() { + match bound { + hir::GenericBound::Trait( + poly, + hir::TraitBoundModifier::Maybe, + ) if poly.trait_ref.trait_def_id() == def_id => { + let sp = match ( + bounds.len(), + pos, + generics.where_clause.predicates.len(), + where_pos, + ) { + // where T: ?Sized + // ^^^^^^^^^^^^^^^ + (1, _, 1, _) => generics.where_clause.span, + // where Foo: Bar, T: ?Sized, + // ^^^^^^^^^^^ + (1, _, len, pos) if pos == len - 1 => { + generics.where_clause.predicates[pos - 1] + .span() + .shrink_to_hi() + .to(*span) + } + // where T: ?Sized, Foo: Bar, + // ^^^^^^^^^^^ + (1, _, _, pos) => span.until( + generics.where_clause.predicates[pos + 1].span(), + ), + // where T: ?Sized + Bar, Foo: Bar, + // ^^^^^^^^^ + (_, 0, _, _) => { + bound.span().to(bounds[1].span().shrink_to_lo()) + } + // where T: Bar + ?Sized, Foo: Bar, + // ^^^^^^^^^ + (_, pos, _, _) => bounds[pos - 1] + .span() + .shrink_to_hi() + .to(bound.span()), + }; + where_unsized_bounds.insert(bound.span()); + err.span_suggestion_verbose( + sp, + "consider removing the `?Sized` bound to make the \ + type parameter `Sized`", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } + } + } + _ => {} + } + } + for (pos, bound) in bounds.iter().enumerate() { + match bound { + hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) + if poly.trait_ref.trait_def_id() == def_id + && !where_unsized_bounds.contains(&bound.span()) => + { + let sp = match (bounds.len(), pos) { + // T: ?Sized, + // ^^^^^^^^ + (1, _) => param.span.shrink_to_hi().to(bound.span()), + // T: ?Sized + Bar, + // ^^^^^^^^^ + (_, 0) => bound.span().to(bounds[1].span().shrink_to_lo()), + // T: Bar + ?Sized, + // ^^^^^^^^^ + (_, pos) => bounds[pos - 1].span().shrink_to_hi().to(bound.span()), + }; + err.span_suggestion_verbose( + sp, + "consider removing the `?Sized` bound to make the type parameter \ + `Sized`", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } + } + } + } return true; } let mut suggest_restrict = |span| { diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 96aae3bd70cd2..b82f760ff4b90 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -115,8 +115,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ArgumentMutability(_) | Mutability => write!(f, "types differ in mutability"), TupleSize(values) => write!( f, - "expected a tuple with {} element{}, \ - found one with {} element{}", + "expected a tuple with {} element{}, found one with {} element{}", values.expected, pluralize!(values.expected), values.found, @@ -124,8 +123,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ), FixedArraySize(values) => write!( f, - "expected an array with a fixed size of {} element{}, \ - found one with {} element{}", + "expected an array with a fixed size of {} element{}, found one with {} element{}", values.expected, pluralize!(values.expected), values.found, diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 9faa172a4973f..c02ecc2912429 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -216,7 +216,7 @@ impl FlagComputation { fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) { match atom { - ty::PredicateKind::Trait(trait_pred, _constness) => { + ty::PredicateKind::Trait(trait_pred, _constness, _) => { self.add_substs(trait_pred.trait_ref.substs); } ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 227aa8dc284e2..ae84306ebb836 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -424,6 +424,38 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } +#[derive(Clone, Copy, Debug, Eq, TyEncodable, TyDecodable, TypeFoldable)] +pub enum ImplicitTraitPredicate { + Yes, + No, +} + +impl Hash for ImplicitTraitPredicate { + fn hash(&self, _: &mut H) + where + H: Hasher, + { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + } +} + +impl ::rustc_data_structures::stable_hasher::HashStable for ImplicitTraitPredicate { + #[inline] + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + } +} + +impl PartialEq for ImplicitTraitPredicate { + fn eq(&self, _: &ImplicitTraitPredicate) -> bool { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + true + } +} + #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateKind<'tcx> { @@ -434,7 +466,7 @@ pub enum PredicateKind<'tcx> { /// A trait predicate will have `Constness::Const` if it originates /// from a bound on a `const fn` without the `?const` opt-out (e.g., /// `const fn foobar() {}`). - Trait(TraitPredicate<'tcx>, Constness), + Trait(TraitPredicate<'tcx>, Constness, ImplicitTraitPredicate), /// `where 'a: 'b` RegionOutlives(RegionOutlivesPredicate<'tcx>), @@ -723,8 +755,23 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness) - .to_predicate(tcx) + PredicateKind::Trait( + ty::TraitPredicate { trait_ref: self.value }, + self.constness, + ImplicitTraitPredicate::No, + ) + .to_predicate(tcx) + } +} + +impl<'tcx> ToPredicate<'tcx> for ImplicitSized>>> { + fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::Trait( + ty::TraitPredicate { trait_ref: self.0.value.skip_binder() }, + self.0.constness, + ImplicitTraitPredicate::Yes, + ) + .to_predicate(tcx) } } @@ -732,7 +779,11 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { self.value .map_bound(|trait_ref| { - PredicateKind::Trait(ty::TraitPredicate { trait_ref }, self.constness) + PredicateKind::Trait( + ty::TraitPredicate { trait_ref }, + self.constness, + ImplicitTraitPredicate::No, + ) }) .to_predicate(tcx) } @@ -740,7 +791,11 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.value.map_bound(|value| PredicateKind::Trait(value, self.constness)).to_predicate(tcx) + self.value + .map_bound(|value| { + PredicateKind::Trait(value, self.constness, ImplicitTraitPredicate::No) + }) + .to_predicate(tcx) } } @@ -766,7 +821,7 @@ impl<'tcx> Predicate<'tcx> { pub fn to_opt_poly_trait_ref(self) -> Option>> { let predicate = self.kind(); match predicate.skip_binder() { - PredicateKind::Trait(t, constness) => { + PredicateKind::Trait(t, constness, _) => { Some(ConstnessAnd { constness, value: predicate.rebind(t.trait_ref) }) } PredicateKind::Projection(..) @@ -1264,7 +1319,17 @@ pub trait WithConstness: Sized { } } +pub struct ImplicitSized(T); + +pub trait WithImplicitSized: Sized { + #[inline] + fn with_implicit(self) -> ImplicitSized { + ImplicitSized(self) + } +} + impl WithConstness for T {} +impl WithImplicitSized for T {} #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)] pub struct ParamEnvAnd<'tcx, T> { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 25557bdd1000e..dd2c31ebbfe50 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -630,8 +630,11 @@ pub trait PrettyPrinter<'tcx>: for (predicate, _) in bounds { let predicate = predicate.subst(self.tcx(), substs); let bound_predicate = predicate.kind(); - if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _default) = + bound_predicate.skip_binder() + { let trait_ref = bound_predicate.rebind(pred.trait_ref); + // Maybe use `_default` to determine whether to show `Sized` if `Yes`. // Don't print +Sized, but rather +?Sized if absent. if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() { is_sized = true; @@ -2191,7 +2194,7 @@ define_print_and_forward_display! { ty::PredicateKind<'tcx> { match *self { - ty::PredicateKind::Trait(ref data, constness) => { + ty::PredicateKind::Trait(ref data, constness, _) => { if let hir::Constness::Const = constness { p!("const "); } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7290c41d615df..0f995eac79e66 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -174,7 +174,7 @@ impl fmt::Debug for ty::Predicate<'tcx> { impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ty::PredicateKind::Trait(ref a, constness) => { + ty::PredicateKind::Trait(ref a, constness, _) => { if let hir::Constness::Const = constness { write!(f, "const ")?; } @@ -419,8 +419,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { type Lifted = ty::PredicateKind<'tcx>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { match self { - ty::PredicateKind::Trait(data, constness) => { - tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness)) + ty::PredicateKind::Trait(data, constness, d) => { + tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness, d)) } ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype), ty::PredicateKind::RegionOutlives(data) => { diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 09cafddeeffde..9080bda62d7ed 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -2718,6 +2718,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Some(ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref }, hir::Constness::NotConst, + ty::ImplicitTraitPredicate::No, )), locations, category, diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index 4fbd27c89d9c8..77fd3563316ce 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -423,7 +423,7 @@ impl Validator<'mir, 'tcx> { ty::PredicateKind::Subtype(_) => { bug!("subtype predicate on function: {:#?}", predicate) } - ty::PredicateKind::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/compiler/rustc_mir/src/transform/function_item_references.rs b/compiler/rustc_mir/src/transform/function_item_references.rs index 8d02ac6d9b774..c1f5603cd3fc3 100644 --- a/compiler/rustc_mir/src/transform/function_item_references.rs +++ b/compiler/rustc_mir/src/transform/function_item_references.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { /// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type. fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option> { - if let ty::PredicateKind::Trait(predicate, _) = bound { + if let ty::PredicateKind::Trait(predicate, _, _) = bound { if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) { Some(predicate.trait_ref.self_ty()) } else { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index e64f12ef48f22..16b07fbe11aff 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -122,7 +122,7 @@ where fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => { + ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _, _) => { self.visit_trait(trait_ref) } ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index ca7cdc4caf505..f3deb28bc4131 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -2658,7 +2658,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| { let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { // The order here needs to match what we would get from `subst_supertrait` let pred_bound_vars = bound_predicate.bound_vars(); let mut all_bound_vars = bound_vars.clone(); diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index f54eb0914a5a7..f6a363362b44b 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -415,8 +415,8 @@ impl AutoTraitFinder<'tcx> { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { if let ( - ty::PredicateKind::Trait(new_trait, _), - ty::PredicateKind::Trait(old_trait, _), + ty::PredicateKind::Trait(new_trait, _, _), + ty::PredicateKind::Trait(old_trait, _, _), ) = (new_pred.kind().skip_binder(), old_pred.kind().skip_binder()) { if new_trait.def_id() == old_trait.def_id() { @@ -638,7 +638,7 @@ impl AutoTraitFinder<'tcx> { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(p, _) => { + ty::PredicateKind::Trait(p, _, _) => { // Add this to `predicates` so that we end up calling `select` // with it. If this predicate ends up being unimplemented, // then `evaluate_predicates` will handle adding it the `ParamEnv` 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 19c3385dd4cbc..34b41b8d9a252 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -259,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { let trait_predicate = bound_predicate.rebind(trait_predicate); let trait_predicate = self.resolve_vars_if_possible(trait_predicate); @@ -1106,7 +1106,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // FIXME: It should be possible to deal with `ForAll` in a cleaner way. let bound_error = error.kind(); let (cond, error) = match (cond.kind().skip_binder(), bound_error.skip_binder()) { - (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => { + (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _, _)) => { (cond, bound_error.rebind(error)) } _ => { @@ -1117,7 +1117,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) { let bound_predicate = obligation.predicate.kind(); - if let ty::PredicateKind::Trait(implication, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(implication, _, _) = bound_predicate.skip_binder() { let error = error.to_poly_trait_ref(); let implication = bound_predicate.rebind(implication.trait_ref); // FIXME: I'm just not taking associated types at all here. @@ -1229,6 +1229,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { obligation.cause.code.peel_derives(), ObligationCauseCode::ItemObligation(_) | ObligationCauseCode::BindingObligation(_, _) + | ObligationCauseCode::ImplicitSizedObligation(_, _) | ObligationCauseCode::ObjectCastObligation(_) | ObligationCauseCode::OpaqueType ); @@ -1260,7 +1261,46 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { "type mismatch resolving `{}`", predicate ); - self.note_type_err(&mut diag, &obligation.cause, None, values, err); + let secondary_span = match predicate.kind().skip_binder() { + ty::PredicateKind::Projection(proj) => self + .tcx + .opt_associated_item(proj.projection_ty.item_def_id) + .and_then(|trait_assoc_item| { + self.tcx + .trait_of_item(proj.projection_ty.item_def_id) + .map(|id| (trait_assoc_item, id)) + }) + .and_then(|(trait_assoc_item, id)| { + self.tcx.find_map_relevant_impl( + id, + proj.projection_ty.self_ty(), + |did| { + self.tcx + .associated_items(did) + .in_definition_order() + .filter(|assoc| assoc.ident == trait_assoc_item.ident) + .next() + }, + ) + }) + .and_then(|item| match self.tcx.hir().get_if_local(item.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(_, Some(ty)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(ty), + .. + }), + ) => { + Some((ty.span, format!("type mismatch resolving `{}`", predicate))) + } + _ => None, + }), + _ => None, + }; + self.note_type_err(&mut diag, &obligation.cause, secondary_span, values, err, true); self.note_obligation_cause(&mut diag, obligation); diag.emit(); } @@ -1493,9 +1533,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = predicate.kind(); let mut err = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, implicit_sized) => { let trait_ref = bound_predicate.rebind(data.trait_ref); - debug!("trait_ref {:?}", trait_ref); + debug!(?trait_ref, ?implicit_sized); if predicate.references_error() { return; @@ -1554,7 +1594,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); } else if let ( Ok(ref snippet), - ObligationCauseCode::BindingObligation(ref def_id, _), + ObligationCauseCode::BindingObligation(ref def_id, _) + | ObligationCauseCode::ImplicitSizedObligation(ref def_id, _), ) = (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code) { @@ -1758,8 +1799,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { match (obligation.predicate.kind().skip_binder(), obligation.cause.code.peel_derives()) { ( - ty::PredicateKind::Trait(pred, _), - &ObligationCauseCode::BindingObligation(item_def_id, span), + ty::PredicateKind::Trait(pred, _, _), + &ObligationCauseCode::BindingObligation(item_def_id, span) + | &ObligationCauseCode::ImplicitSizedObligation(item_def_id, span), ) => (pred, item_def_id, span), _ => return, }; 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 0ca0245a203d1..04478d60e7c47 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 @@ -142,7 +142,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } if let ObligationCauseCode::ItemObligation(item) - | ObligationCauseCode::BindingObligation(item, _) = obligation.cause.code + | ObligationCauseCode::BindingObligation(item, _) + | ObligationCauseCode::ImplicitSizedObligation(item, _) = obligation.cause.code { // FIXME: maybe also have some way of handling methods // from other traits? That would require name resolution, 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 5c35b515f3d02..106248abc40ba 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -790,8 +790,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } else { return try_borrowing(new_mut_trait_ref, expected_trait_ref, true, &[]); } - } else if let ObligationCauseCode::BindingObligation(_, _) - | ObligationCauseCode::ItemObligation(_) = &obligation.cause.code + } else if let ObligationCauseCode::BindingObligation(..) + | ObligationCauseCode::ItemObligation(_) + | ObligationCauseCode::ImplicitSizedObligation(..) = &obligation.cause.code { if try_borrowing( ty::TraitRef::new(trait_ref.def_id, imm_substs), @@ -1384,7 +1385,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // bound was introduced. At least one generator should be present for this diagnostic to be // modified. let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())), + ty::PredicateKind::Trait(p, _, _) => (Some(p.trait_ref), Some(p.self_ty())), _ => (None, None), }; let mut generator = None; @@ -1931,6 +1932,62 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.note(&msg); } } + ObligationCauseCode::ImplicitSizedObligation(item_def_id, span) => { + let item_name = tcx.def_path_str(item_def_id); + let mut sp: MultiSpan = span.into(); + match self.tcx.hir().get_if_local(item_def_id) { + Some(hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(bounds, _), + ident, + .. + })) => { + sp.push_span_label( + span, + format!("required by associated type `{}`", item_name), + ); + err.span_note(sp, "associated types have an implicit `Sized` obligation"); + + let sized_trait = self.tcx.lang_items().sized_trait(); + if bounds.len() == 0 { + err.span_suggestion_verbose( + ident.span.shrink_to_hi(), + "consider relaxing the `Sized` obligation", + ": ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } else if bounds.iter().all(|bound| { + bound.trait_ref().and_then(|tr| tr.trait_def_id()) != sized_trait + }) { + err.span_suggestion_verbose( + bounds.iter().last().unwrap().span().shrink_to_hi(), + "consider relaxing the `Sized` obligation", + " + ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } + } + Some(hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(_), + .. + })) => { + let msg = "associated types on `impl` blocks for types, have an implicit \ + mandatory `Sized` obligation; associated types from `trait`s can be \ + relaxed to `?Sized`"; + sp.push_span_label( + span, + format!("required by associated type `{}`", item_name), + ); + err.span_note(sp, msg); + } + _ => { + sp.push_span_label( + span, + format!("required by this bound in `{}`", item_name), + ); + err.span_note(sp, "type parameters have an implicit `Sized` obligation"); + } + } + } ObligationCauseCode::BindingObligation(item_def_id, span) => { let item_name = tcx.def_path_str(item_def_id); let msg = format!("required by this bound in `{}`", item_name); diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 120680092baaa..87390c50ef405 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { // Evaluation will discard candidates using the leak check. // This means we need to pass it the bound version of our // predicate. - ty::PredicateKind::Trait(trait_ref, _constness) => { + ty::PredicateKind::Trait(trait_ref, _constness, _) => { let trait_obligation = obligation.with(binder.rebind(trait_ref)); self.process_trait_obligation( @@ -388,7 +388,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } }, Some(pred) => match pred { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { let trait_obligation = obligation.with(Binder::dummy(data)); self.process_trait_obligation( diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index d5e1bd3f9ea2e..081c2e446ceda 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -280,7 +280,7 @@ fn predicate_references_self( let self_ty = tcx.types.self_param; let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into()); match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None } } @@ -331,7 +331,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let predicates = predicates.instantiate_identity(tcx).predicates; elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| { match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref trait_pred, _) => { + ty::PredicateKind::Trait(ref trait_pred, _, _) => { trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } ty::PredicateKind::Projection(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs index de538c62c5e39..481c2241950a9 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs @@ -15,7 +15,8 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // `&T`, accounts for about 60% percentage of the predicates // we have to prove. No need to canonicalize and all that for // such cases. - if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_ref, _, _) = key.value.predicate.kind().skip_binder() + { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.self_ty().is_trivially_sized(tcx) { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index ea5eb2b68667f..f3f4856de0286 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -454,7 +454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let result = ensure_sufficient_stack(|| { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(t, _) => { + ty::PredicateKind::Trait(t, _, _) => { let t = bound_predicate.rebind(t); debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(t); @@ -865,7 +865,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { let result = match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), + ty::PredicateKind::Trait(ref data, _, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; debug!(?predicate, ?result, "coinductive_predicate"); @@ -1205,7 +1205,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .enumerate() .filter_map(|(idx, bound)| { let bound_predicate = bound.kind(); - if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _) = bound_predicate.skip_binder() { let bound = bound_predicate.rebind(pred.trait_ref); if self.infcx.probe(|_| { match self.match_normalize_trait_ref( diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index f592cf1cd249d..b1ec5f056accd 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -107,7 +107,7 @@ pub fn predicate_obligations<'a, 'tcx>( // It's ok to skip the binder here because wf code is prepared for it match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(t, _) => { + ty::PredicateKind::Trait(t, _, _) => { wf.compute_trait_ref(&t.trait_ref, Elaborate::None); } ty::PredicateKind::RegionOutlives(..) => {} @@ -225,7 +225,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } } } - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); @@ -694,7 +694,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { iter::zip(iter::zip(predicates.predicates, predicates.spans), origins.into_iter().rev()) .map(|((pred, span), origin_def_id)| { - let cause = self.cause(traits::BindingObligation(origin_def_id, span)); + let code = match pred.kind().skip_binder() { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(origin_def_id, span) + } + _ => traits::BindingObligation(origin_def_id, span), + }; + let cause = self.cause(code); traits::Obligation::with_depth(cause, self.recursion_depth, self.param_env, pred) }) .filter(|pred| !pred.has_escaping_bound_vars()) diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 39890fd5b0574..6d4855c3ecd36 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -87,7 +87,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment { chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))) } - ty::PredicateKind::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv( + ty::PredicateKind::Trait(predicate, _, _) => chalk_ir::DomainGoal::FromEnv( chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)), ), ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds( @@ -137,7 +137,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi collect_bound_vars(interner, interner.tcx, self.kind()); let value = match predicate { - ty::PredicateKind::Trait(predicate, _) => { + ty::PredicateKind::Trait(predicate, _, _) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)), )) @@ -569,7 +569,7 @@ impl<'tcx> LowerInto<'tcx, Option { + ty::PredicateKind::Trait(predicate, _, _) => { Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner))) } ty::PredicateKind::RegionOutlives(predicate) => { @@ -702,7 +702,7 @@ impl<'tcx> LowerInto<'tcx, Option Some(chalk_ir::Binders::new( + ty::PredicateKind::Trait(predicate, _, _) => Some(chalk_ir::Binders::new( binders, chalk_solve::rust_ir::InlineBound::TraitBound( predicate.trait_ref.lower_into(interner), diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index ef1956210448d..1a6d2c09c5ab7 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1293,7 +1293,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { let pred = bound_predicate.rebind(pred); associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs index 5d20064072263..80dac62c55ee3 100644 --- a/compiler/rustc_typeck/src/bounds.rs +++ b/compiler/rustc_typeck/src/bounds.rs @@ -2,7 +2,7 @@ //! `ty` form from the HIR. use rustc_hir::Constness; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness}; +use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness, WithImplicitSized}; use rustc_span::Span; /// Collects together a list of type bounds. These lists of bounds occur in many places @@ -61,7 +61,7 @@ impl<'tcx> Bounds<'tcx> { def_id: sized, substs: tcx.mk_substs_trait(param_ty, &[]), }); - (trait_ref.without_const().to_predicate(tcx), span) + (trait_ref.without_const().with_implicit().to_predicate(tcx), span) }) }); diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index d056f2c90f988..acd35eb85181b 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty(); for o in impl_trait_ret_ty.obligations { match o.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(t, constness) => { + ty::PredicateKind::Trait(t, constness, _) => { let pred = ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref: ty::TraitRef { @@ -612,6 +612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, }, constness, + ty::ImplicitTraitPredicate::No, ); let obl = Obligation::new( o.cause.clone(), diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 70d85796d002e..2bb5ea982d85c 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -790,7 +790,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { let abi = sig.header.abi; fn_maybe_err(tcx, item.ident.span, abi); } - hir::TraitItemKind::Type(.., Some(_default)) => { + hir::TraitItemKind::Type(.., Some(default)) => { let assoc_item = tcx.associated_item(item.def_id); let trait_substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id()); @@ -798,7 +798,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { tcx, assoc_item, assoc_item, - item.span, + default.span, ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs }, ); } @@ -1047,12 +1047,12 @@ pub(super) fn check_impl_items_against_trait<'tcx>( opt_trait_span, ); } - hir::ImplItemKind::TyAlias(_) => { + hir::ImplItemKind::TyAlias(impl_ty) => { let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id); compare_ty_impl( tcx, &ty_impl_item, - impl_item.span, + impl_ty.span, &ty_trait_item, impl_trait_ref, opt_trait_span, diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 236fec94bdba7..3b29fb48f38be 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -586,7 +586,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { debug!("coerce_unsized resolve step: {:?}", obligation); let bound_predicate = obligation.predicate.kind(); let trait_pred = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_pred, _) + ty::PredicateKind::Trait(trait_pred, _, _) if traits.contains(&trait_pred.def_id()) => { if unsize_did == trait_pred.def_id() { diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 60ca562f99200..c63fe09ca66fc 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -374,6 +374,7 @@ fn compare_predicate_entailment<'tcx>( found: impl_fty, })), &terr, + false, ); diag.emit(); return Err(ErrorReported); @@ -748,8 +749,7 @@ fn compare_number_of_method_arguments<'tcx>( tcx.sess, impl_span, E0050, - "method `{}` has {} but the declaration in \ - trait `{}` has {}", + "method `{}` has {} but the declaration in trait `{}` has {}", trait_m.ident, potentially_plural_count(impl_number_args, "parameter"), tcx.def_path_str(trait_m.def_id), @@ -1023,6 +1023,7 @@ crate fn compare_const_impl<'tcx>( found: impl_ty, })), &terr, + false, ); diag.emit(); } @@ -1052,7 +1053,8 @@ crate fn compare_ty_impl<'tcx>( let _: Result<(), ErrorReported> = (|| { compare_number_of_generics(tcx, impl_ty, impl_ty_span, trait_ty, trait_item_span)?; - compare_type_predicate_entailment(tcx, impl_ty, impl_ty_span, trait_ty, impl_trait_ref)?; + let sp = tcx.def_span(impl_ty.def_id); + compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?; check_type_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref) })(); @@ -1237,11 +1239,16 @@ pub fn check_type_bounds<'tcx>( let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()); let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id); - let mk_cause = |span| { + let mk_cause = |bound, span| { ObligationCause::new( impl_ty_span, impl_ty_hir_id, - ObligationCauseCode::BindingObligation(trait_ty.def_id, span), + match bound { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(trait_ty.def_id, span) + } + _ => ObligationCauseCode::BindingObligation(trait_ty.def_id, span), + }, ) }; @@ -1252,7 +1259,11 @@ pub fn check_type_bounds<'tcx>( let concrete_ty_bound = bound.subst(tcx, rebased_substs); debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound); - traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound) + traits::Obligation::new( + mk_cause(bound.kind().skip_binder(), span), + param_env, + concrete_ty_bound, + ) }) .collect(); debug!("check_type_bounds: item_bounds={:?}", obligations); diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index 01276495c185a..1d3f1c8cdf203 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -229,7 +229,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let predicate = predicate.kind(); let p = p.kind(); match (predicate.skip_binder(), p.skip_binder()) { - (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { + (ty::PredicateKind::Trait(a, _, _), ty::PredicateKind::Trait(b, _, _)) => { relator.relate(predicate.rebind(a), p.rebind(b)).is_ok() } (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 96569ae0e7720..37150fbd7491b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -793,7 +793,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_predicate.rebind(data).required_poly_trait_ref(self.tcx), obligation, )), - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation)) } ty::PredicateKind::Subtype(..) => None, @@ -1556,7 +1556,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { // This makes the error point at the bound, but we want to point at the argument if let Some(span) = spans.get(i) { - obligation.cause.make_mut().code = traits::BindingObligation(def_id, *span); + let code = match obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(def_id, *span) + } + _ => ObligationCauseCode::BindingObligation(def_id, *span), + }; + obligation.cause.make_mut().code = code; } self.register_predicate(obligation); } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 49aea19c8d099..be3fa7661df4d 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -903,7 +903,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - if let ty::PredicateKind::Trait(predicate, _) = + if let ty::PredicateKind::Trait(predicate, _, _) = error.obligation.predicate.kind().skip_binder() { // Collect the argument position for all arguments that could have caused this @@ -954,7 +954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(qpath) = &path.kind { if let hir::QPath::Resolved(_, path) = &qpath { for error in errors { - if let ty::PredicateKind::Trait(predicate, _) = + if let ty::PredicateKind::Trait(predicate, _, _) = error.obligation.predicate.kind().skip_binder() { // If any of the type arguments in this path segment caused the diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 4da4835f7cfbb..3b888f2ddb5d3 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -201,7 +201,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { predicates: tcx.arena.alloc_from_iter( self.param_env.caller_bounds().iter().filter_map(|predicate| { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(data, _) if data.self_ty().is_param(index) => { + ty::PredicateKind::Trait(data, _, _) if data.self_ty().is_param(index) => { // HACK(eddyb) should get the original `Span`. let span = tcx.def_span(def_id); Some((predicate, span)) diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index f546a0d896354..44f7124b43808 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -496,7 +496,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) // We don't care about regions here. .filter_map(|obligation| match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { + ty::PredicateKind::Trait(trait_pred, _, _) + if trait_pred.def_id() == sized_def_id => + { let span = iter::zip(&predicates.predicates, &predicates.spans) .find_map( |(p, span)| { diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 440e0f4e1a2ac..02b5296a25444 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -832,7 +832,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { match *trait_predicate.trait_ref.self_ty().kind() { ty::Param(p) if p == param_ty => { Some(bound_predicate.rebind(trait_predicate.trait_ref)) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 16382c7e7a4bd..9d43e940c50a1 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -683,7 +683,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut collect_type_param_suggestions = |self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| { // We don't care about regions here, so it's fine to skip the binder here. - if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = + if let (ty::Param(_), ty::PredicateKind::Trait(p, _, _)) = (self_ty.kind(), parent_pred.kind().skip_binder()) { if let ty::Adt(def, _) = p.trait_ref.self_ty().kind() { @@ -763,7 +763,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_span_label(projection_ty.self_ty(), &obligation, &quiet); Some((obligation, projection_ty.self_ty())) } - ty::PredicateKind::Trait(poly_trait_ref, _) => { + ty::PredicateKind::Trait(poly_trait_ref, _, _) => { let p = poly_trait_ref.trait_ref; let self_ty = p.self_ty(); let path = p.print_only_trait_path(); @@ -1194,7 +1194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match p.kind().skip_binder() { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. - ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, + ty::PredicateKind::Trait(t, _, _) => t.def_id() == info.def_id, ty::PredicateKind::Projection(p) => { p.projection_ty.item_def_id == info.def_id } diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index ad7853b7cd0f1..ee5e46d07a757 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -886,7 +886,7 @@ fn bounds_from_generic_predicates<'tcx>( debug!("predicate {:?}", predicate); let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { let entry = types.entry(trait_predicate.self_ty()).or_default(); let def_id = trait_predicate.def_id(); if Some(def_id) != tcx.lang_items().sized_trait() { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index ee3ac3b62d9ec..6b0748705748b 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -619,7 +619,7 @@ fn type_param_predicates( ) .into_iter() .filter(|(predicate, _)| match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index), + ty::PredicateKind::Trait(data, _, _) => data.self_ty().is_param(index), _ => false, }), ); @@ -1153,7 +1153,7 @@ fn super_predicates_that_define_assoc_type( // which will, in turn, reach indirect supertraits. for &(pred, span) in superbounds { debug!("superbound: {:?}", pred); - if let ty::PredicateKind::Trait(bound, _) = pred.kind().skip_binder() { + if let ty::PredicateKind::Trait(bound, _, _) = pred.kind().skip_binder() { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -2134,7 +2134,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let constness = match modifier { hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst, hir::TraitBoundModifier::None => constness, - hir::TraitBoundModifier::Maybe => bug!("this wasn't handled"), + // We ignore `where T: ?Sized`, it is already part of + // type parameter `T`. + hir::TraitBoundModifier::Maybe => continue, }; let mut bounds = Bounds::default(); @@ -2331,7 +2333,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat .iter() .copied() .filter(|(pred, _)| match pred.kind().skip_binder() { - ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()), + ty::PredicateKind::Trait(tr, _, _) => !is_assoc_item_ty(tr.self_ty()), ty::PredicateKind::Projection(proj) => { !is_assoc_item_ty(proj.projection_ty.self_ty()) } diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index a5b36445aae2e..706bdb4fa5736 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -38,7 +38,7 @@ fn associated_type_bounds<'tcx>( let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| { match pred.kind().skip_binder() { - ty::PredicateKind::Trait(tr, _) => tr.self_ty() == item_ty, + ty::PredicateKind::Trait(tr, _, _) => tr.self_ty() == item_ty, ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty, ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty, _ => false, diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 505d9a59d9c2f..e4196bc0c5e4e 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -366,7 +366,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc _ if predicate.is_global() => (), // We allow specializing on explicitly marked traits with no associated // items. - ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst, _) => { if !matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::Marker) @@ -394,10 +394,10 @@ fn trait_predicate_kind<'tcx>( predicate: ty::Predicate<'tcx>, ) -> Option { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst, _) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } - ty::PredicateKind::Trait(_, hir::Constness::Const) + ty::PredicateKind::Trait(_, hir::Constness::Const, _) | ty::PredicateKind::RegionOutlives(_) | ty::PredicateKind::TypeOutlives(_) | ty::PredicateKind::Projection(_) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index a3f63ea1046e3..cfea393c657dd 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -316,7 +316,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { let bound_predicate = pred.kind(); let tcx = self.cx.tcx; let regions = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _, _) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) } ty::PredicateKind::Projection(poly_proj_pred) => { @@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .filter(|p| { !orig_bounds.contains(p) || match p.kind().skip_binder() { - ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, + ty::PredicateKind::Trait(pred, _, _) => pred.def_id() == sized_trait, _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d1c18821ea644..1d36868977ded 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -346,7 +346,7 @@ impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &mut DocContext<'_>) -> Option { let bound_predicate = self.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), + ty::PredicateKind::Trait(pred, _, _) => Some(bound_predicate.rebind(pred).clean(cx)), ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)), @@ -633,7 +633,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx let param_idx = (|| { let bound_p = p.kind(); match bound_p.skip_binder() { - ty::PredicateKind::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness, _) => { if let ty::Param(param) = pred.self_ty().kind() { return Some(param.index); } @@ -1566,8 +1566,8 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|bound| { let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(tr, _constness) => { - bound_predicate.rebind(tr.trait_ref) + ty::PredicateKind::Trait(pred, _constness, _) => { + bound_predicate.rebind(pred.trait_ref) } ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { if let Some(r) = reg.clean(cx) { diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index d4d0a8ce24c7b..567ffb64fb45e 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -129,7 +129,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::PredicateKind::Trait(pred, _) = pred.kind().skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _) = pred.kind().skip_binder() { if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None } } else { None diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr index 029c923aa7d4a..df8e8b07ca53d 100644 --- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr +++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr @@ -1,20 +1,26 @@ error[E0271]: type mismatch resolving `::Color == Blue` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10 | +LL | impl Vehicle for ModelT { type Color = Black; } + | ----- expected this to be `Blue` +... LL | fn blue_car>(c: C) { | ---------- required by this bound in `blue_car` ... LL | fn b() { blue_car(ModelT); } - | ^^^^^^^^ expected struct `Blue`, found struct `Black` + | ^^^^^^^^ type mismatch resolving `::Color == Blue` error[E0271]: type mismatch resolving `::Color == Black` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10 | +LL | impl Vehicle for ModelU { type Color = Blue; } + | ---- expected this to be `Black` +... LL | fn black_car>(c: C) { | ----------- required by this bound in `black_car` ... LL | fn c() { black_car(ModelU); } - | ^^^^^^^^^ expected struct `Black`, found struct `Blue` + | ^^^^^^^^^ type mismatch resolving `::Color == Black` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/associated-types-eq-3.rs b/src/test/ui/associated-types/associated-types-eq-3.rs index 3bb03c39e0f60..f6988dcf65ebf 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.rs +++ b/src/test/ui/associated-types/associated-types-eq-3.rs @@ -37,8 +37,6 @@ pub fn main() { let a = 42; foo1(a); //~^ ERROR type mismatch resolving - //~| expected struct `Bar`, found `usize` baz(&a); //~^ ERROR type mismatch resolving - //~| expected struct `Bar`, found `usize` } diff --git a/src/test/ui/associated-types/associated-types-eq-3.stderr b/src/test/ui/associated-types/associated-types-eq-3.stderr index dffa4780a09ff..109ac613773c2 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -16,17 +16,23 @@ LL | fn foo2>(x: I) { error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:5 | +LL | type A = usize; + | ----- expected this to be `Bar` +... LL | fn foo1>(x: I) { | ----- required by this bound in `foo1` ... LL | foo1(a); - | ^^^^ expected struct `Bar`, found `usize` + | ^^^^ type mismatch resolving `::A == Bar` error[E0271]: type mismatch resolving `::A == Bar` - --> $DIR/associated-types-eq-3.rs:41:9 + --> $DIR/associated-types-eq-3.rs:40:9 | +LL | type A = usize; + | ----- expected this to be `Bar` +... LL | baz(&a); - | ^^ expected struct `Bar`, found `usize` + | ^^ type mismatch resolving `::A == Bar` | = note: required for the cast to the object type `dyn Foo` diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr index 6897b31fe4685..6e6e77e03bc73 100644 --- a/src/test/ui/associated-types/associated-types-eq-hr.stderr +++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `for<'x> >::A == &'x isize` --> $DIR/associated-types-eq-hr.rs:87:5 | +LL | type A = &'a usize; + | --------- expected this to be `&isize` +... LL | fn foo() | --- required by a bound in this LL | where @@ -8,7 +11,7 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>, | ------------- required by this bound in `foo` ... LL | foo::(); - | ^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` + | ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x isize` | = note: expected reference `&isize` found reference `&usize` @@ -16,6 +19,9 @@ LL | foo::(); error[E0271]: type mismatch resolving `for<'x> >::A == &'x usize` --> $DIR/associated-types-eq-hr.rs:91:5 | +LL | type A = &'a isize; + | --------- expected this to be `&usize` +... LL | fn bar() | --- required by a bound in this LL | where @@ -23,7 +29,7 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x usize>, | ------------- required by this bound in `bar` ... LL | bar::(); - | ^^^^^^^^^^^^^^^^ expected `usize`, found `isize` + | ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x usize` | = note: expected reference `&usize` found reference `&isize` diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index 7193d4163b9ce..09b0ffb416048 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -4,11 +4,14 @@ error[E0271]: type mismatch resolving ` as Iterator>::Item == Option< LL | fn is_iterator_of>(_: &I) {} | ------ required by this bound in `is_iterator_of` ... +LL | type Item = T; + | - expected this to be `Option` +... LL | fn test_adapter>>(it: I) { | - this type parameter ... LL | is_iterator_of::, _>(&adapter); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found type parameter `T` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as Iterator>::Item == Option` | = note: expected enum `Option` found type `T` diff --git a/src/test/ui/associated-types/defaults-suitability.stderr b/src/test/ui/associated-types/defaults-suitability.stderr index af4e6f0a5c161..cba88fa44b6fd 100644 --- a/src/test/ui/associated-types/defaults-suitability.stderr +++ b/src/test/ui/associated-types/defaults-suitability.stderr @@ -1,32 +1,29 @@ error[E0277]: the trait bound `NotClone: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:13:5 + --> $DIR/defaults-suitability.rs:13:22 | LL | type Ty: Clone = NotClone; - | ^^^^^^^^^-----^^^^^^^^^^^^ - | | | - | | required by this bound in `Tr::Ty` - | the trait `Clone` is not implemented for `NotClone` + | ----- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone` + | | + | required by this bound in `Tr::Ty` error[E0277]: the trait bound `NotClone: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:22:5 + --> $DIR/defaults-suitability.rs:22:15 | LL | Self::Ty: Clone, | ----- required by this bound in `Tr2::Ty` LL | { LL | type Ty = NotClone; - | ^^^^^--^^^^^^^^^^^^ - | | | - | | required by a bound in this - | the trait `Clone` is not implemented for `NotClone` + | -- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone` + | | + | required by a bound in this error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:28:5 + --> $DIR/defaults-suitability.rs:28:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^ - | | | - | | required by this bound in `Foo::Bar` - | the trait `Clone` is not implemented for `T` + | ----- ^^^^^^ the trait `Clone` is not implemented for `T` + | | + | required by this bound in `Foo::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec` help: consider restricting type parameter `T` @@ -35,34 +32,31 @@ LL | trait Foo { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/defaults-suitability.rs:34:5 + --> $DIR/defaults-suitability.rs:34:29 | LL | type Assoc: Foo = (); - | ^^^^^^^^^^^^---------^^^^^^ - | | | - | | required by this bound in `Bar::Assoc` - | the trait `Foo` is not implemented for `()` + | --------- ^^ the trait `Foo` is not implemented for `()` + | | + | required by this bound in `Bar::Assoc` error[E0277]: the trait bound `NotClone: IsU8` is not satisfied - --> $DIR/defaults-suitability.rs:56:5 + --> $DIR/defaults-suitability.rs:56:18 | LL | Self::Assoc: IsU8, | ----------------- required by this bound in `D::Assoc` ... LL | type Assoc = NotClone; - | ^^^^^-----^^^^^^^^^^^^ - | | | - | | required by a bound in this - | the trait `IsU8` is not implemented for `NotClone` + | ----- ^^^^^^^^ the trait `IsU8` is not implemented for `NotClone` + | | + | required by a bound in this error[E0277]: the trait bound `>::Baz: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:65:5 + --> $DIR/defaults-suitability.rs:65:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo2::Bar` - | the trait `Clone` is not implemented for `>::Baz` + | ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `>::Baz` + | | + | required by this bound in `Foo2::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec<>::Baz>` help: consider further restricting the associated type @@ -71,13 +65,12 @@ LL | trait Foo2 where >::Baz: Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `>::Baz: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:74:5 + --> $DIR/defaults-suitability.rs:74:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo25::Bar` - | the trait `Clone` is not implemented for `>::Baz` + | ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `>::Baz` + | | + | required by this bound in `Foo25::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec<>::Baz>` help: consider further restricting the associated type @@ -86,16 +79,15 @@ LL | trait Foo25 where >::Baz: Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:87:5 + --> $DIR/defaults-suitability.rs:87:16 | LL | Self::Baz: Clone, | ----- required by this bound in `Foo3::Baz` ... LL | type Baz = T; - | ^^^^^---^^^^^ - | | | - | | required by a bound in this - | the trait `Clone` is not implemented for `T` + | --- ^ the trait `Clone` is not implemented for `T` + | | + | required by a bound in this | help: consider further restricting type parameter `T` | diff --git a/src/test/ui/associated-types/defaults-unsound-62211-1.stderr b/src/test/ui/associated-types/defaults-unsound-62211-1.stderr index bcdb50aa312cb..5e8ee4a10643d 100644 --- a/src/test/ui/associated-types/defaults-unsound-62211-1.stderr +++ b/src/test/ui/associated-types/defaults-unsound-62211-1.stderr @@ -1,11 +1,10 @@ error[E0277]: `Self` doesn't implement `std::fmt::Display` - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | `Self` cannot be formatted with the default formatter + | ------- ^^^^ `Self` cannot be formatted with the default formatter + | | + | required by this bound in `UncheckedCopy::Output` | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider further restricting `Self` @@ -14,13 +13,12 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: cannot add-assign `&'static str` to `Self` - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | no implementation for `Self += &'static str` + | ----------------------- ^^^^ no implementation for `Self += &'static str` + | | + | required by this bound in `UncheckedCopy::Output` | help: consider further restricting `Self` | @@ -28,13 +26,10 @@ LL | trait UncheckedCopy: Sized + AddAssign<&'static str> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Self: Deref` is not satisfied - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Deref` is not implemented for `Self` + | ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self` | help: consider further restricting `Self` | @@ -42,13 +37,10 @@ LL | trait UncheckedCopy: Sized + Deref { | ^^^^^^^ error[E0277]: the trait bound `Self: Copy` is not satisfied - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Copy` is not implemented for `Self` + | ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self` | help: consider further restricting `Self` | diff --git a/src/test/ui/associated-types/defaults-unsound-62211-2.stderr b/src/test/ui/associated-types/defaults-unsound-62211-2.stderr index fa5cf9196edbd..db3a81218a291 100644 --- a/src/test/ui/associated-types/defaults-unsound-62211-2.stderr +++ b/src/test/ui/associated-types/defaults-unsound-62211-2.stderr @@ -1,11 +1,10 @@ error[E0277]: `Self` doesn't implement `std::fmt::Display` - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | `Self` cannot be formatted with the default formatter + | ------- ^^^^ `Self` cannot be formatted with the default formatter + | | + | required by this bound in `UncheckedCopy::Output` | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider further restricting `Self` @@ -14,13 +13,12 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: cannot add-assign `&'static str` to `Self` - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | no implementation for `Self += &'static str` + | ----------------------- ^^^^ no implementation for `Self += &'static str` + | | + | required by this bound in `UncheckedCopy::Output` | help: consider further restricting `Self` | @@ -28,13 +26,10 @@ LL | trait UncheckedCopy: Sized + AddAssign<&'static str> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Self: Deref` is not satisfied - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Deref` is not implemented for `Self` + | ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self` | help: consider further restricting `Self` | @@ -42,13 +37,10 @@ LL | trait UncheckedCopy: Sized + Deref { | ^^^^^^^ error[E0277]: the trait bound `Self: Copy` is not satisfied - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Copy` is not implemented for `Self` + | ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self` | help: consider further restricting `Self` | diff --git a/src/test/ui/associated-types/defaults-wf.stderr b/src/test/ui/associated-types/defaults-wf.stderr index d4fa5be742ff3..5ae9320866ce7 100644 --- a/src/test/ui/associated-types/defaults-wf.stderr +++ b/src/test/ui/associated-types/defaults-wf.stderr @@ -3,13 +3,13 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | LL | type Ty = Vec<[u8]>; | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | -LL | pub struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `[u8]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to previous error diff --git a/src/test/ui/associated-types/issue-43784-associated-type.stderr b/src/test/ui/associated-types/issue-43784-associated-type.stderr index 0e653a7d3b22f..51dfe7d14f35b 100644 --- a/src/test/ui/associated-types/issue-43784-associated-type.stderr +++ b/src/test/ui/associated-types/issue-43784-associated-type.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-43784-associated-type.rs:14:5 + --> $DIR/issue-43784-associated-type.rs:14:18 | LL | type Assoc: Partial; | ------------- required by this bound in `Complete::Assoc` ... LL | type Assoc = T; - | ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/associated-types/issue-43924.stderr b/src/test/ui/associated-types/issue-43924.stderr index 8d4ecac750268..a93dcfe4efaeb 100644 --- a/src/test/ui/associated-types/issue-43924.stderr +++ b/src/test/ui/associated-types/issue-43924.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `(dyn ToString + 'static): Default` is not satisfied - --> $DIR/issue-43924.rs:7:5 + --> $DIR/issue-43924.rs:7:45 | LL | type Out: Default + ToString + ?Sized = dyn ToString; - | ^^^^^^^^^^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo::Out` - | the trait `Default` is not implemented for `(dyn ToString + 'static)` + | ------- ^^^^^^^^^^^^ the trait `Default` is not implemented for `(dyn ToString + 'static)` + | | + | required by this bound in `Foo::Out` error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope --> $DIR/issue-43924.rs:14:39 diff --git a/src/test/ui/associated-types/issue-44153.stderr b/src/test/ui/associated-types/issue-44153.stderr index b7db5d385829c..4d185b7a7f602 100644 --- a/src/test/ui/associated-types/issue-44153.stderr +++ b/src/test/ui/associated-types/issue-44153.stderr @@ -4,8 +4,11 @@ error[E0271]: type mismatch resolving `<() as Array>::Element == &()` LL | fn visit() {} | ---------- required by `Visit::visit` ... +LL | type Element = (); + | -- expected this to be `&()` +... LL | <() as Visit>::visit(); - | ^^^^^^^^^^^^^^^^^^^^ expected `&()`, found `()` + | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()` | note: required because of the requirements on the impl of `Visit` for `()` --> $DIR/issue-44153.rs:13:10 diff --git a/src/test/ui/associated-types/issue-54108.stderr b/src/test/ui/associated-types/issue-54108.stderr index 927a2de996561..2bf61c50ed695 100644 --- a/src/test/ui/associated-types/issue-54108.stderr +++ b/src/test/ui/associated-types/issue-54108.stderr @@ -1,11 +1,11 @@ error[E0277]: cannot add `::ActualSize` to `::ActualSize` - --> $DIR/issue-54108.rs:19:5 + --> $DIR/issue-54108.rs:19:17 | LL | type Size: Add; | ------------------------ required by this bound in `Encoder::Size` ... LL | type Size = ::ActualSize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `::ActualSize + ::ActualSize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `::ActualSize + ::ActualSize` | = help: the trait `Add` is not implemented for `::ActualSize` help: consider further restricting the associated type diff --git a/src/test/ui/associated-types/issue-63593.stderr b/src/test/ui/associated-types/issue-63593.stderr index 16ae07687e2c7..325d3e1ed272b 100644 --- a/src/test/ui/associated-types/issue-63593.stderr +++ b/src/test/ui/associated-types/issue-63593.stderr @@ -1,16 +1,22 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-63593.rs:9:5 + --> $DIR/issue-63593.rs:9:17 | LL | type This = Self; - | ^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by this bound in `MyTrait::This` + | ^^^^ doesn't have a size known at compile-time + | +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-63593.rs:9:5 | +LL | type This = Self; + | ^^^^^^^^^^^^^^^^^ required by associated type `MyTrait::This` help: consider further restricting `Self` | LL | trait MyTrait: Sized { | ^^^^^^^ +help: consider relaxing the `Sized` obligation + | +LL | type This: ?Sized = Self; + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/associated-types/issue-65774-1.stderr b/src/test/ui/associated-types/issue-65774-1.stderr index fc020e40b5ad2..30b14d1bc590f 100644 --- a/src/test/ui/associated-types/issue-65774-1.stderr +++ b/src/test/ui/associated-types/issue-65774-1.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied - --> $DIR/issue-65774-1.rs:10:5 + --> $DIR/issue-65774-1.rs:10:33 | LL | type MpuConfig: MyDisplay = T; - | ^^^^^^^^^^^^^^^^---------^^^^^ - | | | - | | required by this bound in `MPU::MpuConfig` - | the trait `MyDisplay` is not implemented for `T` + | --------- ^ the trait `MyDisplay` is not implemented for `T` + | | + | required by this bound in `MPU::MpuConfig` error[E0277]: the trait bound `T: MyDisplay` is not satisfied --> $DIR/issue-65774-1.rs:44:76 diff --git a/src/test/ui/associated-types/issue-65774-2.stderr b/src/test/ui/associated-types/issue-65774-2.stderr index 572a9cf190952..f00a95b4d017a 100644 --- a/src/test/ui/associated-types/issue-65774-2.stderr +++ b/src/test/ui/associated-types/issue-65774-2.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied - --> $DIR/issue-65774-2.rs:10:5 + --> $DIR/issue-65774-2.rs:10:33 | LL | type MpuConfig: MyDisplay = T; - | ^^^^^^^^^^^^^^^^---------^^^^^ - | | | - | | required by this bound in `MPU::MpuConfig` - | the trait `MyDisplay` is not implemented for `T` + | --------- ^ the trait `MyDisplay` is not implemented for `T` + | | + | required by this bound in `MPU::MpuConfig` error[E0277]: the trait bound `T: MyDisplay` is not satisfied --> $DIR/issue-65774-2.rs:39:25 diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr index 23fabbee1c5d4..7f6623014abd5 100644 --- a/src/test/ui/associated-types/issue-72806.stderr +++ b/src/test/ui/associated-types/issue-72806.stderr @@ -1,11 +1,14 @@ error[E0271]: type mismatch resolving `::Ok == char` - --> $DIR/issue-72806.rs:14:5 + --> $DIR/issue-72806.rs:14:20 | LL | type Sibling: Bar2; | ------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^^^^^^^^^^^^^^^^^ expected `char`, found `u32` + | ^^^^ type mismatch resolving `::Ok == char` +... +LL | type Ok = u32; + | --- expected this to be `char` error: aborting due to previous error diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr index b23030d7cb52b..88d3da52e9483 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr @@ -1,14 +1,14 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:8:18 | LL | type Assoc: Bar; | --- required by this bound in `Foo::Assoc` ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:19:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:19:18 | LL | Self::Assoc: Bar, | --- required by this bound in `Baz::Assoc` @@ -17,10 +17,10 @@ LL | type Assoc; | ----- required by a bound in this ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:30:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:30:18 | LL | ::Assoc: Bar, | --- required by this bound in `Bat::Assoc` @@ -29,7 +29,7 @@ LL | type Assoc; | ----- required by a bound in this ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error: aborting due to 3 previous errors diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr index 7417a5aa3d43a..aa632514e104e 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr @@ -1,11 +1,14 @@ error[E0271]: type mismatch resolving `::Ok == ()` - --> $DIR/point-at-type-on-obligation-failure.rs:14:5 + --> $DIR/point-at-type-on-obligation-failure.rs:14:20 | LL | type Sibling: Bar2; | ----------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `u32` + | ^^^^ type mismatch resolving `::Ok == ()` +... +LL | type Ok = u32; + | --- expected this to be `()` error: aborting due to previous error diff --git a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr index 8fdca54d2d8b8..dbf417eded995 100644 --- a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr +++ b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr @@ -3,12 +3,12 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation | LL | trait ArithmeticOps: Add + Sub + Mul + Div {} | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/ops/arith.rs:LL:COL | -LL | pub trait Add { - | --- required by this bound in `Add` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | +LL | pub trait Add { + | ^^^ required by this bound in `Add` help: consider further restricting `Self` | LL | trait ArithmeticOps: Add + Sub + Mul + Div + Sized {} diff --git a/src/test/ui/chalkify/impl_wf_2.stderr b/src/test/ui/chalkify/impl_wf_2.stderr index 1da2144c0a5d4..ef218aa937e76 100644 --- a/src/test/ui/chalkify/impl_wf_2.stderr +++ b/src/test/ui/chalkify/impl_wf_2.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `f32: Foo` is not satisfied - --> $DIR/impl_wf_2.rs:25:5 + --> $DIR/impl_wf_2.rs:25:17 | LL | type Item: Foo; | --- required by this bound in `Bar::Item` ... LL | type Item = f32; - | ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `f32` + | ^^^ the trait `Foo` is not implemented for `f32` error: aborting due to previous error diff --git a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr b/src/test/ui/const-generics/associated-type-bound-fail.full.stderr index 6644e74f97a0b..0ebf9bdd7ad7c 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.full.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 + --> $DIR/associated-type-bound-fail.rs:13:18 | LL | type Assoc: Bar; | ------ required by this bound in `Foo::Assoc` ... LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` + | ^^^ the trait `Bar` is not implemented for `u16` | = help: the following implementations were found: > diff --git a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr b/src/test/ui/const-generics/associated-type-bound-fail.min.stderr index 6644e74f97a0b..0ebf9bdd7ad7c 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.min.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 + --> $DIR/associated-type-bound-fail.rs:13:18 | LL | type Assoc: Bar; | ------ required by this bound in `Foo::Assoc` ... LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` + | ^^^ the trait `Bar` is not implemented for `u16` | = help: the following implementations were found: > diff --git a/src/test/ui/const-generics/const-argument-if-length.full.stderr b/src/test/ui/const-generics/const-argument-if-length.full.stderr index c6088e665a232..a9f1d0eb65718 100644 --- a/src/test/ui/const-generics/const-argument-if-length.full.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.full.stderr @@ -10,6 +10,11 @@ LL | if std::mem::size_of::() == 0 { | LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub const fn is_zst() -> usize { + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/const-argument-if-length.rs:16:12 @@ -21,6 +26,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct AtLeastByte { + | -- help: borrowed types always have a statically known size | LL | value: &T, diff --git a/src/test/ui/const-generics/const-argument-if-length.min.stderr b/src/test/ui/const-generics/const-argument-if-length.min.stderr index bc06e8d7fb123..173a14716635d 100644 --- a/src/test/ui/const-generics/const-argument-if-length.min.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.min.stderr @@ -17,6 +17,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct AtLeastByte { + | -- help: borrowed types always have a statically known size | LL | value: &T, diff --git a/src/test/ui/dst/dst-object-from-unsized-type.stderr b/src/test/ui/dst/dst-object-from-unsized-type.stderr index 2d12265df98ed..6c57dd9316fbd 100644 --- a/src/test/ui/dst/dst-object-from-unsized-type.stderr +++ b/src/test/ui/dst/dst-object-from-unsized-type.stderr @@ -7,6 +7,10 @@ LL | let u: &dyn Foo = t; | ^ doesn't have a size known at compile-time | = note: required for the cast to the object type `dyn Foo` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn test1(t: &T) { + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:13:23 @@ -17,6 +21,10 @@ LL | let v: &dyn Foo = t as &dyn Foo; | ^ doesn't have a size known at compile-time | = note: required for the cast to the object type `dyn Foo` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn test2(t: &T) { + | -- error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:18:28 diff --git a/src/test/ui/dst/dst-sized-trait-param.stderr b/src/test/ui/dst/dst-sized-trait-param.stderr index 481c01a75e5a9..566a7c3ba94da 100644 --- a/src/test/ui/dst/dst-sized-trait-param.stderr +++ b/src/test/ui/dst/dst-sized-trait-param.stderr @@ -1,13 +1,15 @@ error[E0277]: the size for values of type `[isize]` cannot be known at compilation time --> $DIR/dst-sized-trait-param.rs:7:6 | -LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized - | - required by this bound in `Foo` -LL | LL | impl Foo<[isize]> for usize { } | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[isize]` +note: type parameters have an implicit `Sized` obligation + --> $DIR/dst-sized-trait-param.rs:5:11 + | +LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized + | ^ required by this bound in `Foo` help: consider relaxing the implicit `Sized` restriction | LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr index 580b5aef07e6d..f05c7b4490504 100644 --- a/src/test/ui/error-codes/E0271.stderr +++ b/src/test/ui/error-codes/E0271.stderr @@ -4,8 +4,11 @@ error[E0271]: type mismatch resolving `::AssociatedType == u32` LL | fn foo(t: T) where T: Trait { | ------------------ required by this bound in `foo` ... +LL | impl Trait for i8 { type AssociatedType = &'static str; } + | ------------ expected this to be `u32` +... LL | foo(3_i8); - | ^^^ expected `u32`, found `&str` + | ^^^ type mismatch resolving `::AssociatedType == u32` error: aborting due to previous error diff --git a/src/test/ui/extern/extern-types-unsized.stderr b/src/test/ui/extern/extern-types-unsized.stderr index 72e4be51822e2..b4d10add6719d 100644 --- a/src/test/ui/extern/extern-types-unsized.stderr +++ b/src/test/ui/extern/extern-types-unsized.stderr @@ -1,13 +1,15 @@ error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:22:20 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::(); | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `A` +note: type parameters have an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -16,9 +18,6 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:25:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::(); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | @@ -28,6 +27,11 @@ note: required because it appears within the type `Foo` | LL | struct Foo { | ^^^ +note: type parameters have an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -36,9 +40,6 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:28:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::>(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | @@ -48,6 +49,11 @@ note: required because it appears within the type `Bar` | LL | struct Bar { | ^^^ +note: type parameters have an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -56,9 +62,6 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:31:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | @@ -73,6 +76,11 @@ note: required because it appears within the type `Bar>` | LL | struct Bar { | ^^^ +note: type parameters have an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} diff --git a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr index 4afbde5021f91..82a18bf92ece1 100644 --- a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr @@ -62,10 +62,10 @@ LL | type Assoc where Self: Sized = Foo; = help: add `#![feature(generic_associated_types)]` to the crate attributes to enable error[E0277]: the trait bound `U32: Clone` is not satisfied - --> $DIR/feature-gate-generic_associated_types.rs:16:5 + --> $DIR/feature-gate-generic_associated_types.rs:16:26 | LL | type Pointer2 = Box; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `U32` + | ^^^^^^^^ the trait `Clone` is not implemented for `U32` | help: consider restricting type parameter `U32` | diff --git a/src/test/ui/generic-associated-types/cross-crate-bounds.stderr b/src/test/ui/generic-associated-types/cross-crate-bounds.stderr index d96c5f4540ef5..f004b42d1f3e7 100644 --- a/src/test/ui/generic-associated-types/cross-crate-bounds.stderr +++ b/src/test/ui/generic-associated-types/cross-crate-bounds.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `(): AsRef<()>` is not satisfied - --> $DIR/cross-crate-bounds.rs:15:5 + --> $DIR/cross-crate-bounds.rs:15:16 | LL | type Bar = (); - | ^^^^^^^^^^^^^^ the trait `AsRef<()>` is not implemented for `()` + | ^^ the trait `AsRef<()>` is not implemented for `()` | ::: $DIR/auxiliary/foo_defn.rs:6:15 | diff --git a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr index da8b625ea7f75..9026d95b9e9cf 100644 --- a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr +++ b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr @@ -1,8 +1,8 @@ error[E0277]: `T` doesn't implement `std::fmt::Display` - --> $DIR/generic-associated-types-where.rs:21:5 + --> $DIR/generic-associated-types-where.rs:21:22 | LL | type Assoc2 = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted with the default formatter + | ^^^^^^ `T` cannot be formatted with the default formatter | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 58bcb13e68ebd..81122341dacba 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -25,10 +25,10 @@ LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^ error[E0478]: lifetime bound not satisfied - --> $DIR/impl_bounds.rs:18:5 + --> $DIR/impl_bounds.rs:18:35 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined on the associated item at 18:12 --> $DIR/impl_bounds.rs:18:12 diff --git a/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr b/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr index c92800c3746ad..fae959476f1ff 100644 --- a/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr +++ b/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-68641-check-gat-bounds.rs:15:5 + --> $DIR/issue-68641-check-gat-bounds.rs:15:21 | LL | type Item<'a>: Copy; | ---- required by this bound in `UnsafeCopy::Item` ... LL | type Item<'a> = T; - | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr b/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr index e44547b10c17b..320d267701a23 100644 --- a/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr +++ b/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68642-broken-llvm-ir.rs:15:5 + --> $DIR/issue-68642-broken-llvm-ir.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr b/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr index fd0b4733d9359..9469ffc787680 100644 --- a/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr +++ b/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68643-broken-mir.rs:15:5 + --> $DIR/issue-68643-broken-mir.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr b/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr index 0c23c870f0106..0604df49b2be7 100644 --- a/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr +++ b/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68644-codegen-selection.rs:15:5 + --> $DIR/issue-68644-codegen-selection.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr b/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr index 85d8d3f8e936e..3131e1969704e 100644 --- a/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr +++ b/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68645-codegen-fulfillment.rs:15:5 + --> $DIR/issue-68645-codegen-fulfillment.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr index c4ee2c4e61872..b30f1573983d5 100644 --- a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr +++ b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr @@ -8,7 +8,7 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0271]: type mismatch resolving `::Target == T` - --> $DIR/issue-68656-unsized-values.rs:16:5 + --> $DIR/issue-68656-unsized-values.rs:16:21 | LL | type Item<'a>: std::ops::Deref; | ---------- required by this bound in `UnsafeCopy::Item` @@ -16,7 +16,7 @@ LL | type Item<'a>: std::ops::Deref; LL | impl UnsafeCopy for T { | - this type parameter LL | type Item<'a> = T; - | ^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type + | ^ expected type parameter `T`, found associated type | = note: expected type parameter `T` found associated type `::Target` diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr index 8c3484f9a7300..83fac225808aa 100644 --- a/src/test/ui/generic-associated-types/issue-74684-2.stderr +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -10,11 +10,14 @@ LL | #![feature(generic_associated_types)] error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` --> $DIR/issue-74684-2.rs:24:5 | +LL | type F<'a> = i32; + | --- expected this to be `[u8]` +... LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { | ------------ required by this bound in `bug` ... LL | bug(Box::new(x)); - | ^^^ expected slice `[u8]`, found `i32` + | ^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr index 64bc94d601b78..a08c51323c000 100644 --- a/src/test/ui/generic-associated-types/issue-74816.stderr +++ b/src/test/ui/generic-associated-types/issue-74816.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `Self: Trait1` is not satisfied - --> $DIR/issue-74816.rs:10:5 + --> $DIR/issue-74816.rs:10:31 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^------^^^^^^^^ - | | | - | | required by this bound in `Trait2::Associated` - | the trait `Trait1` is not implemented for `Self` + | ------ ^^^^ the trait `Trait1` is not implemented for `Self` + | | + | required by this bound in `Trait2::Associated` | help: consider further restricting `Self` | @@ -13,18 +12,24 @@ LL | trait Trait2: Trait1 { | ^^^^^^^^ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-74816.rs:10:5 + --> $DIR/issue-74816.rs:10:31 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time - | required by this bound in `Trait2::Associated` + | ^^^^ doesn't have a size known at compile-time + | +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-74816.rs:10:5 | +LL | type Associated: Trait1 = Self; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by associated type `Trait2::Associated` help: consider further restricting `Self` | LL | trait Trait2: Sized { | ^^^^^^^ +help: consider relaxing the `Sized` obligation + | +LL | type Associated: Trait1 + ?Sized = Self; + | ^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/generic-associated-types/issue-74824.stderr b/src/test/ui/generic-associated-types/issue-74824.stderr index 7a7b5fd4f1c55..4b2d8c4128944 100644 --- a/src/test/ui/generic-associated-types/issue-74824.stderr +++ b/src/test/ui/generic-associated-types/issue-74824.stderr @@ -1,20 +1,18 @@ error[E0277]: the trait bound `Box: Copy` is not satisfied - --> $DIR/issue-74824.rs:8:5 + --> $DIR/issue-74824.rs:8:26 | LL | type Copy: Copy = Box; - | ^^^^^^^^^^^^^^----^^^^^^^^^^ - | | | - | | required by this bound in `UnsafeCopy::Copy` - | the trait `Copy` is not implemented for `Box` + | ---- ^^^^^^ the trait `Copy` is not implemented for `Box` + | | + | required by this bound in `UnsafeCopy::Copy` error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/issue-74824.rs:8:5 + --> $DIR/issue-74824.rs:8:26 | LL | type Copy: Copy = Box; - | ^^^^^^^^^^^^^^----^^^^^^^^^^ - | | | - | | required by this bound in `UnsafeCopy::Copy` - | the trait `Clone` is not implemented for `T` + | ---- ^^^^^^ the trait `Clone` is not implemented for `T` + | | + | required by this bound in `UnsafeCopy::Copy` | = note: required because of the requirements on the impl of `Clone` for `Box` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr index d27e46f6836df..c326e40a77bbe 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr @@ -10,11 +10,14 @@ LL | #![feature(generic_associated_types)] error[E0275]: overflow evaluating the requirement `::Item: Sized` --> $DIR/projection-bound-cycle-generic.rs:45:5 | -LL | struct OnlySized where T: Sized { f: T } - | - required by this bound in `OnlySized` -... LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/projection-bound-cycle-generic.rs:29:18 + | +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr index 400b664f97ca9..a19e679930dc4 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr @@ -10,11 +10,14 @@ LL | #![feature(generic_associated_types)] error[E0275]: overflow evaluating the requirement `::Item: Sized` --> $DIR/projection-bound-cycle.rs:47:5 | -LL | struct OnlySized where T: Sized { f: T } - | - required by this bound in `OnlySized` -... LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/projection-bound-cycle.rs:31:18 + | +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr index 5d612284a2187..816144b6f0d58 100644 --- a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr +++ b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr @@ -1,8 +1,8 @@ error[E0477]: the type `&'b ()` does not fulfill the required lifetime - --> $DIR/unsatisfied-outlives-bound.rs:9:5 + --> $DIR/unsatisfied-outlives-bound.rs:9:21 | LL | type Item<'a> = &'b (); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | note: type must outlive the lifetime `'a` as defined on the associated item at 9:15 --> $DIR/unsatisfied-outlives-bound.rs:9:15 @@ -11,10 +11,10 @@ LL | type Item<'a> = &'b (); | ^^ error[E0477]: the type `&'a ()` does not fulfill the required lifetime - --> $DIR/unsatisfied-outlives-bound.rs:18:5 + --> $DIR/unsatisfied-outlives-bound.rs:18:21 | LL | type Item<'a> = &'a (); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | = note: type must satisfy the static lifetime diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index 2b88a6046fdfd..96d1e535d0ab6 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -1,13 +1,15 @@ error[E0277]: the size for values of type `[()]` cannot be known at compilation time --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:19:6 | -LL | trait Tsized {} - | - required by this bound in `Tsized` -LL | LL | impl Tsized for () {} | ^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[()]` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14 + | +LL | trait Tsized {} + | ^ required by this bound in `Tsized` error: aborting due to previous error diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr index 7b81beeed4167..eefe172809469 100644 --- a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -1,8 +1,11 @@ error[E0271]: type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` --> $DIR/issue-62203-hrtb-ice.rs:38:19 | +LL | type O = T::Output; + | --------- expected this to be `Unit4` +... LL | let v = Unit2.m( - | ^ expected struct `Unit4`, found associated type + | ^ type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` | = note: expected struct `Unit4` found associated type `<_ as Ty<'_>>::V` diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr index ba3a2e7f8d4c9..be7467c33fc6a 100644 --- a/src/test/ui/impl-trait/bound-normalization-fail.stderr +++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr @@ -10,8 +10,11 @@ LL | #![feature(impl_trait_in_bindings)] error[E0271]: type mismatch resolving ` as FooLike>::Output == ::Assoc` --> $DIR/bound-normalization-fail.rs:26:32 | +LL | type Output = T; + | - expected this to be `::Assoc` +... LL | fn foo_fail() -> impl FooLike { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == ::Assoc` | = note: expected associated type `::Assoc` found type `()` @@ -29,8 +32,11 @@ LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { error[E0271]: type mismatch resolving ` as FooLike>::Output == >::Assoc` --> $DIR/bound-normalization-fail.rs:42:41 | +LL | type Output = T; + | - expected this to be `>::Assoc` +... LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == >::Assoc` | = note: expected associated type `>::Assoc` found type `()` diff --git a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr index 54eb5a96c9d81..b598230c4f02e 100644 --- a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr +++ b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr @@ -1,8 +1,11 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:13:14 | +LL | type Assoc = u8; + | -- expected this to be `()` +... LL | fn test() -> impl Test { - | ^^^^^^^^^ expected `()`, found `u8` + | ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()` | note: required because of the requirements on the impl of `Test` for `()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:11:9 diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index 2a6e2414593aa..148096fbecdc1 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -49,13 +49,15 @@ LL | impl<'self> Serializable for &'self str { error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/issue-10412.rs:6:13 | -LL | trait Serializable<'self, T> { - | - required by this bound in `Serializable` -... LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-10412.rs:1:27 + | +LL | trait Serializable<'self, T> { + | ^ required by this bound in `Serializable` help: consider relaxing the implicit `Sized` restriction | LL | trait Serializable<'self, T: ?Sized> { diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr index d4b93eb074cfe..11342e26948c5 100644 --- a/src/test/ui/issues/issue-18919.stderr +++ b/src/test/ui/issues/issue-18919.stderr @@ -3,11 +3,13 @@ error[E0277]: the size for values of type `dyn for<'r> Fn(&'r isize) -> isize` c | LL | fn ho_func(f: Option) { | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | enum Option { - | - required by this bound in `Option` | = help: the trait `Sized` is not implemented for `dyn for<'r> Fn(&'r isize) -> isize` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-18919.rs:7:13 + | +LL | enum Option { + | ^ required by this bound in `Option` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-18919.rs:7:13 | diff --git a/src/test/ui/issues/issue-20433.stderr b/src/test/ui/issues/issue-20433.stderr index 5fed02164b5b7..5a28f0233a15f 100644 --- a/src/test/ui/issues/issue-20433.stderr +++ b/src/test/ui/issues/issue-20433.stderr @@ -3,13 +3,13 @@ error[E0277]: the size for values of type `[i32]` cannot be known at compilation | LL | fn iceman(c: Vec<[i32]>) {} | ^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | -LL | pub struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `[i32]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-23281.stderr b/src/test/ui/issues/issue-23281.stderr index a3d2583292551..69f687df68238 100644 --- a/src/test/ui/issues/issue-23281.stderr +++ b/src/test/ui/issues/issue-23281.stderr @@ -3,11 +3,13 @@ error[E0277]: the size for values of type `(dyn Fn() + 'static)` cannot be known | LL | pub fn function(funs: Vec ()>) {} | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-23281.rs:8:12 + | +LL | struct Vec { + | ^ required by this bound in `Vec` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-23281.rs:8:12 | diff --git a/src/test/ui/issues/issue-27060-2.stderr b/src/test/ui/issues/issue-27060-2.stderr index 5dbcc96e87488..64e061a89b410 100644 --- a/src/test/ui/issues/issue-27060-2.stderr +++ b/src/test/ui/issues/issue-27060-2.stderr @@ -8,6 +8,10 @@ LL | data: T, | = note: the last field of a packed struct may only have a dynamically sized type if it does not need drop to be run = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct Bad { + | -- help: borrowed types always have a statically known size | LL | data: &T, diff --git a/src/test/ui/issues/issue-39970.stderr b/src/test/ui/issues/issue-39970.stderr index 2a0693a581c31..d5f1bd3876e9d 100644 --- a/src/test/ui/issues/issue-39970.stderr +++ b/src/test/ui/issues/issue-39970.stderr @@ -4,8 +4,11 @@ error[E0271]: type mismatch resolving `for<'a> <() as Array<'a>>::Element == ()` LL | fn visit() {} | ---------- required by `Visit::visit` ... +LL | type Element = &'a (); + | ------ expected this to be `()` +... LL | <() as Visit>::visit(); - | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&()` + | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'a> <() as Array<'a>>::Element == ()` | note: required because of the requirements on the impl of `Visit` for `()` --> $DIR/issue-39970.rs:13:6 diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index 650570b6471eb..51a8618d1dca2 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -18,13 +18,13 @@ error[E0277]: the size for values of type `<() as Trait<'_>>::Item` cannot be kn | LL | foo((), drop) | ^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub fn drop(_x: T) {} - | - required by this bound in `std::mem::drop` | = help: the trait `Sized` is not implemented for `<() as Trait<'_>>::Item` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub fn drop(_x: T) {} + | ^ required by this bound in `std::mem::drop` help: consider further restricting the associated type | LL | fn main() where <() as Trait<'_>>::Item: Sized { diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/mir/issue-80742.stderr index 961234cf7e854..59c376b5d7614 100644 --- a/src/test/ui/mir/issue-80742.stderr +++ b/src/test/ui/mir/issue-80742.stderr @@ -52,13 +52,15 @@ LL | [u8; size_of::() + 1]: , error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time --> $DIR/issue-80742.rs:31:15 | -LL | struct Inline - | - required by this bound in `Inline` -... LL | let dst = Inline::::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Debug` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-80742.rs:13:15 + | +LL | struct Inline + | ^ required by this bound in `Inline` help: consider relaxing the implicit `Sized` restriction | LL | struct Inline diff --git a/src/test/ui/never_type/issue-51506.stderr b/src/test/ui/never_type/issue-51506.stderr index 16d93c18900a9..ebb23145a8e84 100644 --- a/src/test/ui/never_type/issue-51506.stderr +++ b/src/test/ui/never_type/issue-51506.stderr @@ -1,11 +1,11 @@ error[E0277]: `!` is not an iterator - --> $DIR/issue-51506.rs:13:5 + --> $DIR/issue-51506.rs:13:24 | LL | type Out: Iterator; | -------------------- required by this bound in `Trait::Out` ... LL | default type Out = !; - | ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator + | ^ `!` is not an iterator | = help: the trait `Iterator` is not implemented for `!` diff --git a/src/test/ui/range/range-1.stderr b/src/test/ui/range/range-1.stderr index 2cebffec990f6..758e5424efe89 100644 --- a/src/test/ui/range/range-1.stderr +++ b/src/test/ui/range/range-1.stderr @@ -19,13 +19,13 @@ error[E0277]: the size for values of type `[{integer}]` cannot be known at compi | LL | let range = *arr..; | ^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/ops/range.rs:LL:COL - | -LL | pub struct RangeFrom { - | --- required by this bound in `RangeFrom` | = help: the trait `Sized` is not implemented for `[{integer}]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/ops/range.rs:LL:COL + | +LL | pub struct RangeFrom { + | ^^^ required by this bound in `RangeFrom` error: aborting due to 3 previous errors diff --git a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr index 03da33ae11ffe..24e053b4f6011 100644 --- a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr +++ b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr @@ -1,16 +1,16 @@ error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:15:5 + --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:15:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: type must satisfy the static lifetime error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:20:5 + --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:20:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | note: type must outlive the lifetime `'b` as defined on the impl at 19:10 --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:19:10 diff --git a/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr b/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr index d8efeac5b8a30..efc7428808ed3 100644 --- a/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr +++ b/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr @@ -1,8 +1,8 @@ error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-static-bound-in-trait-not-met.rs:10:5 + --> $DIR/regions-assoc-type-static-bound-in-trait-not-met.rs:10:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: type must satisfy the static lifetime diff --git a/src/test/ui/specialization/deafult-associated-type-bound-1.stderr b/src/test/ui/specialization/deafult-associated-type-bound-1.stderr index 4ca3d83119839..aaad03eadf834 100644 --- a/src/test/ui/specialization/deafult-associated-type-bound-1.stderr +++ b/src/test/ui/specialization/deafult-associated-type-bound-1.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/deafult-associated-type-bound-1.rs:19:5 + --> $DIR/deafult-associated-type-bound-1.rs:19:22 | LL | type U: Clone; | ----- required by this bound in `X::U` ... LL | default type U = str; - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str` + | ^^^ the trait `Clone` is not implemented for `str` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr index 0e8a774bce37f..053e1f8500a62 100644 --- a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr +++ b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: can't compare `&'static B` with `B` - --> $DIR/deafult-associated-type-bound-2.rs:16:5 + --> $DIR/deafult-associated-type-bound-2.rs:16:22 | LL | type U: PartialEq; | ------------ required by this bound in `X::U` ... LL | default type U = &'static B; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&'static B == B` + | ^^^^^^^^^^ no implementation for `&'static B == B` | = help: the trait `PartialEq` is not implemented for `&'static B` help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement diff --git a/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr b/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr index eb5d80bc4dda6..749a4a8420a26 100644 --- a/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr +++ b/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr @@ -17,13 +17,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: can't compare `T` with `T` - --> $DIR/deafult-generic-associated-type-bound.rs:19:5 + --> $DIR/deafult-generic-associated-type-bound.rs:19:26 | LL | type U<'a>: PartialEq<&'a Self> where Self: 'a; | ------------------- required by this bound in `X::U` ... LL | default type U<'a> = &'a T; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `T == T` + | ^^^^^ no implementation for `T == T` | = note: required because of the requirements on the impl of `PartialEq` for `&'a T` help: consider further restricting this bound diff --git a/src/test/ui/specialization/issue-33017.stderr b/src/test/ui/specialization/issue-33017.stderr index bff4618d0be4c..27e2d09eb44cc 100644 --- a/src/test/ui/specialization/issue-33017.stderr +++ b/src/test/ui/specialization/issue-33017.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-33017.rs:12:5 + --> $DIR/issue-33017.rs:12:27 | LL | type Output: From + Copy + Into; | ---- required by this bound in `UncheckedCopy::Output` ... LL | default type Output = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^^^^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/specialization/issue-38091.stderr b/src/test/ui/specialization/issue-38091.stderr index 97e5775ab54ee..3c089c9f005c9 100644 --- a/src/test/ui/specialization/issue-38091.stderr +++ b/src/test/ui/specialization/issue-38091.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: the trait bound `(): Valid` is not satisfied - --> $DIR/issue-38091.rs:12:5 + --> $DIR/issue-38091.rs:12:23 | LL | type Ty: Valid; | ----- required by this bound in `Iterate::Ty` ... LL | default type Ty = (); - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Valid` is not implemented for `()` + | ^^ the trait `Valid` is not implemented for `()` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/specialization/issue-44861.stderr b/src/test/ui/specialization/issue-44861.stderr index 3935a4a5f9931..eca43e2f75165 100644 --- a/src/test/ui/specialization/issue-44861.stderr +++ b/src/test/ui/specialization/issue-44861.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `(): CoerceUnsized<*const [u8]>` is not satisfied - --> $DIR/issue-44861.rs:21:5 + --> $DIR/issue-44861.rs:21:26 | LL | type Data2: CoerceUnsized<*const [u8]>; | -------------------------- required by this bound in `Smartass::Data2` ... LL | default type Data2 = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CoerceUnsized<*const [u8]>` is not implemented for `()` + | ^^ the trait `CoerceUnsized<*const [u8]>` is not implemented for `()` error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr index f3f8b022b01e1..aa9d611331d7b 100644 --- a/src/test/ui/specialization/issue-59435.stderr +++ b/src/test/ui/specialization/issue-59435.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `MyStruct: Default` is not satisfied - --> $DIR/issue-59435.rs:11:5 + --> $DIR/issue-59435.rs:11:27 | LL | type MyType: Default; | ------- required by this bound in `MyTrait::MyType` ... LL | default type MyType = MyStruct; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `MyStruct` + | ^^^^^^^^ the trait `Default` is not implemented for `MyStruct` error: aborting due to previous error diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr index 405542820a394..9297e1d55f542 100644 --- a/src/test/ui/str/str-mut-idx.stderr +++ b/src/test/ui/str/str-mut-idx.stderr @@ -1,13 +1,15 @@ error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/str-mut-idx.rs:4:15 | -LL | fn bot() -> T { loop {} } - | - required by this bound in `bot` -... LL | s[1..2] = bot(); | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` +note: type parameters have an implicit `Sized` obligation + --> $DIR/str-mut-idx.rs:1:8 + | +LL | fn bot() -> T { loop {} } + | ^ required by this bound in `bot` help: consider relaxing the implicit `Sized` restriction | LL | fn bot() -> T { loop {} } diff --git a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr index 5cb3a404037a7..7d7e4bed89cdf 100644 --- a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr +++ b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/adt-param-with-implicit-sized-bound.rs:25:9 | -LL | struct X(T); - | - required by this bound in `X` -... LL | struct Struct5{ | - this type parameter needs to be `std::marker::Sized` LL | _t: X, | ^^^^ doesn't have a size known at compile-time | +note: type parameters have an implicit `Sized` obligation + --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 + | +LL | struct X(T); + | ^ required by this bound in `X` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 | @@ -16,6 +18,10 @@ LL | struct X(T); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `T: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct Struct5{ + | -- error[E0277]: the size for values of type `Self` cannot be known at compilation time --> $DIR/adt-param-with-implicit-sized-bound.rs:2:19 diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index f1e6ef883ae90..21b568f1f9292 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -30,13 +30,15 @@ LL | f_unpin(static || { yield; }); error[E0277]: the size for values of type `dyn Fn()` cannot be known at compilation time --> $DIR/issue-84973-blacklist.rs:22:13 | -LL | fn f_sized(t: T) {} - | - required by this bound in `f_sized` -... LL | f_sized(*ref_cl); | ^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Fn()` +note: type parameters have an implicit `Sized` obligation + --> $DIR/issue-84973-blacklist.rs:9:12 + | +LL | fn f_sized(t: T) {} + | ^ required by this bound in `f_sized` error[E0277]: `Rc<{integer}>` cannot be sent between threads safely --> $DIR/issue-84973-blacklist.rs:28:12 diff --git a/src/test/ui/trait-bounds/unsized-bound.rs b/src/test/ui/trait-bounds/unsized-bound.rs new file mode 100644 index 0000000000000..035b8ef1bdebc --- /dev/null +++ b/src/test/ui/trait-bounds/unsized-bound.rs @@ -0,0 +1,32 @@ +trait Trait {} +impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} +//~^ ERROR E0277 +//~| ERROR E0277 +impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} +//~^ ERROR E0277 +//~| ERROR E0277 +//~| ERROR E0277 +trait Trait2 {} +impl Trait2<(A, B)> for (A, B) {} +//~^ ERROR E0277 +//~| ERROR E0277 +trait Trait3 {} +impl Trait3 for A where A: ?Sized {} +//~^ ERROR E0277 +trait Trait4 {} +impl Trait4 for A {} +//~^ ERROR E0277 +trait Trait5 {} +impl Trait5 for X where X: ?Sized {} +//~^ ERROR E0277 +trait Trait6 {} +impl Trait6 for X {} +//~^ ERROR E0277 +trait Trait7 {} +impl Trait7 for X where Y: ?Sized {} +//~^ ERROR E0277 +trait Trait8 {} +impl Trait8 for X {} +//~^ ERROR E0277 + +fn main() {} diff --git a/src/test/ui/trait-bounds/unsized-bound.stderr b/src/test/ui/trait-bounds/unsized-bound.stderr new file mode 100644 index 0000000000000..dae66b56043c5 --- /dev/null +++ b/src/test/ui/trait-bounds/unsized-bound.stderr @@ -0,0 +1,254 @@ +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:2:12 + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} + | - ^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:1:13 + | +LL | trait Trait {} + | ^ required by this bound in `Trait` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:2:30 + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} + | - ^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B)> for (A, B) where B: ?Sized, {} + | -- + +error[E0277]: the size for values of type `C` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:31 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B, C)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:1:13 + | +LL | trait Trait {} + | ^ required by this bound in `Trait` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:52 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) {} + | -- + +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:52 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | -- + +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:10:28 + | +LL | impl Trait2<(A, B)> for (A, B) {} + | - ^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:9:14 + | +LL | trait Trait2 {} + | ^ required by this bound in `Trait2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait2<(A, B)> for (A, B) {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait2 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:10:47 + | +LL | impl Trait2<(A, B)> for (A, B) {} + | - ^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait2<(A, B)> for (A, B) {} + | -- + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:14:9 + | +LL | trait Trait3 {} + | - required by this bound in `Trait3` +LL | impl Trait3 for A where A: ?Sized {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait3 for A {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait3 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:17:17 + | +LL | trait Trait4 {} + | - required by this bound in `Trait4` +LL | impl Trait4 for A {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait4 for A {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait4 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized-bound.rs:20:12 + | +LL | impl Trait5 for X where X: ?Sized {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:19:14 + | +LL | trait Trait5 {} + | ^ required by this bound in `Trait5` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait5 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait5 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized-bound.rs:23:20 + | +LL | impl Trait6 for X {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:22:14 + | +LL | trait Trait6 {} + | ^ required by this bound in `Trait6` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait6 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait6 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized-bound.rs:26:12 + | +LL | impl Trait7 for X where Y: ?Sized {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:25:17 + | +LL | trait Trait7 {} + | ^ required by this bound in `Trait7` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait7 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait7 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized-bound.rs:29:20 + | +LL | impl Trait8 for X {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:28:17 + | +LL | trait Trait8 {} + | ^ required by this bound in `Trait8` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait8 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait8 {} + | ^^^^^^^^ + +error: aborting due to 13 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr index bd2b789cd9908..3aa0171c3e69b 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr @@ -1,11 +1,14 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-5.rs:23:5 | +LL | type T = U; + | - expected this to be `i64` +... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... LL | is_obj(x) - | ^^^^^^ expected `i64`, found `i32` + | ^^^^^^ type mismatch resolving `::T == i64` error: aborting due to previous error diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr index ea1fdaf46f6ae..09651d91bef49 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr @@ -1,11 +1,14 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-6.rs:20:5 | +LL | type T = U; + | - expected this to be `i64` +... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... LL | is_obj(x) - | ^^^^^^ expected `i64`, found `i32` + | ^^^^^^ type mismatch resolving `::T == i64` error: aborting due to previous error diff --git a/src/test/ui/traits/bad-sized.stderr b/src/test/ui/traits/bad-sized.stderr index 768893d6e25d4..b3937095f7770 100644 --- a/src/test/ui/traits/bad-sized.stderr +++ b/src/test/ui/traits/bad-sized.stderr @@ -14,13 +14,13 @@ error[E0277]: the size for values of type `dyn Trait` cannot be known at compila | LL | let x: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | -LL | pub struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `dyn Trait` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time --> $DIR/bad-sized.rs:4:37 @@ -36,13 +36,13 @@ error[E0277]: the size for values of type `dyn Trait` cannot be known at compila | LL | let x: Vec = Vec::new(); | ^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - | -LL | pub struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `dyn Trait` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to 4 previous errors diff --git a/src/test/ui/traits/inductive-overflow/two-traits.stderr b/src/test/ui/traits/inductive-overflow/two-traits.stderr index 508a12d859a62..6a39a28df3501 100644 --- a/src/test/ui/traits/inductive-overflow/two-traits.stderr +++ b/src/test/ui/traits/inductive-overflow/two-traits.stderr @@ -1,11 +1,11 @@ error[E0277]: `T` cannot be shared between threads safely - --> $DIR/two-traits.rs:11:5 + --> $DIR/two-traits.rs:11:14 | LL | type X: Trait; | ----- required by this bound in `Magic::X` ... LL | type X = Self; - | ^^^^^^^^^^^^^^ `T` cannot be shared between threads safely + | ^^^^ `T` cannot be shared between threads safely | help: consider further restricting this bound | diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index 64cc0bab3f33c..7dd432bae688c 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,13 +1,19 @@ error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time - --> $DIR/issue-65673.rs:9:5 + --> $DIR/issue-65673.rs:9:16 | -LL | type Ctx; - | --------- required by this bound in `WithType::Ctx` -... LL | type Ctx = dyn Alias; - | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-65673.rs:4:5 + | +LL | type Ctx; + | ^^^^^^^^^ required by associated type `WithType::Ctx` +help: consider relaxing the `Sized` obligation + | +LL | type Ctx: ?Sized; + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/traits/mutual-recursion-issue-75860.stderr b/src/test/ui/traits/mutual-recursion-issue-75860.stderr index cf867ef78c3b1..484d5f814a100 100644 --- a/src/test/ui/traits/mutual-recursion-issue-75860.stderr +++ b/src/test/ui/traits/mutual-recursion-issue-75860.stderr @@ -3,13 +3,13 @@ error[E0275]: overflow evaluating the requirement `Option<_>: Sized` | LL | iso(left, right) | ^^^ - | - ::: $SRC_DIR/core/src/option.rs:LL:COL - | -LL | pub enum Option { - | - required by this bound in `Option` | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`mutual_recursion_issue_75860`) +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^ required by this bound in `Option` error: aborting due to previous error diff --git a/src/test/ui/traits/suggest-where-clause.stderr b/src/test/ui/traits/suggest-where-clause.stderr index 025706480821d..79748c3c2d349 100644 --- a/src/test/ui/traits/suggest-where-clause.stderr +++ b/src/test/ui/traits/suggest-where-clause.stderr @@ -6,11 +6,16 @@ LL | fn check() { LL | // suggest a where-clause, if needed LL | mem::size_of::(); | ^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` + | ^ required by this bound in `std::mem::size_of` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn check() { + | -- error[E0277]: the size for values of type `U` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:10:5 @@ -20,17 +25,21 @@ LL | fn check() { ... LL | mem::size_of::>(); | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` | note: required because it appears within the type `Misc` --> $DIR/suggest-where-clause.rs:3:8 | LL | struct Misc(T); | ^^^^ +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn check() { + | -- error[E0277]: the trait bound `u64: From` is not satisfied --> $DIR/suggest-where-clause.rs:15:5 @@ -69,26 +78,26 @@ error[E0277]: the size for values of type `[T]` cannot be known at compilation t | LL | mem::size_of::<[T]>(); | ^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` | = help: the trait `Sized` is not implemented for `[T]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error[E0277]: the size for values of type `[&U]` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:31:5 | LL | mem::size_of::<[&U]>(); | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` | = help: the trait `Sized` is not implemented for `[&U]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error: aborting due to 7 previous errors diff --git a/src/test/ui/union/union-sized-field.stderr b/src/test/ui/union/union-sized-field.stderr index b916bbe8ad10a..ef86c624e9b19 100644 --- a/src/test/ui/union/union-sized-field.stderr +++ b/src/test/ui/union/union-sized-field.stderr @@ -8,6 +8,10 @@ LL | value: T, | = note: no field of a union may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | union Foo { + | -- help: borrowed types always have a statically known size | LL | value: &T, @@ -27,6 +31,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct Foo2 { + | -- help: borrowed types always have a statically known size | LL | value: &T, @@ -46,6 +54,10 @@ LL | Value(T), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum Foo3 { + | -- help: borrowed types always have a statically known size | LL | Value(&T), diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index 19978ae24cacb..800194737ed3f 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -1,12 +1,20 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-bare-typaram.rs:2:29 | -LL | fn bar() { } - | - required by this bound in `bar` LL | fn foo() { bar::() } | - ^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bare-typaram.rs:1:8 + | +LL | fn bar() { } + | ^ required by this bound in `bar` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo() { bar::() } + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum.stderr b/src/test/ui/unsized/unsized-enum.stderr index 601db7d1cd983..d67459eaf980b 100644 --- a/src/test/ui/unsized/unsized-enum.stderr +++ b/src/test/ui/unsized/unsized-enum.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-enum.rs:6:36 | -LL | enum Foo { FooSome(U), FooNone } - | - required by this bound in `Foo` -LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } | - ^^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-enum.rs:4:10 + | +LL | enum Foo { FooSome(U), FooNone } + | ^ required by this bound in `Foo` help: you could relax the implicit `Sized` bound on `U` if it were used through indirection like `&U` or `Box` --> $DIR/unsized-enum.rs:4:10 | @@ -16,6 +18,10 @@ LL | enum Foo { FooSome(U), FooNone } | ^ - ...if indirection were used here: `Box` | | | this could be changed to `U: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo2() { not_sized::>() } + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum2.stderr b/src/test/ui/unsized/unsized-enum2.stderr index 1b6c85858159d..b9a03d904af4d 100644 --- a/src/test/ui/unsized/unsized-enum2.stderr +++ b/src/test/ui/unsized/unsized-enum2.stderr @@ -9,6 +9,10 @@ LL | VA(W), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VA(&W), @@ -29,6 +33,10 @@ LL | VB{x: X}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VB{x: &X}, @@ -49,6 +57,10 @@ LL | VC(isize, Y), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VC(isize, &Y), @@ -69,6 +81,10 @@ LL | VD{u: isize, x: Z}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VD{u: isize, x: &Z}, diff --git a/src/test/ui/unsized/unsized-fn-arg.fixed b/src/test/ui/unsized/unsized-fn-arg.fixed index 2c686c6c2b271..fd9b159a48138 100644 --- a/src/test/ui/unsized/unsized-fn-arg.fixed +++ b/src/test/ui/unsized/unsized-fn-arg.fixed @@ -2,5 +2,5 @@ #![crate_type="lib"] #![allow(unused)] -fn f(t: &T) {} +fn f(t: &T) {} //~^ ERROR the size for values of type `T` cannot be known at compilation time diff --git a/src/test/ui/unsized/unsized-fn-arg.stderr b/src/test/ui/unsized/unsized-fn-arg.stderr index 6b802ddf542d5..acb8a598d2c8a 100644 --- a/src/test/ui/unsized/unsized-fn-arg.stderr +++ b/src/test/ui/unsized/unsized-fn-arg.stderr @@ -7,6 +7,10 @@ LL | fn f(t: T) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f(t: T) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn f(t: &T) {} diff --git a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr index 9d072eda4e81c..42bc4c434911f 100644 --- a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-inherent-impl-self-type.rs:7:17 | -LL | struct S5(Y); - | - required by this bound in `S5` -LL | LL | impl S5 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-inherent-impl-self-type.rs:5:11 + | +LL | struct S5(Y); + | ^ required by this bound in `S5` help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-inherent-impl-self-type.rs:5:11 | @@ -16,6 +18,10 @@ LL | struct S5(Y); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `Y: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl S5 { + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index e38375bff46cf..a5c0184143409 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-struct.rs:6:36 | -LL | struct Foo { data: T } - | - required by this bound in `Foo` -LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } | - ^^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-struct.rs:4:12 + | +LL | struct Foo { data: T } + | ^ required by this bound in `Foo` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/unsized-struct.rs:4:12 | @@ -16,13 +18,14 @@ LL | struct Foo { data: T } | ^ - ...if indirection were used here: `Box` | | | this could be changed to `T: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo2() { not_sized::>() } + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-struct.rs:13:24 | -LL | fn is_sized() { } - | - required by this bound in `is_sized` -... LL | fn bar2() { is_sized::>() } | - ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | | @@ -33,6 +36,15 @@ note: required because it appears within the type `Bar` | LL | struct Bar { data: T } | ^^^ +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-struct.rs:1:13 + | +LL | fn is_sized() { } + | ^ required by this bound in `is_sized` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn bar2() { is_sized::>() } + | -- error: aborting due to 2 previous errors diff --git a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr index aef0d0cbb8395..4d2f0c0c1487b 100644 --- a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-trait-impl-self-type.rs:10:27 | -LL | struct S5(Y); - | - required by this bound in `S5` -LL | LL | impl T3 for S5 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-trait-impl-self-type.rs:8:11 + | +LL | struct S5(Y); + | ^ required by this bound in `S5` help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-trait-impl-self-type.rs:8:11 | @@ -16,6 +18,10 @@ LL | struct S5(Y); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `Y: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T3 for S5 { + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr index f48d4ef9f1461..5f792be56222a 100644 --- a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr @@ -1,14 +1,20 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-trait-impl-trait-arg.rs:8:17 | -LL | trait T2 { - | - required by this bound in `T2` -... LL | impl T2 for S4 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-trait-impl-trait-arg.rs:4:10 + | +LL | trait T2 { + | ^ required by this bound in `T2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T2 for S4 { + | -- help: consider relaxing the implicit `Sized` restriction | LL | trait T2 { diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr index bd36008aca044..fd64ca1b1aab1 100644 --- a/src/test/ui/unsized/unsized3.stderr +++ b/src/test/ui/unsized/unsized3.stderr @@ -5,10 +5,16 @@ LL | fn f1(x: &X) { | - this type parameter needs to be `std::marker::Sized` LL | f2::(x); | ^ doesn't have a size known at compile-time -... + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized3.rs:10:7 + | LL | fn f2(x: &X) { - | - required by this bound in `f2` + | ^ required by this bound in `f2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` | +LL | fn f1(x: &X) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f2(x: &X) { @@ -21,10 +27,16 @@ LL | fn f3(x: &X) { | - this type parameter needs to be `std::marker::Sized` LL | f4::(x); | ^ doesn't have a size known at compile-time -... + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized3.rs:21:7 + | LL | fn f4(x: &X) { - | - required by this bound in `f4` + | ^ required by this bound in `f4` +help: consider removing the `?Sized` bound to make the type parameter `Sized` | +LL | fn f3(x: &X) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f4(x: &X) { @@ -33,9 +45,6 @@ LL | fn f4(x: &X) { error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:33:8 | -LL | fn f5(x: &Y) {} - | - required by this bound in `f5` -... LL | fn f8(x1: &S, x2: &S) { | - this type parameter needs to be `std::marker::Sized` LL | f5(x1); @@ -46,6 +55,15 @@ note: required because it appears within the type `S` | LL | struct S { | ^ +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized3.rs:24:7 + | +LL | fn f5(x: &Y) {} + | ^ required by this bound in `f5` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f8(x1: &S, x2: &S) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} @@ -65,6 +83,10 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f9(x1: Box>) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:45:9 @@ -81,6 +103,10 @@ LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` = note: tuples must have a statically known size to be initialized +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f10(x1: Box>) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:45:8 @@ -99,6 +125,10 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f10(x1: Box>) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} diff --git a/src/test/ui/unsized/unsized5.stderr b/src/test/ui/unsized/unsized5.stderr index 0bfd4565529aa..6e5b355642932 100644 --- a/src/test/ui/unsized/unsized5.stderr +++ b/src/test/ui/unsized/unsized5.stderr @@ -8,6 +8,10 @@ LL | f1: X, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct S1 { + | -- help: borrowed types always have a statically known size | LL | f1: &X, @@ -28,6 +32,10 @@ LL | g: X, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct S2 { + | -- help: borrowed types always have a statically known size | LL | g: &X, @@ -83,6 +91,10 @@ LL | V1(X, isize), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | V1(&X, isize), @@ -102,6 +114,10 @@ LL | V2{f1: X, f: isize}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum F { + | -- help: borrowed types always have a statically known size | LL | V2{f1: &X, f: isize}, diff --git a/src/test/ui/unsized/unsized6.stderr b/src/test/ui/unsized/unsized6.stderr index 8e5734dffb145..5eff89d971fbb 100644 --- a/src/test/ui/unsized/unsized6.stderr +++ b/src/test/ui/unsized/unsized6.stderr @@ -9,6 +9,10 @@ LL | let y: Y; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:7:12 @@ -20,6 +24,10 @@ LL | let _: (isize, (X, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `Z` cannot be known at compilation time --> $DIR/unsized6.rs:11:12 @@ -31,6 +39,10 @@ LL | let y: (isize, (Z, usize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:15:9 @@ -42,6 +54,10 @@ LL | let y: X; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f2(x: &X) { + | -- error[E0277]: the size for values of type `Y` cannot be known at compilation time --> $DIR/unsized6.rs:17:12 @@ -53,6 +69,10 @@ LL | let y: (isize, (Y, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f2(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:22:9 @@ -64,6 +84,10 @@ LL | let y: X = *x1; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:24:9 @@ -76,6 +100,10 @@ LL | let y = *x2; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:26:10 @@ -88,6 +116,10 @@ LL | let (y, z) = (*x3, 4); | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:30:9 @@ -99,6 +131,10 @@ LL | let y: X = *x1; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:32:9 @@ -111,6 +147,10 @@ LL | let y = *x2; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:34:10 @@ -123,6 +163,10 @@ LL | let (y, z) = (*x3, 4); | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:38:18 @@ -133,6 +177,10 @@ LL | fn g1(x: X) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn g1(x: X) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn g1(x: &X) {} @@ -147,6 +195,10 @@ LL | fn g2(x: X) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn g2(x: X) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn g2(x: &X) {} diff --git a/src/test/ui/unsized/unsized7.stderr b/src/test/ui/unsized/unsized7.stderr index 7dbddd4ed2443..0512e47d9f1a0 100644 --- a/src/test/ui/unsized/unsized7.stderr +++ b/src/test/ui/unsized/unsized7.stderr @@ -1,14 +1,20 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized7.rs:12:21 | -LL | trait T1 { - | - required by this bound in `T1` -... LL | impl T1 for S3 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized7.rs:7:10 + | +LL | trait T1 { + | ^ required by this bound in `T1` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T1 for S3 { + | -- help: consider relaxing the implicit `Sized` restriction | LL | trait T1 { diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index e463e3db887a5..42a29dd5a6ee9 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -17,11 +17,13 @@ error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known | LL | fn bar() where Vec:, {} | ^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | struct Vec { - | - required by this bound in `Vec` | = help: the trait `Sized` is not implemented for `(dyn Copy + 'static)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/wf-fn-where-clause.rs:16:12 + | +LL | struct Vec { + | ^ required by this bound in `Vec` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/wf-fn-where-clause.rs:16:12 | diff --git a/src/test/ui/wf/wf-impl-self-type.stderr b/src/test/ui/wf/wf-impl-self-type.stderr index bc30fc90f3a28..fc31cd2cfe094 100644 --- a/src/test/ui/wf/wf-impl-self-type.stderr +++ b/src/test/ui/wf/wf-impl-self-type.stderr @@ -3,13 +3,13 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | LL | impl Foo for Option<[u8]> {} | ^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/option.rs:LL:COL - | -LL | pub enum Option { - | - required by this bound in `Option` | = help: the trait `Sized` is not implemented for `[u8]` +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^ required by this bound in `Option` error: aborting due to previous error diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 515b8887453b9..45525e4e38ca1 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.kind().skip_binder() { + if let Trait(trait_pred, _, _) = obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index e33a33e238633..7fd3ef48fc369 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { - Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => Some(pred), + Some(ty::PredicateKind::Trait(pred, _, _)) if pred.def_id() != sized_trait => Some(pred), _ => None, } }) diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs index 1c420a5042721..eae07ac92fb26 100644 --- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs +++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs @@ -43,7 +43,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); + if let PredicateKind::Trait(poly_trait_pred, _, _) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; 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 0e6ead675c247..36e690852a0af 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 @@ -36,7 +36,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index a92d3be5d3cf2..a1b3a310fd360 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -152,7 +152,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_predicate, _, _) = predicate.kind().skip_binder() { if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; }