Skip to content

Commit 39052da

Browse files
committed
Auto merge of rust-lang#149440 - chenyukang:yukang/issue-149402, r=fee1-dead
Remove suggestion from importing unstable items on stable channel Fixes rust-lang#149402
2 parents 0f14563 + c578560 commit 39052da

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16141614
}
16151615
}
16161616

1617+
suggestions.retain(|suggestion| suggestion.is_stable || self.tcx.sess.is_nightly_build());
16171618
suggestions
16181619
}
16191620

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() {
2+
let x = Vec::new();
3+
x.push(Complete::Item { name: "hello" });
4+
}
5+
6+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0433]: failed to resolve: use of undeclared type `Complete`
2+
--> foo.rs:3:12
3+
|
4+
3 | x.push(Complete::Item { name: "hello" });
5+
| ^^^^^^^^ use of undeclared type `Complete`
6+
|
7+
help: there is an enum variant `core::ops::CoroutineState::Complete` and 1 other; try using the variant's enum
8+
|
9+
3 - x.push(Complete::Item { name: "hello" });
10+
3 + x.push(core::ops::CoroutineState::Item { name: "hello" });
11+
|
12+
3 - x.push(Complete::Item { name: "hello" });
13+
3 + x.push(std::ops::CoroutineState::Item { name: "hello" });
14+
|
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0433`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@@ -3,6 +3,15 @@
2+
|
3+
3 | x.push(Complete::Item { name: "hello" });
4+
| ^^^^^^^^ use of undeclared type `Complete`
5+
+ |
6+
+help: there is an enum variant `core::ops::CoroutineState::Complete` and 1 other; try using the variant's enum
7+
+ |
8+
+3 - x.push(Complete::Item { name: "hello" });
9+
+3 + x.push(core::ops::CoroutineState::Item { name: "hello" });
10+
+ |
11+
+3 - x.push(Complete::Item { name: "hello" });
12+
+3 + x.push(std::ops::CoroutineState::Item { name: "hello" });
13+
+ |
14+
15+
error: aborting due to 1 previous error
16+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Check that unstable name-resolution suggestions are omitted on stable.
2+
//!
3+
//! Regression test for <https://github.com/rust-lang/rust/issues/149402>.
4+
//!
5+
//@ only-nightly
6+
//@ needs-target-std
7+
8+
use run_make_support::{diff, rustc, similar};
9+
10+
fn main() {
11+
let stable_like = rustc()
12+
.env("RUSTC_BOOTSTRAP", "-1")
13+
.edition("2024")
14+
.input("foo.rs")
15+
.run_fail()
16+
.stderr_utf8();
17+
18+
assert!(!stable_like.contains("CoroutineState::Complete"));
19+
diff().expected_file("stable.err").actual_text("stable_like", &stable_like).run();
20+
21+
let nightly = rustc().edition("2024").input("foo.rs").run_fail().stderr_utf8();
22+
23+
assert!(nightly.contains("CoroutineState::Complete"));
24+
diff().expected_file("nightly.err").actual_text("nightly", &nightly).run();
25+
26+
let stderr_diff =
27+
similar::TextDiff::from_lines(&stable_like, &nightly).unified_diff().to_string();
28+
diff().expected_file("output.diff").actual_text("diff", stderr_diff).run();
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared type `Complete`
2+
--> foo.rs:3:12
3+
|
4+
3 | x.push(Complete::Item { name: "hello" });
5+
| ^^^^^^^^ use of undeclared type `Complete`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)