mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Properly deal with missing/placeholder types inside GACs
This commit is contained in:
parent
791adf759c
commit
24afa42a90
@ -235,11 +235,16 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
|
||||
if let Some(item) = tcx.opt_associated_item(def_id.into())
|
||||
&& let ty::AssocKind::Const = item.kind
|
||||
&& let ty::ImplContainer = item.container
|
||||
&& let Some(trait_item) = item.trait_item_def_id
|
||||
&& let Some(trait_item_def_id) = item.trait_item_def_id
|
||||
{
|
||||
let args =
|
||||
tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args;
|
||||
Some(tcx.type_of(trait_item).instantiate(tcx, args))
|
||||
let impl_def_id = item.container_id(tcx);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity();
|
||||
let args = ty::GenericArgs::identity_for_item(tcx, def_id).rebase_onto(
|
||||
tcx,
|
||||
impl_def_id,
|
||||
impl_trait_ref.args,
|
||||
);
|
||||
Some(tcx.type_of(trait_item_def_id).instantiate(tcx, args))
|
||||
} else {
|
||||
Some(fcx.next_ty_var(span))
|
||||
}
|
||||
|
17
tests/ui/generic-const-items/assoc-const-missing-type.rs
Normal file
17
tests/ui/generic-const-items/assoc-const-missing-type.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Ensure that we properly deal with missing/placeholder types inside GACs.
|
||||
// issue: rust-lang/rust#124833
|
||||
#![feature(generic_const_items)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Trait {
|
||||
const K<T>: T;
|
||||
}
|
||||
|
||||
impl Trait for () {
|
||||
const K<T> = ();
|
||||
//~^ ERROR missing type for `const` item
|
||||
//~| ERROR mismatched types
|
||||
//~| ERROR mismatched types
|
||||
}
|
||||
|
||||
fn main() {}
|
32
tests/ui/generic-const-items/assoc-const-missing-type.stderr
Normal file
32
tests/ui/generic-const-items/assoc-const-missing-type.stderr
Normal file
@ -0,0 +1,32 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/assoc-const-missing-type.rs:11:18
|
||||
|
|
||||
LL | const K<T> = ();
|
||||
| - ^^ expected type parameter `T`, found `()`
|
||||
| |
|
||||
| expected this type parameter
|
||||
|
|
||||
= note: expected type parameter `T`
|
||||
found unit type `()`
|
||||
|
||||
error: missing type for `const` item
|
||||
--> $DIR/assoc-const-missing-type.rs:11:15
|
||||
|
|
||||
LL | const K<T> = ();
|
||||
| ^ help: provide a type for the associated constant: `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/assoc-const-missing-type.rs:11:18
|
||||
|
|
||||
LL | const K<T> = ();
|
||||
| - ^^ expected type parameter `T`, found `()`
|
||||
| |
|
||||
| expected this type parameter
|
||||
|
|
||||
= note: expected type parameter `T`
|
||||
found unit type `()`
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user