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

This commit is contained in:
Michael Goulet 2024-08-21 00:57:58 -04:00
parent 4d5b3b1962
commit 25ff9b6bcb
48 changed files with 106 additions and 121 deletions

View file

@ -913,7 +913,7 @@ pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
#[help(parse_tuple_exception_line_1)]
#[help(parse_tuple_exception_line_2)]
#[help(parse_tuple_exception_line_3)]
pub exception: Option<()>,
pub exception: bool,
}
#[derive(Diagnostic)]
@ -1299,7 +1299,7 @@ pub(crate) struct ComparisonOperatorsCannotBeChained {
pub suggest_turbofish: Option<Span>,
#[help(parse_sugg_turbofish_syntax)]
#[help(parse_sugg_parentheses_for_function_args)]
pub help_turbofish: Option<()>,
pub help_turbofish: bool,
#[subdiagnostic]
pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
}
@ -1578,7 +1578,7 @@ pub(crate) struct PathSingleColon {
pub suggestion: Span,
#[note(parse_type_ascription_removed)]
pub type_ascription: Option<()>,
pub type_ascription: bool,
}
#[derive(Diagnostic)]
@ -1589,7 +1589,7 @@ pub(crate) struct ColonAsSemi {
pub span: Span,
#[note(parse_type_ascription_removed)]
pub type_ascription: Option<()>,
pub type_ascription: bool,
}
#[derive(Diagnostic)]
@ -2462,7 +2462,7 @@ pub(crate) struct TrailingVertNotAllowed {
pub start: Option<Span>,
pub token: Token,
#[note(parse_note_pattern_alternatives_use_single_vert)]
pub note_double_vert: Option<()>,
pub note_double_vert: bool,
}
#[derive(Diagnostic)]
@ -2894,7 +2894,7 @@ pub(crate) struct BadItemKind {
pub descr: &'static str,
pub ctx: &'static str,
#[help]
pub help: Option<()>,
pub help: bool,
}
#[derive(Diagnostic)]

View file

@ -1403,7 +1403,7 @@ impl<'a> Parser<'a> {
let mut err = ComparisonOperatorsCannotBeChained {
span: vec![op.span, self.prev_token.span],
suggest_turbofish: None,
help_turbofish: None,
help_turbofish: false,
chaining_sugg: None,
};
@ -1436,7 +1436,7 @@ impl<'a> Parser<'a> {
{
err.suggest_turbofish = Some(op.span.shrink_to_lo());
} else {
err.help_turbofish = Some(());
err.help_turbofish = true;
}
let snapshot = self.create_snapshot_for_diagnostic();
@ -1468,7 +1468,7 @@ impl<'a> Parser<'a> {
{
err.suggest_turbofish = Some(op.span.shrink_to_lo());
} else {
err.help_turbofish = Some(());
err.help_turbofish = true;
}
// Consume the fn call arguments.
match self.consume_fn_args() {
@ -1487,7 +1487,7 @@ impl<'a> Parser<'a> {
{
// All we know is that this is `foo < bar >` and *nothing* else. Try to
// be helpful, but don't attempt to recover.
err.help_turbofish = Some(());
err.help_turbofish = true;
}
// If it looks like a genuine attempt to chain operators (as opposed to a
@ -1895,7 +1895,7 @@ impl<'a> Parser<'a> {
{
self.dcx().emit_err(ColonAsSemi {
span: self.token.span,
type_ascription: self.psess.unstable_features.is_nightly_build().then_some(()),
type_ascription: self.psess.unstable_features.is_nightly_build(),
});
self.bump();
return true;

View file

@ -2162,13 +2162,13 @@ impl<'a> Parser<'a> {
self.dcx().emit_warn(errors::InvalidLiteralSuffixOnTupleIndex {
span,
suffix,
exception: Some(()),
exception: true,
});
} else {
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
span,
suffix,
exception: None,
exception: false,
});
}
}

View file

@ -1248,8 +1248,8 @@ impl<'a> Parser<'a> {
let span = self.psess.source_map().guess_head_span(span);
let descr = kind.descr();
let help = match kind {
ItemKind::DelegationMac(deleg) if deleg.suffixes.is_none() => None,
_ => Some(()),
ItemKind::DelegationMac(deleg) if deleg.suffixes.is_none() => false,
_ => true,
};
self.dcx().emit_err(errors::BadItemKind { span, descr, ctx, help });
None

View file

@ -333,7 +333,7 @@ impl<'a> Parser<'a> {
span: self.token.span,
start: lo,
token: self.token.clone(),
note_double_vert: matches!(self.token.kind, token::OrOr).then_some(()),
note_double_vert: matches!(self.token.kind, token::OrOr),
});
self.bump();
true

View file

@ -261,11 +261,7 @@ impl<'a> Parser<'a> {
self.dcx().emit_err(PathSingleColon {
span: self.prev_token.span,
suggestion: self.prev_token.span.shrink_to_hi(),
type_ascription: self
.psess
.unstable_features
.is_nightly_build()
.then_some(()),
type_ascription: self.psess.unstable_features.is_nightly_build(),
});
}
continue;
@ -334,11 +330,7 @@ impl<'a> Parser<'a> {
err = self.dcx().create_err(PathSingleColon {
span: self.token.span,
suggestion: self.prev_token.span.shrink_to_hi(),
type_ascription: self
.psess
.unstable_features
.is_nightly_build()
.then_some(()),
type_ascription: self.psess.unstable_features.is_nightly_build(),
});
}
// Attempt to find places where a missing `>` might belong.