Skip to content

"incompatible arm" diagnostic span tweak #46956

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 1 commit into from
Dec 26, 2017
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
14 changes: 12 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
match cause.code {
ObligationCauseCode::MatchExpressionArm { arm_span, source } => match source {
hir::MatchSource::IfLetDesugar {..} => {
err.span_note(arm_span, "`if let` arm with an incompatible type");
let msg = "`if let` arm with an incompatible type";
if self.tcx.sess.codemap().is_multiline(arm_span) {
err.span_note(arm_span, msg);
} else {
err.span_label(arm_span, msg);
}
}
_ => {
err.span_note(arm_span, "match arm with an incompatible type");
let msg = "match arm with an incompatible type";
if self.tcx.sess.codemap().is_multiline(arm_span) {
err.span_note(arm_span, msg);
} else {
err.span_label(arm_span, msg);
}
}
},
_ => ()
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ impl CodeMap {
.expect("CodeMap::span_to_unmapped_path called for imported FileMap?")
}

pub fn is_multiline(&self, sp: Span) -> bool {
let lo = self.lookup_char_pos(sp.lo());
let hi = self.lookup_char_pos(sp.hi());
lo.line != hi.line
}

pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
debug!("span_to_lines(sp={:?})", sp);

Expand Down
7 changes: 2 additions & 5 deletions src/test/ui/issue-11319.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ error[E0308]: match arms have incompatible types
14 | | //~| expected type `bool`
15 | | //~| found type `()`
... |
19 | | None => (),
| | -- match arm with an incompatible type
20 | | _ => true
21 | | }
| |_____^ expected bool, found ()
|
= note: expected type `bool`
found type `()`
note: match arm with an incompatible type
--> $DIR/issue-11319.rs:19:20
|
19 | None => (),
| ^^

error: aborting due to previous error

6 changes: 1 addition & 5 deletions src/test/ui/issue-24036.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ error[E0308]: match arms have incompatible types
19 | | //~^ ERROR match arms have incompatible types
20 | | 1 => |c| c + 1,
21 | | 2 => |c| c - 1,
| | --------- match arm with an incompatible type
22 | | _ => |c| c - 1
23 | | };
| |_____^ expected closure, found a different closure
Expand All @@ -25,11 +26,6 @@ error[E0308]: match arms have incompatible types
found type `[closure@$DIR/issue-24036.rs:21:14: 21:23]`
= note: no two closures, even if identical, have the same type
= help: consider boxing your closure and/or using it as a trait object
note: match arm with an incompatible type
--> $DIR/issue-24036.rs:21:14
|
21 | 2 => |c| c - 1,
| ^^^^^^^^^

error: aborting due to 2 previous errors

6 changes: 1 addition & 5 deletions src/test/ui/lub-glb/old-lub-glb-hr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ error[E0308]: match arms have incompatible types
| _____________^
19 | | 0 => x,
20 | | _ => y,
| | - match arm with an incompatible type
21 | | };
| |_____^ expected bound lifetime parameter, found concrete lifetime
|
= note: expected type `for<'r, 's> fn(&'r u8, &'s u8)`
found type `for<'a> fn(&'a u8, &'a u8)`
= note: this was previously accepted by the compiler but has been phased out
= note: for more information, see https://github.com/rust-lang/rust/issues/45852
note: match arm with an incompatible type
--> $DIR/old-lub-glb-hr.rs:20:14
|
20 | _ => y,
| ^

error: aborting due to previous error

6 changes: 1 addition & 5 deletions src/test/ui/lub-glb/old-lub-glb-object.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ error[E0308]: match arms have incompatible types
| _____________^
21 | | 0 => x,
22 | | _ => y,
| | - match arm with an incompatible type
23 | | };
| |_____^ expected bound lifetime parameter 'a, found concrete lifetime
|
= note: expected type `&for<'a, 'b> Foo<&'a u8, &'b u8>`
found type `&for<'a> Foo<&'a u8, &'a u8>`
= note: this was previously accepted by the compiler but has been phased out
= note: for more information, see https://github.com/rust-lang/rust/issues/45852
note: match arm with an incompatible type
--> $DIR/old-lub-glb-object.rs:22:14
|
22 | _ => y,
| ^

error: aborting due to previous error