Skip to content

Commit

Permalink
Remove field
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Feb 27, 2021
1 parent 1cd23bd commit 11e682d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Expand Up @@ -75,7 +75,6 @@ struct LazyTokenStreamImpl {
num_calls: u32,
desugar_doc_comments: bool,
append_unglued_token: Option<(Token, Spacing)>,
start_calls: u32,
replace_ranges: Box<[ReplaceRange]>,
}

Expand Down Expand Up @@ -116,9 +115,6 @@ impl CreateTokenStream for LazyTokenStreamImpl {
new_tokens
);

let range_start = range.start - self.start_calls;
let range_end = range.end - self.start_calls;

// Replace any removed tokens with `FlatToken::Empty`.
// This keeps the total length of `tokens` constant throughout the
// replacement process, allowing us to use all of the `ReplaceRanges` entries
Expand All @@ -127,7 +123,7 @@ impl CreateTokenStream for LazyTokenStreamImpl {
.take(range.len() - new_tokens.len());

tokens.splice(
(range_start as usize)..(range_end as usize),
(range.start as usize)..(range.end as usize),
new_tokens.clone().into_iter().chain(filler),
);
}
Expand Down Expand Up @@ -270,12 +266,6 @@ impl<'a> Parser<'a> {
return Ok(ret);
}

// Handle previous replace ranges
let replace_ranges = if ret.attrs().is_empty() {
vec![]
} else {
self.capture_state.replace_ranges[replace_ranges_start..replace_ranges_end].to_vec()
};

let cursor_snapshot_next_calls = cursor_snapshot.num_next_calls;
let mut end_pos = self.token_cursor.num_next_calls;
Expand All @@ -295,14 +285,27 @@ impl<'a> Parser<'a> {

let num_calls = end_pos - cursor_snapshot_next_calls;

// Handle previous replace ranges
let replace_ranges: Box<[ReplaceRange]> = if ret.attrs().is_empty() {
Box::new([])
} else {
let start_calls: u32 = cursor_snapshot_next_calls.try_into().unwrap();
self.capture_state.replace_ranges[replace_ranges_start..replace_ranges_end]
.iter()
.cloned()
.map(|(range, tokens)| {
((range.start - start_calls)..(range.end - start_calls), tokens)
})
.collect()
};

let tokens = LazyTokenStream::new(LazyTokenStreamImpl {
start_token,
num_calls: num_calls.try_into().unwrap(),
cursor_snapshot,
desugar_doc_comments: self.desugar_doc_comments,
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
replace_ranges: replace_ranges.into(),
start_calls: cursor_snapshot_next_calls.try_into().unwrap(),
});

let final_attrs: Option<AttributesData> = ret.finalize_tokens(tokens);
Expand Down

0 comments on commit 11e682d

Please sign in to comment.