diff --git a/src/librustc/traits/error_reporting/mod.rs b/src/librustc/traits/error_reporting/mod.rs index 28084c9d4ac49..6d3719b32d07e 100644 --- a/src/librustc/traits/error_reporting/mod.rs +++ b/src/librustc/traits/error_reporting/mod.rs @@ -27,7 +27,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_span::source_map::SourceMap; use rustc_span::{ExpnKind, Span, DUMMY_SP}; use std::fmt; use syntax::ast; @@ -1034,6 +1033,10 @@ pub fn report_object_safety_error( violations: Vec, ) -> DiagnosticBuilder<'tcx> { let trait_str = tcx.def_path_str(trait_def_id); + let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node { + hir::Node::Item(item) => Some(item.ident.span), + _ => None, + }); let span = tcx.sess.source_map().def_span(span); let mut err = struct_span_err!( tcx.sess, @@ -1045,14 +1048,45 @@ pub fn report_object_safety_error( err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str)); let mut reported_violations = FxHashSet::default(); + let mut had_span_label = false; for violation in violations { + if let ObjectSafetyViolation::SizedSelf(sp) = &violation { + if !sp.is_empty() { + // Do not report `SizedSelf` without spans pointing at `SizedSelf` obligations + // with a `Span`. + reported_violations.insert(ObjectSafetyViolation::SizedSelf(vec![].into())); + } + } if reported_violations.insert(violation.clone()) { - match violation.span() { - Some(span) => err.span_label(span, violation.error_msg()), - None => err.note(&violation.error_msg()), + let spans = violation.spans(); + let msg = if trait_span.is_none() || spans.is_empty() { + format!("the trait cannot be made into an object because {}", violation.error_msg()) + } else { + had_span_label = true; + format!("...because {}", violation.error_msg()) }; + if spans.is_empty() { + err.note(&msg); + } else { + for span in spans { + err.span_label(span, &msg); + } + } + match (trait_span, violation.solution()) { + (Some(_), Some((note, None))) => { + err.help(¬e); + } + (Some(_), Some((note, Some((sugg, span))))) => { + err.span_suggestion(span, ¬e, sugg, Applicability::MachineApplicable); + } + // Only provide the help if its a local trait, otherwise it's not actionable. + _ => {} + } } } + if let (Some(trait_span), true) = (trait_span, had_span_label) { + err.span_label(trait_span, "this trait cannot be made into an object..."); + } if tcx.sess.trait_methods_not_found.borrow().contains(&span) { // Avoid emitting error caused by non-existing method (#58734) @@ -1305,6 +1339,44 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &obligation.cause.code, &mut vec![], ); + self.suggest_unsized_bound_if_applicable(err, obligation); + } + } + + fn suggest_unsized_bound_if_applicable( + &self, + err: &mut DiagnosticBuilder<'_>, + obligation: &PredicateObligation<'tcx>, + ) { + if let ( + ty::Predicate::Trait(pred, _), + ObligationCauseCode::BindingObligation(item_def_id, span), + ) = (&obligation.predicate, &obligation.cause.code) + { + if let (Some(generics), true) = ( + self.tcx.hir().get_if_local(*item_def_id).as_ref().and_then(|n| n.generics()), + Some(pred.def_id()) == self.tcx.lang_items().sized_trait(), + ) { + for param in generics.params { + if param.span == *span + && !param.bounds.iter().any(|bound| { + bound.trait_def_id() == self.tcx.lang_items().sized_trait() + }) + { + let (span, separator) = match param.bounds { + [] => (span.shrink_to_hi(), ":"), + [.., bound] => (bound.span().shrink_to_hi(), " + "), + }; + err.span_suggestion( + span, + "consider relaxing the implicit `Sized` restriction", + format!("{} ?Sized", separator), + Applicability::MachineApplicable, + ); + return; + } + } + } } } @@ -1354,74 +1426,3 @@ impl ArgKind { } } } - -/// Suggest restricting a type param with a new bound. -pub fn suggest_constraining_type_param( - generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, - param_name: &str, - constraint: &str, - source_map: &SourceMap, - span: Span, -) -> bool { - let restrict_msg = "consider further restricting this bound"; - if let Some(param) = - generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next() - { - if param_name.starts_with("impl ") { - // `impl Trait` in argument: - // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}` - err.span_suggestion( - param.span, - restrict_msg, - // `impl CurrentTrait + MissingTrait` - format!("{} + {}", param_name, constraint), - Applicability::MachineApplicable, - ); - } else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() { - // If there are no bounds whatsoever, suggest adding a constraint - // to the type parameter: - // `fn foo(t: T) {}` → `fn foo(t: T) {}` - err.span_suggestion( - param.span, - "consider restricting this bound", - format!("{}: {}", param_name, constraint), - Applicability::MachineApplicable, - ); - } else if !generics.where_clause.predicates.is_empty() { - // There is a `where` clause, so suggest expanding it: - // `fn foo(t: T) where T: Debug {}` → - // `fn foo(t: T) where T: Debug, T: Trait {}` - err.span_suggestion( - generics.where_clause.span().unwrap().shrink_to_hi(), - &format!("consider further restricting type parameter `{}`", param_name), - format!(", {}: {}", param_name, constraint), - Applicability::MachineApplicable, - ); - } else { - // If there is no `where` clause lean towards constraining to the - // type parameter: - // `fn foo(t: T, x: X) {}` → `fn foo(t: T) {}` - // `fn foo(t: T) {}` → `fn foo(t: T) {}` - let sp = param.span.with_hi(span.hi()); - let span = source_map.span_through_char(sp, ':'); - if sp != param.span && sp != span { - // Only suggest if we have high certainty that the span - // covers the colon in `foo`. - err.span_suggestion( - span, - restrict_msg, - format!("{}: {} + ", param_name, constraint), - Applicability::MachineApplicable, - ); - } else { - err.span_label( - param.span, - &format!("consider adding a `where {}: {}` bound", param_name, constraint), - ); - } - } - return true; - } - false -} diff --git a/src/librustc/traits/error_reporting/suggestions.rs b/src/librustc/traits/error_reporting/suggestions.rs index 72629c6a3cffa..c1facd34dfee5 100644 --- a/src/librustc/traits/error_reporting/suggestions.rs +++ b/src/librustc/traits/error_reporting/suggestions.rs @@ -145,12 +145,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let param_name = self_ty.to_string(); let constraint = trait_ref.print_only_trait_path().to_string(); if suggest_constraining_type_param( + self.tcx, generics, &mut err, ¶m_name, &constraint, self.tcx.sess.source_map(), *span, + Some(trait_ref.def_id()), ) { return; } @@ -1652,18 +1654,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// Suggest restricting a type param with a new bound. pub fn suggest_constraining_type_param( + tcx: TyCtxt<'_>, generics: &hir::Generics<'_>, err: &mut DiagnosticBuilder<'_>, param_name: &str, constraint: &str, source_map: &SourceMap, span: Span, + def_id: Option, ) -> bool { let restrict_msg = "consider further restricting this bound"; if let Some(param) = generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next() { - if param_name.starts_with("impl ") { + 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), + ); + } else if param_name.starts_with("impl ") { // `impl Trait` in argument: // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}` err.span_suggestion( diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 15f81bb3f47ed..d0dbfe73c91d5 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -13,24 +13,26 @@ use super::elaborate_predicates; use crate::traits::{self, Obligation, ObligationCause}; use crate::ty::subst::{InternalSubsts, Subst}; use crate::ty::{self, Predicate, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness}; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; +use smallvec::{smallvec, SmallVec}; use syntax::ast; use std::borrow::Cow; use std::iter::{self}; -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum ObjectSafetyViolation { /// `Self: Sized` declared on the trait. - SizedSelf, + SizedSelf(SmallVec<[Span; 1]>), /// Supertrait reference references `Self` an in illegal location /// (e.g., `trait Foo : Bar`). - SupertraitSelf, + SupertraitSelf(SmallVec<[Span; 1]>), /// Method has something illegal. Method(ast::Name, MethodViolationCode, Span), @@ -42,50 +44,91 @@ pub enum ObjectSafetyViolation { impl ObjectSafetyViolation { pub fn error_msg(&self) -> Cow<'static, str> { match *self { - ObjectSafetyViolation::SizedSelf => { - "the trait cannot require that `Self : Sized`".into() - } - ObjectSafetyViolation::SupertraitSelf => { - "the trait cannot use `Self` as a type parameter \ - in the supertraits or where-clauses" - .into() + ObjectSafetyViolation::SizedSelf(_) => "it requires `Self: Sized`".into(), + ObjectSafetyViolation::SupertraitSelf(ref spans) => { + if spans.iter().any(|sp| *sp != DUMMY_SP) { + "it uses `Self` as a type parameter in this".into() + } else { + "it cannot use `Self` as a type parameter in a supertrait or `where`-clause" + .into() + } } - ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => { + ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => { format!("associated function `{}` has no `self` parameter", name).into() } - ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!( - "method `{}` references the `Self` type in its parameters or return type", + ObjectSafetyViolation::Method( name, - ) - .into(), + MethodViolationCode::ReferencesSelfInput(_), + DUMMY_SP, + ) => format!("method `{}` references the `Self` type in its parameters", name).into(), + ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfInput(_), _) => { + format!("method `{}` references the `Self` type in this parameter", name).into() + } + ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfOutput, _) => { + format!("method `{}` references the `Self` type in its return type", name).into() + } ObjectSafetyViolation::Method( name, MethodViolationCode::WhereClauseReferencesSelf, _, - ) => format!("method `{}` references the `Self` type in where clauses", name).into(), + ) => { + format!("method `{}` references the `Self` type in its `where` clause", name).into() + } ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) => { format!("method `{}` has generic type parameters", name).into() } ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => { format!("method `{}`'s `self` parameter cannot be dispatched on", name).into() } - ObjectSafetyViolation::AssocConst(name, _) => { - format!("the trait cannot contain associated consts like `{}`", name).into() + ObjectSafetyViolation::AssocConst(name, DUMMY_SP) => { + format!("it contains associated `const` `{}`", name).into() } + ObjectSafetyViolation::AssocConst(..) => "it contains this associated `const`".into(), } } - pub fn span(&self) -> Option { + pub fn solution(&self) -> Option<(String, Option<(String, Span)>)> { + Some(match *self { + ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => { + return None; + } + ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(sugg), _) => ( + format!( + "consider turning `{}` into a method by giving it a `&self` argument or \ + constraining it so it does not apply to trait objects", + name + ), + sugg.map(|(sugg, sp)| (sugg.to_string(), sp)), + ), + ObjectSafetyViolation::Method( + name, + MethodViolationCode::UndispatchableReceiver, + span, + ) => ( + format!("consider changing method `{}`'s `self` parameter to be `&self`", name) + .into(), + Some(("&Self".to_string(), span)), + ), + ObjectSafetyViolation::AssocConst(name, _) + | ObjectSafetyViolation::Method(name, ..) => { + (format!("consider moving `{}` to another trait", name), None) + } + }) + } + + pub fn spans(&self) -> SmallVec<[Span; 1]> { // When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so // diagnostics use a `note` instead of a `span_label`. - match *self { + match self { + ObjectSafetyViolation::SupertraitSelf(spans) + | ObjectSafetyViolation::SizedSelf(spans) => spans.clone(), ObjectSafetyViolation::AssocConst(_, span) | ObjectSafetyViolation::Method(_, _, span) - if span != DUMMY_SP => + if *span != DUMMY_SP => { - Some(span) + smallvec![*span] } - _ => None, + _ => smallvec![], } } } @@ -94,10 +137,13 @@ impl ObjectSafetyViolation { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum MethodViolationCode { /// e.g., `fn foo()` - StaticMethod, + StaticMethod(Option<(&'static str, Span)>), + + /// e.g., `fn foo(&self, x: Self)` + ReferencesSelfInput(usize), - /// e.g., `fn foo(&self, x: Self)` or `fn foo(&self) -> Self` - ReferencesSelf, + /// e.g., `fn foo(&self) -> Self` + ReferencesSelfOutput, /// e.g., `fn foo(&self) where Self: Clone` WhereClauseReferencesSelf, @@ -119,8 +165,9 @@ pub fn astconv_object_safety_violations( ) -> Vec { debug_assert!(tcx.generics_of(trait_def_id).has_self); let violations = traits::supertrait_def_ids(tcx, trait_def_id) - .filter(|&def_id| predicates_reference_self(tcx, def_id, true)) - .map(|_| ObjectSafetyViolation::SupertraitSelf) + .map(|def_id| predicates_reference_self(tcx, def_id, true)) + .filter(|spans| !spans.is_empty()) + .map(|spans| ObjectSafetyViolation::SupertraitSelf(spans)) .collect(); debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", trait_def_id, violations); @@ -168,7 +215,7 @@ fn object_safety_violations_for_trait( .filter(|item| item.kind == ty::AssocKind::Method) .filter_map(|item| { object_safety_violation_for_method(tcx, trait_def_id, &item) - .map(|code| ObjectSafetyViolation::Method(item.ident.name, code, item.ident.span)) + .map(|(code, span)| ObjectSafetyViolation::Method(item.ident.name, code, span)) }) .filter(|violation| { if let ObjectSafetyViolation::Method( @@ -179,7 +226,7 @@ fn object_safety_violations_for_trait( { // Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id. // It's also hard to get a use site span, so we use the method definition span. - tcx.struct_span_lint_hir( + let mut err = tcx.struct_span_lint_hir( WHERE_CLAUSES_OBJECT_SAFETY, hir::CRATE_HIR_ID, *span, @@ -187,9 +234,29 @@ fn object_safety_violations_for_trait( "the trait `{}` cannot be made into an object", tcx.def_path_str(trait_def_id) ), - ) - .note(&violation.error_msg()) - .emit(); + ); + let node = tcx.hir().get_if_local(trait_def_id); + let msg = if let Some(hir::Node::Item(item)) = node { + err.span_label(item.ident.span, "this trait cannot be made into an object..."); + format!("...because {}", violation.error_msg()) + } else { + format!( + "the trait cannot be made into an object because {}", + violation.error_msg() + ) + }; + err.span_label(*span, &msg); + match (node, violation.solution()) { + (Some(_), Some((note, None))) => { + err.help(¬e); + } + (Some(_), Some((note, Some((sugg, span))))) => { + err.span_suggestion(span, ¬e, sugg, Applicability::MachineApplicable); + } + // Only provide the help if its a local trait, otherwise it's not actionable. + _ => {} + } + err.emit(); false } else { true @@ -199,10 +266,13 @@ fn object_safety_violations_for_trait( // Check the trait itself. if trait_has_sized_self(tcx, trait_def_id) { - violations.push(ObjectSafetyViolation::SizedSelf); + // We don't want to include the requirement from `Sized` itself to be `Sized` in the list. + let spans = get_sized_bounds(tcx, trait_def_id); + violations.push(ObjectSafetyViolation::SizedSelf(spans)); } - if predicates_reference_self(tcx, trait_def_id, false) { - violations.push(ObjectSafetyViolation::SupertraitSelf); + let spans = predicates_reference_self(tcx, trait_def_id, false); + if !spans.is_empty() { + violations.push(ObjectSafetyViolation::SupertraitSelf(spans)); } violations.extend( @@ -219,7 +289,64 @@ fn object_safety_violations_for_trait( violations } -fn predicates_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId, supertraits_only: bool) -> bool { +fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> { + tcx.hir() + .get_if_local(trait_def_id) + .and_then(|node| match node { + hir::Node::Item(hir::Item { + kind: hir::ItemKind::Trait(.., generics, bounds, _), + .. + }) => Some( + generics + .where_clause + .predicates + .iter() + .filter_map(|pred| { + match pred { + hir::WherePredicate::BoundPredicate(pred) + if pred.bounded_ty.hir_id.owner_def_id() == trait_def_id => + { + // Fetch spans for trait bounds that are Sized: + // `trait T where Self: Pred` + Some(pred.bounds.iter().filter_map(|b| match b { + hir::GenericBound::Trait( + trait_ref, + hir::TraitBoundModifier::None, + ) if trait_has_sized_self( + tcx, + trait_ref.trait_ref.trait_def_id(), + ) => + { + Some(trait_ref.span) + } + _ => None, + })) + } + _ => None, + } + }) + .flatten() + .chain(bounds.iter().filter_map(|b| match b { + hir::GenericBound::Trait(trait_ref, hir::TraitBoundModifier::None) + if trait_has_sized_self(tcx, trait_ref.trait_ref.trait_def_id()) => + { + // Fetch spans for supertraits that are `Sized`: `trait T: Super` + Some(trait_ref.span) + } + _ => None, + })) + .collect::>(), + ), + _ => None, + }) + .unwrap_or_else(SmallVec::new) +} + +fn predicates_reference_self( + tcx: TyCtxt<'_>, + trait_def_id: DefId, + supertraits_only: bool, +) -> SmallVec<[Span; 1]> { let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id)); let predicates = if supertraits_only { tcx.super_predicates_of(trait_def_id) @@ -231,12 +358,16 @@ fn predicates_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId, supertraits_o predicates .predicates .iter() - .map(|(predicate, _)| predicate.subst_supertrait(tcx, &trait_ref)) - .any(|predicate| { + .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp)) + .filter_map(|(predicate, &sp)| { match predicate { ty::Predicate::Trait(ref data, _) => { // In the case of a trait predicate, we can skip the "self" type. - data.skip_binder().input_types().skip(1).any(has_self_ty) + if data.skip_binder().input_types().skip(1).any(has_self_ty) { + Some(sp) + } else { + None + } } ty::Predicate::Projection(ref data) => { // And similarly for projections. This should be redundant with @@ -251,12 +382,18 @@ fn predicates_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId, supertraits_o // // This is ALT2 in issue #56288, see that for discussion of the // possible alternatives. - data.skip_binder() + if data + .skip_binder() .projection_ty .trait_ref(tcx) .input_types() .skip(1) .any(has_self_ty) + { + Some(sp) + } else { + None + } } ty::Predicate::WellFormed(..) | ty::Predicate::ObjectSafe(..) @@ -264,9 +401,10 @@ fn predicates_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId, supertraits_o | ty::Predicate::RegionOutlives(..) | ty::Predicate::ClosureKind(..) | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) => false, + | ty::Predicate::ConstEvaluatable(..) => None, } }) + .collect() } fn trait_has_sized_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool { @@ -304,7 +442,7 @@ fn object_safety_violation_for_method( tcx: TyCtxt<'_>, trait_def_id: DefId, method: &ty::AssocItem, -) -> Option { +) -> Option<(MethodViolationCode, Span)> { debug!("object_safety_violation_for_method({:?}, {:?})", trait_def_id, method); // Any method that has a `Self : Sized` requisite is otherwise // exempt from the regulations. @@ -312,7 +450,26 @@ fn object_safety_violation_for_method( return None; } - virtual_call_violation_for_method(tcx, trait_def_id, method) + let violation = virtual_call_violation_for_method(tcx, trait_def_id, method); + // Get an accurate span depending on the violation. + violation.map(|v| { + let node = tcx.hir().get_if_local(method.def_id); + let span = match (v, node) { + (MethodViolationCode::ReferencesSelfInput(arg), Some(node)) => node + .fn_decl() + .and_then(|decl| decl.inputs.get(arg + 1)) + .map_or(method.ident.span, |arg| arg.span), + (MethodViolationCode::UndispatchableReceiver, Some(node)) => node + .fn_decl() + .and_then(|decl| decl.inputs.get(0)) + .map_or(method.ident.span, |arg| arg.span), + (MethodViolationCode::ReferencesSelfOutput, Some(node)) => { + node.fn_decl().map_or(method.ident.span, |decl| decl.output.span()) + } + _ => method.ident.span, + }; + (v, span) + }) } /// Returns `Some(_)` if this method cannot be called on a trait @@ -326,18 +483,26 @@ fn virtual_call_violation_for_method<'tcx>( ) -> Option { // The method's first parameter must be named `self` if !method.method_has_self_argument { - return Some(MethodViolationCode::StaticMethod); + // We'll attempt to provide a structured suggestion for `Self: Sized`. + let sugg = + tcx.hir().get_if_local(method.def_id).as_ref().and_then(|node| node.generics()).map( + |generics| match generics.where_clause.predicates { + [] => (" where Self: Sized", generics.where_clause.span), + [.., pred] => (", Self: Sized", pred.span().shrink_to_hi()), + }, + ); + return Some(MethodViolationCode::StaticMethod(sugg)); } let sig = tcx.fn_sig(method.def_id); - for input_ty in &sig.skip_binder().inputs()[1..] { + for (i, input_ty) in sig.skip_binder().inputs()[1..].iter().enumerate() { if contains_illegal_self_type_reference(tcx, trait_def_id, input_ty) { - return Some(MethodViolationCode::ReferencesSelf); + return Some(MethodViolationCode::ReferencesSelfInput(i)); } } if contains_illegal_self_type_reference(tcx, trait_def_id, sig.output().skip_binder()) { - return Some(MethodViolationCode::ReferencesSelf); + return Some(MethodViolationCode::ReferencesSelfOutput); } // We can't monomorphize things like `fn foo(...)`. diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index f417b907a3811..0781feee84541 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1015,6 +1015,7 @@ impl<'tcx> GenericPredicates<'tcx> { ) -> InstantiatedPredicates<'tcx> { InstantiatedPredicates { predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(), + spans: self.predicates.iter().map(|(_, sp)| *sp).collect(), } } @@ -1028,6 +1029,7 @@ impl<'tcx> GenericPredicates<'tcx> { tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs); } instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p.subst(tcx, substs))); + instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp)); } pub fn instantiate_identity(&self, tcx: TyCtxt<'tcx>) -> InstantiatedPredicates<'tcx> { @@ -1044,7 +1046,8 @@ impl<'tcx> GenericPredicates<'tcx> { if let Some(def_id) = self.parent { tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated); } - instantiated.predicates.extend(self.predicates.iter().map(|&(p, _)| p)) + instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p)); + instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s)); } pub fn instantiate_supertrait( @@ -1059,6 +1062,7 @@ impl<'tcx> GenericPredicates<'tcx> { .iter() .map(|(pred, _)| pred.subst_supertrait(tcx, poly_trait_ref)) .collect(), + spans: self.predicates.iter().map(|(_, sp)| *sp).collect(), } } } @@ -1511,11 +1515,12 @@ impl<'tcx> Predicate<'tcx> { #[derive(Clone, Debug, TypeFoldable)] pub struct InstantiatedPredicates<'tcx> { pub predicates: Vec>, + pub spans: Vec, } impl<'tcx> InstantiatedPredicates<'tcx> { pub fn empty() -> InstantiatedPredicates<'tcx> { - InstantiatedPredicates { predicates: vec![] } + InstantiatedPredicates { predicates: vec![], spans: vec![] } } pub fn is_empty(&self) -> bool { diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 0db75454aee38..3ed0ad16eebf2 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -2631,4 +2631,25 @@ impl Node<'_> { _ => None, } } + + pub fn fn_decl(&self) -> Option<&FnDecl<'_>> { + match self { + Node::TraitItem(TraitItem { kind: TraitItemKind::Method(fn_sig, _), .. }) + | Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. }) + | Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl), + Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => { + Some(fn_decl) + } + _ => None, + } + } + + pub fn generics(&self) -> Option<&Generics<'_>> { + match self { + Node::TraitItem(TraitItem { generics, .. }) + | Node::ImplItem(ImplItem { generics, .. }) + | Node::Item(Item { kind: ItemKind::Fn(_, generics, _), .. }) => Some(generics), + _ => None, + } + } } diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index a8e534a9f650c..b0b9790abb12a 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -3,7 +3,7 @@ use rustc::mir::{ FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, VarBindingForm, }; -use rustc::traits::error_reporting::suggest_constraining_type_param; +use rustc::traits::error_reporting::suggestions::suggest_constraining_type_param; use rustc::ty::{self, Ty}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; @@ -217,12 +217,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id)) { suggest_constraining_type_param( + tcx, generics, &mut err, ¶m.name.as_str(), "Copy", tcx.sess.source_map(), span, + None, ); } } diff --git a/src/librustc_parse/parser/generics.rs b/src/librustc_parse/parser/generics.rs index 075583711f5d3..0984263bb283e 100644 --- a/src/librustc_parse/parser/generics.rs +++ b/src/librustc_parse/parser/generics.rs @@ -172,7 +172,7 @@ impl<'a> Parser<'a> { /// ``` pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> { let mut where_clause = - WhereClause { predicates: Vec::new(), span: self.prev_span.to(self.prev_span) }; + WhereClause { predicates: Vec::new(), span: self.prev_span.shrink_to_hi() }; if !self.eat_keyword(kw::Where) { return Ok(where_clause); diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index 7df27e67d5b1c..0e26e9461f4c3 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -161,7 +161,7 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> { } // Compute the bounds on `Self` and the type parameters. - let ty::InstantiatedPredicates { predicates } = + let ty::InstantiatedPredicates { predicates, .. } = tcx.predicates_of(def_id).instantiate_identity(tcx); let clauses = predicates diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 8f882be1a090e..9f867cf8ab464 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -228,7 +228,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { } // Compute the bounds on Self and the type parameters. - let ty::InstantiatedPredicates { predicates } = + let ty::InstantiatedPredicates { predicates, .. } = tcx.predicates_of(def_id).instantiate_identity(tcx); // Finally, we have to normalize the bounds in the environment, in diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 832aa9f62ff4d..eee9dc99d35b4 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> { pub struct ConfirmResult<'tcx> { pub callee: MethodCallee<'tcx>, - pub illegal_sized_bound: bool, + pub illegal_sized_bound: Option, } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -112,7 +112,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // Add any trait/regions obligations specified on the method's type parameters. // We won't add these if we encountered an illegal sized bound, so that we can use // a custom error in that case. - if !illegal_sized_bound { + if illegal_sized_bound.is_none() { let method_ty = self.tcx.mk_fn_ptr(ty::Binder::bind(method_sig)); self.add_obligations(method_ty, all_substs, &method_predicates); } @@ -561,23 +561,31 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { fn predicates_require_illegal_sized_bound( &self, predicates: &ty::InstantiatedPredicates<'tcx>, - ) -> bool { + ) -> Option { let sized_def_id = match self.tcx.lang_items().sized_trait() { Some(def_id) => def_id, - None => return false, + None => return None, }; traits::elaborate_predicates(self.tcx, predicates.predicates.clone()) .filter_map(|predicate| match predicate { ty::Predicate::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { - Some(trait_pred) + let span = predicates + .predicates + .iter() + .zip(predicates.spans.iter()) + .filter_map(|(p, span)| if *p == predicate { Some(*span) } else { None }) + .next() + .unwrap_or(rustc_span::DUMMY_SP); + Some((trait_pred, span)) } _ => None, }) - .any(|trait_pred| match trait_pred.skip_binder().self_ty().kind { - ty::Dynamic(..) => true, - _ => false, + .filter_map(|(trait_pred, span)| match trait_pred.skip_binder().self_ty().kind { + ty::Dynamic(..) => Some(span), + _ => None, }) + .next() } fn enforce_illegal_method_limitations(&self, pick: &probe::Pick<'_>) { diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index c1cf3522b5d9c..e90c2ef5e4361 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -58,7 +58,7 @@ pub enum MethodError<'tcx> { // Found a `Self: Sized` bound where `Self` is a trait object, also the caller may have // forgotten to import a trait. - IllegalSizedBound(Vec, bool), + IllegalSizedBound(Vec, bool, Span), // Found a match, but the return type is wrong BadReturnType, @@ -204,7 +204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let result = self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment); - if result.illegal_sized_bound { + if let Some(span) = result.illegal_sized_bound { let mut needs_mut = false; if let ty::Ref(region, t_type, mutability) = self_ty.kind { let trait_type = self @@ -249,7 +249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => Vec::new(), }; - return Err(IllegalSizedBound(candidates, needs_mut)); + return Err(IllegalSizedBound(candidates, needs_mut, span)); } Ok(result.callee) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 490c69b55362b..789bac2705b07 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -640,9 +640,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } - MethodError::IllegalSizedBound(candidates, needs_mut) => { + MethodError::IllegalSizedBound(candidates, needs_mut, bound_span) => { let msg = format!("the `{}` method cannot be invoked on a trait object", item_name); let mut err = self.sess().struct_span_err(span, &msg); + err.span_label(bound_span, "this has a `Sized` requirement"); if !candidates.is_empty() { let help = format!( "{an}other candidate{s} {were} found in the following trait{s}, perhaps \ diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 82811826ae7e7..fc194e3af97f2 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -10,7 +10,7 @@ use rustc::ty::{ self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness, }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{struct_span_err, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir::def_id::DefId; use rustc_hir::ItemKind; use rustc_span::symbol::sym; @@ -176,9 +176,72 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) { hir::TraitItemKind::Method(ref sig, _) => Some(sig), _ => None, }; + check_object_unsafe_self_trait_by_name(tcx, &trait_item); check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig); } +fn could_be_self(trait_def_id: DefId, ty: &hir::Ty<'_>) -> bool { + match ty.kind { + hir::TyKind::TraitObject([trait_ref], ..) => match trait_ref.trait_ref.path.segments { + [s] => s.res.and_then(|r| r.opt_def_id()) == Some(trait_def_id), + _ => false, + }, + _ => false, + } +} + +/// Detect when an object unsafe trait is referring to itself in one of its associated items. +/// When this is done, suggest using `Self` instead. +fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) { + let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id)) { + hir::Node::Item(item) => match item.kind { + hir::ItemKind::Trait(..) => (item.ident, tcx.hir().local_def_id(item.hir_id)), + _ => return, + }, + _ => return, + }; + let mut trait_should_be_self = vec![]; + match &item.kind { + hir::TraitItemKind::Const(ty, _) | hir::TraitItemKind::Type(_, Some(ty)) + if could_be_self(trait_def_id, ty) => + { + trait_should_be_self.push(ty.span) + } + hir::TraitItemKind::Method(sig, _) => { + for ty in sig.decl.inputs { + if could_be_self(trait_def_id, ty) { + trait_should_be_self.push(ty.span); + } + } + match sig.decl.output { + hir::FunctionRetTy::Return(ty) if could_be_self(trait_def_id, ty) => { + trait_should_be_self.push(ty.span); + } + _ => {} + } + } + _ => {} + } + if !trait_should_be_self.is_empty() { + if rustc::traits::object_safety_violations(tcx, trait_def_id).is_empty() { + return; + } + let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect(); + tcx.sess + .struct_span_err( + trait_should_be_self, + "associated item referring to unboxed trait object for its own trait", + ) + .span_label(trait_name.span, "in this trait") + .multipart_suggestion( + "you might have meant to use `Self` to refer to the implementing type", + sugg, + Applicability::MachineApplicable, + ) + .emit(); + } +} + pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); let impl_item = tcx.hir().expect_impl_item(hir_id); @@ -219,9 +282,17 @@ fn check_associated_item( ty::AssocKind::Method => { let sig = fcx.tcx.fn_sig(item.def_id); let sig = fcx.normalize_associated_types_in(span, &sig); - check_fn_or_method(tcx, fcx, span, sig, item.def_id, &mut implied_bounds); - let sig_if_method = sig_if_method.expect("bad signature for method"); - check_method_receiver(fcx, sig_if_method, &item, self_ty); + let hir_sig = sig_if_method.expect("bad signature for method"); + check_fn_or_method( + tcx, + fcx, + item.ident.span, + sig, + hir_sig, + item.def_id, + &mut implied_bounds, + ); + check_method_receiver(fcx, hir_sig, &item, self_ty); } ty::AssocKind::Type => { if item.defaultness.has_value() { @@ -364,7 +435,11 @@ fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { let sig = fcx.tcx.fn_sig(def_id); let sig = fcx.normalize_associated_types_in(item.span, &sig); let mut implied_bounds = vec![]; - check_fn_or_method(tcx, fcx, item.span, sig, def_id, &mut implied_bounds); + let hir_sig = match &item.kind { + ItemKind::Fn(sig, ..) => sig, + _ => bug!("expected `ItemKind::Fn`, found `{:?}`", item.kind), + }; + check_fn_or_method(tcx, fcx, item.ident.span, sig, hir_sig, def_id, &mut implied_bounds); implied_bounds }) } @@ -452,7 +527,7 @@ fn check_where_clauses<'tcx, 'fcx>( fcx: &FnCtxt<'fcx, 'tcx>, span: Span, def_id: DefId, - return_ty: Option>, + return_ty: Option<(Ty<'tcx>, Span)>, ) { debug!("check_where_clauses(def_id={:?}, return_ty={:?})", def_id, return_ty); @@ -586,17 +661,22 @@ fn check_where_clauses<'tcx, 'fcx>( let mut predicates = predicates.instantiate_identity(fcx.tcx); - if let Some(return_ty) = return_ty { - predicates.predicates.extend(check_opaque_types(tcx, fcx, def_id, span, return_ty)); + if let Some((return_ty, span)) = return_ty { + let opaque_types = check_opaque_types(tcx, fcx, def_id, span, return_ty); + for _ in 0..opaque_types.len() { + predicates.spans.push(span); + } + predicates.predicates.extend(opaque_types); } let predicates = fcx.normalize_associated_types_in(span, &predicates); debug!("check_where_clauses: predicates={:?}", predicates.predicates); - let wf_obligations = predicates - .predicates - .iter() - .flat_map(|p| traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, span)); + assert_eq!(predicates.predicates.len(), predicates.spans.len()); + let wf_obligations = + predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(p, sp)| { + traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, *sp) + }); for obligation in wf_obligations.chain(default_obligations) { debug!("next obligation cause: {:?}", obligation.cause); @@ -609,23 +689,28 @@ fn check_fn_or_method<'fcx, 'tcx>( fcx: &FnCtxt<'fcx, 'tcx>, span: Span, sig: ty::PolyFnSig<'tcx>, + hir_sig: &hir::FnSig<'_>, def_id: DefId, implied_bounds: &mut Vec>, ) { let sig = fcx.normalize_associated_types_in(span, &sig); let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig); - for input_ty in sig.inputs() { + for (input_ty, span) in sig.inputs().iter().zip(hir_sig.decl.inputs.iter().map(|t| t.span)) { fcx.register_wf_obligation(&input_ty, span, ObligationCauseCode::MiscObligation); } implied_bounds.extend(sig.inputs()); - fcx.register_wf_obligation(sig.output(), span, ObligationCauseCode::ReturnType); + fcx.register_wf_obligation( + sig.output(), + hir_sig.decl.output.span(), + ObligationCauseCode::ReturnType, + ); // FIXME(#25759) return types should not be implied bounds implied_bounds.push(sig.output()); - check_where_clauses(tcx, fcx, span, def_id, Some(sig.output())); + check_where_clauses(tcx, fcx, span, def_id, Some((sig.output(), hir_sig.decl.output.span()))); } /// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions diff --git a/src/test/ui/associated-const/associated-const-in-trait.stderr b/src/test/ui/associated-const/associated-const-in-trait.stderr index a5d7fc5b70246..a8a8d01ed78fb 100644 --- a/src/test/ui/associated-const/associated-const-in-trait.stderr +++ b/src/test/ui/associated-const/associated-const-in-trait.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/associated-const-in-trait.rs:9:6 | +LL | trait Trait { + | ----- this trait cannot be made into an object... LL | const N: usize; - | - the trait cannot contain associated consts like `N` + | - ...because it contains this associated `const` ... LL | impl dyn Trait { | ^^^^^^^^^ the trait `Trait` cannot be made into an object + | + = help: consider moving `N` to another trait error: aborting due to previous error diff --git a/src/test/ui/associated-item/issue-48027.stderr b/src/test/ui/associated-item/issue-48027.stderr index ddabd552897a8..62a380732a8bb 100644 --- a/src/test/ui/associated-item/issue-48027.stderr +++ b/src/test/ui/associated-item/issue-48027.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/issue-48027.rs:6:6 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | const X: usize; - | - the trait cannot contain associated consts like `X` + | - ...because it contains this associated `const` ... LL | impl dyn Bar {} | ^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `X` to another trait error[E0283]: type annotations needed --> $DIR/issue-48027.rs:3:32 diff --git a/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr b/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr index 5303a09644d50..efd5a92a4fced 100644 --- a/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr +++ b/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr @@ -7,76 +7,49 @@ LL | impl Case1 for S1 { = help: the trait `for<'a> std::fmt::Debug` is not implemented for `>::App` error[E0277]: `<::C as std::iter::Iterator>::Item` is not an iterator - --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1 + --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20 | -LL | fn assume_case1() { - | ^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::iter::Iterator` - | _| - | | -LL | | -LL | | -LL | | -... | -LL | | assert_c::<_, _, _, T::C>(); -LL | | } - | |_^ `<::C as std::iter::Iterator>::Item` is not an iterator +LL | fn assume_case1() { + | ^^^^^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::iter::Iterator` + | | + | `<::C as std::iter::Iterator>::Item` is not an iterator | = help: the trait `std::iter::Iterator` is not implemented for `<::C as std::iter::Iterator>::Item` error[E0277]: `<::C as std::iter::Iterator>::Item` cannot be sent between threads safely - --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1 + --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20 | -LL | trait Case1 { - | ----------- required by `Case1` +LL | trait Case1 { + | ----------- required by `Case1` ... -LL | fn assume_case1() { - | ^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::marker::Send` - | _| - | | -LL | | -LL | | -LL | | -... | -LL | | assert_c::<_, _, _, T::C>(); -LL | | } - | |_^ `<::C as std::iter::Iterator>::Item` cannot be sent between threads safely +LL | fn assume_case1() { + | ^^^^^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::marker::Send` + | | + | `<::C as std::iter::Iterator>::Item` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `<::C as std::iter::Iterator>::Item` error[E0277]: `<::C as std::iter::Iterator>::Item` cannot be shared between threads safely - --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1 + --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20 | -LL | trait Case1 { - | ----------- required by `Case1` +LL | trait Case1 { + | ----------- required by `Case1` ... -LL | fn assume_case1() { - | ^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::marker::Sync` - | _| - | | -LL | | -LL | | -LL | | -... | -LL | | assert_c::<_, _, _, T::C>(); -LL | | } - | |_^ `<::C as std::iter::Iterator>::Item` cannot be shared between threads safely +LL | fn assume_case1() { + | ^^^^^ - help: consider further restricting the associated type: `where <::C as std::iter::Iterator>::Item: std::marker::Sync` + | | + | `<::C as std::iter::Iterator>::Item` cannot be shared between threads safely | = help: the trait `std::marker::Sync` is not implemented for `<::C as std::iter::Iterator>::Item` error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug` - --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1 + --> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20 | -LL | trait Case1 { - | ----------- required by `Case1` +LL | trait Case1 { + | ----------- required by `Case1` ... -LL | / fn assume_case1() { -LL | | -LL | | -LL | | -... | -LL | | assert_c::<_, _, _, T::C>(); -LL | | } - | |_^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` +LL | fn assume_case1() { + | ^^^^^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `for<'a> std::fmt::Debug` is not implemented for `<_ as Lam<&'a u8>>::App` diff --git a/src/test/ui/associated-types/associated-types-overridden-binding.stderr b/src/test/ui/associated-types/associated-types-overridden-binding.stderr index 069da955b674e..9e10ed7b72952 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding.stderr @@ -1,20 +1,20 @@ error[E0284]: type annotations needed - --> $DIR/associated-types-overridden-binding.rs:4:1 + --> $DIR/associated-types-overridden-binding.rs:4:12 | LL | trait Foo: Iterator {} | ------------------------------- required by `Foo` LL | trait Bar: Foo {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` + | ^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | = note: cannot resolve `::Item == i32` error[E0284]: type annotations needed - --> $DIR/associated-types-overridden-binding.rs:7:1 + --> $DIR/associated-types-overridden-binding.rs:7:21 | LL | trait I32Iterator = Iterator; | ----------------------------------------- required by `I32Iterator` LL | trait U32Iterator = I32Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | = note: cannot resolve `::Item == i32` diff --git a/src/test/ui/closures/closure-bounds-cant-promote-superkind-in-struct.stderr b/src/test/ui/closures/closure-bounds-cant-promote-superkind-in-struct.stderr index 3c8f637e13369..0834014b31c35 100644 --- a/src/test/ui/closures/closure-bounds-cant-promote-superkind-in-struct.stderr +++ b/src/test/ui/closures/closure-bounds-cant-promote-superkind-in-struct.stderr @@ -1,17 +1,13 @@ error[E0277]: `F` cannot be sent between threads safely - --> $DIR/closure-bounds-cant-promote-superkind-in-struct.rs:5:1 + --> $DIR/closure-bounds-cant-promote-superkind-in-struct.rs:5:22 | -LL | struct X where F: FnOnce() + 'static + Send { - | ---------------------------------------------- required by `X` +LL | struct X where F: FnOnce() + 'static + Send { + | ---------------------------------------------- required by `X` ... -LL | fn foo(blk: F) -> X where F: FnOnce() + 'static { - | ^ - help: consider further restricting type parameter `F`: `, F: std::marker::Send` - | _| - | | -LL | | -LL | | return X { field: blk }; -LL | | } - | |_^ `F` cannot be sent between threads safely +LL | fn foo(blk: F) -> X where F: FnOnce() + 'static { + | ^^^^ - help: consider further restricting type parameter `F`: `, F: std::marker::Send` + | | + | `F` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `F` diff --git a/src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr b/src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr index ed6be60de460c..85ed360a1f74a 100644 --- a/src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr +++ b/src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr @@ -2,9 +2,13 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:6 | LL | trait NotObjectSafe { fn eq(&self, other: Self); } - | -- method `eq` references the `Self` type in its parameters or return type + | ------------- ---- ...because method `eq` references the `Self` type in this parameter + | | + | this trait cannot be made into an object... LL | impl NotObjectSafe for dyn NotObjectSafe { } | ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object + | + = help: consider moving `eq` to another trait error: aborting due to previous error diff --git a/src/test/ui/consts/too_generic_eval_ice.stderr b/src/test/ui/consts/too_generic_eval_ice.stderr index 599d1d79e7555..fd68cb9c6cf85 100644 --- a/src/test/ui/consts/too_generic_eval_ice.stderr +++ b/src/test/ui/consts/too_generic_eval_ice.stderr @@ -18,7 +18,7 @@ LL | pub struct Foo(A, B); | --------------------------- required by `Foo` LL | LL | impl Foo { - | - help: consider restricting this bound: `A: std::marker::Sized` + | - this type parameter needs to be `std::marker::Sized` ... LL | [5; Self::HOST_SIZE] == [6; 0] | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -33,7 +33,7 @@ LL | pub struct Foo(A, B); | --------------------------- required by `Foo` LL | LL | impl Foo { - | - help: consider restricting this bound: `B: std::marker::Sized` + | - this type parameter needs to be `std::marker::Sized` ... LL | [5; Self::HOST_SIZE] == [6; 0] | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time diff --git a/src/test/ui/did_you_mean/trait-object-reference-without-parens-suggestion.stderr b/src/test/ui/did_you_mean/trait-object-reference-without-parens-suggestion.stderr index 8c6c33b11865b..333754891c164 100644 --- a/src/test/ui/did_you_mean/trait-object-reference-without-parens-suggestion.stderr +++ b/src/test/ui/did_you_mean/trait-object-reference-without-parens-suggestion.stderr @@ -16,7 +16,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object LL | let _: &Copy + 'static; | ^^^^^ the trait `std::marker::Copy` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` + = note: the trait cannot be made into an object because it requires `Self: Sized` error: aborting due to 3 previous errors 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 40db575eabd38..80d188bf2f89b 100644 --- a/src/test/ui/dst/dst-object-from-unsized-type.stderr +++ b/src/test/ui/dst/dst-object-from-unsized-type.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/dst-object-from-unsized-type.rs:8:23 | LL | fn test1(t: &T) { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let u: &dyn Foo = t; | ^ doesn't have a size known at compile-time | @@ -14,7 +14,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/dst-object-from-unsized-type.rs:13:23 | LL | fn test2(t: &T) { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let v: &dyn Foo = t as &dyn Foo; | ^ doesn't have a size known at compile-time | diff --git a/src/test/ui/error-codes/E0033-teach.stderr b/src/test/ui/error-codes/E0033-teach.stderr index 80f3d4441bd9f..f323a9904557a 100644 --- a/src/test/ui/error-codes/E0033-teach.stderr +++ b/src/test/ui/error-codes/E0033-teach.stderr @@ -7,11 +7,18 @@ LL | let trait_obj: &dyn SomeTrait = SomeTrait; error[E0038]: the trait `SomeTrait` cannot be made into an object --> $DIR/E0033-teach.rs:8:20 | +LL | trait SomeTrait { + | --------- this trait cannot be made into an object... LL | fn foo(); - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | let trait_obj: &dyn SomeTrait = SomeTrait; | ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error[E0033]: type `&dyn SomeTrait` cannot be dereferenced --> $DIR/E0033-teach.rs:12:9 diff --git a/src/test/ui/error-codes/E0033.stderr b/src/test/ui/error-codes/E0033.stderr index c2843796cc851..84481ff16c07e 100644 --- a/src/test/ui/error-codes/E0033.stderr +++ b/src/test/ui/error-codes/E0033.stderr @@ -7,11 +7,18 @@ LL | let trait_obj: &dyn SomeTrait = SomeTrait; error[E0038]: the trait `SomeTrait` cannot be made into an object --> $DIR/E0033.rs:6:20 | +LL | trait SomeTrait { + | --------- this trait cannot be made into an object... LL | fn foo(); - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | let trait_obj: &dyn SomeTrait = SomeTrait; | ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error[E0033]: type `&dyn SomeTrait` cannot be dereferenced --> $DIR/E0033.rs:10:9 diff --git a/src/test/ui/error-codes/E0038.stderr b/src/test/ui/error-codes/E0038.stderr index 5c4d6d53c4626..638e924b0eb43 100644 --- a/src/test/ui/error-codes/E0038.stderr +++ b/src/test/ui/error-codes/E0038.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/E0038.rs:5:1 + --> $DIR/E0038.rs:5:16 | +LL | trait Trait { + | ----- this trait cannot be made into an object... LL | fn foo(&self) -> Self; - | --- method `foo` references the `Self` type in its parameters or return type + | ---- ...because method `foo` references the `Self` type in its return type ... LL | fn call_foo(x: Box) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object + | ^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object + | + = help: consider moving `foo` to another trait error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0275.stderr b/src/test/ui/error-codes/E0275.stderr index f607a9fbbf269..1d087a465942e 100644 --- a/src/test/ui/error-codes/E0275.stderr +++ b/src/test/ui/error-codes/E0275.stderr @@ -1,11 +1,11 @@ error[E0275]: overflow evaluating the requirement `Bar>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` - --> $DIR/E0275.rs:5:1 + --> $DIR/E0275.rs:5:33 | LL | trait Foo {} | --------- required by `Foo` ... LL | impl Foo for T where Bar: Foo {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate = note: required because of the requirements on the impl of `Foo` for `Bar>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` diff --git a/src/test/ui/extern/extern-types-unsized.stderr b/src/test/ui/extern/extern-types-unsized.stderr index 0417186eed346..0c9165fd9585d 100644 --- a/src/test/ui/extern/extern-types-unsized.stderr +++ b/src/test/ui/extern/extern-types-unsized.stderr @@ -2,7 +2,9 @@ error[E0277]: the size for values of type `A` cannot be known at compilation tim --> $DIR/extern-types-unsized.rs:22:20 | LL | fn assert_sized() { } - | ------------ - required by this bound in `assert_sized` + | ------------ -- help: consider relaxing the implicit `Sized` restriction: `: ?Sized` + | | + | required by this bound in `assert_sized` ... LL | assert_sized::(); | ^ doesn't have a size known at compile-time diff --git a/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr b/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr index 54e64e2fc1bd4..c66bbb0c5045f 100644 --- a/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr +++ b/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr @@ -1,45 +1,66 @@ error[E0038]: the trait `NonObjectSafe1` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:18:1 + --> $DIR/feature-gate-object_safe_for_dispatch.rs:18:38 | +LL | trait NonObjectSafe1: Sized {} + | -------------- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | fn takes_non_object_safe_ref(obj: &dyn NonObjectSafe1) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` + | ^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object error[E0038]: the trait `NonObjectSafe2` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:22:1 + --> $DIR/feature-gate-object_safe_for_dispatch.rs:22:36 | +LL | trait NonObjectSafe2 { + | -------------- this trait cannot be made into an object... LL | fn static_fn() {} - | --------- associated function `static_fn` has no `self` parameter + | --------- ...because associated function `static_fn` has no `self` parameter ... LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object + | +help: consider turning `static_fn` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn static_fn() where Self: Sized {} + | ^^^^^^^^^^^^^^^^^ error[E0038]: the trait `NonObjectSafe3` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:27:1 + --> $DIR/feature-gate-object_safe_for_dispatch.rs:27:35 | +LL | trait NonObjectSafe3 { + | -------------- this trait cannot be made into an object... LL | fn foo(&self); - | --- method `foo` has generic type parameters + | --- ...because method `foo` has generic type parameters ... LL | fn takes_non_object_safe_box(obj: Box) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object + | + = help: consider moving `foo` to another trait error[E0038]: the trait `NonObjectSafe4` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:31:1 + --> $DIR/feature-gate-object_safe_for_dispatch.rs:31:35 | +LL | trait NonObjectSafe4 { + | -------------- this trait cannot be made into an object... LL | fn foo(&self, &Self); - | --- method `foo` references the `Self` type in its parameters or return type + | ----- ...because method `foo` references the `Self` type in this parameter ... LL | fn return_non_object_safe_rc() -> std::rc::Rc { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object + | + = help: consider moving `foo` to another trait error[E0038]: the trait `NonObjectSafe1` cannot be made into an object --> $DIR/feature-gate-object_safe_for_dispatch.rs:38:6 | +LL | trait NonObjectSafe1: Sized {} + | -------------- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | impl Trait for dyn NonObjectSafe1 {} | ^^^^^ the trait `NonObjectSafe1` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` error: aborting due to 5 previous errors diff --git a/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.rs b/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.rs index 60466d0bcd040..1a79dbf2279a0 100644 --- a/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.rs +++ b/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.rs @@ -4,8 +4,8 @@ // FIXME(generic-associated-types) Investigate why this doesn't compile. trait Iterator { - //~^ ERROR the requirement `for<'a> ::Item<'a>: 'a` is not satisfied type Item<'a>: 'a; + //~^ ERROR the requirement `for<'a> ::Item<'a>: 'a` is not satisfied } fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.stderr b/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.stderr index 4dc69cdd1dcf0..687423962361b 100644 --- a/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.stderr +++ b/src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.stderr @@ -1,15 +1,10 @@ error[E0280]: the requirement `for<'a> ::Item<'a>: 'a` is not satisfied - --> $DIR/issue-62326-parameter-out-of-range.rs:6:1 + --> $DIR/issue-62326-parameter-out-of-range.rs:7:20 | -LL | trait Iterator { - | ^------------- - | | - | _required by `Iterator` - | | -LL | | -LL | | type Item<'a>: 'a; -LL | | } - | |_^ +LL | trait Iterator { + | -------------- required by `Iterator` +LL | type Item<'a>: 'a; + | ^^ error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/iterable.stderr b/src/test/ui/generic-associated-types/iterable.stderr index d0d75f3cc6336..ccb1c9bcc7f4e 100644 --- a/src/test/ui/generic-associated-types/iterable.stderr +++ b/src/test/ui/generic-associated-types/iterable.stderr @@ -25,16 +25,13 @@ LL | type Item<'a> where T: 'a = as Iterator>::Item = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html error[E0271]: type mismatch resolving `for<'a> < as Iterable>::Iter<'a> as std::iter::Iterator>::Item == as Iterable>::Item<'a>` - --> $DIR/iterable.rs:19:5 + --> $DIR/iterable.rs:19:30 | -LL | trait Iterable { - | -------------- required by `Iterable` +LL | trait Iterable { + | -------------- required by `Iterable` ... -LL | / fn iter<'a>(&'a self) -> Self::Iter<'a> { -LL | | -LL | | self.iter() -LL | | } - | |_____^ expected associated type, found reference +LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { + | ^^^^^^^^^^^^^^ expected associated type, found reference | = note: expected associated type ` as Iterable>::Item<'_>` found reference `&T` @@ -42,16 +39,13 @@ LL | | } = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <[T] as Iterable>::Item<'a>` - --> $DIR/iterable.rs:31:5 + --> $DIR/iterable.rs:31:30 | -LL | trait Iterable { - | -------------- required by `Iterable` +LL | trait Iterable { + | -------------- required by `Iterable` ... -LL | / fn iter<'a>(&'a self) -> Self::Iter<'a> { -LL | | -LL | | self.iter() -LL | | } - | |_____^ expected associated type, found reference +LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { + | ^^^^^^^^^^^^^^ expected associated type, found reference | = note: expected associated type `<[T] as Iterable>::Item<'_>` found reference `&T` diff --git a/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr b/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr index 0c8d267c13434..9df5188bbdd08 100644 --- a/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr +++ b/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr @@ -1,20 +1,34 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:1 + --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13 | +LL | trait NotObjectSafe { + | ------------- this trait cannot be made into an object... LL | fn foo() -> Self; - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | fn car() -> dyn NotObjectSafe { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object + | ^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() -> Self where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:1 + --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:13 | +LL | trait NotObjectSafe { + | ------------- this trait cannot be made into an object... LL | fn foo() -> Self; - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | fn cat() -> Box { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() -> Self where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr index 87528652bd482..c8b9045efe6a0 100644 --- a/src/test/ui/issues/issue-18919.stderr +++ b/src/test/ui/issues/issue-18919.stderr @@ -1,10 +1,8 @@ error[E0277]: the size for values of type `dyn for<'r> std::ops::Fn(&'r isize) -> isize` cannot be known at compilation time - --> $DIR/issue-18919.rs:3:1 + --> $DIR/issue-18919.rs:3:15 | -LL | / fn ho_func(f: Option) { -LL | | -LL | | } - | |_^ doesn't have a size known at compile-time +LL | fn ho_func(f: Option) { + | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `dyn for<'r> std::ops::Fn(&'r isize) -> isize` = note: to learn more, visit diff --git a/src/test/ui/issues/issue-18959.stderr b/src/test/ui/issues/issue-18959.stderr index d5e7092801ecd..b3ba7aecad0db 100644 --- a/src/test/ui/issues/issue-18959.stderr +++ b/src/test/ui/issues/issue-18959.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/issue-18959.rs:11:1 + --> $DIR/issue-18959.rs:11:11 | LL | pub trait Foo { fn foo(&self, ext_thing: &T); } - | --- method `foo` has generic type parameters + | --- ...because method `foo` has generic type parameters +LL | pub trait Bar: Foo { } + | --- this trait cannot be made into an object... ... LL | fn foo(b: &dyn Bar) { - | ^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | ^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `foo` to another trait error: aborting due to previous error diff --git a/src/test/ui/issues/issue-19380.stderr b/src/test/ui/issues/issue-19380.stderr index 92bfdf1f26e93..0a080171a7951 100644 --- a/src/test/ui/issues/issue-19380.stderr +++ b/src/test/ui/issues/issue-19380.stderr @@ -1,11 +1,18 @@ error[E0038]: the trait `Qiz` cannot be made into an object --> $DIR/issue-19380.rs:11:3 | +LL | trait Qiz { + | --- this trait cannot be made into an object... LL | fn qiz(); - | --- associated function `qiz` has no `self` parameter + | --- ...because associated function `qiz` has no `self` parameter ... LL | foos: &'static [&'static (dyn Qiz + 'static)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Qiz` cannot be made into an object + | +help: consider turning `qiz` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn qiz() where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-19538.stderr b/src/test/ui/issues/issue-19538.stderr index 83c03b514ddcc..b6033e47b1a44 100644 --- a/src/test/ui/issues/issue-19538.stderr +++ b/src/test/ui/issues/issue-19538.stderr @@ -2,20 +2,29 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/issue-19538.rs:17:15 | LL | fn foo(&self, val: T); - | --- method `foo` has generic type parameters + | --- ...because method `foo` has generic type parameters +... +LL | trait Bar: Foo { } + | --- this trait cannot be made into an object... ... LL | let test: &mut dyn Bar = &mut thing; | ^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `foo` to another trait error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/issue-19538.rs:17:30 | LL | fn foo(&self, val: T); - | --- method `foo` has generic type parameters + | --- ...because method `foo` has generic type parameters +... +LL | trait Bar: Foo { } + | --- this trait cannot be made into an object... ... LL | let test: &mut dyn Bar = &mut thing; | ^^^^^^^^^^ the trait `Bar` cannot be made into an object | + = help: consider moving `foo` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&mut dyn Bar>` for `&mut Thing` = note: required by cast to type `&mut dyn Bar` diff --git a/src/test/ui/issues/issue-20005.rs b/src/test/ui/issues/issue-20005.rs index 6d63c9e5b613a..36350bff100dd 100644 --- a/src/test/ui/issues/issue-20005.rs +++ b/src/test/ui/issues/issue-20005.rs @@ -5,9 +5,9 @@ trait From { } trait To { - fn to( //~ ERROR the size for values of type + fn to( self - ) -> >::Result where Dst: From { + ) -> >::Result where Dst: From { //~ ERROR the size for values of type From::from(self) } } diff --git a/src/test/ui/issues/issue-20005.stderr b/src/test/ui/issues/issue-20005.stderr index 31376f2d1be0f..529571a6b74dd 100644 --- a/src/test/ui/issues/issue-20005.stderr +++ b/src/test/ui/issues/issue-20005.stderr @@ -1,16 +1,13 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-20005.rs:8:5 + --> $DIR/issue-20005.rs:10:49 | -LL | trait From { - | --------------- required by `From` +LL | trait From { + | --------------- required by `From` ... -LL | / fn to( -LL | | self -LL | | ) -> >::Result where Dst: From { - | | - help: consider further restricting `Self`: `, Self: std::marker::Sized` -LL | | From::from(self) -LL | | } - | |_____^ doesn't have a size known at compile-time +LL | ) -> >::Result where Dst: From { + | ^^^^^^^^^^- help: consider further restricting `Self`: `, Self: std::marker::Sized` + | | + | doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `Self` = note: to learn more, visit diff --git a/src/test/ui/issues/issue-20413.rs b/src/test/ui/issues/issue-20413.rs index 7eb6d5c0ecbaa..19ef52af65736 100644 --- a/src/test/ui/issues/issue-20413.rs +++ b/src/test/ui/issues/issue-20413.rs @@ -6,9 +6,9 @@ struct NoData; //~^ ERROR: parameter `T` is never used impl Foo for T where NoData: Foo { -//~^ ERROR: overflow evaluating the requirement - fn answer(self) { //~^ ERROR: overflow evaluating the requirement + //~| ERROR: overflow evaluating the requirement + fn answer(self) { let val: NoData = NoData; } } diff --git a/src/test/ui/issues/issue-20413.stderr b/src/test/ui/issues/issue-20413.stderr index 6ecb4e736acd9..e765144ff0b48 100644 --- a/src/test/ui/issues/issue-20413.stderr +++ b/src/test/ui/issues/issue-20413.stderr @@ -7,19 +7,13 @@ LL | struct NoData; = help: consider removing `T`, referring to it in a field, or using a marker such as `std::marker::PhantomData` error[E0275]: overflow evaluating the requirement `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` - --> $DIR/issue-20413.rs:8:1 + --> $DIR/issue-20413.rs:8:36 | -LL | trait Foo { - | --------- required by `Foo` +LL | trait Foo { + | --------- required by `Foo` ... -LL | / impl Foo for T where NoData: Foo { -LL | | -LL | | fn answer(self) { -LL | | -LL | | let val: NoData = NoData; -LL | | } -LL | | } - | |_^ +LL | impl Foo for T where NoData: Foo { + | ^^^ | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate = note: required because of the requirements on the impl of `Foo` for `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` @@ -151,16 +145,13 @@ LL | | } = note: required because of the requirements on the impl of `Foo` for `NoData` error[E0275]: overflow evaluating the requirement `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` - --> $DIR/issue-20413.rs:10:3 + --> $DIR/issue-20413.rs:8:36 | -LL | trait Foo { - | --------- required by `Foo` +LL | trait Foo { + | --------- required by `Foo` ... -LL | / fn answer(self) { -LL | | -LL | | let val: NoData = NoData; -LL | | } - | |___^ +LL | impl Foo for T where NoData: Foo { + | ^^^ | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate = note: required because of the requirements on the impl of `Foo` for `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` diff --git a/src/test/ui/issues/issue-20433.stderr b/src/test/ui/issues/issue-20433.stderr index f7cb28edd6216..abd2290952baf 100644 --- a/src/test/ui/issues/issue-20433.stderr +++ b/src/test/ui/issues/issue-20433.stderr @@ -1,8 +1,8 @@ error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/issue-20433.rs:6:5 + --> $DIR/issue-20433.rs:6:18 | LL | fn iceman(c: Vec<[i32]>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `[i32]` = note: to learn more, visit diff --git a/src/test/ui/issues/issue-20692.rs b/src/test/ui/issues/issue-20692.rs index 2a05bba7b1632..1cb2d8c7302a0 100644 --- a/src/test/ui/issues/issue-20692.rs +++ b/src/test/ui/issues/issue-20692.rs @@ -1,4 +1,4 @@ -trait Array: Sized {} +trait Array: Sized + Copy {} fn f(x: &T) { let _ = x diff --git a/src/test/ui/issues/issue-20692.stderr b/src/test/ui/issues/issue-20692.stderr index 06c83f65be26c..ca2611e0f9eb5 100644 --- a/src/test/ui/issues/issue-20692.stderr +++ b/src/test/ui/issues/issue-20692.stderr @@ -1,18 +1,27 @@ error[E0038]: the trait `Array` cannot be made into an object --> $DIR/issue-20692.rs:7:5 | +LL | trait Array: Sized + Copy {} + | ----- ----- ---- ...because it requires `Self: Sized` + | | | + | | ...because it requires `Self: Sized` + | this trait cannot be made into an object... +... LL | &dyn Array; | ^^^^^^^^^^ the trait `Array` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` error[E0038]: the trait `Array` cannot be made into an object --> $DIR/issue-20692.rs:4:13 | +LL | trait Array: Sized + Copy {} + | ----- ----- ---- ...because it requires `Self: Sized` + | | | + | | ...because it requires `Self: Sized` + | this trait cannot be made into an object... +... LL | let _ = x | ^ the trait `Array` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Array>` for `&T` = note: required by cast to type `&dyn Array` diff --git a/src/test/ui/issues/issue-20831-debruijn.stderr b/src/test/ui/issues/issue-20831-debruijn.stderr index a4ea1cd9834c8..a785a956ca9f5 100644 --- a/src/test/ui/issues/issue-20831-debruijn.stderr +++ b/src/test/ui/issues/issue-20831-debruijn.stderr @@ -61,16 +61,10 @@ LL | | } | |_____^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/issue-20831-debruijn.rs:28:5 + --> $DIR/issue-20831-debruijn.rs:28:33 | -LL | / fn subscribe(&mut self, t : Box::Output> + 'a>) { -LL | | // Not obvious, but there is an implicit lifetime here -------^ -LL | | -LL | | -... | -LL | | self.sub = t; -LL | | } - | |_____^ +LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 28:5... --> $DIR/issue-20831-debruijn.rs:28:5 @@ -89,30 +83,18 @@ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on LL | impl<'a> Publisher<'a> for MyStruct<'a> { | ^^ note: ...so that the types are compatible - --> $DIR/issue-20831-debruijn.rs:28:5 + --> $DIR/issue-20831-debruijn.rs:28:33 | -LL | / fn subscribe(&mut self, t : Box::Output> + 'a>) { -LL | | // Not obvious, but there is an implicit lifetime here -------^ -LL | | -LL | | -... | -LL | | self.sub = t; -LL | | } - | |_____^ +LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected `Publisher<'_>` found `Publisher<'_>` error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/issue-20831-debruijn.rs:28:5 + --> $DIR/issue-20831-debruijn.rs:28:33 | -LL | / fn subscribe(&mut self, t : Box::Output> + 'a>) { -LL | | // Not obvious, but there is an implicit lifetime here -------^ -LL | | -LL | | -... | -LL | | self.sub = t; -LL | | } - | |_____^ +LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 28:5... --> $DIR/issue-20831-debruijn.rs:28:5 @@ -131,16 +113,10 @@ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on LL | impl<'a> Publisher<'a> for MyStruct<'a> { | ^^ note: ...so that the types are compatible - --> $DIR/issue-20831-debruijn.rs:28:5 + --> $DIR/issue-20831-debruijn.rs:28:33 | -LL | / fn subscribe(&mut self, t : Box::Output> + 'a>) { -LL | | // Not obvious, but there is an implicit lifetime here -------^ -LL | | -LL | | -... | -LL | | self.sub = t; -LL | | } - | |_____^ +LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected `Publisher<'_>` found `Publisher<'_>` diff --git a/src/test/ui/issues/issue-21974.rs b/src/test/ui/issues/issue-21974.rs index 0cbe38d6ec0b6..f7c659be148db 100644 --- a/src/test/ui/issues/issue-21974.rs +++ b/src/test/ui/issues/issue-21974.rs @@ -7,8 +7,8 @@ trait Foo { fn foo(self); } -fn foo<'a,'b,T>(x: &'a T, y: &'b T) //~ ERROR type annotations needed - where &'a T : Foo, +fn foo<'a,'b,T>(x: &'a T, y: &'b T) + where &'a T : Foo, //~ ERROR type annotations needed &'b T : Foo { x.foo(); diff --git a/src/test/ui/issues/issue-21974.stderr b/src/test/ui/issues/issue-21974.stderr index b1536bd8ddb0a..19823499066eb 100644 --- a/src/test/ui/issues/issue-21974.stderr +++ b/src/test/ui/issues/issue-21974.stderr @@ -1,17 +1,11 @@ error[E0283]: type annotations needed - --> $DIR/issue-21974.rs:10:1 + --> $DIR/issue-21974.rs:11:19 | -LL | trait Foo { - | --------- required by `Foo` +LL | trait Foo { + | --------- required by `Foo` ... -LL | / fn foo<'a,'b,T>(x: &'a T, y: &'b T) -LL | | where &'a T : Foo, -LL | | &'b T : Foo -LL | | { -LL | | x.foo(); -LL | | y.foo(); -LL | | } - | |_^ cannot infer type for reference `&'a T` +LL | where &'a T : Foo, + | ^^^ cannot infer type for reference `&'a T` | = note: cannot resolve `&'a T: Foo` diff --git a/src/test/ui/issues/issue-23281.stderr b/src/test/ui/issues/issue-23281.stderr index f1def47458368..68a90c6d80f3b 100644 --- a/src/test/ui/issues/issue-23281.stderr +++ b/src/test/ui/issues/issue-23281.stderr @@ -1,8 +1,8 @@ error[E0277]: the size for values of type `(dyn std::ops::Fn() + 'static)` cannot be known at compilation time - --> $DIR/issue-23281.rs:4:5 + --> $DIR/issue-23281.rs:4:27 | LL | pub fn function(funs: Vec ()>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `(dyn std::ops::Fn() + 'static)` = note: to learn more, visit diff --git a/src/test/ui/issues/issue-24204.stderr b/src/test/ui/issues/issue-24204.stderr index 3eb1f1b4f6e81..2a714861da1fd 100644 --- a/src/test/ui/issues/issue-24204.stderr +++ b/src/test/ui/issues/issue-24204.stderr @@ -1,11 +1,11 @@ error[E0271]: type mismatch resolving `<::A as MultiDispatch>::O == T` - --> $DIR/issue-24204.rs:14:1 + --> $DIR/issue-24204.rs:14:12 | LL | trait Trait: Sized { | ------------------ required by `Trait` ... LL | fn test>(b: i32) -> T where T::A: MultiDispatch { T::new(b) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type + | ^^^^^^^^^^^^ expected type parameter `T`, found associated type | = note: expected type parameter `T` found associated type `<::A as MultiDispatch>::O` diff --git a/src/test/ui/issues/issue-24424.stderr b/src/test/ui/issues/issue-24424.stderr index 8f0850328b446..538d44c3b2ef3 100644 --- a/src/test/ui/issues/issue-24424.stderr +++ b/src/test/ui/issues/issue-24424.stderr @@ -1,11 +1,11 @@ error[E0283]: type annotations needed - --> $DIR/issue-24424.rs:4:1 + --> $DIR/issue-24424.rs:4:57 | LL | trait Trait0<'l0> {} | ----------------- required by `Trait0` LL | LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T0` + | ^^^^^^^^^^^ cannot infer type for type parameter `T0` | = note: cannot resolve `T0: Trait0<'l0>` diff --git a/src/test/ui/issues/issue-26056.stderr b/src/test/ui/issues/issue-26056.stderr index 9c4cf0b18acfe..be438ef9ac7ba 100644 --- a/src/test/ui/issues/issue-26056.stderr +++ b/src/test/ui/issues/issue-26056.stderr @@ -1,10 +1,13 @@ error[E0038]: the trait `Map` cannot be made into an object --> $DIR/issue-26056.rs:20:13 | +LL | trait Map: MapLookup<::Key> { + | --- ----------------------------- ...because it uses `Self` as a type parameter in this + | | + | this trait cannot be made into an object... +... LL | as &dyn Map; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Map` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error: aborting due to previous error diff --git a/src/test/ui/issues/issue-27060-2.stderr b/src/test/ui/issues/issue-27060-2.stderr index 553041c5106c5..1ddea73e00ae0 100644 --- a/src/test/ui/issues/issue-27060-2.stderr +++ b/src/test/ui/issues/issue-27060-2.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/issue-27060-2.rs:3:5 | LL | pub struct Bad { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | data: T, | ^^^^^^^ doesn't have a size known at compile-time | diff --git a/src/test/ui/issues/issue-27942.stderr b/src/test/ui/issues/issue-27942.stderr index d290b176161be..6ce0fa37a8840 100644 --- a/src/test/ui/issues/issue-27942.stderr +++ b/src/test/ui/issues/issue-27942.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/issue-27942.rs:5:5 + --> $DIR/issue-27942.rs:5:25 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch + | ^^^^^^^^^^^^^^^^^^^ lifetime mismatch | = note: expected type `Resources<'_>` found type `Resources<'a>` @@ -18,10 +18,10 @@ LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ error[E0308]: mismatched types - --> $DIR/issue-27942.rs:5:5 + --> $DIR/issue-27942.rs:5:25 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch + | ^^^^^^^^^^^^^^^^^^^ lifetime mismatch | = note: expected type `Resources<'_>` found type `Resources<'a>` diff --git a/src/test/ui/issues/issue-28576.stderr b/src/test/ui/issues/issue-28576.stderr index 3249d76e69b57..658199003c18d 100644 --- a/src/test/ui/issues/issue-28576.stderr +++ b/src/test/ui/issues/issue-28576.stderr @@ -1,11 +1,16 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/issue-28576.rs:7:12 | +LL | pub trait Bar: Foo { + | --- ------------- + | | | | + | | | ...because it uses `Self` as a type parameter in this + | | ...because it uses `Self` as a type parameter in this + | this trait cannot be made into an object... +LL | fn new(&self, b: & LL | / dyn Bar LL | | | |________________________^ the trait `Bar` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error: aborting due to previous error diff --git a/src/test/ui/issues/issue-35976.stderr b/src/test/ui/issues/issue-35976.stderr index 99b243a077792..f9b9b7dbd34bb 100644 --- a/src/test/ui/issues/issue-35976.stderr +++ b/src/test/ui/issues/issue-35976.stderr @@ -1,6 +1,9 @@ error: the `wait` method cannot be invoked on a trait object --> $DIR/issue-35976.rs:14:9 | +LL | fn wait(&self) where Self: Sized; + | ----- this has a `Sized` requirement +... LL | arg.wait(); | ^^^^ | diff --git a/src/test/ui/issues/issue-38404.stderr b/src/test/ui/issues/issue-38404.stderr index d18a26b3a7638..50c5195dc93b0 100644 --- a/src/test/ui/issues/issue-38404.stderr +++ b/src/test/ui/issues/issue-38404.stderr @@ -1,10 +1,12 @@ error[E0038]: the trait `B` cannot be made into an object --> $DIR/issue-38404.rs:3:15 | +LL | trait A: std::ops::Add + Sized {} + | ------------------- ...because it uses `Self` as a type parameter in this +LL | trait B: A {} + | - this trait cannot be made into an object... LL | trait C: A> {} | ^^^^^^^^^^^^^^^^^^^^^^ the trait `B` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error: aborting due to previous error diff --git a/src/test/ui/issues/issue-38604.stderr b/src/test/ui/issues/issue-38604.stderr index 8b923a2c6b23f..2bba50e1f41c8 100644 --- a/src/test/ui/issues/issue-38604.stderr +++ b/src/test/ui/issues/issue-38604.stderr @@ -1,18 +1,25 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/issue-38604.rs:14:13 | +LL | trait Foo where u32: Q { + | --- ------- ...because it uses `Self` as a type parameter in this + | | + | this trait cannot be made into an object... +... LL | let _f: Box = | ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/issue-38604.rs:15:9 | +LL | trait Foo where u32: Q { + | --- ------- ...because it uses `Self` as a type parameter in this + | | + | this trait cannot be made into an object... +... LL | Box::new(()); | ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box<()>` = note: required by cast to type `std::boxed::Box` diff --git a/src/test/ui/issues/issue-50781.stderr b/src/test/ui/issues/issue-50781.stderr index cb6ca24c7124a..03e3a7f227a23 100644 --- a/src/test/ui/issues/issue-50781.stderr +++ b/src/test/ui/issues/issue-50781.stderr @@ -1,8 +1,10 @@ error: the trait `X` cannot be made into an object --> $DIR/issue-50781.rs:6:8 | +LL | trait X { + | - this trait cannot be made into an object... LL | fn foo(&self) where Self: Trait; - | ^^^ + | ^^^ ...because method `foo` references the `Self` type in its `where` clause | note: the lint level is defined here --> $DIR/issue-50781.rs:1:9 @@ -11,7 +13,7 @@ LL | #![deny(where_clauses_object_safety)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #51443 - = note: method `foo` references the `Self` type in where clauses + = help: consider moving `foo` to another trait error: aborting due to previous error diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr index da1a7a7520e07..2a9fd13be5f01 100644 --- a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr +++ b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr @@ -12,18 +12,25 @@ LL | take_param(&x); error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:19 | +LL | trait Foo : Copy { + | --- ---- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let z = &x as &dyn Foo; | ^^^^^^^^ the trait `Foo` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:13 | +LL | trait Foo : Copy { + | --- ---- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let z = &x as &dyn Foo; | ^^ the trait `Foo` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Foo>` for `&std::boxed::Box<{integer}>` = note: required by cast to type `&dyn Foo` diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr index f272f829ba600..6227ada4dc938 100644 --- a/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr +++ b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr @@ -12,10 +12,14 @@ LL | take_param(&x); error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:13 | +LL | trait Foo : Copy { + | --- ---- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let z = &x as &dyn Foo; | ^^ the trait `Foo` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Foo>` for `&std::boxed::Box` = note: required by cast to type `&dyn Foo` diff --git a/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr index 7b823f012b9f9..4e50064efb4ec 100644 --- a/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr +++ b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr @@ -13,87 +13,71 @@ LL | foo: &'static T | ^^^^^^^^^^^^^^^ error[E0309]: the parameter type `K` may not live long enough - --> $DIR/lifetime-doesnt-live-long-enough.rs:24:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:24:19 | LL | trait X: Sized { | - help: consider adding an explicit lifetime bound `K: 'a`... LL | fn foo<'a, L: X<&'a Nested>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | note: ...so that the reference type `&'a Nested` does not outlive the data it points at - --> $DIR/lifetime-doesnt-live-long-enough.rs:24:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:24:19 | LL | fn foo<'a, L: X<&'a Nested>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error[E0309]: the parameter type `Self` may not live long enough - --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:28:19 | LL | fn bar<'a, L: X<&'a Nested>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `Self: 'a`... note: ...so that the reference type `&'a Nested` does not outlive the data it points at - --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:28:19 | LL | fn bar<'a, L: X<&'a Nested>>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error[E0309]: the parameter type `L` may not live long enough - --> $DIR/lifetime-doesnt-live-long-enough.rs:32:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:32:22 | -LL | fn baz<'a, L, M: X<&'a Nested>>() { - | ^ - help: consider adding an explicit lifetime bound `L: 'a`... - | _____| - | | -LL | | -LL | | } - | |_____^ +LL | fn baz<'a, L, M: X<&'a Nested>>() { + | - ^^^^^^^^^^^^^^^^ + | | + | help: consider adding an explicit lifetime bound `L: 'a`... | note: ...so that the reference type `&'a Nested` does not outlive the data it points at - --> $DIR/lifetime-doesnt-live-long-enough.rs:32:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:32:22 | -LL | / fn baz<'a, L, M: X<&'a Nested>>() { -LL | | -LL | | } - | |_____^ +LL | fn baz<'a, L, M: X<&'a Nested>>() { + | ^^^^^^^^^^^^^^^^ error[E0309]: the parameter type `K` may not live long enough - --> $DIR/lifetime-doesnt-live-long-enough.rs:41:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:41:33 | -LL | impl Nested { - | - help: consider adding an explicit lifetime bound `K: 'a`... -LL | / fn generic_in_parent<'a, L: X<&'a Nested>>() { -LL | | -LL | | } - | |_____^ +LL | impl Nested { + | - help: consider adding an explicit lifetime bound `K: 'a`... +LL | fn generic_in_parent<'a, L: X<&'a Nested>>() { + | ^^^^^^^^^^^^^^^^ | note: ...so that the reference type `&'a Nested` does not outlive the data it points at - --> $DIR/lifetime-doesnt-live-long-enough.rs:41:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:41:33 | -LL | / fn generic_in_parent<'a, L: X<&'a Nested>>() { -LL | | -LL | | } - | |_____^ +LL | fn generic_in_parent<'a, L: X<&'a Nested>>() { + | ^^^^^^^^^^^^^^^^ error[E0309]: the parameter type `M` may not live long enough - --> $DIR/lifetime-doesnt-live-long-enough.rs:44:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:44:36 | -LL | fn generic_in_child<'a, 'b, L: X<&'a Nested>, M: 'b>() { - | ^ -- help: consider adding an explicit lifetime bound `M: 'a`... - | _____| - | | -LL | | -LL | | } - | |_____^ +LL | fn generic_in_child<'a, 'b, L: X<&'a Nested>, M: 'b>() { + | ^^^^^^^^^^^^^^^^ -- help: consider adding an explicit lifetime bound `M: 'a`... | note: ...so that the reference type `&'a Nested` does not outlive the data it points at - --> $DIR/lifetime-doesnt-live-long-enough.rs:44:5 + --> $DIR/lifetime-doesnt-live-long-enough.rs:44:36 | -LL | / fn generic_in_child<'a, 'b, L: X<&'a Nested>, M: 'b>() { -LL | | -LL | | } - | |_____^ +LL | fn generic_in_child<'a, 'b, L: X<&'a Nested>, M: 'b>() { + | ^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr b/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr index 67ef7a62f1052..890acde35c4f8 100644 --- a/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr +++ b/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-associated-consts.rs:12:1 + --> $DIR/object-safety-associated-consts.rs:12:30 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | const X: usize; - | - the trait cannot contain associated consts like `X` + | - ...because it contains this associated `const` ... LL | fn make_bar(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | ^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `X` to another trait error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr index 20993a680ba48..e2a95d95a13ed 100644 --- a/src/test/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr @@ -1,12 +1,15 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-associated-consts.rs:14:5 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | const X: usize; - | - the trait cannot contain associated consts like `X` + | - ...because it contains this associated `const` ... LL | t | ^ the trait `Bar` cannot be made into an object | + = help: consider moving `X` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` diff --git a/src/test/ui/object-safety/object-safety-generics.curr.stderr b/src/test/ui/object-safety/object-safety-generics.curr.stderr index 8ae9236a5c322..9e70abbd32fc6 100644 --- a/src/test/ui/object-safety/object-safety-generics.curr.stderr +++ b/src/test/ui/object-safety/object-safety-generics.curr.stderr @@ -1,20 +1,28 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:18:1 + --> $DIR/object-safety-generics.rs:18:30 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, t: T); - | --- method `bar` has generic type parameters + | --- ...because method `bar` has generic type parameters ... LL | fn make_bar(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | ^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `bar` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:24:1 + --> $DIR/object-safety-generics.rs:24:39 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, t: T); - | --- method `bar` has generic type parameters + | --- ...because method `bar` has generic type parameters ... LL | fn make_bar_explicit(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | ^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `bar` to another trait error: aborting due to 2 previous errors diff --git a/src/test/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr index d3d8d36888836..7443d38470c03 100644 --- a/src/test/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr @@ -1,24 +1,30 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-generics.rs:20:5 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, t: T); - | --- method `bar` has generic type parameters + | --- ...because method `bar` has generic type parameters ... LL | t | ^ the trait `Bar` cannot be made into an object | + = help: consider moving `bar` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-generics.rs:26:5 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, t: T); - | --- method `bar` has generic type parameters + | --- ...because method `bar` has generic type parameters ... LL | t as &dyn Bar | ^ the trait `Bar` cannot be made into an object | + = help: consider moving `bar` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` diff --git a/src/test/ui/object-safety/object-safety-issue-22040.stderr b/src/test/ui/object-safety/object-safety-issue-22040.stderr index 1f5c472ddc25a..fe9ca5b6fa4b7 100644 --- a/src/test/ui/object-safety/object-safety-issue-22040.stderr +++ b/src/test/ui/object-safety/object-safety-issue-22040.stderr @@ -1,10 +1,13 @@ error[E0038]: the trait `Expr` cannot be made into an object --> $DIR/object-safety-issue-22040.rs:12:23 | +LL | trait Expr: Debug + PartialEq { + | ---- --------- ...because it uses `Self` as a type parameter in this + | | + | this trait cannot be made into an object... +... LL | elements: Vec>, | ^^^^^^^^^^^^^ the trait `Expr` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr b/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr index 297cd876187fe..4dbb27b425b32 100644 --- a/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr +++ b/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr @@ -1,20 +1,28 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:22:1 + --> $DIR/object-safety-mentions-Self.rs:22:30 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, x: &Self); - | --- method `bar` references the `Self` type in its parameters or return type + | ----- ...because method `bar` references the `Self` type in this parameter ... LL | fn make_bar(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object + | ^^^^^^^^ the trait `Bar` cannot be made into an object + | + = help: consider moving `bar` to another trait error[E0038]: the trait `Baz` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:28:1 + --> $DIR/object-safety-mentions-Self.rs:28:30 | +LL | trait Baz { + | --- this trait cannot be made into an object... LL | fn baz(&self) -> Self; - | --- method `baz` references the `Self` type in its parameters or return type + | ---- ...because method `baz` references the `Self` type in its return type ... LL | fn make_baz(t: &T) -> &dyn Baz { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Baz` cannot be made into an object + | ^^^^^^^^ the trait `Baz` cannot be made into an object + | + = help: consider moving `baz` to another trait error: aborting due to 2 previous errors diff --git a/src/test/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr index 03b2b8da07533..89b273fb8adde 100644 --- a/src/test/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr @@ -1,24 +1,30 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-mentions-Self.rs:24:5 | +LL | trait Bar { + | --- this trait cannot be made into an object... LL | fn bar(&self, x: &Self); - | --- method `bar` references the `Self` type in its parameters or return type + | ----- ...because method `bar` references the `Self` type in this parameter ... LL | t | ^ the trait `Bar` cannot be made into an object | + = help: consider moving `bar` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` error[E0038]: the trait `Baz` cannot be made into an object --> $DIR/object-safety-mentions-Self.rs:30:5 | +LL | trait Baz { + | --- this trait cannot be made into an object... LL | fn baz(&self) -> Self; - | --- method `baz` references the `Self` type in its parameters or return type + | ---- ...because method `baz` references the `Self` type in its return type ... LL | t | ^ the trait `Baz` cannot be made into an object | + = help: consider moving `baz` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Baz>` for `&T` = note: required by cast to type `&dyn Baz` diff --git a/src/test/ui/object-safety/object-safety-no-static.curr.stderr b/src/test/ui/object-safety/object-safety-no-static.curr.stderr index 1641ce577719e..f878cf8b46241 100644 --- a/src/test/ui/object-safety/object-safety-no-static.curr.stderr +++ b/src/test/ui/object-safety/object-safety-no-static.curr.stderr @@ -1,11 +1,18 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-no-static.rs:12:1 + --> $DIR/object-safety-no-static.rs:12:18 | +LL | trait Foo { + | --- this trait cannot be made into an object... LL | fn foo() {} - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | fn diverges() -> Box { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object + | ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized {} + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr index 91a9285b63ccc..de56843962bea 100644 --- a/src/test/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr @@ -1,14 +1,20 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/object-safety-no-static.rs:22:27 | +LL | trait Foo { + | --- this trait cannot be made into an object... LL | fn foo() {} - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | let b: Box = Box::new(Bar); | ^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object | = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box` = note: required by cast to type `std::boxed::Box` +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized {} + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-sized-2.curr.stderr b/src/test/ui/object-safety/object-safety-sized-2.curr.stderr index 1e1d2bf64c427..2f605d8e904c5 100644 --- a/src/test/ui/object-safety/object-safety-sized-2.curr.stderr +++ b/src/test/ui/object-safety/object-safety-sized-2.curr.stderr @@ -1,10 +1,13 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized-2.rs:14:1 + --> $DIR/object-safety-sized-2.rs:14:30 | +LL | trait Bar + | --- this trait cannot be made into an object... +LL | where Self : Sized + | ----- ...because it requires `Self: Sized` +... LL | fn make_bar(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` + | ^^^^^^^^ the trait `Bar` cannot be made into an object error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr index 06ecfd019c841..2f1f06f4cf5fa 100644 --- a/src/test/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr @@ -1,10 +1,14 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-sized-2.rs:16:5 | +LL | trait Bar + | --- this trait cannot be made into an object... +LL | where Self : Sized + | ----- ...because it requires `Self: Sized` +... LL | t | ^ the trait `Bar` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` diff --git a/src/test/ui/object-safety/object-safety-sized.curr.stderr b/src/test/ui/object-safety/object-safety-sized.curr.stderr index 1a67e79e83d32..54f65c43d9cde 100644 --- a/src/test/ui/object-safety/object-safety-sized.curr.stderr +++ b/src/test/ui/object-safety/object-safety-sized.curr.stderr @@ -1,10 +1,13 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized.rs:12:1 + --> $DIR/object-safety-sized.rs:12:30 | +LL | trait Bar : Sized { + | --- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | fn make_bar(t: &T) -> &dyn Bar { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object - | - = note: the trait cannot require that `Self : Sized` + | ^^^^^^^^ the trait `Bar` cannot be made into an object error: aborting due to previous error diff --git a/src/test/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr b/src/test/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr index 3d88dfc40ed38..58c2b7721474f 100644 --- a/src/test/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr +++ b/src/test/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr @@ -1,10 +1,14 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-sized.rs:14:5 | +LL | trait Bar : Sized { + | --- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | t | ^ the trait `Bar` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T` = note: required by cast to type `&dyn Bar` diff --git a/src/test/ui/object-safety/object-safety-supertrait-mentions-Self.stderr b/src/test/ui/object-safety/object-safety-supertrait-mentions-Self.stderr index 8ae89832703d1..ef7f6bacd1233 100644 --- a/src/test/ui/object-safety/object-safety-supertrait-mentions-Self.stderr +++ b/src/test/ui/object-safety/object-safety-supertrait-mentions-Self.stderr @@ -1,10 +1,13 @@ error[E0038]: the trait `Baz` cannot be made into an object --> $DIR/object-safety-supertrait-mentions-Self.rs:15:31 | +LL | trait Baz : Bar { + | --- --------- ...because it uses `Self` as a type parameter in this + | | + | this trait cannot be made into an object... +... LL | fn make_baz(t: &T) -> &dyn Baz { | ^^^^^^^ the trait `Baz` cannot be made into an object - | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses error: aborting due to previous error diff --git a/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr b/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr index ad555efadf7ec..5ab423d9e2077 100644 --- a/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr +++ b/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr @@ -1,12 +1,8 @@ error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the data it references - --> $DIR/regions-free-region-ordering-callee-4.rs:5:1 + --> $DIR/regions-free-region-ordering-callee-4.rs:5:68 | -LL | / fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { -LL | | -LL | | // Do not infer ordering from closure argument types. -LL | | let z: Option<&'a &'b usize> = None; -LL | | } - | |_^ +LL | fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { + | ^^^^^^^^^^^^^^^^^^^^^ | note: the pointer is valid for the lifetime `'a` as defined on the function body at 5:14 --> $DIR/regions-free-region-ordering-callee-4.rs:5:14 diff --git a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr index c4ca7e970749c..6470ebf541b5b 100644 --- a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr +++ b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr @@ -1,11 +1,8 @@ error[E0491]: in type `&'x (dyn for<'z> Trait1<>::Foo> + 'x)`, reference has a longer lifetime than the data it references - --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:1 + --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:25 | -LL | / fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) -LL | | -LL | | { -LL | | } - | |_^ +LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the pointer is valid for the lifetime `'x` as defined on the function body at 21:11 --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:11 diff --git a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr index cc2245f81ace5..c35516d2c0871 100644 --- a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr +++ b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr @@ -67,15 +67,10 @@ LL | | } found `Project<'_, '_>` error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/regions-normalize-in-where-clause-list.rs:22:1 + --> $DIR/regions-normalize-in-where-clause-list.rs:22:4 | -LL | / fn bar<'a, 'b>() -LL | | -LL | | -LL | | where <() as Project<'a, 'b>>::Item : Eq -LL | | { -LL | | } - | |_^ +LL | fn bar<'a, 'b>() + | ^^^ | note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 22:8... --> $DIR/regions-normalize-in-where-clause-list.rs:22:8 @@ -88,15 +83,10 @@ note: ...but the lifetime must also be valid for the lifetime `'b` as defined on LL | fn bar<'a, 'b>() | ^^ note: ...so that the types are compatible - --> $DIR/regions-normalize-in-where-clause-list.rs:22:1 + --> $DIR/regions-normalize-in-where-clause-list.rs:22:4 | -LL | / fn bar<'a, 'b>() -LL | | -LL | | -LL | | where <() as Project<'a, 'b>>::Item : Eq -LL | | { -LL | | } - | |_^ +LL | fn bar<'a, 'b>() + | ^^^ = note: expected `Project<'a, 'b>` found `Project<'_, '_>` diff --git a/src/test/ui/resolve/issue-3907-2.stderr b/src/test/ui/resolve/issue-3907-2.stderr index 63ac11dc8ae01..d0c278d12d70a 100644 --- a/src/test/ui/resolve/issue-3907-2.stderr +++ b/src/test/ui/resolve/issue-3907-2.stderr @@ -1,10 +1,10 @@ error[E0038]: the trait `issue_3907::Foo` cannot be made into an object - --> $DIR/issue-3907-2.rs:11:1 + --> $DIR/issue-3907-2.rs:11:12 | LL | fn bar(_x: Foo) {} - | ^^^^^^^^^^^^^^^ the trait `issue_3907::Foo` cannot be made into an object + | ^^^ the trait `issue_3907::Foo` cannot be made into an object | - = note: associated function `bar` has no `self` parameter + = note: the trait cannot be made into an object because associated function `bar` has no `self` parameter error: aborting due to previous error diff --git a/src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr b/src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr index 653ccb9db949a..7948f7e9d6bc6 100644 --- a/src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr +++ b/src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr @@ -1,8 +1,13 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/arbitrary-self-types-not-object-safe.rs:33:32 | +LL | trait Foo { + | --- this trait cannot be made into an object... LL | fn foo(self: &Rc) -> usize; - | --- method `foo`'s `self` parameter cannot be dispatched on + | --------- + | | + | ...because method `foo`'s `self` parameter cannot be dispatched on + | help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^ the trait `Foo` cannot be made into an object @@ -10,8 +15,13 @@ LL | let x = Rc::new(5usize) as Rc; error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13 | +LL | trait Foo { + | --- this trait cannot be made into an object... LL | fn foo(self: &Rc) -> usize; - | --- method `foo`'s `self` parameter cannot be dispatched on + | --------- + | | + | ...because method `foo`'s `self` parameter cannot be dispatched on + | help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object diff --git a/src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr b/src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr index 33f1fa2e51be3..74e76b8265f70 100644 --- a/src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr +++ b/src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr @@ -1,8 +1,13 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13 | +LL | trait Foo { + | --- this trait cannot be made into an object... LL | fn foo(self: &Rc) -> usize; - | --- method `foo`'s `self` parameter cannot be dispatched on + | --------- + | | + | ...because method `foo`'s `self` parameter cannot be dispatched on + | help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr index 3c957970e51c2..a9ec6b9c02fe8 100644 --- a/src/test/ui/str/str-mut-idx.stderr +++ b/src/test/ui/str/str-mut-idx.stderr @@ -2,7 +2,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t --> $DIR/str-mut-idx.rs:4:15 | LL | fn bot() -> T { loop {} } - | --- - required by this bound in `bot` + | --- -- help: consider relaxing the implicit `Sized` restriction: `: ?Sized` + | | + | required by this bound in `bot` ... LL | s[1..2] = bot(); | ^^^ doesn't have a size known at compile-time diff --git a/src/test/ui/suggestions/imm-ref-trait-object.rs b/src/test/ui/suggestions/imm-ref-trait-object.rs index 288d6c699f59a..241dde9fec1d6 100644 --- a/src/test/ui/suggestions/imm-ref-trait-object.rs +++ b/src/test/ui/suggestions/imm-ref-trait-object.rs @@ -1,3 +1,8 @@ +// FIXME: missing sysroot spans (#53081) +// ignore-i586-unknown-linux-gnu +// ignore-i586-unknown-linux-musl +// ignore-i686-unknown-linux-musl + fn test(t: &dyn Iterator) -> u64 { t.min().unwrap() //~ ERROR the `min` method cannot be invoked on a trait object } diff --git a/src/test/ui/suggestions/imm-ref-trait-object.stderr b/src/test/ui/suggestions/imm-ref-trait-object.stderr index 9185eaa65c06d..c5fe6ddb8a9bf 100644 --- a/src/test/ui/suggestions/imm-ref-trait-object.stderr +++ b/src/test/ui/suggestions/imm-ref-trait-object.stderr @@ -1,8 +1,13 @@ error: the `min` method cannot be invoked on a trait object - --> $DIR/imm-ref-trait-object.rs:2:8 + --> $DIR/imm-ref-trait-object.rs:7:8 | LL | t.min().unwrap() | ^^^ + | + ::: $SRC_DIR/libcore/iter/traits/iterator.rs:LL:COL + | +LL | Self: Sized, + | ----- this has a `Sized` requirement | = note: you need `&mut dyn std::iter::Iterator` instead of `&dyn std::iter::Iterator` diff --git a/src/test/ui/suggestions/missing-assoc-type-bound-restriction.stderr b/src/test/ui/suggestions/missing-assoc-type-bound-restriction.stderr index c6f2e5cda66af..31d974ed43d99 100644 --- a/src/test/ui/suggestions/missing-assoc-type-bound-restriction.stderr +++ b/src/test/ui/suggestions/missing-assoc-type-bound-restriction.stderr @@ -1,20 +1,13 @@ error[E0277]: the trait bound `::Assoc: Child` is not satisfied - --> $DIR/missing-assoc-type-bound-restriction.rs:17:1 + --> $DIR/missing-assoc-type-bound-restriction.rs:17:19 | -LL | trait Parent { - | ------------ required by `Parent` +LL | trait Parent { + | ------------ required by `Parent` ... -LL | impl> Parent for ParentWrapper { - | ^ - help: consider further restricting the associated type: `where ::Assoc: Child` - | _| - | | -LL | | -LL | | type Ty = A; -LL | | type Assoc = ChildWrapper; -LL | | -LL | | -LL | | } - | |_^ the trait `Child` is not implemented for `::Assoc` +LL | impl> Parent for ParentWrapper { + | ^^^^^^ - help: consider further restricting the associated type: `where ::Assoc: Child` + | | + | the trait `Child` is not implemented for `::Assoc` error[E0277]: the trait bound `::Assoc: Child` is not satisfied --> $DIR/missing-assoc-type-bound-restriction.rs:20:5 diff --git a/src/test/ui/suggestions/object-unsafe-trait-references-self.rs b/src/test/ui/suggestions/object-unsafe-trait-references-self.rs new file mode 100644 index 0000000000000..07bf053e99665 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-references-self.rs @@ -0,0 +1,12 @@ +trait Trait { + fn baz(&self, _: Self) {} + fn bat(&self) -> Self {} +} + +fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object + +trait Other: Sized {} + +fn foo(x: &dyn Other) {} //~ ERROR the trait `Other` cannot be made into an object + +fn main() {} diff --git a/src/test/ui/suggestions/object-unsafe-trait-references-self.stderr b/src/test/ui/suggestions/object-unsafe-trait-references-self.stderr new file mode 100644 index 0000000000000..c3cfad70bf430 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-references-self.stderr @@ -0,0 +1,30 @@ +error[E0038]: the trait `Trait` cannot be made into an object + --> $DIR/object-unsafe-trait-references-self.rs:6:11 + | +LL | trait Trait { + | ----- this trait cannot be made into an object... +LL | fn baz(&self, _: Self) {} + | ---- ...because method `baz` references the `Self` type in this parameter +LL | fn bat(&self) -> Self {} + | ---- ...because method `bat` references the `Self` type in its return type +... +LL | fn bar(x: &dyn Trait) {} + | ^^^^^^^^^^ the trait `Trait` cannot be made into an object + | + = help: consider moving `baz` to another trait + = help: consider moving `bat` to another trait + +error[E0038]: the trait `Other` cannot be made into an object + --> $DIR/object-unsafe-trait-references-self.rs:10:11 + | +LL | trait Other: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +LL | +LL | fn foo(x: &dyn Other) {} + | ^^^^^^^^^^ the trait `Other` cannot be made into an object + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs new file mode 100644 index 0000000000000..75f99075eb18f --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs @@ -0,0 +1,16 @@ +#![allow(bare_trait_objects)] +trait A: Sized { + fn f(a: A) -> A; + //~^ ERROR associated item referring to unboxed trait object for its own trait + //~| ERROR the trait `A` cannot be made into an object +} +trait B { + fn f(a: B) -> B; + //~^ ERROR associated item referring to unboxed trait object for its own trait + //~| ERROR the trait `B` cannot be made into an object +} +trait C { + fn f(&self, a: C) -> C; +} + +fn main() {} diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr new file mode 100644 index 0000000000000..58be59602b9c5 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr @@ -0,0 +1,54 @@ +error: associated item referring to unboxed trait object for its own trait + --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + | +LL | trait A: Sized { + | - in this trait +LL | fn f(a: A) -> A; + | ^ ^ + | +help: you might have meant to use `Self` to refer to the implementing type + | +LL | fn f(a: Self) -> Self; + | ^^^^ ^^^^ + +error[E0038]: the trait `A` cannot be made into an object + --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + | +LL | trait A: Sized { + | - ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +LL | fn f(a: A) -> A; + | ^ the trait `A` cannot be made into an object + +error: associated item referring to unboxed trait object for its own trait + --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + | +LL | trait B { + | - in this trait +LL | fn f(a: B) -> B; + | ^ ^ + | +help: you might have meant to use `Self` to refer to the implementing type + | +LL | fn f(a: Self) -> Self; + | ^^^^ ^^^^ + +error[E0038]: the trait `B` cannot be made into an object + --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + | +LL | trait B { + | - this trait cannot be made into an object... +LL | fn f(a: B) -> B; + | - ^ the trait `B` cannot be made into an object + | | + | ...because associated function `f` has no `self` parameter + | +help: consider turning `f` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn f(a: B) -> B where Self: Sized; + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.fixed b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.fixed new file mode 100644 index 0000000000000..c4b8960b65e4a --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.fixed @@ -0,0 +1,13 @@ +// run-rustfix +#![allow(unused_variables, dead_code)] + +trait Trait { + fn foo() where Self: Other, Self: Sized, { } + fn bar(self: &Self) {} //~ ERROR invalid `self` parameter type +} + +fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object + +trait Other {} + +fn main() {} diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.rs b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.rs new file mode 100644 index 0000000000000..38d9aea16ebf6 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.rs @@ -0,0 +1,13 @@ +// run-rustfix +#![allow(unused_variables, dead_code)] + +trait Trait { + fn foo() where Self: Other, { } + fn bar(self: ()) {} //~ ERROR invalid `self` parameter type +} + +fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object + +trait Other {} + +fn main() {} diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr new file mode 100644 index 0000000000000..6466a768ecbe9 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr @@ -0,0 +1,35 @@ +error[E0038]: the trait `Trait` cannot be made into an object + --> $DIR/object-unsafe-trait-should-use-where-sized.rs:9:11 + | +LL | trait Trait { + | ----- this trait cannot be made into an object... +LL | fn foo() where Self: Other, { } + | --- ...because associated function `foo` has no `self` parameter +LL | fn bar(self: ()) {} + | -- ...because method `bar`'s `self` parameter cannot be dispatched on +... +LL | fn bar(x: &dyn Trait) {} + | ^^^^^^^^^^ the trait `Trait` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Other, Self: Sized, { } + | ^^^^^^^^^^^^^ +help: consider changing method `bar`'s `self` parameter to be `&self` + | +LL | fn bar(self: &Self) {} + | ^^^^^ + +error[E0307]: invalid `self` parameter type: () + --> $DIR/object-unsafe-trait-should-use-where-sized.rs:6:18 + | +LL | fn bar(self: ()) {} + | ^^ + | + = note: type of `self` must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0038, E0307. +For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/traits/trait-alias/trait-alias-object-fail.rs b/src/test/ui/traits/trait-alias/trait-alias-object-fail.rs index d62fd7e59c920..3be8db8663ab7 100644 --- a/src/test/ui/traits/trait-alias/trait-alias-object-fail.rs +++ b/src/test/ui/traits/trait-alias/trait-alias-object-fail.rs @@ -1,3 +1,8 @@ +// FIXME: missing sysroot spans (#53081) +// ignore-i586-unknown-linux-gnu +// ignore-i586-unknown-linux-musl +// ignore-i686-unknown-linux-musl + #![feature(trait_alias)] trait EqAlias = Eq; diff --git a/src/test/ui/traits/trait-alias/trait-alias-object-fail.stderr b/src/test/ui/traits/trait-alias/trait-alias-object-fail.stderr index 5551b1303b927..21818097bd6a0 100644 --- a/src/test/ui/traits/trait-alias/trait-alias-object-fail.stderr +++ b/src/test/ui/traits/trait-alias/trait-alias-object-fail.stderr @@ -1,13 +1,16 @@ error[E0038]: the trait `std::cmp::Eq` cannot be made into an object - --> $DIR/trait-alias-object-fail.rs:7:13 + --> $DIR/trait-alias-object-fail.rs:12:13 | LL | let _: &dyn EqAlias = &123; | ^^^^^^^^^^^ the trait `std::cmp::Eq` cannot be made into an object + | + ::: $SRC_DIR/libcore/cmp.rs:LL:COL | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses +LL | pub trait Eq: PartialEq { + | --------------- the trait cannot be made into an object because it uses `Self` as a type parameter in this error[E0191]: the value of the associated type `Item` (from trait `std::iter::Iterator`) must be specified - --> $DIR/trait-alias-object-fail.rs:9:17 + --> $DIR/trait-alias-object-fail.rs:14:17 | LL | let _: &dyn IteratorAlias = &vec![123].into_iter(); | ^^^^^^^^^^^^^ help: specify the associated type: `IteratorAlias` diff --git a/src/test/ui/traits/trait-alias/trait-alias-wf.stderr b/src/test/ui/traits/trait-alias/trait-alias-wf.stderr index 4355a517bd724..b71c0d719ff3f 100644 --- a/src/test/ui/traits/trait-alias/trait-alias-wf.stderr +++ b/src/test/ui/traits/trait-alias/trait-alias-wf.stderr @@ -1,13 +1,12 @@ error[E0277]: the trait bound `T: Foo` is not satisfied - --> $DIR/trait-alias-wf.rs:5:1 + --> $DIR/trait-alias-wf.rs:5:14 | LL | trait A {} | --------------- required by `A` LL | trait B = A; - | ^^^^^^^^-^^^^^^^^^ - | | | - | | help: consider restricting this bound: `T: Foo` - | the trait `Foo` is not implemented for `T` + | - ^^^^ the trait `Foo` is not implemented for `T` + | | + | help: consider restricting this bound: `T: Foo` error: aborting due to previous error diff --git a/src/test/ui/traits/trait-bounds-on-structs-and-enums-in-fns.stderr b/src/test/ui/traits/trait-bounds-on-structs-and-enums-in-fns.stderr index 3c68d461f80d6..a2253021a7f1f 100644 --- a/src/test/ui/traits/trait-bounds-on-structs-and-enums-in-fns.stderr +++ b/src/test/ui/traits/trait-bounds-on-structs-and-enums-in-fns.stderr @@ -1,20 +1,20 @@ error[E0277]: the trait bound `u32: Trait` is not satisfied - --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:13:1 + --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:13:15 | LL | struct Foo { | ------------------- required by `Foo` ... LL | fn explode(x: Foo) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u32` + | ^^^^^^^^ the trait `Trait` is not implemented for `u32` error[E0277]: the trait bound `f32: Trait` is not satisfied - --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:16:1 + --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:16:14 | LL | enum Bar { | ----------------- required by `Bar` ... LL | fn kaboom(y: Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `f32` + | ^^^^^^^^ the trait `Trait` is not implemented for `f32` error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/trait-bounds-on-structs-and-enums-xc.stderr b/src/test/ui/traits/trait-bounds-on-structs-and-enums-xc.stderr index 2f2c903a45c19..c5a7746afdfdb 100644 --- a/src/test/ui/traits/trait-bounds-on-structs-and-enums-xc.stderr +++ b/src/test/ui/traits/trait-bounds-on-structs-and-enums-xc.stderr @@ -1,16 +1,16 @@ error[E0277]: the trait bound `usize: trait_bounds_on_structs_and_enums_xc::Trait` is not satisfied - --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:7:1 + --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:7:15 | LL | fn explode(x: Foo) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `trait_bounds_on_structs_and_enums_xc::Trait` is not implemented for `usize` + | ^^^^^^^^^^ the trait `trait_bounds_on_structs_and_enums_xc::Trait` is not implemented for `usize` | = note: required by `trait_bounds_on_structs_and_enums_xc::Foo` error[E0277]: the trait bound `f32: trait_bounds_on_structs_and_enums_xc::Trait` is not satisfied - --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:10:1 + --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:10:14 | LL | fn kaboom(y: Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `trait_bounds_on_structs_and_enums_xc::Trait` is not implemented for `f32` + | ^^^^^^^^ the trait `trait_bounds_on_structs_and_enums_xc::Trait` is not implemented for `f32` | = note: required by `trait_bounds_on_structs_and_enums_xc::Bar` diff --git a/src/test/ui/traits/trait-item-privacy.stderr b/src/test/ui/traits/trait-item-privacy.stderr index 4df8845de279a..072328ab50c70 100644 --- a/src/test/ui/traits/trait-item-privacy.stderr +++ b/src/test/ui/traits/trait-item-privacy.stderr @@ -111,16 +111,22 @@ error[E0038]: the trait `assoc_const::C` cannot be made into an object --> $DIR/trait-item-privacy.rs:101:5 | LL | const A: u8 = 0; - | - the trait cannot contain associated consts like `A` + | - ...because it contains this associated `const` ... LL | const B: u8 = 0; - | - the trait cannot contain associated consts like `B` + | - ...because it contains this associated `const` ... +LL | pub trait C: A + B { + | - this trait cannot be made into an object... LL | const C: u8 = 0; - | - the trait cannot contain associated consts like `C` + | - ...because it contains this associated `const` ... LL | C::A; | ^^^^ the trait `assoc_const::C` cannot be made into an object + | + = help: consider moving `C` to another trait + = help: consider moving `B` to another trait + = help: consider moving `A` to another trait error[E0223]: ambiguous associated type --> $DIR/trait-item-privacy.rs:115:12 diff --git a/src/test/ui/traits/trait-object-macro-matcher.stderr b/src/test/ui/traits/trait-object-macro-matcher.stderr index 6b5effaad9bc4..a8511f63c16a5 100644 --- a/src/test/ui/traits/trait-object-macro-matcher.stderr +++ b/src/test/ui/traits/trait-object-macro-matcher.stderr @@ -10,7 +10,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object LL | m!(dyn Copy + Send + 'static); | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` + = note: the trait cannot be made into an object because it requires `Self: Sized` error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/trait-object-safety.stderr b/src/test/ui/traits/trait-object-safety.stderr index 028e9eedd641a..162e9249b880e 100644 --- a/src/test/ui/traits/trait-object-safety.stderr +++ b/src/test/ui/traits/trait-object-safety.stderr @@ -1,23 +1,36 @@ error[E0038]: the trait `Tr` cannot be made into an object --> $DIR/trait-object-safety.rs:15:22 | +LL | trait Tr { + | -- this trait cannot be made into an object... LL | fn foo(); - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | let _: &dyn Tr = &St; | ^^^ the trait `Tr` cannot be made into an object | = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Tr>` for `&St` = note: required by cast to type `&dyn Tr` +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error[E0038]: the trait `Tr` cannot be made into an object --> $DIR/trait-object-safety.rs:15:12 | +LL | trait Tr { + | -- this trait cannot be made into an object... LL | fn foo(); - | --- associated function `foo` has no `self` parameter + | --- ...because associated function `foo` has no `self` parameter ... LL | let _: &dyn Tr = &St; | ^^^^^^^ the trait `Tr` cannot be made into an object + | +help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects + | +LL | fn foo() where Self: Sized; + | ^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/trait-suggest-where-clause.stderr b/src/test/ui/traits/trait-suggest-where-clause.stderr index 831dd439298d9..9680d58b8c0c7 100644 --- a/src/test/ui/traits/trait-suggest-where-clause.stderr +++ b/src/test/ui/traits/trait-suggest-where-clause.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `U` cannot be known at compilation tim --> $DIR/trait-suggest-where-clause.rs:11:20 | LL | fn check() { - | -- help: consider further restricting this bound: `U: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | // suggest a where-clause, if needed LL | mem::size_of::(); | ^ doesn't have a size known at compile-time @@ -19,7 +19,7 @@ error[E0277]: the size for values of type `U` cannot be known at compilation tim --> $DIR/trait-suggest-where-clause.rs:14:5 | LL | fn check() { - | -- help: consider further restricting this bound: `U: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | mem::size_of::>(); | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time diff --git a/src/test/ui/traits/trait-test-2.stderr b/src/test/ui/traits/trait-test-2.stderr index 9b750d382ec96..9d1eef547568e 100644 --- a/src/test/ui/traits/trait-test-2.stderr +++ b/src/test/ui/traits/trait-test-2.stderr @@ -14,24 +14,31 @@ error[E0038]: the trait `bar` cannot be made into an object --> $DIR/trait-test-2.rs:11:16 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } - | --- ---- method `blah` has generic type parameters - | | - | method `dup` references the `Self` type in its parameters or return type + | --- ---- ---- ...because method `blah` has generic type parameters + | | | + | | ...because method `dup` references the `Self` type in its return type + | this trait cannot be made into an object... ... LL | (box 10 as Box).dup(); | ^^^^^^^^^^^^ the trait `bar` cannot be made into an object + | + = help: consider moving `dup` to another trait + = help: consider moving `blah` to another trait error[E0038]: the trait `bar` cannot be made into an object --> $DIR/trait-test-2.rs:11:6 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } - | --- ---- method `blah` has generic type parameters - | | - | method `dup` references the `Self` type in its parameters or return type + | --- ---- ---- ...because method `blah` has generic type parameters + | | | + | | ...because method `dup` references the `Self` type in its return type + | this trait cannot be made into an object... ... LL | (box 10 as Box).dup(); | ^^^^^^ the trait `bar` cannot be made into an object | + = help: consider moving `dup` to another trait + = help: consider moving `blah` to another trait = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box<{integer}>` = note: required by cast to type `std::boxed::Box` diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr index a4d9a672154fb..08b26b8fc1307 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr @@ -1,10 +1,8 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:7:1 + --> $DIR/generic_duplicate_lifetime_param.rs:7:26 | -LL | / fn one<'a>(t: &'a ()) -> Two<'a, 'a> { -LL | | t -LL | | } - | |_^ +LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> { + | ^^^^^^^^^^^ | note: lifetime used multiple times --> $DIR/generic_duplicate_lifetime_param.rs:5:10 diff --git a/src/test/ui/type/type-check-defaults.stderr b/src/test/ui/type/type-check-defaults.stderr index 6f84b37d61249..e5d2ebda31858 100644 --- a/src/test/ui/type/type-check-defaults.stderr +++ b/src/test/ui/type/type-check-defaults.stderr @@ -47,15 +47,14 @@ LL | trait TraitBound {} | required by `TraitBound` error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied - --> $DIR/type-check-defaults.rs:21:1 + --> $DIR/type-check-defaults.rs:21:25 | LL | trait Super { } | -------------------- required by `Super` LL | trait Base: Super { } - | ^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | help: consider restricting this bound: `T: std::marker::Copy` - | the trait `std::marker::Copy` is not implemented for `T` + | - ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` + | | + | help: consider restricting this bound: `T: std::marker::Copy` error[E0277]: cannot add `u8` to `i32` --> $DIR/type-check-defaults.rs:24:66 diff --git a/src/test/ui/type/type-check/issue-40294.rs b/src/test/ui/type/type-check/issue-40294.rs index 7e6429ccfbe30..5493a4e5f10a8 100644 --- a/src/test/ui/type/type-check/issue-40294.rs +++ b/src/test/ui/type/type-check/issue-40294.rs @@ -2,8 +2,8 @@ trait Foo: Sized { fn foo(self); } -fn foo<'a,'b,T>(x: &'a T, y: &'b T) //~ ERROR type annotations needed - where &'a T : Foo, +fn foo<'a,'b,T>(x: &'a T, y: &'b T) + where &'a T : Foo, //~ ERROR type annotations needed &'b T : Foo { x.foo(); diff --git a/src/test/ui/type/type-check/issue-40294.stderr b/src/test/ui/type/type-check/issue-40294.stderr index 4fc0285509149..2c889b6c2ca0a 100644 --- a/src/test/ui/type/type-check/issue-40294.stderr +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -1,17 +1,11 @@ error[E0283]: type annotations needed - --> $DIR/issue-40294.rs:5:1 + --> $DIR/issue-40294.rs:6:19 | -LL | trait Foo: Sized { - | ---------------- required by `Foo` +LL | trait Foo: Sized { + | ---------------- required by `Foo` ... -LL | / fn foo<'a,'b,T>(x: &'a T, y: &'b T) -LL | | where &'a T : Foo, -LL | | &'b T : Foo -LL | | { -LL | | x.foo(); -LL | | y.foo(); -LL | | } - | |_^ cannot infer type for reference `&'a T` +LL | where &'a T : Foo, + | ^^^ cannot infer type for reference `&'a T` | = note: cannot resolve `&'a T: Foo` diff --git a/src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr b/src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr index b315fe9df8afd..539189982a8d7 100644 --- a/src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr +++ b/src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr @@ -14,10 +14,14 @@ error[E0038]: the trait `MyAdd` cannot be made into an object --> $DIR/type-parameter-defaults-referencing-Self-ppaux.rs:14:18 | LL | trait MyAdd { fn add(&self, other: &Rhs) -> Self; } - | --- method `add` references the `Self` type in its parameters or return type + | ----- ---- ...because method `add` references the `Self` type in its return type + | | + | this trait cannot be made into an object... ... LL | let y = x as dyn MyAdd; | ^^^^^^^^^^^^^^ the trait `MyAdd` cannot be made into an object + | + = help: consider moving `add` to another trait error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-sized-field.stderr b/src/test/ui/union/union-sized-field.stderr index c9fec1d21d152..62dacd064bed0 100644 --- a/src/test/ui/union/union-sized-field.stderr +++ b/src/test/ui/union/union-sized-field.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/union-sized-field.rs:4:5 | LL | union Foo { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | value: T, | ^^^^^^^^ doesn't have a size known at compile-time | @@ -14,7 +14,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/union-sized-field.rs:9:5 | LL | struct Foo2 { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | value: T, | ^^^^^^^^ doesn't have a size known at compile-time | @@ -26,7 +26,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim --> $DIR/union-sized-field.rs:15:11 | LL | enum Foo3 { - | -- help: consider further restricting this bound: `T: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | Value(T), | ^ doesn't have a size known at compile-time | diff --git a/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr b/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr index 7e9a2316be2bf..4cd2098eef256 100644 --- a/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr +++ b/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr @@ -1,6 +1,9 @@ error: the `foo` method cannot be invoked on a trait object --> $DIR/by-value-trait-object-safety.rs:18:7 | +LL | fn foo(self) -> String where Self: Sized; + | ----- this has a `Sized` requirement +... LL | x.foo(); | ^^^ diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index bd97b0203b510..772de23e64cf0 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -4,9 +4,9 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim LL | fn bar() { } | --- - required by this bound in `bar` LL | fn foo() { bar::() } - | -- ^ doesn't have a size known at compile-time + | - ^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `T: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `T` = note: to learn more, visit diff --git a/src/test/ui/unsized/unsized-enum.stderr b/src/test/ui/unsized/unsized-enum.stderr index 341d3e4cc2df2..88f7b1f77aee0 100644 --- a/src/test/ui/unsized/unsized-enum.stderr +++ b/src/test/ui/unsized/unsized-enum.stderr @@ -5,9 +5,9 @@ LL | enum Foo { FooSome(U), FooNone } | ----------- required by `Foo` LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } - | -- ^^^^^^ doesn't have a size known at compile-time + | - ^^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `T: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `T` = note: to learn more, visit diff --git a/src/test/ui/unsized/unsized-enum2.stderr b/src/test/ui/unsized/unsized-enum2.stderr index e85b6d662f9d5..bc3b3831f3269 100644 --- a/src/test/ui/unsized/unsized-enum2.stderr +++ b/src/test/ui/unsized/unsized-enum2.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `W` cannot be known at compilation tim --> $DIR/unsized-enum2.rs:23:8 | LL | enum E { - | -- help: consider further restricting this bound: `W: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | // parameter LL | VA(W), | ^ doesn't have a size known at compile-time @@ -15,7 +15,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized-enum2.rs:25:8 | LL | enum E { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | VB{x: X}, | ^^^^ doesn't have a size known at compile-time @@ -28,7 +28,7 @@ error[E0277]: the size for values of type `Y` cannot be known at compilation tim --> $DIR/unsized-enum2.rs:27:15 | LL | enum E { - | -- help: consider further restricting this bound: `Y: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | VC(isize, Y), | ^ doesn't have a size known at compile-time @@ -41,7 +41,7 @@ error[E0277]: the size for values of type `Z` cannot be known at compilation tim --> $DIR/unsized-enum2.rs:29:18 | LL | enum E { - | -- help: consider further restricting this bound: `Z: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | VD{u: isize, x: Z}, | ^^^^ doesn't have a size known at compile-time 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 280b8fd43cab0..5688ae5b89a04 100644 --- a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr @@ -5,9 +5,9 @@ LL | struct S5(Y); | ---------------- required by `S5` LL | LL | impl S5 { - | -- ^^^^^ doesn't have a size known at compile-time + | - ^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index 2894d5d56710d..653fb5c1ae8dc 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -5,9 +5,9 @@ LL | struct Foo { data: T } | ------------- required by `Foo` LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } - | -- ^^^^^^ doesn't have a size known at compile-time + | - ^^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `T: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `T` = note: to learn more, visit @@ -19,9 +19,9 @@ 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 + | - ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `T: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: within `Bar`, the trait `std::marker::Sized` is not implemented for `T` = note: to learn more, visit 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 ba1550439c0d9..3597073e7e6c6 100644 --- a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr @@ -5,9 +5,9 @@ LL | struct S5(Y); | ---------------- required by `S5` LL | LL | impl T3 for S5 { - | -- ^^^^^ doesn't have a size known at compile-time + | - ^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit 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 41371d63f9e53..b37d9f9d5369e 100644 --- a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr @@ -2,9 +2,9 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized-trait-impl-trait-arg.rs:8:17 | LL | impl T2 for S4 { - | -- ^^^^^ doesn't have a size known at compile-time + | - ^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit diff --git a/src/test/ui/unsized3.stderr b/src/test/ui/unsized3.stderr index 232296ad09126..e97d00fc4741d 100644 --- a/src/test/ui/unsized3.stderr +++ b/src/test/ui/unsized3.stderr @@ -2,12 +2,14 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized3.rs:7:13 | LL | fn f1(x: &X) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f2::(x); | ^ doesn't have a size known at compile-time ... LL | fn f2(x: &X) { - | -- - required by this bound in `f2` + | -- -- help: consider relaxing the implicit `Sized` restriction: `: ?Sized` + | | + | required by this bound in `f2` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit @@ -16,12 +18,14 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized3.rs:18:13 | LL | fn f3(x: &X) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f4::(x); | ^ doesn't have a size known at compile-time ... LL | fn f4(x: &X) { - | -- - required by this bound in `f4` + | -- - - help: consider relaxing the implicit `Sized` restriction: `+ ?Sized` + | | + | required by this bound in `f4` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit @@ -33,7 +37,7 @@ LL | fn f5(x: &Y) {} | -- - required by this bound in `f5` ... LL | fn f8(x1: &S, x2: &S) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f5(x1); | ^^ doesn't have a size known at compile-time | @@ -45,7 +49,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized3.rs:40:8 | LL | fn f9(x1: Box>) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f5(&(*x1, 34)); | ^^^^^^^^^^ doesn't have a size known at compile-time | @@ -58,7 +62,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized3.rs:45:9 | LL | fn f10(x1: Box>) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); | ^^^^^^^^^ doesn't have a size known at compile-time | @@ -75,7 +79,7 @@ LL | fn f5(x: &Y) {} | -- - required by this bound in `f5` ... LL | fn f10(x1: Box>) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); | ^^^^^^^^^^ doesn't have a size known at compile-time | diff --git a/src/test/ui/unsized5.stderr b/src/test/ui/unsized5.stderr index bfd3f4aa691eb..de4da309791c0 100644 --- a/src/test/ui/unsized5.stderr +++ b/src/test/ui/unsized5.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized5.rs:4:5 | LL | struct S1 { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f1: X, | ^^^^^ doesn't have a size known at compile-time | @@ -14,7 +14,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized5.rs:10:5 | LL | struct S2 { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | f: isize, LL | g: X, | ^^^^ doesn't have a size known at compile-time @@ -47,7 +47,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized5.rs:25:8 | LL | enum E { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | V1(X, isize), | ^ doesn't have a size known at compile-time | @@ -59,7 +59,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized5.rs:29:8 | LL | enum F { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | V2{f1: X, f: isize}, | ^^^^^ doesn't have a size known at compile-time | diff --git a/src/test/ui/unsized6.stderr b/src/test/ui/unsized6.stderr index 95acd987a5a27..337afd2ee7e10 100644 --- a/src/test/ui/unsized6.stderr +++ b/src/test/ui/unsized6.stderr @@ -2,7 +2,7 @@ error[E0277]: the size for values of type `Y` cannot be known at compilation tim --> $DIR/unsized6.rs:9:9 | LL | fn f1(x: &X) { - | -- help: consider further restricting this bound: `Y: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let y: Y; | ^ doesn't have a size known at compile-time @@ -16,7 +16,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:7:12 | LL | fn f1(x: &X) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let _: W; // <-- this is OK, no bindings created, no initializer. LL | let _: (isize, (X, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -29,7 +29,7 @@ error[E0277]: the size for values of type `Z` cannot be known at compilation tim --> $DIR/unsized6.rs:11:12 | LL | fn f1(x: &X) { - | -- help: consider further restricting this bound: `Z: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let y: (isize, (Z, usize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -42,7 +42,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:15:9 | LL | fn f2(x: &X) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let y: X; | ^ doesn't have a size known at compile-time | @@ -55,7 +55,7 @@ error[E0277]: the size for values of type `Y` cannot be known at compilation tim --> $DIR/unsized6.rs:17:12 | LL | fn f2(x: &X) { - | -- help: consider further restricting this bound: `Y: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let y: (isize, (Y, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -68,7 +68,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:22:9 | LL | fn f3(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let y: X = *x1; | ^ doesn't have a size known at compile-time | @@ -81,7 +81,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:24:9 | LL | fn f3(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let y = *x2; | ^ doesn't have a size known at compile-time @@ -95,7 +95,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:26:10 | LL | fn f3(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let (y, z) = (*x3, 4); | ^ doesn't have a size known at compile-time @@ -109,7 +109,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:30:9 | LL | fn f4(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` LL | let y: X = *x1; | ^ doesn't have a size known at compile-time | @@ -122,7 +122,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:32:9 | LL | fn f4(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let y = *x2; | ^ doesn't have a size known at compile-time @@ -136,7 +136,7 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:34:10 | LL | fn f4(x1: Box, x2: Box, x3: Box) { - | -- help: consider further restricting this bound: `X: std::marker::Sized +` + | - this type parameter needs to be `std::marker::Sized` ... LL | let (y, z) = (*x3, 4); | ^ doesn't have a size known at compile-time @@ -150,9 +150,9 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:38:18 | LL | fn g1(x: X) {} - | -- ^ doesn't have a size known at compile-time + | - ^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit @@ -163,9 +163,9 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized6.rs:40:22 | LL | fn g2(x: X) {} - | -- ^ doesn't have a size known at compile-time + | - ^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit diff --git a/src/test/ui/unsized7.stderr b/src/test/ui/unsized7.stderr index c77503a6f87aa..0f71c5f6f8fe6 100644 --- a/src/test/ui/unsized7.stderr +++ b/src/test/ui/unsized7.stderr @@ -2,9 +2,9 @@ error[E0277]: the size for values of type `X` cannot be known at compilation tim --> $DIR/unsized7.rs:12:21 | LL | impl T1 for S3 { - | -- ^^^^^ doesn't have a size known at compile-time + | - ^^^^^ doesn't have a size known at compile-time | | - | help: consider further restricting this bound: `X: std::marker::Sized +` + | this type parameter needs to be `std::marker::Sized` | = help: the trait `std::marker::Sized` is not implemented for `X` = note: to learn more, visit diff --git a/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.stderr b/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.stderr index 0b63aef2bce10..eefb450155cdb 100644 --- a/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.stderr +++ b/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.stderr @@ -1,30 +1,42 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj-box.rs:16:33 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let t_box: Box = Box::new(S); | ^^^^^^^^^^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box` = note: required by cast to type `std::boxed::Box` error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj-box.rs:17:15 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | takes_box(Box::new(S)); | ^^^^^^^^^^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box` = note: required by cast to type `std::boxed::Box<(dyn Trait + 'static)>` error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj-box.rs:15:5 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | Box::new(S) as Box; | ^^^^^^^^^^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::boxed::Box` = note: required by cast to type `std::boxed::Box` diff --git a/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr b/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr index 7aeefd731fb28..5e645382d1b21 100644 --- a/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr +++ b/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr @@ -1,30 +1,42 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:16:25 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let t: &dyn Trait = &S; | ^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Trait>` for `&S` = note: required by cast to type `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:17:17 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | takes_trait(&S); | ^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Trait>` for `&S` = note: required by cast to type `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:15:5 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | &S as &dyn Trait; | ^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Trait>` for `&S` = note: required by cast to type `&dyn Trait` diff --git a/src/test/ui/wf/wf-enum-bound.rs b/src/test/ui/wf/wf-enum-bound.rs index c9eb9d894331e..042a2cb09d27b 100644 --- a/src/test/ui/wf/wf-enum-bound.rs +++ b/src/test/ui/wf/wf-enum-bound.rs @@ -6,8 +6,8 @@ trait ExtraCopy { } -enum SomeEnum //~ ERROR E0277 - where T: ExtraCopy +enum SomeEnum + where T: ExtraCopy //~ ERROR E0277 { SomeVariant(T,U) } diff --git a/src/test/ui/wf/wf-enum-bound.stderr b/src/test/ui/wf/wf-enum-bound.stderr index eaacd6b6881ef..0d22d18bf6fd9 100644 --- a/src/test/ui/wf/wf-enum-bound.stderr +++ b/src/test/ui/wf/wf-enum-bound.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-enum-bound.rs:9:1 + --> $DIR/wf-enum-bound.rs:10:14 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` -LL | -LL | / enum SomeEnum -LL | | where T: ExtraCopy - | | - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` -LL | | { -LL | | SomeVariant(T,U) -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` +... +LL | where T: ExtraCopy + | ^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index 9b8b04a7b86a3..1c530ece29580 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -1,34 +1,31 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-fn-where-clause.rs:8:1 + --> $DIR/wf-fn-where-clause.rs:8:24 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` LL | -LL | fn foo() where T: ExtraCopy - | ^ - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` - | _| - | | -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | fn foo() where T: ExtraCopy + | ^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error[E0277]: the size for values of type `(dyn std::marker::Copy + 'static)` cannot be known at compilation time - --> $DIR/wf-fn-where-clause.rs:12:1 + --> $DIR/wf-fn-where-clause.rs:12:16 | LL | fn bar() where Vec:, {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `(dyn std::marker::Copy + 'static)` = note: to learn more, visit = note: required by `std::vec::Vec` error[E0038]: the trait `std::marker::Copy` cannot be made into an object - --> $DIR/wf-fn-where-clause.rs:12:1 + --> $DIR/wf-fn-where-clause.rs:12:16 | LL | fn bar() where Vec:, {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object + | ^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` + = note: the trait cannot be made into an object because it requires `Self: Sized` error: aborting due to 3 previous errors diff --git a/src/test/ui/wf/wf-in-fn-arg.stderr b/src/test/ui/wf/wf-in-fn-arg.stderr index 3798ba1ec6e75..b8e88de54c2f1 100644 --- a/src/test/ui/wf/wf-in-fn-arg.stderr +++ b/src/test/ui/wf/wf-in-fn-arg.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied - --> $DIR/wf-in-fn-arg.rs:10:1 + --> $DIR/wf-in-fn-arg.rs:10:14 | -LL | struct MustBeCopy { - | ------------------------- required by `MustBeCopy` +LL | struct MustBeCopy { + | ------------------------- required by `MustBeCopy` ... -LL | fn bar(_: &MustBeCopy) - | ^ - help: consider restricting this bound: `T: std::marker::Copy` - | _| - | | -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `T` +LL | fn bar(_: &MustBeCopy) + | - ^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` + | | + | help: consider restricting this bound: `T: std::marker::Copy` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-in-fn-ret.stderr b/src/test/ui/wf/wf-in-fn-ret.stderr index 2e46ce4900033..6ca1626d3aef5 100644 --- a/src/test/ui/wf/wf-in-fn-ret.stderr +++ b/src/test/ui/wf/wf-in-fn-ret.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied - --> $DIR/wf-in-fn-ret.rs:10:1 + --> $DIR/wf-in-fn-ret.rs:10:16 | -LL | struct MustBeCopy { - | ------------------------- required by `MustBeCopy` +LL | struct MustBeCopy { + | ------------------------- required by `MustBeCopy` ... -LL | fn bar() -> MustBeCopy - | ^ - help: consider restricting this bound: `T: std::marker::Copy` - | _| - | | -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `T` +LL | fn bar() -> MustBeCopy + | - ^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` + | | + | help: consider restricting this bound: `T: std::marker::Copy` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-in-fn-where-clause.rs b/src/test/ui/wf/wf-in-fn-where-clause.rs index 65a1771d41a48..e55295a3b2578 100644 --- a/src/test/ui/wf/wf-in-fn-where-clause.rs +++ b/src/test/ui/wf/wf-in-fn-where-clause.rs @@ -6,8 +6,8 @@ trait MustBeCopy { } -fn bar() //~ ERROR E0277 - where T: MustBeCopy +fn bar() + where T: MustBeCopy //~ ERROR E0277 { } diff --git a/src/test/ui/wf/wf-in-fn-where-clause.stderr b/src/test/ui/wf/wf-in-fn-where-clause.stderr index 979802dec4998..495041b7dadf8 100644 --- a/src/test/ui/wf/wf-in-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-in-fn-where-clause.stderr @@ -1,15 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-in-fn-where-clause.rs:9:1 + --> $DIR/wf-in-fn-where-clause.rs:10:14 | -LL | trait MustBeCopy { - | ------------------------ required by `MustBeCopy` +LL | trait MustBeCopy { + | ------------------------ required by `MustBeCopy` ... -LL | / fn bar() -LL | | where T: MustBeCopy - | | - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | where T: MustBeCopy + | ^^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-inherent-impl-method-where-clause.stderr b/src/test/ui/wf/wf-inherent-impl-method-where-clause.stderr index 21f825ac9ef9a..e9c1c8ddaf640 100644 --- a/src/test/ui/wf/wf-inherent-impl-method-where-clause.stderr +++ b/src/test/ui/wf/wf-inherent-impl-method-where-clause.stderr @@ -1,14 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-inherent-impl-method-where-clause.rs:12:5 + --> $DIR/wf-inherent-impl-method-where-clause.rs:12:27 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` ... -LL | impl Foo { - | - help: consider restricting this bound: `U: std::marker::Copy` -LL | / fn foo(self) where T: ExtraCopy -LL | | {} - | |______^ the trait `std::marker::Copy` is not implemented for `U` +LL | impl Foo { + | - help: consider restricting this bound: `U: std::marker::Copy` +LL | fn foo(self) where T: ExtraCopy + | ^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-inherent-impl-where-clause.stderr b/src/test/ui/wf/wf-inherent-impl-where-clause.stderr index 35b9093381329..a4e6dce39cdcd 100644 --- a/src/test/ui/wf/wf-inherent-impl-where-clause.stderr +++ b/src/test/ui/wf/wf-inherent-impl-where-clause.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-inherent-impl-where-clause.rs:11:1 + --> $DIR/wf-inherent-impl-where-clause.rs:11:29 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` ... -LL | impl Foo where T: ExtraCopy - | ^ - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` - | _| - | | -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | impl Foo where T: ExtraCopy + | ^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-object-safe.stderr b/src/test/ui/wf/wf-object-safe.stderr index 0d8441f87e7e7..8935d766354fe 100644 --- a/src/test/ui/wf/wf-object-safe.stderr +++ b/src/test/ui/wf/wf-object-safe.stderr @@ -1,11 +1,15 @@ error[E0038]: the trait `A` cannot be made into an object --> $DIR/wf-object-safe.rs:9:13 | +LL | trait A { + | - this trait cannot be made into an object... LL | fn foo(&self, _x: &Self); - | --- method `foo` references the `Self` type in its parameters or return type + | ----- ...because method `foo` references the `Self` type in this parameter ... LL | let _x: &dyn A; | ^^^^^^ the trait `A` cannot be made into an object + | + = help: consider moving `foo` to another trait error: aborting due to previous error diff --git a/src/test/ui/wf/wf-struct-bound.rs b/src/test/ui/wf/wf-struct-bound.rs index 69be71cd130b0..6e558ca8ff0b0 100644 --- a/src/test/ui/wf/wf-struct-bound.rs +++ b/src/test/ui/wf/wf-struct-bound.rs @@ -6,8 +6,8 @@ trait ExtraCopy { } -struct SomeStruct //~ ERROR E0277 - where T: ExtraCopy +struct SomeStruct + where T: ExtraCopy //~ ERROR E0277 { data: (T,U) } diff --git a/src/test/ui/wf/wf-struct-bound.stderr b/src/test/ui/wf/wf-struct-bound.stderr index 2155977349256..3f4047d9b5609 100644 --- a/src/test/ui/wf/wf-struct-bound.stderr +++ b/src/test/ui/wf/wf-struct-bound.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-struct-bound.rs:9:1 + --> $DIR/wf-struct-bound.rs:10:14 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` -LL | -LL | / struct SomeStruct -LL | | where T: ExtraCopy - | | - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` -LL | | { -LL | | data: (T,U) -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` +... +LL | where T: ExtraCopy + | ^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-associated-type-bound.rs b/src/test/ui/wf/wf-trait-associated-type-bound.rs index 29e305577acbc..2f20e65e5021a 100644 --- a/src/test/ui/wf/wf-trait-associated-type-bound.rs +++ b/src/test/ui/wf/wf-trait-associated-type-bound.rs @@ -6,8 +6,8 @@ trait ExtraCopy { } -trait SomeTrait { //~ ERROR E0277 - type Type1: ExtraCopy; +trait SomeTrait { + type Type1: ExtraCopy; //~ ERROR E0277 } diff --git a/src/test/ui/wf/wf-trait-associated-type-bound.stderr b/src/test/ui/wf/wf-trait-associated-type-bound.stderr index af0433fd22f6e..3370cfc86939d 100644 --- a/src/test/ui/wf/wf-trait-associated-type-bound.stderr +++ b/src/test/ui/wf/wf-trait-associated-type-bound.stderr @@ -1,16 +1,13 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied - --> $DIR/wf-trait-associated-type-bound.rs:9:1 + --> $DIR/wf-trait-associated-type-bound.rs:10:17 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` LL | -LL | trait SomeTrait { - | ^ - help: consider restricting this bound: `T: std::marker::Copy` - | _| - | | -LL | | type Type1: ExtraCopy; -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `T` +LL | trait SomeTrait { + | - help: consider restricting this bound: `T: std::marker::Copy` +LL | type Type1: ExtraCopy; + | ^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-bound.rs b/src/test/ui/wf/wf-trait-bound.rs index d8746ba4d6e52..62a1eb5b08864 100644 --- a/src/test/ui/wf/wf-trait-bound.rs +++ b/src/test/ui/wf/wf-trait-bound.rs @@ -6,8 +6,8 @@ trait ExtraCopy { } -trait SomeTrait //~ ERROR E0277 - where T: ExtraCopy +trait SomeTrait + where T: ExtraCopy //~ ERROR E0277 { } diff --git a/src/test/ui/wf/wf-trait-bound.stderr b/src/test/ui/wf/wf-trait-bound.stderr index 13e2f8f590149..87c33714ff879 100644 --- a/src/test/ui/wf/wf-trait-bound.stderr +++ b/src/test/ui/wf/wf-trait-bound.stderr @@ -1,15 +1,13 @@ error[E0277]: the trait bound `U: std::marker::Copy` is not satisfied - --> $DIR/wf-trait-bound.rs:9:1 + --> $DIR/wf-trait-bound.rs:10:14 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` -LL | -LL | / trait SomeTrait -LL | | where T: ExtraCopy - | | - help: consider further restricting type parameter `U`: `, U: std::marker::Copy` -LL | | { -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `U` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` +... +LL | where T: ExtraCopy + | ^^^^^^^^^^^^- help: consider further restricting type parameter `U`: `, U: std::marker::Copy` + | | + | the trait `std::marker::Copy` is not implemented for `U` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-default-fn-arg.stderr b/src/test/ui/wf/wf-trait-default-fn-arg.stderr index 9f3545b9c6a6b..6a97d31cf3e65 100644 --- a/src/test/ui/wf/wf-trait-default-fn-arg.stderr +++ b/src/test/ui/wf/wf-trait-default-fn-arg.stderr @@ -1,18 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-default-fn-arg.rs:11:5 + --> $DIR/wf-trait-default-fn-arg.rs:11:22 | -LL | struct Bar { value: Box } - | ----------------------- required by `Bar` +LL | struct Bar { value: Box } + | ----------------------- required by `Bar` ... -LL | fn bar(&self, x: &Bar) { - | ^ - help: consider further restricting `Self`: `where Self: std::cmp::Eq` - | _____| - | | -LL | | -LL | | // -LL | | // Here, Eq ought to be implemented. -LL | | } - | |_____^ the trait `std::cmp::Eq` is not implemented for `Self` +LL | fn bar(&self, x: &Bar) { + | ^^^^^^^^^^ - help: consider further restricting `Self`: `where Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-default-fn-ret.stderr b/src/test/ui/wf/wf-trait-default-fn-ret.stderr index e32630a5a4a40..36c1e486269f6 100644 --- a/src/test/ui/wf/wf-trait-default-fn-ret.stderr +++ b/src/test/ui/wf/wf-trait-default-fn-ret.stderr @@ -1,19 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-default-fn-ret.rs:11:5 + --> $DIR/wf-trait-default-fn-ret.rs:11:22 | -LL | struct Bar { value: Box } - | ----------------------- required by `Bar` +LL | struct Bar { value: Box } + | ----------------------- required by `Bar` ... -LL | fn bar(&self) -> Bar { - | ^ - help: consider further restricting `Self`: `where Self: std::cmp::Eq` - | _____| - | | -LL | | -LL | | // -LL | | // Here, Eq ought to be implemented. -LL | | loop { } -LL | | } - | |_____^ the trait `std::cmp::Eq` is not implemented for `Self` +LL | fn bar(&self) -> Bar { + | ^^^^^^^^^- help: consider further restricting `Self`: `where Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-default-fn-where-clause.stderr b/src/test/ui/wf/wf-trait-default-fn-where-clause.stderr index a443ff1bb6396..6b63feaba89a3 100644 --- a/src/test/ui/wf/wf-trait-default-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-trait-default-fn-where-clause.stderr @@ -1,18 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-default-fn-where-clause.rs:11:5 + --> $DIR/wf-trait-default-fn-where-clause.rs:11:31 | -LL | trait Bar { } - | ---------------------- required by `Bar` +LL | trait Bar { } + | ---------------------- required by `Bar` ... -LL | fn bar(&self) where A: Bar { - | ^ - help: consider further restricting `Self`: `, Self: std::cmp::Eq` - | _____| - | | -LL | | -LL | | // -LL | | // Here, Eq ought to be implemented. -LL | | } - | |_____^ the trait `std::cmp::Eq` is not implemented for `Self` +LL | fn bar(&self) where A: Bar { + | ^^^^^^^^^- help: consider further restricting `Self`: `, Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-fn-arg.stderr b/src/test/ui/wf/wf-trait-fn-arg.stderr index 42a28ee676373..69e2ab72912d4 100644 --- a/src/test/ui/wf/wf-trait-fn-arg.stderr +++ b/src/test/ui/wf/wf-trait-fn-arg.stderr @@ -1,14 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-fn-arg.rs:10:5 + --> $DIR/wf-trait-fn-arg.rs:10:22 | LL | struct Bar { value: Box } | ----------------------- required by `Bar` ... LL | fn bar(&self, x: &Bar); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | | - | | help: consider further restricting `Self`: `where Self: std::cmp::Eq` - | the trait `std::cmp::Eq` is not implemented for `Self` + | ^^^^^^^^^^ - help: consider further restricting `Self`: `where Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-fn-ret.stderr b/src/test/ui/wf/wf-trait-fn-ret.stderr index 7ec4dbe0056b4..bfc6265662e48 100644 --- a/src/test/ui/wf/wf-trait-fn-ret.stderr +++ b/src/test/ui/wf/wf-trait-fn-ret.stderr @@ -1,14 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-fn-ret.rs:10:5 + --> $DIR/wf-trait-fn-ret.rs:10:22 | LL | struct Bar { value: Box } | ----------------------- required by `Bar` ... LL | fn bar(&self) -> &Bar; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | | - | | help: consider further restricting `Self`: `where Self: std::cmp::Eq` - | the trait `std::cmp::Eq` is not implemented for `Self` + | ^^^^^^^^^^- help: consider further restricting `Self`: `where Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-fn-where-clause.stderr b/src/test/ui/wf/wf-trait-fn-where-clause.stderr index 256edb5b2ca1d..ec8f02c9c4fed 100644 --- a/src/test/ui/wf/wf-trait-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-trait-fn-where-clause.stderr @@ -1,14 +1,13 @@ error[E0277]: the trait bound `Self: std::cmp::Eq` is not satisfied - --> $DIR/wf-trait-fn-where-clause.rs:10:5 + --> $DIR/wf-trait-fn-where-clause.rs:10:49 | LL | struct Bar { value: Box } | ----------------------- required by `Bar` ... LL | fn bar(&self) where Self: Sized, Bar: Copy; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | | - | | help: consider further restricting `Self`: `, Self: std::cmp::Eq` - | the trait `std::cmp::Eq` is not implemented for `Self` + | ^^^^- help: consider further restricting `Self`: `, Self: std::cmp::Eq` + | | + | the trait `std::cmp::Eq` is not implemented for `Self` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-trait-superbound.stderr b/src/test/ui/wf/wf-trait-superbound.stderr index a61b8dd3a3849..9ea9d046b2602 100644 --- a/src/test/ui/wf/wf-trait-superbound.stderr +++ b/src/test/ui/wf/wf-trait-superbound.stderr @@ -1,15 +1,13 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied - --> $DIR/wf-trait-superbound.rs:9:1 + --> $DIR/wf-trait-superbound.rs:9:21 | -LL | trait ExtraCopy { } - | ----------------------- required by `ExtraCopy` +LL | trait ExtraCopy { } + | ----------------------- required by `ExtraCopy` LL | -LL | trait SomeTrait: ExtraCopy { - | ^ - help: consider restricting this bound: `T: std::marker::Copy` - | _| - | | -LL | | } - | |_^ the trait `std::marker::Copy` is not implemented for `T` +LL | trait SomeTrait: ExtraCopy { + | - ^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` + | | + | help: consider restricting this bound: `T: std::marker::Copy` error: aborting due to previous error diff --git a/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr index 594fad4138505..9319e3382c2d4 100644 --- a/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr @@ -15,20 +15,28 @@ LL | | } error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-unsafe-trait-obj-match.rs:26:21 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | Some(()) => &S, | ^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Trait>` for `&S` = note: required by cast to type `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-unsafe-trait-obj-match.rs:25:25 | +LL | trait Trait: Sized {} + | ----- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... +... LL | let t: &dyn Trait = match opt() { | ^^^^^^^^^^^ the trait `Trait` cannot be made into an object | - = note: the trait cannot require that `Self : Sized` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Trait>` for `&R` = note: required by cast to type `&dyn Trait`