Remove some unnecessary integer conversions.

These should have been removed in #127233 when the positions were
changed from `usize` to `u32`.
This commit is contained in:
Nicholas Nethercote 2024-07-04 17:50:53 +10:00
parent c422581297
commit dd790ab8ef
2 changed files with 3 additions and 5 deletions

View file

@ -282,7 +282,7 @@ impl<'a> Parser<'a> {
pub fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> { pub fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> {
let mut attrs = ast::AttrVec::new(); let mut attrs = ast::AttrVec::new();
loop { loop {
let start_pos: u32 = self.num_bump_calls.try_into().unwrap(); let start_pos = self.num_bump_calls;
// Only try to parse if it is an inner attribute (has `!`). // Only try to parse if it is an inner attribute (has `!`).
let attr = if self.check(&token::Pound) && self.look_ahead(1, |t| t == &token::Not) { let attr = if self.check(&token::Pound) && self.look_ahead(1, |t| t == &token::Not) {
Some(self.parse_attribute(InnerAttrPolicy::Permitted)?) Some(self.parse_attribute(InnerAttrPolicy::Permitted)?)
@ -303,7 +303,7 @@ impl<'a> Parser<'a> {
None None
}; };
if let Some(attr) = attr { if let Some(attr) = attr {
let end_pos: u32 = self.num_bump_calls.try_into().unwrap(); let end_pos = self.num_bump_calls;
// If we are currently capturing tokens, mark the location of this inner attribute. // If we are currently capturing tokens, mark the location of this inner attribute.
// If capturing ends up creating a `LazyAttrTokenStream`, we will include // If capturing ends up creating a `LazyAttrTokenStream`, we will include
// this replace range with it, removing the inner attribute from the final // this replace range with it, removing the inner attribute from the final

View file

@ -8,7 +8,6 @@ use rustc_errors::PResult;
use rustc_session::parse::ParseSess; use rustc_session::parse::ParseSess;
use rustc_span::{sym, Span, DUMMY_SP}; use rustc_span::{sym, Span, DUMMY_SP};
use std::ops::Range;
use std::{iter, mem}; use std::{iter, mem};
/// A wrapper type to ensure that the parser handles outer attributes correctly. /// A wrapper type to ensure that the parser handles outer attributes correctly.
@ -356,8 +355,7 @@ impl<'a> Parser<'a> {
let new_tokens = vec![(FlatToken::AttrTarget(attr_data), Spacing::Alone)]; let new_tokens = vec![(FlatToken::AttrTarget(attr_data), Spacing::Alone)];
assert!(!self.break_last_token, "Should not have unglued last token with cfg attr"); assert!(!self.break_last_token, "Should not have unglued last token with cfg attr");
let range: Range<u32> = (start_pos.try_into().unwrap())..(end_pos.try_into().unwrap()); self.capture_state.replace_ranges.push((start_pos..end_pos, new_tokens));
self.capture_state.replace_ranges.push((range, new_tokens));
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges); self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
} }