Rollup merge of #130033 - compiler-errors:foreign-fn-types, r=BoxyUwU

Don't call `fn_arg_names` query for non-`fn` foreign items in resolver

Fixes #130015
This commit is contained in:
Matthias Krüger 2024-09-16 21:53:06 +02:00 committed by GitHub
commit 7be15b850f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 24 deletions

View File

@ -2068,11 +2068,14 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
) {
let res = binding.res();
if filter_fn(res) {
let def_id = res.def_id();
match res {
Res::Def(DefKind::Fn | DefKind::AssocFn, def_id) => {
let has_self = match def_id.as_local() {
Some(def_id) => {
self.r.delegation_fn_sigs.get(&def_id).map_or(false, |sig| sig.has_self)
}
Some(def_id) => self
.r
.delegation_fn_sigs
.get(&def_id)
.map_or(false, |sig| sig.has_self),
None => self
.r
.tcx
@ -2083,10 +2086,9 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if has_self {
return Some(AssocSuggestion::MethodWithSelf { called });
} else {
match res {
Res::Def(DefKind::AssocFn, _) => {
return Some(AssocSuggestion::AssocFn { called });
}
}
Res::Def(DefKind::AssocConst, _) => {
return Some(AssocSuggestion::AssocConst);
}
@ -2098,7 +2100,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
}
}
}
None
}

View File

@ -0,0 +1,3 @@
pub trait Foo {
type Bar;
}

View File

@ -0,0 +1,11 @@
//@ aux-build:foreign-trait-with-assoc.rs
extern crate foreign_trait_with_assoc;
use foreign_trait_with_assoc::Foo;
// Make sure we don't try to call `fn_arg_names` on a non-fn item.
impl Foo for Bar {}
//~^ ERROR cannot find type `Bar` in this scope
fn main() {}

View File

@ -0,0 +1,14 @@
error[E0412]: cannot find type `Bar` in this scope
--> $DIR/dont-compute-arg-names-for-non-fn.rs:8:14
|
LL | impl Foo for Bar {}
| ^^^
|
help: you might have meant to use the associated type
|
LL | impl Foo for Self::Bar {}
| ++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0412`.