Rename DivergingFallbackBehavior
variants and don't use ::*
This commit is contained in:
parent
0f63cd1056
commit
e79aafcaa8
@ -18,12 +18,12 @@
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum DivergingFallbackBehavior {
|
pub enum DivergingFallbackBehavior {
|
||||||
/// Always fallback to `()` (aka "always spontaneous decay")
|
/// Always fallback to `()` (aka "always spontaneous decay")
|
||||||
FallbackToUnit,
|
ToUnit,
|
||||||
/// 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,
|
ContextDependent,
|
||||||
/// Always fallback to `!` (which should be equivalent to never falling back + not making
|
/// Always fallback to `!` (which should be equivalent to never falling back + not making
|
||||||
/// never-to-any coercions unless necessary)
|
/// never-to-any coercions unless necessary)
|
||||||
FallbackToNever,
|
ToNever,
|
||||||
/// Don't fallback at all
|
/// Don't fallback at all
|
||||||
NoFallback,
|
NoFallback,
|
||||||
}
|
}
|
||||||
@ -403,13 +403,12 @@ fn calculate_diverging_fallback(
|
|||||||
diverging_fallback.insert(diverging_ty, ty);
|
diverging_fallback.insert(diverging_ty, ty);
|
||||||
};
|
};
|
||||||
|
|
||||||
use DivergingFallbackBehavior::*;
|
|
||||||
match behavior {
|
match behavior {
|
||||||
FallbackToUnit => {
|
DivergingFallbackBehavior::ToUnit => {
|
||||||
debug!("fallback to () - legacy: {:?}", diverging_vid);
|
debug!("fallback to () - legacy: {:?}", diverging_vid);
|
||||||
fallback_to(self.tcx.types.unit);
|
fallback_to(self.tcx.types.unit);
|
||||||
}
|
}
|
||||||
FallbackToNiko => {
|
DivergingFallbackBehavior::ContextDependent => {
|
||||||
if found_infer_var_info.self_in_trait && found_infer_var_info.output {
|
if found_infer_var_info.self_in_trait && found_infer_var_info.output {
|
||||||
// This case falls back to () to ensure that the code pattern in
|
// This case falls back to () to ensure that the code pattern in
|
||||||
// tests/ui/never_type/fallback-closure-ret.rs continues to
|
// tests/ui/never_type/fallback-closure-ret.rs continues to
|
||||||
@ -445,14 +444,14 @@ fn calculate_diverging_fallback(
|
|||||||
fallback_to(self.tcx.types.never);
|
fallback_to(self.tcx.types.never);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FallbackToNever => {
|
DivergingFallbackBehavior::ToNever => {
|
||||||
debug!(
|
debug!(
|
||||||
"fallback to ! - `rustc_never_type_mode = \"fallback_to_never\")`: {:?}",
|
"fallback to ! - `rustc_never_type_mode = \"fallback_to_never\")`: {:?}",
|
||||||
diverging_vid
|
diverging_vid
|
||||||
);
|
);
|
||||||
fallback_to(self.tcx.types.never);
|
fallback_to(self.tcx.types.never);
|
||||||
}
|
}
|
||||||
NoFallback => {
|
DivergingFallbackBehavior::NoFallback => {
|
||||||
debug!(
|
debug!(
|
||||||
"no fallback - `rustc_never_type_mode = \"no_fallback\"`: {:?}",
|
"no fallback - `rustc_never_type_mode = \"no_fallback\"`: {:?}",
|
||||||
diverging_vid
|
diverging_vid
|
||||||
|
@ -390,27 +390,23 @@ fn never_type_behavior(tcx: TyCtxt<'_>) -> (DivergingFallbackBehavior, Diverging
|
|||||||
|
|
||||||
/// Returns the default fallback which is used when there is no explicit override via `#![never_type_options(...)]`.
|
/// Returns the default fallback which is used when there is no explicit override via `#![never_type_options(...)]`.
|
||||||
fn default_fallback(tcx: TyCtxt<'_>) -> DivergingFallbackBehavior {
|
fn default_fallback(tcx: TyCtxt<'_>) -> DivergingFallbackBehavior {
|
||||||
use DivergingFallbackBehavior::*;
|
|
||||||
|
|
||||||
// Edition 2024: fallback to `!`
|
// Edition 2024: fallback to `!`
|
||||||
if tcx.sess.edition().at_least_rust_2024() {
|
if tcx.sess.edition().at_least_rust_2024() {
|
||||||
return FallbackToNever;
|
return DivergingFallbackBehavior::ToNever;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `feature(never_type_fallback)`: fallback to `!` or `()` trying to not break stuff
|
// `feature(never_type_fallback)`: fallback to `!` or `()` trying to not break stuff
|
||||||
if tcx.features().never_type_fallback {
|
if tcx.features().never_type_fallback {
|
||||||
return FallbackToNiko;
|
return DivergingFallbackBehavior::ContextDependent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise: fallback to `()`
|
// Otherwise: fallback to `()`
|
||||||
FallbackToUnit
|
DivergingFallbackBehavior::ToUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_never_type_options_attr(
|
fn parse_never_type_options_attr(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
) -> (Option<DivergingFallbackBehavior>, Option<DivergingBlockBehavior>) {
|
) -> (Option<DivergingFallbackBehavior>, Option<DivergingBlockBehavior>) {
|
||||||
use DivergingFallbackBehavior::*;
|
|
||||||
|
|
||||||
// Error handling is dubious here (unwraps), but that's probably fine for an internal attribute.
|
// Error handling is dubious here (unwraps), but that's probably fine for an internal attribute.
|
||||||
// Just don't write incorrect attributes <3
|
// Just don't write incorrect attributes <3
|
||||||
|
|
||||||
@ -426,10 +422,10 @@ fn parse_never_type_options_attr(
|
|||||||
if item.has_name(sym::fallback) && fallback.is_none() {
|
if item.has_name(sym::fallback) && fallback.is_none() {
|
||||||
let mode = item.value_str().unwrap();
|
let mode = item.value_str().unwrap();
|
||||||
match mode {
|
match mode {
|
||||||
sym::unit => fallback = Some(FallbackToUnit),
|
sym::unit => fallback = Some(DivergingFallbackBehavior::ToUnit),
|
||||||
sym::niko => fallback = Some(FallbackToNiko),
|
sym::niko => fallback = Some(DivergingFallbackBehavior::ContextDependent),
|
||||||
sym::never => fallback = Some(FallbackToNever),
|
sym::never => fallback = Some(DivergingFallbackBehavior::ToNever),
|
||||||
sym::no => fallback = Some(NoFallback),
|
sym::no => fallback = Some(DivergingFallbackBehavior::NoFallback),
|
||||||
_ => {
|
_ => {
|
||||||
tcx.dcx().span_err(item.span(), format!("unknown never type fallback mode: `{mode}` (supported: `unit`, `niko`, `never` and `no`)"));
|
tcx.dcx().span_err(item.span(), format!("unknown never type fallback mode: `{mode}` (supported: `unit`, `niko`, `never` and `no`)"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user