Skip to content

Commit cbcd1c3

Browse files
Rollup merge of #151036 - issue-151026, r=mati865
Better handle when trying to iterate on a `Range` of a type that isn't `Step` Mention when a trait bound corresponds to an unstable trait. Mention `Range` when `Step` bound is unment, and explain that only some std types impl `Iterator` for `Range`. CC #151026
2 parents 4874f18 + 1fe705c commit cbcd1c3

57 files changed

Lines changed: 137 additions & 119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
681681
// Ambiguous predicates should never error
682682
| ty::PredicateKind::Ambiguous
683683
// We never return Err when proving UnstableFeature goal.
684-
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature{ .. })
684+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature { .. })
685685
| ty::PredicateKind::NormalizesTo { .. }
686686
| ty::PredicateKind::AliasRelate { .. }
687687
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType { .. }) => {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5550,7 +5550,14 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
55505550
};
55515551
if let ty::PredicatePolarity::Positive = trait_predicate.polarity() {
55525552
format!(
5553-
"{pre_message}the trait `{}` is not implemented for{desc} `{}`",
5553+
"{pre_message}the {}trait `{}` is not implemented for{desc} `{}`",
5554+
if tcx.lookup_stability(trait_predicate.def_id()).map(|s| s.level.is_stable())
5555+
== Some(false)
5556+
{
5557+
"nightly-only, unstable "
5558+
} else {
5559+
""
5560+
},
55545561
trait_predicate.print_modifiers_and_trait_path(),
55555562
tcx.short_string(trait_predicate.self_ty().skip_binder(), long_ty_path),
55565563
)

library/core/src/iter/range.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ unsafe_impl_trusted_step![AsciiChar char i8 i16 i32 i64 i128 isize u8 u16 u32 u6
2121
/// The *successor* operation moves towards values that compare greater.
2222
/// The *predecessor* operation moves towards values that compare lesser.
2323
#[rustc_diagnostic_item = "range_step"]
24+
#[rustc_on_unimplemented(
25+
message = "`std::ops::Range<{Self}>` is not an iterator",
26+
label = "`Range<{Self}>` is not an iterator",
27+
note = "`Range` only implements `Iterator` for select types in the standard library, \
28+
particularly integers; to see the full list of types, see the documentation for the \
29+
unstable `Step` trait"
30+
)]
2431
#[unstable(feature = "step_trait", issue = "42168")]
2532
pub trait Step: Clone + PartialOrd + Sized {
2633
/// Returns the bounds on the number of *successor* steps required to get from `start` to `end`

tests/run-make/missing-unstable-trait-bound/missing-bound.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0277]: the trait bound `T: Step` is not satisfied
1+
error[E0277]: `std::ops::Range<T>` is not an iterator
22
--> missing-bound.rs:2:14
33
|
44
2 | for _ in t {}
5-
| ^ the trait `Step` is not implemented for `T`
5+
| ^ `Range<T>` is not an iterator
66
|
7+
= note: `Range` only implements `Iterator` for select types in the standard library, particularly integers; to see the full list of types, see the documentation for the unstable `Step` trait
78
= note: required for `std::ops::Range<T>` to implement `Iterator`
89
= note: required for `std::ops::Range<T>` to implement `IntoIterator`
910

tests/ui-fulldeps/rustc-dev-remap.only-remap.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `NotAValidResultType: VisitorResult` is not satisf
44
LL | type Result = NotAValidResultType;
55
| ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
66
|
7-
help: the trait `VisitorResult` is not implemented for `NotAValidResultType`
7+
help: the nightly-only, unstable trait `VisitorResult` is not implemented for `NotAValidResultType`
88
--> $DIR/rustc-dev-remap.rs:LL:COL
99
|
1010
LL | struct NotAValidResultType;

tests/ui-fulldeps/rustc-dev-remap.remap-unremap.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `NotAValidResultType: VisitorResult` is not satisf
44
LL | type Result = NotAValidResultType;
55
| ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
66
|
7-
help: the trait `VisitorResult` is not implemented for `NotAValidResultType`
7+
help: the nightly-only, unstable trait `VisitorResult` is not implemented for `NotAValidResultType`
88
--> $DIR/rustc-dev-remap.rs:LL:COL
99
|
1010
LL | struct NotAValidResultType;

tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[derive(Diagnostic)]
77
LL | arg: NotIntoDiagArg,
88
| ^^^^^^^^^^^^^^ unsatisfied trait bound
99
|
10-
help: the trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
10+
help: the nightly-only, unstable trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
1111
--> $DIR/diagnostic-derive-doc-comment-field.rs:28:1
1212
|
1313
LL | struct NotIntoDiagArg;
@@ -29,7 +29,7 @@ LL | #[derive(Subdiagnostic)]
2929
LL | arg: NotIntoDiagArg,
3030
| ^^^^^^^^^^^^^^ unsatisfied trait bound
3131
|
32-
help: the trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
32+
help: the nightly-only, unstable trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
3333
--> $DIR/diagnostic-derive-doc-comment-field.rs:28:1
3434
|
3535
LL | struct NotIntoDiagArg;

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ LL | #[derive(Diagnostic)]
657657
LL | other: Hello,
658658
| ^^^^^ unsatisfied trait bound
659659
|
660-
help: the trait `IntoDiagArg` is not implemented for `Hello`
660+
help: the nightly-only, unstable trait `IntoDiagArg` is not implemented for `Hello`
661661
--> $DIR/diagnostic-derive.rs:40:1
662662
|
663663
LL | struct Hello {}

tests/ui/abi/issues/issue-22565-rust-call.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: functions with the "rust-call" ABI must take a single non-self tup
22
--> $DIR/issue-22565-rust-call.rs:3:1
33
|
44
LL | extern "rust-call" fn b(_i: i32) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Tuple` is not implemented for `i32`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `i32`
66

77
error: functions with the "rust-call" ABI must take a single non-self tuple argument
88
--> $DIR/issue-22565-rust-call.rs:17:5
@@ -32,7 +32,7 @@ error[E0277]: functions with the "rust-call" ABI must take a single non-self tup
3232
--> $DIR/issue-22565-rust-call.rs:27:7
3333
|
3434
LL | b(10);
35-
| ^^ the trait `std::marker::Tuple` is not implemented for `i32`
35+
| ^^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `i32`
3636

3737
error: functions with the "rust-call" ABI must take a single non-self tuple argument
3838
--> $DIR/issue-22565-rust-call.rs:29:5

tests/ui/async-await/coroutine-not-future.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `impl Future<Output = ()>: Coroutine<_>` is not sa
22
--> $DIR/coroutine-not-future.rs:36:21
33
|
44
LL | takes_coroutine(async_fn());
5-
| --------------- ^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future<Output = ()>`
5+
| --------------- ^^^^^^^^^^ the nightly-only, unstable trait `Coroutine<_>` is not implemented for `impl Future<Output = ()>`
66
| |
77
| required by a bound introduced by this call
88
|
@@ -16,7 +16,7 @@ error[E0277]: the trait bound `impl Future<Output = ()>: Coroutine<_>` is not sa
1616
--> $DIR/coroutine-not-future.rs:38:21
1717
|
1818
LL | takes_coroutine(returns_async_block());
19-
| --------------- ^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future<Output = ()>`
19+
| --------------- ^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Coroutine<_>` is not implemented for `impl Future<Output = ()>`
2020
| |
2121
| required by a bound introduced by this call
2222
|
@@ -30,7 +30,7 @@ error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:40:21:
3030
--> $DIR/coroutine-not-future.rs:40:21
3131
|
3232
LL | takes_coroutine(async {});
33-
| --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:40:21: 40:26}`
33+
| --------------- ^^^^^^^^ the nightly-only, unstable trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:40:21: 40:26}`
3434
| |
3535
| required by a bound introduced by this call
3636
|

0 commit comments

Comments
 (0)