Skip to content

Commit 092d04a

Browse files
committed
Rename FnStyle trait to Unsafety.
1 parent 52f7a4a commit 092d04a

File tree

41 files changed

+254
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+254
-273
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ fn parse_hex(st: &mut PState) -> uint {
549549
};
550550
}
551551

552-
fn parse_fn_style(c: char) -> ast::FnStyle {
552+
fn parse_unsafety(c: char) -> ast::Unsafety {
553553
match c {
554-
'u' => ast::UnsafeFn,
555-
'n' => ast::NormalFn,
556-
_ => panic!("parse_fn_style: bad fn_style {}", c)
554+
'u' => ast::Unsafety::Unsafe,
555+
'n' => ast::Unsafety::Normal,
556+
_ => panic!("parse_unsafety: bad unsafety {}", c)
557557
}
558558
}
559559

@@ -575,14 +575,14 @@ fn parse_onceness(c: char) -> ast::Onceness {
575575

576576
fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
577577
conv: conv_did) -> ty::ClosureTy<'tcx> {
578-
let fn_style = parse_fn_style(next(st));
578+
let unsafety = parse_unsafety(next(st));
579579
let onceness = parse_onceness(next(st));
580580
let store = parse_trait_store(st, |x,y| conv(x,y));
581581
let bounds = parse_existential_bounds(st, |x,y| conv(x,y));
582582
let sig = parse_sig(st, |x,y| conv(x,y));
583583
let abi = parse_abi_set(st);
584584
ty::ClosureTy {
585-
fn_style: fn_style,
585+
unsafety: unsafety,
586586
onceness: onceness,
587587
store: store,
588588
bounds: bounds,
@@ -593,11 +593,11 @@ fn parse_closure_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
593593

594594
fn parse_bare_fn_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
595595
conv: conv_did) -> ty::BareFnTy<'tcx> {
596-
let fn_style = parse_fn_style(next(st));
596+
let unsafety = parse_unsafety(next(st));
597597
let abi = parse_abi_set(st);
598598
let sig = parse_sig(st, |x,y| conv(x,y));
599599
ty::BareFnTy {
600-
fn_style: fn_style,
600+
unsafety: unsafety,
601601
abi: abi,
602602
sig: sig
603603
}

src/librustc/metadata/tyencode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ fn enc_sty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
313313
}
314314
}
315315

316-
fn enc_fn_style(w: &mut SeekableMemWriter, p: ast::FnStyle) {
316+
fn enc_unsafety(w: &mut SeekableMemWriter, p: ast::Unsafety) {
317317
match p {
318-
ast::NormalFn => mywrite!(w, "n"),
319-
ast::UnsafeFn => mywrite!(w, "u"),
318+
ast::Unsafety::Normal => mywrite!(w, "n"),
319+
ast::Unsafety::Unsafe => mywrite!(w, "u"),
320320
}
321321
}
322322

@@ -335,14 +335,14 @@ fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) {
335335

336336
pub fn enc_bare_fn_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
337337
ft: &ty::BareFnTy<'tcx>) {
338-
enc_fn_style(w, ft.fn_style);
338+
enc_unsafety(w, ft.unsafety);
339339
enc_abi(w, ft.abi);
340340
enc_fn_sig(w, cx, &ft.sig);
341341
}
342342

343343
pub fn enc_closure_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
344344
ft: &ty::ClosureTy<'tcx>) {
345-
enc_fn_style(w, ft.fn_style);
345+
enc_unsafety(w, ft.unsafety);
346346
enc_onceness(w, ft.onceness);
347347
enc_trait_store(w, cx, ft.store);
348348
enc_existential_bounds(w, cx, &ft.bounds);

src/librustc/middle/effect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl Copy for UnsafeContext {}
3434

3535
fn type_is_unsafe_function(ty: Ty) -> bool {
3636
match ty.sty {
37-
ty::ty_bare_fn(ref f) => f.fn_style == ast::UnsafeFn,
38-
ty::ty_closure(ref f) => f.fn_style == ast::UnsafeFn,
37+
ty::ty_bare_fn(ref f) => f.unsafety == ast::Unsafety::Unsafe,
38+
ty::ty_closure(ref f) => f.unsafety == ast::Unsafety::Unsafe,
3939
_ => false,
4040
}
4141
}
@@ -92,9 +92,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
9292

9393
let (is_item_fn, is_unsafe_fn) = match fn_kind {
9494
visit::FkItemFn(_, _, fn_style, _) =>
95-
(true, fn_style == ast::UnsafeFn),
95+
(true, fn_style == ast::Unsafety::Unsafe),
9696
visit::FkMethod(_, _, method) =>
97-
(true, method.pe_fn_style() == ast::UnsafeFn),
97+
(true, method.pe_unsafety() == ast::Unsafety::Unsafe),
9898
_ => (false, false),
9999
};
100100

src/librustc/middle/infer/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
521521
debug!("coerce_from_bare_fn(a={}, b={})",
522522
a.repr(self.get_ref().infcx.tcx), b.repr(self.get_ref().infcx.tcx));
523523

524-
if fn_ty_a.abi != abi::Rust || fn_ty_a.fn_style != ast::NormalFn {
524+
if fn_ty_a.abi != abi::Rust || fn_ty_a.unsafety != ast::Unsafety::Normal {
525525
return self.subtype(a, b);
526526
}
527527

src/librustc/middle/infer/combine.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use middle::ty_fold;
5151
use middle::ty_fold::{TypeFoldable};
5252
use util::ppaux::Repr;
5353

54-
use syntax::ast::{Onceness, FnStyle};
54+
use syntax::ast::{Onceness, Unsafety};
5555
use syntax::ast;
5656
use syntax::abi;
5757
use syntax::codemap::Span;
@@ -193,12 +193,12 @@ pub trait Combine<'tcx> {
193193

194194
fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
195195
b: &ty::BareFnTy<'tcx>) -> cres<'tcx, ty::BareFnTy<'tcx>> {
196-
let fn_style = try!(self.fn_styles(a.fn_style, b.fn_style));
196+
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
197197
let abi = try!(self.abi(a.abi, b.abi));
198198
let sig = try!(self.fn_sigs(&a.sig, &b.sig));
199-
Ok(ty::BareFnTy {fn_style: fn_style,
200-
abi: abi,
201-
sig: sig})
199+
Ok(ty::BareFnTy {unsafety: unsafety,
200+
abi: abi,
201+
sig: sig})
202202
}
203203

204204
fn closure_tys(&self, a: &ty::ClosureTy<'tcx>,
@@ -219,13 +219,13 @@ pub trait Combine<'tcx> {
219219
return Err(ty::terr_sigil_mismatch(expected_found(self, a.store, b.store)))
220220
}
221221
};
222-
let fn_style = try!(self.fn_styles(a.fn_style, b.fn_style));
222+
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
223223
let onceness = try!(self.oncenesses(a.onceness, b.onceness));
224224
let bounds = try!(self.existential_bounds(a.bounds, b.bounds));
225225
let sig = try!(self.fn_sigs(&a.sig, &b.sig));
226226
let abi = try!(self.abi(a.abi, b.abi));
227227
Ok(ty::ClosureTy {
228-
fn_style: fn_style,
228+
unsafety: unsafety,
229229
onceness: onceness,
230230
store: store,
231231
bounds: bounds,
@@ -240,7 +240,7 @@ pub trait Combine<'tcx> {
240240
self.contratys(a, b).and_then(|t| Ok(t))
241241
}
242242

243-
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle>;
243+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety>;
244244

245245
fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<'tcx, abi::Abi> {
246246
if a == b {

src/librustc/middle/infer/equate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use middle::infer::{TypeTrace, Subtype};
2121
use middle::infer::type_variable::{EqTo};
2222
use util::ppaux::{Repr};
2323

24-
use syntax::ast::{Onceness, FnStyle};
24+
use syntax::ast::{Onceness, Unsafety};
2525

2626
pub struct Equate<'f, 'tcx: 'f> {
2727
fields: CombineFields<'f, 'tcx>
@@ -70,9 +70,9 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> {
7070
Ok(ty::mt { mutbl: a.mutbl, ty: t })
7171
}
7272

73-
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
73+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
7474
if a != b {
75-
Err(ty::terr_fn_style_mismatch(expected_found(self, a, b)))
75+
Err(ty::terr_unsafety_mismatch(expected_found(self, a, b)))
7676
} else {
7777
Ok(a)
7878
}

src/librustc/middle/infer/error_reporting.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ trait ErrorReportingHelpers<'tcx> {
157157

158158
fn give_expl_lifetime_param(&self,
159159
decl: &ast::FnDecl,
160-
fn_style: ast::FnStyle,
160+
unsafety: ast::Unsafety,
161161
ident: ast::Ident,
162162
opt_explicit_self: Option<&ast::ExplicitSelf_>,
163163
generics: &ast::Generics,
@@ -828,7 +828,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
828828
ast::MethodImplItem(ref m) => {
829829
Some((m.pe_fn_decl(),
830830
m.pe_generics(),
831-
m.pe_fn_style(),
831+
m.pe_unsafety(),
832832
m.pe_ident(),
833833
Some(&m.pe_explicit_self().node),
834834
m.span))
@@ -841,7 +841,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
841841
ast::ProvidedMethod(ref m) => {
842842
Some((m.pe_fn_decl(),
843843
m.pe_generics(),
844-
m.pe_fn_style(),
844+
m.pe_unsafety(),
845845
m.pe_ident(),
846846
Some(&m.pe_explicit_self().node),
847847
m.span))
@@ -853,14 +853,14 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
853853
},
854854
None => None
855855
};
856-
let (fn_decl, generics, fn_style, ident, expl_self, span)
856+
let (fn_decl, generics, unsafety, ident, expl_self, span)
857857
= node_inner.expect("expect item fn");
858858
let taken = lifetimes_in_scope(self.tcx, scope_id);
859859
let life_giver = LifeGiver::with_taken(taken.as_slice());
860860
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
861861
generics, same_regions, &life_giver);
862862
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
863-
self.give_expl_lifetime_param(&fn_decl, fn_style, ident,
863+
self.give_expl_lifetime_param(&fn_decl, unsafety, ident,
864864
expl_self.as_ref(), &generics, span);
865865
}
866866
}
@@ -1407,12 +1407,12 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
14071407
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
14081408
fn give_expl_lifetime_param(&self,
14091409
decl: &ast::FnDecl,
1410-
fn_style: ast::FnStyle,
1410+
unsafety: ast::Unsafety,
14111411
ident: ast::Ident,
14121412
opt_explicit_self: Option<&ast::ExplicitSelf_>,
14131413
generics: &ast::Generics,
14141414
span: codemap::Span) {
1415-
let suggested_fn = pprust::fun_to_string(decl, fn_style, ident,
1415+
let suggested_fn = pprust::fun_to_string(decl, unsafety, ident,
14161416
opt_explicit_self, generics);
14171417
let msg = format!("consider using an explicit lifetime \
14181418
parameter as shown: {}", suggested_fn);

src/librustc/middle/infer/glb.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use super::{TypeTrace, Subtype};
2020
use middle::ty::{BuiltinBounds};
2121
use middle::ty::{mod, Ty};
2222
use syntax::ast::{Many, Once, MutImmutable, MutMutable};
23-
use syntax::ast::{NormalFn, UnsafeFn};
24-
use syntax::ast::{Onceness, FnStyle};
23+
use syntax::ast::{Onceness, Unsafety};
2524
use util::ppaux::mt_to_string;
2625
use util::ppaux::Repr;
2726

@@ -81,10 +80,10 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> {
8180
self.lub().tys(a, b)
8281
}
8382

84-
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
83+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
8584
match (a, b) {
86-
(NormalFn, _) | (_, NormalFn) => Ok(NormalFn),
87-
(UnsafeFn, UnsafeFn) => Ok(UnsafeFn)
85+
(Unsafety::Normal, _) | (_, Unsafety::Normal) => Ok(Unsafety::Normal),
86+
(Unsafety::Unsafe, Unsafety::Unsafe) => Ok(Unsafety::Unsafe)
8887
}
8988
}
9089

src/librustc/middle/infer/lub.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use super::{TypeTrace, Subtype};
2020
use middle::ty::{BuiltinBounds};
2121
use middle::ty::{mod, Ty};
2222
use syntax::ast::{Many, Once};
23-
use syntax::ast::{NormalFn, UnsafeFn};
24-
use syntax::ast::{Onceness, FnStyle};
23+
use syntax::ast::{Onceness, Unsafety};
2524
use syntax::ast::{MutMutable, MutImmutable};
2625
use util::ppaux::mt_to_string;
2726
use util::ppaux::Repr;
@@ -77,10 +76,10 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> {
7776
self.glb().tys(a, b)
7877
}
7978

80-
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
79+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
8180
match (a, b) {
82-
(UnsafeFn, _) | (_, UnsafeFn) => Ok(UnsafeFn),
83-
(NormalFn, NormalFn) => Ok(NormalFn),
81+
(Unsafety::Unsafe, _) | (_, Unsafety::Unsafe) => Ok(Unsafety::Unsafe),
82+
(Unsafety::Normal, Unsafety::Normal) => Ok(Unsafety::Normal),
8483
}
8584
}
8685

src/librustc/middle/infer/sub.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use middle::ty::{mod, Ty};
2323
use middle::ty::TyVar;
2424
use util::ppaux::{Repr};
2525

26-
use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable};
26+
use syntax::ast::{Onceness, MutImmutable, MutMutable, Unsafety};
2727

2828

2929
/// "Greatest lower bound" (common subtype)
@@ -93,9 +93,9 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> {
9393
Ok(*a) // return is meaningless in sub, just return *a
9494
}
9595

96-
fn fn_styles(&self, a: FnStyle, b: FnStyle) -> cres<'tcx, FnStyle> {
97-
self.lub().fn_styles(a, b).compare(b, || {
98-
ty::terr_fn_style_mismatch(expected_found(self, a, b))
96+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
97+
self.lub().unsafeties(a, b).compare(b, || {
98+
ty::terr_unsafety_mismatch(expected_found(self, a, b))
9999
})
100100
}
101101

src/librustc/middle/traits/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
791791

792792
// provide an impl, but only for suitable `fn` pointers
793793
ty::ty_bare_fn(ty::BareFnTy {
794-
fn_style: ast::NormalFn,
794+
unsafety: ast::Unsafety::Normal,
795795
abi: abi::Rust,
796796
sig: ty::FnSig {
797797
inputs: _,
@@ -1505,7 +1505,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15051505
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
15061506
let sig = match self_ty.sty {
15071507
ty::ty_bare_fn(ty::BareFnTy {
1508-
fn_style: ast::NormalFn,
1508+
unsafety: ast::Unsafety::Normal,
15091509
abi: abi::Rust,
15101510
ref sig
15111511
}) => {

0 commit comments

Comments
 (0)