
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use rustc_ast as ast;
|
|
use rustc_span::{DUMMY_SP, Ident, create_default_session_globals_then};
|
|
use thin_vec::ThinVec;
|
|
|
|
use super::*;
|
|
|
|
fn fun_to_string(
|
|
decl: &ast::FnDecl,
|
|
header: ast::FnHeader,
|
|
name: Ident,
|
|
generics: &ast::Generics,
|
|
) -> String {
|
|
to_string(|s| {
|
|
s.head("");
|
|
s.print_fn(decl, header, Some(name), generics);
|
|
s.end(); // Close the head box.
|
|
s.end(); // Close the outer box.
|
|
})
|
|
}
|
|
|
|
fn variant_to_string(var: &ast::Variant) -> String {
|
|
to_string(|s| s.print_variant(var))
|
|
}
|
|
|
|
#[test]
|
|
fn test_fun_to_string() {
|
|
create_default_session_globals_then(|| {
|
|
let abba_ident = Ident::from_str("abba");
|
|
|
|
let decl = ast::FnDecl { inputs: ThinVec::new(), output: ast::FnRetTy::Default(DUMMY_SP) };
|
|
let generics = ast::Generics::default();
|
|
assert_eq!(
|
|
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
|
|
"fn abba()"
|
|
);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn test_variant_to_string() {
|
|
create_default_session_globals_then(|| {
|
|
let ident = Ident::from_str("principal_skinner");
|
|
|
|
let var = ast::Variant {
|
|
ident,
|
|
vis: ast::Visibility {
|
|
span: DUMMY_SP,
|
|
kind: ast::VisibilityKind::Inherited,
|
|
tokens: None,
|
|
},
|
|
attrs: ast::AttrVec::new(),
|
|
id: ast::DUMMY_NODE_ID,
|
|
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
|
|
disr_expr: None,
|
|
span: DUMMY_SP,
|
|
is_placeholder: false,
|
|
};
|
|
|
|
let varstr = variant_to_string(&var);
|
|
assert_eq!(varstr, "principal_skinner");
|
|
})
|
|
}
|