Skip to content

Commit 43fee0e

Browse files
authored
Rollup merge of #90646 - BoxyUwU:funky_ice, r=estebank
type error go brrrrrrrr Fixes #90444 when we relate something like: `fn(fn((), (), u32))` with `fn(fn((), (), ()))` we relate the inner fn ptrs: `fn((), (), u32)` with `fn((), (), ())` yielding a `TypeError::ArgumentSorts(_, 2)` which we then use as the `TypeError` for the `fn(fn(..))` which later causes the ICE as the `2` does not correspond to any input or output types in `fn(_)` r? `@estebank`
2 parents 5f0e6ca + abb9a98 commit 43fee0e

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

compiler/rustc_middle/src/ty/relate.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
187187
})
188188
.enumerate()
189189
.map(|(i, r)| match r {
190-
Err(TypeError::Sorts(exp_found)) => Err(TypeError::ArgumentSorts(exp_found, i)),
191-
Err(TypeError::Mutability) => Err(TypeError::ArgumentMutability(i)),
190+
Err(TypeError::Sorts(exp_found) | TypeError::ArgumentSorts(exp_found, _)) => {
191+
Err(TypeError::ArgumentSorts(exp_found, i))
192+
}
193+
Err(TypeError::Mutability | TypeError::ArgumentMutability(_)) => {
194+
Err(TypeError::ArgumentMutability(i))
195+
}
192196
r => r,
193197
});
194198
Ok(ty::FnSig {

compiler/rustc_typeck/src/check/compare_method.rs

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
453453
Ok(())
454454
}
455455

456+
#[instrument(level = "debug", skip(infcx))]
456457
fn extract_spans_for_error_reporting<'a, 'tcx>(
457458
infcx: &infer::InferCtxt<'a, 'tcx>,
458459
terr: &TypeError<'_>,
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub struct A;
2+
impl From<fn((), (), &())> for A {
3+
fn from(_: fn((), (), &mut ())) -> Self {
4+
//~^ error: method `from` has an incompatible type for trait
5+
loop {}
6+
}
7+
}
8+
9+
pub struct B;
10+
impl From<fn((), (), u32)> for B {
11+
fn from(_: fn((), (), u64)) -> Self {
12+
//~^ error: method `from` has an incompatible type for trait
13+
loop {}
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0053]: method `from` has an incompatible type for trait
2+
--> $DIR/issue-90444.rs:3:16
3+
|
4+
LL | fn from(_: fn((), (), &mut ())) -> Self {
5+
| ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| types differ in mutability
8+
| help: change the parameter type to match the trait: `for<'r> fn((), (), &'r ())`
9+
|
10+
= note: expected fn pointer `fn(for<'r> fn((), (), &'r ())) -> A`
11+
found fn pointer `fn(for<'r> fn((), (), &'r mut ())) -> A`
12+
13+
error[E0053]: method `from` has an incompatible type for trait
14+
--> $DIR/issue-90444.rs:11:16
15+
|
16+
LL | fn from(_: fn((), (), u64)) -> Self {
17+
| ^^^^^^^^^^^^^^^
18+
| |
19+
| expected `u32`, found `u64`
20+
| help: change the parameter type to match the trait: `fn((), (), u32)`
21+
|
22+
= note: expected fn pointer `fn(fn((), (), u32)) -> B`
23+
found fn pointer `fn(fn((), (), u64)) -> B`
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)