Skip to content
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

Account for match expr in single line #105347

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
format!("this and all prior arms are found to be of type `{}`", t),
);
}
let outer_error_span = if any_multiline_arm {
let outer = if any_multiline_arm || !source_map.is_multiline(cause.span) {
// Cover just `match` and the scrutinee expression, not
// the entire match body, to reduce diagram noise.
cause.span.shrink_to_lo().to(scrut_span)
} else {
cause.span
};
let msg = "`match` arms have incompatible types";
err.span_label(outer_error_span, msg);
err.span_label(outer, msg);
self.suggest_remove_semi_or_return_binding(
err,
prior_arm_block_id,
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/match/single-line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let _ = match Some(42) { Some(x) => x, None => "" }; //~ ERROR E0308
}
12 changes: 12 additions & 0 deletions src/test/ui/match/single-line.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: `match` arms have incompatible types
--> $DIR/single-line.rs:2:52
|
LL | let _ = match Some(42) { Some(x) => x, None => "" };
| -------------- - ^^ expected integer, found `&str`
| | |
| | this is found to be of type `{integer}`
| `match` arms have incompatible types

error: aborting due to previous error

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