]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/mut_visit.rs
Rename `ItemKind::Ty` to `ItemKind::TyAlias`
[rust.git] / src / libsyntax / mut_visit.rs
index 7b328e817bf8e36b624686af6ee7aa557f2d09cd..8fac2f30a5146a4a58123cffb1c5e32ebbfaa496 100644 (file)
@@ -22,6 +22,9 @@
 use std::ops::DerefMut;
 use std::{panic, process, ptr};
 
+#[cfg(test)]
+mod tests;
+
 pub trait ExpectOne<A: Array> {
     fn expect_one(self, err: &'static str) -> A::Item;
 }
@@ -844,11 +847,11 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
         ItemKind::Mod(m) => vis.visit_mod(m),
         ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
         ItemKind::GlobalAsm(_ga) => {}
-        ItemKind::Ty(ty, generics) => {
+        ItemKind::TyAlias(ty, generics) => {
             vis.visit_ty(ty);
             vis.visit_generics(generics);
         }
-        ItemKind::Existential(bounds, generics) => {
+        ItemKind::OpaqueTy(bounds, generics) => {
             visit_bounds(bounds, vis);
             vis.visit_generics(generics);
         }
@@ -931,7 +934,7 @@ pub fn noop_flat_map_impl_item<T: MutVisitor>(mut item: ImplItem, visitor: &mut
             visitor.visit_block(body);
         }
         ImplItemKind::Type(ty) => visitor.visit_ty(ty),
-        ImplItemKind::Existential(bounds) => visit_bounds(bounds, visitor),
+        ImplItemKind::OpaqueTy(bounds) => visit_bounds(bounds, visitor),
         ImplItemKind::Macro(mac) => visitor.visit_mac(mac),
     }
     visitor.visit_span(span);
@@ -1255,77 +1258,3 @@ pub fn noop_visit_vis<T: MutVisitor>(Spanned { node, span }: &mut Visibility, vi
     }
     vis.visit_span(span);
 }
-
-#[cfg(test)]
-mod tests {
-    use crate::ast::{self, Ident};
-    use crate::util::parser_testing::{string_to_crate, matches_codepattern};
-    use crate::print::pprust;
-    use crate::mut_visit;
-    use crate::with_default_globals;
-    use super::*;
-
-    // this version doesn't care about getting comments or docstrings in.
-    fn fake_print_crate(s: &mut pprust::State<'_>,
-                        krate: &ast::Crate) {
-        s.print_mod(&krate.module, &krate.attrs)
-    }
-
-    // change every identifier to "zz"
-    struct ToZzIdentMutVisitor;
-
-    impl MutVisitor for ToZzIdentMutVisitor {
-        fn visit_ident(&mut self, ident: &mut ast::Ident) {
-            *ident = Ident::from_str("zz");
-        }
-        fn visit_mac(&mut self, mac: &mut ast::Mac) {
-            mut_visit::noop_visit_mac(mac, self)
-        }
-    }
-
-    // maybe add to expand.rs...
-    macro_rules! assert_pred {
-        ($pred:expr, $predname:expr, $a:expr , $b:expr) => (
-            {
-                let pred_val = $pred;
-                let a_val = $a;
-                let b_val = $b;
-                if !(pred_val(&a_val, &b_val)) {
-                    panic!("expected args satisfying {}, got {} and {}",
-                          $predname, a_val, b_val);
-                }
-            }
-        )
-    }
-
-    // make sure idents get transformed everywhere
-    #[test] fn ident_transformation () {
-        with_default_globals(|| {
-            let mut zz_visitor = ToZzIdentMutVisitor;
-            let mut krate = string_to_crate(
-                "#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}".to_string());
-            zz_visitor.visit_crate(&mut krate);
-            assert_pred!(
-                matches_codepattern,
-                "matches_codepattern",
-                pprust::to_string(|s| fake_print_crate(s, &krate)),
-                "#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string());
-        })
-    }
-
-    // even inside macro defs....
-    #[test] fn ident_transformation_in_defs () {
-        with_default_globals(|| {
-            let mut zz_visitor = ToZzIdentMutVisitor;
-            let mut krate = string_to_crate(
-                "macro_rules! a {(b $c:expr $(d $e:token)f+ => \
-                (g $(d $d $e)+))} ".to_string());
-            zz_visitor.visit_crate(&mut krate);
-            assert_pred!(
-                matches_codepattern,
-                "matches_codepattern",
-                pprust::to_string(|s| fake_print_crate(s, &krate)),
-                "macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
-        })
-    }
-}