Skip to content

Commit e3ff2a8

Browse files
authored
Rollup merge of #121323 - compiler-errors:raw-param-types, r=oli-obk
Don't use raw parameter types in `find_builder_fn` We shouldn't really ever be using `EarlyBinder::skip_binder` then performing type equality, since param types will never be equal to other types. When checking compatibility with the signature, we instead create some fresh args. Fixes #121314
2 parents d43fd29 + 1c80aad commit e3ff2a8

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use rustc_middle::ty::IsSuggestable;
3434
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt};
3535
use rustc_span::def_id::DefIdSet;
3636
use rustc_span::symbol::{kw, sym, Ident};
37-
use rustc_span::Symbol;
3837
use rustc_span::{edit_distance, ExpnKind, FileName, MacroKind, Span};
38+
use rustc_span::{Symbol, DUMMY_SP};
3939
use rustc_trait_selection::infer::InferCtxtExt;
4040
use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedNote;
4141
use rustc_trait_selection::traits::error_reporting::on_unimplemented::TypeErrCtxtExt as _;
@@ -1597,7 +1597,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15971597
.filter(|item| matches!(item.kind, ty::AssocKind::Fn) && !item.fn_has_self_parameter)
15981598
.filter_map(|item| {
15991599
// Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
1600-
let ret_ty = self.tcx.fn_sig(item.def_id).skip_binder().output();
1600+
let ret_ty = self
1601+
.tcx
1602+
.fn_sig(item.def_id)
1603+
.instantiate(self.tcx, self.fresh_args_for_item(DUMMY_SP, item.def_id))
1604+
.output();
16011605
let ret_ty = self.tcx.instantiate_bound_regions_with_erased(ret_ty);
16021606
let ty::Adt(def, args) = ret_ty.kind() else {
16031607
return None;

tests/ui/issues/issue-30123.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ error[E0599]: no function or associated item named `new_undirected` found for st
44
LL | let ug = Graph::<i32, i32>::new_undirected();
55
| ^^^^^^^^^^^^^^ function or associated item not found in `Graph<i32, i32>`
66
|
7+
note: if you're trying to build a new `issue_30123_aux::Graph<i32, i32>`, consider using `issue_30123_aux::Graph::<N, E>::new` which returns `issue_30123_aux::Graph<_, _>`
8+
--> $DIR/auxiliary/issue-30123-aux.rs:14:5
9+
|
10+
LL | pub fn new() -> Self {
11+
| ^^^^^^^^^^^^^^^^^^^^
712
= note: the function or associated item was found for
813
- `issue_30123_aux::Graph<N, E, Undirected>`
914

tests/ui/ufcs/bad-builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn hello<Q>() -> Vec<Q> {
2+
Vec::<Q>::mew()
3+
//~^ ERROR no function or associated item named `mew` found for struct `Vec<Q>` in the current scope
4+
}
5+
6+
fn main() {}

tests/ui/ufcs/bad-builder.stderr

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0599]: no function or associated item named `mew` found for struct `Vec<Q>` in the current scope
2+
--> $DIR/bad-builder.rs:2:15
3+
|
4+
LL | Vec::<Q>::mew()
5+
| ^^^
6+
| |
7+
| function or associated item not found in `Vec<Q>`
8+
| help: there is an associated function with a similar name: `new`
9+
|
10+
note: if you're trying to build a new `Vec<Q>` consider using one of the following associated functions:
11+
Vec::<T>::new
12+
Vec::<T>::with_capacity
13+
Vec::<T>::from_raw_parts
14+
Vec::<T, A>::new_in
15+
and 2 others
16+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)