Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
exprs.len()
);

if prev_ty == new_ty {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment here referencing #88097 and coercion of a closure to itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it; fixed now.

return Ok(prev_ty);
}

// Special-case that coercion alone cannot handle:
// Function items or non-capturing closures of differing IDs or InternalSubsts.
let (a_sig, b_sig) = {
Expand Down
31 changes: 31 additions & 0 deletions src/test/ui/coercion/issue-88097.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// In #88097, the compiler attempted to coerce a closure type to itself via
// a function pointer, which caused an unnecessary error. Check that this
// behavior has been fixed.

// check-pass

fn peculiar() -> impl Fn(u8) -> u8 {
return |x| x + 1
}

fn peculiar2() -> impl Fn(u8) -> u8 {
return |x| x + 1;
}

fn peculiar3() -> impl Fn(u8) -> u8 {
let f = |x| x + 1;
return f
}

fn peculiar4() -> impl Fn(u8) -> u8 {
let f = |x| x + 1;
f
}

fn peculiar5() -> impl Fn(u8) -> u8 {
let f = |x| x + 1;
let g = |x| x + 2;
return if true { f } else { g }
}

fn main() {}