Skip to content

Commit 8bcc87f

Browse files
committed
Fix ICE
1 parent 64d7e0d commit 8bcc87f

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21122112
&& !expected_inputs.is_empty()
21132113
&& expected_inputs.len() == found_inputs.len()
21142114
&& let Some(typeck) = &self.typeck_results
2115-
&& let Res::Def(_, fn_def_id) = typeck.qpath_res(&path, *arg_hir_id)
2115+
&& let Res::Def(res_kind, fn_def_id) = typeck.qpath_res(&path, *arg_hir_id)
2116+
&& res_kind.is_fn_like()
21162117
{
21172118
let closure: Vec<_> = self
21182119
.tcx
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub enum Sexpr<'a> {
2+
Ident(&'a mut S),
3+
//~^ ERROR cannot find type `S` in this scope [E0412]
4+
}
5+
6+
fn map<'a, F: FnOnce(&Foo<'a>) -> T>(f: F) {}
7+
//~^ ERROR cannot find type `Foo` in this scope [E0412]
8+
//~| ERROR cannot find type `T` in this scope [E0412]
9+
10+
fn main() {
11+
map(Sexpr::Ident);
12+
//~^ ERROR type mismatch in function arguments
13+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0412]: cannot find type `S` in this scope
2+
--> $DIR/issue-118510.rs:2:19
3+
|
4+
LL | Ident(&'a mut S),
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | pub enum Sexpr<'a, S> {
10+
| +++
11+
12+
error[E0412]: cannot find type `Foo` in this scope
13+
--> $DIR/issue-118510.rs:6:23
14+
|
15+
LL | fn map<'a, F: FnOnce(&Foo<'a>) -> T>(f: F) {}
16+
| ^^^ not found in this scope
17+
18+
error[E0412]: cannot find type `T` in this scope
19+
--> $DIR/issue-118510.rs:6:35
20+
|
21+
LL | fn map<'a, F: FnOnce(&Foo<'a>) -> T>(f: F) {}
22+
| - ^ help: a type parameter with a similar name exists: `F`
23+
| |
24+
| similarly named type parameter `F` defined here
25+
26+
error[E0631]: type mismatch in function arguments
27+
--> $DIR/issue-118510.rs:11:9
28+
|
29+
LL | Ident(&'a mut S),
30+
| ----- found signature defined here
31+
...
32+
LL | map(Sexpr::Ident);
33+
| --- ^^^^^^^^^^^^ expected due to this
34+
| |
35+
| required by a bound introduced by this call
36+
|
37+
= note: expected function signature `for<'a> fn(&'a {type error}) -> _`
38+
found function signature `fn(&mut {type error}) -> _`
39+
note: required by a bound in `map`
40+
--> $DIR/issue-118510.rs:6:15
41+
|
42+
LL | fn map<'a, F: FnOnce(&Foo<'a>) -> T>(f: F) {}
43+
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
44+
help: consider wrapping the function in a closure
45+
|
46+
LL | map(|arg0: &{type error}| Sexpr::Ident(&mut *arg0));
47+
| +++++++++++++++++++++ ++++++++++++
48+
49+
error: aborting due to 4 previous errors
50+
51+
Some errors have detailed explanations: E0412, E0631.
52+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)