From 6f1b0f18747a215e43c42973d41be5131cee93d1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 17 Apr 2025 16:47:55 +0000 Subject: [PATCH] Don't compute name of associated item if it's an RPITIT --- .../errors/wrong_number_of_generic_args.rs | 2 +- .../dont-probe-missing-item-name-2.rs | 12 ++++++++++ .../dont-probe-missing-item-name-2.stderr | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.rs create mode 100644 tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.stderr diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 526ee30209c7d..7a9d36b6c9c94 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -487,6 +487,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { items .in_definition_order() .filter(|item| item.is_type()) + .filter(|item| !item.is_impl_trait_in_trait()) .filter(|item| { !self .gen_args @@ -494,7 +495,6 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { .iter() .any(|constraint| constraint.ident.name == item.name()) }) - .filter(|item| !item.is_impl_trait_in_trait()) .map(|item| self.tcx.item_ident(item.def_id).to_string()) .collect() } else { diff --git a/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.rs b/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.rs new file mode 100644 index 0000000000000..e8329e3694d73 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.rs @@ -0,0 +1,12 @@ +trait Foo { + fn rpitit() -> impl Sized; +} + +// Ensure that we don't try to probe the name of the RPITIT when looking for +// fixes to suggest for the redundant generic below. + +fn test>() {} +//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied +//~| ERROR associated type `Assoc` not found for `Foo` + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.stderr b/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.stderr new file mode 100644 index 0000000000000..1058ef01f323f --- /dev/null +++ b/tests/ui/impl-trait/in-trait/dont-probe-missing-item-name-2.stderr @@ -0,0 +1,24 @@ +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/dont-probe-missing-item-name-2.rs:8:12 + | +LL | fn test>() {} + | ^^^------------------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/dont-probe-missing-item-name-2.rs:1:7 + | +LL | trait Foo { + | ^^^ + +error[E0220]: associated type `Assoc` not found for `Foo` + --> $DIR/dont-probe-missing-item-name-2.rs:8:21 + | +LL | fn test>() {} + | ^^^^^ associated type `Assoc` not found + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0220. +For more information about an error, try `rustc --explain E0107`.