From a8ce93e13a9f1e7d7933ca76f6cae9c8f6127c34 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 18 Sep 2019 20:04:01 -0400 Subject: [PATCH] Introduce Diverges::always constructor Rename the existing Diverges.always method to Diverges.is_always --- src/librustc_typeck/check/_match.rs | 7 ++----- src/librustc_typeck/check/expr.rs | 5 +---- src/librustc_typeck/check/mod.rs | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 034cba0f12a..9481638fc14 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -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", diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 5733b8d1db1..049f2eb16bb 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -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. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e424aa67908..410eef5e092 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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