1
Fork 0

Rollup merge of #129344 - compiler-errors:less-option-unit-diagnostics, r=jieyouxu

Use `bool` in favor of `Option<()>` for diagnostics

We originally only supported `Option<()>` for optional notes/labels, but we now support `bool`. Let's use that, since it usually leads to more readable code.

I'm not removing the support from the derive macro, though I guess we could error on it... 🤔
This commit is contained in:
Matthias Krüger 2024-08-21 18:15:05 +02:00 committed by GitHub
commit 937a18daf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 106 additions and 121 deletions

View file

@ -793,7 +793,7 @@ impl UnsafeOpKind {
missing.iter().map(|feature| Cow::from(feature.to_string())).collect(),
),
missing_target_features_count: missing.len(),
note: if build_enabled.is_empty() { None } else { Some(()) },
note: !build_enabled.is_empty(),
build_target_features: DiagArgValue::StrListSepByAnd(
build_enabled
.iter()
@ -958,7 +958,7 @@ impl UnsafeOpKind {
missing.iter().map(|feature| Cow::from(feature.to_string())).collect(),
),
missing_target_features_count: missing.len(),
note: if build_enabled.is_empty() { None } else { Some(()) },
note: !build_enabled.is_empty(),
build_target_features: DiagArgValue::StrListSepByAnd(
build_enabled
.iter()
@ -977,7 +977,7 @@ impl UnsafeOpKind {
missing.iter().map(|feature| Cow::from(feature.to_string())).collect(),
),
missing_target_features_count: missing.len(),
note: if build_enabled.is_empty() { None } else { Some(()) },
note: !build_enabled.is_empty(),
build_target_features: DiagArgValue::StrListSepByAnd(
build_enabled
.iter()

View file

@ -161,7 +161,7 @@ pub(crate) struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe {
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) note: bool,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
@ -413,7 +413,7 @@ pub(crate) struct CallToFunctionWithRequiresUnsafe {
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) note: bool,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
@ -431,7 +431,7 @@ pub(crate) struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) note: bool,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
@ -621,7 +621,7 @@ pub(crate) struct LowerRangeBoundMustBeLessThanOrEqualToUpper {
#[label]
pub(crate) span: Span,
#[note(mir_build_teach_note)]
pub(crate) teach: Option<()>,
pub(crate) teach: bool,
}
#[derive(Diagnostic)]
@ -863,7 +863,7 @@ pub(crate) struct PatternNotCovered<'s, 'tcx> {
#[subdiagnostic]
pub(crate) adt_defined_here: Option<AdtDefinedHere<'tcx>>,
#[note(mir_build_privately_uninhabited)]
pub(crate) witness_1_is_privately_uninhabited: Option<()>,
pub(crate) witness_1_is_privately_uninhabited: bool,
#[note(mir_build_pattern_ty)]
pub(crate) _p: (),
pub(crate) pattern_ty: Ty<'tcx>,

View file

@ -718,7 +718,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
uncovered: Uncovered::new(pat.span, &cx, witnesses),
inform,
interpreted_as_const,
witness_1_is_privately_uninhabited: witness_1_is_privately_uninhabited.then_some(()),
witness_1_is_privately_uninhabited,
_p: (),
pattern_ty,
let_suggestion,

View file

@ -256,7 +256,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
RangeEnd::Included => {
self.tcx.dcx().emit_err(LowerRangeBoundMustBeLessThanOrEqualToUpper {
span,
teach: self.tcx.sess.teach(E0030).then_some(()),
teach: self.tcx.sess.teach(E0030),
})
}
RangeEnd::Excluded => {