1
Fork 0

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 { match c {
'u' => ast::UnsafeFn, 'u' => ast::Unsafety::Unsafe,
'n' => ast::NormalFn, 'n' => ast::Unsafety::Normal,
_ => panic!("parse_fn_style: bad fn_style {}", c) _ => 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>, fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
conv: conv_did) -> ty::ClosureTy<'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 onceness = parse_onceness(next(st));
let store = parse_trait_store(st, |x,y| conv(x,y)); let store = parse_trait_store(st, |x,y| conv(x,y));
let bounds = parse_existential_bounds(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 sig = parse_sig(st, |x,y| conv(x,y));
let abi = parse_abi_set(st); let abi = parse_abi_set(st);
ty::ClosureTy { ty::ClosureTy {
fn_style: fn_style, unsafety: unsafety,
onceness: onceness, onceness: onceness,
store: store, store: store,
bounds: bounds, 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>, fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
conv: conv_did) -> ty::BareFnTy<'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 abi = parse_abi_set(st);
let sig = parse_sig(st, |x,y| conv(x,y)); let sig = parse_sig(st, |x,y| conv(x,y));
ty::BareFnTy { ty::BareFnTy {
fn_style: fn_style, unsafety: unsafety,
abi: abi, abi: abi,
sig: sig 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 { match p {
ast::NormalFn => mywrite!(w, "n"), ast::Unsafety::Normal => mywrite!(w, "n"),
ast::UnsafeFn => mywrite!(w, "u"), 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>, pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
ft: &ty::BareFnTy<'tcx>) { ft: &ty::BareFnTy<'tcx>) {
enc_fn_style(w, ft.fn_style); enc_unsafety(w, ft.unsafety);
enc_abi(w, ft.abi); enc_abi(w, ft.abi);
enc_fn_sig(w, cx, &ft.sig); enc_fn_sig(w, cx, &ft.sig);
} }
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
ft: &ty::ClosureTy<'tcx>) { ft: &ty::ClosureTy<'tcx>) {
enc_fn_style(w, ft.fn_style); enc_unsafety(w, ft.unsafety);
enc_onceness(w, ft.onceness); enc_onceness(w, ft.onceness);
enc_trait_store(w, cx, ft.store); enc_trait_store(w, cx, ft.store);
enc_existential_bounds(w, cx, &ft.bounds); 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 { fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty { match ty.sty {
ty::ty_bare_fn(ref f) => f.fn_style == ast::UnsafeFn, ty::ty_bare_fn(ref f) => f.unsafety == ast::Unsafety::Unsafe,
ty::ty_closure(ref f) => f.fn_style == ast::UnsafeFn, ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe,
_ => false, _ => 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 { let (is_item_fn, is_unsafe_fn) = match fn_kind {
visit::FkItemFn(_, _, fn_style, _) => visit::FkItemFn(_, _, fn_style, _) =>
(true, fn_style == ast::UnsafeFn), (true, fn_style == ast::Unsafety::Unsafe),
visit::FkMethod(_, _, method) => visit::FkMethod(_, _, method) =>
(true, method.pe_fn_style() == ast::UnsafeFn), (true, method.pe_unsafety() == ast::Unsafety::Unsafe),
_ => (false, false), _ => (false, false),
}; };

View file

@ -521,7 +521,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
debug!("coerce_from_bare_fn(a={}, b={})", debug!("coerce_from_bare_fn(a={}, b={})",
a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx)); 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); return self.subtype(a, b);
} }

View file

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

View file

@ -21,7 +21,7 @@ use middle::infer::{TypeTrace, Subtype};
use middle::infer::type_variable::{EqTo}; use middle::infer::type_variable::{EqTo};
use util::ppaux::{Repr}; use util::ppaux::{Repr};
use syntax::ast::{Onceness, FnStyle}; use syntax::ast::{Onceness, Unsafety};
pub struct Equate<'f, 'tcx: 'f> { pub struct Equate<'f, 'tcx: 'f> {
fields: CombineFields<'f, 'tcx> 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 }) 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 { 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 { } else {
Ok(a) Ok(a)
} }

View file

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

View file

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

View file

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

View file

@ -23,7 +23,7 @@ use middle::ty::{mod, Ty};
use middle::ty::TyVar; use middle::ty::TyVar;
use util::ppaux::{Repr}; use util::ppaux::{Repr};
use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable}; use syntax::ast::{Onceness, MutImmutable, MutMutable, Unsafety};
/// "Greatest lower bound" (common subtype) /// "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 Ok(*a) // return is meaningless in sub, just return *a
} }
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> { fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
self.lub().fn_styles(a, b).compare(b, || { self.lub().unsafeties(a, b).compare(b, || {
ty::terr_fn_style_mismatch(expected_found(self, a, 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 // provide an impl, but only for suitable `fn` pointers
ty::ty_bare_fn(ty::BareFnTy { ty::ty_bare_fn(ty::BareFnTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
abi: abi::Rust, abi: abi::Rust,
sig: ty::FnSig { sig: ty::FnSig {
inputs: _, inputs: _,
@ -1505,7 +1505,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
let sig = match self_ty.sty { let sig = match self_ty.sty {
ty::ty_bare_fn(ty::BareFnTy { ty::ty_bare_fn(ty::BareFnTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
abi: abi::Rust, abi: abi::Rust,
ref sig ref sig
}) => { }) => {

View file

@ -80,7 +80,7 @@ use std::rc::Rc;
use std::collections::enum_set::{EnumSet, CLike}; use std::collections::enum_set::{EnumSet, CLike};
use std::collections::hash_map::{HashMap, Occupied, Vacant}; use std::collections::hash_map::{HashMap, Occupied, Vacant};
use syntax::abi; 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::{MutImmutable, MutMutable, Name, NamedField, NodeId};
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField}; use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
use syntax::ast::{Visibility}; use syntax::ast::{Visibility};
@ -908,14 +908,14 @@ pub fn type_escapes_depth(ty: Ty, depth: uint) -> bool {
#[deriving(Clone, PartialEq, Eq, Hash, Show)] #[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct BareFnTy<'tcx> { pub struct BareFnTy<'tcx> {
pub fn_style: ast::FnStyle, pub unsafety: ast::Unsafety,
pub abi: abi::Abi, pub abi: abi::Abi,
pub sig: FnSig<'tcx>, pub sig: FnSig<'tcx>,
} }
#[deriving(Clone, PartialEq, Eq, Hash, Show)] #[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ClosureTy<'tcx> { pub struct ClosureTy<'tcx> {
pub fn_style: ast::FnStyle, pub unsafety: ast::Unsafety,
pub onceness: ast::Onceness, pub onceness: ast::Onceness,
pub store: TraitStore, pub store: TraitStore,
pub bounds: ExistentialBounds, pub bounds: ExistentialBounds,
@ -1380,7 +1380,7 @@ impl<T:Copy> Copy for expected_found<T> {}
#[deriving(Clone, Show)] #[deriving(Clone, Show)]
pub enum type_err<'tcx> { pub enum type_err<'tcx> {
terr_mismatch, terr_mismatch,
terr_fn_style_mismatch(expected_found<FnStyle>), terr_unsafety_mismatch(expected_found<ast::Unsafety>),
terr_onceness_mismatch(expected_found<Onceness>), terr_onceness_mismatch(expected_found<Onceness>),
terr_abi_mismatch(expected_found<abi::Abi>), terr_abi_mismatch(expected_found<abi::Abi>),
terr_mutability, 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(); let input_args = input_tys.iter().map(|ty| *ty).collect();
mk_bare_fn(cx, mk_bare_fn(cx,
BareFnTy { BareFnTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
abi: abi::Rust, abi: abi::Rust,
sig: FnSig { sig: FnSig {
inputs: input_args, inputs: input_args,
@ -3994,7 +3994,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
ty::mk_closure( ty::mk_closure(
cx, cx,
ty::ClosureTy {fn_style: b.fn_style, ty::ClosureTy {unsafety: b.unsafety,
onceness: ast::Many, onceness: ast::Many,
store: store, store: store,
bounds: bounds, bounds: bounds,
@ -4404,7 +4404,7 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
match *err { match *err {
terr_cyclic_ty => "cyclic type of infinite size".to_string(), terr_cyclic_ty => "cyclic type of infinite size".to_string(),
terr_mismatch => "types differ".to_string(), terr_mismatch => "types differ".to_string(),
terr_fn_style_mismatch(values) => { terr_unsafety_mismatch(values) => {
format!("expected {} fn, found {} fn", format!("expected {} fn, found {} fn",
values.expected.to_string(), values.expected.to_string(),
values.found.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) => { ty_bare_fn(ref b) => {
byte!(14); byte!(14);
hash!(b.fn_style); hash!(b.unsafety);
hash!(b.abi); hash!(b.abi);
} }
ty_closure(ref c) => { ty_closure(ref c) => {
byte!(15); byte!(15);
hash!(c.fn_style); hash!(c.unsafety);
hash!(c.onceness); hash!(c.onceness);
hash!(c.bounds); hash!(c.bounds);
match c.store { 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), ty::BareFnTy { sig: fty.sig.fold_with(this),
abi: fty.abi, abi: fty.abi,
fn_style: fty.fn_style } unsafety: fty.unsafety }
} }
pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, 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 { ty::ClosureTy {
store: fty.store.fold_with(this), store: fty.store.fold_with(this),
sig: fty.sig.fold_with(this), sig: fty.sig.fold_with(this),
fn_style: fty.fn_style, unsafety: fty.unsafety,
onceness: fty.onceness, onceness: fty.onceness,
bounds: fty.bounds.fold_with(this), bounds: fty.bounds.fold_with(this),
abi: fty.abi, 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 { pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>, fn bare_fn_to_string<'tcx>(cx: &ctxt<'tcx>,
fn_style: ast::FnStyle, unsafety: ast::Unsafety,
abi: abi::Abi, abi: abi::Abi,
ident: Option<ast::Ident>, ident: Option<ast::Ident>,
sig: &ty::FnSig<'tcx>) sig: &ty::FnSig<'tcx>)
-> String { -> String {
let mut s = String::new(); let mut s = String::new();
match fn_style { match unsafety {
ast::NormalFn => {} ast::Unsafety::Normal => {}
_ => { ast::Unsafety::Unsafe => {
s.push_str(fn_style.to_string().as_slice()); s.push_str(unsafety.to_string().as_slice());
s.push(' '); s.push(' ');
} }
}; };
@ -302,10 +302,10 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
} }
} }
match cty.fn_style { match cty.unsafety {
ast::NormalFn => {} ast::Unsafety::Normal => {}
_ => { ast::Unsafety::Unsafe => {
s.push_str(cty.fn_style.to_string().as_slice()); s.push_str(cty.unsafety.to_string().as_slice());
s.push(' '); 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) closure_to_string(cx, &**f)
} }
ty_bare_fn(ref 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_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
ty_err => "[type error]".to_string(), 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> { impl<'tcx> Repr<'tcx> for ty::BareFnTy<'tcx> {
fn repr(&self, tcx: &ctxt<'tcx>) -> String { fn repr(&self, tcx: &ctxt<'tcx>) -> String {
format!("BareFnTy {{fn_style: {}, abi: {}, sig: {}}}", format!("BareFnTy {{unsafety: {}, abi: {}, sig: {}}}",
self.fn_style, self.unsafety,
self.abi.to_string(), self.abi.to_string(),
self.sig.repr(tcx)) self.sig.repr(tcx))
} }

View file

@ -270,7 +270,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
-> Ty<'tcx> -> Ty<'tcx>
{ {
ty::mk_closure(self.infcx.tcx, ty::ClosureTy { ty::mk_closure(self.infcx.tcx, ty::ClosureTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
onceness: ast::Many, onceness: ast::Many,
store: ty::RegionTraitStore(region_bound, ast::MutMutable), store: ty::RegionTraitStore(region_bound, ast::MutMutable),
bounds: ty::region_existential_bound(region_bound), 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. // which is the fn pointer, and `args`, which is the arguments tuple.
let (input_tys, output_ty) = let (input_tys, output_ty) =
match bare_fn_ty.sty { 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, abi: synabi::Rust,
sig: ty::FnSig { inputs: ref input_tys, sig: ty::FnSig { inputs: ref input_tys,
output: output_ty, 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_input_ty = ty::mk_tup(tcx, input_tys.to_vec());
let tuple_fn_ty = ty::mk_bare_fn(tcx, let tuple_fn_ty = ty::mk_bare_fn(tcx,
ty::BareFnTy { fn_style: ast::NormalFn, ty::BareFnTy { unsafety: ast::Unsafety::Normal,
abi: synabi::RustCall, abi: synabi::RustCall,
sig: ty::FnSig { sig: ty::FnSig {
inputs: vec![bare_fn_ty_ref, inputs: vec![bare_fn_ty_ref,

View file

@ -433,8 +433,8 @@ impl<'tcx> TypeMap<'tcx> {
&trait_data.principal.substs, &trait_data.principal.substs,
&mut unique_type_id); &mut unique_type_id);
}, },
ty::ty_bare_fn(ty::BareFnTy{ fn_style, abi, ref sig } ) => { ty::ty_bare_fn(ty::BareFnTy{ unsafety, abi, ref sig } ) => {
if fn_style == ast::UnsafeFn { if unsafety == ast::Unsafety::Unsafe {
unique_type_id.push_str("unsafe "); unique_type_id.push_str("unsafe ");
} }
@ -551,13 +551,13 @@ impl<'tcx> TypeMap<'tcx> {
cx: &CrateContext<'a, 'tcx>, cx: &CrateContext<'a, 'tcx>,
closure_ty: ty::ClosureTy<'tcx>, closure_ty: ty::ClosureTy<'tcx>,
unique_type_id: &mut String) { unique_type_id: &mut String) {
let ty::ClosureTy { fn_style, let ty::ClosureTy { unsafety,
onceness, onceness,
store, store,
ref bounds, ref bounds,
ref sig, ref sig,
abi: _ } = closure_ty; abi: _ } = closure_ty;
if fn_style == ast::UnsafeFn { if unsafety == ast::Unsafety::Unsafe {
unique_type_id.push_str("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_item_name(cx, trait_data.principal.def_id, false, output);
push_type_params(cx, &trait_data.principal.substs, output); push_type_params(cx, &trait_data.principal.substs, output);
}, },
ty::ty_bare_fn(ty::BareFnTy{ fn_style, abi, ref sig } ) => { ty::ty_bare_fn(ty::BareFnTy{ unsafety, abi, ref sig } ) => {
if fn_style == ast::UnsafeFn { if unsafety == ast::Unsafety::Unsafe {
output.push_str("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, onceness,
store, store,
ref sig, ref sig,
.. // omitting bounds ... .. // omitting bounds ...
}) => { }) => {
if fn_style == ast::UnsafeFn { if unsafety == ast::Unsafety::Unsafe {
output.push_str("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, tcx.sess.span_err(ast_ty.span,
"variadic function must have C calling convention"); "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) => { ast::TyClosure(ref f) => {
// Use corresponding trait store to figure out default bounds // 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, None,
f.bounds.as_slice()); f.bounds.as_slice());
let fn_decl = ty_of_closure(this, let fn_decl = ty_of_closure(this,
f.fn_style, f.unsafety,
f.onceness, f.onceness,
bounds, bounds,
ty::RegionTraitStore( ty::RegionTraitStore(
@ -1082,7 +1082,7 @@ struct SelfInfo<'a, 'tcx> {
pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>( pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>(
this: &AC, this: &AC,
fn_style: ast::FnStyle, unsafety: ast::Unsafety,
untransformed_self_ty: Ty<'tcx>, untransformed_self_ty: Ty<'tcx>,
explicit_self: &ast::ExplicitSelf, explicit_self: &ast::ExplicitSelf,
decl: &ast::FnDecl, decl: &ast::FnDecl,
@ -1094,22 +1094,22 @@ pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>(
}); });
let (bare_fn_ty, optional_explicit_self_category) = let (bare_fn_ty, optional_explicit_self_category) =
ty_of_method_or_bare_fn(this, ty_of_method_or_bare_fn(this,
fn_style, unsafety,
abi, abi,
self_info, self_info,
decl); decl);
(bare_fn_ty, optional_explicit_self_category.unwrap()) (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> { 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 bare_fn_ty
} }
fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>( fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>(
this: &AC, this: &AC,
fn_style: ast::FnStyle, unsafety: ast::Unsafety,
abi: abi::Abi, abi: abi::Abi,
opt_self_info: Option<SelfInfo<'a, 'tcx>>, opt_self_info: Option<SelfInfo<'a, 'tcx>>,
decl: &ast::FnDecl) decl: &ast::FnDecl)
@ -1207,7 +1207,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx, AC: AstConv<'tcx>>(
}; };
(ty::BareFnTy { (ty::BareFnTy {
fn_style: fn_style, unsafety: unsafety,
abi: abi, abi: abi,
sig: ty::FnSig { sig: ty::FnSig {
inputs: self_and_input_tys, 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>>( pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>(
this: &AC, this: &AC,
fn_style: ast::FnStyle, unsafety: ast::Unsafety,
onceness: ast::Onceness, onceness: ast::Onceness,
bounds: ty::ExistentialBounds, bounds: ty::ExistentialBounds,
store: ty::TraitStore, 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())); debug!("ty_of_closure: output_ty={}", output_ty.repr(this.tcx()));
ty::ClosureTy { ty::ClosureTy {
fn_style: fn_style, unsafety: unsafety,
onceness: onceness, onceness: onceness,
store: store, store: store,
bounds: bounds, 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( let mut fn_ty = astconv::ty_of_closure(
fcx, fcx,
ast::NormalFn, ast::Unsafety::Normal,
ast::Many, ast::Many,
// The `RegionTraitStore` and region_existential_bounds // 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); fcx.write_ty(expr.id, closure_type);
check_fn(fcx.ccx, check_fn(fcx.ccx,
ast::NormalFn, ast::Unsafety::Normal,
expr.id, expr.id,
&fn_ty.sig, &fn_ty.sig,
decl, decl,
@ -304,7 +304,7 @@ fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
// construct the function type // construct the function type
let fn_ty = astconv::ty_of_closure(fcx, let fn_ty = astconv::ty_of_closure(fcx,
ast::NormalFn, ast::Unsafety::Normal,
expected_onceness, expected_onceness,
expected_bounds, expected_bounds,
store, 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. // style inferred for it, then check it under its parent's style.
// Otherwise, use its own // Otherwise, use its own
let (inherited_style, inherited_style_id) = match store { 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), fcx.ps.borrow().def),
ty::UniqTraitStore => (ast::NormalFn, expr.id) ty::UniqTraitStore => (ast::Unsafety::Normal, expr.id)
}; };
check_fn(fcx.ccx, check_fn(fcx.ccx,

View file

@ -115,7 +115,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
// Create the final `MethodCallee`. // Create the final `MethodCallee`.
let fty = ty::mk_bare_fn(self.tcx(), ty::BareFnTy { let fty = ty::mk_bare_fn(self.tcx(), ty::BareFnTy {
sig: method_sig, sig: method_sig,
fn_style: pick.method_ty.fty.fn_style, unsafety: pick.method_ty.fty.unsafety,
abi: pick.method_ty.fty.abi.clone(), abi: pick.method_ty.fty.abi.clone(),
}); });
let callee = MethodCallee { 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 transformed_self_ty = fn_sig.inputs[0];
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy { let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
sig: fn_sig, sig: fn_sig,
fn_style: bare_fn_ty.fn_style, unsafety: bare_fn_ty.unsafety,
abi: bare_fn_ty.abi.clone(), abi: bare_fn_ty.abi.clone(),
}); });

View file

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

View file

@ -277,7 +277,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
&m.explicit_self, &m.explicit_self,
m.abi, m.abi,
&m.generics, &m.generics,
&m.fn_style, &m.unsafety,
&*m.decl) &*m.decl)
} }
ast::ProvidedMethod(ref m) => { ast::ProvidedMethod(ref m) => {
@ -291,7 +291,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
m.pe_explicit_self(), m.pe_explicit_self(),
m.pe_abi(), m.pe_abi(),
m.pe_generics(), m.pe_generics(),
&m.pe_fn_style(), &m.pe_unsafety(),
&*m.pe_fn_decl()) &*m.pe_fn_decl())
} }
ast::TypeTraitItem(ref at) => { ast::TypeTraitItem(ref at) => {
@ -366,7 +366,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
m_explicit_self: &ast::ExplicitSelf, m_explicit_self: &ast::ExplicitSelf,
m_abi: abi::Abi, m_abi: abi::Abi,
m_generics: &ast::Generics, m_generics: &ast::Generics,
m_fn_style: &ast::FnStyle, m_unsafety: &ast::Unsafety,
m_decl: &ast::FnDecl) m_decl: &ast::FnDecl)
-> ty::Method<'tcx> { -> ty::Method<'tcx> {
let ty_generics = 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(), let trait_self_ty = ty::mk_self_type(tmcx.tcx(),
local_def(trait_id)); local_def(trait_id));
astconv::ty_of_method(&tmcx, astconv::ty_of_method(&tmcx,
*m_fn_style, *m_unsafety,
trait_self_ty, trait_self_ty,
m_explicit_self, m_explicit_self,
m_decl, m_decl,
@ -572,7 +572,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
method_generics: &m_ty_generics, method_generics: &m_ty_generics,
}; };
astconv::ty_of_method(&imcx, astconv::ty_of_method(&imcx,
m.pe_fn_style(), m.pe_unsafety(),
untransformed_rcvr_ty, untransformed_rcvr_ty,
m.pe_explicit_self(), m.pe_explicit_self(),
&*m.pe_fn_decl(), &*m.pe_fn_decl(),
@ -586,7 +586,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
method_generics: &m_ty_generics, method_generics: &m_ty_generics,
}; };
astconv::ty_of_method(&tmcx, astconv::ty_of_method(&tmcx,
m.pe_fn_style(), m.pe_unsafety(),
untransformed_rcvr_ty, untransformed_rcvr_ty,
m.pe_explicit_self(), m.pe_explicit_self(),
&*m.pe_fn_decl(), &*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()); tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty; 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( let ty_generics = ty_generics_for_fn_or_method(
ccx, ccx,
generics, generics,
@ -1457,7 +1457,7 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
ccx: ccx, ccx: ccx,
generics: &ty_generics, 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 { let pty = Polytype {
generics: ty_generics, generics: ty_generics,
@ -2151,7 +2151,7 @@ pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
ccx.tcx, ccx.tcx,
ty::BareFnTy { ty::BareFnTy {
abi: abi, abi: abi,
fn_style: ast::UnsafeFn, unsafety: ast::Unsafety::Unsafe,
sig: ty::FnSig {inputs: input_tys, sig: ty::FnSig {inputs: input_tys,
output: output, output: output,
variadic: decl.variadic} 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 { let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
abi: abi::Rust, abi: abi::Rust,
sig: ty::FnSig { sig: ty::FnSig {
inputs: Vec::new(), inputs: Vec::new(),
@ -274,7 +274,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
} }
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
fn_style: ast::NormalFn, unsafety: ast::Unsafety::Normal,
abi: abi::Rust, abi: abi::Rust,
sig: ty::FnSig { sig: ty::FnSig {
inputs: vec!( 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 { fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Function {
let t = ty::lookup_item_type(tcx, did); let t = ty::lookup_item_type(tcx, did);
let (decl, style) = match t.ty.sty { 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"), _ => panic!("bad function"),
}; };
clean::Function { clean::Function {
decl: decl, decl: decl,
generics: (&t.generics, subst::FnSpace).clean(cx), 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); let mut item = method.clean(cx);
item.inner = match item.inner.clone() { item.inner = match item.inner.clone() {
clean::TyMethodItem(clean::TyMethod { clean::TyMethodItem(clean::TyMethod {
fn_style, decl, self_, generics unsafety, decl, self_, generics
}) => { }) => {
clean::MethodItem(clean::Method { clean::MethodItem(clean::Method {
fn_style: fn_style, unsafety: unsafety,
decl: decl, decl: decl,
self_: self_, self_: self_,
generics: generics, generics: generics,

View file

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

View file

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

View file

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

View file

@ -58,7 +58,7 @@ use rustc::util::nodemap::NodeSet;
use clean; use clean;
use doctree; use doctree;
use fold::DocFolder; 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::format::{ConciseStability, TyParamBounds, WhereClause};
use html::highlight; use html::highlight;
use html::item_type::ItemType; 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, fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
f: &clean::Function) -> fmt::Result { 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>", {name}{generics}{decl}{where_clause}</pre>",
vis = VisSpace(it.visibility), vis = VisSpace(it.visibility),
fn_style = FnStyleSpace(f.fn_style), unsafety = UnsafetySpace(f.unsafety),
name = it.name.as_ref().unwrap().as_slice(), name = it.name.as_ref().unwrap().as_slice(),
generics = f.generics, generics = f.generics,
where_clause = WhereClause(&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 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, g: &clean::Generics, selfty: &clean::SelfTy,
d: &clean::FnDecl) -> fmt::Result { d: &clean::FnDecl) -> fmt::Result {
write!(w, "{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\ write!(w, "{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
{generics}{decl}{where_clause}", {generics}{decl}{where_clause}",
match fn_style { match unsafety {
ast::UnsafeFn => "unsafe ", ast::Unsafety::Unsafe => "unsafe ",
_ => "", _ => "",
}, },
ty = shortty(it), ty = shortty(it),
@ -1841,10 +1841,10 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
} }
match meth.inner { match meth.inner {
clean::TyMethodItem(ref m) => { 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) => { 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) => { clean::AssociatedTypeItem(ref typ) => {
assoc_type(w, meth, 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, pub fn visit_fn(&mut self, item: &ast::Item,
name: ast::Ident, fd: &ast::FnDecl, name: ast::Ident, fd: &ast::FnDecl,
fn_style: &ast::FnStyle, _abi: &abi::Abi, unsafety: &ast::Unsafety, _abi: &abi::Abi,
gen: &ast::Generics) -> Function { gen: &ast::Generics) -> Function {
debug!("Visiting fn"); debug!("Visiting fn");
Function { Function {
@ -133,7 +133,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
name: name, name: name,
whence: item.span, whence: item.span,
generics: gen.clone(), 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::ExplicitSelf_::*;
pub use self::Expr_::*; pub use self::Expr_::*;
pub use self::FloatTy::*; pub use self::FloatTy::*;
pub use self::FnStyle::*;
pub use self::FunctionRetTy::*; pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*; pub use self::ForeignItem_::*;
pub use self::ImplItem::*; pub use self::ImplItem::*;
@ -1027,7 +1026,7 @@ pub struct TypeField {
pub struct TypeMethod { pub struct TypeMethod {
pub ident: Ident, pub ident: Ident,
pub attrs: Vec<Attribute>, pub attrs: Vec<Attribute>,
pub fn_style: FnStyle, pub unsafety: Unsafety,
pub abi: Abi, pub abi: Abi,
pub decl: P<FnDecl>, pub decl: P<FnDecl>,
pub generics: Generics, pub generics: Generics,
@ -1198,7 +1197,7 @@ impl fmt::Show for Onceness {
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ClosureTy { pub struct ClosureTy {
pub lifetimes: Vec<LifetimeDef>, pub lifetimes: Vec<LifetimeDef>,
pub fn_style: FnStyle, pub unsafety: Unsafety,
pub onceness: Onceness, pub onceness: Onceness,
pub decl: P<FnDecl>, pub decl: P<FnDecl>,
pub bounds: TyParamBounds, pub bounds: TyParamBounds,
@ -1206,7 +1205,7 @@ pub struct ClosureTy {
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct BareFnTy { pub struct BareFnTy {
pub fn_style: FnStyle, pub unsafety: Unsafety,
pub abi: Abi, pub abi: Abi,
pub lifetimes: Vec<LifetimeDef>, pub lifetimes: Vec<LifetimeDef>,
pub decl: P<FnDecl> pub decl: P<FnDecl>
@ -1304,21 +1303,17 @@ pub struct FnDecl {
pub variadic: bool pub variadic: bool
} }
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)] #[deriving(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum FnStyle { pub enum Unsafety {
/// Declared with "unsafe fn" Unsafe,
UnsafeFn, Normal,
/// Declared with "fn"
NormalFn,
} }
impl Copy for FnStyle {} impl fmt::Show for Unsafety {
impl fmt::Show for FnStyle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
NormalFn => "normal".fmt(f), Unsafety::Normal => "normal".fmt(f),
UnsafeFn => "unsafe".fmt(f), Unsafety::Unsafe => "unsafe".fmt(f),
} }
} }
} }
@ -1371,7 +1366,7 @@ pub enum Method_ {
Generics, Generics,
Abi, Abi,
ExplicitSelf, ExplicitSelf,
FnStyle, Unsafety,
P<FnDecl>, P<FnDecl>,
P<Block>, P<Block>,
Visibility), Visibility),
@ -1609,7 +1604,7 @@ pub struct Item {
pub enum Item_ { pub enum Item_ {
ItemStatic(P<Ty>, Mutability, P<Expr>), ItemStatic(P<Ty>, Mutability, P<Expr>),
ItemConst(P<Ty>, 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), ItemMod(Mod),
ItemForeignMod(ForeignMod), ItemForeignMod(ForeignMod),
ItemTy(P<Ty>, Generics), ItemTy(P<Ty>, Generics),

View file

@ -122,7 +122,7 @@ impl<'a> Code<'a> {
struct ItemFnParts<'a> { struct ItemFnParts<'a> {
ident: ast::Ident, ident: ast::Ident,
decl: &'a ast::FnDecl, decl: &'a ast::FnDecl,
style: ast::FnStyle, unsafety: ast::Unsafety,
abi: abi::Abi, abi: abi::Abi,
generics: &'a ast::Generics, generics: &'a ast::Generics,
body: &'a Block, body: &'a Block,
@ -182,7 +182,7 @@ impl<'a> FnLikeNode<'a> {
pub fn kind(self) -> visit::FnKind<'a> { pub fn kind(self) -> visit::FnKind<'a> {
let item = |: p: ItemFnParts<'a>| -> 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| { let closure = |: _: ClosureParts| {
visit::FkFnBlock visit::FkFnBlock
@ -200,9 +200,9 @@ impl<'a> FnLikeNode<'a> {
{ {
match self.node { match self.node {
ast_map::NodeItem(i) => match i.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{ 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 generics: generics, abi: abi, id: i.id, span: i.span
}), }),
_ => panic!("item FnLikeNode that is not fn-like"), _ => 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, ref generics,
abi, abi,
ref explicit_self, ref explicit_self,
fn_style, unsafety,
ref decl, ref decl,
_, _,
vis) => { vis) => {
TypeMethod { TypeMethod {
ident: ident, ident: ident,
attrs: method.attrs.clone(), attrs: method.attrs.clone(),
fn_style: fn_style, unsafety: unsafety,
decl: (*decl).clone(), decl: (*decl).clone(),
generics: generics.clone(), generics: generics.clone(),
explicit_self: (*explicit_self).clone(), explicit_self: (*explicit_self).clone(),
@ -722,7 +722,7 @@ pub trait PostExpansionMethod {
fn pe_generics<'a>(&'a self) -> &'a ast::Generics; fn pe_generics<'a>(&'a self) -> &'a ast::Generics;
fn pe_abi(&self) -> Abi; fn pe_abi(&self) -> Abi;
fn pe_explicit_self<'a>(&'a self) -> &'a ast::ExplicitSelf; 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_fn_decl<'a>(&'a self) -> &'a ast::FnDecl;
fn pe_body<'a>(&'a self) -> &'a ast::Block; fn pe_body<'a>(&'a self) -> &'a ast::Block;
fn pe_vis(&self) -> ast::Visibility; 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_abi,Abi,MethDecl(_,_,abi,_,_,_,_,_),abi)
mf_method!(pe_explicit_self,&'a ast::ExplicitSelf, mf_method!(pe_explicit_self,&'a ast::ExplicitSelf,
MethDecl(_,_,_,ref explicit_self,_,_,_,_),explicit_self) 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_fn_decl,&'a ast::FnDecl,MethDecl(_,_,_,_,_,ref decl,_,_),&**decl)
mf_method!(pe_body,&'a ast::Block,MethDecl(_,_,_,_,_,_,ref body,_),&**body) mf_method!(pe_body,&'a ast::Block,MethDecl(_,_,_,_,_,_,ref body,_),&**body)
mf_method!(pe_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,_,vis),vis) mf_method!(pe_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,_,vis),vis)

View file

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

View file

@ -684,7 +684,7 @@ impl<'a> MethodDef<'a> {
fn_generics, fn_generics,
abi, abi,
explicit_self, explicit_self,
ast::NormalFn, ast::Unsafety::Normal,
fn_decl, fn_decl,
body_block, body_block,
ast::Inherited) 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)) TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
} }
TyClosure(f) => { TyClosure(f) => {
TyClosure(f.map(|ClosureTy {fn_style, onceness, bounds, decl, lifetimes}| { TyClosure(f.map(|ClosureTy {unsafety, onceness, bounds, decl, lifetimes}| {
ClosureTy { ClosureTy {
fn_style: fn_style, unsafety: unsafety,
onceness: onceness, onceness: onceness,
bounds: fld.fold_bounds(bounds), bounds: fld.fold_bounds(bounds),
decl: fld.fold_fn_decl(decl), 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) => {
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), lifetimes: fld.fold_lifetime_defs(lifetimes),
fn_style: fn_style, unsafety: unsafety,
abi: abi, abi: abi,
decl: fld.fold_fn_decl(decl) 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(t, e) => {
ItemConst(folder.fold_ty(t), folder.fold_expr(e)) ItemConst(folder.fold_ty(t), folder.fold_expr(e))
} }
ItemFn(decl, fn_style, abi, generics, body) => { ItemFn(decl, unsafety, abi, generics, body) => {
ItemFn( ItemFn(
folder.fold_fn_decl(decl), folder.fold_fn_decl(decl),
fn_style, unsafety,
abi, abi,
folder.fold_generics(generics), folder.fold_generics(generics),
folder.fold_block(body) folder.fold_block(body)
@ -1077,7 +1077,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
id, id,
ident, ident,
attrs, attrs,
fn_style, unsafety,
abi, abi,
decl, decl,
generics, generics,
@ -1089,7 +1089,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
id: fld.new_id(id), id: fld.new_id(id),
ident: fld.fold_ident(ident), ident: fld.fold_ident(ident),
attrs: attrs.move_map(|a| fld.fold_attribute(a)), attrs: attrs.move_map(|a| fld.fold_attribute(a)),
fn_style: fn_style, unsafety: unsafety,
abi: abi, abi: abi,
decl: fld.fold_fn_decl(decl), decl: fld.fold_fn_decl(decl),
generics: fld.fold_generics(generics), generics: fld.fold_generics(generics),
@ -1211,7 +1211,7 @@ pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<
generics, generics,
abi, abi,
explicit_self, explicit_self,
fn_style, unsafety,
decl, decl,
body, body,
vis) => { vis) => {
@ -1219,7 +1219,7 @@ pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<
folder.fold_generics(generics), folder.fold_generics(generics),
abi, abi,
folder.fold_explicit_self(explicit_self), folder.fold_explicit_self(explicit_self),
fn_style, unsafety,
folder.fold_fn_decl(decl), folder.fold_fn_decl(decl),
folder.fold_block(body), folder.fold_block(body),
vis) vis)

View file

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

View file

@ -16,7 +16,7 @@ use self::ItemOrViewItem::*;
use abi; use abi;
use ast::{AssociatedType, BareFnTy, ClosureTy}; use ast::{AssociatedType, BareFnTy, ClosureTy};
use ast::{RegionTyParamBound, TraitTyParamBound}; 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::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue};
use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, Block}; use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, Block};
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause};
@ -34,7 +34,7 @@ use ast::{Many};
use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
use ast::{FnOnceUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind};
use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy}; 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::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
use ast::{LifetimeDef, Lit, Lit_}; 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::{TyRptr, TyTup, TyU32, TyVec, UnUniq};
use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind}; use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
use ast::{UnnamedField, UnsafeBlock}; 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::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
use ast::{Visibility, WhereClause}; use ast::{Visibility, WhereClause};
use ast; use ast;
@ -1121,7 +1121,7 @@ impl<'a> Parser<'a> {
Function Style Function Style
*/ */
let fn_style = self.parse_unsafety(); let unsafety = self.parse_unsafety();
let abi = if self.eat_keyword(keywords::Extern) { let abi = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abi().unwrap_or(abi::C) self.parse_opt_abi().unwrap_or(abi::C)
} else { } else {
@ -1139,7 +1139,7 @@ impl<'a> Parser<'a> {
}); });
TyBareFn(P(BareFnTy { TyBareFn(P(BareFnTy {
abi: abi, abi: abi,
fn_style: fn_style, unsafety: unsafety,
lifetimes: lifetime_defs, lifetimes: lifetime_defs,
decl: decl 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); let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
@ -1266,7 +1266,7 @@ impl<'a> Parser<'a> {
}); });
TyClosure(P(ClosureTy { TyClosure(P(ClosureTy {
fn_style: fn_style, unsafety: unsafety,
onceness: Many, onceness: Many,
bounds: bounds, bounds: bounds,
decl: decl, 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) { if self.eat_keyword(keywords::Unsafe) {
return UnsafeFn; return Unsafety::Unsafe;
} else { } else {
return NormalFn; return Unsafety::Normal;
} }
} }
@ -1351,7 +1351,7 @@ impl<'a> Parser<'a> {
let lo = p.span.lo; let lo = p.span.lo;
let vis = p.parse_visibility(); let vis = p.parse_visibility();
let style = p.parse_fn_style(); let style = p.parse_unsafety();
let abi = if p.eat_keyword(keywords::Extern) { let abi = if p.eat_keyword(keywords::Extern) {
p.parse_opt_abi().unwrap_or(abi::C) p.parse_opt_abi().unwrap_or(abi::C)
} else { } else {
@ -1379,7 +1379,7 @@ impl<'a> Parser<'a> {
RequiredMethod(TypeMethod { RequiredMethod(TypeMethod {
ident: ident, ident: ident,
attrs: attrs, attrs: attrs,
fn_style: style, unsafety: style,
decl: d, decl: d,
generics: generics, generics: generics,
abi: abi, abi: abi,
@ -4548,12 +4548,12 @@ impl<'a> Parser<'a> {
} }
/// Parse an item-position function declaration. /// 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 (ident, mut generics) = self.parse_fn_header();
let decl = self.parse_fn_decl(false); let decl = self.parse_fn_decl(false);
self.parse_where_clause(&mut generics); self.parse_where_clause(&mut generics);
let (inner_attrs, body) = self.parse_inner_attrs_and_block(); 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 /// Parse a method in a trait impl
@ -4591,7 +4591,7 @@ impl<'a> Parser<'a> {
self.span.hi) }; self.span.hi) };
(ast::MethMac(m), self.span.hi, attrs) (ast::MethMac(m), self.span.hi, attrs)
} else { } else {
let fn_style = self.parse_fn_style(); let unsafety = self.parse_unsafety();
let abi = if self.eat_keyword(keywords::Extern) { let abi = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abi().unwrap_or(abi::C) self.parse_opt_abi().unwrap_or(abi::C)
} else { } else {
@ -4612,7 +4612,7 @@ impl<'a> Parser<'a> {
generics, generics,
abi, abi,
explicit_self, explicit_self,
fn_style, unsafety,
decl, decl,
body, body,
visa), 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 /// At this point, this is essentially a wrapper for
/// parse_foreign_items. /// parse_foreign_items.
fn parse_foreign_mod_items(&mut self, fn parse_foreign_mod_items(&mut self,
@ -5491,7 +5481,7 @@ impl<'a> Parser<'a> {
// EXTERN FUNCTION ITEM // EXTERN FUNCTION ITEM
let abi = opt_abi.unwrap_or(abi::C); let abi = opt_abi.unwrap_or(abi::C);
let (ident, item_, extra_attrs) = 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 last_span = self.last_span;
let item = self.mk_item(lo, let item = self.mk_item(lo,
last_span.hi, last_span.hi,
@ -5554,7 +5544,7 @@ impl<'a> Parser<'a> {
// FUNCTION ITEM // FUNCTION ITEM
self.bump(); self.bump();
let (ident, item_, extra_attrs) = 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 last_span = self.last_span;
let item = self.mk_item(lo, let item = self.mk_item(lo,
last_span.hi, last_span.hi,
@ -5575,7 +5565,7 @@ impl<'a> Parser<'a> {
}; };
self.expect_keyword(keywords::Fn); self.expect_keyword(keywords::Fn);
let (ident, item_, extra_attrs) = 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 last_span = self.last_span;
let item = self.mk_item(lo, let item = self.mk_item(lo,
last_span.hi, 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)) $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_>, opt_explicit_self: Option<&ast::ExplicitSelf_>,
generics: &ast::Generics) -> String { generics: &ast::Generics) -> String {
$to_string(|s| { $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)); name, generics, opt_explicit_self, ast::Inherited));
try!(s.end()); // Close the head box try!(s.end()); // Close the head box
s.end() // Close the outer box s.end() // Close the outer box
@ -707,7 +707,7 @@ impl<'a> State<'a> {
}; };
try!(self.print_ty_fn(Some(f.abi), try!(self.print_ty_fn(Some(f.abi),
None, None,
f.fn_style, f.unsafety,
ast::Many, ast::Many,
&*f.decl, &*f.decl,
None, None,
@ -726,7 +726,7 @@ impl<'a> State<'a> {
}; };
try!(self.print_ty_fn(None, try!(self.print_ty_fn(None,
Some('&'), Some('&'),
f.fn_style, f.unsafety,
f.onceness, f.onceness,
&*f.decl, &*f.decl,
None, None,
@ -858,10 +858,10 @@ impl<'a> State<'a> {
try!(word(&mut self.s, ";")); try!(word(&mut self.s, ";"));
try!(self.end()); // end the outer cbox 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( try!(self.print_fn(
&**decl, &**decl,
Some(fn_style), Some(unsafety),
abi, abi,
item.ident, item.ident,
typarams, typarams,
@ -1188,7 +1188,7 @@ impl<'a> State<'a> {
try!(self.print_outer_attributes(m.attrs.as_slice())); try!(self.print_outer_attributes(m.attrs.as_slice()));
try!(self.print_ty_fn(None, try!(self.print_ty_fn(None,
None, None,
m.fn_style, m.unsafety,
ast::Many, ast::Many,
&*m.decl, &*m.decl,
Some(m.ident), Some(m.ident),
@ -1223,12 +1223,12 @@ impl<'a> State<'a> {
ref generics, ref generics,
abi, abi,
ref explicit_self, ref explicit_self,
fn_style, unsafety,
ref decl, ref decl,
ref body, ref body,
vis) => { vis) => {
try!(self.print_fn(&**decl, try!(self.print_fn(&**decl,
Some(fn_style), Some(unsafety),
abi, abi,
ident, ident,
generics, generics,
@ -2164,14 +2164,14 @@ impl<'a> State<'a> {
pub fn print_fn(&mut self, pub fn print_fn(&mut self,
decl: &ast::FnDecl, decl: &ast::FnDecl,
fn_style: Option<ast::FnStyle>, unsafety: Option<ast::Unsafety>,
abi: abi::Abi, abi: abi::Abi,
name: ast::Ident, name: ast::Ident,
generics: &ast::Generics, generics: &ast::Generics,
opt_explicit_self: Option<&ast::ExplicitSelf_>, opt_explicit_self: Option<&ast::ExplicitSelf_>,
vis: ast::Visibility) -> IoResult<()> { vis: ast::Visibility) -> IoResult<()> {
try!(self.head("")); 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.nbsp());
try!(self.print_ident(name)); try!(self.print_ident(name));
try!(self.print_generics(generics)); try!(self.print_generics(generics));
@ -2588,7 +2588,7 @@ impl<'a> State<'a> {
pub fn print_ty_fn(&mut self, pub fn print_ty_fn(&mut self,
opt_abi: Option<abi::Abi>, opt_abi: Option<abi::Abi>,
opt_sigil: Option<char>, opt_sigil: Option<char>,
fn_style: ast::FnStyle, unsafety: ast::Unsafety,
onceness: ast::Onceness, onceness: ast::Onceness,
decl: &ast::FnDecl, decl: &ast::FnDecl,
id: Option<ast::Ident>, id: Option<ast::Ident>,
@ -2603,11 +2603,11 @@ impl<'a> State<'a> {
if opt_sigil == Some('~') && onceness == ast::Once { if opt_sigil == Some('~') && onceness == ast::Once {
try!(word(&mut self.s, "proc")); try!(word(&mut self.s, "proc"));
} else if opt_sigil == Some('&') { } 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)); try!(self.print_extern_opt_abi(opt_abi));
} else { } else {
assert!(opt_sigil.is_none()); 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!(self.print_opt_abi_and_extern_if_nondefault(opt_abi));
try!(word(&mut self.s, "fn")); try!(word(&mut self.s, "fn"));
} }
@ -2872,10 +2872,10 @@ impl<'a> State<'a> {
} }
} }
pub fn print_opt_fn_style(&mut self, pub fn print_opt_unsafety(&mut self,
opt_fn_style: Option<ast::FnStyle>) -> IoResult<()> { opt_unsafety: Option<ast::Unsafety>) -> IoResult<()> {
match opt_fn_style { match opt_unsafety {
Some(fn_style) => self.print_fn_style(fn_style), Some(unsafety) => self.print_unsafety(unsafety),
None => Ok(()) None => Ok(())
} }
} }
@ -2906,11 +2906,11 @@ impl<'a> State<'a> {
pub fn print_fn_header_info(&mut self, pub fn print_fn_header_info(&mut self,
_opt_explicit_self: Option<&ast::ExplicitSelf_>, _opt_explicit_self: Option<&ast::ExplicitSelf_>,
opt_fn_style: Option<ast::FnStyle>, opt_unsafety: Option<ast::Unsafety>,
abi: abi::Abi, abi: abi::Abi,
vis: ast::Visibility) -> IoResult<()> { vis: ast::Visibility) -> IoResult<()> {
try!(word(&mut self.s, visibility_qualified(vis, "").as_slice())); 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 { if abi != abi::Rust {
try!(self.word_nbsp("extern")); try!(self.word_nbsp("extern"));
@ -2920,10 +2920,10 @@ impl<'a> State<'a> {
word(&mut self.s, "fn") 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 { match s {
ast::NormalFn => Ok(()), ast::Unsafety::Normal => Ok(()),
ast::UnsafeFn => self.word_nbsp("unsafe"), ast::Unsafety::Unsafe => self.word_nbsp("unsafe"),
} }
} }
} }
@ -2950,7 +2950,7 @@ mod test {
variadic: false variadic: false
}; };
let generics = ast_util::empty_generics(); 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), None, &generics),
"fn abba()"); "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) { if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
match i.node { match i.node {
ast::ItemFn(_, ast::UnsafeFn, _, _, _) => { ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _) => {
let diag = self.cx.span_diagnostic; let diag = self.cx.span_diagnostic;
diag.span_fatal(i.span, diag.span_fatal(i.span,
"unsafe functions cannot be used for \ "unsafe functions cannot be used for \

View file

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