Skip to content

Commit 0b58522

Browse files
committed
remove normalize call
1 parent ce8cfd2 commit 0b58522

File tree

4 files changed

+88
-20
lines changed

4 files changed

+88
-20
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
356356
let coercion = RegionVariableOrigin::Coercion(self.cause.span);
357357
let r_borrow = self.next_region_var(coercion);
358358
let autorefd_deref_ty = Ty::new_ref(self.tcx, r_borrow, deref_ty, mutbl_b);
359-
359+
360360
// Note that we unify the autoref'd `Target` type with `b` rather than
361361
// the `Target` type with the pointee of `b`. This is necessary
362362
// to properly account for the differing variances of the pointees
@@ -804,9 +804,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
804804
debug_assert!(self.shallow_resolve(a) == a);
805805
debug_assert!(self.shallow_resolve(b) == b);
806806

807-
let InferOk { value: b, mut obligations } =
808-
self.at(&self.cause, self.param_env).normalize(b);
809-
810807
match b.kind() {
811808
ty::FnPtr(_, b_hdr) => {
812809
let mut a_sig = a.fn_sig(self.tcx);
@@ -838,9 +835,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
838835
}
839836
}
840837

841-
let InferOk { value: a_sig, obligations: o1 } =
838+
// FIXME: we shouldn't be normalizing here as coercion is inside of
839+
// a probe. This can probably cause ICEs.
840+
let InferOk { value: a_sig, mut obligations } =
842841
self.at(&self.cause, self.param_env).normalize(a_sig);
843-
obligations.extend(o1);
844842

845843
let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn(
846844
a_sig,
@@ -855,8 +853,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
855853
}
856854
}
857855

858-
/// Attempts to coerce from the type of a non-capturing closure
859-
/// into a function pointer.
856+
/// Attempts to coerce from a closure to a function pointer. Fails
857+
/// if the closure has any upvars.
860858
fn coerce_closure_to_fn(
861859
&self,
862860
a: Ty<'tcx>,

tests/crashes/132765.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// We have two function parameters with types:
2+
// - `&?0`
3+
// - `Box<for<'a> fn(<?0 as Trait<'a>>::Item)>`
4+
//
5+
// As the alias in the second parameter has a `?0` it is an ambig
6+
// alias, and as it references bound vars it can't be normalized to
7+
// an infer var.
8+
//
9+
// When checking function arguments we try to coerce both:
10+
// - `&()` to `&?0`
11+
// - `FnDef(f)` to `Box<for<'a> fn(<?0 as Trait<'a>>::Item)>`
12+
//
13+
// The first coercion infers `?0=()`. Previously when handling
14+
// the second coercion we wound *re-normalize* the alias, which
15+
// now that `?0` has been inferred allowed us to determine this
16+
// alias is not wellformed and normalize it to some infer var `?1`.
17+
//
18+
// We would then see that `FnDef(f)` can't be coerced to `Box<fn(?1)>`
19+
// and return a `TypeError` referencing this new variable `?1`. This
20+
// then caused ICEs as diagnostics would encounter inferences variables
21+
// from the result of normalization inside of the probe used be coercion.
22+
23+
24+
trait LendingIterator {
25+
type Item<'q>;
26+
fn for_each(&self, _f: Box<fn(Self::Item<'_>)>) {}
27+
}
28+
29+
fn f(_: ()) {}
30+
31+
fn main() {
32+
LendingIterator::for_each(&(), f);
33+
//~^ ERROR: the trait bound `(): LendingIterator` is not satisfied
34+
//~| ERROR: the trait bound `(): LendingIterator` is not satisfied
35+
//~| ERROR: mismatched types
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0277]: the trait bound `(): LendingIterator` is not satisfied
2+
--> $DIR/hr_alias_normalization_leaking_vars.rs:32:31
3+
|
4+
LL | LendingIterator::for_each(&(), f);
5+
| ------------------------- ^^^ the trait `LendingIterator` is not implemented for `()`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/hr_alias_normalization_leaking_vars.rs:24:1
11+
|
12+
LL | trait LendingIterator {
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/hr_alias_normalization_leaking_vars.rs:32:36
17+
|
18+
LL | LendingIterator::for_each(&(), f);
19+
| ------------------------- ^ expected `Box<fn(...)>`, found fn item
20+
| |
21+
| arguments to this function are incorrect
22+
|
23+
= note: expected struct `Box<for<'a> fn(<() as LendingIterator>::Item<'a>)>`
24+
found fn item `fn(()) {f}`
25+
note: method defined here
26+
--> $DIR/hr_alias_normalization_leaking_vars.rs:26:8
27+
|
28+
LL | fn for_each(&self, _f: Box<fn(Self::Item<'_>)>) {}
29+
| ^^^^^^^^ ---------------------------
30+
31+
error[E0277]: the trait bound `(): LendingIterator` is not satisfied
32+
--> $DIR/hr_alias_normalization_leaking_vars.rs:32:36
33+
|
34+
LL | LendingIterator::for_each(&(), f);
35+
| ^ the trait `LendingIterator` is not implemented for `()`
36+
|
37+
help: this trait has no implementations, consider adding one
38+
--> $DIR/hr_alias_normalization_leaking_vars.rs:24:1
39+
|
40+
LL | trait LendingIterator {
41+
| ^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: aborting due to 3 previous errors
44+
45+
Some errors have detailed explanations: E0277, E0308.
46+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)