Add rustc_never_type_mode = "no_fallback"

This commit is contained in:
Maybe Waffle 2024-03-15 14:50:45 +00:00
parent 19bc337063
commit adfdd273ae
3 changed files with 18 additions and 3 deletions

View File

@ -581,7 +581,7 @@ pub struct BuiltinAttribute {
), ),
rustc_attr!( rustc_attr!(
rustc_never_type_mode, Normal, template!(NameValueStr: "fallback_to_unit|fallback_to_niko|no_fallback"), ErrorFollowing, rustc_never_type_mode, Normal, template!(NameValueStr: "fallback_to_unit|fallback_to_niko|fallback_to_never|no_fallback"), ErrorFollowing,
@only_local: true, @only_local: true,
"`rustc_never_type_fallback` is used to experiment with never type fallback and work on \ "`rustc_never_type_fallback` is used to experiment with never type fallback and work on \
never type stabilization, and will never be stable" never type stabilization, and will never be stable"

View File

@ -14,6 +14,9 @@ enum DivergingFallbackBehavior {
FallbackToUnit, FallbackToUnit,
/// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken. /// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken.
FallbackToNiko, FallbackToNiko,
/// Always fallback to `!` (which should be equivalent to never falling back + not making
/// never-to-any coercions unless necessary)
FallbackToNever,
/// Don't fallback at all /// Don't fallback at all
NoFallback, NoFallback,
} }
@ -107,9 +110,10 @@ fn diverging_fallback_behavior(&self) -> DivergingFallbackBehavior {
match mode { match mode {
sym::fallback_to_unit => DivergingFallbackBehavior::FallbackToUnit, sym::fallback_to_unit => DivergingFallbackBehavior::FallbackToUnit,
sym::fallback_to_niko => DivergingFallbackBehavior::FallbackToNiko, sym::fallback_to_niko => DivergingFallbackBehavior::FallbackToNiko,
sym::fallback_to_never => DivergingFallbackBehavior::FallbackToNever,
sym::no_fallback => DivergingFallbackBehavior::NoFallback, sym::no_fallback => DivergingFallbackBehavior::NoFallback,
_ => { _ => {
self.tcx.dcx().span_err(span, format!("unknown never type mode: `{mode}` (supported: `fallback_to_unit`, `fallback_to_niko`, and `no_fallback`)")); self.tcx.dcx().span_err(span, format!("unknown never type mode: `{mode}` (supported: `fallback_to_unit`, `fallback_to_niko`, `fallback_to_never` and `no_fallback`)"));
DivergingFallbackBehavior::FallbackToUnit DivergingFallbackBehavior::FallbackToUnit
} }
@ -426,8 +430,18 @@ fn calculate_diverging_fallback(
diverging_fallback.insert(diverging_ty, self.tcx.types.never); diverging_fallback.insert(diverging_ty, self.tcx.types.never);
} }
} }
FallbackToNever => {
debug!(
"fallback to ! - `rustc_never_type_mode = \"fallback_to_never\")`: {:?}",
diverging_vid
);
diverging_fallback.insert(diverging_ty, self.tcx.types.never);
}
NoFallback => { NoFallback => {
debug!("no fallback - `rustc_never_type_mode = "no_fallback"`: {:?}", diverging_vid); debug!(
"no fallback - `rustc_never_type_mode = \"no_fallback\"`: {:?}",
diverging_vid
);
} }
} }
} }

View File

@ -815,6 +815,7 @@
fadd_algebraic, fadd_algebraic,
fadd_fast, fadd_fast,
fake_variadic, fake_variadic,
fallback_to_never,
fallback_to_niko, fallback_to_niko,
fallback_to_unit, fallback_to_unit,
fdiv_algebraic, fdiv_algebraic,