Skip to content

Commit 0dc36fc

Browse files
committed
fix: don't suggest similar method when unstable
1 parent 18e305d commit 0dc36fc

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
@@ -1027,6 +1027,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10271027
true
10281028
}
10291029
})
1030+
// ensure that we don't suggest unstable methods
1031+
.filter(|candidate| {
1032+
// note that `DUMMY_SP` is ok here because it is only used for
1033+
// suggestions and macro stuff which isn't applicable here.
1034+
!matches!(
1035+
self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1036+
stability::EvalResult::Deny { .. }
1037+
)
1038+
})
10301039
.map(|candidate| candidate.item.ident(self.tcx))
10311040
.filter(|&name| set.insert(name))
10321041
.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)