Skip to content

Commit a8ce93e

Browse files
committed
Introduce Diverges::always constructor
Rename the existing Diverges.always method to Diverges.is_always
1 parent 6edcfbe commit a8ce93e

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4343

4444
// If there are no arms, that is a diverging match; a special case.
4545
if arms.is_empty() {
46-
self.diverges.set(self.diverges.get() | Diverges::Always {
47-
span: expr.span,
48-
custom_note: None
49-
});
46+
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
5047
return tcx.types.never;
5148
}
5249

@@ -198,7 +195,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198195
/// When the previously checked expression (the scrutinee) diverges,
199196
/// warn the user about the match arms being unreachable.
200197
fn warn_arms_when_scrutinee_diverges(&self, arms: &'tcx [hir::Arm], source: hir::MatchSource) {
201-
if self.diverges.get().always() {
198+
if self.diverges.get().is_always() {
202199
use hir::MatchSource::*;
203200
let msg = match source {
204201
IfDesugar { .. } | IfLetDesugar { .. } => "block in `if` expression",

src/librustc_typeck/check/expr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
170170

171171
// Any expression that produces a value of type `!` must have diverged
172172
if ty.is_never() {
173-
self.diverges.set(self.diverges.get() | Diverges::Always {
174-
span: expr.span,
175-
custom_note: None
176-
});
173+
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
177174
}
178175

179176
// Record the type, which applies it effects.

src/librustc_typeck/check/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ pub enum Diverges {
470470
WarnedAlways
471471
}
472472

473+
impl Diverges {
474+
/// Creates a `Diverges::Always` with the provided span and the default note message
475+
fn always(span: Span) -> Diverges {
476+
Diverges::Always {
477+
span,
478+
custom_note: None
479+
}
480+
}
481+
}
482+
473483
// Convenience impls for combinig `Diverges`.
474484

475485
impl ops::BitAnd for Diverges {
@@ -499,7 +509,7 @@ impl ops::BitOrAssign for Diverges {
499509
}
500510

501511
impl Diverges {
502-
fn always(self) -> bool {
512+
fn is_always(self) -> bool {
503513
// Enum comparison ignores the
504514
// contents of fields, so we just
505515
// fill them in with garbage here.
@@ -3852,7 +3862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38523862
//
38533863
// #41425 -- label the implicit `()` as being the
38543864
// "found type" here, rather than the "expected type".
3855-
if !self.diverges.get().always() {
3865+
if !self.diverges.get().is_always() {
38563866
// #50009 -- Do not point at the entire fn block span, point at the return type
38573867
// span, as it is the cause of the requirement, and
38583868
// `consider_hint_about_removing_semicolon` will point at the last expression

0 commit comments

Comments
 (0)