Skip to content

Commit 0fed940

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 f441a75 commit 0fed940

File tree

19 files changed

+44
-44
lines changed

19 files changed

+44
-44
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
@@ -1006,8 +1006,8 @@ impl Token {
10061006
(Gt, Ge) => ShrEq,
10071007
(Gt, _) => return None,
10081008

1009-
(Not, Eq) => Ne,
1010-
(Not, _) => return None,
1009+
(Bang, Eq) => Ne,
1010+
(Bang, _) => return None,
10111011

10121012
(Plus, Eq) => PlusEq,
10131013
(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
@@ -331,7 +331,7 @@ impl<'a> StripUnconfigured<'a> {
331331

332332
// For inner attributes, we do the same thing for the `!` in `#![attr]`.
333333
let mut trees = if cfg_attr.style == AttrStyle::Inner {
334-
let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _)) =
334+
let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Bang, .. }, _)) =
335335
orig_trees.next()
336336
else {
337337
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
@@ -129,7 +129,7 @@ impl<'a> Parser<'a> {
129129
assert!(this.eat(&token::Pound), "parse_attribute called in non-attribute position");
130130

131131
let style =
132-
if this.eat(&token::Not) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
132+
if this.eat(&token::Bang) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
133133

134134
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
135135
let item = this.parse_attr_item(ForceCollect::No)?;
@@ -306,7 +306,7 @@ impl<'a> Parser<'a> {
306306
loop {
307307
let start_pos = self.num_bump_calls;
308308
// Only try to parse if it is an inner attribute (has `!`).
309-
let attr = if self.check(&token::Pound) && self.look_ahead(1, |t| t == &token::Not) {
309+
let attr = if self.check(&token::Pound) && self.look_ahead(1, |t| t == &token::Bang) {
310310
Some(self.parse_attribute(InnerAttrPolicy::Permitted)?)
311311
} else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind {
312312
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
@@ -1997,7 +1997,7 @@ impl<'a> Parser<'a> {
19971997
&mut self,
19981998
await_sp: Span,
19991999
) -> PResult<'a, P<Expr>> {
2000-
let (hi, expr, is_question) = if self.token == token::Not {
2000+
let (hi, expr, is_question) = if self.token == token::Bang {
20012001
// Handle `await!(<expr>)`.
20022002
self.recover_await_macro()?
20032003
} else {
@@ -2009,7 +2009,7 @@ impl<'a> Parser<'a> {
20092009
}
20102010

20112011
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
2012-
self.expect(&token::Not)?;
2012+
self.expect(&token::Bang)?;
20132013
self.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
20142014
let expr = self.parse_expr()?;
20152015
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
@@ -2069,7 +2069,7 @@ impl<'a> Parser<'a> {
20692069

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

20752075
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
@@ -513,7 +513,7 @@ impl<'a> Parser<'a> {
513513
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
514514
match this.token.uninterpolate().kind {
515515
// `!expr`
516-
token::Not => make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Not)),
516+
token::Bang => make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Not)),
517517
// `~expr`
518518
token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)),
519519
// `-expr`
@@ -1573,7 +1573,7 @@ impl<'a> Parser<'a> {
15731573
};
15741574

15751575
// `!`, as an operator, is prefix, so we know this isn't that.
1576-
let (span, kind) = if self.eat(&token::Not) {
1576+
let (span, kind) = if self.eat(&token::Bang) {
15771577
// MACRO INVOCATION expression
15781578
if qself.is_some() {
15791579
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
@@ -479,7 +479,7 @@ impl<'a> Parser<'a> {
479479
/// Parses an item macro, e.g., `item!();`.
480480
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall> {
481481
let path = self.parse_path(PathStyle::Mod)?; // `foo::bar`
482-
self.expect(&token::Not)?; // `!`
482+
self.expect(&token::Bang)?; // `!`
483483
match self.parse_delim_args() {
484484
// `( .. )` or `[ .. ]` (followed by `;`), or `{ .. }`.
485485
Ok(args) => {
@@ -539,7 +539,7 @@ impl<'a> Parser<'a> {
539539

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

1580-
if this.token == token::Not {
1580+
if this.token == token::Bang {
15811581
if let Err(err) = this.unexpected() {
15821582
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
15831583
}
@@ -2028,7 +2028,7 @@ impl<'a> Parser<'a> {
20282028
attrs: AttrVec,
20292029
) -> PResult<'a, FieldDef> {
20302030
let name = self.parse_field_ident(adt_ty, lo)?;
2031-
if self.token == token::Not {
2031+
if self.token == token::Bang {
20322032
if let Err(mut err) = self.unexpected() {
20332033
// Encounter the macro invocation
20342034
err.subdiagnostic(MacroExpandsToAdtField { adt_ty });
@@ -2181,7 +2181,7 @@ impl<'a> Parser<'a> {
21812181
if self.check_keyword(kw::MacroRules) {
21822182
let macro_rules_span = self.token.span;
21832183

2184-
if self.look_ahead(1, |t| *t == token::Not) && self.look_ahead(2, |t| t.is_ident()) {
2184+
if self.look_ahead(1, |t| *t == token::Bang) && self.look_ahead(2, |t| t.is_ident()) {
21852185
return IsMacroRulesItem::Yes { has_bang: true };
21862186
} else if self.look_ahead(1, |t| (t.is_ident())) {
21872187
// macro_rules foo
@@ -2206,11 +2206,11 @@ impl<'a> Parser<'a> {
22062206
self.expect_keyword(kw::MacroRules)?; // `macro_rules`
22072207

22082208
if has_bang {
2209-
self.expect(&token::Not)?; // `!`
2209+
self.expect(&token::Bang)?; // `!`
22102210
}
22112211
let ident = self.parse_ident()?;
22122212

2213-
if self.eat(&token::Not) {
2213+
if self.eat(&token::Bang) {
22142214
// Handle macro_rules! foo!
22152215
let span = self.prev_token.span;
22162216
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
@@ -741,7 +741,7 @@ impl<'a> Parser<'a> {
741741
self.recover_dotdotdot_rest_pat(lo)
742742
} else if let Some(form) = self.parse_range_end() {
743743
self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
744-
} else if self.eat(&token::Not) {
744+
} else if self.eat(&token::Bang) {
745745
// Parse `!`
746746
self.psess.gated_spans.gate(sym::never_patterns, self.prev_token.span);
747747
PatKind::Never
@@ -797,7 +797,7 @@ impl<'a> Parser<'a> {
797797
};
798798
let span = lo.to(self.prev_token.span);
799799

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

13171317
/// 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(&token::Not) {
179+
if this.eat(&token::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/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(&token::OpenDelim(Delimiter::Parenthesis)) {
255255
self.parse_ty_tuple_or_parens(lo, allow_plus)?
256-
} else if self.eat(&token::Not) {
256+
} else if self.eat(&token::Bang) {
257257
// Never type `!`
258258
TyKind::Never
259259
} else if self.eat(&token::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(&token::Not) {
771+
if self.eat(&token::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(&token::Not)
824+
|| self.check(&token::Bang)
825825
|| self.check(&token::Question)
826826
|| self.check(&token::Tilde)
827827
|| self.check_keyword(kw::For)
@@ -972,7 +972,7 @@ impl<'a> Parser<'a> {
972972

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

src/librustdoc/clean/render_macro_matchers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn print_tts(printer: &mut Printer<'_>, tts: &TokenStream) {
140140
(DollarParen, token::Plus | token::Star | token::Question) => (false, Other),
141141
(DollarParen, _) => (false, DollarParenSep),
142142
(DollarParenSep, token::Plus | token::Star) => (false, Other),
143-
(Pound, token::Not) => (false, PoundBang),
143+
(Pound, token::Bang) => (false, PoundBang),
144144
(_, token::Ident(symbol, IdentIsRaw::No))
145145
if !usually_needs_space_between_keyword_and_open_delim(*symbol, tt.span) =>
146146
{

src/tools/rustfmt/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ fn force_space_before(tok: &TokenKind) -> bool {
10881088
| TokenKind::Gt
10891089
| TokenKind::AndAnd
10901090
| TokenKind::OrOr
1091-
| TokenKind::Not
1091+
| TokenKind::Bang
10921092
| TokenKind::Tilde
10931093
| TokenKind::PlusEq
10941094
| TokenKind::MinusEq
@@ -1131,7 +1131,7 @@ fn next_space(tok: &TokenKind) -> SpaceState {
11311131
debug!("next_space: {:?}", tok);
11321132

11331133
match tok {
1134-
TokenKind::Not
1134+
TokenKind::Bang
11351135
| TokenKind::And
11361136
| TokenKind::Tilde
11371137
| TokenKind::At

0 commit comments

Comments
 (0)