Skip to content

Commit e10e9fe

Browse files
committed
Properly deal with missing/placeholder types inside GACs
1 parent 791adf7 commit e10e9fe

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,13 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
237237
&& let ty::ImplContainer = item.container
238238
&& let Some(trait_item) = item.trait_item_def_id
239239
{
240-
let args =
241-
tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args;
240+
let impl_item = item.container_id(tcx);
241+
let impl_trait_ref = tcx.impl_trait_ref(impl_item).unwrap().instantiate_identity();
242+
let args = ty::GenericArgs::identity_for_item(tcx, def_id).rebase_onto(
243+
tcx,
244+
impl_item,
245+
impl_trait_ref.args,
246+
);
242247
Some(tcx.type_of(trait_item).instantiate(tcx, args))
243248
} else {
244249
Some(fcx.next_ty_var(span))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Ensure that we properly deal with missing/placeholder types inside GACs.
2+
// issue: rust-lang/rust#124833
3+
#![feature(generic_const_items)]
4+
#![allow(incomplete_features)]
5+
6+
trait Trait {
7+
const K<T>: T;
8+
}
9+
10+
impl Trait for () {
11+
const K<T> = ();
12+
//~^ ERROR missing type for `const` item
13+
//~| ERROR mismatched types
14+
//~| ERROR mismatched types
15+
}
16+
17+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/assoc-const-missing-type.rs:11:18
3+
|
4+
LL | const K<T> = ();
5+
| - ^^ expected type parameter `T`, found `()`
6+
| |
7+
| expected this type parameter
8+
|
9+
= note: expected type parameter `T`
10+
found unit type `()`
11+
12+
error: missing type for `const` item
13+
--> $DIR/assoc-const-missing-type.rs:11:15
14+
|
15+
LL | const K<T> = ();
16+
| ^ help: provide a type for the associated constant: `()`
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/assoc-const-missing-type.rs:11:18
20+
|
21+
LL | const K<T> = ();
22+
| - ^^ expected type parameter `T`, found `()`
23+
| |
24+
| expected this type parameter
25+
|
26+
= note: expected type parameter `T`
27+
found unit type `()`
28+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29+
30+
error: aborting due to 3 previous errors
31+
32+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)