1 use crate::tests
::{matches_codepattern, string_to_crate}
;
3 use rustc_ast
::ast
::{self, Ident}
;
4 use rustc_ast
::mut_visit
::{self, MutVisitor}
;
5 use rustc_ast
::with_default_globals
;
6 use rustc_ast_pretty
::pprust
;
8 // This version doesn't care about getting comments or doc-strings in.
9 fn fake_print_crate(s
: &mut pprust
::State
<'_
>, krate
: &ast
::Crate
) {
10 s
.print_mod(&krate
.module
, &krate
.attrs
)
13 // Change every identifier to "zz".
14 struct ToZzIdentMutVisitor
;
16 impl MutVisitor
for ToZzIdentMutVisitor
{
17 fn visit_ident(&mut self, ident
: &mut ast
::Ident
) {
18 *ident
= Ident
::from_str("zz");
20 fn visit_mac(&mut self, mac
: &mut ast
::MacCall
) {
21 mut_visit
::noop_visit_mac(mac
, self)
25 // Maybe add to `expand.rs`.
26 macro_rules
! assert_pred
{
27 ($pred
:expr
, $predname
:expr
, $a
:expr
, $b
:expr
) => {{
31 if !(pred_val(&a_val
, &b_val
)) {
32 panic
!("expected args satisfying {}, got {} and {}", $predname
, a_val
, b_val
);
37 // Make sure idents get transformed everywhere.
39 fn ident_transformation() {
40 with_default_globals(|| {
41 let mut zz_visitor
= ToZzIdentMutVisitor
;
43 string_to_crate("#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
44 zz_visitor
.visit_crate(&mut krate
);
47 "matches_codepattern",
48 pprust
::to_string(|s
| fake_print_crate(s
, &krate
)),
49 "#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string()
54 // Make sure idents get transformed even inside macro defs.
56 fn ident_transformation_in_defs() {
57 with_default_globals(|| {
58 let mut zz_visitor
= ToZzIdentMutVisitor
;
59 let mut krate
= string_to_crate(
60 "macro_rules! a {(b $c:expr $(d $e:token)f+ => \
64 zz_visitor
.visit_crate(&mut krate
);
67 "matches_codepattern",
68 pprust
::to_string(|s
| fake_print_crate(s
, &krate
)),
69 "macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string()