Skip to content

Commit adbf517

Browse files
committed
Rename ast::TokenKind::Not as ast::TokenKind::Bang.
For consistency with `rustc_lexer::TokenKind::Bang`, and because other `ast::TokenKind` variants generally have syntactic names instead of semantic names (e.g. `Star` and `DotDot` instead of `Mul` and `Range`).
1 parent 8b8378d commit adbf517

File tree

20 files changed

+48
-48
lines changed

20 files changed

+48
-48
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub enum TokenKind {
355355
/// `||`
356356
OrOr,
357357
/// `!`
358-
Not,
358+
Bang,
359359
/// `~`
360360
Tilde,
361361
// `+`
@@ -517,7 +517,7 @@ impl TokenKind {
517517
Some(match (self, n) {
518518
(Le, 1) => (Lt, Eq),
519519
(EqEq, 1) => (Eq, Eq),
520-
(Ne, 1) => (Not, Eq),
520+
(Ne, 1) => (Bang, Eq),
521521
(Ge, 1) => (Gt, Eq),
522522
(AndAnd, 1) => (And, And),
523523
(OrOr, 1) => (Or, Or),
@@ -599,7 +599,7 @@ impl Token {
599599

600600
pub fn is_punct(&self) -> bool {
601601
match self.kind {
602-
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | Plus | Minus
602+
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Bang | Tilde | Plus | Minus
603603
| Star | Slash | Percent | Caret | And | Or | Shl | Shr | PlusEq | MinusEq | StarEq
604604
| SlashEq | PercentEq | CaretEq | AndEq | OrEq | ShlEq | ShrEq | At | Dot | DotDot
605605
| DotDotDot | DotDotEq | Comma | Semi | Colon | PathSep | RArrow | LArrow
@@ -625,7 +625,7 @@ impl Token {
625625
ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
626626
OpenDelim(Parenthesis | Brace | Bracket) | // tuple, array or block
627627
Literal(..) | // literal
628-
Not | // operator not
628+
Bang | // operator not
629629
Minus | // unary minus
630630
Star | // dereference
631631
Or | OrOr | // closure
@@ -701,7 +701,7 @@ impl Token {
701701
ident_can_begin_type(name, self.span, is_raw), // type name or keyword
702702
OpenDelim(Delimiter::Parenthesis) | // tuple
703703
OpenDelim(Delimiter::Bracket) | // array
704-
Not | // never
704+
Bang | // never
705705
Star | // raw pointer
706706
And | // reference
707707
AndAnd | // double reference
@@ -1007,8 +1007,8 @@ impl Token {
10071007
(Gt, Ge) => ShrEq,
10081008
(Gt, _) => return None,
10091009

1010-
(Not, Eq) => Ne,
1011-
(Not, _) => return None,
1010+
(Bang, Eq) => Ne,
1011+
(Bang, _) => return None,
10121012

10131013
(Plus, Eq) => PlusEq,
10141014
(Plus, _) => return None,

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl TokenStream {
655655
if attr_style == AttrStyle::Inner {
656656
vec![
657657
TokenTree::token_joint(token::Pound, span),
658-
TokenTree::token_joint_hidden(token::Not, span),
658+
TokenTree::token_joint_hidden(token::Bang, span),
659659
body,
660660
]
661661
} else {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
317317
(tt1, Tok(Token { kind: Comma | Semi | Dot, .. }, _)) if !is_punct(tt1) => false,
318318

319319
// IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
320-
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Not, .. }, _))
320+
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Bang, .. }, _))
321321
if !Ident::new(*sym, *span).is_reserved() || matches!(is_raw, IdentIsRaw::Yes) =>
322322
{
323323
false
@@ -892,7 +892,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
892892
token::Ne => "!=".into(),
893893
token::Ge => ">=".into(),
894894
token::Gt => ">".into(),
895-
token::Not => "!".into(),
895+
token::Bang => "!".into(),
896896
token::Tilde => "~".into(),
897897
token::OrOr => "||".into(),
898898
token::AndAnd => "&&".into(),

compiler/rustc_expand/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a> StripUnconfigured<'a> {
328328

329329
// For inner attributes, we do the same thing for the `!` in `#![attr]`.
330330
let mut trees = if cfg_attr.style == AttrStyle::Inner {
331-
let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _)) =
331+
let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Bang, .. }, _)) =
332332
orig_trees.next()
333333
else {
334334
panic!("Bad tokens for attribute {cfg_attr:?}");

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn check_nested_occurrences(
432432
}
433433
(
434434
NestedMacroState::MacroRules,
435-
&TokenTree::Token(Token { kind: TokenKind::Not, .. }),
435+
&TokenTree::Token(Token { kind: TokenKind::Bang, .. }),
436436
) => {
437437
state = NestedMacroState::MacroRulesNot;
438438
}

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
691691
&& let TokenKind::Ident(ident, _) = ident.kind
692692
&& ident == sym::compile_error
693693
&& let mbe::TokenTree::Token(bang) = bang
694-
&& let TokenKind::Not = bang.kind
694+
&& let TokenKind::Bang = bang.kind
695695
&& let mbe::TokenTree::Delimited(.., del) = args
696696
&& !del.delim.skip()
697697
{

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
180180
Gt => op(">"),
181181
AndAnd => op("&&"),
182182
OrOr => op("||"),
183-
Not => op("!"),
183+
Bang => op("!"),
184184
Tilde => op("~"),
185185
Plus => op("+"),
186186
Minus => op("-"),
@@ -322,7 +322,7 @@ impl ToInternal<SmallVec<[tokenstream::TokenTree; 2]>>
322322
b'=' => Eq,
323323
b'<' => Lt,
324324
b'>' => Gt,
325-
b'!' => Not,
325+
b'!' => Bang,
326326
b'~' => Tilde,
327327
b'+' => Plus,
328328
b'-' => Minus,

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
384384
rustc_lexer::TokenKind::Colon => token::Colon,
385385
rustc_lexer::TokenKind::Dollar => token::Dollar,
386386
rustc_lexer::TokenKind::Eq => token::Eq,
387-
rustc_lexer::TokenKind::Bang => token::Not,
387+
rustc_lexer::TokenKind::Bang => token::Bang,
388388
rustc_lexer::TokenKind::Lt => token::Lt,
389389
rustc_lexer::TokenKind::Gt => token::Gt,
390390
rustc_lexer::TokenKind::Minus => token::Minus,

compiler/rustc_parse/src/lexer/unicode_chars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const ASCII_ARRAY: &[(&str, &str, Option<token::TokenKind>)] = &[
312312
(",", "Comma", Some(token::Comma)),
313313
(";", "Semicolon", Some(token::Semi)),
314314
(":", "Colon", Some(token::Colon)),
315-
("!", "Exclamation Mark", Some(token::Not)),
315+
("!", "Exclamation Mark", Some(token::Bang)),
316316
("?", "Question Mark", Some(token::Question)),
317317
(".", "Period", Some(token::Dot)),
318318
("(", "Left Parenthesis", Some(token::OpenDelim(Delimiter::Parenthesis))),

compiler/rustc_parse/src/parser/attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'a> Parser<'a> {
128128
assert!(this.eat(exp!(Pound)), "parse_attribute called in non-attribute position");
129129

130130
let style =
131-
if this.eat(exp!(Not)) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
131+
if this.eat(exp!(Bang)) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
132132

133133
this.expect(exp!(OpenBracket))?;
134134
let item = this.parse_attr_item(ForceCollect::No)?;
@@ -305,7 +305,7 @@ impl<'a> Parser<'a> {
305305
loop {
306306
let start_pos = self.num_bump_calls;
307307
// Only try to parse if it is an inner attribute (has `!`).
308-
let attr = if self.check(exp!(Pound)) && self.look_ahead(1, |t| t == &token::Not) {
308+
let attr = if self.check(exp!(Pound)) && self.look_ahead(1, |t| t == &token::Bang) {
309309
Some(self.parse_attribute(InnerAttrPolicy::Permitted)?)
310310
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
311311
if attr_style == ast::AttrStyle::Inner {

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ impl<'a> Parser<'a> {
19571957
&mut self,
19581958
await_sp: Span,
19591959
) -> PResult<'a, P<Expr>> {
1960-
let (hi, expr, is_question) = if self.token == token::Not {
1960+
let (hi, expr, is_question) = if self.token == token::Bang {
19611961
// Handle `await!(<expr>)`.
19621962
self.recover_await_macro()?
19631963
} else {
@@ -1969,7 +1969,7 @@ impl<'a> Parser<'a> {
19691969
}
19701970

19711971
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
1972-
self.expect(exp!(Not))?;
1972+
self.expect(exp!(Bang))?;
19731973
self.expect(exp!(OpenParen))?;
19741974
let expr = self.parse_expr()?;
19751975
self.expect(exp!(CloseParen))?;
@@ -2029,7 +2029,7 @@ impl<'a> Parser<'a> {
20292029

20302030
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
20312031
let is_try = self.token.is_keyword(kw::Try);
2032-
let is_questionmark = self.look_ahead(1, |t| t == &token::Not); //check for !
2032+
let is_questionmark = self.look_ahead(1, |t| t == &token::Bang); //check for !
20332033
let is_open = self.look_ahead(2, |t| t == &token::OpenDelim(Delimiter::Parenthesis)); //check for (
20342034

20352035
if is_try && is_questionmark && is_open {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl<'a> Parser<'a> {
505505
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
506506
match this.token.uninterpolate().kind {
507507
// `!expr`
508-
token::Not => make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Not)),
508+
token::Bang => make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Not)),
509509
// `~expr`
510510
token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)),
511511
// `-expr`
@@ -1567,7 +1567,7 @@ impl<'a> Parser<'a> {
15671567
};
15681568

15691569
// `!`, as an operator, is prefix, so we know this isn't that.
1570-
let (span, kind) = if self.eat(exp!(Not)) {
1570+
let (span, kind) = if self.eat(exp!(Bang)) {
15711571
// MACRO INVOCATION expression
15721572
if qself.is_some() {
15731573
self.dcx().emit_err(errors::MacroInvocationWithQualifiedPath(path.span));

compiler/rustc_parse/src/parser/item.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'a> Parser<'a> {
379379

380380
/// Are we sure this could not possibly be a macro invocation?
381381
fn isnt_macro_invocation(&mut self) -> bool {
382-
self.check_ident() && self.look_ahead(1, |t| *t != token::Not && *t != token::PathSep)
382+
self.check_ident() && self.look_ahead(1, |t| *t != token::Bang && *t != token::PathSep)
383383
}
384384

385385
/// Recover on encountering a struct, enum, or method definition where the user
@@ -477,7 +477,7 @@ impl<'a> Parser<'a> {
477477
/// Parses an item macro, e.g., `item!();`.
478478
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall> {
479479
let path = self.parse_path(PathStyle::Mod)?; // `foo::bar`
480-
self.expect(exp!(Not))?; // `!`
480+
self.expect(exp!(Bang))?; // `!`
481481
match self.parse_delim_args() {
482482
// `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
483483
Ok(args) => {
@@ -537,7 +537,7 @@ impl<'a> Parser<'a> {
537537

538538
fn parse_polarity(&mut self) -> ast::ImplPolarity {
539539
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
540-
if self.check(exp!(Not)) && self.look_ahead(1, |t| t.can_begin_type()) {
540+
if self.check(exp!(Bang)) && self.look_ahead(1, |t| t.can_begin_type()) {
541541
self.bump(); // `!`
542542
ast::ImplPolarity::Negative(self.prev_token.span)
543543
} else {
@@ -1576,7 +1576,7 @@ impl<'a> Parser<'a> {
15761576
}
15771577
let ident = this.parse_field_ident("enum", vlo)?;
15781578

1579-
if this.token == token::Not {
1579+
if this.token == token::Bang {
15801580
if let Err(err) = this.unexpected() {
15811581
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
15821582
}
@@ -2031,7 +2031,7 @@ impl<'a> Parser<'a> {
20312031
attrs: AttrVec,
20322032
) -> PResult<'a, FieldDef> {
20332033
let name = self.parse_field_ident(adt_ty, lo)?;
2034-
if self.token == token::Not {
2034+
if self.token == token::Bang {
20352035
if let Err(mut err) = self.unexpected() {
20362036
// Encounter the macro invocation
20372037
err.subdiagnostic(MacroExpandsToAdtField { adt_ty });
@@ -2184,7 +2184,7 @@ impl<'a> Parser<'a> {
21842184
if self.check_keyword(exp!(MacroRules)) {
21852185
let macro_rules_span = self.token.span;
21862186

2187-
if self.look_ahead(1, |t| *t == token::Not) && self.look_ahead(2, |t| t.is_ident()) {
2187+
if self.look_ahead(1, |t| *t == token::Bang) && self.look_ahead(2, |t| t.is_ident()) {
21882188
return IsMacroRulesItem::Yes { has_bang: true };
21892189
} else if self.look_ahead(1, |t| (t.is_ident())) {
21902190
// macro_rules foo
@@ -2209,11 +2209,11 @@ impl<'a> Parser<'a> {
22092209
self.expect_keyword(exp!(MacroRules))?; // `macro_rules`
22102210

22112211
if has_bang {
2212-
self.expect(exp!(Not))?; // `!`
2212+
self.expect(exp!(Bang))?; // `!`
22132213
}
22142214
let ident = self.parse_ident()?;
22152215

2216-
if self.eat(exp!(Not)) {
2216+
if self.eat(exp!(Bang)) {
22172217
// Handle macro_rules! foo!
22182218
let span = self.prev_token.span;
22192219
self.dcx().emit_err(errors::MacroNameRemoveBang { span });

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl<'a> Parser<'a> {
742742
self.recover_dotdotdot_rest_pat(lo)
743743
} else if let Some(form) = self.parse_range_end() {
744744
self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
745-
} else if self.eat(exp!(Not)) {
745+
} else if self.eat(exp!(Bang)) {
746746
// Parse `!`
747747
self.psess.gated_spans.gate(sym::never_patterns, self.prev_token.span);
748748
PatKind::Never
@@ -798,7 +798,7 @@ impl<'a> Parser<'a> {
798798
};
799799
let span = lo.to(self.prev_token.span);
800800

801-
if qself.is_none() && self.check(exp!(Not)) {
801+
if qself.is_none() && self.check(exp!(Bang)) {
802802
self.parse_pat_mac_invoc(path)?
803803
} else if let Some(form) = self.parse_range_end() {
804804
let begin = self.mk_expr(span, ExprKind::Path(qself, path));
@@ -1312,7 +1312,7 @@ impl<'a> Parser<'a> {
13121312
| token::OpenDelim(Delimiter::Brace) // A struct pattern.
13131313
| token::DotDotDot | token::DotDotEq | token::DotDot // A range pattern.
13141314
| token::PathSep // A tuple / struct variant pattern.
1315-
| token::Not)) // A macro expanding to a pattern.
1315+
| token::Bang)) // A macro expanding to a pattern.
13161316
}
13171317

13181318
/// Parses `ident` or `ident @ pat`.

compiler/rustc_parse/src/parser/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a> Parser<'a> {
176176
let stmt = self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| {
177177
let path = this.parse_path(PathStyle::Expr)?;
178178

179-
if this.eat(exp!(Not)) {
179+
if this.eat(exp!(Bang)) {
180180
let stmt_mac = this.parse_stmt_mac(lo, attrs, path)?;
181181
return Ok((
182182
stmt_mac,

compiler/rustc_parse/src/parser/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ fn string_to_tts_macro() {
22942294
Token { kind: token::Ident(name_macro_rules, IdentIsRaw::No), .. },
22952295
_,
22962296
),
2297-
TokenTree::Token(Token { kind: token::Not, .. }, _),
2297+
TokenTree::Token(Token { kind: token::Bang, .. }, _),
22982298
TokenTree::Token(Token { kind: token::Ident(name_zip, IdentIsRaw::No), .. }, _),
22992299
TokenTree::Delimited(.., macro_delim, macro_tts),
23002300
] if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" => {

compiler/rustc_parse/src/parser/token_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum TokenType {
2525
Gt,
2626
AndAnd,
2727
OrOr,
28-
Not,
28+
Bang,
2929
Tilde,
3030

3131
// BinOps
@@ -170,7 +170,7 @@ impl TokenType {
170170
Gt,
171171
AndAnd,
172172
OrOr,
173-
Not,
173+
Bang,
174174
Tilde,
175175

176176
Plus,
@@ -360,7 +360,7 @@ impl TokenType {
360360
TokenType::Gt => "`>`",
361361
TokenType::AndAnd => "`&&`",
362362
TokenType::OrOr => "`||`",
363-
TokenType::Not => "`!`",
363+
TokenType::Bang => "`!`",
364364
TokenType::Tilde => "`~`",
365365

366366
TokenType::Plus => "`+`",
@@ -473,7 +473,7 @@ macro_rules! exp {
473473
(Gt) => { exp!(@tok, Gt) };
474474
(AndAnd) => { exp!(@tok, AndAnd) };
475475
(OrOr) => { exp!(@tok, OrOr) };
476-
(Not) => { exp!(@tok, Not) };
476+
(Bang) => { exp!(@tok, Bang) };
477477
(Tilde) => { exp!(@tok, Tilde) };
478478
(Plus) => { exp!(@tok, Plus) };
479479
(Minus) => { exp!(@tok, Minus) };

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'a> Parser<'a> {
253253
let mut impl_dyn_multi = false;
254254
let kind = if self.check(exp!(OpenParen)) {
255255
self.parse_ty_tuple_or_parens(lo, allow_plus)?
256-
} else if self.eat(exp!(Not)) {
256+
} else if self.eat(exp!(Bang)) {
257257
// Never type `!`
258258
TyKind::Never
259259
} else if self.eat(exp!(Star)) {
@@ -768,7 +768,7 @@ impl<'a> Parser<'a> {
768768
) -> PResult<'a, TyKind> {
769769
// Simple path
770770
let path = self.parse_path_inner(PathStyle::Type, ty_generics)?;
771-
if self.eat(exp!(Not)) {
771+
if self.eat(exp!(Bang)) {
772772
// Macro invocation in type position
773773
Ok(TyKind::MacCall(P(MacCall { path, args: self.parse_delim_args()? })))
774774
} else if allow_plus == AllowPlus::Yes && self.check_plus() {
@@ -821,7 +821,7 @@ impl<'a> Parser<'a> {
821821
fn can_begin_bound(&mut self) -> bool {
822822
self.check_path()
823823
|| self.check_lifetime()
824-
|| self.check(exp!(Not))
824+
|| self.check(exp!(Bang))
825825
|| self.check(exp!(Question))
826826
|| self.check(exp!(Tilde))
827827
|| self.check_keyword(exp!(For))
@@ -972,7 +972,7 @@ impl<'a> Parser<'a> {
972972

973973
let polarity = if self.eat(exp!(Question)) {
974974
BoundPolarity::Maybe(self.prev_token.span)
975-
} else if self.eat(exp!(Not)) {
975+
} else if self.eat(exp!(Bang)) {
976976
self.psess.gated_spans.gate(sym::negative_bounds, self.prev_token.span);
977977
BoundPolarity::Negative(self.prev_token.span)
978978
} else {

0 commit comments

Comments
 (0)