mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
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:
commit
7be15b850f
@ -2068,33 +2068,34 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||||||
) {
|
) {
|
||||||
let res = binding.res();
|
let res = binding.res();
|
||||||
if filter_fn(res) {
|
if filter_fn(res) {
|
||||||
let def_id = res.def_id();
|
match res {
|
||||||
let has_self = match def_id.as_local() {
|
Res::Def(DefKind::Fn | DefKind::AssocFn, def_id) => {
|
||||||
Some(def_id) => {
|
let has_self = match def_id.as_local() {
|
||||||
self.r.delegation_fn_sigs.get(&def_id).map_or(false, |sig| sig.has_self)
|
Some(def_id) => self
|
||||||
}
|
.r
|
||||||
None => self
|
.delegation_fn_sigs
|
||||||
.r
|
.get(&def_id)
|
||||||
.tcx
|
.map_or(false, |sig| sig.has_self),
|
||||||
.fn_arg_names(def_id)
|
None => self
|
||||||
.first()
|
.r
|
||||||
.is_some_and(|ident| ident.name == kw::SelfLower),
|
.tcx
|
||||||
};
|
.fn_arg_names(def_id)
|
||||||
if has_self {
|
.first()
|
||||||
return Some(AssocSuggestion::MethodWithSelf { called });
|
.is_some_and(|ident| ident.name == kw::SelfLower),
|
||||||
} else {
|
};
|
||||||
match res {
|
if has_self {
|
||||||
Res::Def(DefKind::AssocFn, _) => {
|
return Some(AssocSuggestion::MethodWithSelf { called });
|
||||||
|
} else {
|
||||||
return Some(AssocSuggestion::AssocFn { called });
|
return Some(AssocSuggestion::AssocFn { called });
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::AssocConst, _) => {
|
|
||||||
return Some(AssocSuggestion::AssocConst);
|
|
||||||
}
|
|
||||||
Res::Def(DefKind::AssocTy, _) => {
|
|
||||||
return Some(AssocSuggestion::AssocType);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
Res::Def(DefKind::AssocConst, _) => {
|
||||||
|
return Some(AssocSuggestion::AssocConst);
|
||||||
|
}
|
||||||
|
Res::Def(DefKind::AssocTy, _) => {
|
||||||
|
return Some(AssocSuggestion::AssocType);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
tests/ui/resolve/auxiliary/foreign-trait-with-assoc.rs
Normal file
3
tests/ui/resolve/auxiliary/foreign-trait-with-assoc.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub trait Foo {
|
||||||
|
type Bar;
|
||||||
|
}
|
11
tests/ui/resolve/dont-compute-arg-names-for-non-fn.rs
Normal file
11
tests/ui/resolve/dont-compute-arg-names-for-non-fn.rs
Normal 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() {}
|
14
tests/ui/resolve/dont-compute-arg-names-for-non-fn.stderr
Normal file
14
tests/ui/resolve/dont-compute-arg-names-for-non-fn.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user