Use the correct ParamEnv

This commit is contained in:
León Orell Valerian Liehr 2023-02-17 18:41:24 +01:00
parent 488d0c9efd
commit aa7edf7073
No known key found for this signature in database
GPG Key ID: D17A07215F68E713
6 changed files with 41 additions and 3 deletions

View File

@ -2219,12 +2219,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return Ok(None);
}
let param_env = tcx.param_env(block.owner.to_def_id());
let cause = ObligationCause::misc(span, block.owner.def_id);
let mut unsatisfied_predicates = Vec::new();
for &(impl_, (assoc_item, def_scope)) in &candidates {
let infcx = tcx.infer_ctxt().ignoring_regions().build();
let param_env = tcx.param_env(impl_);
let impl_ty = tcx.type_of(impl_);
let impl_substs = self.fresh_item_substs(impl_, &infcx);

View File

@ -33,3 +33,9 @@ fn main() {
let _: Choose<NonCopy>::Result = ();
let _: Choose<&str>::Result = vec!["..."];
}
// Test if we use the correct `ParamEnv` when proving obligations.
pub fn parameterized<T: Copy>(x: T) {
let _: Choose<T>::Result = vec![x];
}

View File

@ -1,5 +1,5 @@
error: the associated type `Yield` exists for `Container<[u8]>`, but its trait bounds were not satisfied
--> $DIR/not-found-unsatisfied-bounds.rs:19:29
--> $DIR/not-found-unsatisfied-bounds-0.rs:19:29
|
LL | struct Container<T: ?Sized>(T);
| --------------------------- associated item `Yield` not found for this struct
@ -11,7 +11,7 @@ LL | let _: Container<[u8]>::Yield = 1;
`[u8]: Sized`
error: the associated type `Combination` exists for `Duple<String, Rc<str>>`, but its trait bounds were not satisfied
--> $DIR/not-found-unsatisfied-bounds.rs:20:45
--> $DIR/not-found-unsatisfied-bounds-0.rs:20:45
|
LL | struct Duple<T, U>(T, U);
| ------------------ associated item `Combination` not found for this struct

View File

@ -0,0 +1,18 @@
// fail-check
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
// Test if we use the correct `ParamEnv` when proving obligations.
fn parameterized<T>() {
let _: Container<T>::Proj = String::new(); //~ ERROR the associated type `Proj` exists for `Container<T>`, but its trait bounds were not satisfied
}
struct Container<T>(T);
impl<T: Clone> Container<T> {
type Proj = String;
}
fn main() {}

View File

@ -0,0 +1,14 @@
error: the associated type `Proj` exists for `Container<T>`, but its trait bounds were not satisfied
--> $DIR/not-found-unsatisfied-bounds-1.rs:9:26
|
LL | let _: Container<T>::Proj = String::new();
| ^^^^ associated type cannot be referenced on `Container<T>` due to unsatisfied trait bounds
...
LL | struct Container<T>(T);
| ------------------- associated item `Proj` not found for this struct
|
= note: the following trait bounds were not satisfied:
`T: Clone`
error: aborting due to previous error