Mention traits being upcasted, types being coerced
This commit is contained in:
parent
4c5f6e6277
commit
0de7568e41
3 changed files with 16 additions and 9 deletions
|
@ -615,7 +615,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let mut has_unsized_tuple_coercion = false;
|
let mut has_unsized_tuple_coercion = false;
|
||||||
let mut has_trait_upcasting_coercion = false;
|
let mut has_trait_upcasting_coercion = None;
|
||||||
|
|
||||||
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
|
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
|
||||||
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
|
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
|
||||||
|
@ -635,7 +635,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
&& data_a.principal_def_id() != data_b.principal_def_id()
|
&& data_a.principal_def_id() != data_b.principal_def_id()
|
||||||
{
|
{
|
||||||
debug!("coerce_unsized: found trait upcasting coercion");
|
debug!("coerce_unsized: found trait upcasting coercion");
|
||||||
has_trait_upcasting_coercion = true;
|
has_trait_upcasting_coercion = Some((self_ty, unsize_ty));
|
||||||
}
|
}
|
||||||
if let ty::Tuple(..) = unsize_ty.kind() {
|
if let ty::Tuple(..) = unsize_ty.kind() {
|
||||||
debug!("coerce_unsized: found unsized tuple coercion");
|
debug!("coerce_unsized: found unsized tuple coercion");
|
||||||
|
@ -706,14 +706,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_trait_upcasting_coercion && !self.tcx().features().trait_upcasting {
|
if let Some((sub, sup)) = has_trait_upcasting_coercion
|
||||||
feature_err(
|
&& !self.tcx().features().trait_upcasting
|
||||||
|
{
|
||||||
|
// Renders better when we erase regions, since they're not really the point here.
|
||||||
|
let (sub, sup) = self.tcx.erase_regions((sub, sup));
|
||||||
|
let mut err = feature_err(
|
||||||
&self.tcx.sess.parse_sess,
|
&self.tcx.sess.parse_sess,
|
||||||
sym::trait_upcasting,
|
sym::trait_upcasting,
|
||||||
self.cause.span,
|
self.cause.span,
|
||||||
"trait upcasting coercion is experimental",
|
&format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"),
|
||||||
)
|
);
|
||||||
.emit();
|
err.note(&format!("required when coercing `{source}` into `{target}`"));
|
||||||
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(coercion)
|
Ok(coercion)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0658]: trait upcasting coercion is experimental
|
error[E0658]: cannot cast `dyn Bar` to `dyn Foo`, trait upcasting coercion is experimental
|
||||||
--> $DIR/feature-gate-trait_upcasting.rs:11:25
|
--> $DIR/feature-gate-trait_upcasting.rs:11:25
|
||||||
|
|
|
|
||||||
LL | let foo: &dyn Foo = bar;
|
LL | let foo: &dyn Foo = bar;
|
||||||
|
@ -6,6 +6,7 @@ LL | let foo: &dyn Foo = bar;
|
||||||
|
|
|
|
||||||
= note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information
|
= note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information
|
||||||
= help: add `#![feature(trait_upcasting)]` to the crate attributes to enable
|
= help: add `#![feature(trait_upcasting)]` to the crate attributes to enable
|
||||||
|
= note: required when coercing `&dyn Bar` into `&dyn Foo`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0658]: trait upcasting coercion is experimental
|
error[E0658]: cannot cast `dyn Fn()` to `dyn FnMut()`, trait upcasting coercion is experimental
|
||||||
--> $DIR/issue-11515.rs:9:33
|
--> $DIR/issue-11515.rs:9:33
|
||||||
|
|
|
|
||||||
LL | let test = box Test { func: closure };
|
LL | let test = box Test { func: closure };
|
||||||
|
@ -6,6 +6,7 @@ LL | let test = box Test { func: closure };
|
||||||
|
|
|
|
||||||
= note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information
|
= note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information
|
||||||
= help: add `#![feature(trait_upcasting)]` to the crate attributes to enable
|
= help: add `#![feature(trait_upcasting)]` to the crate attributes to enable
|
||||||
|
= note: required when coercing `Box<(dyn Fn() + 'static)>` into `Box<(dyn FnMut() + 'static)>`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue