Skip to content

Commit

Permalink
Introduce Diverges::always constructor
Browse files Browse the repository at this point in the history
Rename the existing Diverges.always method to Diverges.is_always
  • Loading branch information
Aaron1011 committed Sep 19, 2019
1 parent 6edcfbe commit a8ce93e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
7 changes: 2 additions & 5 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_typeck/check/expr.rs
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a8ce93e

Please sign in to comment.