Replace another lock with an append-only vec

This commit is contained in:
Oli Scherer 2023-03-14 12:16:19 +00:00
parent 4699632637
commit 7edd1d8799
4 changed files with 20 additions and 4 deletions

View File

@ -76,3 +76,19 @@ pub fn get(&self, i: usize) -> Option<T> {
return self.vec.get(i);
}
}
impl<T: Copy + PartialEq> AppendOnlyVec<T> {
pub fn contains(&self, val: T) -> bool {
for i in 0.. {
match self.get(i) {
None => return false,
Some(v) => {
if val == v {
return true;
}
}
}
}
false
}
}

View File

@ -1947,7 +1947,7 @@ fn check_ident_token(
};
// Don't lint `r#foo`.
if cx.sess().parse_sess.raw_identifier_spans.borrow().contains(&ident.span) {
if cx.sess().parse_sess.raw_identifier_spans.contains(ident.span) {
return;
}

View File

@ -175,7 +175,7 @@ fn next_token(&mut self) -> (Token, bool) {
if !sym.can_be_raw() {
self.sess.emit_err(errors::CannotBeRawIdent { span, ident: sym });
}
self.sess.raw_identifier_spans.borrow_mut().push(span);
self.sess.raw_identifier_spans.push(span);
token::Ident(sym, true)
}
rustc_lexer::TokenKind::UnknownPrefix => {

View File

@ -194,7 +194,7 @@ pub struct ParseSess {
pub edition: Edition,
/// Places where raw identifiers were used. This is used to avoid complaining about idents
/// clashing with keywords in new editions.
pub raw_identifier_spans: Lock<Vec<Span>>,
pub raw_identifier_spans: AppendOnlyVec<Span>,
/// Places where identifiers that contain invalid Unicode codepoints but that look like they
/// should be. Useful to avoid bad tokenization when encountering emoji. We group them to
/// provide a single error per unique incorrect identifier.
@ -247,7 +247,7 @@ pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self {
config: FxIndexSet::default(),
check_config: CrateCheckConfig::default(),
edition: ExpnId::root().expn_data().edition,
raw_identifier_spans: Lock::new(Vec::new()),
raw_identifier_spans: Default::default(),
bad_unicode_identifiers: Lock::new(Default::default()),
source_map,
buffered_lints: Lock::new(vec![]),