Skip to content

Commit

Permalink
Augment stringify.rs test.
Browse files Browse the repository at this point in the history
By adding tests (or placeholders, or comments) for missing AST variants.
  • Loading branch information
nnethercote committed Oct 24, 2023
1 parent f0a2635 commit 2e2e780
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ pub enum RangeSyntax {
}

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

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

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

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

// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum ItemKind {
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
Expand Down
49 changes: 47 additions & 2 deletions tests/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
// edition:2021
// compile-flags: --test

#![allow(incomplete_features)]
#![feature(async_closure)]
#![feature(auto_traits)]
#![feature(box_patterns)]
#![feature(const_trait_impl)]
#![feature(decl_macro)]
#![feature(coroutines)]
#![feature(explicit_tail_calls)]
#![feature(more_qualified_paths)]
#![feature(raw_ref_op)]
#![feature(trait_alias)]
#![feature(try_blocks)]
#![feature(type_ascription)]
#![feature(yeet_expr)]
#![deny(unused_macros)]

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

// ExprKind::ConstBlock
// FIXME: todo

// ExprKind::Call
c1!(expr, [ f() ], "f()");
c2!(expr, [ f::<u8>() ], "f::<u8>()", "f :: < u8 > ()");
Expand Down Expand Up @@ -116,8 +122,10 @@ fn test_expr() {
c1!(expr, [ expr as T ], "expr as T");
c2!(expr, [ expr as T<u8> ], "expr as T<u8>", "expr as T < u8 >");

// ExprKind::Type
// There is no syntax for type ascription.
// ExprKind::Type: there is no syntax for type ascription.

// ExprKind::Let
c1!(expr, [ if let Some(a) = b { c } else { d } ], "if let Some(a) = b { c } else { d }");

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

// ExprKind::Underscore
// FIXME: todo

// ExprKind::Path
c1!(expr, [ thing ], "thing");
c2!(expr, [ m::thing ], "m::thing", "m :: thing");
Expand Down Expand Up @@ -294,6 +305,10 @@ fn test_expr() {
c1!(expr, [ return ], "return");
c1!(expr, [ return true ], "return true");

// ExprKind::InlineAsm: untestable because this test works pre-expansion.

// ExprKind::OffsetOf: untestable because this test works pre-expansion.

// ExprKind::MacCall
c2!(expr, [ mac!(...) ], "mac!(...)", "mac! (...)");
c2!(expr, [ mac![...] ], "mac![...]", "mac! [...]");
Expand Down Expand Up @@ -332,6 +347,20 @@ fn test_expr() {
// ExprKind::Yield
c1!(expr, [ yield ], "yield");
c1!(expr, [ yield true ], "yield true");

// ExprKind::Yeet
c1!(expr, [ do yeet ], "do yeet");
c1!(expr, [ do yeet 0 ], "do yeet 0");

// ExprKind::Become
// FIXME: todo

// ExprKind::IncludedBytes
// FIXME: todo

// ExprKind::FormatArgs: untestable because this test works pre-expansion.

// ExprKind::Err: untestable.
}

#[test]
Expand Down Expand Up @@ -386,6 +415,8 @@ fn test_item() {
"unsafe extern \"C++\" {}"
);

// ItemKind::GlobalAsm: untestable because this test works pre-expansion.

// ItemKind::TyAlias
#[rustfmt::skip]
c2!(item,
Expand Down Expand Up @@ -641,6 +672,7 @@ fn test_stmt() {

// StmtKind::Item
c2!(stmt, [ struct S; ], "struct S;", "struct S ;");
c1!(stmt, [ struct S {} ], "struct S {}");

// StmtKind::Expr
c1!(stmt, [ loop {} ], "loop {}");
Expand Down Expand Up @@ -692,6 +724,10 @@ fn test_ty() {
c1!(ty, [ (T,) ], "(T,)");
c1!(ty, [ (T, U) ], "(T, U)");

// TyKind::AnonStruct: untestable in isolation.

// TyKind::AnonUnion: untestable in isolation.

// TyKind::Path
c1!(ty, [ T ], "T");
c2!(ty, [ Ref<'a> ], "Ref<'a>", "Ref < 'a >");
Expand Down Expand Up @@ -720,13 +756,22 @@ fn test_ty() {
// TyKind::Paren
c1!(ty, [ (T) ], "(T)");

// TyKind::Typeof: unused for now.

// TyKind::Infer
c1!(ty, [ _ ], "_");

// TyKind::ImplicitSelf: there is no syntax for this.

// TyKind::MacCall
c2!(ty, [ mac!(...) ], "mac!(...)", "mac! (...)");
c2!(ty, [ mac![...] ], "mac![...]", "mac! [...]");
c1!(ty, [ mac! { ... } ], "mac! { ... }");

// TyKind::Err: untestable.

// TyKind::CVarArgs
// FIXME: todo
}

#[test]
Expand Down

0 comments on commit 2e2e780

Please sign in to comment.