diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-20 19:35:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-20 19:35:41 +0100 |
| commit | e3ff2a8e381f1aad544886fc105d53af3f9c335a (patch) | |
| tree | 8810cc69dc3bde4c50ac83f784f82de57530bba8 | |
| parent | d43fd29bf2d0133b729d2c2187d195915b8cacfd (diff) | |
| parent | 1c80aadb0566a344adc028b06f47f1a21ec21e0c (diff) | |
| download | rust-e3ff2a8e381f1aad544886fc105d53af3f9c335a.tar.gz rust-e3ff2a8e381f1aad544886fc105d53af3f9c335a.zip | |
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
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/suggest.rs | 8 | ||||
| -rw-r--r-- | tests/ui/issues/issue-30123.stderr | 5 | ||||
| -rw-r--r-- | tests/ui/ufcs/bad-builder.rs | 6 | ||||
| -rw-r--r-- | tests/ui/ufcs/bad-builder.stderr | 20 |
4 files changed, 37 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 005d217fdc4..c77e5856307 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<Self>` or `Result<Self, _>`. - 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 cf71a01b58a..c086b45ac9b 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::<i32, i32>::new_undirected(); | ^^^^^^^^^^^^^^ function or associated item not found in `Graph<i32, i32>` | +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<_, _>` + --> $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<N, E, Undirected>` diff --git a/tests/ui/ufcs/bad-builder.rs b/tests/ui/ufcs/bad-builder.rs new file mode 100644 index 00000000000..350c96acca0 --- /dev/null +++ b/tests/ui/ufcs/bad-builder.rs @@ -0,0 +1,6 @@ +fn hello<Q>() -> Vec<Q> { + Vec::<Q>::mew() + //~^ ERROR no function or associated item named `mew` found for struct `Vec<Q>` 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 00000000000..7fa47c82de2 --- /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<Q>` in the current scope + --> $DIR/bad-builder.rs:2:15 + | +LL | Vec::<Q>::mew() + | ^^^ + | | + | function or associated item not found in `Vec<Q>` + | help: there is an associated function with a similar name: `new` + | +note: if you're trying to build a new `Vec<Q>` consider using one of the following associated functions: + Vec::<T>::new + Vec::<T>::with_capacity + Vec::<T>::from_raw_parts + Vec::<T, A>::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`. |
