Skip to content

Commit 2e2e780

Browse files
committed
Augment stringify.rs test.
By adding tests (or placeholders, or comments) for missing AST variants.
1 parent f0a2635 commit 2e2e780

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

compiler/rustc_ast/src/ast.rs

+7
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ pub enum RangeSyntax {
734734
}
735735

736736
/// All the different flavors of pattern that Rust recognizes.
737+
//
738+
// Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`.
737739
#[derive(Clone, Encodable, Decodable, Debug)]
738740
pub enum PatKind {
739741
/// Represents a wildcard pattern (`_`).
@@ -967,6 +969,7 @@ impl Stmt {
967969
}
968970
}
969971

972+
// Adding a new variant? Please update `test_stmt` in `tests/ui/macros/stringify.rs`.
970973
#[derive(Clone, Encodable, Decodable, Debug)]
971974
pub enum StmtKind {
972975
/// A local (let) binding.
@@ -1345,6 +1348,7 @@ pub struct StructExpr {
13451348
pub rest: StructRest,
13461349
}
13471350

1351+
// Adding a new variant? Please update `test_expr` in `tests/ui/macros/stringify.rs`.
13481352
#[derive(Clone, Encodable, Decodable, Debug)]
13491353
pub enum ExprKind {
13501354
/// An array (`[a, b, c, d]`)
@@ -2015,6 +2019,8 @@ pub struct BareFnTy {
20152019
}
20162020

20172021
/// The various kinds of type recognized by the compiler.
2022+
//
2023+
// Adding a new variant? Please update `test_ty` in `tests/ui/macros/stringify.rs`.
20182024
#[derive(Clone, Encodable, Decodable, Debug)]
20192025
pub enum TyKind {
20202026
/// A variable-length slice (`[T]`).
@@ -2880,6 +2886,7 @@ pub struct ConstItem {
28802886
pub expr: Option<P<Expr>>,
28812887
}
28822888

2889+
// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
28832890
#[derive(Clone, Encodable, Decodable, Debug)]
28842891
pub enum ItemKind {
28852892
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.

tests/ui/macros/stringify.rs

+47-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
// edition:2021
33
// compile-flags: --test
44

5+
#![allow(incomplete_features)]
56
#![feature(async_closure)]
67
#![feature(auto_traits)]
78
#![feature(box_patterns)]
89
#![feature(const_trait_impl)]
910
#![feature(decl_macro)]
1011
#![feature(coroutines)]
12+
#![feature(explicit_tail_calls)]
1113
#![feature(more_qualified_paths)]
1214
#![feature(raw_ref_op)]
1315
#![feature(trait_alias)]
1416
#![feature(try_blocks)]
1517
#![feature(type_ascription)]
18+
#![feature(yeet_expr)]
1619
#![deny(unused_macros)]
1720

1821
// These macros force the use of AST pretty-printing by converting the input to
@@ -79,6 +82,9 @@ fn test_expr() {
7982
c2!(expr, [ [true,] ], "[true]", "[true,]");
8083
c1!(expr, [ [true, true] ], "[true, true]");
8184

85+
// ExprKind::ConstBlock
86+
// FIXME: todo
87+
8288
// ExprKind::Call
8389
c1!(expr, [ f() ], "f()");
8490
c2!(expr, [ f::<u8>() ], "f::<u8>()", "f :: < u8 > ()");
@@ -116,8 +122,10 @@ fn test_expr() {
116122
c1!(expr, [ expr as T ], "expr as T");
117123
c2!(expr, [ expr as T<u8> ], "expr as T<u8>", "expr as T < u8 >");
118124

119-
// ExprKind::Type
120-
// There is no syntax for type ascription.
125+
// ExprKind::Type: there is no syntax for type ascription.
126+
127+
// ExprKind::Let
128+
c1!(expr, [ if let Some(a) = b { c } else { d } ], "if let Some(a) = b { c } else { d }");
121129

122130
// ExprKind::If
123131
c1!(expr, [ if true {} ], "if true {}");
@@ -265,6 +273,9 @@ fn test_expr() {
265273
c2!(expr, [ lo..=hi ], "lo..=hi", "lo ..= hi");
266274
c2!(expr, [ -2..=-1 ], "-2..=-1", "- 2 ..= - 1");
267275

276+
// ExprKind::Underscore
277+
// FIXME: todo
278+
268279
// ExprKind::Path
269280
c1!(expr, [ thing ], "thing");
270281
c2!(expr, [ m::thing ], "m::thing", "m :: thing");
@@ -294,6 +305,10 @@ fn test_expr() {
294305
c1!(expr, [ return ], "return");
295306
c1!(expr, [ return true ], "return true");
296307

308+
// ExprKind::InlineAsm: untestable because this test works pre-expansion.
309+
310+
// ExprKind::OffsetOf: untestable because this test works pre-expansion.
311+
297312
// ExprKind::MacCall
298313
c2!(expr, [ mac!(...) ], "mac!(...)", "mac! (...)");
299314
c2!(expr, [ mac![...] ], "mac![...]", "mac! [...]");
@@ -332,6 +347,20 @@ fn test_expr() {
332347
// ExprKind::Yield
333348
c1!(expr, [ yield ], "yield");
334349
c1!(expr, [ yield true ], "yield true");
350+
351+
// ExprKind::Yeet
352+
c1!(expr, [ do yeet ], "do yeet");
353+
c1!(expr, [ do yeet 0 ], "do yeet 0");
354+
355+
// ExprKind::Become
356+
// FIXME: todo
357+
358+
// ExprKind::IncludedBytes
359+
// FIXME: todo
360+
361+
// ExprKind::FormatArgs: untestable because this test works pre-expansion.
362+
363+
// ExprKind::Err: untestable.
335364
}
336365

337366
#[test]
@@ -386,6 +415,8 @@ fn test_item() {
386415
"unsafe extern \"C++\" {}"
387416
);
388417

418+
// ItemKind::GlobalAsm: untestable because this test works pre-expansion.
419+
389420
// ItemKind::TyAlias
390421
#[rustfmt::skip]
391422
c2!(item,
@@ -641,6 +672,7 @@ fn test_stmt() {
641672

642673
// StmtKind::Item
643674
c2!(stmt, [ struct S; ], "struct S;", "struct S ;");
675+
c1!(stmt, [ struct S {} ], "struct S {}");
644676

645677
// StmtKind::Expr
646678
c1!(stmt, [ loop {} ], "loop {}");
@@ -692,6 +724,10 @@ fn test_ty() {
692724
c1!(ty, [ (T,) ], "(T,)");
693725
c1!(ty, [ (T, U) ], "(T, U)");
694726

727+
// TyKind::AnonStruct: untestable in isolation.
728+
729+
// TyKind::AnonUnion: untestable in isolation.
730+
695731
// TyKind::Path
696732
c1!(ty, [ T ], "T");
697733
c2!(ty, [ Ref<'a> ], "Ref<'a>", "Ref < 'a >");
@@ -720,13 +756,22 @@ fn test_ty() {
720756
// TyKind::Paren
721757
c1!(ty, [ (T) ], "(T)");
722758

759+
// TyKind::Typeof: unused for now.
760+
723761
// TyKind::Infer
724762
c1!(ty, [ _ ], "_");
763+
764+
// TyKind::ImplicitSelf: there is no syntax for this.
725765

726766
// TyKind::MacCall
727767
c2!(ty, [ mac!(...) ], "mac!(...)", "mac! (...)");
728768
c2!(ty, [ mac![...] ], "mac![...]", "mac! [...]");
729769
c1!(ty, [ mac! { ... } ], "mac! { ... }");
770+
771+
// TyKind::Err: untestable.
772+
773+
// TyKind::CVarArgs
774+
// FIXME: todo
730775
}
731776

732777
#[test]

0 commit comments

Comments
 (0)