Skip to content

Commit 53167c0

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 2a1e2e9 commit 53167c0

File tree

20 files changed

+48
-48
lines changed

20 files changed

+48
-48
lines changed

compiler/rustc_ast/src/token.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub enum TokenKind {
360360
/// `||`
361361
OrOr,
362362
/// `!`
363-
Not,
363+
Bang,
364364
/// `~`
365365
Tilde,
366366
// `+`
@@ -522,7 +522,7 @@ impl TokenKind {
522522
Some(match (self, n) {
523523
(Le, 1) => (Lt, Eq),
524524
(EqEq, 1) => (Eq, Eq),
525-
(Ne, 1) => (Not, Eq),
525+
(Ne, 1) => (Bang, Eq),
526526
(Ge, 1) => (Gt, Eq),
527527
(AndAnd, 1) => (And, And),
528528
(OrOr, 1) => (Or, Or),
@@ -604,7 +604,7 @@ impl Token {
604604

605605
pub fn is_punct(&self) -> bool {
606606
match self.kind {
607-
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | Plus | Minus
607+
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Bang | Tilde | Plus | Minus
608608
| Star | Slash | Percent | Caret | And | Or | Shl | Shr | PlusEq | MinusEq | StarEq
609609
| SlashEq | PercentEq | CaretEq | AndEq | OrEq | ShlEq | ShrEq | At | Dot | DotDot
610610
| DotDotDot | DotDotEq | Comma | Semi | Colon | PathSep | RArrow | LArrow
@@ -630,7 +630,7 @@ impl Token {
630630
ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
631631
OpenDelim(Parenthesis | Brace | Bracket) | // tuple, array or block
632632
Literal(..) | // literal
633-
Not | // operator not
633+
Bang | // operator not
634634
Minus | // unary minus
635635
Star | // dereference
636636
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
@@ -1004,8 +1004,8 @@ impl Token {
10041004
(Gt, Ge) => ShrEq,
10051005
(Gt, _) => return None,
10061006

1007-
(Not, Eq) => Ne,
1008-
(Not, _) => return None,
1007+
(Bang, Eq) => Ne,
1008+
(Bang, _) => return None,
10091009

10101010
(Plus, Eq) => PlusEq,
10111011
(Plus, _) => return None,

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ impl TokenStream {
651651
if attr_style == AttrStyle::Inner {
652652
vec![
653653
TokenTree::token_joint(token::Pound, span),
654-
TokenTree::token_joint_hidden(token::Not, span),
654+
TokenTree::token_joint_hidden(token::Bang, span),
655655
body,
656656
]
657657
} else {

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
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
@@ -896,7 +896,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
896896
token::Ne => "!=".into(),
897897
token::Ge => ">=".into(),
898898
token::Gt => ">".into(),
899-
token::Not => "!".into(),
899+
token::Bang => "!".into(),
900900
token::Tilde => "~".into(),
901901
token::OrOr => "||".into(),
902902
token::AndAnd => "&&".into(),

compiler/rustc_expand/src/config.rs

+1-1
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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
690690
&& let TokenKind::Ident(ident, _) = ident.kind
691691
&& ident == sym::compile_error
692692
&& let mbe::TokenTree::Token(bang) = bang
693-
&& let TokenKind::Not = bang.kind
693+
&& let TokenKind::Bang = bang.kind
694694
&& let mbe::TokenTree::Delimited(.., del) = args
695695
&& !del.delim.skip()
696696
{

compiler/rustc_expand/src/proc_macro_server.rs

+2-2
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

+1-1
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

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a> Parser<'a> {
130130
assert!(this.eat(exp!(Pound)), "parse_attribute called in non-attribute position");
131131

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

135135
this.expect(exp!(OpenBracket))?;
136136
let item = this.parse_attr_item(ForceCollect::No)?;
@@ -312,7 +312,7 @@ impl<'a> Parser<'a> {
312312
loop {
313313
let start_pos = self.num_bump_calls;
314314
// Only try to parse if it is an inner attribute (has `!`).
315-
let attr = if self.check(exp!(Pound)) && self.look_ahead(1, |t| t == &token::Not) {
315+
let attr = if self.check(exp!(Pound)) && self.look_ahead(1, |t| t == &token::Bang) {
316316
Some(self.parse_attribute(InnerAttrPolicy::Permitted)?)
317317
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
318318
if attr_style == ast::AttrStyle::Inner {

compiler/rustc_parse/src/parser/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ impl<'a> Parser<'a> {
19611961
&mut self,
19621962
await_sp: Span,
19631963
) -> PResult<'a, P<Expr>> {
1964-
let (hi, expr, is_question) = if self.token == token::Not {
1964+
let (hi, expr, is_question) = if self.token == token::Bang {
19651965
// Handle `await!(<expr>)`.
19661966
self.recover_await_macro()?
19671967
} else {
@@ -1973,7 +1973,7 @@ impl<'a> Parser<'a> {
19731973
}
19741974

19751975
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
1976-
self.expect(exp!(Not))?;
1976+
self.expect(exp!(Bang))?;
19771977
self.expect(exp!(OpenParen))?;
19781978
let expr = self.parse_expr()?;
19791979
self.expect(exp!(CloseParen))?;
@@ -2033,7 +2033,7 @@ impl<'a> Parser<'a> {
20332033

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

20392039
if is_try && is_questionmark && is_open {

compiler/rustc_parse/src/parser/expr.rs

+2-2
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`
@@ -1570,7 +1570,7 @@ impl<'a> Parser<'a> {
15701570
};
15711571

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

compiler/rustc_parse/src/parser/item.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'a> Parser<'a> {
382382

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

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

541541
fn parse_polarity(&mut self) -> ast::ImplPolarity {
542542
// Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type.
543-
if self.check(exp!(Not)) && self.look_ahead(1, |t| t.can_begin_type()) {
543+
if self.check(exp!(Bang)) && self.look_ahead(1, |t| t.can_begin_type()) {
544544
self.bump(); // `!`
545545
ast::ImplPolarity::Negative(self.prev_token.span)
546546
} else {
@@ -1579,7 +1579,7 @@ impl<'a> Parser<'a> {
15791579
}
15801580
let ident = this.parse_field_ident("enum", vlo)?;
15811581

1582-
if this.token == token::Not {
1582+
if this.token == token::Bang {
15831583
if let Err(err) = this.unexpected() {
15841584
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
15851585
}
@@ -2034,7 +2034,7 @@ impl<'a> Parser<'a> {
20342034
attrs: AttrVec,
20352035
) -> PResult<'a, FieldDef> {
20362036
let name = self.parse_field_ident(adt_ty, lo)?;
2037-
if self.token == token::Not {
2037+
if self.token == token::Bang {
20382038
if let Err(mut err) = self.unexpected() {
20392039
// Encounter the macro invocation
20402040
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ impl<'a> Parser<'a> {
767767
self.recover_dotdotdot_rest_pat(lo)
768768
} else if let Some(form) = self.parse_range_end() {
769769
self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
770-
} else if self.eat(exp!(Not)) {
770+
} else if self.eat(exp!(Bang)) {
771771
// Parse `!`
772772
self.psess.gated_spans.gate(sym::never_patterns, self.prev_token.span);
773773
PatKind::Never
@@ -823,7 +823,7 @@ impl<'a> Parser<'a> {
823823
};
824824
let span = lo.to(self.prev_token.span);
825825

826-
if qself.is_none() && self.check(exp!(Not)) {
826+
if qself.is_none() && self.check(exp!(Bang)) {
827827
self.parse_pat_mac_invoc(path)?
828828
} else if let Some(form) = self.parse_range_end() {
829829
let begin = self.mk_expr(span, ExprKind::Path(qself, path));
@@ -1335,7 +1335,7 @@ impl<'a> Parser<'a> {
13351335
| token::OpenDelim(Delimiter::Brace) // A struct pattern.
13361336
| token::DotDotDot | token::DotDotEq | token::DotDot // A range pattern.
13371337
| token::PathSep // A tuple / struct variant pattern.
1338-
| token::Not)) // A macro expanding to a pattern.
1338+
| token::Bang)) // A macro expanding to a pattern.
13391339
}
13401340

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

compiler/rustc_parse/src/parser/stmt.rs

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ fn string_to_tts_macro() {
22912291
Token { kind: token::Ident(name_macro_rules, IdentIsRaw::No), .. },
22922292
_,
22932293
),
2294-
TokenTree::Token(Token { kind: token::Not, .. }, _),
2294+
TokenTree::Token(Token { kind: token::Bang, .. }, _),
22952295
TokenTree::Token(Token { kind: token::Ident(name_zip, IdentIsRaw::No), .. }, _),
22962296
TokenTree::Delimited(.., macro_delim, macro_tts),
22972297
] if name_macro_rules == &kw::MacroRules && name_zip.as_str() == "zip" => {

compiler/rustc_parse/src/parser/token_type.rs

+4-4
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
@@ -172,7 +172,7 @@ impl TokenType {
172172
Gt,
173173
AndAnd,
174174
OrOr,
175-
Not,
175+
Bang,
176176
Tilde,
177177

178178
Plus,
@@ -366,7 +366,7 @@ impl TokenType {
366366
TokenType::Gt => "`>`",
367367
TokenType::AndAnd => "`&&`",
368368
TokenType::OrOr => "`||`",
369-
TokenType::Not => "`!`",
369+
TokenType::Bang => "`!`",
370370
TokenType::Tilde => "`~`",
371371

372372
TokenType::Plus => "`+`",
@@ -479,7 +479,7 @@ macro_rules! exp {
479479
(Gt) => { exp!(@tok, Gt) };
480480
(AndAnd) => { exp!(@tok, AndAnd) };
481481
(OrOr) => { exp!(@tok, OrOr) };
482-
(Not) => { exp!(@tok, Not) };
482+
(Bang) => { exp!(@tok, Bang) };
483483
(Tilde) => { exp!(@tok, Tilde) };
484484
(Plus) => { exp!(@tok, Plus) };
485485
(Minus) => { exp!(@tok, Minus) };

compiler/rustc_parse/src/parser/ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a> Parser<'a> {
260260
let mut impl_dyn_multi = false;
261261
let kind = if self.check(exp!(OpenParen)) {
262262
self.parse_ty_tuple_or_parens(lo, allow_plus)?
263-
} else if self.eat(exp!(Not)) {
263+
} else if self.eat(exp!(Bang)) {
264264
// Never type `!`
265265
TyKind::Never
266266
} else if self.eat(exp!(Star)) {
@@ -817,7 +817,7 @@ impl<'a> Parser<'a> {
817817
) -> PResult<'a, TyKind> {
818818
// Simple path
819819
let path = self.parse_path_inner(PathStyle::Type, ty_generics)?;
820-
if self.eat(exp!(Not)) {
820+
if self.eat(exp!(Bang)) {
821821
// Macro invocation in type position
822822
Ok(TyKind::MacCall(P(MacCall { path, args: self.parse_delim_args()? })))
823823
} else if allow_plus == AllowPlus::Yes && self.check_plus() {
@@ -870,7 +870,7 @@ impl<'a> Parser<'a> {
870870
fn can_begin_bound(&mut self) -> bool {
871871
self.check_path()
872872
|| self.check_lifetime()
873-
|| self.check(exp!(Not))
873+
|| self.check(exp!(Bang))
874874
|| self.check(exp!(Question))
875875
|| self.check(exp!(Tilde))
876876
|| self.check_keyword(exp!(For))
@@ -1021,7 +1021,7 @@ impl<'a> Parser<'a> {
10211021

10221022
let polarity = if self.eat(exp!(Question)) {
10231023
BoundPolarity::Maybe(self.prev_token.span)
1024-
} else if self.eat(exp!(Not)) {
1024+
} else if self.eat(exp!(Bang)) {
10251025
self.psess.gated_spans.gate(sym::negative_bounds, self.prev_token.span);
10261026
BoundPolarity::Negative(self.prev_token.span)
10271027
} else {

0 commit comments

Comments
 (0)