Skip to content

Commit ddfa64f

Browse files
Don't compute name of associated item if it's an RPITIT
1 parent 883f9f7 commit ddfa64f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Diff for: compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
487487
items
488488
.in_definition_order()
489489
.filter(|item| item.is_type())
490+
.filter(|item| !item.is_impl_trait_in_trait())
490491
.filter(|item| {
491492
!self
492493
.gen_args
493494
.constraints
494495
.iter()
495496
.any(|constraint| constraint.ident.name == item.name())
496497
})
497-
.filter(|item| !item.is_impl_trait_in_trait())
498498
.map(|item| self.tcx.item_ident(item.def_id).to_string())
499499
.collect()
500500
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Foo {
2+
fn rpitit() -> impl Sized;
3+
}
4+
5+
// Ensure that we don't try to probe the name of the RPITIT when looking for
6+
// fixes to suggest for the redundant generic below.
7+
8+
fn test<T: Foo<i32, Assoc = i32>>() {}
9+
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
10+
//~| ERROR associated type `Assoc` not found for `Foo`
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
2+
--> $DIR/dont-probe-missing-item-name-2.rs:5:12
3+
|
4+
LL | fn test<T: Foo<i32, Assoc = i32>>() {}
5+
| ^^^------------------ help: remove the unnecessary generics
6+
| |
7+
| expected 0 generic arguments
8+
|
9+
note: trait defined here, with 0 generic parameters
10+
--> $DIR/dont-probe-missing-item-name-2.rs:1:7
11+
|
12+
LL | trait Foo {
13+
| ^^^
14+
15+
error[E0220]: associated type `Assoc` not found for `Foo`
16+
--> $DIR/dont-probe-missing-item-name-2.rs:5:21
17+
|
18+
LL | fn test<T: Foo<i32, Assoc = i32>>() {}
19+
| ^^^^^ associated type `Assoc` not found
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0107, E0220.
24+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)