Skip to content

Commit 779b684

Browse files
committed
Rename DivergingFallbackBehavior variants and don't use ::*
1 parent dc8297a commit 779b684

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use rustc_middle::ty::{self, Ty};
1010
#[derive(Copy, Clone)]
1111
pub enum DivergingFallbackBehavior {
1212
/// Always fallback to `()` (aka "always spontaneous decay")
13-
FallbackToUnit,
13+
ToUnit,
1414
/// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken.
15-
FallbackToNiko,
15+
ContextDependent,
1616
/// Always fallback to `!` (which should be equivalent to never falling back + not making
1717
/// never-to-any coercions unless necessary)
18-
FallbackToNever,
18+
ToNever,
1919
/// Don't fallback at all
2020
NoFallback,
2121
}
@@ -359,13 +359,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
359359
output: infer_var_infos.items().any(|info| info.output),
360360
};
361361

362-
use DivergingFallbackBehavior::*;
363362
match behavior {
364-
FallbackToUnit => {
363+
DivergingFallbackBehavior::ToUnit => {
365364
debug!("fallback to () - legacy: {:?}", diverging_vid);
366365
diverging_fallback.insert(diverging_ty, self.tcx.types.unit);
367366
}
368-
FallbackToNiko => {
367+
DivergingFallbackBehavior::ContextDependent => {
369368
if found_infer_var_info.self_in_trait && found_infer_var_info.output {
370369
// This case falls back to () to ensure that the code pattern in
371370
// tests/ui/never_type/fallback-closure-ret.rs continues to
@@ -401,14 +400,14 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
401400
diverging_fallback.insert(diverging_ty, self.tcx.types.never);
402401
}
403402
}
404-
FallbackToNever => {
403+
DivergingFallbackBehavior::ToNever => {
405404
debug!(
406405
"fallback to ! - `rustc_never_type_mode = \"fallback_to_never\")`: {:?}",
407406
diverging_vid
408407
);
409408
diverging_fallback.insert(diverging_ty, self.tcx.types.never);
410409
}
411-
NoFallback => {
410+
DivergingFallbackBehavior::NoFallback => {
412411
debug!(
413412
"no fallback - `rustc_never_type_mode = \"no_fallback\"`: {:?}",
414413
diverging_vid

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -395,27 +395,23 @@ fn never_type_behavior(tcx: TyCtxt<'_>) -> (DivergingFallbackBehavior, Diverging
395395

396396
/// Returns the default fallback which is used when there is no explicit override via `#![never_type_options(...)]`.
397397
fn default_fallback(tcx: TyCtxt<'_>) -> DivergingFallbackBehavior {
398-
use DivergingFallbackBehavior::*;
399-
400398
// Edition 2024: fallback to `!`
401399
if tcx.sess.edition().at_least_rust_2024() {
402-
return FallbackToNever;
400+
return DivergingFallbackBehavior::ToNever;
403401
}
404402

405403
// `feature(never_type_fallback)`: fallback to `!` or `()` trying to not break stuff
406404
if tcx.features().never_type_fallback {
407-
return FallbackToNiko;
405+
return DivergingFallbackBehavior::ContextDependent;
408406
}
409407

410408
// Otherwise: fallback to `()`
411-
FallbackToUnit
409+
DivergingFallbackBehavior::ToUnit
412410
}
413411

414412
fn parse_never_type_options_attr(
415413
tcx: TyCtxt<'_>,
416414
) -> (Option<DivergingFallbackBehavior>, Option<DivergingBlockBehavior>) {
417-
use DivergingFallbackBehavior::*;
418-
419415
// Error handling is dubious here (unwraps), but that's probably fine for an internal attribute.
420416
// Just don't write incorrect attributes <3
421417

@@ -431,10 +427,10 @@ fn parse_never_type_options_attr(
431427
if item.has_name(sym::fallback) && fallback.is_none() {
432428
let mode = item.value_str().unwrap();
433429
match mode {
434-
sym::unit => fallback = Some(FallbackToUnit),
435-
sym::niko => fallback = Some(FallbackToNiko),
436-
sym::never => fallback = Some(FallbackToNever),
437-
sym::no => fallback = Some(NoFallback),
430+
sym::unit => fallback = Some(DivergingFallbackBehavior::ToUnit),
431+
sym::niko => fallback = Some(DivergingFallbackBehavior::ContextDependent),
432+
sym::never => fallback = Some(DivergingFallbackBehavior::ToNever),
433+
sym::no => fallback = Some(DivergingFallbackBehavior::NoFallback),
438434
_ => {
439435
tcx.dcx().span_err(item.span(), format!("unknown never type fallback mode: `{mode}` (supported: `unit`, `niko`, `never` and `no`)"));
440436
}

0 commit comments

Comments
 (0)