-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Point at original span when emitting unreachable lint #64592
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
Changes from 2 commits
822393d
cd4b468
9e777eb
6edcfbe
a8ce93e
41e1128
034a8fd
d67528f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
|
||
// If there are no arms, that is a diverging match; a special case. | ||
if arms.is_empty() { | ||
self.diverges.set(self.diverges.get() | Diverges::Always); | ||
self.diverges.set(self.diverges.get() | Diverges::Always { | ||
span: expr.span, | ||
custom_note: None | ||
}); | ||
return tcx.types.never; | ||
} | ||
|
||
|
@@ -69,7 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
// warnings). | ||
match all_pats_diverge { | ||
Diverges::Maybe => Diverges::Maybe, | ||
Diverges::Always | Diverges::WarnedAlways => Diverges::WarnedAlways, | ||
Diverges::Always { .. } | Diverges::WarnedAlways => Diverges::WarnedAlways, | ||
} | ||
}).collect(); | ||
|
||
|
@@ -167,6 +170,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
prior_arm_ty = Some(arm_ty); | ||
} | ||
|
||
// If all of the arms in the 'match' diverge, | ||
Aaron1011 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// and we're dealing with an actual 'match' block | ||
Aaron1011 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// (as opposed to a 'match' desugared from something else'), | ||
Aaron1011 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// we can emit a better note. Rather than pointing | ||
// at a diverging expression in an arbitrary arm, | ||
// we can point at the entire 'match' expression | ||
Aaron1011 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
match (all_arms_diverge, match_src) { | ||
Centril marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(Diverges::Always { .. }, hir::MatchSource::Normal) => { | ||
all_arms_diverge = Diverges::Always { | ||
span: expr.span, | ||
custom_note: Some( | ||
"any code following this `match` expression is unreachable, \ | ||
as all arms diverge" | ||
) | ||
}; | ||
}, | ||
_ => {} | ||
} | ||
|
||
// We won't diverge unless the discriminant or all arms diverge. | ||
self.diverges.set(discrim_diverges | all_arms_diverge); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this + the new bit above be refactored into a method? (I'd like to avoid too much non-spec logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such a method would need to take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well... it depends on what you intend to read. If you are writing text for the reference or auditing the reviewing of the language you don't care about Rustfmt would display the following on a single line: fn f1() {
impl I {
fn f2() {
self.set_diverges_match(expr, match_src, discrim_diverges, all_arms_diverge);
}
}
} |
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.