Note base types of coercion

This commit is contained in:
Michael Goulet 2023-05-11 02:10:56 +00:00
parent 2a8221dbdf
commit 14bf909e71
65 changed files with 142 additions and 225 deletions

View File

@ -281,9 +281,6 @@ pub enum ObligationCauseCode<'tcx> {
/// A type like `Box<Foo<'a> + 'b>` is WF only if `'b: 'a`.
ObjectTypeBound(Ty<'tcx>, ty::Region<'tcx>),
/// Obligation incurred due to an object cast.
ObjectCastObligation(/* Concrete type */ Ty<'tcx>, /* Object type */ Ty<'tcx>),
/// Obligation incurred due to a coercion.
Coercion {
source: Ty<'tcx>,

View File

@ -797,9 +797,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err.span_label(span, explanation);
}
if let ObligationCauseCode::ObjectCastObligation(concrete_ty, obj_ty) = obligation.cause.code().peel_derives() &&
Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
self.suggest_borrowing_for_object_cast(&mut err, &root_obligation, *concrete_ty, *obj_ty);
if let ObligationCauseCode::Coercion { source, target } =
*obligation.cause.code().peel_derives()
{
if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
self.suggest_borrowing_for_object_cast(
&mut err,
&root_obligation,
source,
target,
);
}
}
let UnsatisfiedConst(unsatisfied_const) = self
@ -1510,7 +1518,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::BindingObligation(_, _)
| ObligationCauseCode::ExprItemObligation(..)
| ObligationCauseCode::ExprBindingObligation(..)
| ObligationCauseCode::ObjectCastObligation(..)
| ObligationCauseCode::Coercion { .. }
| ObligationCauseCode::OpaqueType
);

View File

@ -1442,8 +1442,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
self_ty: Ty<'tcx>,
object_ty: Ty<'tcx>,
target_ty: Ty<'tcx>,
) {
let ty::Ref(_, object_ty, hir::Mutability::Not) = target_ty.kind() else { return; };
let ty::Dynamic(predicates, _, ty::Dyn) = object_ty.kind() else { return; };
let self_ref_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, self_ty);
@ -1458,7 +1459,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err.span_suggestion(
obligation.cause.span.shrink_to_lo(),
format!(
"consider borrowing the value, since `&{self_ty}` can be coerced into `{object_ty}`"
"consider borrowing the value, since `&{self_ty}` can be coerced into `{target_ty}`"
),
"&",
Applicability::MaybeIncorrect,
@ -2851,30 +2852,27 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err.span_note(tcx.def_span(item_def_id), descr);
}
}
ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => {
let (concrete_ty, concrete_file) =
self.tcx.short_ty_string(self.resolve_vars_if_possible(concrete_ty));
let (object_ty, object_file) =
self.tcx.short_ty_string(self.resolve_vars_if_possible(object_ty));
ObligationCauseCode::Coercion { source, target } => {
let (source, source_file) =
self.tcx.short_ty_string(self.resolve_vars_if_possible(source));
let (target, target_file) =
self.tcx.short_ty_string(self.resolve_vars_if_possible(target));
err.note(with_forced_trimmed_paths!(format!(
"required for the cast from `{concrete_ty}` to the object type `{object_ty}`",
"required for the cast from `{source}` to `{target}`",
)));
if let Some(file) = concrete_file {
if let Some(file) = source_file {
err.note(format!(
"the full name for the casted type has been written to '{}'",
"the full name for the source type has been written to '{}'",
file.display(),
));
}
if let Some(file) = object_file {
if let Some(file) = target_file {
err.note(format!(
"the full name for the object type has been written to '{}'",
"the full name for the target type has been written to '{}'",
file.display(),
));
}
}
ObligationCauseCode::Coercion { source: _, target } => {
err.note(format!("required by cast to type `{}`", self.ty_to_string(target)));
}
ObligationCauseCode::RepeatElementCopy { is_const_fn } => {
err.note(
"the `Copy` trait is required because this value will be copied for each element of the array",

View File

@ -29,9 +29,9 @@ use crate::traits::{
ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData,
ImplSourceConstDestructData, ImplSourceFnPointerData, ImplSourceFutureData,
ImplSourceGeneratorData, ImplSourceObjectData, ImplSourceTraitAliasData,
ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, ObjectCastObligation,
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, Obligation,
ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
TraitNotObjectSafe, TraitObligation, Unimplemented,
};
use super::BuiltinImplConditions;
@ -905,16 +905,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.map_err(|_| Unimplemented)?;
nested.extend(obligations);
// Register one obligation for 'a: 'b.
let cause = ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
ObjectCastObligation(source, target),
);
let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth(
tcx,
cause,
obligation.cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
obligation.predicate.rebind(outlives),
@ -1005,15 +999,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
nested.extend(obligations);
// Register one obligation for 'a: 'b.
let cause = ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
ObjectCastObligation(source, target),
);
let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth(
tcx,
cause,
obligation.cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
obligation.predicate.rebind(outlives),
@ -1027,16 +1016,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return Err(TraitNotObjectSafe(did));
}
let cause = ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
ObjectCastObligation(source, target),
);
let predicate_to_obligation = |predicate| {
Obligation::with_depth(
tcx,
cause.clone(),
obligation.cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
predicate,
@ -1056,7 +1039,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);
// We can only make objects from sized types.
let tr = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, cause.span, [source]);
let tr = ty::TraitRef::from_lang_item(
tcx,
LangItem::Sized,
obligation.cause.span,
[source],
);
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
// If the type is `Foo + 'a`, ensure that the type

View File

@ -2647,14 +2647,19 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
let predicates = predicates.instantiate_own(tcx, substs);
let mut obligations = Vec::with_capacity(predicates.len());
for (index, (predicate, span)) in predicates.into_iter().enumerate() {
let cause = cause.clone().derived_cause(parent_trait_pred, |derived| {
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
derived,
impl_or_alias_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
});
let cause =
if Some(parent_trait_pred.def_id()) == tcx.lang_items().coerce_unsized_trait() {
cause.clone()
} else {
cause.clone().derived_cause(parent_trait_pred, |derived| {
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
derived,
impl_or_alias_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
})
};
let predicate = normalize_with_depth_to(
self,
param_env,

View File

@ -43,7 +43,7 @@ note: expected this to be `Bar`
|
LL | type A = usize;
| ^^^^^
= note: required for the cast from `isize` to the object type `dyn Foo<A = Bar>`
= note: required for the cast from `&isize` to `&dyn Foo<A = Bar>`
error: aborting due to 3 previous errors

View File

@ -4,7 +4,7 @@ error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `i32`, but
LL | let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();
| ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
|
= note: required for the cast from `std::vec::IntoIter<u32>` to the object type `dyn Iterator<Item = u32, Item = i32>`
= note: required for the cast from `&std::vec::IntoIter<u32>` to `&dyn Iterator<Item = u32, Item = i32>`
error: aborting due to previous error

View File

@ -25,7 +25,7 @@ LL | impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }
| --------- ^^^^^^^^^ ^^^^^^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `&mut T` to the object type `dyn MyDisplay`
= note: required for the cast from `&&mut T` to `&dyn MyDisplay`
error: aborting due to 2 previous errors

View File

@ -18,7 +18,7 @@ LL | writer.my_write(valref)
| ^^^^^^ the trait `MyDisplay` is not implemented for `T`
|
= help: the trait `MyDisplay` is implemented for `&'a mut T`
= note: required for the cast from `T` to the object type `dyn MyDisplay`
= note: required for the cast from `&mut T` to `&dyn MyDisplay`
error: aborting due to 2 previous errors

View File

@ -35,7 +35,7 @@ error[E0271]: expected `[async block@$DIR/async-block-control-flow-static-semant
LL | let _: &dyn Future<Output = ()> = &block;
| ^^^^^^ expected `()`, found `u8`
|
= note: required for the cast from `[async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 25:6]` to the object type `dyn Future<Output = ()>`
= note: required for the cast from `&[async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 25:6]` to `&dyn Future<Output = ()>`
error[E0308]: mismatched types
--> $DIR/async-block-control-flow-static-semantics.rs:12:43
@ -51,7 +51,7 @@ error[E0271]: expected `[async block@$DIR/async-block-control-flow-static-semant
LL | let _: &dyn Future<Output = ()> = &block;
| ^^^^^^ expected `()`, found `u8`
|
= note: required for the cast from `[async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 16:6]` to the object type `dyn Future<Output = ()>`
= note: required for the cast from `&[async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 16:6]` to `&dyn Future<Output = ()>`
error[E0308]: mismatched types
--> $DIR/async-block-control-flow-static-semantics.rs:49:44

View File

@ -13,7 +13,7 @@ note: captured value is not `Send` because `&` references cannot be sent unless
|
LL | let x = x;
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
= note: required for the cast from `[async block@$DIR/issue-86507.rs:21:17: 23:18]` to the object type `dyn Future<Output = ()> + Send`
= note: required for the cast from `Pin<Box<[async block@$DIR/issue-86507.rs:21:17: 23:18]>>` to `Pin<Box<(dyn Future<Output = ()> + Send + 'async_trait)>>`
help: consider further restricting this bound
|
LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T)

View File

@ -13,7 +13,7 @@ note: captured value is not `Send` because `&` references cannot be sent unless
|
LL | let x = x;
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
= note: required for the cast from `[async block@$DIR/issue-86507.rs:21:17: 23:18]` to the object type `dyn Future<Output = ()> + Send`
= note: required for the cast from `Pin<Box<[async block@$DIR/issue-86507.rs:21:17: 23:18]>>` to `Pin<Box<(dyn Future<Output = ()> + Send + 'async_trait)>>`
help: consider further restricting this bound
|
LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T)

View File

@ -13,7 +13,7 @@ note: captured value is not `Send` because `&` references cannot be sent unless
|
LL | let x = x;
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
= note: required for the cast from `[async block@$DIR/issue-86507.rs:21:17: 23:18]` to the object type `dyn Future<Output = ()> + Send`
= note: required for the cast from `Pin<Box<[async block@$DIR/issue-86507.rs:21:17: 23:18]>>` to `Pin<Box<(dyn Future<Output = ()> + Send + 'async_trait)>>`
help: consider further restricting this bound
|
LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T)

View File

@ -9,7 +9,7 @@ LL | num += 1;
LL | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
|
= note: required for the cast from `[closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21]` to the object type `dyn Fn()`
= note: required for the cast from `Box<[closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21]>` to `Box<(dyn Fn() + 'static)>`
error: aborting due to previous error

View File

@ -9,7 +9,7 @@ LL | vec
LL | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
|
= note: required for the cast from `[closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26]` to the object type `dyn Fn() -> Vec<u8>`
= note: required for the cast from `Box<[closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26]>` to `Box<(dyn Fn() -> Vec<u8> + 'static)>`
error: aborting due to previous error

View File

@ -4,7 +4,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `()` to the object type `dyn std::error::Error`
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never-windows.rs:23:49
@ -12,7 +12,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `()` to the object type `(dyn std::error::Error + 'static)`
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`
error: aborting due to 2 previous errors

View File

@ -4,7 +4,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `()` to the object type `dyn std::error::Error`
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never.rs:23:49
@ -12,7 +12,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `()` to the object type `(dyn std::error::Error + 'static)`
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`
error: aborting due to 2 previous errors

View File

@ -5,7 +5,7 @@ LL | foo(&10_u32);
| ^^^^^^^ the trait `Trait` is not implemented for `u32`
|
= help: the trait `Trait<2>` is implemented for `u32`
= note: required for the cast from `u32` to the object type `dyn Trait`
= note: required for the cast from `&u32` to `&dyn Trait`
error[E0277]: the trait bound `bool: Traitor<_>` is not satisfied
--> $DIR/trait_objects_fail.rs:28:9
@ -14,7 +14,7 @@ LL | bar(&true);
| ^^^^^ the trait `Traitor<_>` is not implemented for `bool`
|
= help: the trait `Traitor<2, 3>` is implemented for `bool`
= note: required for the cast from `bool` to the object type `dyn Traitor<_>`
= note: required for the cast from `&bool` to `&dyn Traitor<_>`
error: aborting due to 2 previous errors

View File

@ -6,7 +6,7 @@ LL | #[test]
LL | fn wrong_kind(){}
| ^^^^^^^^^^^^^^^^^ the trait `Testable` is not implemented for `TestDescAndFn`
|
= note: required for the cast from `TestDescAndFn` to the object type `dyn Testable`
= note: required for the cast from `&TestDescAndFn` to `&dyn Testable`
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error

View File

@ -15,8 +15,8 @@ note: expected this to be `Foo`
|
LL | type Error = E;
| ^
= note: required for the cast from `Result<Result<..., ...>, ...>` to the object type `dyn Future<Error = Foo>`
= note: the full name for the casted type has been written to '$TEST_BUILD_DIR/diagnostic-width/E0271/E0271.long-type-hash.txt'
= note: required for the cast from `Box<Result<..., ...>>` to `Box<(dyn Future<Error = Foo> + 'static)>`
= note: the full name for the source type has been written to '$TEST_BUILD_DIR/diagnostic-width/E0271/E0271.long-type-hash.txt'
error: aborting due to previous error

View File

@ -15,7 +15,7 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied
LL | let f3: &Fat<dyn Bar> = f2;
| ^^ the trait `Bar` is not implemented for `Foo`
|
= note: required for the cast from `Foo` to the object type `dyn Bar`
= note: required for the cast from `&Fat<Foo>` to `&Fat<dyn Bar>`
error[E0308]: mismatched types
--> $DIR/dst-bad-coerce1.rs:28:27
@ -34,7 +34,7 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied
LL | let f3: &(dyn Bar,) = f2;
| ^^ the trait `Bar` is not implemented for `Foo`
|
= note: required for the cast from `Foo` to the object type `dyn Bar`
= note: required for the cast from `&(Foo,)` to `&(dyn Bar,)`
error: aborting due to 4 previous errors

View File

@ -6,7 +6,7 @@ LL | fn test1<T: ?Sized + Foo>(t: &T) {
LL | let u: &dyn Foo = t;
| ^ doesn't have a size known at compile-time
|
= note: required for the cast from `T` to the object type `dyn Foo`
= note: required for the cast from `&T` to `&dyn Foo`
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
LL - fn test1<T: ?Sized + Foo>(t: &T) {
@ -21,7 +21,7 @@ LL | fn test2<T: ?Sized + Foo>(t: &T) {
LL | let v: &dyn Foo = t as &dyn Foo;
| ^ doesn't have a size known at compile-time
|
= note: required for the cast from `T` to the object type `dyn Foo`
= note: required for the cast from `&T` to `&dyn Foo`
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
LL - fn test2<T: ?Sized + Foo>(t: &T) {
@ -35,7 +35,7 @@ LL | let _: &[&dyn Foo] = &["hi"];
| ^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn Foo`
= note: required for the cast from `&'static str` to `&dyn Foo`
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/dst-object-from-unsized-type.rs:23:23
@ -44,7 +44,7 @@ LL | let _: &dyn Foo = x as &dyn Foo;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: required for the cast from `[u8]` to the object type `dyn Foo`
= note: required for the cast from `&[u8]` to `&dyn Foo`
error: aborting due to 4 previous errors

View File

@ -31,14 +31,7 @@ LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | fn ptr(self: Ptr<Self>);
| ^^^^^^^^^ ...because method `ptr`'s `self` parameter cannot be dispatched on
note: required for `Ptr<{integer}>` to implement `CoerceUnsized<Ptr<dyn Trait>>`
--> $DIR/feature-gate-dispatch-from-dyn-missing-impl.rs:20:40
|
LL | impl<T: Unsize<U> + ?Sized, U: ?Sized> CoerceUnsized<Ptr<U>> for Ptr<T> {}
| --------- ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
| |
| unsatisfied trait bound introduced here
= note: required by cast to type `Ptr<dyn Trait>`
= note: required for the cast from `Ptr<{integer}>` to `Ptr<dyn Trait>`
error: aborting due to 2 previous errors

View File

@ -43,8 +43,7 @@ LL | pub trait SuperTrait {
LL | type SubType<'a>: SubTrait where Self: 'a;
| ^^^^^^^ ...because it contains the generic associated type `SubType`
= help: consider moving `SubType` to another trait
= note: required for `Box<SuperStruct>` to implement `CoerceUnsized<Box<dyn SuperTrait<SubType = SubStruct<'_>>>>`
= note: required by cast to type `Box<dyn SuperTrait<SubType = SubStruct<'_>>>`
= note: required for the cast from `Box<SuperStruct>` to `Box<dyn SuperTrait<SubType = SubStruct<'_>>>`
error: aborting due to 3 previous errors

View File

@ -43,8 +43,7 @@ LL | trait MapLike<K, V> {
LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
| ^^^^^^^^ ...because it contains the generic associated type `VRefCont`
= help: consider moving `VRefCont` to another trait
= note: required for `Box<BTreeMap<u8, u8>>` to implement `CoerceUnsized<Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>>`
= note: required by cast to type `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`
= note: required for the cast from `Box<BTreeMap<u8, u8>>` to `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`
error: aborting due to 3 previous errors

View File

@ -27,7 +27,7 @@ LL | type VRefCont<'a> = &'a V where Self: 'a;
| ^^^^^
= note: expected trait object `(dyn RefCont<'_, u8> + 'static)`
found reference `&u8`
= note: required for the cast from `BTreeMap<u8, u8>` to the object type `dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>`
= note: required for the cast from `Box<BTreeMap<u8, u8>>` to `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`
error: aborting due to 2 previous errors

View File

@ -42,8 +42,7 @@ LL | trait Foo {
LL | fn baz(&self) -> impl Debug;
| ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type
= help: consider moving `baz` to another trait
= note: required for `Box<u32>` to implement `CoerceUnsized<Box<dyn Foo>>`
= note: required by cast to type `Box<dyn Foo>`
= note: required for the cast from `Box<u32>` to `Box<dyn Foo>`
error: aborting due to 3 previous errors

View File

@ -42,8 +42,7 @@ LL | trait Foo {
LL | fn baz(&self) -> impl Debug;
| ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type
= help: consider moving `baz` to another trait
= note: required for `Box<u32>` to implement `CoerceUnsized<Box<dyn Foo>>`
= note: required by cast to type `Box<dyn Foo>`
= note: required for the cast from `Box<u32>` to `Box<dyn Foo>`
error: aborting due to 3 previous errors

View File

@ -5,8 +5,8 @@ LL | let _x = "test" as &dyn (::std::any::Any);
| ^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn Any`
help: consider borrowing the value, since `&str` can be coerced into `dyn Any`
= note: required for the cast from `&'static str` to `&(dyn Any + 'static)`
help: consider borrowing the value, since `&&'static str` can be coerced into `&(dyn Any + 'static)`
|
LL | let _x = &"test" as &dyn (::std::any::Any);
| +

View File

@ -6,7 +6,7 @@ LL | &mut *(ptr as *mut dyn Fn())
|
= help: the trait `Fn<()>` is not implemented for `()`
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
= note: required for the cast from `()` to the object type `dyn Fn()`
= note: required for the cast from `*mut ()` to `*mut dyn Fn()`
error: aborting due to previous error

View File

@ -13,7 +13,7 @@ LL | impl<'b, P> Wrap<'b> for Wrapper<P>
LL | where P: Process<'b>,
LL | <P as Process<'b>>::Item: Iterator {
| -------- unsatisfied trait bound introduced here
= note: required for the cast from `Wrapper<P>` to the object type `dyn for<'b> Wrap<'b>`
= note: required for the cast from `Box<Wrapper<P>>` to `Box<dyn for<'b> Wrap<'b>>`
help: consider further restricting the associated type
|
LL | fn push_process<P>(process: P) where P: Process<'static>, <P as Process<'_>>::Item: Iterator {

View File

@ -11,7 +11,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
= note: required for the cast from `&S<T>` to `&dyn Gettable<T>`
help: consider restricting type parameter `T`
|
LL | fn f<T: std::marker::Send>(val: T) {
@ -30,7 +30,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
= note: required for the cast from `&S<T>` to `&dyn Gettable<T>`
help: consider restricting type parameter `T`
|
LL | fn f<T: std::marker::Copy>(val: T) {
@ -49,7 +49,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
= note: required for the cast from `&S<T>` to `&dyn Gettable<T>`
help: consider restricting type parameter `T`
|
LL | fn g<T: std::marker::Send>(val: T) {
@ -68,7 +68,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
= note: required for the cast from `&S<T>` to `&dyn Gettable<T>`
help: consider restricting type parameter `T`
|
LL | fn g<T: std::marker::Copy>(val: T) {
@ -88,7 +88,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<String>` to the object type `dyn Gettable<String>`
= note: required for the cast from `Box<S<String>>` to `Box<dyn Gettable<String>>`
error[E0277]: the trait bound `Foo: Copy` is not satisfied
--> $DIR/kindck-impl-type-params.rs:43:37
@ -104,7 +104,7 @@ LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
| ---- ^^^^^^^^^^^ ^^^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `S<Foo>` to the object type `dyn Gettable<Foo>`
= note: required for the cast from `Box<S<Foo>>` to `Box<dyn Gettable<Foo>>`
help: consider annotating `Foo` with `#[derive(Copy)]`
|
LL + #[derive(Copy)]

View File

@ -46,8 +46,7 @@ LL | trait Foo : Copy {
| --- ^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&Box<{integer}>` to implement `CoerceUnsized<&dyn Foo>`
= note: required by cast to type `&dyn Foo`
= note: required for the cast from `&Box<{integer}>` to `&dyn Foo`
error: aborting due to 3 previous errors

View File

@ -32,8 +32,7 @@ LL | trait Foo : Copy {
| --- ^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&Box<i32>` to implement `CoerceUnsized<&dyn Foo>`
= note: required by cast to type `&dyn Foo`
= note: required for the cast from `&Box<i32>` to `&dyn Foo`
error: aborting due to 2 previous errors

View File

@ -220,11 +220,7 @@ LL | let _ = fat_v as *const dyn Foo;
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: required for the cast from `[u8]` to the object type `dyn Foo`
help: consider borrowing the value, since `&[u8]` can be coerced into `dyn Foo`
|
LL | let _ = &fat_v as *const dyn Foo;
| +
= note: required for the cast from `*const [u8]` to `*const dyn Foo`
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/cast-rfc0401.rs:62:13
@ -233,11 +229,7 @@ LL | let _ = a as *const dyn Foo;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn Foo`
help: consider borrowing the value, since `&str` can be coerced into `dyn Foo`
|
LL | let _ = &a as *const dyn Foo;
| +
= note: required for the cast from `*const str` to `*const dyn Foo`
error[E0606]: casting `&{float}` as `f32` is invalid
--> $DIR/cast-rfc0401.rs:71:30

View File

@ -10,7 +10,7 @@ LL | | }) as Box<dyn FnMut()>);
|
= note: expected unit type `()`
found type `!`
= note: required for the cast from `[closure@$DIR/fallback-closure-wrap.rs:18:40: 18:47]` to the object type `dyn FnMut()`
= note: required for the cast from `Box<[closure@$DIR/fallback-closure-wrap.rs:18:40: 18:47]>` to `Box<dyn FnMut()>`
error: aborting due to previous error

View File

@ -29,8 +29,7 @@ LL | fn foo<T>(&self, val: T);
LL | trait Bar: Foo { }
| --- this trait cannot be made into an object...
= help: consider moving `foo` to another trait
= note: required for `&mut Thing` to implement `CoerceUnsized<&mut dyn Bar>`
= note: required by cast to type `&mut dyn Bar`
= note: required for the cast from `&mut Thing` to `&mut dyn Bar`
error: aborting due to 2 previous errors

View File

@ -12,8 +12,7 @@ LL | trait Bar {
LL | const X: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `X` to another trait
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to previous error

View File

@ -12,8 +12,7 @@ LL | trait Bar {
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-generics.rs:26:5
@ -29,8 +28,7 @@ LL | trait Bar {
LL | fn bar<T>(&self, t: T);
| ^^^ ...because method `bar` has generic type parameters
= help: consider moving `bar` to another trait
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to 2 previous errors

View File

@ -12,8 +12,7 @@ LL | trait Bar {
LL | fn bar(&self, x: &Self);
| ^^^^^ ...because method `bar` references the `Self` type in this parameter
= help: consider moving `bar` to another trait
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error[E0038]: the trait `Baz` cannot be made into an object
--> $DIR/object-safety-mentions-Self.rs:30:5
@ -29,8 +28,7 @@ LL | trait Baz {
LL | fn baz(&self) -> Self;
| ^^^^ ...because method `baz` references the `Self` type in its return type
= help: consider moving `baz` to another trait
= note: required for `&T` to implement `CoerceUnsized<&dyn Baz>`
= note: required by cast to type `&dyn Baz`
= note: required for the cast from `&T` to `&dyn Baz`
error: aborting due to 2 previous errors

View File

@ -11,8 +11,7 @@ LL | trait Foo {
| --- this trait cannot be made into an object...
LL | fn foo() {}
| ^^^ ...because associated function `foo` has no `self` parameter
= note: required for `Box<Bar>` to implement `CoerceUnsized<Box<dyn Foo>>`
= note: required by cast to type `Box<dyn Foo>`
= note: required for the cast from `Box<Bar>` to `Box<dyn Foo>`
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self) {}

View File

@ -11,8 +11,7 @@ LL | trait Bar
| --- this trait cannot be made into an object...
LL | where Self : Sized
| ^^^^^ ...because it requires `Self: Sized`
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to previous error

View File

@ -11,8 +11,7 @@ LL | trait Bar : Sized {
| --- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&T` to implement `CoerceUnsized<&dyn Bar>`
= note: required by cast to type `&dyn Bar`
= note: required for the cast from `&T` to `&dyn Bar`
error: aborting due to previous error

View File

@ -31,8 +31,7 @@ LL | trait Foo {
| --- this trait cannot be made into an object...
LL | fn foo(self: &Rc<Self>) -> usize;
| ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
= note: required for `Rc<usize>` to implement `CoerceUnsized<Rc<dyn Foo>>`
= note: required by cast to type `Rc<dyn Foo>`
= note: required for the cast from `Rc<usize>` to `Rc<dyn Foo>`
error: aborting due to 2 previous errors

View File

@ -14,8 +14,7 @@ LL | trait Foo {
| --- this trait cannot be made into an object...
LL | fn foo(self: &Rc<Self>) -> usize;
| ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
= note: required for `Rc<usize>` to implement `CoerceUnsized<Rc<dyn Foo>>`
= note: required by cast to type `Rc<dyn Foo>`
= note: required for the cast from `Rc<usize>` to `Rc<dyn Foo>`
error: aborting due to previous error

View File

@ -36,7 +36,7 @@ LL | impl<T: Debug + Trait> Debug for Inner<T> {
| unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `&c::Inner<T>` to implement `Debug`
= note: required for the cast from `&c::Inner<T>` to the object type `dyn Debug`
= note: required for the cast from `&&c::Inner<T>` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|
@ -58,7 +58,7 @@ LL | impl<T> Debug for Inner<T> where T: Debug, T: Trait {
| ^^^^^ ^^^^^^^^ ----- unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `&d::Inner<T>` to implement `Debug`
= note: required for the cast from `&d::Inner<T>` to the object type `dyn Debug`
= note: required for the cast from `&&d::Inner<T>` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|
@ -80,7 +80,7 @@ LL | impl<T> Debug for Inner<T> where T: Debug + Trait {
| ^^^^^ ^^^^^^^^ ----- unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `&e::Inner<T>` to implement `Debug`
= note: required for the cast from `&e::Inner<T>` to the object type `dyn Debug`
= note: required for the cast from `&&e::Inner<T>` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|
@ -102,7 +102,7 @@ LL | impl<T: Debug> Debug for Inner<T> where T: Trait {
| ^^^^^ ^^^^^^^^ ----- unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `&f::Inner<T>` to implement `Debug`
= note: required for the cast from `&f::Inner<T>` to the object type `dyn Debug`
= note: required for the cast from `&&f::Inner<T>` to `&dyn Debug`
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
|

View File

@ -1,16 +0,0 @@
use std::ffi::{OsStr, OsString};
use std::path::Path;
fn check(p: &dyn AsRef<Path>) {
let m = std::fs::metadata(&p);
println!("{:?}", &m);
}
fn main() {
let s: OsString = ".".into();
let s: &OsStr = &s;
check(s);
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
//~| HELP within `OsStr`, the trait `Sized` is not implemented for `[u8]`
//~| HELP consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef<Path>`
}

View File

@ -1,18 +0,0 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/suggest-borrow-to-dyn-object.rs:12:11
|
LL | check(s);
| ^ doesn't have a size known at compile-time
|
= help: within `OsStr`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `OsStr`
--> $SRC_DIR/std/src/ffi/os_str.rs:LL:COL
= note: required for the cast from `OsStr` to the object type `dyn AsRef<Path>`
help: consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef<Path>`
|
LL | check(&s);
| +
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -5,7 +5,7 @@ LL | let s: Box<dyn Trait<isize>> = Box::new(Struct { person: "Fred" });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<isize>` is not implemented for `Struct`
|
= help: the trait `Trait<&'static str>` is implemented for `Struct`
= note: required for the cast from `Struct` to the object type `dyn Trait<isize>`
= note: required for the cast from `Box<Struct>` to `Box<dyn Trait<isize>>`
error: aborting due to previous error

View File

@ -27,8 +27,7 @@ LL | trait Array: Sized + Copy {}
| | |
| | ...because it requires `Self: Sized`
| this trait cannot be made into an object...
= note: required for `&T` to implement `CoerceUnsized<&dyn Array>`
= note: required by cast to type `&dyn Array`
= note: required for the cast from `&T` to `&dyn Array`
error: aborting due to 2 previous errors

View File

@ -25,8 +25,7 @@ LL | trait Foo where u32: Q<Self> {
| --- ^^^^^^^ ...because it uses `Self` as a type parameter
| |
| this trait cannot be made into an object...
= note: required for `Box<()>` to implement `CoerceUnsized<Box<dyn Foo>>`
= note: required by cast to type `Box<dyn Foo>`
= note: required for the cast from `Box<()>` to `Box<dyn Foo>`
error: aborting due to 2 previous errors

View File

@ -12,7 +12,7 @@ note: required because it appears within the type `B`
|
LL | struct B {
| ^
= note: required for the cast from `B` to the object type `dyn Foo + Send`
= note: required for the cast from `Box<B>` to `Box<dyn Foo + Send>`
error: aborting due to previous error

View File

@ -5,7 +5,7 @@ LL | let y: Box<dyn Map<usize, isize>> = Box::new(x);
| ^^^^^^^^^^^ the trait `Map<usize, isize>` is not implemented for `Box<dyn Map<isize, isize>>`
|
= help: the trait `Map<K, V>` is implemented for `HashMap<K, V>`
= note: required for the cast from `Box<dyn Map<isize, isize>>` to the object type `dyn Map<usize, isize>`
= note: required for the cast from `Box<Box<dyn Map<isize, isize>>>` to `Box<dyn Map<usize, isize>>`
error: aborting due to previous error

View File

@ -20,8 +20,7 @@ LL | trait Foo: for<T> Bar<T> {}
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
| |
| this trait cannot be made into an object...
= note: required for `&()` to implement `CoerceUnsized<&dyn Foo>`
= note: required by cast to type `&dyn Foo`
= note: required for the cast from `&()` to `&dyn Foo`
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/supertrait-object-safety.rs:19:12

View File

@ -11,8 +11,7 @@ LL | trait Tr {
| -- this trait cannot be made into an object...
LL | fn foo();
| ^^^ ...because associated function `foo` has no `self` parameter
= note: required for `&St` to implement `CoerceUnsized<&dyn Tr>`
= note: required by cast to type `&dyn Tr`
= note: required for the cast from `&St` to `&dyn Tr`
help: consider turning `foo` into a method by giving it a `&self` argument
|
LL | fn foo(&self);

View File

@ -76,8 +76,7 @@ LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
| this trait cannot be made into an object...
= help: consider moving `dup` to another trait
= help: consider moving `blah` to another trait
= note: required for `Box<{integer}>` to implement `CoerceUnsized<Box<dyn bar>>`
= note: required by cast to type `Box<dyn bar>`
= note: required for the cast from `Box<{integer}>` to `Box<dyn bar>`
error: aborting due to 5 previous errors

View File

@ -15,7 +15,7 @@ error[E0277]: the trait bound `&dyn Foo: Bar<_>` is not satisfied
LL | let _ = x as &dyn Bar<_>; // Ambiguous
| ^ the trait `Bar<_>` is not implemented for `&dyn Foo`
|
= note: required for the cast from `&dyn Foo` to the object type `dyn Bar<_>`
= note: required for the cast from `&&dyn Foo` to `&dyn Bar<_>`
error: aborting due to 2 previous errors

View File

@ -15,7 +15,7 @@ error[E0277]: the trait bound `&dyn Foo<i32>: Bar<u32>` is not satisfied
LL | let _ = x as &dyn Bar<u32>; // Error
| ^ the trait `Bar<u32>` is not implemented for `&dyn Foo<i32>`
|
= note: required for the cast from `&dyn Foo<i32>` to the object type `dyn Bar<u32>`
= note: required for the cast from `&&dyn Foo<i32>` to `&dyn Bar<u32>`
error[E0605]: non-primitive cast: `&dyn Foo<u32>` as `&dyn Bar<_>`
--> $DIR/type-checking-test-2.rs:25:13
@ -34,7 +34,7 @@ error[E0277]: the trait bound `&dyn Foo<u32>: Bar<_>` is not satisfied
LL | let a = x as &dyn Bar<_>; // Ambiguous
| ^ the trait `Bar<_>` is not implemented for `&dyn Foo<u32>`
|
= note: required for the cast from `&dyn Foo<u32>` to the object type `dyn Bar<_>`
= note: required for the cast from `&&dyn Foo<u32>` to `&dyn Bar<_>`
error: aborting due to 4 previous errors

View File

@ -4,7 +4,7 @@ error[E0271]: expected `test` to be a fn item that returns `Pin<Box<dyn Future<O
LL | Box::new(test) as AsyncFnPtr;
| ^^^^^^^^^^^^^^ expected `Pin<Box<dyn Future<Output = ()>>>`, found future
|
= note: required for the cast from `fn() -> impl Future<Output = ()> {test}` to the object type `dyn Fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>>`
= note: required for the cast from `Box<fn() -> impl Future<Output = ()> {test}>` to `Box<(dyn Fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> + 'static)>`
error: aborting due to previous error

View File

@ -9,7 +9,7 @@ LL | let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi);
|
= note: expected struct `Box<u8>`
found opaque type `impl Sized`
= note: required for the cast from `fn() -> impl Sized {hi}` to the object type `dyn Fn() -> Box<u8>`
= note: required for the cast from `Box<fn() -> impl Sized {hi}>` to `Box<dyn Fn() -> Box<u8>>`
error: aborting due to previous error

View File

@ -6,7 +6,7 @@ LL | x = Some(Box::new(callback));
|
= help: within `fn() -> dyn ToString`, the trait `Sized` is not implemented for `dyn ToString`
= note: required because it appears within the type `fn() -> dyn ToString`
= note: required for the cast from `fn() -> dyn ToString` to the object type `dyn Fn() -> (dyn ToString + 'static)`
= note: required for the cast from `Box<fn() -> dyn ToString>` to `Box<dyn Fn() -> (dyn ToString + 'static)>`
error: aborting due to previous error

View File

@ -5,8 +5,8 @@ LL | foo11("bar", &"baz");
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn AsRef<Path>`
help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<Path>`
= note: required for the cast from `&'static str` to `&dyn AsRef<Path>`
help: consider borrowing the value, since `&&'static str` can be coerced into `&dyn AsRef<Path>`
|
LL | foo11(&"bar", &"baz");
| +
@ -18,8 +18,8 @@ LL | foo12(&"bar", "baz");
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn AsRef<Path>`
help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<Path>`
= note: required for the cast from `&'static str` to `&dyn AsRef<Path>`
help: consider borrowing the value, since `&&'static str` can be coerced into `&dyn AsRef<Path>`
|
LL | foo12(&"bar", &"baz");
| +
@ -31,8 +31,8 @@ LL | foo21("bar", &"baz");
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn AsRef<str>`
help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<str>`
= note: required for the cast from `&'static str` to `&dyn AsRef<str>`
help: consider borrowing the value, since `&&'static str` can be coerced into `&dyn AsRef<str>`
|
LL | foo21(&"bar", &"baz");
| +
@ -44,8 +44,8 @@ LL | foo22(&"bar", "baz");
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast from `str` to the object type `dyn AsRef<str>`
help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef<str>`
= note: required for the cast from `&'static str` to `&dyn AsRef<str>`
help: consider borrowing the value, since `&&'static str` can be coerced into `&dyn AsRef<str>`
|
LL | foo22(&"bar", &"baz");
| +

View File

@ -11,8 +11,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `Box<S>` to implement `CoerceUnsized<Box<dyn Trait>>`
= note: required by cast to type `Box<dyn Trait>`
= note: required for the cast from `Box<S>` to `Box<dyn Trait>`
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-convert-unsafe-trait-obj-box.rs:17:15
@ -27,8 +26,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `Box<S>` to implement `CoerceUnsized<Box<dyn Trait>>`
= note: required by cast to type `Box<(dyn Trait + 'static)>`
= note: required for the cast from `Box<S>` to `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
@ -43,8 +41,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `Box<S>` to implement `CoerceUnsized<Box<dyn Trait>>`
= note: required by cast to type `Box<dyn Trait>`
= note: required for the cast from `Box<S>` to `Box<dyn Trait>`
error: aborting due to 3 previous errors

View File

@ -11,8 +11,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&S` to implement `CoerceUnsized<&dyn Trait>`
= note: required by cast to type `&dyn Trait`
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-convert-unsafe-trait-obj.rs:17:17
@ -27,8 +26,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&S` to implement `CoerceUnsized<&dyn Trait>`
= note: required by cast to type `&dyn Trait`
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-convert-unsafe-trait-obj.rs:15:5
@ -43,8 +41,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&S` to implement `CoerceUnsized<&dyn Trait>`
= note: required by cast to type `&dyn Trait`
= note: required for the cast from `&S` to `&dyn Trait`
error: aborting due to 3 previous errors

View File

@ -25,8 +25,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&S` to implement `CoerceUnsized<&dyn Trait>`
= note: required by cast to type `&dyn Trait`
= note: required for the cast from `&S` to `&dyn Trait`
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-unsafe-trait-obj-match.rs:25:25
@ -45,8 +44,7 @@ LL | trait Trait: Sized {}
| ----- ^^^^^ ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
= note: required for `&R` to implement `CoerceUnsized<&dyn Trait>`
= note: required by cast to type `&dyn Trait`
= note: required for the cast from `&R` to `&dyn Trait`
error: aborting due to 3 previous errors