From 18fdf59bf5fc20d1c651f1d0e1dfae5cf421f685 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 20 Feb 2024 02:58:07 +0000 Subject: [PATCH 1/2] Don't use raw parameter types in find_builder_fn --- compiler/rustc_hir_typeck/src/method/suggest.rs | 8 ++++++-- tests/ui/issues/issue-30123.stderr | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 4151298b42f0a..5aededa62bd79 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -34,8 +34,8 @@ use rustc_middle::ty::IsSuggestable; use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt}; use rustc_span::def_id::DefIdSet; use rustc_span::symbol::{kw, sym, Ident}; -use rustc_span::Symbol; use rustc_span::{edit_distance, ExpnKind, FileName, MacroKind, Span}; +use rustc_span::{Symbol, DUMMY_SP}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedNote; use rustc_trait_selection::traits::error_reporting::on_unimplemented::TypeErrCtxtExt as _; @@ -1597,7 +1597,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .filter(|item| matches!(item.kind, ty::AssocKind::Fn) && !item.fn_has_self_parameter) .filter_map(|item| { // Only assoc fns that return `Self`, `Option` or `Result`. - let ret_ty = self.tcx.fn_sig(item.def_id).skip_binder().output(); + let ret_ty = self + .tcx + .fn_sig(item.def_id) + .instantiate(self.tcx, self.fresh_args_for_item(DUMMY_SP, item.def_id)) + .output(); let ret_ty = self.tcx.instantiate_bound_regions_with_erased(ret_ty); let ty::Adt(def, args) = ret_ty.kind() else { return None; diff --git a/tests/ui/issues/issue-30123.stderr b/tests/ui/issues/issue-30123.stderr index cf71a01b58a5c..c086b45ac9bc0 100644 --- a/tests/ui/issues/issue-30123.stderr +++ b/tests/ui/issues/issue-30123.stderr @@ -4,6 +4,11 @@ error[E0599]: no function or associated item named `new_undirected` found for st LL | let ug = Graph::::new_undirected(); | ^^^^^^^^^^^^^^ function or associated item not found in `Graph` | +note: if you're trying to build a new `issue_30123_aux::Graph`, consider using `issue_30123_aux::Graph::::new` which returns `issue_30123_aux::Graph<_, _>` + --> $DIR/auxiliary/issue-30123-aux.rs:14:5 + | +LL | pub fn new() -> Self { + | ^^^^^^^^^^^^^^^^^^^^ = note: the function or associated item was found for - `issue_30123_aux::Graph` From 1c80aadb0566a344adc028b06f47f1a21ec21e0c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 20 Feb 2024 03:01:35 +0000 Subject: [PATCH 2/2] test --- tests/ui/ufcs/bad-builder.rs | 6 ++++++ tests/ui/ufcs/bad-builder.stderr | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ui/ufcs/bad-builder.rs create mode 100644 tests/ui/ufcs/bad-builder.stderr diff --git a/tests/ui/ufcs/bad-builder.rs b/tests/ui/ufcs/bad-builder.rs new file mode 100644 index 0000000000000..350c96acca08b --- /dev/null +++ b/tests/ui/ufcs/bad-builder.rs @@ -0,0 +1,6 @@ +fn hello() -> Vec { + Vec::::mew() + //~^ ERROR no function or associated item named `mew` found for struct `Vec` in the current scope +} + +fn main() {} diff --git a/tests/ui/ufcs/bad-builder.stderr b/tests/ui/ufcs/bad-builder.stderr new file mode 100644 index 0000000000000..7fa47c82de2f7 --- /dev/null +++ b/tests/ui/ufcs/bad-builder.stderr @@ -0,0 +1,20 @@ +error[E0599]: no function or associated item named `mew` found for struct `Vec` in the current scope + --> $DIR/bad-builder.rs:2:15 + | +LL | Vec::::mew() + | ^^^ + | | + | function or associated item not found in `Vec` + | help: there is an associated function with a similar name: `new` + | +note: if you're trying to build a new `Vec` consider using one of the following associated functions: + Vec::::new + Vec::::with_capacity + Vec::::from_raw_parts + Vec::::new_in + and 2 others + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`.