1
Fork 0

Remove unnecessary maybe_ternary_lo field

This commit is contained in:
Catherine Flores 2023-07-25 18:37:56 +00:00
parent 16481807f5
commit faa73953c0
5 changed files with 55 additions and 37 deletions

View file

@ -501,10 +501,8 @@ impl<'a> Parser<'a> {
// Special-case "expected `;`" errors
if expected.contains(&TokenType::Token(token::Semi)) {
if self.prev_token.kind == token::Question {
self.maybe_ternary_lo = Some(self.prev_token.span.lo());
let result = self.maybe_recover_from_ternary_operator().map(|_| true);
self.maybe_ternary_lo = None;
return result;
self.maybe_recover_from_ternary_operator();
return Ok(true);
}
if self.token.span == DUMMY_SP || self.prev_token.span == DUMMY_SP {
@ -1339,7 +1337,7 @@ impl<'a> Parser<'a> {
/// Rust has no ternary operator (`cond ? then : else`). Parse it and try
/// to recover from it if `then` and `else` are valid expressions.
pub(super) fn maybe_recover_from_ternary_operator(&mut self) -> PResult<'a, ()> {
pub(super) fn maybe_recover_from_ternary_operator(&mut self) {
let snapshot = self.create_snapshot_for_diagnostic();
let lo = self.prev_token.span.lo();
@ -1368,8 +1366,6 @@ impl<'a> Parser<'a> {
} else {
self.restore_snapshot(snapshot);
};
Ok(())
}
pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a, ()> {

View file

@ -37,7 +37,6 @@ use rustc_errors::{
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::BytePos;
use std::ops::Range;
use std::{cmp, mem, slice};
use thin_vec::ThinVec;
@ -158,17 +157,12 @@ pub struct Parser<'a> {
/// Whether the parser is allowed to do recovery.
/// This is disabled when parsing macro arguments, see #103534
pub recovery: Recovery,
/// The low part of a ternary operator (`cond ? then : else`).
/// FIXME(Centri3): This is currently only used so that type ascription is
/// not mentioned in the error. Once the error in `stmt.rs` is removed, this
/// can be removed.
maybe_ternary_lo: Option<BytePos>,
}
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure
// it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Parser<'_>, 280);
rustc_data_structures::static_assert_size!(Parser<'_>, 272);
/// Stores span information about a closure.
#[derive(Clone)]
@ -481,7 +475,6 @@ impl<'a> Parser<'a> {
},
current_closure: None,
recovery: Recovery::Allowed,
maybe_ternary_lo: None,
};
// Make parser point to the first token.

View file

@ -576,9 +576,7 @@ impl<'a> Parser<'a> {
Applicability::MaybeIncorrect,
);
}
if self.sess.unstable_features.is_nightly_build()
&& self.maybe_ternary_lo.is_none()
{
if self.sess.unstable_features.is_nightly_build() {
// FIXME(Nilstrieb): Remove this again after a few months.
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
}