Skip to content

Commit 3350ae9

Browse files
authored
Rollup merge of #105882 - compiler-errors:issue-105832, r=jackh726
Don't ICE in closure arg borrow suggestion Fixes #105832
2 parents a9005b6 + dd8897e commit 3350ae9

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
17891789
self.note_conflicting_closure_bounds(cause, &mut err);
17901790

17911791
if let Some(found_node) = found_node {
1792-
hint_missing_borrow(span, found_span, found, expected, found_node, &mut err);
1792+
hint_missing_borrow(span, found, expected, found_node, &mut err);
17931793
}
17941794

17951795
err
@@ -3460,7 +3460,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
34603460
/// Add a hint to add a missing borrow or remove an unnecessary one.
34613461
fn hint_missing_borrow<'tcx>(
34623462
span: Span,
3463-
found_span: Span,
34643463
found: Ty<'tcx>,
34653464
expected: Ty<'tcx>,
34663465
found_node: Node<'_>,
@@ -3479,9 +3478,8 @@ fn hint_missing_borrow<'tcx>(
34793478
}
34803479
};
34813480

3482-
let fn_decl = found_node
3483-
.fn_decl()
3484-
.unwrap_or_else(|| span_bug!(found_span, "found node must be a function"));
3481+
// This could be a variant constructor, for example.
3482+
let Some(fn_decl) = found_node.fn_decl() else { return; };
34853483

34863484
let arg_spans = fn_decl.inputs.iter().map(|ty| ty.span);
34873485

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub enum Sexpr<'a> {
2+
Ident(&'a str),
3+
}
4+
5+
fn map<'a, F: Fn(String) -> Sexpr<'a>>(f: F) {}
6+
7+
fn main() {
8+
map(Sexpr::Ident);
9+
//~^ ERROR type mismatch in function arguments
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0631]: type mismatch in function arguments
2+
--> $DIR/enum-variant-arg-mismatch.rs:8:9
3+
|
4+
LL | Ident(&'a str),
5+
| ----- found signature defined here
6+
...
7+
LL | map(Sexpr::Ident);
8+
| --- ^^^^^^^^^^^^ expected due to this
9+
| |
10+
| required by a bound introduced by this call
11+
|
12+
= note: expected function signature `fn(String) -> _`
13+
found function signature `fn(&str) -> _`
14+
note: required by a bound in `map`
15+
--> $DIR/enum-variant-arg-mismatch.rs:5:15
16+
|
17+
LL | fn map<'a, F: Fn(String) -> Sexpr<'a>>(f: F) {}
18+
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0631`.

0 commit comments

Comments
 (0)