Skip to content

Return equal for two identical projections #109433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2023
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
6 changes: 2 additions & 4 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

unreachable!(
"we captured two identical projections: capture1 = {:?}, capture2 = {:?}",
capture1, capture2
);
// return Equal for two identical projections
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like this could be a delay_span_bug instead? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I will make a change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I add delay_span_bug and also keep the std::cmp::Ordering::Equal so that we keep minimal change since we need to return Ordering type for the sort_by function.

std::cmp::Ordering::Equal
});
}

Expand Down
22 changes: 22 additions & 0 deletions tests/ui/closures/issue-109188.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
enum Either {
One(X),
Two(X),
}

struct X(Y);

struct Y;

fn consume_fnmut(f: &dyn FnMut()) {
f();
}

fn move_into_fnmut() {
let x = move_into_fnmut();
consume_fnmut(&|| {
let Either::One(_t) = x; //~ ERROR mismatched types
let Either::Two(_t) = x; //~ ERROR mismatched types
});
}

fn main() { }
19 changes: 19 additions & 0 deletions tests/ui/closures/issue-109188.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0308]: mismatched types
--> $DIR/issue-109188.rs:17:13
|
LL | let Either::One(_t) = x;
| ^^^^^^^^^^^^^^^ - this expression has type `()`
| |
| expected `()`, found `Either`

error[E0308]: mismatched types
--> $DIR/issue-109188.rs:18:13
|
LL | let Either::Two(_t) = x;
| ^^^^^^^^^^^^^^^ - this expression has type `()`
| |
| expected `()`, found `Either`

error: aborting due to 2 previous errors

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