Skip to content

Commit 879d6f2

Browse files
authored
Rollup merge of #109212 - Ezrashaw:no-similar-sugg-for-unstable, r=estebank
fix: don't suggest similar method when unstable Fixes #109177 Don't display typo suggestions for unstable things, unless the feature flag is enabled. AFAIK, there are two places this occurs: - `rustc_resolve`: before type checking, effectively just `FnCtxt::Free`. - `rustc_hir_typck`: during type checking, for `FnCtxt::Assoc(..)`s. The linked issue is about the latter, obviously the issue is applicable to both. r? `@estebank`
2 parents 654204f + 0dc36fc commit 879d6f2

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10281028
true
10291029
}
10301030
})
1031+
// ensure that we don't suggest unstable methods
1032+
.filter(|candidate| {
1033+
// note that `DUMMY_SP` is ok here because it is only used for
1034+
// suggestions and macro stuff which isn't applicable here.
1035+
!matches!(
1036+
self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1037+
stability::EvalResult::Deny { .. }
1038+
)
1039+
})
10311040
.map(|candidate| candidate.item.ident(self.tcx))
10321041
.filter(|&name| set.insert(name))
10331042
.collect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(staged_api)]
2+
#![stable(feature = "libfoo", since = "1.0.0")]
3+
4+
#[unstable(feature = "foo", reason = "...", issue = "none")]
5+
pub fn foo() {}
6+
7+
#[stable(feature = "libfoo", since = "1.0.0")]
8+
pub struct Foo;
9+
10+
impl Foo {
11+
#[unstable(feature = "foo", reason = "...", issue = "none")]
12+
pub fn foo(&self) {}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-build: similar-unstable-method.rs
2+
3+
extern crate similar_unstable_method;
4+
5+
fn main() {
6+
// FIXME: this function should not suggest the `foo` function.
7+
similar_unstable_method::foo1();
8+
//~^ ERROR cannot find function `foo1` in crate `similar_unstable_method` [E0425]
9+
10+
let foo = similar_unstable_method::Foo;
11+
foo.foo1();
12+
//~^ ERROR no method named `foo1` found for struct `Foo` in the current scope [E0599]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0425]: cannot find function `foo1` in crate `similar_unstable_method`
2+
--> $DIR/issue-109177.rs:7:30
3+
|
4+
LL | similar_unstable_method::foo1();
5+
| ^^^^ help: a function with a similar name exists: `foo`
6+
|
7+
::: $DIR/auxiliary/similar-unstable-method.rs:5:1
8+
|
9+
LL | pub fn foo() {}
10+
| ------------ similarly named function `foo` defined here
11+
12+
error[E0599]: no method named `foo1` found for struct `Foo` in the current scope
13+
--> $DIR/issue-109177.rs:11:9
14+
|
15+
LL | foo.foo1();
16+
| ^^^^ method not found in `Foo`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0425, E0599.
21+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)