Rename FnStyle trait to Unsafety.

This commit is contained in:
Niko Matsakis 2014-12-09 10:36:46 -05:00
parent 52f7a4a351
commit 092d04a40a
41 changed files with 254 additions and 273 deletions

View File

@ -549,11 +549,11 @@ fn parse_hex(st: &mut PState) -> uint {
};
}
fn parse_fn_style(c: char) -> ast::FnStyle {
fn parse_unsafety(c: char) -> ast::Unsafety {
match c {
'u' => ast::UnsafeFn,
'n' => ast::NormalFn,
_ => panic!("parse_fn_style: bad fn_style {}", c)
'u' => ast::Unsafety::Unsafe,
'n' => ast::Unsafety::Normal,
_ => panic!("parse_unsafety: bad unsafety {}", c)
}
}
@ -575,14 +575,14 @@ fn parse_onceness(c: char) -> ast::Onceness {
fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
conv: conv_did) -> ty::ClosureTy<'tcx> {
let fn_style = parse_fn_style(next(st));
let unsafety = parse_unsafety(next(st));
let onceness = parse_onceness(next(st));
let store = parse_trait_store(st, |x,y| conv(x,y));
let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
let sig = parse_sig(st, |x,y| conv(x,y));
let abi = parse_abi_set(st);
ty::ClosureTy {
fn_style: fn_style,
unsafety: unsafety,
onceness: onceness,
store: store,
bounds: bounds,
@ -593,11 +593,11 @@ fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
conv: conv_did) -> ty::BareFnTy<'tcx> {
let fn_style = parse_fn_style(next(st));
let unsafety = parse_unsafety(next(st));
let abi = parse_abi_set(st);
let sig = parse_sig(st, |x,y| conv(x,y));
ty::BareFnTy {
fn_style: fn_style,
unsafety: unsafety,
abi: abi,
sig: sig
}

View File

@ -313,10 +313,10 @@ fn enc_sty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
}
}
fn enc_fn_style(w: &mut SeekableMemWriter, p: ast::FnStyle) {
fn enc_unsafety(w: &mut SeekableMemWriter, p: ast::Unsafety) {
match p {
ast::NormalFn => mywrite!(w, "n"),
ast::UnsafeFn => mywrite!(w, "u"),
ast::Unsafety::Normal => mywrite!(w, "n"),
ast::Unsafety::Unsafe => mywrite!(w, "u"),
}
}
@ -335,14 +335,14 @@ fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) {
pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
ft: &ty::BareFnTy<'tcx>) {
enc_fn_style(w, ft.fn_style);
enc_unsafety(w, ft.unsafety);
enc_abi(w, ft.abi);
enc_fn_sig(w, cx, &ft.sig);
}
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
ft: &ty::ClosureTy<'tcx>) {
enc_fn_style(w, ft.fn_style);
enc_unsafety(w, ft.unsafety);
enc_onceness(w, ft.onceness);
enc_trait_store(w, cx, ft.store);
enc_existential_bounds(w, cx, &ft.bounds);

View File

@ -34,8 +34,8 @@ impl Copy for UnsafeContext {}
fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty {
ty::ty_bare_fn(ref f) => f.fn_style == ast::UnsafeFn,
ty::ty_closure(ref f) => f.fn_style == ast::UnsafeFn,
ty::ty_bare_fn(ref f) => f.unsafety == ast::Unsafety::Unsafe,
ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe,
_ => false,
}
}
@ -92,9 +92,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
let (is_item_fn, is_unsafe_fn) = match fn_kind {
visit::FkItemFn(_, _, fn_style, _) =>
(true, fn_style == ast::UnsafeFn),
(true, fn_style == ast::Unsafety::Unsafe),
visit::FkMethod(_, _, method) =>
(true, method.pe_fn_style() == ast::UnsafeFn),
(true, method.pe_unsafety() == ast::Unsafety::Unsafe),
_ => (false, false),
};

View File

@ -521,7 +521,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
debug!("coerce_from_bare_fn(a={}, b={})",
a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx));
if fn_ty_a.abi != abi::Rust || fn_ty_a.fn_style != ast::NormalFn {
if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal {
return self.subtype(a, b);
}

View File

@ -51,7 +51,7 @@ use middle::ty_fold;
use middle::ty_fold::{TypeFoldable};
use util::ppaux::Repr;
use syntax::ast::{Onceness, FnStyle};
use syntax::ast::{Onceness, Unsafety};
use syntax::ast;
use syntax::abi;
use syntax::codemap::Span;
@ -193,12 +193,12 @@ pub trait Combine<'tcx> {
fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
b: &ty::BareFnTy<'tcx>) -> cres<'tcx, ty::BareFnTy<'tcx>> {
let fn_style = try!(self.fn_styles(a.fn_style, b.fn_style));
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
let abi = try!(self.abi(a.abi, b.abi));
let sig = try!(self.fn_sigs(&a.sig, &b.sig));
Ok(ty::BareFnTy {fn_style: fn_style,
abi: abi,
sig: sig})
Ok(ty::BareFnTy {unsafety: unsafety,
abi: abi,
sig: sig})
}
fn closure_tys(&self, a: &ty::ClosureTy<'tcx>,
@ -219,13 +219,13 @@ pub trait Combine<'tcx> {
return Err(ty::terr_sigil_mismatch(expected_found(self, a.store, b.store)))
}
};
let fn_style = try!(self.fn_styles(a.fn_style, b.fn_style));
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
let onceness = try!(self.oncenesses(a.onceness, b.onceness));
let bounds = try!(self.existential_bounds(a.bounds, b.bounds));
let sig = try!(self.fn_sigs(&a.sig, &b.sig));
let abi = try!(self.abi(a.abi, b.abi));
Ok(ty::ClosureTy {
fn_style: fn_style,
unsafety: unsafety,
onceness: onceness,
store: store,
bounds: bounds,
@ -240,7 +240,7 @@ pub trait Combine<'tcx> {
self.contratys(a, b).and_then(|t| Ok(t))
}
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle>;
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety>;
fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<'tcx, abi::Abi> {
if a == b {

View File

@ -21,7 +21,7 @@ use middle::infer::{TypeTrace, Subtype};
use middle::infer::type_variable::{EqTo};
use util::ppaux::{Repr};
use syntax::ast::{Onceness, FnStyle};
use syntax::ast::{Onceness, Unsafety};
pub struct Equate<'f, 'tcx: 'f> {
fields: CombineFields<'f, 'tcx>
@ -70,9 +70,9 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> {
Ok(ty::mt { mutbl: a.mutbl, ty: t })
}
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
if a != b {
Err(ty::terr_fn_style_mismatch(expected_found(self, a, b)))
Err(ty::terr_unsafety_mismatch(expected_found(self, a, b)))
} else {
Ok(a)
}

View File

@ -157,7 +157,7 @@ trait ErrorReportingHelpers<'tcx> {
fn give_expl_lifetime_param(&self,
decl: &ast::FnDecl,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
ident: ast::Ident,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
generics: &ast::Generics,
@ -828,7 +828,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
ast::MethodImplItem(ref m) => {
Some((m.pe_fn_decl(),
m.pe_generics(),
m.pe_fn_style(),
m.pe_unsafety(),
m.pe_ident(),
Some(&m.pe_explicit_self().node),
m.span))
@ -841,7 +841,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
ast::ProvidedMethod(ref m) => {
Some((m.pe_fn_decl(),
m.pe_generics(),
m.pe_fn_style(),
m.pe_unsafety(),
m.pe_ident(),
Some(&m.pe_explicit_self().node),
m.span))
@ -853,14 +853,14 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
},
None => None
};
let (fn_decl, generics, fn_style, ident, expl_self, span)
let (fn_decl, generics, unsafety, ident, expl_self, span)
= node_inner.expect("expect item fn");
let taken = lifetimes_in_scope(self.tcx, scope_id);
let life_giver = LifeGiver::with_taken(taken.as_slice());
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
generics, same_regions, &life_giver);
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
self.give_expl_lifetime_param(&fn_decl, fn_style, ident,
self.give_expl_lifetime_param(&fn_decl, unsafety, ident,
expl_self.as_ref(), &generics, span);
}
}
@ -1407,12 +1407,12 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
fn give_expl_lifetime_param(&self,
decl: &ast::FnDecl,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
ident: ast::Ident,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
generics: &ast::Generics,
span: codemap::Span) {
let suggested_fn = pprust::fun_to_string(decl, fn_style, ident,
let suggested_fn = pprust::fun_to_string(decl, unsafety, ident,
opt_explicit_self, generics);
let msg = format!("consider using an explicit lifetime \
parameter as shown: {}", suggested_fn);

View File

@ -20,8 +20,7 @@ use super::{TypeTrace, Subtype};
use middle::ty::{BuiltinBounds};
use middle::ty::{mod, Ty};
use syntax::ast::{Many, Once, MutImmutable, MutMutable};
use syntax::ast::{NormalFn, UnsafeFn};
use syntax::ast::{Onceness, FnStyle};
use syntax::ast::{Onceness, Unsafety};
use util::ppaux::mt_to_string;
use util::ppaux::Repr;
@ -81,10 +80,10 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> {
self.lub().tys(a, b)
}
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
match (a, b) {
(NormalFn, _) | (_, NormalFn) => Ok(NormalFn),
(UnsafeFn, UnsafeFn) => Ok(UnsafeFn)
(Unsafety::Normal, _) | (_, Unsafety::Normal) => Ok(Unsafety::Normal),
(Unsafety::Unsafe, Unsafety::Unsafe) => Ok(Unsafety::Unsafe)
}
}

View File

@ -20,8 +20,7 @@ use super::{TypeTrace, Subtype};
use middle::ty::{BuiltinBounds};
use middle::ty::{mod, Ty};
use syntax::ast::{Many, Once};
use syntax::ast::{NormalFn, UnsafeFn};
use syntax::ast::{Onceness, FnStyle};
use syntax::ast::{Onceness, Unsafety};
use syntax::ast::{MutMutable, MutImmutable};
use util::ppaux::mt_to_string;
use util::ppaux::Repr;
@ -77,10 +76,10 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> {
self.glb().tys(a, b)
}
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
match (a, b) {
(UnsafeFn, _) | (_, UnsafeFn) => Ok(UnsafeFn),
(NormalFn, NormalFn) => Ok(NormalFn),
(Unsafety::Unsafe, _) | (_, Unsafety::Unsafe) => Ok(Unsafety::Unsafe),
(Unsafety::Normal, Unsafety::Normal) => Ok(Unsafety::Normal),
}
}

View File

@ -23,7 +23,7 @@ use middle::ty::{mod, Ty};
use middle::ty::TyVar;
use util::ppaux::{Repr};
use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable};
use syntax::ast::{Onceness, MutImmutable, MutMutable, Unsafety};
/// "Greatest lower bound" (common subtype)
@ -93,9 +93,9 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> {
Ok(*a) // return is meaningless in sub, just return *a
}
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
self.lub().fn_styles(a, b).compare(b, || {
ty::terr_fn_style_mismatch(expected_found(self, a, b))
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
self.lub().unsafeties(a, b).compare(b, || {
ty::terr_unsafety_mismatch(expected_found(self, a, b))
})
}

View File

@ -791,7 +791,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// provide an impl, but only for suitable `fn` pointers
ty::ty_bare_fn(ty::BareFnTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
sig: ty::FnSig {
inputs: _,
@ -1505,7 +1505,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
let sig = match self_ty.sty {
ty::ty_bare_fn(ty::BareFnTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
ref sig
}) => {

View File

@ -80,7 +80,7 @@ use std::rc::Rc;
use std::collections::enum_set::{EnumSet, CLike};
use std::collections::hash_map::{HashMap, Occupied, Vacant};
use syntax::abi;
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
use syntax::ast::{Visibility};
@ -908,14 +908,14 @@ pub fn type_escapes_depth(ty: Ty, depth: uint) -> bool {
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct BareFnTy<'tcx> {
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub abi: abi::Abi,
pub sig: FnSig<'tcx>,
}
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ClosureTy<'tcx> {
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub onceness: ast::Onceness,
pub store: TraitStore,
pub bounds: ExistentialBounds,
@ -1380,7 +1380,7 @@ impl<T:Copy> Copy for expected_found<T> {}
#[deriving(Clone, Show)]
pub enum type_err<'tcx> {
terr_mismatch,
terr_fn_style_mismatch(expected_found<FnStyle>),
terr_unsafety_mismatch(expected_found<ast::Unsafety>),
terr_onceness_mismatch(expected_found<Onceness>),
terr_abi_mismatch(expected_found<abi::Abi>),
terr_mutability,
@ -2354,7 +2354,7 @@ pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>,
let input_args = input_tys.iter().map(|ty| *ty).collect();
mk_bare_fn(cx,
BareFnTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
sig: FnSig {
inputs: input_args,
@ -3994,7 +3994,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
ty::mk_closure(
cx,
ty::ClosureTy {fn_style: b.fn_style,
ty::ClosureTy {unsafety: b.unsafety,
onceness: ast::Many,
store: store,
bounds: bounds,
@ -4404,7 +4404,7 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
match *err {
terr_cyclic_ty => "cyclic type of infinite size".to_string(),
terr_mismatch => "types differ".to_string(),
terr_fn_style_mismatch(values) => {
terr_unsafety_mismatch(values) => {
format!("expected {} fn, found {} fn",
values.expected.to_string(),
values.found.to_string())
@ -5871,12 +5871,12 @@ pub fn hash_crate_independent(tcx: &ctxt, ty: Ty, svh: &Svh) -> u64 {
}
ty_bare_fn(ref b) => {
byte!(14);
hash!(b.fn_style);
hash!(b.unsafety);
hash!(b.abi);
}
ty_closure(ref c) => {
byte!(15);
hash!(c.fn_style);
hash!(c.unsafety);
hash!(c.onceness);
hash!(c.bounds);
match c.store {

View File

@ -563,7 +563,7 @@ pub fn super_fold_bare_fn_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
{
ty::BareFnTy { sig: fty.sig.fold_with(this),
abi: fty.abi,
fn_style: fty.fn_style }
unsafety: fty.unsafety }
}
pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
@ -573,7 +573,7 @@ pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
ty::ClosureTy {
store: fty.store.fold_with(this),
sig: fty.sig.fold_with(this),
fn_style: fty.fn_style,
unsafety: fty.unsafety,
onceness: fty.onceness,
bounds: fty.bounds.fold_with(this),
abi: fty.abi,

View File

@ -259,16 +259,16 @@ pub fn trait_ref_to_string<'tcx>(cx: &ctxt<'tcx>,
pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
abi: abi::Abi,
ident: Option<ast::Ident>,
sig: &ty::FnSig<'tcx>)
-> String {
let mut s = String::new();
match fn_style {
ast::NormalFn => {}
_ => {
s.push_str(fn_style.to_string().as_slice());
match unsafety {
ast::Unsafety::Normal => {}
ast::Unsafety::Unsafe => {
s.push_str(unsafety.to_string().as_slice());
s.push(' ');
}
};
@ -302,10 +302,10 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
}
}
match cty.fn_style {
ast::NormalFn => {}
_ => {
s.push_str(cty.fn_style.to_string().as_slice());
match cty.unsafety {
ast::Unsafety::Normal => {}
ast::Unsafety::Unsafe => {
s.push_str(cty.unsafety.to_string().as_slice());
s.push(' ');
}
};
@ -414,7 +414,7 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
closure_to_string(cx, &**f)
}
ty_bare_fn(ref f) => {
bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
bare_fn_to_string(cx, f.unsafety, f.abi, None, &f.sig)
}
ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
ty_err => "[type error]".to_string(),
@ -1001,8 +1001,8 @@ impl<'tcx> Repr<'tcx> for ast::Visibility {
impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> {
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
format!("BareFnTy {{fn_style: {}, abi: {}, sig: {}}}",
self.fn_style,
format!("BareFnTy {{unsafety: {}, abi: {}, sig: {}}}",
self.unsafety,
self.abi.to_string(),
self.sig.repr(tcx))
}

View File

@ -270,7 +270,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
-> Ty<'tcx>
{
ty::mk_closure(self.infcx.tcx, ty::ClosureTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
onceness: ast::Many,
store: ty::RegionTraitStore(region_bound, ast::MutMutable),
bounds: ty::region_existential_bound(region_bound),

View File

@ -278,7 +278,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
// which is the fn pointer, and `args`, which is the arguments tuple.
let (input_tys, output_ty) =
match bare_fn_ty.sty {
ty::ty_bare_fn(ty::BareFnTy { fn_style: ast::NormalFn,
ty::ty_bare_fn(ty::BareFnTy { unsafety: ast::Unsafety::Normal,
abi: synabi::Rust,
sig: ty::FnSig { inputs: ref input_tys,
output: output_ty,
@ -294,7 +294,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
};
let tuple_input_ty = ty::mk_tup(tcx, input_tys.to_vec());
let tuple_fn_ty = ty::mk_bare_fn(tcx,
ty::BareFnTy { fn_style: ast::NormalFn,
ty::BareFnTy { unsafety: ast::Unsafety::Normal,
abi: synabi::RustCall,
sig: ty::FnSig {
inputs: vec![bare_fn_ty_ref,

View File

@ -433,8 +433,8 @@ impl<'tcx> TypeMap<'tcx> {
&trait_data.principal.substs,
&mut unique_type_id);
},
ty::ty_bare_fn(ty::BareFnTy{ fn_style, abi, ref sig } ) => {
if fn_style == ast::UnsafeFn {
ty::ty_bare_fn(ty::BareFnTy{ unsafety, abi, ref sig } ) => {
if unsafety == ast::Unsafety::Unsafe {
unique_type_id.push_str("unsafe ");
}
@ -551,13 +551,13 @@ impl<'tcx> TypeMap<'tcx> {
cx: &CrateContext<'a, 'tcx>,
closure_ty: ty::ClosureTy<'tcx>,
unique_type_id: &mut String) {
let ty::ClosureTy { fn_style,
let ty::ClosureTy { unsafety,
onceness,
store,
ref bounds,
ref sig,
abi: _ } = closure_ty;
if fn_style == ast::UnsafeFn {
if unsafety == ast::Unsafety::Unsafe {
unique_type_id.push_str("unsafe ");
}
@ -3767,8 +3767,8 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
push_item_name(cx, trait_data.principal.def_id, false, output);
push_type_params(cx, &trait_data.principal.substs, output);
},
ty::ty_bare_fn(ty::BareFnTy{ fn_style, abi, ref sig } ) => {
if fn_style == ast::UnsafeFn {
ty::ty_bare_fn(ty::BareFnTy{ unsafety, abi, ref sig } ) => {
if unsafety == ast::Unsafety::Unsafe {
output.push_str("unsafe ");
}
@ -3810,13 +3810,13 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}
}
},
ty::ty_closure(box ty::ClosureTy { fn_style,
ty::ty_closure(box ty::ClosureTy { unsafety,
onceness,
store,
ref sig,
.. // omitting bounds ...
}) => {
if fn_style == ast::UnsafeFn {
if unsafety == ast::Unsafety::Unsafe {
output.push_str("unsafe ");
}

View File

@ -924,7 +924,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
tcx.sess.span_err(ast_ty.span,
"variadic function must have C calling convention");
}
ty::mk_bare_fn(tcx, ty_of_bare_fn(this, bf.fn_style, bf.abi, &*bf.decl))
ty::mk_bare_fn(tcx, ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl))
}
ast::TyClosure(ref f) => {
// Use corresponding trait store to figure out default bounds
@ -935,7 +935,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
None,
f.bounds.as_slice());
let fn_decl = ty_of_closure(this,
f.fn_style,
f.unsafety,
f.onceness,
bounds,
ty::RegionTraitStore(
@ -1082,7 +1082,7 @@ struct SelfInfo<'a, 'tcx> {
pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>(
this: &AC,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
untransformed_self_ty: Ty<'tcx>,
explicit_self: &ast::ExplicitSelf,
decl: &ast::FnDecl,
@ -1094,22 +1094,22 @@ pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>(
});
let (bare_fn_ty, optional_explicit_self_category) =
ty_of_method_or_bare_fn(this,
fn_style,
unsafety,
abi,
self_info,
decl);
(bare_fn_ty, optional_explicit_self_category.unwrap())
}
pub fn ty_of_bare_fn<'tcx, AC: AstConv<'tcx>>(this: &AC, fn_style: ast::FnStyle, abi: abi::Abi,
pub fn ty_of_bare_fn<'tcx, AC: AstConv<'tcx>>(this: &AC, unsafety: ast::Unsafety, abi: abi::Abi,
decl: &ast::FnDecl) -> ty::BareFnTy<'tcx> {
let (bare_fn_ty, _) = ty_of_method_or_bare_fn(this, fn_style, abi, None, decl);
let (bare_fn_ty, _) = ty_of_method_or_bare_fn(this, unsafety, abi, None, decl);
bare_fn_ty
}
fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>(
this: &AC,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
abi: abi::Abi,
opt_self_info: Option<SelfInfo<'a, 'tcx>>,
decl: &ast::FnDecl)
@ -1207,7 +1207,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>(
};
(ty::BareFnTy {
fn_style: fn_style,
unsafety: unsafety,
abi: abi,
sig: ty::FnSig {
inputs: self_and_input_tys,
@ -1301,7 +1301,7 @@ fn determine_explicit_self_category<'a, 'tcx, AC: AstConv<'tcx>,
pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>(
this: &AC,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
onceness: ast::Onceness,
bounds: ty::ExistentialBounds,
store: ty::TraitStore,
@ -1346,7 +1346,7 @@ pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>(
debug!("ty_of_closure: output_ty={}", output_ty.repr(this.tcx()));
ty::ClosureTy {
fn_style: fn_style,
unsafety: unsafety,
onceness: onceness,
store: store,
bounds: bounds,

View File

@ -89,7 +89,7 @@ fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
let mut fn_ty = astconv::ty_of_closure(
fcx,
ast::NormalFn,
ast::Unsafety::Normal,
ast::Many,
// The `RegionTraitStore` and region_existential_bounds
@ -119,7 +119,7 @@ fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
fcx.write_ty(expr.id, closure_type);
check_fn(fcx.ccx,
ast::NormalFn,
ast::Unsafety::Normal,
expr.id,
&fn_ty.sig,
decl,
@ -304,7 +304,7 @@ fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
// construct the function type
let fn_ty = astconv::ty_of_closure(fcx,
ast::NormalFn,
ast::Unsafety::Normal,
expected_onceness,
expected_bounds,
store,
@ -321,9 +321,9 @@ fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
// style inferred for it, then check it under its parent's style.
// Otherwise, use its own
let (inherited_style, inherited_style_id) = match store {
ty::RegionTraitStore(..) => (fcx.ps.borrow().fn_style,
ty::RegionTraitStore(..) => (fcx.ps.borrow().unsafety,
fcx.ps.borrow().def),
ty::UniqTraitStore => (ast::NormalFn, expr.id)
ty::UniqTraitStore => (ast::Unsafety::Normal, expr.id)
};
check_fn(fcx.ccx,

View File

@ -115,7 +115,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
// Create the final `MethodCallee`.
let fty = ty::mk_bare_fn(self.tcx(), ty::BareFnTy {
sig: method_sig,
fn_style: pick.method_ty.fty.fn_style,
unsafety: pick.method_ty.fty.unsafety,
abi: pick.method_ty.fty.abi.clone(),
});
let callee = MethodCallee {

View File

@ -205,7 +205,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
let transformed_self_ty = fn_sig.inputs[0];
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
sig: fn_sig,
fn_style: bare_fn_ty.fn_style,
unsafety: bare_fn_ty.unsafety,
abi: bare_fn_ty.abi.clone(),
});

View File

@ -180,35 +180,33 @@ enum Expectation<'tcx> {
impl<'tcx> Copy for Expectation<'tcx> {}
#[deriving(Clone)]
pub struct FnStyleState {
#[deriving(Copy, Clone)]
pub struct UnsafetyState {
pub def: ast::NodeId,
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
from_fn: bool
}
impl Copy for FnStyleState {}
impl FnStyleState {
pub fn function(fn_style: ast::FnStyle, def: ast::NodeId) -> FnStyleState {
FnStyleState { def: def, fn_style: fn_style, from_fn: true }
impl UnsafetyState {
pub fn function(unsafety: ast::Unsafety, def: ast::NodeId) -> UnsafetyState {
UnsafetyState { def: def, unsafety: unsafety, from_fn: true }
}
pub fn recurse(&mut self, blk: &ast::Block) -> FnStyleState {
match self.fn_style {
pub fn recurse(&mut self, blk: &ast::Block) -> UnsafetyState {
match self.unsafety {
// If this unsafe, then if the outer function was already marked as
// unsafe we shouldn't attribute the unsafe'ness to the block. This
// way the block can be warned about instead of ignoring this
// extraneous block (functions are never warned about).
ast::UnsafeFn if self.from_fn => *self,
ast::Unsafety::Unsafe if self.from_fn => *self,
fn_style => {
let (fn_style, def) = match blk.rules {
ast::UnsafeBlock(..) => (ast::UnsafeFn, blk.id),
ast::DefaultBlock => (fn_style, self.def),
unsafety => {
let (unsafety, def) = match blk.rules {
ast::UnsafeBlock(..) => (ast::Unsafety::Unsafe, blk.id),
ast::DefaultBlock => (unsafety, self.def),
};
FnStyleState{ def: def,
fn_style: fn_style,
UnsafetyState{ def: def,
unsafety: unsafety,
from_fn: false }
}
}
@ -240,7 +238,7 @@ pub struct FnCtxt<'a, 'tcx: 'a> {
ret_ty: ty::FnOutput<'tcx>,
ps: RefCell<FnStyleState>,
ps: RefCell<UnsafetyState>,
inh: &'a Inherited<'a, 'tcx>,
@ -312,7 +310,7 @@ pub fn blank_fn_ctxt<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
writeback_errors: Cell::new(false),
err_count_on_creation: ccx.tcx.sess.err_count(),
ret_ty: rty,
ps: RefCell::new(FnStyleState::function(ast::NormalFn, 0)),
ps: RefCell::new(UnsafetyState::function(ast::Unsafety::Normal, 0)),
inh: inh,
ccx: ccx
}
@ -374,7 +372,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
match fty.sty {
ty::ty_bare_fn(ref fn_ty) => {
let inh = Inherited::new(ccx.tcx, param_env);
let fcx = check_fn(ccx, fn_ty.fn_style, id, &fn_ty.sig,
let fcx = check_fn(ccx, fn_ty.unsafety, id, &fn_ty.sig,
decl, id, body, &inh);
vtable::select_all_fcx_obligations_or_error(&fcx);
@ -476,8 +474,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for GatherLocalsVisitor<'a, 'tcx> {
/// * ...
/// * inherited: other fields inherited from the enclosing fn (if any)
fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
fn_style: ast::FnStyle,
fn_style_id: ast::NodeId,
unsafety: ast::Unsafety,
unsafety_id: ast::NodeId,
fn_sig: &ty::FnSig<'tcx>,
decl: &ast::FnDecl,
fn_id: ast::NodeId,
@ -506,7 +504,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
writeback_errors: Cell::new(false),
err_count_on_creation: err_count_on_creation,
ret_ty: ret_ty,
ps: RefCell::new(FnStyleState::function(fn_style, fn_style_id)),
ps: RefCell::new(UnsafetyState::function(unsafety, unsafety_id)),
inh: inherited,
ccx: ccx
};
@ -4493,8 +4491,8 @@ fn check_block_with_expected<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
expected: Expectation<'tcx>) {
let prev = {
let mut fcx_ps = fcx.ps.borrow_mut();
let fn_style_state = fcx_ps.recurse(blk);
replace(&mut *fcx_ps, fn_style_state)
let unsafety_state = fcx_ps.recurse(blk);
replace(&mut *fcx_ps, unsafety_state)
};
let mut warned = false;
@ -5696,7 +5694,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
(n_tps, inputs, ty::FnConverging(output))
};
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
fn_style: ast::UnsafeFn,
unsafety: ast::Unsafety::Unsafe,
abi: abi::RustIntrinsic,
sig: FnSig {
inputs: inputs,

View File

@ -277,7 +277,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
&m.explicit_self,
m.abi,
&m.generics,
&m.fn_style,
&m.unsafety,
&*m.decl)
}
ast::ProvidedMethod(ref m) => {
@ -291,7 +291,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
m.pe_explicit_self(),
m.pe_abi(),
m.pe_generics(),
&m.pe_fn_style(),
&m.pe_unsafety(),
&*m.pe_fn_decl())
}
ast::TypeTraitItem(ref at) => {
@ -366,7 +366,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
m_explicit_self: &ast::ExplicitSelf,
m_abi: abi::Abi,
m_generics: &ast::Generics,
m_fn_style: &ast::FnStyle,
m_unsafety: &ast::Unsafety,
m_decl: &ast::FnDecl)
-> ty::Method<'tcx> {
let ty_generics =
@ -386,7 +386,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let trait_self_ty = ty::mk_self_type(tmcx.tcx(),
local_def(trait_id));
astconv::ty_of_method(&tmcx,
*m_fn_style,
*m_unsafety,
trait_self_ty,
m_explicit_self,
m_decl,
@ -572,7 +572,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
method_generics: &m_ty_generics,
};
astconv::ty_of_method(&imcx,
m.pe_fn_style(),
m.pe_unsafety(),
untransformed_rcvr_ty,
m.pe_explicit_self(),
&*m.pe_fn_decl(),
@ -586,7 +586,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
method_generics: &m_ty_generics,
};
astconv::ty_of_method(&tmcx,
m.pe_fn_style(),
m.pe_unsafety(),
untransformed_rcvr_ty,
m.pe_explicit_self(),
&*m.pe_fn_decl(),
@ -1446,7 +1446,7 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemFn(ref decl, fn_style, abi, ref generics, _) => {
ast::ItemFn(ref decl, unsafety, abi, ref generics, _) => {
let ty_generics = ty_generics_for_fn_or_method(
ccx,
generics,
@ -1457,7 +1457,7 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
ccx: ccx,
generics: &ty_generics,
};
astconv::ty_of_bare_fn(&fcx, fn_style, abi, &**decl)
astconv::ty_of_bare_fn(&fcx, unsafety, abi, &**decl)
};
let pty = Polytype {
generics: ty_generics,
@ -2151,7 +2151,7 @@ pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ccx.tcx,
ty::BareFnTy {
abi: abi,
fn_style: ast::UnsafeFn,
unsafety: ast::Unsafety::Unsafe,
sig: ty::FnSig {inputs: input_tys,
output: output,
variadic: decl.variadic}

View File

@ -226,7 +226,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
_ => ()
}
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
sig: ty::FnSig {
inputs: Vec::new(),
@ -274,7 +274,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
}
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
fn_style: ast::NormalFn,
unsafety: ast::Unsafety::Normal,
abi: abi::Rust,
sig: ty::FnSig {
inputs: vec!(

View File

@ -171,13 +171,13 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt,
fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Function {
let t = ty::lookup_item_type(tcx, did);
let (decl, style) = match t.ty.sty {
ty::ty_bare_fn(ref f) => ((did, &f.sig).clean(cx), f.fn_style),
ty::ty_bare_fn(ref f) => ((did, &f.sig).clean(cx), f.unsafety),
_ => panic!("bad function"),
};
clean::Function {
decl: decl,
generics: (&t.generics, subst::FnSpace).clean(cx),
fn_style: style,
unsafety: style,
}
}
@ -299,10 +299,10 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
let mut item = method.clean(cx);
item.inner = match item.inner.clone() {
clean::TyMethodItem(clean::TyMethod {
fn_style, decl, self_, generics
unsafety, decl, self_, generics
}) => {
clean::MethodItem(clean::Method {
fn_style: fn_style,
unsafety: unsafety,
decl: decl,
self_: self_,
generics: generics,

View File

@ -740,7 +740,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>, subst::ParamSpace) {
pub struct Method {
pub generics: Generics,
pub self_: SelfTy,
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub decl: FnDecl,
}
@ -768,7 +768,7 @@ impl Clean<Item> for ast::Method {
inner: MethodItem(Method {
generics: self.pe_generics().clean(cx),
self_: self.pe_explicit_self().node.clean(cx),
fn_style: self.pe_fn_style().clone(),
unsafety: self.pe_unsafety().clone(),
decl: decl,
}),
}
@ -777,7 +777,7 @@ impl Clean<Item> for ast::Method {
#[deriving(Clone, Encodable, Decodable)]
pub struct TyMethod {
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub decl: FnDecl,
pub generics: Generics,
pub self_: SelfTy,
@ -804,7 +804,7 @@ impl Clean<Item> for ast::TypeMethod {
visibility: None,
stability: get_stability(cx, ast_util::local_def(self.id)),
inner: TyMethodItem(TyMethod {
fn_style: self.fn_style.clone(),
unsafety: self.unsafety.clone(),
decl: decl,
self_: self.explicit_self.node.clean(cx),
generics: self.generics.clean(cx),
@ -838,7 +838,7 @@ impl Clean<SelfTy> for ast::ExplicitSelf_ {
pub struct Function {
pub decl: FnDecl,
pub generics: Generics,
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
}
impl Clean<Item> for doctree::Function {
@ -853,7 +853,7 @@ impl Clean<Item> for doctree::Function {
inner: FunctionItem(Function {
decl: self.decl.clean(cx),
generics: self.generics.clean(cx),
fn_style: self.fn_style,
unsafety: self.unsafety,
}),
}
}
@ -864,7 +864,7 @@ pub struct ClosureDecl {
pub lifetimes: Vec<Lifetime>,
pub decl: FnDecl,
pub onceness: ast::Onceness,
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub bounds: Vec<TyParamBound>,
}
@ -874,7 +874,7 @@ impl Clean<ClosureDecl> for ast::ClosureTy {
lifetimes: self.lifetimes.clean(cx),
decl: self.decl.clean(cx),
onceness: self.onceness,
fn_style: self.fn_style,
unsafety: self.unsafety,
bounds: self.bounds.clean(cx)
}
}
@ -1111,7 +1111,7 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
source: Span::empty(),
inner: TyMethodItem(TyMethod {
fn_style: self.fty.fn_style,
unsafety: self.fty.unsafety,
generics: (&self.generics, subst::FnSpace).clean(cx),
self_: self_,
decl: (self.def_id, &sig).clean(cx),
@ -1364,7 +1364,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
type_: box mt.ty.clean(cx),
},
ty::ty_bare_fn(ref fty) => BareFunction(box BareFunctionDecl {
fn_style: fty.fn_style,
unsafety: fty.unsafety,
generics: Generics {
lifetimes: Vec::new(),
type_params: Vec::new(),
@ -1378,7 +1378,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
lifetimes: Vec::new(), // FIXME: this looks wrong...
decl: (ast_util::local_def(0), &fty.sig).clean(cx),
onceness: fty.onceness,
fn_style: fty.fn_style,
unsafety: fty.unsafety,
bounds: fty.bounds.clean(cx),
};
match fty.store {
@ -1789,7 +1789,7 @@ impl Clean<Item> for doctree::Typedef {
#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct BareFunctionDecl {
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub generics: Generics,
pub decl: FnDecl,
pub abi: String,
@ -1798,7 +1798,7 @@ pub struct BareFunctionDecl {
impl Clean<BareFunctionDecl> for ast::BareFnTy {
fn clean(&self, cx: &DocContext) -> BareFunctionDecl {
BareFunctionDecl {
fn_style: self.fn_style,
unsafety: self.unsafety,
generics: Generics {
lifetimes: self.lifetimes.clean(cx),
type_params: Vec::new(),
@ -2071,7 +2071,7 @@ impl Clean<Item> for ast::ForeignItem {
ForeignFunctionItem(Function {
decl: decl.clean(cx),
generics: generics.clean(cx),
fn_style: ast::UnsafeFn,
unsafety: ast::Unsafety::Unsafe,
})
}
ast::ForeignItemStatic(ref ty, mutbl) => {

View File

@ -129,7 +129,7 @@ pub struct Function {
pub name: Ident,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
pub fn_style: ast::FnStyle,
pub unsafety: ast::Unsafety,
pub whence: Span,
pub generics: ast::Generics,
}

View File

@ -32,7 +32,7 @@ use html::render::{cache, CURRENT_LOCATION_KEY};
pub struct VisSpace(pub Option<ast::Visibility>);
/// Similarly to VisSpace, this structure is used to render a function style with a
/// space after it.
pub struct FnStyleSpace(pub ast::FnStyle);
pub struct UnsafetySpace(pub ast::Unsafety);
/// Wrapper struct for properly emitting a method declaration.
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
/// Similar to VisSpace, but used for mutability
@ -49,7 +49,7 @@ pub struct WhereClause<'a>(pub &'a clean::Generics);
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
impl Copy for VisSpace {}
impl Copy for FnStyleSpace {}
impl Copy for UnsafetySpace {}
impl Copy for MutableSpace {}
impl Copy for RawMutableSpace {}
@ -59,9 +59,9 @@ impl VisSpace {
}
}
impl FnStyleSpace {
pub fn get(&self) -> ast::FnStyle {
let FnStyleSpace(v) = *self; v
impl UnsafetySpace {
pub fn get(&self) -> ast::Unsafety {
let UnsafetySpace(v) = *self; v
}
}
@ -404,7 +404,7 @@ impl fmt::Show for clean::Type {
clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()),
clean::Closure(ref decl) => {
write!(f, "{style}{lifetimes}|{args}|{bounds}{arrow}",
style = FnStyleSpace(decl.fn_style),
style = UnsafetySpace(decl.unsafety),
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
@ -433,7 +433,7 @@ impl fmt::Show for clean::Type {
}
clean::Proc(ref decl) => {
write!(f, "{style}{lifetimes}proc({args}){bounds}{arrow}",
style = FnStyleSpace(decl.fn_style),
style = UnsafetySpace(decl.unsafety),
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
@ -454,7 +454,7 @@ impl fmt::Show for clean::Type {
}
clean::BareFunction(ref decl) => {
write!(f, "{}{}fn{}{}",
FnStyleSpace(decl.fn_style),
UnsafetySpace(decl.unsafety),
match decl.abi.as_slice() {
"" => " extern ".to_string(),
"\"Rust\"" => "".to_string(),
@ -584,11 +584,11 @@ impl fmt::Show for VisSpace {
}
}
impl fmt::Show for FnStyleSpace {
impl fmt::Show for UnsafetySpace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.get() {
ast::UnsafeFn => write!(f, "unsafe "),
ast::NormalFn => Ok(())
ast::Unsafety::Unsafe => write!(f, "unsafe "),
ast::Unsafety::Normal => Ok(())
}
}
}

View File

@ -58,7 +58,7 @@ use rustc::util::nodemap::NodeSet;
use clean;
use doctree;
use fold::DocFolder;
use html::format::{VisSpace, Method, FnStyleSpace, MutableSpace, Stability};
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace, Stability};
use html::format::{ConciseStability, TyParamBounds, WhereClause};
use html::highlight;
use html::item_type::ItemType;
@ -1664,10 +1664,10 @@ fn item_static(w: &mut fmt::Formatter, it: &clean::Item,
fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
f: &clean::Function) -> fmt::Result {
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \
try!(write!(w, "<pre class='rust fn'>{vis}{unsafety}fn \
{name}{generics}{decl}{where_clause}</pre>",
vis = VisSpace(it.visibility),
fn_style = FnStyleSpace(f.fn_style),
unsafety = UnsafetySpace(f.unsafety),
name = it.name.as_ref().unwrap().as_slice(),
generics = f.generics,
where_clause = WhereClause(&f.generics),
@ -1813,13 +1813,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
fn method(w: &mut fmt::Formatter, it: &clean::Item, fn_style: ast::FnStyle,
fn method(w: &mut fmt::Formatter, it: &clean::Item, unsafety: ast::Unsafety,
g: &clean::Generics, selfty: &clean::SelfTy,
d: &clean::FnDecl) -> fmt::Result {
write!(w, "{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
{generics}{decl}{where_clause}",
match fn_style {
ast::UnsafeFn => "unsafe ",
match unsafety {
ast::Unsafety::Unsafe => "unsafe ",
_ => "",
},
ty = shortty(it),
@ -1841,10 +1841,10 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
}
match meth.inner {
clean::TyMethodItem(ref m) => {
method(w, meth, m.fn_style, &m.generics, &m.self_, &m.decl)
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
}
clean::MethodItem(ref m) => {
method(w, meth, m.fn_style, &m.generics, &m.self_, &m.decl)
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
}
clean::AssociatedTypeItem(ref typ) => {
assoc_type(w, meth, typ)

View File

@ -121,7 +121,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
pub fn visit_fn(&mut self, item: &ast::Item,
name: ast::Ident, fd: &ast::FnDecl,
fn_style: &ast::FnStyle, _abi: &abi::Abi,
unsafety: &ast::Unsafety, _abi: &abi::Abi,
gen: &ast::Generics) -> Function {
debug!("Visiting fn");
Function {
@ -133,7 +133,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
name: name,
whence: item.span,
generics: gen.clone(),
fn_style: *fn_style,
unsafety: *unsafety,
}
}

View File

@ -20,7 +20,6 @@ pub use self::Decl_::*;
pub use self::ExplicitSelf_::*;
pub use self::Expr_::*;
pub use self::FloatTy::*;
pub use self::FnStyle::*;
pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*;
pub use self::ImplItem::*;
@ -1027,7 +1026,7 @@ pub struct TypeField {
pub struct TypeMethod {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub fn_style: FnStyle,
pub unsafety: Unsafety,
pub abi: Abi,
pub decl: P<FnDecl>,
pub generics: Generics,
@ -1198,7 +1197,7 @@ impl fmt::Show for Onceness {
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ClosureTy {
pub lifetimes: Vec<LifetimeDef>,
pub fn_style: FnStyle,
pub unsafety: Unsafety,
pub onceness: Onceness,
pub decl: P<FnDecl>,
pub bounds: TyParamBounds,
@ -1206,7 +1205,7 @@ pub struct ClosureTy {
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct BareFnTy {
pub fn_style: FnStyle,
pub unsafety: Unsafety,
pub abi: Abi,
pub lifetimes: Vec<LifetimeDef>,
pub decl: P<FnDecl>
@ -1304,21 +1303,17 @@ pub struct FnDecl {
pub variadic: bool
}
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum FnStyle {
/// Declared with "unsafe fn"
UnsafeFn,
/// Declared with "fn"
NormalFn,
#[deriving(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum Unsafety {
Unsafe,
Normal,
}
impl Copy for FnStyle {}
impl fmt::Show for FnStyle {
impl fmt::Show for Unsafety {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
NormalFn => "normal".fmt(f),
UnsafeFn => "unsafe".fmt(f),
Unsafety::Normal => "normal".fmt(f),
Unsafety::Unsafe => "unsafe".fmt(f),
}
}
}
@ -1371,7 +1366,7 @@ pub enum Method_ {
Generics,
Abi,
ExplicitSelf,
FnStyle,
Unsafety,
P<FnDecl>,
P<Block>,
Visibility),
@ -1609,7 +1604,7 @@ pub struct Item {
pub enum Item_ {
ItemStatic(P<Ty>, Mutability, P<Expr>),
ItemConst(P<Ty>, P<Expr>),
ItemFn(P<FnDecl>, FnStyle, Abi, Generics, P<Block>),
ItemFn(P<FnDecl>, Unsafety, Abi, Generics, P<Block>),
ItemMod(Mod),
ItemForeignMod(ForeignMod),
ItemTy(P<Ty>, Generics),

View File

@ -122,7 +122,7 @@ impl<'a> Code<'a> {
struct ItemFnParts<'a> {
ident: ast::Ident,
decl: &'a ast::FnDecl,
style: ast::FnStyle,
unsafety: ast::Unsafety,
abi: abi::Abi,
generics: &'a ast::Generics,
body: &'a Block,
@ -182,7 +182,7 @@ impl<'a> FnLikeNode<'a> {
pub fn kind(self) -> visit::FnKind<'a> {
let item = |: p: ItemFnParts<'a>| -> visit::FnKind<'a> {
visit::FkItemFn(p.ident, p.generics, p.style, p.abi)
visit::FkItemFn(p.ident, p.generics, p.unsafety, p.abi)
};
let closure = |: _: ClosureParts| {
visit::FkFnBlock
@ -200,9 +200,9 @@ impl<'a> FnLikeNode<'a> {
{
match self.node {
ast_map::NodeItem(i) => match i.node {
ast::ItemFn(ref decl, style, abi, ref generics, ref block) =>
ast::ItemFn(ref decl, unsafety, abi, ref generics, ref block) =>
item_fn(ItemFnParts{
ident: i.ident, decl: &**decl, style: style, body: &**block,
ident: i.ident, decl: &**decl, unsafety: unsafety, body: &**block,
generics: generics, abi: abi, id: i.id, span: i.span
}),
_ => panic!("item FnLikeNode that is not fn-like"),

View File

@ -233,14 +233,14 @@ pub fn trait_method_to_ty_method(method: &Method) -> TypeMethod {
ref generics,
abi,
ref explicit_self,
fn_style,
unsafety,
ref decl,
_,
vis) => {
TypeMethod {
ident: ident,
attrs: method.attrs.clone(),
fn_style: fn_style,
unsafety: unsafety,
decl: (*decl).clone(),
generics: generics.clone(),
explicit_self: (*explicit_self).clone(),
@ -722,7 +722,7 @@ pub trait PostExpansionMethod {
fn pe_generics<'a>(&'a self) -> &'a ast::Generics;
fn pe_abi(&self) -> Abi;
fn pe_explicit_self<'a>(&'a self) -> &'a ast::ExplicitSelf;
fn pe_fn_style(&self) -> ast::FnStyle;
fn pe_unsafety(&self) -> ast::Unsafety;
fn pe_fn_decl<'a>(&'a self) -> &'a ast::FnDecl;
fn pe_body<'a>(&'a self) -> &'a ast::Block;
fn pe_vis(&self) -> ast::Visibility;
@ -749,7 +749,7 @@ impl PostExpansionMethod for Method {
mf_method!(pe_abi,Abi,MethDecl(_,_,abi,_,_,_,_,_),abi)
mf_method!(pe_explicit_self,&'a ast::ExplicitSelf,
MethDecl(_,_,_,ref explicit_self,_,_,_,_),explicit_self)
mf_method!(pe_fn_style,ast::FnStyle,MethDecl(_,_,_,_,fn_style,_,_,_),fn_style)
mf_method!(pe_unsafety,ast::Unsafety,MethDecl(_,_,_,_,unsafety,_,_,_),unsafety)
mf_method!(pe_fn_decl,&'a ast::FnDecl,MethDecl(_,_,_,_,_,ref decl,_,_),&**decl)
mf_method!(pe_body,&'a ast::Block,MethDecl(_,_,_,_,_,_,ref body,_),&**body)
mf_method!(pe_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,_,vis),vis)

View File

@ -969,7 +969,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
name,
Vec::new(),
ast::ItemFn(self.fn_decl(inputs, output),
ast::NormalFn,
ast::Unsafety::Normal,
abi::Rust,
generics,
body))

View File

@ -684,7 +684,7 @@ impl<'a> MethodDef<'a> {
fn_generics,
abi,
explicit_self,
ast::NormalFn,
ast::Unsafety::Normal,
fn_decl,
body_block,
ast::Inherited)

View File

@ -415,9 +415,9 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
}
TyClosure(f) => {
TyClosure(f.map(|ClosureTy {fn_style, onceness, bounds, decl, lifetimes}| {
TyClosure(f.map(|ClosureTy {unsafety, onceness, bounds, decl, lifetimes}| {
ClosureTy {
fn_style: fn_style,
unsafety: unsafety,
onceness: onceness,
bounds: fld.fold_bounds(bounds),
decl: fld.fold_fn_decl(decl),
@ -426,9 +426,9 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
}))
}
TyBareFn(f) => {
TyBareFn(f.map(|BareFnTy {lifetimes, fn_style, abi, decl}| BareFnTy {
TyBareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy {
lifetimes: fld.fold_lifetime_defs(lifetimes),
fn_style: fn_style,
unsafety: unsafety,
abi: abi,
decl: fld.fold_fn_decl(decl)
}))
@ -983,10 +983,10 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
ItemConst(t, e) => {
ItemConst(folder.fold_ty(t), folder.fold_expr(e))
}
ItemFn(decl, fn_style, abi, generics, body) => {
ItemFn(decl, unsafety, abi, generics, body) => {
ItemFn(
folder.fold_fn_decl(decl),
fn_style,
unsafety,
abi,
folder.fold_generics(generics),
folder.fold_block(body)
@ -1077,7 +1077,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
id,
ident,
attrs,
fn_style,
unsafety,
abi,
decl,
generics,
@ -1089,7 +1089,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
id: fld.new_id(id),
ident: fld.fold_ident(ident),
attrs: attrs.move_map(|a| fld.fold_attribute(a)),
fn_style: fn_style,
unsafety: unsafety,
abi: abi,
decl: fld.fold_fn_decl(decl),
generics: fld.fold_generics(generics),
@ -1211,7 +1211,7 @@ pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<
generics,
abi,
explicit_self,
fn_style,
unsafety,
decl,
body,
vis) => {
@ -1219,7 +1219,7 @@ pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<
folder.fold_generics(generics),
abi,
folder.fold_explicit_self(explicit_self),
fn_style,
unsafety,
folder.fold_fn_decl(decl),
folder.fold_block(body),
vis)

View File

@ -1062,7 +1062,7 @@ mod test {
span:sp(15,15)})), // not sure
variadic: false
}),
ast::NormalFn,
ast::Unsafety::Normal,
abi::Rust,
ast::Generics{ // no idea on either of these:
lifetimes: Vec::new(),

View File

@ -16,7 +16,7 @@ use self::ItemOrViewItem::*;
use abi;
use ast::{AssociatedType, BareFnTy, ClosureTy};
use ast::{RegionTyParamBound, TraitTyParamBound};
use ast::{ProvidedMethod, Public, FnStyle};
use ast::{ProvidedMethod, Public, Unsafety};
use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue};
use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, Block};
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause};
@ -34,7 +34,7 @@ use ast::{Many};
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
use ast::{FnOnceUnboxedClosureKind};
use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy};
use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic};
use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic};
use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
use ast::{LifetimeDef, Lit, Lit_};
@ -60,7 +60,7 @@ use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath
use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq};
use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
use ast::{UnnamedField, UnsafeBlock};
use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
use ast::{ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
use ast::{Visibility, WhereClause};
use ast;
@ -1121,7 +1121,7 @@ impl<'a> Parser<'a> {
Function Style
*/
let fn_style = self.parse_unsafety();
let unsafety = self.parse_unsafety();
let abi = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abi().unwrap_or(abi::C)
} else {
@ -1139,7 +1139,7 @@ impl<'a> Parser<'a> {
});
TyBareFn(P(BareFnTy {
abi: abi,
fn_style: fn_style,
unsafety: unsafety,
lifetimes: lifetime_defs,
decl: decl
}))
@ -1240,7 +1240,7 @@ impl<'a> Parser<'a> {
*/
let fn_style = self.parse_unsafety();
let unsafety = self.parse_unsafety();
let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
@ -1266,7 +1266,7 @@ impl<'a> Parser<'a> {
});
TyClosure(P(ClosureTy {
fn_style: fn_style,
unsafety: unsafety,
onceness: Many,
bounds: bounds,
decl: decl,
@ -1274,11 +1274,11 @@ impl<'a> Parser<'a> {
}))
}
pub fn parse_unsafety(&mut self) -> FnStyle {
pub fn parse_unsafety(&mut self) -> Unsafety {
if self.eat_keyword(keywords::Unsafe) {
return UnsafeFn;
return Unsafety::Unsafe;
} else {
return NormalFn;
return Unsafety::Normal;
}
}
@ -1351,7 +1351,7 @@ impl<'a> Parser<'a> {
let lo = p.span.lo;
let vis = p.parse_visibility();
let style = p.parse_fn_style();
let style = p.parse_unsafety();
let abi = if p.eat_keyword(keywords::Extern) {
p.parse_opt_abi().unwrap_or(abi::C)
} else {
@ -1379,7 +1379,7 @@ impl<'a> Parser<'a> {
RequiredMethod(TypeMethod {
ident: ident,
attrs: attrs,
fn_style: style,
unsafety: style,
decl: d,
generics: generics,
abi: abi,
@ -4548,12 +4548,12 @@ impl<'a> Parser<'a> {
}
/// Parse an item-position function declaration.
fn parse_item_fn(&mut self, fn_style: FnStyle, abi: abi::Abi) -> ItemInfo {
fn parse_item_fn(&mut self, unsafety: Unsafety, abi: abi::Abi) -> ItemInfo {
let (ident, mut generics) = self.parse_fn_header();
let decl = self.parse_fn_decl(false);
self.parse_where_clause(&mut generics);
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
(ident, ItemFn(decl, fn_style, abi, generics, body), Some(inner_attrs))
(ident, ItemFn(decl, unsafety, abi, generics, body), Some(inner_attrs))
}
/// Parse a method in a trait impl
@ -4591,7 +4591,7 @@ impl<'a> Parser<'a> {
self.span.hi) };
(ast::MethMac(m), self.span.hi, attrs)
} else {
let fn_style = self.parse_fn_style();
let unsafety = self.parse_unsafety();
let abi = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abi().unwrap_or(abi::C)
} else {
@ -4612,7 +4612,7 @@ impl<'a> Parser<'a> {
generics,
abi,
explicit_self,
fn_style,
unsafety,
decl,
body,
visa),
@ -5143,16 +5143,6 @@ impl<'a> Parser<'a> {
})
}
/// Parse unsafe or not
fn parse_fn_style(&mut self) -> FnStyle {
if self.eat_keyword(keywords::Unsafe) {
UnsafeFn
} else {
NormalFn
}
}
/// At this point, this is essentially a wrapper for
/// parse_foreign_items.
fn parse_foreign_mod_items(&mut self,
@ -5491,7 +5481,7 @@ impl<'a> Parser<'a> {
// EXTERN FUNCTION ITEM
let abi = opt_abi.unwrap_or(abi::C);
let (ident, item_, extra_attrs) =
self.parse_item_fn(NormalFn, abi);
self.parse_item_fn(Unsafety::Normal, abi);
let last_span = self.last_span;
let item = self.mk_item(lo,
last_span.hi,
@ -5554,7 +5544,7 @@ impl<'a> Parser<'a> {
// FUNCTION ITEM
self.bump();
let (ident, item_, extra_attrs) =
self.parse_item_fn(NormalFn, abi::Rust);
self.parse_item_fn(Unsafety::Normal, abi::Rust);
let last_span = self.last_span;
let item = self.mk_item(lo,
last_span.hi,
@ -5575,7 +5565,7 @@ impl<'a> Parser<'a> {
};
self.expect_keyword(keywords::Fn);
let (ident, item_, extra_attrs) =
self.parse_item_fn(UnsafeFn, abi);
self.parse_item_fn(Unsafety::Unsafe, abi);
let last_span = self.last_span;
let item = self.mk_item(lo,
last_span.hi,

View File

@ -363,11 +363,11 @@ pub fn ident_to_string(id: &ast::Ident) -> String {
$to_string(|s| s.print_ident(*id))
}
pub fn fun_to_string(decl: &ast::FnDecl, fn_style: ast::FnStyle, name: ast::Ident,
pub fn fun_to_string(decl: &ast::FnDecl, unsafety: ast::Unsafety, name: ast::Ident,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
generics: &ast::Generics) -> String {
$to_string(|s| {
try!(s.print_fn(decl, Some(fn_style), abi::Rust,
try!(s.print_fn(decl, Some(unsafety), abi::Rust,
name, generics, opt_explicit_self, ast::Inherited));
try!(s.end()); // Close the head box
s.end() // Close the outer box
@ -707,7 +707,7 @@ impl<'a> State<'a> {
};
try!(self.print_ty_fn(Some(f.abi),
None,
f.fn_style,
f.unsafety,
ast::Many,
&*f.decl,
None,
@ -726,7 +726,7 @@ impl<'a> State<'a> {
};
try!(self.print_ty_fn(None,
Some('&'),
f.fn_style,
f.unsafety,
f.onceness,
&*f.decl,
None,
@ -858,10 +858,10 @@ impl<'a> State<'a> {
try!(word(&mut self.s, ";"));
try!(self.end()); // end the outer cbox
}
ast::ItemFn(ref decl, fn_style, abi, ref typarams, ref body) => {
ast::ItemFn(ref decl, unsafety, abi, ref typarams, ref body) => {
try!(self.print_fn(
&**decl,
Some(fn_style),
Some(unsafety),
abi,
item.ident,
typarams,
@ -1188,7 +1188,7 @@ impl<'a> State<'a> {
try!(self.print_outer_attributes(m.attrs.as_slice()));
try!(self.print_ty_fn(None,
None,
m.fn_style,
m.unsafety,
ast::Many,
&*m.decl,
Some(m.ident),
@ -1223,12 +1223,12 @@ impl<'a> State<'a> {
ref generics,
abi,
ref explicit_self,
fn_style,
unsafety,
ref decl,
ref body,
vis) => {
try!(self.print_fn(&**decl,
Some(fn_style),
Some(unsafety),
abi,
ident,
generics,
@ -2164,14 +2164,14 @@ impl<'a> State<'a> {
pub fn print_fn(&mut self,
decl: &ast::FnDecl,
fn_style: Option<ast::FnStyle>,
unsafety: Option<ast::Unsafety>,
abi: abi::Abi,
name: ast::Ident,
generics: &ast::Generics,
opt_explicit_self: Option<&ast::ExplicitSelf_>,
vis: ast::Visibility) -> IoResult<()> {
try!(self.head(""));
try!(self.print_fn_header_info(opt_explicit_self, fn_style, abi, vis));
try!(self.print_fn_header_info(opt_explicit_self, unsafety, abi, vis));
try!(self.nbsp());
try!(self.print_ident(name));
try!(self.print_generics(generics));
@ -2588,7 +2588,7 @@ impl<'a> State<'a> {
pub fn print_ty_fn(&mut self,
opt_abi: Option<abi::Abi>,
opt_sigil: Option<char>,
fn_style: ast::FnStyle,
unsafety: ast::Unsafety,
onceness: ast::Onceness,
decl: &ast::FnDecl,
id: Option<ast::Ident>,
@ -2603,11 +2603,11 @@ impl<'a> State<'a> {
if opt_sigil == Some('~') && onceness == ast::Once {
try!(word(&mut self.s, "proc"));
} else if opt_sigil == Some('&') {
try!(self.print_fn_style(fn_style));
try!(self.print_unsafety(unsafety));
try!(self.print_extern_opt_abi(opt_abi));
} else {
assert!(opt_sigil.is_none());
try!(self.print_fn_style(fn_style));
try!(self.print_unsafety(unsafety));
try!(self.print_opt_abi_and_extern_if_nondefault(opt_abi));
try!(word(&mut self.s, "fn"));
}
@ -2872,10 +2872,10 @@ impl<'a> State<'a> {
}
}
pub fn print_opt_fn_style(&mut self,
opt_fn_style: Option<ast::FnStyle>) -> IoResult<()> {
match opt_fn_style {
Some(fn_style) => self.print_fn_style(fn_style),
pub fn print_opt_unsafety(&mut self,
opt_unsafety: Option<ast::Unsafety>) -> IoResult<()> {
match opt_unsafety {
Some(unsafety) => self.print_unsafety(unsafety),
None => Ok(())
}
}
@ -2906,11 +2906,11 @@ impl<'a> State<'a> {
pub fn print_fn_header_info(&mut self,
_opt_explicit_self: Option<&ast::ExplicitSelf_>,
opt_fn_style: Option<ast::FnStyle>,
opt_unsafety: Option<ast::Unsafety>,
abi: abi::Abi,
vis: ast::Visibility) -> IoResult<()> {
try!(word(&mut self.s, visibility_qualified(vis, "").as_slice()));
try!(self.print_opt_fn_style(opt_fn_style));
try!(self.print_opt_unsafety(opt_unsafety));
if abi != abi::Rust {
try!(self.word_nbsp("extern"));
@ -2920,10 +2920,10 @@ impl<'a> State<'a> {
word(&mut self.s, "fn")
}
pub fn print_fn_style(&mut self, s: ast::FnStyle) -> IoResult<()> {
pub fn print_unsafety(&mut self, s: ast::Unsafety) -> IoResult<()> {
match s {
ast::NormalFn => Ok(()),
ast::UnsafeFn => self.word_nbsp("unsafe"),
ast::Unsafety::Normal => Ok(()),
ast::Unsafety::Unsafe => self.word_nbsp("unsafe"),
}
}
}
@ -2950,7 +2950,7 @@ mod test {
variadic: false
};
let generics = ast_util::empty_generics();
assert_eq!(fun_to_string(&decl, ast::NormalFn, abba_ident,
assert_eq!(fun_to_string(&decl, ast::Unsafety::Normal, abba_ident,
None, &generics),
"fn abba()");
}

View File

@ -123,7 +123,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
match i.node {
ast::ItemFn(_, ast::UnsafeFn, _, _, _) => {
ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _) => {
let diag = self.cx.span_diagnostic;
diag.span_fatal(i.span,
"unsafe functions cannot be used for \

View File

@ -34,7 +34,7 @@ use owned_slice::OwnedSlice;
pub enum FnKind<'a> {
/// fn foo() or extern "Abi" fn foo()
FkItemFn(Ident, &'a Generics, FnStyle, Abi),
FkItemFn(Ident, &'a Generics, Unsafety, Abi),
/// fn foo(&self)
FkMethod(Ident, &'a Generics, &'a Method),