Skip to content

Commit 5de94b6

Browse files
authored
Rollup merge of #128337 - bvanjoi:issue-121613, r=compiler-errors
skip assoc type during infer source visitor Fixes #121613 Due to the generic arguments being lost during normalization, the associated type cannot retrieve the correct generics information, so this PR follows this [comment](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs#L937-L942) and skips `DefKind::AssocTy` r? `@lcnr`
2 parents 28c1743 + 97469cc commit 5de94b6

File tree

7 files changed

+120
-56
lines changed

7 files changed

+120
-56
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
934934
// which makes this somewhat difficult and prevents us from just
935935
// using `self.path_inferred_arg_iter` here.
936936
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _)
937-
// FIXME(TaKO8Ki): Ideally we should support this. For that
938-
// we have to map back from the self type to the
939-
// type alias though. That's difficult.
937+
// FIXME(TaKO8Ki): Ideally we should support other kinds,
938+
// such as `TyAlias` or `AssocTy`. For that we have to map
939+
// back from the self type to the type alias though. That's difficult.
940940
//
941941
// See the `need_type_info/issue-103053.rs` test for
942942
// a example.
943-
if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
943+
if matches!(path.res, Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)) => {
944944
if let Some(ty) = self.opt_node_type(expr.hir_id)
945945
&& let ty::Adt(_, args) = ty.kind()
946946
{

tests/crashes/121613-2.rs

-28
This file was deleted.

tests/crashes/121613.rs

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// issue#121613
2+
3+
#![feature(more_qualified_paths)]
4+
5+
struct S {}
6+
7+
struct Foo;
8+
9+
trait A {
10+
type Assoc;
11+
}
12+
13+
impl A for Foo {
14+
type Assoc = S;
15+
}
16+
17+
fn f() {}
18+
19+
fn main() {
20+
<Foo as A>::Assoc {};
21+
f(|a, b| a.cmp(b));
22+
//~^ ERROR: type annotations needed
23+
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/incompat-call-after-qualified-path-0.rs:21:6
3+
|
4+
LL | f(|a, b| a.cmp(b));
5+
| ^ - type must be known at this point
6+
|
7+
help: consider giving this closure parameter an explicit type
8+
|
9+
LL | f(|a: /* Type */, b| a.cmp(b));
10+
| ++++++++++++
11+
12+
error[E0061]: this function takes 0 arguments but 1 argument was supplied
13+
--> $DIR/incompat-call-after-qualified-path-0.rs:21:3
14+
|
15+
LL | f(|a, b| a.cmp(b));
16+
| ^ --------------- unexpected argument
17+
|
18+
note: function defined here
19+
--> $DIR/incompat-call-after-qualified-path-0.rs:17:4
20+
|
21+
LL | fn f() {}
22+
| ^
23+
help: remove the extra argument
24+
|
25+
LL - f(|a, b| a.cmp(b));
26+
LL + f();
27+
|
28+
29+
error: aborting due to 2 previous errors
30+
31+
Some errors have detailed explanations: E0061, E0282.
32+
For more information about an error, try `rustc --explain E0061`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// issue#121613
2+
3+
#![feature(more_qualified_paths)]
4+
5+
struct S<T> {
6+
a: T
7+
}
8+
9+
struct Foo;
10+
11+
trait A {
12+
type Assoc<T>;
13+
}
14+
15+
impl A for Foo {
16+
type Assoc<T> = S<T>;
17+
}
18+
19+
fn f() {}
20+
21+
fn main() {
22+
<Foo as A>::Assoc::<i32> {
23+
a: 1
24+
};
25+
f(|a, b| a.cmp(b));
26+
//~^ ERROR: type annotations needed
27+
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/incompat-call-after-qualified-path-1.rs:25:6
3+
|
4+
LL | f(|a, b| a.cmp(b));
5+
| ^ - type must be known at this point
6+
|
7+
help: consider giving this closure parameter an explicit type
8+
|
9+
LL | f(|a: /* Type */, b| a.cmp(b));
10+
| ++++++++++++
11+
12+
error[E0061]: this function takes 0 arguments but 1 argument was supplied
13+
--> $DIR/incompat-call-after-qualified-path-1.rs:25:3
14+
|
15+
LL | f(|a, b| a.cmp(b));
16+
| ^ --------------- unexpected argument
17+
|
18+
note: function defined here
19+
--> $DIR/incompat-call-after-qualified-path-1.rs:19:4
20+
|
21+
LL | fn f() {}
22+
| ^
23+
help: remove the extra argument
24+
|
25+
LL - f(|a, b| a.cmp(b));
26+
LL + f();
27+
|
28+
29+
error: aborting due to 2 previous errors
30+
31+
Some errors have detailed explanations: E0061, E0282.
32+
For more information about an error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)