diff --git a/src/librustc/traits/error_reporting/mod.rs b/src/librustc/traits/error_reporting/mod.rs index f15fa779534e..f2cc8a303a95 100644 --- a/src/librustc/traits/error_reporting/mod.rs +++ b/src/librustc/traits/error_reporting/mod.rs @@ -1034,6 +1034,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,6 +1049,7 @@ 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() { @@ -1055,15 +1060,28 @@ pub fn report_object_safety_error( } if reported_violations.insert(violation.clone()) { 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(&violation.error_msg()); + err.note(&msg); } else { for span in spans { - err.span_label(span, violation.error_msg()); + err.span_label(span, &msg); } } + if let (Some(_), Some(note)) = (trait_span, violation.solution()) { + // Only provide the help if its a local trait, otherwise it's not actionable. + err.help(¬e); + } } } + 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) diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index dec9ef4f4216..ac9e4950b72c 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -43,12 +43,9 @@ pub enum ObjectSafetyViolation { impl ObjectSafetyViolation { pub fn error_msg(&self) -> Cow<'static, str> { match *self { - ObjectSafetyViolation::SizedSelf(_) => { - "traits that require `Self: Sized` cannot be made into an object".into() - } + ObjectSafetyViolation::SizedSelf(_) => "it requires `Self: Sized`".into(), ObjectSafetyViolation::SupertraitSelf => { - "the trait cannot use `Self` as a type parameter \ - in the supertraits or where-clauses" + "it cannot use `Self` as a type parameter in the supertraits or `where`-clauses" .into() } ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => { @@ -63,19 +60,45 @@ impl ObjectSafetyViolation { 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(_, DUMMY_SP) => { + "it cannot contain associated consts".into() + } ObjectSafetyViolation::AssocConst(name, _) => { - format!("the trait cannot contain associated consts like `{}`", name).into() + format!("it cannot contain associated consts like `{}`", name).into() } } } + pub fn solution(&self) -> Option { + Some(match *self { + ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf => { + return None; + } + ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => format!( + "consider turning `{}` into a method by giving it a `&self` argument or \ + constraining it with `where Self: Sized`", + name + ), + ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => { + format!("consider changing method `{}`'s `self` parameter to be `&self`", name) + .into() + } + ObjectSafetyViolation::AssocConst(name, _) + | ObjectSafetyViolation::Method(name, ..) => { + format!("consider moving `{}` to another trait", name) + } + }) + } + 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`. @@ -190,7 +213,21 @@ fn object_safety_violations_for_trait( tcx.def_path_str(trait_def_id) ), ); - err.span_label(*span, violation.error_msg()); + 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); + if let (Some(_), Some(note)) = (node, violation.solution()) { + // Only provide the help if its a local trait, otherwise it's not actionable. + err.help(¬e); + } err.emit(); false } else { 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 a5d7fc5b7024..b9101c86d218 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 cannot contain associated consts like `N` ... 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 ddabd552897a..e8442c6c9ac1 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 cannot contain associated consts like `X` ... 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/coherence/coherence-impl-trait-for-trait-object-safe.stderr b/src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr index ed6be60de460..c999cabcc141 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 its parameters or return type + | | + | 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/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 070917f2db98..333754891c16 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: traits that require `Self: Sized` cannot be made into an object + = 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/error-codes/E0033-teach.stderr b/src/test/ui/error-codes/E0033-teach.stderr index 80f3d4441bd9..050ea63aa4fa 100644 --- a/src/test/ui/error-codes/E0033-teach.stderr +++ b/src/test/ui/error-codes/E0033-teach.stderr @@ -7,11 +7,15 @@ 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 with `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 c2843796cc85..c736fbcf92a8 100644 --- a/src/test/ui/error-codes/E0033.stderr +++ b/src/test/ui/error-codes/E0033.stderr @@ -7,11 +7,15 @@ 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 with `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 6eaf6e4a8aad..62b6f4cf2469 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: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 parameters or return type ... LL | fn call_foo(x: Box) { | ^^^^^^^^^^^^^^ 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/feature-gates/feature-gate-object_safe_for_dispatch.stderr b/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr index ce9830694051..290598806689 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 @@ -2,7 +2,9 @@ error[E0038]: the trait `NonObjectSafe1` cannot be made into an object --> $DIR/feature-gate-object_safe_for_dispatch.rs:18:38 | LL | trait NonObjectSafe1: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | -------------- ----- ...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 @@ -10,35 +12,49 @@ LL | fn takes_non_object_safe_ref(obj: &dyn NonObjectSafe1) { error[E0038]: the trait `NonObjectSafe2` cannot be made into an object --> $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 + | + = help: consider turning `static_fn` into a method by giving it a `&self` argument or constraining it with `where Self: Sized` error[E0038]: the trait `NonObjectSafe3` cannot be made into an object --> $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 + | + = 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: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 its parameters or return type ... LL | fn return_non_object_safe_rc() -> std::rc::Rc { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 {} - | ----- traits that require `Self: Sized` cannot be made into an object + | -------------- ----- ...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 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 ff4bfc30a4a6..1443be0b30eb 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,28 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object --> $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 + | + = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `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: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 + | + = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-18959.stderr b/src/test/ui/issues/issue-18959.stderr index 0c59486b416b..b3ba7aecad0d 100644 --- a/src/test/ui/issues/issue-18959.stderr +++ b/src/test/ui/issues/issue-18959.stderr @@ -2,10 +2,14 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $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 + | + = 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 92bfdf1f26e9..22e744f88417 100644 --- a/src/test/ui/issues/issue-19380.stderr +++ b/src/test/ui/issues/issue-19380.stderr @@ -1,11 +1,15 @@ 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 with `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 83c03b514ddc..b6033e47b1a4 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-20692.stderr b/src/test/ui/issues/issue-20692.stderr index 552b65b36209..ca2611e0f9eb 100644 --- a/src/test/ui/issues/issue-20692.stderr +++ b/src/test/ui/issues/issue-20692.stderr @@ -2,9 +2,10 @@ error[E0038]: the trait `Array` cannot be made into an object --> $DIR/issue-20692.rs:7:5 | LL | trait Array: Sized + Copy {} - | ----- ---- traits that require `Self: Sized` cannot be made into an object - | | - | traits that require `Self: Sized` cannot be made into an object + | ----- ----- ---- ...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 @@ -13,9 +14,10 @@ error[E0038]: the trait `Array` cannot be made into an object --> $DIR/issue-20692.rs:4:13 | LL | trait Array: Sized + Copy {} - | ----- ---- traits that require `Self: Sized` cannot be made into an object - | | - | traits that require `Self: Sized` cannot be made into an object + | ----- ----- ---- ...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 diff --git a/src/test/ui/issues/issue-26056.stderr b/src/test/ui/issues/issue-26056.stderr index 9c4cf0b18acf..2744fb91d6fe 100644 --- a/src/test/ui/issues/issue-26056.stderr +++ b/src/test/ui/issues/issue-26056.stderr @@ -4,7 +4,7 @@ error[E0038]: the trait `Map` 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 + = note: the trait cannot be made into an object because it 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-28576.stderr b/src/test/ui/issues/issue-28576.stderr index 3249d76e69b5..5bed9a77d189 100644 --- a/src/test/ui/issues/issue-28576.stderr +++ b/src/test/ui/issues/issue-28576.stderr @@ -5,7 +5,7 @@ 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 + = note: the trait cannot be made into an object because it 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-38404.stderr b/src/test/ui/issues/issue-38404.stderr index d18a26b3a763..613888758cab 100644 --- a/src/test/ui/issues/issue-38404.stderr +++ b/src/test/ui/issues/issue-38404.stderr @@ -4,7 +4,7 @@ error[E0038]: the trait `B` 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 + = note: the trait cannot be made into an object because it 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 8b923a2c6b23..b3ad71e174a9 100644 --- a/src/test/ui/issues/issue-38604.stderr +++ b/src/test/ui/issues/issue-38604.stderr @@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` 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 + = note: the trait cannot be made into an object because it 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 @@ -12,7 +12,7 @@ error[E0038]: the trait `Foo` 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: the trait cannot be made into an object because it 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 c161e9efd126..03e3a7f227a2 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; - | ^^^ method `foo` references the `Self` type in where clauses + | ^^^ ...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,6 +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 + = 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 728a5ea6faa9..2a9fd13be5f0 100644 --- a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr +++ b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr @@ -13,7 +13,9 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:19 | LL | trait Foo : Copy { - | ---- traits that require `Self: Sized` cannot be made into an object + | --- ---- ...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 @@ -22,7 +24,9 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:13 | LL | trait Foo : Copy { - | ---- traits that require `Self: Sized` cannot be made into an object + | --- ---- ...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 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 b4fba9706bc0..6227ada4dc93 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 @@ -13,7 +13,9 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/kindck-inherited-copy-bound.rs:28:13 | LL | trait Foo : Copy { - | ---- traits that require `Self: Sized` cannot be made into an object + | --- ---- ...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 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 b67b0e4f40e8..e0e0344af759 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: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 cannot contain associated consts like `X` ... LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^^ 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 20993a680ba4..ff0bd17dccce 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 cannot contain associated consts like `X` ... 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 2469467f084a..9e70abbd32fc 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: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 + | + = help: consider moving `bar` to another trait error[E0038]: the trait `Bar` cannot be made into an object --> $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 + | + = 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 d3d8d3688883..7443d38470c0 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 1f5c472ddc25..55baf69401b0 100644 --- a/src/test/ui/object-safety/object-safety-issue-22040.stderr +++ b/src/test/ui/object-safety/object-safety-issue-22040.stderr @@ -4,7 +4,7 @@ error[E0038]: the trait `Expr` 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 + = note: the trait cannot be made into an object because it 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 2123e306b16a..e90f9b6d0a0c 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: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 its parameters or return type ... LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^^ 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: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 parameters or return type ... LL | fn make_baz(t: &T) -> &dyn Baz { | ^^^^^^^^ 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 03b2b8da0753..4a23fb56e91a 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 its parameters or return type ... 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 parameters or 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 099876c562ae..2f79d53d1c12 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,15 @@ error[E0038]: the trait `Foo` cannot be made into an object --> $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 + | + = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `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 91a9285b63cc..bed6757fc680 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,12 +1,15 @@ 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 | + = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where 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/object-safety/object-safety-sized-2.curr.stderr b/src/test/ui/object-safety/object-safety-sized-2.curr.stderr index 49f98e008508..2f605d8e904c 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,8 +1,10 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-sized-2.rs:14:30 | +LL | trait Bar + | --- this trait cannot be made into an object... LL | where Self : Sized - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ...because it requires `Self: Sized` ... LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^^ the trait `Bar` cannot be made into an object 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 9b189c48f930..2f1f06f4cf5f 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,8 +1,10 @@ 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 - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ...because it requires `Self: Sized` ... LL | t | ^ the trait `Bar` cannot be made into an object 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 3b588034e332..54f65c43d9cd 100644 --- a/src/test/ui/object-safety/object-safety-sized.curr.stderr +++ b/src/test/ui/object-safety/object-safety-sized.curr.stderr @@ -2,7 +2,9 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-sized.rs:12:30 | LL | trait Bar : Sized { - | ----- traits that require `Self: Sized` cannot be made into an object + | --- ----- ...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 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 6b60eef30d3d..58c2b7721474 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 @@ -2,7 +2,9 @@ error[E0038]: the trait `Bar` cannot be made into an object --> $DIR/object-safety-sized.rs:14:5 | LL | trait Bar : Sized { - | ----- traits that require `Self: Sized` cannot be made into an object + | --- ----- ...because it requires `Self: Sized` + | | + | this trait cannot be made into an object... ... LL | t | ^ the trait `Bar` cannot be made into an object 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 8ae89832703d..04f630d5dacb 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 @@ -4,7 +4,7 @@ error[E0038]: the trait `Baz` 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 + = note: the trait cannot be made into an object because it 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/resolve/issue-3907-2.stderr b/src/test/ui/resolve/issue-3907-2.stderr index 1d6b378b9c8a..d0c278d12d70 100644 --- a/src/test/ui/resolve/issue-3907-2.stderr +++ b/src/test/ui/resolve/issue-3907-2.stderr @@ -4,7 +4,7 @@ error[E0038]: the trait `issue_3907::Foo` cannot be made into an object LL | fn bar(_x: Foo) {} | ^^^ 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 653ccb9db949..c06538fae3b4 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,21 +1,28 @@ 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 ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^ the trait `Foo` cannot be made into an object + | + = help: consider changing method `foo`'s `self` parameter to be `&self` 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 ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object | + = help: consider changing method `foo`'s `self` parameter to be `&self` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::rc::Rc` = note: required by cast to type `std::rc::Rc` 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 33f1fa2e51be..bebd5cbcf780 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,12 +1,15 @@ 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 ... LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object | + = help: consider changing method `foo`'s `self` parameter to be `&self` = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::rc::Rc` = note: required by cast to type `std::rc::Rc` 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 index 4a9242b1f4fa..55185a2c8cdd 100644 --- a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr @@ -15,7 +15,9 @@ 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 { - | ----- traits that require `Self: Sized` cannot be made into an object + | - ----- ...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 @@ -35,10 +37,14 @@ 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 | | - | associated function `f` has no `self` parameter + | ...because associated function `f` has no `self` parameter + | + = help: consider turning `f` into a method by giving it a `&self` argument or constraining it with `where Self: Sized` error: aborting due to 4 previous errors 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 5551b1303b92..1f9ffb6a4cfb 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 @@ -4,7 +4,7 @@ error[E0038]: the trait `std::cmp::Eq` cannot be made into an object LL | let _: &dyn EqAlias = &123; | ^^^^^^^^^^^ the trait `std::cmp::Eq` cannot be made into an object | - = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses + = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses 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 diff --git a/src/test/ui/traits/trait-item-privacy.stderr b/src/test/ui/traits/trait-item-privacy.stderr index 4df8845de279..e050d6940abc 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 cannot contain associated consts like `A` ... LL | const B: u8 = 0; - | - the trait cannot contain associated consts like `B` + | - ...because it cannot contain associated consts like `B` ... +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 cannot contain associated consts like `C` ... 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 f41ebf4166d0..a8511f63c16a 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: traits that require `Self: Sized` cannot be made into an object + = 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 028e9eedd641..5eb8cd0d8063 100644 --- a/src/test/ui/traits/trait-object-safety.stderr +++ b/src/test/ui/traits/trait-object-safety.stderr @@ -1,23 +1,30 @@ 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 | + = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized` = 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` 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 with `where Self: Sized` error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/trait-test-2.stderr b/src/test/ui/traits/trait-test-2.stderr index 9b750d382ec9..5b2b7b51f3da 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 parameters or 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 parameters or 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/type-parameter-defaults-referencing-Self-ppaux.stderr b/src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr index b315fe9df8af..fa6c5a92fb43 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 parameters or 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/wf/wf-convert-unsafe-trait-obj-box.stderr b/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.stderr index 7e055d746f67..eefb450155cd 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 @@ -2,7 +2,9 @@ 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 {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 @@ -14,7 +16,9 @@ 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 {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 @@ -26,7 +30,9 @@ 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 {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 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 9e7fe7f3e1df..5e645382d1b2 100644 --- a/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr +++ b/src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr @@ -2,7 +2,9 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:16:25 | LL | trait Trait: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 @@ -14,7 +16,9 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:17:17 | LL | trait Trait: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 @@ -26,7 +30,9 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-convert-unsafe-trait-obj.rs:15:5 | LL | trait Trait: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index f17391520a32..1c530ece2958 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -25,7 +25,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object LL | fn bar() where Vec:, {} | ^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object | - = note: traits that require `Self: Sized` cannot be made into an object + = 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-object-safe.stderr b/src/test/ui/wf/wf-object-safe.stderr index 0d8441f87e7e..2ff6383bc80e 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 its parameters or return type ... 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-unsafe-trait-obj-match.stderr b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr index 452a2a5e58b7..9319e3382c2d 100644 --- a/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/src/test/ui/wf/wf-unsafe-trait-obj-match.stderr @@ -16,7 +16,9 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-unsafe-trait-obj-match.rs:26:21 | LL | trait Trait: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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 @@ -28,7 +30,9 @@ error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/wf-unsafe-trait-obj-match.rs:25:25 | LL | trait Trait: Sized {} - | ----- traits that require `Self: Sized` cannot be made into an object + | ----- ----- ...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