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_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,
"`rustc_never_type_fallback` is used to experiment with never type fallback and work on \
never type stabilization, and will never be stable"

View File

@ -14,6 +14,9 @@ enum DivergingFallbackBehavior {
FallbackToUnit,
/// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken.
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
NoFallback,
}
@ -107,9 +110,10 @@ fn diverging_fallback_behavior(&self) -> DivergingFallbackBehavior {
match mode {
sym::fallback_to_unit => DivergingFallbackBehavior::FallbackToUnit,
sym::fallback_to_niko => DivergingFallbackBehavior::FallbackToNiko,
sym::fallback_to_never => DivergingFallbackBehavior::FallbackToNever,
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
}
@ -426,8 +430,18 @@ fn calculate_diverging_fallback(
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 => {
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_fast,
fake_variadic,
fallback_to_never,
fallback_to_niko,
fallback_to_unit,
fdiv_algebraic,