Skip to content

Commit 125e69e

Browse files
committed
Suppress unstable-trait notes under -Zforce-unstable-if-unmarked
1 parent 0f5c221 commit 125e69e

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff 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
)

tests/ui/traits/nightly-only-unstable.force.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): LocalTrait` is not satisfied
22
--> $DIR/nightly-only-unstable.rs:25:21
33
|
44
LL | 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
|
2323
LL | 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
|

tests/ui/traits/nightly-only-unstable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)