Skip to content

Commit 29f31c5

Browse files
Don't call fn_arg_names for non-fn in resolver
1 parent 59d4114 commit 29f31c5

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+25-24
Original file line numberDiff line numberDiff line change
@@ -2068,33 +2068,34 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20682068
) {
20692069
let res = binding.res();
20702070
if filter_fn(res) {
2071-
let def_id = res.def_id();
2072-
let has_self = match def_id.as_local() {
2073-
Some(def_id) => {
2074-
self.r.delegation_fn_sigs.get(&def_id).map_or(false, |sig| sig.has_self)
2075-
}
2076-
None => self
2077-
.r
2078-
.tcx
2079-
.fn_arg_names(def_id)
2080-
.first()
2081-
.is_some_and(|ident| ident.name == kw::SelfLower),
2082-
};
2083-
if has_self {
2084-
return Some(AssocSuggestion::MethodWithSelf { called });
2085-
} else {
2086-
match res {
2087-
Res::Def(DefKind::AssocFn, _) => {
2071+
match res {
2072+
Res::Def(DefKind::Fn | DefKind::AssocFn, def_id) => {
2073+
let has_self = match def_id.as_local() {
2074+
Some(def_id) => self
2075+
.r
2076+
.delegation_fn_sigs
2077+
.get(&def_id)
2078+
.map_or(false, |sig| sig.has_self),
2079+
None => self
2080+
.r
2081+
.tcx
2082+
.fn_arg_names(def_id)
2083+
.first()
2084+
.is_some_and(|ident| ident.name == kw::SelfLower),
2085+
};
2086+
if has_self {
2087+
return Some(AssocSuggestion::MethodWithSelf { called });
2088+
} else {
20882089
return Some(AssocSuggestion::AssocFn { called });
20892090
}
2090-
Res::Def(DefKind::AssocConst, _) => {
2091-
return Some(AssocSuggestion::AssocConst);
2092-
}
2093-
Res::Def(DefKind::AssocTy, _) => {
2094-
return Some(AssocSuggestion::AssocType);
2095-
}
2096-
_ => {}
20972091
}
2092+
Res::Def(DefKind::AssocConst, _) => {
2093+
return Some(AssocSuggestion::AssocConst);
2094+
}
2095+
Res::Def(DefKind::AssocTy, _) => {
2096+
return Some(AssocSuggestion::AssocType);
2097+
}
2098+
_ => {}
20982099
}
20992100
}
21002101
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub trait Foo {
2+
type Bar;
3+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ aux-build:foreign-trait-with-assoc.rs
2+
3+
extern crate foreign_trait_with_assoc;
4+
use foreign_trait_with_assoc::Foo;
5+
6+
// Make sure we don't try to call `fn_arg_names` on a non-fn item.
7+
8+
impl Foo for Bar {}
9+
//~^ ERROR cannot find type `Bar` in this scope
10+
11+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0412]: cannot find type `Bar` in this scope
2+
--> $DIR/dont-compute-arg-names-for-non-fn.rs:8:14
3+
|
4+
LL | impl Foo for Bar {}
5+
| ^^^
6+
|
7+
help: you might have meant to use the associated type
8+
|
9+
LL | impl Foo for Self::Bar {}
10+
| ++++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)