Introduce Diverges::always constructor

Rename the existing Diverges.always method to Diverges.is_always
This commit is contained in:
Aaron Hill 2019-09-18 20:04:01 -04:00
parent 6edcfbe59a
commit a8ce93e13a
No known key found for this signature in database
GPG key ID: B4087E510E98B164
3 changed files with 15 additions and 11 deletions

View file

@ -43,10 +43,7 @@ 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 {
span: expr.span,
custom_note: None
});
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
return tcx.types.never;
}
@ -198,7 +195,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// When the previously checked expression (the scrutinee) diverges,
/// warn the user about the match arms being unreachable.
fn warn_arms_when_scrutinee_diverges(&self, arms: &'tcx [hir::Arm], source: hir::MatchSource) {
if self.diverges.get().always() {
if self.diverges.get().is_always() {
use hir::MatchSource::*;
let msg = match source {
IfDesugar { .. } | IfLetDesugar { .. } => "block in `if` expression",

View file

@ -170,10 +170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Any expression that produces a value of type `!` must have diverged
if ty.is_never() {
self.diverges.set(self.diverges.get() | Diverges::Always {
span: expr.span,
custom_note: None
});
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
}
// Record the type, which applies it effects.

View file

@ -470,6 +470,16 @@ pub enum Diverges {
WarnedAlways
}
impl Diverges {
/// Creates a `Diverges::Always` with the provided span and the default note message
fn always(span: Span) -> Diverges {
Diverges::Always {
span,
custom_note: None
}
}
}
// Convenience impls for combinig `Diverges`.
impl ops::BitAnd for Diverges {
@ -499,7 +509,7 @@ impl ops::BitOrAssign for Diverges {
}
impl Diverges {
fn always(self) -> bool {
fn is_always(self) -> bool {
// Enum comparison ignores the
// contents of fields, so we just
// fill them in with garbage here.
@ -3852,7 +3862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
//
// #41425 -- label the implicit `()` as being the
// "found type" here, rather than the "expected type".
if !self.diverges.get().always() {
if !self.diverges.get().is_always() {
// #50009 -- Do not point at the entire fn block span, point at the return type
// span, as it is the cause of the requirement, and
// `consider_hint_about_removing_semicolon` will point at the last expression