Skip to content

Commit aa7edf7

Browse files
committed
Use the correct ParamEnv
1 parent 488d0c9 commit aa7edf7

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,12 +2219,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22192219
return Ok(None);
22202220
}
22212221

2222+
let param_env = tcx.param_env(block.owner.to_def_id());
22222223
let cause = ObligationCause::misc(span, block.owner.def_id);
22232224
let mut unsatisfied_predicates = Vec::new();
22242225

22252226
for &(impl_, (assoc_item, def_scope)) in &candidates {
22262227
let infcx = tcx.infer_ctxt().ignoring_regions().build();
2227-
let param_env = tcx.param_env(impl_);
22282228

22292229
let impl_ty = tcx.type_of(impl_);
22302230
let impl_substs = self.fresh_item_substs(impl_, &infcx);

tests/ui/associated-inherent-types/dispatch-on-self-type-0.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ fn main() {
3333
let _: Choose<NonCopy>::Result = ();
3434
let _: Choose<&str>::Result = vec!["..."];
3535
}
36+
37+
// Test if we use the correct `ParamEnv` when proving obligations.
38+
39+
pub fn parameterized<T: Copy>(x: T) {
40+
let _: Choose<T>::Result = vec![x];
41+
}

tests/ui/associated-inherent-types/not-found-unsatisfied-bounds.stderr renamed to tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-0.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the associated type `Yield` exists for `Container<[u8]>`, but its trait bounds were not satisfied
2-
--> $DIR/not-found-unsatisfied-bounds.rs:19:29
2+
--> $DIR/not-found-unsatisfied-bounds-0.rs:19:29
33
|
44
LL | struct Container<T: ?Sized>(T);
55
| --------------------------- associated item `Yield` not found for this struct
@@ -11,7 +11,7 @@ LL | let _: Container<[u8]>::Yield = 1;
1111
`[u8]: Sized`
1212

1313
error: the associated type `Combination` exists for `Duple<String, Rc<str>>`, but its trait bounds were not satisfied
14-
--> $DIR/not-found-unsatisfied-bounds.rs:20:45
14+
--> $DIR/not-found-unsatisfied-bounds-0.rs:20:45
1515
|
1616
LL | struct Duple<T, U>(T, U);
1717
| ------------------ associated item `Combination` not found for this struct
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// fail-check
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
// Test if we use the correct `ParamEnv` when proving obligations.
7+
8+
fn parameterized<T>() {
9+
let _: Container<T>::Proj = String::new(); //~ ERROR the associated type `Proj` exists for `Container<T>`, but its trait bounds were not satisfied
10+
}
11+
12+
struct Container<T>(T);
13+
14+
impl<T: Clone> Container<T> {
15+
type Proj = String;
16+
}
17+
18+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: the associated type `Proj` exists for `Container<T>`, but its trait bounds were not satisfied
2+
--> $DIR/not-found-unsatisfied-bounds-1.rs:9:26
3+
|
4+
LL | let _: Container<T>::Proj = String::new();
5+
| ^^^^ associated type cannot be referenced on `Container<T>` due to unsatisfied trait bounds
6+
...
7+
LL | struct Container<T>(T);
8+
| ------------------- associated item `Proj` not found for this struct
9+
|
10+
= note: the following trait bounds were not satisfied:
11+
`T: Clone`
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)