Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. If you cannot produce a minimal reproduction case (something that would work in isolation), please provide the steps or even link to a repository that causes the problematic output to occur. --Given the following code: <!-- Please provide a link to -- The current output is: <!-- The following is not always necessary. --It should name the traits are attempted to be coerced, maybe tell me why that's not allowed (yet), etc. Right now it just highlights the entire line. The original example I had that made me run into this issue had an even longer expression there (multiple chained iterator methods) which just got all highlighted as one big block saying "somewhere here trait coercion is used and it's not allowed". Note that I understand why it's not allowed, I was just disappointed by the error message. I already talked to about this, and they also thought this output may be problematic. Even though the feature may be unstable, it's quite easy to arrive at a situation where you may get this error. <!-- If the problem is not self-explanatory, please provide a rationale for the change. --<!-- If dramatically different output is caused by small changes, consider also adding them here. If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. The output might also be different depending on the Edition. --<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
claim

Discussion:
)]; let mut has_unsized_tuple_coercion = false; <del> let mut has_trait_upcasting_coercion = false; </del> <ins> let mut has_trait_upcasting_coercion = None; </ins> // Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid // emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where

&& data_a.principal_def_id() != data_b.principal_def_id() { debug!("coerce_unsized: found trait upcasting coercion"); <del> has_trait_upcasting_coercion = true; </del> <ins> has_trait_upcasting_coercion = Some((self_ty, unsize_ty)); </ins> } if let ty::Tuple(..) = unsize_ty.kind() { debug!("coerce_unsized: found unsized tuple coercion");

.emit(); } <del> if has_trait_upcasting_coercion && !self.tcx().features().trait_upcasting { feature_err( </del> <ins> if let Some((sub, sup)) = has_trait_upcasting_coercion && !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( </ins> &self.tcx.sess.parse_sess, sym::trait_upcasting, self.cause.span, <del> "trait upcasting coercion is experimental", ) .emit(); </del> <ins> &format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"), ); err.note(&format!("required when coercing `{source}` into `{target}`")); err.emit(); </ins> } Ok(coercion)

<del> error[E0658]: trait upcasting coercion is experimental </del> <ins> error[E0658]: cannot cast `dyn Bar` to `dyn Foo`, trait upcasting coercion is experimental </ins> --> $DIR/feature-gate-trait_upcasting.rs:11:25 | LL |     let foo: &dyn Foo = bar;

| = 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 <ins> = note: required when coercing `&dyn Bar` into `&dyn Foo` </ins> error: aborting due to previous error

<del> error[E0658]: trait upcasting coercion is experimental </del> <ins> error[E0658]: cannot cast `dyn Fn()` to `dyn FnMut()`, trait upcasting coercion is experimental </ins> --> $DIR/issue-11515.rs:9:33 | LL |     let test = box Test { func: closure };

| = 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 <ins> = note: required when coercing `Box<(dyn Fn() + 'static)>` into `Box<(dyn FnMut() + 'static)>` </ins> error: aborting due to previous error