From 5b003456246ad18d3141eb748d750f152f51194f Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 28 Nov 2025 14:07:18 +0800 Subject: [PATCH] Surpress suggestion from unstable items on stable channel --- compiler/rustc_resolve/src/diagnostics.rs | 1 + .../resolve/suggest-unresolve-nightly-149402.rs | 9 +++++++++ .../suggest-unresolve-nightly-149402.stderr | 15 +++++++++++++++ .../ui/resolve/suggest-unresolve-stable-149402.rs | 9 +++++++++ .../suggest-unresolve-stable-149402.stderr | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 tests/ui/resolve/suggest-unresolve-nightly-149402.rs create mode 100644 tests/ui/resolve/suggest-unresolve-nightly-149402.stderr create mode 100644 tests/ui/resolve/suggest-unresolve-stable-149402.rs create mode 100644 tests/ui/resolve/suggest-unresolve-stable-149402.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 2f4a18f9cfa6b..50fad9fa39d12 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1609,6 +1609,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } + suggestions.retain(|suggestion| suggestion.is_stable || self.tcx.sess.is_nightly_build()); suggestions } diff --git a/tests/ui/resolve/suggest-unresolve-nightly-149402.rs b/tests/ui/resolve/suggest-unresolve-nightly-149402.rs new file mode 100644 index 0000000000000..0af1c5086814d --- /dev/null +++ b/tests/ui/resolve/suggest-unresolve-nightly-149402.rs @@ -0,0 +1,9 @@ +//@ only-nightly + +fn foo() { + let x = Vec::new(); + x.push(Complete::Item { name: "hello" }); + //~^ ERROR failed to resolve: use of undeclared type `Complete` +} + +fn main() {} diff --git a/tests/ui/resolve/suggest-unresolve-nightly-149402.stderr b/tests/ui/resolve/suggest-unresolve-nightly-149402.stderr new file mode 100644 index 0000000000000..dbb3c488254ed --- /dev/null +++ b/tests/ui/resolve/suggest-unresolve-nightly-149402.stderr @@ -0,0 +1,15 @@ +error[E0433]: failed to resolve: use of undeclared type `Complete` + --> $DIR/suggest-unresolve-nightly-149402.rs:5:12 + | +LL | x.push(Complete::Item { name: "hello" }); + | ^^^^^^^^ use of undeclared type `Complete` + | +help: there is an enum variant `std::ops::CoroutineState::Complete`; try using the variant's enum + | +LL - x.push(Complete::Item { name: "hello" }); +LL + x.push(std::ops::CoroutineState::Item { name: "hello" }); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/resolve/suggest-unresolve-stable-149402.rs b/tests/ui/resolve/suggest-unresolve-stable-149402.rs new file mode 100644 index 0000000000000..88457271e99e3 --- /dev/null +++ b/tests/ui/resolve/suggest-unresolve-stable-149402.rs @@ -0,0 +1,9 @@ +//@ only-stable + +fn foo() { + let x = Vec::new(); + x.push(Complete::Item { name: "hello" }); + //~^ ERROR failed to resolve: use of undeclared type `Complete` +} + +fn main() {} diff --git a/tests/ui/resolve/suggest-unresolve-stable-149402.stderr b/tests/ui/resolve/suggest-unresolve-stable-149402.stderr new file mode 100644 index 0000000000000..6258861e19c3e --- /dev/null +++ b/tests/ui/resolve/suggest-unresolve-stable-149402.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared type `Complete` + --> $DIR/suggest-unresolve-stable-149402.rs:5:12 + | +LL | x.push(Complete::Item { name: "hello" }); + | ^^^^^^^^ use of undeclared type `Complete` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`.