Skip to content

Commit c24148e

Browse files
committed
Allow coercing functions whose signature differs in opaque types in their defining scope into a shared function pointer type
1 parent a18f043 commit c24148e

File tree

3 files changed

+4
-43
lines changed

3 files changed

+4
-43
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11891189
let sig = self
11901190
.at(cause, self.param_env)
11911191
.trace(prev_ty, new_ty)
1192-
.lub(DefineOpaqueTypes::No, a_sig, b_sig)
1192+
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
11931193
.map(|ok| self.register_infer_ok_obligations(ok))?;
11941194

11951195
// Reify both sides and return the reified fn pointer type.

tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type J = impl Sized;
3434
fn j(a: J) {
3535
let x = match true {
3636
true => bar::<J>,
37-
false => foo::<()>, //~ ERROR: incompatible types
37+
false => foo::<()>,
3838
};
3939
x(a);
4040
x(());
@@ -49,7 +49,7 @@ fn k() -> impl Sized {
4949
let f = foo;
5050
bind(k(), f)
5151
}
52-
false => bar::<()>, //~ ERROR: incompatible types
52+
false => bar::<()>,
5353
};
5454
todo!()
5555
}

tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr

+1-40
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,6 @@ help: use parentheses to call this function
3333
LL | x = foo::<I>(/* I */);
3434
| +++++++++
3535

36-
error[E0308]: `match` arms have incompatible types
37-
--> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:37:18
38-
|
39-
LL | type J = impl Sized;
40-
| ---------- the expected opaque type
41-
...
42-
LL | let x = match true {
43-
| _____________-
44-
LL | | true => bar::<J>,
45-
| | -------- this is found to be of type `fn(J) -> J {bar::<J>}`
46-
LL | | false => foo::<()>,
47-
| | ^^^^^^^^^ expected opaque type, found `()`
48-
LL | | };
49-
| |_____- `match` arms have incompatible types
50-
|
51-
= note: expected fn item `fn(J) -> J {bar::<J>}`
52-
found fn item `fn(()) {foo::<()>}`
53-
54-
error[E0308]: `match` arms have incompatible types
55-
--> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:52:18
56-
|
57-
LL | fn k() -> impl Sized {
58-
| ---------- the expected opaque type
59-
...
60-
LL | let x = match true {
61-
| _____________-
62-
LL | | true => {
63-
LL | | let f = foo;
64-
LL | | bind(k(), f)
65-
| | ------------ this is found to be of type `fn(impl Sized) -> impl Sized {foo::<impl Sized>}`
66-
LL | | }
67-
LL | | false => bar::<()>,
68-
| | ^^^^^^^^^ expected opaque type, found `()`
69-
LL | | };
70-
| |_____- `match` arms have incompatible types
71-
|
72-
= note: expected fn item `fn(impl Sized) -> impl Sized {foo::<impl Sized>}`
73-
found fn item `fn(()) {bar::<()>}`
74-
75-
error: aborting due to 4 previous errors
36+
error: aborting due to 2 previous errors
7637

7738
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)