Syntactically permit unsafety on mods
This commit is contained in:
parent
25b2f48612
commit
fd4dd00dde
17 changed files with 284 additions and 37 deletions
|
@ -2289,12 +2289,15 @@ impl FnRetTy {
|
|||
/// Module declaration.
|
||||
///
|
||||
/// E.g., `mod foo;` or `mod foo { .. }`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Default)]
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct Mod {
|
||||
/// A span from the first token past `{` to the last token until `}`.
|
||||
/// For `mod foo;`, the inner span ranges from the first token
|
||||
/// to the last token in the external file.
|
||||
pub inner: Span,
|
||||
/// `unsafe` keyword accepted syntactically for macro DSLs, but not
|
||||
/// semantically by Rust.
|
||||
pub unsafety: Unsafe,
|
||||
pub items: Vec<P<Item>>,
|
||||
/// `true` for `mod foo { .. }`; `false` for `mod foo;`.
|
||||
pub inline: bool,
|
||||
|
@ -2302,9 +2305,12 @@ pub struct Mod {
|
|||
|
||||
/// Foreign module declaration.
|
||||
///
|
||||
/// E.g., `extern { .. }` or `extern C { .. }`.
|
||||
/// E.g., `extern { .. }` or `extern "C" { .. }`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct ForeignMod {
|
||||
/// `unsafe` keyword accepted syntactically for macro DSLs, but not
|
||||
/// semantically by Rust.
|
||||
pub unsafety: Unsafe,
|
||||
pub abi: Option<StrLit>,
|
||||
pub items: Vec<P<ForeignItem>>,
|
||||
}
|
||||
|
|
|
@ -490,7 +490,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
|||
}
|
||||
|
||||
pub fn noop_visit_foreign_mod<T: MutVisitor>(foreign_mod: &mut ForeignMod, vis: &mut T) {
|
||||
let ForeignMod { abi: _, items } = foreign_mod;
|
||||
let ForeignMod { unsafety: _, abi: _, items } = foreign_mod;
|
||||
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
|
||||
}
|
||||
|
||||
|
@ -970,7 +970,8 @@ pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
|
|||
vis.visit_asyncness(asyncness);
|
||||
}
|
||||
|
||||
pub fn noop_visit_mod<T: MutVisitor>(Mod { inner, items, inline: _ }: &mut Mod, vis: &mut T) {
|
||||
pub fn noop_visit_mod<T: MutVisitor>(module: &mut Mod, vis: &mut T) {
|
||||
let Mod { inner, unsafety: _, items, inline: _ } = module;
|
||||
vis.visit_span(inner);
|
||||
items.flat_map_in_place(|item| vis.flat_map_item(item));
|
||||
}
|
||||
|
@ -990,7 +991,7 @@ pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
|||
|
||||
let len = items.len();
|
||||
if len == 0 {
|
||||
let module = Mod { inner: span, items: vec![], inline: true };
|
||||
let module = Mod { inner: span, unsafety: Unsafe::No, items: vec![], inline: true };
|
||||
Crate { module, attrs: vec![], span, proc_macros }
|
||||
} else if len == 1 {
|
||||
let Item { attrs, span, kind, .. } = items.into_iter().next().unwrap().into_inner();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue