File tree Expand file tree Collapse file tree
compiler/rustc_trait_selection/src/error_reporting/traits Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5608,15 +5608,17 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
56085608 None => String :: new ( ) ,
56095609 } ;
56105610 if let ty:: PredicatePolarity :: Positive = trait_predicate. polarity ( ) {
5611+ // If the trait in question is unstable, mention that fact in the diagnostic.
5612+ // But if we're building with `-Zforce-unstable-if-unmarked` then _any_ trait
5613+ // not explicitly marked stable is considered unstable, so the extra text is
5614+ // unhelpful noise. See <https://github.com/rust-lang/rust/issues/152692>.
5615+ let mention_unstable = !tcx. sess . opts . unstable_opts . force_unstable_if_unmarked
5616+ && try { tcx. lookup_stability ( trait_predicate. def_id ( ) ) ?. level . is_stable ( ) }
5617+ == Some ( false ) ;
5618+ let unstable = if mention_unstable { "nightly-only, unstable " } else { "" } ;
5619+
56115620 format ! (
5612- "{pre_message}the {}trait `{}` is not implemented for{desc} `{}`" ,
5613- if tcx. lookup_stability( trait_predicate. def_id( ) ) . map( |s| s. level. is_stable( ) )
5614- == Some ( false )
5615- {
5616- "nightly-only, unstable "
5617- } else {
5618- ""
5619- } ,
5621+ "{pre_message}the {unstable}trait `{}` is not implemented for{desc} `{}`" ,
56205622 trait_predicate. print_modifiers_and_trait_path( ) ,
56215623 tcx. short_string( trait_predicate. self_ty( ) . skip_binder( ) , long_ty_path) ,
56225624 )
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): LocalTrait` is not satisfied
22 --> $DIR/nightly-only-unstable.rs:25:21
33 |
44LL | use_local_trait(());
5- | --------------- ^^ the nightly-only, unstable trait `LocalTrait` is not implemented for `()`
5+ | --------------- ^^ the trait `LocalTrait` is not implemented for `()`
66 | |
77 | required by a bound introduced by this call
88 |
@@ -21,7 +21,7 @@ error[E0277]: the trait bound `(): ForeignTrait` is not satisfied
2121 --> $DIR/nightly-only-unstable.rs:31:23
2222 |
2323LL | use_foreign_trait(());
24- | ----------------- ^^ the nightly-only, unstable trait `ForeignTrait` is not implemented for `()`
24+ | ----------------- ^^ the trait `ForeignTrait` is not implemented for `()`
2525 | |
2626 | required by a bound introduced by this call
2727 |
Original file line number Diff line number Diff line change @@ -25,12 +25,12 @@ fn main() {
2525 use_local_trait ( ( ) ) ;
2626 //~^ ERROR the trait bound `(): LocalTrait` is not satisfied
2727 //[normal]~| NOTE the trait `LocalTrait` is not implemented for `()`
28- //[force]~| NOTE the nightly-only, unstable trait `LocalTrait` is not implemented for `()`
28+ //[force]~| NOTE the trait `LocalTrait` is not implemented for `()`
2929 //~| NOTE required by a bound introduced by this call
3030
3131 use_foreign_trait ( ( ) ) ;
3232 //~^ ERROR the trait bound `(): ForeignTrait` is not satisfied
3333 //[normal]~| NOTE the nightly-only, unstable trait `ForeignTrait` is not implemented for `()`
34- //[force]~| NOTE the nightly-only, unstable trait `ForeignTrait` is not implemented for `()`
34+ //[force]~| NOTE the trait `ForeignTrait` is not implemented for `()`
3535 //~| NOTE required by a bound introduced by this call
3636}
You can’t perform that action at this time.
0 commit comments