diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-11-28 19:31:37 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-12-07 21:26:23 +0000 |
| commit | 568b0ac624553150330f1cc3bbff9b99e5d358a2 (patch) | |
| tree | cd69eaf52c24be564e4cf1179e6a668720ade3df | |
| parent | d13c34828e4bc0924f7e27bae994f9afecaf0ab4 (diff) | |
| download | rust-568b0ac624553150330f1cc3bbff9b99e5d358a2.tar.gz rust-568b0ac624553150330f1cc3bbff9b99e5d358a2.zip | |
Add test for lack of suggestion in stable
This test will break when `Step` gets stabilized, but punt until then.
5 files changed, 49 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index a8500398082..d34fb0945bb 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -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. diff --git a/tests/run-make/missing-unstable-trait-bound/missing-bound.rs b/tests/run-make/missing-unstable-trait-bound/missing-bound.rs new file mode 100644 index 00000000000..65d0745f494 --- /dev/null +++ b/tests/run-make/missing-unstable-trait-bound/missing-bound.rs @@ -0,0 +1,4 @@ +pub fn baz<T>(t: std::ops::Range<T>) { + for _ in t {} +} +fn main() {} diff --git a/tests/run-make/missing-unstable-trait-bound/rmake.rs b/tests/run-make/missing-unstable-trait-bound/rmake.rs new file mode 100644 index 00000000000..1e0cb1336a4 --- /dev/null +++ b/tests/run-make/missing-unstable-trait-bound/rmake.rs @@ -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`"#, + ); +} diff --git a/tests/ui/trait-bounds/unstable-trait-suggestion.rs b/tests/ui/trait-bounds/unstable-trait-suggestion.rs index c49e2a34033..ba96b4f3f97 100644 --- a/tests/ui/trait-bounds/unstable-trait-suggestion.rs +++ b/tests/ui/trait-bounds/unstable-trait-suggestion.rs @@ -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() {} diff --git a/tests/ui/trait-bounds/unstable-trait-suggestion.stderr b/tests/ui/trait-bounds/unstable-trait-suggestion.stderr index a326965b683..fa8e428aa1f 100644 --- a/tests/ui/trait-bounds/unstable-trait-suggestion.stderr +++ b/tests/ui/trait-bounds/unstable-trait-suggestion.stderr @@ -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`. |
