Skip to content

Commit 875df37

Browse files
committed
Auto merge of #133219 - matthiaskrgr:rollup-hnuq0zf, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #123947 (Add vec_deque::Iter::as_slices and friends) - #125405 (Add std::thread::add_spawn_hook.) - #133175 (ci: use free runner in dist-i686-msvc) - #133183 (Mention std::fs::remove_dir_all in std::fs::remove_dir) - #133188 (Add `visit` methods to ast nodes that already have `walk`s on ast visitors) - #133201 (Remove `TokenKind::InvalidPrefix`) - #133207 (Default-enable `llvm_tools_enabled` when no `config.toml` is present) - #133213 (Correct the tier listing of `wasm32-wasip2`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ee612c4 + 2467654 commit 875df37

File tree

18 files changed

+429
-90
lines changed

18 files changed

+429
-90
lines changed

compiler/rustc_ast/src/mut_visit.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ pub trait MutVisitor: Sized {
330330
fn visit_capture_by(&mut self, capture_by: &mut CaptureBy) {
331331
walk_capture_by(self, capture_by)
332332
}
333+
334+
fn visit_fn_ret_ty(&mut self, fn_ret_ty: &mut FnRetTy) {
335+
walk_fn_ret_ty(self, fn_ret_ty)
336+
}
333337
}
334338

335339
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
@@ -609,7 +613,7 @@ fn walk_angle_bracketed_parameter_data<T: MutVisitor>(vis: &mut T, data: &mut An
609613
fn walk_parenthesized_parameter_data<T: MutVisitor>(vis: &mut T, args: &mut ParenthesizedArgs) {
610614
let ParenthesizedArgs { inputs, output, span, inputs_span } = args;
611615
visit_thin_vec(inputs, |input| vis.visit_ty(input));
612-
walk_fn_ret_ty(vis, output);
616+
vis.visit_fn_ret_ty(output);
613617
vis.visit_span(span);
614618
vis.visit_span(inputs_span);
615619
}
@@ -911,7 +915,7 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
911915
fn walk_fn_decl<T: MutVisitor>(vis: &mut T, decl: &mut P<FnDecl>) {
912916
let FnDecl { inputs, output } = decl.deref_mut();
913917
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
914-
walk_fn_ret_ty(vis, output);
918+
vis.visit_fn_ret_ty(output);
915919
}
916920

917921
fn walk_fn_ret_ty<T: MutVisitor>(vis: &mut T, fn_ret_ty: &mut FnRetTy) {

compiler/rustc_ast/src/visit.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ pub trait Visitor<'ast>: Sized {
299299
fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
300300
Self::Result::output()
301301
}
302+
fn visit_fn_decl(&mut self, fn_decl: &'ast FnDecl) -> Self::Result {
303+
walk_fn_decl(self, fn_decl)
304+
}
305+
fn visit_qself(&mut self, qs: &'ast Option<P<QSelf>>) -> Self::Result {
306+
walk_qself(self, qs)
307+
}
302308
}
303309

304310
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
@@ -434,13 +440,13 @@ impl WalkItemKind for ItemKind {
434440
body,
435441
from_glob: _,
436442
}) => {
437-
try_visit!(walk_qself(visitor, qself));
443+
try_visit!(visitor.visit_qself(qself));
438444
try_visit!(visitor.visit_path(path, *id));
439445
visit_opt!(visitor, visit_ident, rename);
440446
visit_opt!(visitor, visit_block, body);
441447
}
442448
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
443-
try_visit!(walk_qself(visitor, qself));
449+
try_visit!(visitor.visit_qself(qself));
444450
try_visit!(visitor.visit_path(prefix, id));
445451
if let Some(suffixes) = suffixes {
446452
for (ident, rename) in suffixes {
@@ -518,10 +524,10 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
518524
let BareFnTy { safety: _, ext: _, generic_params, decl, decl_span: _ } =
519525
&**function_declaration;
520526
walk_list!(visitor, visit_generic_param, generic_params);
521-
try_visit!(walk_fn_decl(visitor, decl));
527+
try_visit!(visitor.visit_fn_decl(decl));
522528
}
523529
TyKind::Path(maybe_qself, path) => {
524-
try_visit!(walk_qself(visitor, maybe_qself));
530+
try_visit!(visitor.visit_qself(maybe_qself));
525531
try_visit!(visitor.visit_path(path, *id));
526532
}
527533
TyKind::Pat(ty, pat) => {
@@ -652,16 +658,16 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
652658
let Pat { id, kind, span: _, tokens: _ } = pattern;
653659
match kind {
654660
PatKind::TupleStruct(opt_qself, path, elems) => {
655-
try_visit!(walk_qself(visitor, opt_qself));
661+
try_visit!(visitor.visit_qself(opt_qself));
656662
try_visit!(visitor.visit_path(path, *id));
657663
walk_list!(visitor, visit_pat, elems);
658664
}
659665
PatKind::Path(opt_qself, path) => {
660-
try_visit!(walk_qself(visitor, opt_qself));
666+
try_visit!(visitor.visit_qself(opt_qself));
661667
try_visit!(visitor.visit_path(path, *id))
662668
}
663669
PatKind::Struct(opt_qself, path, fields, _rest) => {
664-
try_visit!(walk_qself(visitor, opt_qself));
670+
try_visit!(visitor.visit_qself(opt_qself));
665671
try_visit!(visitor.visit_path(path, *id));
666672
walk_list!(visitor, visit_pat_field, fields);
667673
}
@@ -846,13 +852,13 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
846852
// Identifier and visibility are visited as a part of the item.
847853
try_visit!(visitor.visit_fn_header(header));
848854
try_visit!(visitor.visit_generics(generics));
849-
try_visit!(walk_fn_decl(visitor, decl));
855+
try_visit!(visitor.visit_fn_decl(decl));
850856
visit_opt!(visitor, visit_block, body);
851857
}
852858
FnKind::Closure(binder, coroutine_kind, decl, body) => {
853859
try_visit!(visitor.visit_closure_binder(binder));
854860
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
855-
try_visit!(walk_fn_decl(visitor, decl));
861+
try_visit!(visitor.visit_fn_decl(decl));
856862
try_visit!(visitor.visit_expr(body));
857863
}
858864
}
@@ -902,13 +908,13 @@ impl WalkItemKind for AssocItemKind {
902908
body,
903909
from_glob: _,
904910
}) => {
905-
try_visit!(walk_qself(visitor, qself));
911+
try_visit!(visitor.visit_qself(qself));
906912
try_visit!(visitor.visit_path(path, *id));
907913
visit_opt!(visitor, visit_ident, rename);
908914
visit_opt!(visitor, visit_block, body);
909915
}
910916
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
911-
try_visit!(walk_qself(visitor, qself));
917+
try_visit!(visitor.visit_qself(qself));
912918
try_visit!(visitor.visit_path(prefix, id));
913919
if let Some(suffixes) = suffixes {
914920
for (ident, rename) in suffixes {
@@ -1023,7 +1029,7 @@ pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(
10231029
visitor: &mut V,
10241030
InlineAsmSym { id, qself, path }: &'a InlineAsmSym,
10251031
) -> V::Result {
1026-
try_visit!(walk_qself(visitor, qself));
1032+
try_visit!(visitor.visit_qself(qself));
10271033
visitor.visit_path(path, *id)
10281034
}
10291035

@@ -1055,7 +1061,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
10551061
}
10561062
ExprKind::Struct(se) => {
10571063
let StructExpr { qself, path, fields, rest } = &**se;
1058-
try_visit!(walk_qself(visitor, qself));
1064+
try_visit!(visitor.visit_qself(qself));
10591065
try_visit!(visitor.visit_path(path, *id));
10601066
walk_list!(visitor, visit_expr_field, fields);
10611067
match rest {
@@ -1164,7 +1170,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11641170
}
11651171
ExprKind::Underscore => {}
11661172
ExprKind::Path(maybe_qself, path) => {
1167-
try_visit!(walk_qself(visitor, maybe_qself));
1173+
try_visit!(visitor.visit_qself(maybe_qself));
11681174
try_visit!(visitor.visit_path(path, *id));
11691175
}
11701176
ExprKind::Break(opt_label, opt_expr) => {

compiler/rustc_codegen_cranelift/scripts/setup_rust_fork.sh

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ local-rebuild = true
3838
codegen-backends = ["cranelift"]
3939
deny-warnings = false
4040
verbose-tests = false
41+
# The cg_clif sysroot doesn't contain llvm tools and unless llvm_tools is
42+
# disabled bootstrap will crash trying to copy llvm tools for the bootstrap
43+
# compiler.
44+
llvm_tools = false
45+
4146
EOF
4247
popd
4348

compiler/rustc_lexer/src/lib.rs

+49-57
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ impl Token {
5757
/// Enum representing common lexeme types.
5858
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5959
pub enum TokenKind {
60-
// Multi-char tokens:
61-
/// "// comment"
60+
/// A line comment, e.g. `// comment`.
6261
LineComment { doc_style: Option<DocStyle> },
6362

64-
/// `/* block comment */`
63+
/// A block comment, e.g. `/* block comment */`.
6564
///
6665
/// Block comments can be recursive, so a sequence like `/* /* */`
6766
/// will not be considered terminated and will result in a parsing error.
@@ -70,18 +69,17 @@ pub enum TokenKind {
7069
/// Any whitespace character sequence.
7170
Whitespace,
7271

73-
/// "ident" or "continue"
74-
///
75-
/// At this step, keywords are also considered identifiers.
72+
/// An identifier or keyword, e.g. `ident` or `continue`.
7673
Ident,
7774

78-
/// Like the above, but containing invalid unicode codepoints.
75+
/// An identifier that is invalid because it contains emoji.
7976
InvalidIdent,
8077

81-
/// "r#ident"
78+
/// A raw identifier, e.g. "r#ident".
8279
RawIdent,
8380

84-
/// An unknown prefix, like `foo#`, `foo'`, `foo"`.
81+
/// An unknown literal prefix, like `foo#`, `foo'`, `foo"`. Excludes
82+
/// literal prefixes that contain emoji, which are considered "invalid".
8583
///
8684
/// Note that only the
8785
/// prefix (`foo`) is included in the token, not the separator (which is
@@ -93,87 +91,83 @@ pub enum TokenKind {
9391

9492
/// An unknown prefix in a lifetime, like `'foo#`.
9593
///
96-
/// Note that like above, only the `'` and prefix are included in the token
94+
/// Like `UnknownPrefix`, only the `'` and prefix are included in the token
9795
/// and not the separator.
9896
UnknownPrefixLifetime,
9997

100-
/// `'r#lt`, which in edition < 2021 is split into several tokens: `'r # lt`.
98+
/// A raw lifetime, e.g. `'r#foo`. In edition < 2021 it will be split into
99+
/// several tokens: `'r` and `#` and `foo`.
101100
RawLifetime,
102101

103-
/// Similar to the above, but *always* an error on every edition. This is used
104-
/// for emoji identifier recovery, as those are not meant to be ever accepted.
105-
InvalidPrefix,
106-
107102
/// Guarded string literal prefix: `#"` or `##`.
108103
///
109104
/// Used for reserving "guarded strings" (RFC 3598) in edition 2024.
110105
/// Split into the component tokens on older editions.
111106
GuardedStrPrefix,
112107

113-
/// Examples: `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
108+
/// Literals, e.g. `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
114109
/// suffix, but may be present here on string and float literals. Users of
115110
/// this type will need to check for and reject that case.
116111
///
117112
/// See [LiteralKind] for more details.
118113
Literal { kind: LiteralKind, suffix_start: u32 },
119114

120-
/// "'a"
115+
/// A lifetime, e.g. `'a`.
121116
Lifetime { starts_with_number: bool },
122117

123-
// One-char tokens:
124-
/// ";"
118+
/// `;`
125119
Semi,
126-
/// ","
120+
/// `,`
127121
Comma,
128-
/// "."
122+
/// `.`
129123
Dot,
130-
/// "("
124+
/// `(`
131125
OpenParen,
132-
/// ")"
126+
/// `)`
133127
CloseParen,
134-
/// "{"
128+
/// `{`
135129
OpenBrace,
136-
/// "}"
130+
/// `}`
137131
CloseBrace,
138-
/// "["
132+
/// `[`
139133
OpenBracket,
140-
/// "]"
134+
/// `]`
141135
CloseBracket,
142-
/// "@"
136+
/// `@`
143137
At,
144-
/// "#"
138+
/// `#`
145139
Pound,
146-
/// "~"
140+
/// `~`
147141
Tilde,
148-
/// "?"
142+
/// `?`
149143
Question,
150-
/// ":"
144+
/// `:`
151145
Colon,
152-
/// "$"
146+
/// `$`
153147
Dollar,
154-
/// "="
148+
/// `=`
155149
Eq,
156-
/// "!"
150+
/// `!`
157151
Bang,
158-
/// "<"
152+
/// `<`
159153
Lt,
160-
/// ">"
154+
/// `>`
161155
Gt,
162-
/// "-"
156+
/// `-`
163157
Minus,
164-
/// "&"
158+
/// `&`
165159
And,
166-
/// "|"
160+
/// `|`
167161
Or,
168-
/// "+"
162+
/// `+`
169163
Plus,
170-
/// "*"
164+
/// `*`
171165
Star,
172-
/// "/"
166+
/// `/`
173167
Slash,
174-
/// "^"
168+
/// `^`
175169
Caret,
176-
/// "%"
170+
/// `%`
177171
Percent,
178172

179173
/// Unknown token, not expected by the lexer, e.g. "№"
@@ -468,7 +462,7 @@ impl Cursor<'_> {
468462
Literal { kind, suffix_start }
469463
}
470464
// Identifier starting with an emoji. Only lexed for graceful error recovery.
471-
c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(),
465+
c if !c.is_ascii() && c.is_emoji_char() => self.invalid_ident(),
472466
_ => Unknown,
473467
};
474468
let res = Token::new(token_kind, self.pos_within_token());
@@ -552,24 +546,22 @@ impl Cursor<'_> {
552546
// we see a prefix here, it is definitely an unknown prefix.
553547
match self.first() {
554548
'#' | '"' | '\'' => UnknownPrefix,
555-
c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(),
549+
c if !c.is_ascii() && c.is_emoji_char() => self.invalid_ident(),
556550
_ => Ident,
557551
}
558552
}
559553

560-
fn fake_ident_or_unknown_prefix(&mut self) -> TokenKind {
554+
fn invalid_ident(&mut self) -> TokenKind {
561555
// Start is already eaten, eat the rest of identifier.
562556
self.eat_while(|c| {
563-
unicode_xid::UnicodeXID::is_xid_continue(c)
564-
|| (!c.is_ascii() && c.is_emoji_char())
565-
|| c == '\u{200d}'
557+
const ZERO_WIDTH_JOINER: char = '\u{200d}';
558+
is_id_continue(c) || (!c.is_ascii() && c.is_emoji_char()) || c == ZERO_WIDTH_JOINER
566559
});
567-
// Known prefixes must have been handled earlier. So if
568-
// we see a prefix here, it is definitely an unknown prefix.
569-
match self.first() {
570-
'#' | '"' | '\'' => InvalidPrefix,
571-
_ => InvalidIdent,
572-
}
560+
// An invalid identifier followed by '#' or '"' or '\'' could be
561+
// interpreted as an invalid literal prefix. We don't bother doing that
562+
// because the treatment of invalid identifiers and invalid prefixes
563+
// would be the same.
564+
InvalidIdent
573565
}
574566

575567
fn c_or_byte_string(

compiler/rustc_parse/src/lexer/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
213213
let ident = Symbol::intern(lifetime_name);
214214
token::Lifetime(ident, IdentIsRaw::No)
215215
}
216-
rustc_lexer::TokenKind::InvalidIdent | rustc_lexer::TokenKind::InvalidPrefix
216+
rustc_lexer::TokenKind::InvalidIdent
217217
// Do not recover an identifier with emoji if the codepoint is a confusable
218218
// with a recoverable substitution token, like `➖`.
219219
if !UNICODE_ARRAY.iter().any(|&(c, _, _)| {
@@ -359,8 +359,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
359359
rustc_lexer::TokenKind::Percent => token::BinOp(token::Percent),
360360

361361
rustc_lexer::TokenKind::Unknown
362-
| rustc_lexer::TokenKind::InvalidIdent
363-
| rustc_lexer::TokenKind::InvalidPrefix => {
362+
| rustc_lexer::TokenKind::InvalidIdent => {
364363
// Don't emit diagnostics for sequences of the same invalid token
365364
if swallow_next_invalid > 0 {
366365
swallow_next_invalid -= 1;

0 commit comments

Comments
 (0)