mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-01 02:14:20 +00:00
Add test for lack of suggestion in stable
This test will break when `Step` gets stabilized, but punt until then.
This commit is contained in:
parent
d13c34828e
commit
568b0ac624
@ -488,7 +488,7 @@ pub fn suggest_constraining_type_params<'a>(
|
||||
.into_iter()
|
||||
.filter(|(span, _, _, _)| !span.in_derive_expansion())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let suggested = !suggestions.is_empty();
|
||||
if suggestions.len() == 1 {
|
||||
let (span, constraint, suggestion, msg) = suggestions.pop().unwrap();
|
||||
let post = format!(
|
||||
@ -524,7 +524,7 @@ pub fn suggest_constraining_type_params<'a>(
|
||||
);
|
||||
}
|
||||
|
||||
true
|
||||
suggested
|
||||
}
|
||||
|
||||
/// Collect al types that have an implicit `'static` obligation that we could suggest `'_` for.
|
||||
|
@ -0,0 +1,4 @@
|
||||
pub fn baz<T>(t: std::ops::Range<T>) {
|
||||
for _ in t {}
|
||||
}
|
||||
fn main() {}
|
22
tests/run-make/missing-unstable-trait-bound/rmake.rs
Normal file
22
tests/run-make/missing-unstable-trait-bound/rmake.rs
Normal file
@ -0,0 +1,22 @@
|
||||
//@ only-linux
|
||||
//@ ignore-wasm32
|
||||
//@ ignore-wasm64
|
||||
// ignore-tidy-linelength
|
||||
|
||||
// Ensure that on stable we don't suggest restricting with an unsafe trait and we continue
|
||||
// mentioning the rest of the obligation chain.
|
||||
|
||||
use run_make_support::{rust_lib_name, rustc};
|
||||
|
||||
fn main() {
|
||||
rustc()
|
||||
.env("RUSTC_BOOTSTRAP", "-1")
|
||||
.input("missing-bound.rs")
|
||||
.run_fail()
|
||||
.assert_stderr_not_contains("help: consider restricting type parameter `T`")
|
||||
.assert_stderr_contains(
|
||||
r#"
|
||||
= note: required for `std::ops::Range<T>` to implement `Iterator`
|
||||
= note: required for `std::ops::Range<T>` to implement `IntoIterator`"#,
|
||||
);
|
||||
}
|
@ -9,7 +9,11 @@ pub trait Unstable {}
|
||||
fn foo<T: Unstable>(_: T) {}
|
||||
|
||||
#[stable(feature = "unit_test", since = "1.0.0")]
|
||||
pub fn demo<T>(t: T) { //~ HELP consider restricting type parameter `T` with unstable trait `Unstable`
|
||||
pub fn bar<T>(t: T) { //~ HELP consider restricting type parameter `T` with unstable trait `Unstable`
|
||||
foo(t) //~ ERROR E0277
|
||||
}
|
||||
#[stable(feature = "unit_test", since = "1.0.0")]
|
||||
pub fn baz<T>(t: std::ops::Range<T>) { //~ HELP consider restricting type parameter `T` with unstable trait
|
||||
for _ in t {} //~ ERROR E0277
|
||||
}
|
||||
fn main() {}
|
||||
|
@ -13,9 +13,22 @@ LL | fn foo<T: Unstable>(_: T) {}
|
||||
| ^^^^^^^^ required by this bound in `foo`
|
||||
help: consider restricting type parameter `T` with unstable trait `Unstable`
|
||||
|
|
||||
LL | pub fn demo<T: Unstable>(t: T) {
|
||||
| ++++++++++
|
||||
LL | pub fn bar<T: Unstable>(t: T) {
|
||||
| ++++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error[E0277]: the trait bound `T: Step` is not satisfied
|
||||
--> $DIR/unstable-trait-suggestion.rs:17:14
|
||||
|
|
||||
LL | for _ in t {}
|
||||
| ^ the trait `Step` is not implemented for `T`
|
||||
|
|
||||
= note: required for `std::ops::Range<T>` to implement `Iterator`
|
||||
= note: required for `std::ops::Range<T>` to implement `IntoIterator`
|
||||
help: consider restricting type parameter `T` with unstable trait `std::iter::Step`
|
||||
|
|
||||
LL | pub fn baz<T: std::iter::Step>(t: std::ops::Range<T>) {
|
||||
| +++++++++++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
Loading…
Reference in New Issue
Block a user