1
Fork 0

Handle trait/impl GAC mismatches when inferring missing/placeholder types

This commit is contained in:
León Orell Valerian Liehr 2024-05-23 20:05:28 +02:00
parent 24afa42a90
commit 39d9b840bb
No known key found for this signature in database
GPG key ID: D17A07215F68E713
4 changed files with 27 additions and 16 deletions

View file

@ -244,7 +244,8 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
impl_def_id, impl_def_id,
impl_trait_ref.args, impl_trait_ref.args,
); );
Some(tcx.type_of(trait_item_def_id).instantiate(tcx, args)) tcx.check_args_compatible(trait_item_def_id, args)
.then(|| tcx.type_of(trait_item_def_id).instantiate(tcx, args))
} else { } else {
Some(fcx.next_ty_var(span)) Some(fcx.next_ty_var(span))
} }

View file

@ -1,10 +0,0 @@
//@ known-bug: rust-lang/rust#124833
#![feature(generic_const_items)]
trait Trait {
const C<'a>: &'a str;
}
impl Trait for () {
const C<'a>: = "C";
}

View file

@ -5,6 +5,7 @@
trait Trait { trait Trait {
const K<T>: T; const K<T>: T;
const Q<'a>: &'a str;
} }
impl Trait for () { impl Trait for () {
@ -12,6 +13,9 @@ impl Trait for () {
//~^ ERROR missing type for `const` item //~^ ERROR missing type for `const` item
//~| ERROR mismatched types //~| ERROR mismatched types
//~| ERROR mismatched types //~| ERROR mismatched types
const Q = "";
//~^ ERROR missing type for `const` item
//~| ERROR lifetime parameters or bounds on const `Q` do not match the trait declaration
} }
fn main() {} fn main() {}

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/assoc-const-missing-type.rs:11:18 --> $DIR/assoc-const-missing-type.rs:12:18
| |
LL | const K<T> = (); LL | const K<T> = ();
| - ^^ expected type parameter `T`, found `()` | - ^^ expected type parameter `T`, found `()`
@ -10,13 +10,28 @@ LL | const K<T> = ();
found unit type `()` found unit type `()`
error: missing type for `const` item error: missing type for `const` item
--> $DIR/assoc-const-missing-type.rs:11:15 --> $DIR/assoc-const-missing-type.rs:12:15
| |
LL | const K<T> = (); LL | const K<T> = ();
| ^ help: provide a type for the associated constant: `()` | ^ help: provide a type for the associated constant: `()`
error[E0195]: lifetime parameters or bounds on const `Q` do not match the trait declaration
--> $DIR/assoc-const-missing-type.rs:16:12
|
LL | const Q<'a>: &'a str;
| ---- lifetimes in impl do not match this const in trait
...
LL | const Q = "";
| ^ lifetimes do not match const in trait
error: missing type for `const` item
--> $DIR/assoc-const-missing-type.rs:16:12
|
LL | const Q = "";
| ^ help: provide a type for the associated constant: `: &str`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/assoc-const-missing-type.rs:11:18 --> $DIR/assoc-const-missing-type.rs:12:18
| |
LL | const K<T> = (); LL | const K<T> = ();
| - ^^ expected type parameter `T`, found `()` | - ^^ expected type parameter `T`, found `()`
@ -27,6 +42,7 @@ LL | const K<T> = ();
found unit type `()` found unit type `()`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 3 previous errors error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`. Some errors have detailed explanations: E0195, E0308.
For more information about an error, try `rustc --explain E0195`.