Change ast::Visibility to Spanned type

This commit is contained in:
Seiichi Uchida 2018-01-29 14:12:09 +09:00
parent 0bddba9248
commit d6bdf296a4
24 changed files with 153 additions and 127 deletions

View File

@ -3362,10 +3362,10 @@ impl<'a> LoweringContext<'a> {
v: &Visibility, v: &Visibility,
explicit_owner: Option<NodeId>) explicit_owner: Option<NodeId>)
-> hir::Visibility { -> hir::Visibility {
match *v { match v.node {
Visibility::Public => hir::Public, VisibilityKind::Public => hir::Public,
Visibility::Crate(..) => hir::Visibility::Crate, VisibilityKind::Crate(..) => hir::Visibility::Crate,
Visibility::Restricted { ref path, id, .. } => { VisibilityKind::Restricted { ref path, id, .. } => {
hir::Visibility::Restricted { hir::Visibility::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit, true)), path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
id: if let Some(owner) = explicit_owner { id: if let Some(owner) = explicit_owner {
@ -3375,7 +3375,7 @@ impl<'a> LoweringContext<'a> {
} }
} }
} }
Visibility::Inherited => hir::Inherited, VisibilityKind::Inherited => hir::Inherited,
} }
} }

View File

@ -13,7 +13,7 @@ use rustc_errors;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast::{Crate, Attribute, LitKind, StrStyle, ExprKind}; use syntax::ast::{Crate, Attribute, LitKind, StrStyle, ExprKind};
use syntax::ast::{Unsafety, Constness, Generics, Mutability, Ty, Mac, Arg}; use syntax::ast::{Unsafety, Constness, Generics, Mutability, Ty, Mac, Arg};
use syntax::ast::{self, Ident, Item, ItemKind, TyKind, Visibility, Expr}; use syntax::ast::{self, Ident, Item, ItemKind, TyKind, VisibilityKind, Expr};
use syntax::attr; use syntax::attr;
use syntax::codemap::dummy_spanned; use syntax::codemap::dummy_spanned;
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute}; use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute};
@ -97,7 +97,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
]); ]);
let mut items = vec![ let mut items = vec![
f.cx.item_extern_crate(f.span, f.alloc), f.cx.item_extern_crate(f.span, f.alloc),
f.cx.item_use_simple(f.span, Visibility::Inherited, super_path), f.cx.item_use_simple(f.span, dummy_spanned(VisibilityKind::Inherited), super_path),
]; ];
for method in ALLOCATOR_METHODS { for method in ALLOCATOR_METHODS {
items.push(f.allocator_fn(method)); items.push(f.allocator_fn(method));

View File

@ -34,6 +34,7 @@ use std::rc::Rc;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::codemap;
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax::parse::filemap_to_stream; use syntax::parse::filemap_to_stream;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
@ -496,7 +497,7 @@ impl CrateStore for cstore::CStore {
tokens: body.into(), tokens: body.into(),
legacy: def.legacy, legacy: def.legacy,
}), }),
vis: ast::Visibility::Inherited, vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited),
tokens: None, tokens: None,
}) })
} }

View File

@ -58,14 +58,14 @@ impl<'a> AstValidator<'a> {
} }
} }
fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) { fn invalid_visibility(&self, vis: &Visibility, note: Option<&str>) {
if vis != &Visibility::Inherited { if vis.node != VisibilityKind::Inherited {
let mut err = struct_span_err!(self.session, let mut err = struct_span_err!(self.session,
span, vis.span,
E0449, E0449,
"unnecessary visibility qualifier"); "unnecessary visibility qualifier");
if vis == &Visibility::Public { if vis.node == VisibilityKind::Public {
err.span_label(span, "`pub` not needed here"); err.span_label(vis.span, "`pub` not needed here");
} }
if let Some(note) = note { if let Some(note) = note {
err.note(note); err.note(note);
@ -216,7 +216,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_item(&mut self, item: &'a Item) { fn visit_item(&mut self, item: &'a Item) {
match item.node { match item.node {
ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => { ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
self.invalid_visibility(&item.vis, item.span, None); self.invalid_visibility(&item.vis, None);
if ty.node == TyKind::Err { if ty.node == TyKind::Err {
self.err_handler() self.err_handler()
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax") .struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
@ -226,7 +226,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
span_err!(self.session, item.span, E0198, "negative impls cannot be unsafe"); span_err!(self.session, item.span, E0198, "negative impls cannot be unsafe");
} }
for impl_item in impl_items { for impl_item in impl_items {
self.invalid_visibility(&impl_item.vis, impl_item.span, None); self.invalid_visibility(&impl_item.vis, None);
if let ImplItemKind::Method(ref sig, _) = impl_item.node { if let ImplItemKind::Method(ref sig, _) = impl_item.node {
self.check_trait_fn_not_const(sig.constness); self.check_trait_fn_not_const(sig.constness);
} }
@ -234,7 +234,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
} }
ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => { ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
self.invalid_visibility(&item.vis, self.invalid_visibility(&item.vis,
item.span,
Some("place qualifiers on individual impl items instead")); Some("place qualifiers on individual impl items instead"));
if unsafety == Unsafety::Unsafe { if unsafety == Unsafety::Unsafe {
span_err!(self.session, item.span, E0197, "inherent impls cannot be unsafe"); span_err!(self.session, item.span, E0197, "inherent impls cannot be unsafe");
@ -247,16 +246,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
} }
} }
ItemKind::ForeignMod(..) => { ItemKind::ForeignMod(..) => {
self.invalid_visibility(&item.vis, self.invalid_visibility(
item.span, &item.vis,
Some("place qualifiers on individual foreign items \ Some("place qualifiers on individual foreign items instead"),
instead")); );
} }
ItemKind::Enum(ref def, _) => { ItemKind::Enum(ref def, _) => {
for variant in &def.variants { for variant in &def.variants {
self.invalid_non_exhaustive_attribute(variant); self.invalid_non_exhaustive_attribute(variant);
for field in variant.node.data.fields() { for field in variant.node.data.fields() {
self.invalid_visibility(&field.vis, field.span, None); self.invalid_visibility(&field.vis, None);
} }
} }
} }
@ -359,8 +358,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
} }
fn visit_vis(&mut self, vis: &'a Visibility) { fn visit_vis(&mut self, vis: &'a Visibility) {
match *vis { match vis.node {
Visibility::Restricted { ref path, .. } => { VisibilityKind::Restricted { ref path, .. } => {
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| {
self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(), self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(),
"generic arguments in visibility path"); "generic arguments in visibility path");

View File

@ -86,7 +86,7 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> {
// because this means that they were generated in some fashion by the // because this means that they were generated in some fashion by the
// compiler and we don't need to consider them. // compiler and we don't need to consider them.
if let ast::ItemKind::Use(..) = item.node { if let ast::ItemKind::Use(..) = item.node {
if item.vis == ast::Visibility::Public || item.span.source_equal(&DUMMY_SP) { if item.vis.node == ast::VisibilityKind::Public || item.span.source_equal(&DUMMY_SP) {
return; return;
} }
} }

View File

@ -3796,13 +3796,15 @@ impl<'a> Resolver<'a> {
} }
fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility { fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility {
match *vis { match vis.node {
ast::Visibility::Public => ty::Visibility::Public, ast::VisibilityKind::Public => ty::Visibility::Public,
ast::Visibility::Crate(..) => ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)), ast::VisibilityKind::Crate(..) => {
ast::Visibility::Inherited => { ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
}
ast::VisibilityKind::Inherited => {
ty::Visibility::Restricted(self.current_module.normal_ancestor_id) ty::Visibility::Restricted(self.current_module.normal_ancestor_id)
} }
ast::Visibility::Restricted { ref path, id, .. } => { ast::VisibilityKind::Restricted { ref path, id, .. } => {
let def = self.smart_resolve_path(id, None, path, let def = self.smart_resolve_path(id, None, path,
PathSource::Visibility).base_def(); PathSource::Visibility).base_def();
if def == Def::Err { if def == Def::Err {

View File

@ -43,7 +43,7 @@ use syntax::print::pprust::{
ty_to_string ty_to_string
}; };
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::{Spanned, DUMMY_SP}; use syntax::codemap::{Spanned, DUMMY_SP, dummy_spanned};
use syntax_pos::*; use syntax_pos::*;
use {escape, generated_code, lower_attributes, PathCollector, SaveContext}; use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
@ -65,12 +65,19 @@ macro_rules! down_cast_data {
} }
macro_rules! access_from { macro_rules! access_from {
($save_ctxt:expr, $vis:expr, $id:expr) => {
Access {
public: $vis.node == ast::VisibilityKind::Public,
reachable: $save_ctxt.analysis.access_levels.is_reachable($id),
}
};
($save_ctxt:expr, $item:expr) => { ($save_ctxt:expr, $item:expr) => {
Access { Access {
public: $item.vis == ast::Visibility::Public, public: $item.vis.node == ast::VisibilityKind::Public,
reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id), reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id),
} }
} };
} }
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> { pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
@ -405,12 +412,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
method_data.value = sig_str; method_data.value = sig_str;
method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt); method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt);
self.dumper.dump_def( self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data);
&Access {
public: vis == ast::Visibility::Public,
reachable: self.save_ctxt.analysis.access_levels.is_reachable(id),
},
method_data);
} }
// walk arg and return types // walk arg and return types
@ -543,10 +545,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
let span = self.span_from_span(sub_span.expect("No span found for variable")); let span = self.span_from_span(sub_span.expect("No span found for variable"));
self.dumper.dump_def( self.dumper.dump_def(
&Access { &access_from!(self.save_ctxt, vis, id),
public: vis == ast::Visibility::Public,
reachable: self.save_ctxt.analysis.access_levels.is_reachable(id),
},
Def { Def {
kind: DefKind::Const, kind: DefKind::Const,
id: ::id_from_node_id(id, &self.save_ctxt), id: ::id_from_node_id(id, &self.save_ctxt),
@ -597,7 +596,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
.iter() .iter()
.enumerate() .enumerate()
.filter_map(|(i, f)| { .filter_map(|(i, f)| {
if include_priv_fields || f.vis == ast::Visibility::Public { if include_priv_fields || f.vis.node == ast::VisibilityKind::Public {
f.ident f.ident
.map(|i| i.to_string()) .map(|i| i.to_string())
.or_else(|| Some(i.to_string())) .or_else(|| Some(i.to_string()))
@ -1144,7 +1143,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
&ty, &ty,
expr.as_ref().map(|e| &**e), expr.as_ref().map(|e| &**e),
trait_id, trait_id,
ast::Visibility::Public, dummy_spanned(ast::VisibilityKind::Public),
&trait_item.attrs, &trait_item.attrs,
); );
} }
@ -1155,7 +1154,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
trait_item.id, trait_item.id,
trait_item.ident, trait_item.ident,
&trait_item.generics, &trait_item.generics,
ast::Visibility::Public, dummy_spanned(ast::VisibilityKind::Public),
trait_item.span, trait_item.span,
); );
} }
@ -1259,10 +1258,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// The access is calculated using the current tree ID, but with the root tree's visibility // The access is calculated using the current tree ID, but with the root tree's visibility
// (since nested trees don't have their own visibility). // (since nested trees don't have their own visibility).
let access = Access { let access = access_from!(self.save_ctxt, root_item.vis, id);
public: root_item.vis == ast::Visibility::Public,
reachable: self.save_ctxt.analysis.access_levels.is_reachable(id),
};
// The parent def id of a given use tree is always the enclosing item. // The parent def id of a given use tree is always the enclosing item.
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(id) let parent = self.save_ctxt.tcx.hir.opt_local_def_id(id)

View File

@ -1937,11 +1937,13 @@ pub enum CrateSugar {
JustCrate, JustCrate,
} }
pub type Visibility = Spanned<VisibilityKind>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Visibility { pub enum VisibilityKind {
Public, Public,
Crate(Span, CrateSugar), Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId, span: Span }, Restricted { path: P<Path>, id: NodeId },
Inherited, Inherited,
} }

View File

@ -14,6 +14,7 @@ use std::env;
use ast; use ast;
use ast::{Ident, Name}; use ast::{Ident, Name};
use codemap;
use syntax_pos::Span; use syntax_pos::Span;
use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::base::{ExtCtxt, MacEager, MacResult};
use ext::build::AstBuilder; use ext::build::AstBuilder;
@ -234,7 +235,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
ty, ty,
expr, expr,
), ),
vis: ast::Visibility::Public, vis: codemap::dummy_spanned(ast::VisibilityKind::Public),
span, span,
tokens: None, tokens: None,
}) })

View File

@ -987,7 +987,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attrs, attrs,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node, node,
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
span, span,
tokens: None, tokens: None,
}) })
@ -1033,7 +1033,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
span: ty.span, span: ty.span,
ty, ty,
ident: None, ident: None,
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
attrs: Vec::new(), attrs: Vec::new(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
} }

View File

@ -11,7 +11,7 @@
use ast::{self, Block, Ident, NodeId, PatKind, Path}; use ast::{self, Block, Ident, NodeId, PatKind, Path};
use ast::{MacStmtStyle, StmtKind, ItemKind}; use ast::{MacStmtStyle, StmtKind, ItemKind};
use attr::{self, HasAttrs}; use attr::{self, HasAttrs};
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned}; use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned, respan};
use config::{is_test_or_bench, StripUnconfigured}; use config::{is_test_or_bench, StripUnconfigured};
use errors::FatalError; use errors::FatalError;
use ext::base::*; use ext::base::*;
@ -238,7 +238,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
node: ast::ItemKind::Mod(krate.module), node: ast::ItemKind::Mod(krate.module),
ident: keywords::Invalid.ident(), ident: keywords::Invalid.ident(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
vis: ast::Visibility::Public, vis: dummy_spanned(ast::VisibilityKind::Public),
tokens: None, tokens: None,
}))); })));
@ -1022,7 +1022,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
// Ensure that test functions are accessible from the test harness. // Ensure that test functions are accessible from the test harness.
ast::ItemKind::Fn(..) if self.cx.ecfg.should_test => { ast::ItemKind::Fn(..) if self.cx.ecfg.should_test => {
if item.attrs.iter().any(|attr| is_test_or_bench(attr)) { if item.attrs.iter().any(|attr| is_test_or_bench(attr)) {
item = item.map(|mut item| { item.vis = ast::Visibility::Public; item }); item = item.map(|mut item| {
item.vis = respan(item.vis.span, ast::VisibilityKind::Public);
item
});
} }
noop_fold_item(item, self) noop_fold_item(item, self)
} }

View File

@ -33,7 +33,7 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion {
let ident = keywords::Invalid.ident(); let ident = keywords::Invalid.ident();
let attrs = Vec::new(); let attrs = Vec::new();
let generics = ast::Generics::default(); let generics = ast::Generics::default();
let vis = ast::Visibility::Inherited; let vis = dummy_spanned(ast::VisibilityKind::Inherited);
let span = DUMMY_SP; let span = DUMMY_SP;
let expr_placeholder = || P(ast::Expr { let expr_placeholder = || P(ast::Expr {
id, span, id, span,

View File

@ -9,6 +9,7 @@
// except according to those terms. // except according to those terms.
use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty}; use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty};
use codemap::dummy_spanned;
use syntax_pos::Span; use syntax_pos::Span;
use ext::base::ExtCtxt; use ext::base::ExtCtxt;
use ext::base; use ext::base;
@ -855,7 +856,12 @@ fn expand_wrapper(cx: &ExtCtxt,
let mut stmts = imports.iter().map(|path| { let mut stmts = imports.iter().map(|path| {
// make item: `use ...;` // make item: `use ...;`
let path = path.iter().map(|s| s.to_string()).collect(); let path = path.iter().map(|s| s.to_string()).collect();
cx.stmt_item(sp, cx.item_use_glob(sp, ast::Visibility::Inherited, ids_ext(path))) let use_item = cx.item_use_glob(
sp,
dummy_spanned(ast::VisibilityKind::Inherited),
ids_ext(path),
);
cx.stmt_item(sp, use_item)
}).chain(Some(stmt_let_ext_cx)).collect::<Vec<_>>(); }).chain(Some(stmt_let_ext_cx)).collect::<Vec<_>>();
stmts.push(cx.stmt_expr(expr)); stmts.push(cx.stmt_expr(expr));

View File

@ -1816,8 +1816,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
} }
fn visit_vis(&mut self, vis: &'a ast::Visibility) { fn visit_vis(&mut self, vis: &'a ast::Visibility) {
if let ast::Visibility::Crate(span, ast::CrateSugar::JustCrate) = *vis { if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node {
gate_feature_post!(&self, crate_visibility_modifier, span, gate_feature_post!(&self, crate_visibility_modifier, vis.span,
"`crate` visibility modifier is experimental"); "`crate` visibility modifier is experimental");
} }
visit::walk_vis(self, vis); visit::walk_vis(self, vis);

View File

@ -21,7 +21,7 @@
use ast::*; use ast::*;
use ast; use ast;
use syntax_pos::Span; use syntax_pos::Span;
use codemap::{Spanned, respan}; use codemap::{Spanned, respan, dummy_spanned};
use parse::token::{self, Token}; use parse::token::{self, Token};
use ptr::P; use ptr::P;
use symbol::keywords; use symbol::keywords;
@ -1018,7 +1018,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
ident: keywords::Invalid.ident(), ident: keywords::Invalid.ident(),
attrs, attrs,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
vis: ast::Visibility::Public, vis: dummy_spanned(ast::VisibilityKind::Public),
span, span,
node: ast::ItemKind::Mod(module), node: ast::ItemKind::Mod(module),
tokens: None, tokens: None,
@ -1367,12 +1367,13 @@ pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVe
} }
pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility { pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility {
match vis { match vis.node {
Visibility::Restricted { path, id, span } => Visibility::Restricted { VisibilityKind::Restricted { path, id } => {
path: path.map(|path| folder.fold_path(path)), respan(vis.span, VisibilityKind::Restricted {
id: folder.new_id(id), path: path.map(|path| folder.fold_path(path)),
span: folder.new_span(span), id: folder.new_id(id),
}, })
}
_ => vis, _ => vis,
} }
} }

View File

@ -932,7 +932,7 @@ mod tests {
span: sp(15,21), span: sp(15,21),
recovered: false, recovered: false,
})), })),
vis: ast::Visibility::Inherited, vis: codemap::dummy_spanned(ast::VisibilityKind::Inherited),
span: sp(0,21)}))); span: sp(0,21)})));
} }

View File

@ -36,7 +36,7 @@ use ast::StrStyle;
use ast::SelfKind; use ast::SelfKind;
use ast::{TraitItem, TraitRef, TraitObjectSyntax}; use ast::{TraitItem, TraitRef, TraitObjectSyntax};
use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds};
use ast::{Visibility, WhereClause, CrateSugar}; use ast::{Visibility, VisibilityKind, WhereClause, CrateSugar};
use ast::{UseTree, UseTreeKind}; use ast::{UseTree, UseTreeKind};
use ast::{BinOpKind, UnOp}; use ast::{BinOpKind, UnOp};
use ast::{RangeEnd, RangeSyntax}; use ast::{RangeEnd, RangeSyntax};
@ -4132,7 +4132,7 @@ impl<'a> Parser<'a> {
token::Ident(ident) if ident.name == "macro_rules" && token::Ident(ident) if ident.name == "macro_rules" &&
self.look_ahead(1, |t| *t == token::Not) => { self.look_ahead(1, |t| *t == token::Not) => {
let prev_span = self.prev_span; let prev_span = self.prev_span;
self.complain_if_pub_macro(vis, prev_span); self.complain_if_pub_macro(&vis.node, prev_span);
self.bump(); self.bump();
self.bump(); self.bump();
@ -4169,7 +4169,11 @@ impl<'a> Parser<'a> {
node: StmtKind::Local(self.parse_local(attrs.into())?), node: StmtKind::Local(self.parse_local(attrs.into())?),
span: lo.to(self.prev_span), span: lo.to(self.prev_span),
} }
} else if let Some(macro_def) = self.eat_macro_def(&attrs, &Visibility::Inherited, lo)? { } else if let Some(macro_def) = self.eat_macro_def(
&attrs,
&codemap::respan(lo, VisibilityKind::Inherited),
lo,
)? {
Stmt { Stmt {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: StmtKind::Item(macro_def), node: StmtKind::Item(macro_def),
@ -4296,7 +4300,7 @@ impl<'a> Parser<'a> {
self.mk_item( self.mk_item(
span, id /*id is good here*/, span, id /*id is good here*/,
ItemKind::Mac(respan(span, Mac_ { path: pth, tts: tts })), ItemKind::Mac(respan(span, Mac_ { path: pth, tts: tts })),
Visibility::Inherited, respan(lo, VisibilityKind::Inherited),
attrs) attrs)
}), }),
} }
@ -5213,15 +5217,15 @@ impl<'a> Parser<'a> {
}) })
} }
fn complain_if_pub_macro(&mut self, vis: &Visibility, sp: Span) { fn complain_if_pub_macro(&mut self, vis: &VisibilityKind, sp: Span) {
if let Err(mut err) = self.complain_if_pub_macro_diag(vis, sp) { if let Err(mut err) = self.complain_if_pub_macro_diag(vis, sp) {
err.emit(); err.emit();
} }
} }
fn complain_if_pub_macro_diag(&mut self, vis: &Visibility, sp: Span) -> PResult<'a, ()> { fn complain_if_pub_macro_diag(&mut self, vis: &VisibilityKind, sp: Span) -> PResult<'a, ()> {
match *vis { match *vis {
Visibility::Inherited => Ok(()), VisibilityKind::Inherited => Ok(()),
_ => { _ => {
let is_macro_rules: bool = match self.token { let is_macro_rules: bool = match self.token {
token::Ident(sid) => sid.name == Symbol::intern("macro_rules"), token::Ident(sid) => sid.name == Symbol::intern("macro_rules"),
@ -5283,7 +5287,7 @@ impl<'a> Parser<'a> {
self.expect(&token::Not)?; self.expect(&token::Not)?;
} }
self.complain_if_pub_macro(vis, prev_span); self.complain_if_pub_macro(&vis.node, prev_span);
// eat a matched-delimiter token tree: // eat a matched-delimiter token tree:
*at_end = true; *at_end = true;
@ -5686,12 +5690,13 @@ impl<'a> Parser<'a> {
self.expected_tokens.push(TokenType::Keyword(keywords::Crate)); self.expected_tokens.push(TokenType::Keyword(keywords::Crate));
if self.is_crate_vis() { if self.is_crate_vis() {
self.bump(); // `crate` self.bump(); // `crate`
return Ok(Visibility::Crate(self.prev_span, CrateSugar::JustCrate)); return Ok(respan(self.prev_span, VisibilityKind::Crate(CrateSugar::JustCrate)));
} }
if !self.eat_keyword(keywords::Pub) { if !self.eat_keyword(keywords::Pub) {
return Ok(Visibility::Inherited) return Ok(respan(self.prev_span, VisibilityKind::Inherited))
} }
let lo = self.prev_span;
if self.check(&token::OpenDelim(token::Paren)) { if self.check(&token::OpenDelim(token::Paren)) {
// We don't `self.bump()` the `(` yet because this might be a struct definition where // We don't `self.bump()` the `(` yet because this might be a struct definition where
@ -5703,7 +5708,10 @@ impl<'a> Parser<'a> {
self.bump(); // `(` self.bump(); // `(`
self.bump(); // `crate` self.bump(); // `crate`
self.expect(&token::CloseDelim(token::Paren))?; // `)` self.expect(&token::CloseDelim(token::Paren))?; // `)`
let vis = Visibility::Crate(self.prev_span, CrateSugar::PubCrate); let vis = respan(
lo.to(self.prev_span),
VisibilityKind::Crate(CrateSugar::PubCrate),
);
return Ok(vis) return Ok(vis)
} else if self.look_ahead(1, |t| t.is_keyword(keywords::In)) { } else if self.look_ahead(1, |t| t.is_keyword(keywords::In)) {
// `pub(in path)` // `pub(in path)`
@ -5711,11 +5719,10 @@ impl<'a> Parser<'a> {
self.bump(); // `in` self.bump(); // `in`
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `path` let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `path`
self.expect(&token::CloseDelim(token::Paren))?; // `)` self.expect(&token::CloseDelim(token::Paren))?; // `)`
let vis = Visibility::Restricted { let vis = respan(lo.to(self.prev_span), VisibilityKind::Restricted {
path: P(path), path: P(path),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: self.prev_span, });
};
return Ok(vis) return Ok(vis)
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) && } else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Super) || self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
@ -5725,11 +5732,10 @@ impl<'a> Parser<'a> {
self.bump(); // `(` self.bump(); // `(`
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `super`/`self` let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `super`/`self`
self.expect(&token::CloseDelim(token::Paren))?; // `)` self.expect(&token::CloseDelim(token::Paren))?; // `)`
let vis = Visibility::Restricted { let vis = respan(lo.to(self.prev_span), VisibilityKind::Restricted {
path: P(path), path: P(path),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: self.prev_span, });
};
return Ok(vis) return Ok(vis)
} else if !can_take_tuple { // Provide this diagnostic if this is not a tuple struct } else if !can_take_tuple { // Provide this diagnostic if this is not a tuple struct
// `pub(something) fn ...` or `struct X { pub(something) y: Z }` // `pub(something) fn ...` or `struct X { pub(something) y: Z }`
@ -5749,7 +5755,7 @@ impl<'a> Parser<'a> {
} }
} }
Ok(Visibility::Public) Ok(respan(lo, VisibilityKind::Public))
} }
/// Parse defaultness: `default` or nothing. /// Parse defaultness: `default` or nothing.
@ -6582,7 +6588,7 @@ impl<'a> Parser<'a> {
// Verify wether we have encountered a struct or method definition where the user forgot to // Verify wether we have encountered a struct or method definition where the user forgot to
// add the `struct` or `fn` keyword after writing `pub`: `pub S {}` // add the `struct` or `fn` keyword after writing `pub`: `pub S {}`
if visibility == Visibility::Public && if visibility.node == VisibilityKind::Public &&
self.check_ident() && self.check_ident() &&
self.look_ahead(1, |t| *t != token::Not) self.look_ahead(1, |t| *t != token::Not)
{ {
@ -6690,7 +6696,7 @@ impl<'a> Parser<'a> {
// MACRO INVOCATION ITEM // MACRO INVOCATION ITEM
let prev_span = self.prev_span; let prev_span = self.prev_span;
self.complain_if_pub_macro(&visibility, prev_span); self.complain_if_pub_macro(&visibility.node, prev_span);
let mac_lo = self.span; let mac_lo = self.span;
@ -6724,8 +6730,8 @@ impl<'a> Parser<'a> {
} }
// FAILURE TO PARSE ITEM // FAILURE TO PARSE ITEM
match visibility { match visibility.node {
Visibility::Inherited => {} VisibilityKind::Inherited => {}
_ => { _ => {
return Err(self.span_fatal(self.prev_span, "unmatched visibility `pub`")); return Err(self.span_fatal(self.prev_span, "unmatched visibility `pub`"));
} }

View File

@ -377,7 +377,7 @@ pub fn fun_to_string(decl: &ast::FnDecl,
to_string(|s| { to_string(|s| {
s.head("")?; s.head("")?;
s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name),
generics, &ast::Visibility::Inherited)?; generics, &codemap::dummy_spanned(ast::VisibilityKind::Inherited))?;
s.end()?; // Close the head box s.end()?; // Close the head box
s.end() // Close the outer box s.end() // Close the outer box
}) })
@ -1458,13 +1458,13 @@ impl<'a> State<'a> {
} }
pub fn print_visibility(&mut self, vis: &ast::Visibility) -> io::Result<()> { pub fn print_visibility(&mut self, vis: &ast::Visibility) -> io::Result<()> {
match *vis { match vis.node {
ast::Visibility::Public => self.word_nbsp("pub"), ast::VisibilityKind::Public => self.word_nbsp("pub"),
ast::Visibility::Crate(_, sugar) => match sugar { ast::VisibilityKind::Crate(sugar) => match sugar {
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"), ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
ast::CrateSugar::JustCrate => self.word_nbsp("crate") ast::CrateSugar::JustCrate => self.word_nbsp("crate")
} }
ast::Visibility::Restricted { ref path, .. } => { ast::VisibilityKind::Restricted { ref path, .. } => {
let path = to_string(|s| s.print_path(path, false, 0, true)); let path = to_string(|s| s.print_path(path, false, 0, true));
if path == "self" || path == "super" { if path == "self" || path == "super" {
self.word_nbsp(&format!("pub({})", path)) self.word_nbsp(&format!("pub({})", path))
@ -1472,7 +1472,7 @@ impl<'a> State<'a> {
self.word_nbsp(&format!("pub(in {})", path)) self.word_nbsp(&format!("pub(in {})", path))
} }
} }
ast::Visibility::Inherited => Ok(()) ast::VisibilityKind::Inherited => Ok(())
} }
} }
@ -1569,15 +1569,23 @@ impl<'a> State<'a> {
self.print_outer_attributes(&ti.attrs)?; self.print_outer_attributes(&ti.attrs)?;
match ti.node { match ti.node {
ast::TraitItemKind::Const(ref ty, ref default) => { ast::TraitItemKind::Const(ref ty, ref default) => {
self.print_associated_const(ti.ident, ty, self.print_associated_const(
default.as_ref().map(|expr| &**expr), ti.ident,
&ast::Visibility::Inherited)?; ty,
default.as_ref().map(|expr| &**expr),
&codemap::dummy_spanned(ast::VisibilityKind::Inherited),
)?;
} }
ast::TraitItemKind::Method(ref sig, ref body) => { ast::TraitItemKind::Method(ref sig, ref body) => {
if body.is_some() { if body.is_some() {
self.head("")?; self.head("")?;
} }
self.print_method_sig(ti.ident, &ti.generics, sig, &ast::Visibility::Inherited)?; self.print_method_sig(
ti.ident,
&ti.generics,
sig,
&codemap::dummy_spanned(ast::VisibilityKind::Inherited),
)?;
if let Some(ref body) = *body { if let Some(ref body) = *body {
self.nbsp()?; self.nbsp()?;
self.print_block_with_attrs(body, &ti.attrs)?; self.print_block_with_attrs(body, &ti.attrs)?;
@ -3055,7 +3063,7 @@ impl<'a> State<'a> {
abi, abi,
name, name,
&generics, &generics,
&ast::Visibility::Inherited)?; &codemap::dummy_spanned(ast::VisibilityKind::Inherited))?;
self.end() self.end()
} }

View File

@ -14,7 +14,7 @@ use std::cell::Cell;
use ext::hygiene::{Mark, SyntaxContext}; use ext::hygiene::{Mark, SyntaxContext};
use symbol::{Symbol, keywords}; use symbol::{Symbol, keywords};
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute}; use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned};
use ptr::P; use ptr::P;
use tokenstream::TokenStream; use tokenstream::TokenStream;
@ -60,7 +60,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<Strin
attrs: vec![attr::mk_attr_outer(DUMMY_SP, attrs: vec![attr::mk_attr_outer(DUMMY_SP,
attr::mk_attr_id(), attr::mk_attr_id(),
attr::mk_word_item(Symbol::intern("macro_use")))], attr::mk_word_item(Symbol::intern("macro_use")))],
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::ExternCrate(Some(crate_name)), node: ast::ItemKind::ExternCrate(Some(crate_name)),
ident: ast::Ident::from_str(name), ident: ast::Ident::from_str(name),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
@ -78,7 +78,7 @@ pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<Strin
is_sugared_doc: false, is_sugared_doc: false,
span, span,
}], }],
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
node: ast::ItemKind::Use(P(ast::UseTree { node: ast::ItemKind::Use(P(ast::UseTree {
prefix: ast::Path { prefix: ast::Path {
segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| { segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| {

View File

@ -233,11 +233,11 @@ fn mk_reexport_mod(cx: &mut TestCtxt,
let super_ = Ident::from_str("super"); let super_ = Ident::from_str("super");
let items = tests.into_iter().map(|r| { let items = tests.into_iter().map(|r| {
cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public, cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),
cx.ext_cx.path(DUMMY_SP, vec![super_, r])) cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
}).chain(tested_submods.into_iter().map(|(r, sym)| { }).chain(tested_submods.into_iter().map(|(r, sym)| {
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]); let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Visibility::Public, r, path) cx.ext_cx.item_use_simple_(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public), r, path)
})).collect(); })).collect();
let reexport_mod = ast::Mod { let reexport_mod = ast::Mod {
@ -253,7 +253,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt,
attrs: Vec::new(), attrs: Vec::new(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::Mod(reexport_mod), node: ast::ItemKind::Mod(reexport_mod),
vis: ast::Visibility::Public, vis: dummy_spanned(ast::VisibilityKind::Public),
span: DUMMY_SP, span: DUMMY_SP,
tokens: None, tokens: None,
})).pop().unwrap(); })).pop().unwrap();
@ -462,16 +462,16 @@ fn mk_std(cx: &TestCtxt) -> P<ast::Item> {
prefix: path_node(vec![id_test]), prefix: path_node(vec![id_test]),
kind: ast::UseTreeKind::Simple(id_test), kind: ast::UseTreeKind::Simple(id_test),
})), })),
ast::Visibility::Public, keywords::Invalid.ident()) ast::VisibilityKind::Public, keywords::Invalid.ident())
} else { } else {
(ast::ItemKind::ExternCrate(None), ast::Visibility::Inherited, id_test) (ast::ItemKind::ExternCrate(None), ast::VisibilityKind::Inherited, id_test)
}; };
P(ast::Item { P(ast::Item {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
ident, ident,
node: vi, node: vi,
attrs: vec![], attrs: vec![],
vis, vis: dummy_spanned(vis),
span: sp, span: sp,
tokens: None, tokens: None,
}) })
@ -513,7 +513,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
attrs: vec![main_attr], attrs: vec![main_attr],
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: main, node: main,
vis: ast::Visibility::Public, vis: dummy_spanned(ast::VisibilityKind::Public),
span: sp, span: sp,
tokens: None, tokens: None,
}) })
@ -543,7 +543,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) {
ident: mod_ident, ident: mod_ident,
attrs: vec![], attrs: vec![],
node: item_, node: item_,
vis: ast::Visibility::Public, vis: dummy_spanned(ast::VisibilityKind::Public),
span: DUMMY_SP, span: DUMMY_SP,
tokens: None, tokens: None,
})).pop().unwrap(); })).pop().unwrap();
@ -562,7 +562,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) {
ident: keywords::Invalid.ident(), ident: keywords::Invalid.ident(),
attrs: vec![], attrs: vec![],
node: ast::ItemKind::Use(P(use_path)), node: ast::ItemKind::Use(P(use_path)),
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
span: DUMMY_SP, span: DUMMY_SP,
tokens: None, tokens: None,
})).pop().unwrap() })).pop().unwrap()

View File

@ -811,7 +811,7 @@ pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
} }
pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) { pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
if let Visibility::Restricted { ref path, id, .. } = *vis { if let VisibilityKind::Restricted { ref path, id } = vis.node {
visitor.visit_path(path, id); visitor.visit_path(path, id);
} }
} }

View File

@ -530,7 +530,7 @@ impl<'a> TraitDef<'a> {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: self.span, span: self.span,
ident, ident,
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final, defaultness: ast::Defaultness::Final,
attrs: Vec::new(), attrs: Vec::new(),
generics: Generics::default(), generics: Generics::default(),
@ -977,7 +977,7 @@ impl<'a> MethodDef<'a> {
attrs: self.attributes.clone(), attrs: self.attributes.clone(),
generics: fn_generics, generics: fn_generics,
span: trait_.span, span: trait_.span,
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final, defaultness: ast::Defaultness::Final,
ident: method_ident, ident: method_ident,
node: ast::ImplItemKind::Method(ast::MethodSig { node: ast::ImplItemKind::Method(ast::MethodSig {

View File

@ -19,6 +19,7 @@
/// therefore apply. /// therefore apply.
use syntax::ast; use syntax::ast;
use syntax::codemap::dummy_spanned;
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::feature_gate; use syntax::feature_gate;
@ -59,7 +60,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
asm, asm,
ctxt: cx.backtrace(), ctxt: cx.backtrace(),
})), })),
vis: ast::Visibility::Inherited, vis: dummy_spanned(ast::VisibilityKind::Inherited),
span: sp, span: sp,
tokens: None, tokens: None,
}))) })))

View File

@ -14,7 +14,7 @@ use errors;
use syntax::ast::{self, Ident, NodeId}; use syntax::ast::{self, Ident, NodeId};
use syntax::attr; use syntax::attr;
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute}; use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, respan};
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig; use syntax::ext::expand::ExpansionConfig;
@ -103,7 +103,7 @@ impl<'a> CollectProcMacros<'a> {
fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) { fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
if self.is_proc_macro_crate && if self.is_proc_macro_crate &&
self.in_root && self.in_root &&
*vis == ast::Visibility::Public { vis.node == ast::VisibilityKind::Public {
self.handler.span_err(sp, self.handler.span_err(sp,
"`proc-macro` crate types cannot \ "`proc-macro` crate types cannot \
export any items other than functions \ export any items other than functions \
@ -181,7 +181,7 @@ impl<'a> CollectProcMacros<'a> {
Vec::new() Vec::new()
}; };
if self.in_root && item.vis == ast::Visibility::Public { if self.in_root && item.vis.node == ast::VisibilityKind::Public {
self.derives.push(ProcMacroDerive { self.derives.push(ProcMacroDerive {
span: item.span, span: item.span,
trait_name, trait_name,
@ -206,7 +206,7 @@ impl<'a> CollectProcMacros<'a> {
return; return;
} }
if self.in_root && item.vis == ast::Visibility::Public { if self.in_root && item.vis.node == ast::VisibilityKind::Public {
self.attr_macros.push(ProcMacroDef { self.attr_macros.push(ProcMacroDef {
span: item.span, span: item.span,
function_name: item.ident, function_name: item.ident,
@ -229,7 +229,7 @@ impl<'a> CollectProcMacros<'a> {
return; return;
} }
if self.in_root && item.vis == ast::Visibility::Public { if self.in_root && item.vis.node == ast::VisibilityKind::Public {
self.bang_macros.push(ProcMacroDef { self.bang_macros.push(ProcMacroDef {
span: item.span, span: item.span,
function_name: item.ident, function_name: item.ident,
@ -439,12 +439,12 @@ fn mk_registrar(cx: &mut ExtCtxt,
let derive_registrar = cx.attribute(span, derive_registrar); let derive_registrar = cx.attribute(span, derive_registrar);
let func = func.map(|mut i| { let func = func.map(|mut i| {
i.attrs.push(derive_registrar); i.attrs.push(derive_registrar);
i.vis = ast::Visibility::Public; i.vis = respan(span, ast::VisibilityKind::Public);
i i
}); });
let ident = ast::Ident::with_empty_ctxt(Symbol::gensym("registrar")); let ident = ast::Ident::with_empty_ctxt(Symbol::gensym("registrar"));
let module = cx.item_mod(span, span, ident, Vec::new(), vec![krate, func]).map(|mut i| { let module = cx.item_mod(span, span, ident, Vec::new(), vec![krate, func]).map(|mut i| {
i.vis = ast::Visibility::Public; i.vis = respan(span, ast::VisibilityKind::Public);
i i
}); });