Skip to content

Commit 0ac5326

Browse files
committed
syntax: remove ast::Sigil.
1 parent 65abf96 commit 0ac5326

File tree

5 files changed

+52
-78
lines changed

5 files changed

+52
-78
lines changed

src/libsyntax/ast.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,6 @@ pub enum Mutability {
359359
MutImmutable,
360360
}
361361

362-
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
363-
pub enum Sigil {
364-
BorrowedSigil,
365-
OwnedSigil,
366-
ManagedSigil
367-
}
368-
369-
impl fmt::Show for Sigil {
370-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
371-
match *self {
372-
BorrowedSigil => "&".fmt(f),
373-
OwnedSigil => "~".fmt(f),
374-
ManagedSigil => "@".fmt(f),
375-
}
376-
}
377-
}
378-
379362
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
380363
pub enum ExprVstore {
381364
ExprVstoreUniq, // ~[1,2,3,4]
@@ -791,8 +774,6 @@ impl fmt::Show for Onceness {
791774

792775
#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)]
793776
pub struct ClosureTy {
794-
pub sigil: Sigil,
795-
pub region: Option<Lifetime>,
796777
pub lifetimes: Vec<Lifetime>,
797778
pub fn_style: FnStyle,
798779
pub onceness: Onceness,
@@ -822,7 +803,8 @@ pub enum Ty_ {
822803
TyFixedLengthVec(P<Ty>, @Expr),
823804
TyPtr(MutTy),
824805
TyRptr(Option<Lifetime>, MutTy),
825-
TyClosure(@ClosureTy),
806+
TyClosure(@ClosureTy, Option<Lifetime>),
807+
TyProc(@ClosureTy),
826808
TyBareFn(@BareFnTy),
827809
TyTup(Vec<P<Ty>> ),
828810
TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above

src/libsyntax/fold.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ pub trait Folder {
155155
TyRptr(ref region, ref mt) => {
156156
TyRptr(fold_opt_lifetime(region, self), fold_mt(mt, self))
157157
}
158-
TyClosure(ref f) => {
158+
TyClosure(ref f, ref region) => {
159159
TyClosure(@ClosureTy {
160-
sigil: f.sigil,
161160
fn_style: f.fn_style,
162-
region: fold_opt_lifetime(&f.region, self),
161+
onceness: f.onceness,
162+
bounds: fold_opt_bounds(&f.bounds, self),
163+
decl: self.fold_fn_decl(f.decl),
164+
lifetimes: f.lifetimes.iter().map(|l| fold_lifetime(l, self)).collect(),
165+
}, fold_opt_lifetime(region, self))
166+
}
167+
TyProc(ref f) => {
168+
TyProc(@ClosureTy {
169+
fn_style: f.fn_style,
163170
onceness: f.onceness,
164171
bounds: fold_opt_bounds(&f.bounds, self),
165172
decl: self.fold_fn_decl(f.decl),

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![macro_escape]
1212

1313
use abi;
14-
use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil};
1514
use ast::{BareFnTy, ClosureTy};
1615
use ast::{RegionTyParamBound, TraitTyParamBound};
1716
use ast::{Provided, Public, FnStyle};
@@ -49,8 +48,8 @@ use ast::StrStyle;
4948
use ast::{SelfRegion, SelfStatic, SelfUniq, SelfValue};
5049
use ast::{TokenTree, TraitMethod, TraitRef, TTDelim, TTSeq, TTTok};
5150
use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox};
52-
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyBareFn, TyTypeof};
53-
use ast::{TyInfer, TypeMethod};
51+
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
52+
use ast::{TyTypeof, TyInfer, TypeMethod};
5453
use ast::{TyNil, TyParam, TyParamBound, TyPath, TyPtr, TyRptr};
5554
use ast::{TyTup, TyU32, TyUniq, TyVec, UnUniq};
5655
use ast::{UnnamedField, UnsafeBlock, UnsafeFn, ViewItem};
@@ -923,9 +922,7 @@ impl<'a> Parser<'a> {
923922
cf: ret_style,
924923
variadic: variadic
925924
});
926-
TyClosure(@ClosureTy {
927-
sigil: OwnedSigil,
928-
region: None,
925+
TyProc(@ClosureTy {
929926
fn_style: NormalFn,
930927
onceness: Once,
931928
bounds: bounds,
@@ -984,14 +981,12 @@ impl<'a> Parser<'a> {
984981
});
985982

986983
TyClosure(@ClosureTy {
987-
sigil: BorrowedSigil,
988-
region: region,
989984
fn_style: fn_style,
990985
onceness: onceness,
991986
bounds: bounds,
992987
decl: decl,
993988
lifetimes: lifetimes,
994-
})
989+
}, region)
995990
}
996991

997992
pub fn parse_unsafety(&mut self) -> FnStyle {
@@ -1201,11 +1196,11 @@ impl<'a> Parser<'a> {
12011196
} else if self.token == token::AT {
12021197
// MANAGED POINTER
12031198
self.bump();
1204-
self.parse_box_or_uniq_pointee(ManagedSigil)
1199+
TyBox(self.parse_ty(false))
12051200
} else if self.token == token::TILDE {
12061201
// OWNED POINTER
12071202
self.bump();
1208-
self.parse_box_or_uniq_pointee(OwnedSigil)
1203+
TyUniq(self.parse_ty(false))
12091204
} else if self.token == token::BINOP(token::STAR) {
12101205
// STAR POINTER (bare pointer?)
12111206
self.bump();
@@ -1271,21 +1266,6 @@ impl<'a> Parser<'a> {
12711266
P(Ty {id: ast::DUMMY_NODE_ID, node: t, span: sp})
12721267
}
12731268

1274-
// parse the type following a @ or a ~
1275-
pub fn parse_box_or_uniq_pointee(&mut self,
1276-
sigil: ast::Sigil)
1277-
-> Ty_ {
1278-
// other things are parsed as @/~ + a type. Note that constructs like
1279-
// ~[] and ~str will be resolved during typeck to slices and so forth,
1280-
// rather than boxed ptrs. But the special casing of str/vec is not
1281-
// reflected in the AST type.
1282-
if sigil == OwnedSigil {
1283-
TyUniq(self.parse_ty(false))
1284-
} else {
1285-
TyBox(self.parse_ty(false))
1286-
}
1287-
}
1288-
12891269
pub fn parse_borrowed_pointee(&mut self) -> Ty_ {
12901270
// look for `&'lt` or `&'foo ` and interpret `foo` as the region name:
12911271
let opt_lifetime = self.parse_opt_lifetime();

src/libsyntax/print/pprust.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,23 @@ impl<'a> State<'a> {
483483
f.fn_style, ast::Many, f.decl, None, &None,
484484
Some(&generics), None));
485485
}
486-
ast::TyClosure(f) => {
486+
ast::TyClosure(f, ref region) => {
487487
let generics = ast::Generics {
488488
lifetimes: f.lifetimes.clone(),
489489
ty_params: OwnedSlice::empty()
490490
};
491-
try!(self.print_ty_fn(None, Some(f.sigil), &f.region,
492-
f.fn_style, f.onceness, f.decl, None, &f.bounds,
493-
Some(&generics), None));
491+
try!(self.print_ty_fn(None, Some('&'), region, f.fn_style,
492+
f.onceness, f.decl, None, &f.bounds,
493+
Some(&generics), None));
494+
}
495+
ast::TyProc(f) => {
496+
let generics = ast::Generics {
497+
lifetimes: f.lifetimes.clone(),
498+
ty_params: OwnedSlice::empty()
499+
};
500+
try!(self.print_ty_fn(None, Some('~'), &None, f.fn_style,
501+
f.onceness, f.decl, None, &f.bounds,
502+
Some(&generics), None));
494503
}
495504
ast::TyPath(ref path, ref bounds, _) => {
496505
try!(self.print_bounded_path(path, bounds));
@@ -1716,8 +1725,7 @@ impl<'a> State<'a> {
17161725
opt_explicit_self: Option<ast::ExplicitSelf_>,
17171726
vis: ast::Visibility) -> IoResult<()> {
17181727
try!(self.head(""));
1719-
try!(self.print_fn_header_info(opt_explicit_self, fn_style, abi,
1720-
ast::Many, None, vis));
1728+
try!(self.print_fn_header_info(opt_explicit_self, fn_style, abi, vis));
17211729
try!(self.nbsp());
17221730
try!(self.print_ident(name));
17231731
try!(self.print_generics(generics));
@@ -2023,7 +2031,7 @@ impl<'a> State<'a> {
20232031

20242032
pub fn print_ty_fn(&mut self,
20252033
opt_abi: Option<abi::Abi>,
2026-
opt_sigil: Option<ast::Sigil>,
2034+
opt_sigil: Option<char>,
20272035
opt_region: &Option<ast::Lifetime>,
20282036
fn_style: ast::FnStyle,
20292037
onceness: ast::Onceness,
@@ -2037,15 +2045,15 @@ impl<'a> State<'a> {
20372045

20382046
// Duplicates the logic in `print_fn_header_info()`. This is because that
20392047
// function prints the sigil in the wrong place. That should be fixed.
2040-
if opt_sigil == Some(ast::OwnedSigil) && onceness == ast::Once {
2048+
if opt_sigil == Some('~') && onceness == ast::Once {
20412049
try!(word(&mut self.s, "proc"));
2042-
} else if opt_sigil == Some(ast::BorrowedSigil) {
2050+
} else if opt_sigil == Some('&') {
20432051
try!(self.print_extern_opt_abi(opt_abi));
20442052
try!(self.print_fn_style(fn_style));
20452053
try!(self.print_onceness(onceness));
20462054
} else {
2055+
assert!(opt_sigil.is_none());
20472056
try!(self.print_opt_abi_and_extern_if_nondefault(opt_abi));
2048-
try!(self.print_opt_sigil(opt_sigil));
20492057
try!(self.print_fn_style(fn_style));
20502058
try!(self.print_onceness(onceness));
20512059
try!(word(&mut self.s, "fn"));
@@ -2062,15 +2070,15 @@ impl<'a> State<'a> {
20622070
match generics { Some(g) => try!(self.print_generics(g)), _ => () }
20632071
try!(zerobreak(&mut self.s));
20642072

2065-
if opt_sigil == Some(ast::BorrowedSigil) {
2073+
if opt_sigil == Some('&') {
20662074
try!(word(&mut self.s, "|"));
20672075
} else {
20682076
try!(self.popen());
20692077
}
20702078

20712079
try!(self.print_fn_args(decl, opt_explicit_self));
20722080

2073-
if opt_sigil == Some(ast::BorrowedSigil) {
2081+
if opt_sigil == Some('&') {
20742082
try!(word(&mut self.s, "|"));
20752083
} else {
20762084
if decl.variadic {
@@ -2327,22 +2335,10 @@ impl<'a> State<'a> {
23272335
}
23282336
}
23292337

2330-
pub fn print_opt_sigil(&mut self,
2331-
opt_sigil: Option<ast::Sigil>) -> IoResult<()> {
2332-
match opt_sigil {
2333-
Some(ast::BorrowedSigil) => word(&mut self.s, "&"),
2334-
Some(ast::OwnedSigil) => word(&mut self.s, "~"),
2335-
Some(ast::ManagedSigil) => word(&mut self.s, "@"),
2336-
None => Ok(())
2337-
}
2338-
}
2339-
23402338
pub fn print_fn_header_info(&mut self,
23412339
_opt_explicit_self: Option<ast::ExplicitSelf_>,
23422340
opt_fn_style: Option<ast::FnStyle>,
23432341
abi: abi::Abi,
2344-
onceness: ast::Onceness,
2345-
opt_sigil: Option<ast::Sigil>,
23462342
vis: ast::Visibility) -> IoResult<()> {
23472343
try!(word(&mut self.s, visibility_qualified(vis, "")));
23482344

@@ -2357,9 +2353,7 @@ impl<'a> State<'a> {
23572353
try!(self.print_opt_fn_style(opt_fn_style));
23582354
}
23592355

2360-
try!(self.print_onceness(onceness));
2361-
try!(word(&mut self.s, "fn"));
2362-
self.print_opt_sigil(opt_sigil)
2356+
word(&mut self.s, "fn")
23632357
}
23642358

23652359
pub fn print_fn_style(&mut self, s: ast::FnStyle) -> IoResult<()> {

src/libsyntax/visit.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
328328
visitor.visit_ty(tuple_element_type, env.clone())
329329
}
330330
}
331-
TyClosure(ref function_declaration) => {
331+
TyClosure(ref function_declaration, ref region) => {
332332
for argument in function_declaration.decl.inputs.iter() {
333333
visitor.visit_ty(argument.ty, env.clone())
334334
}
@@ -338,11 +338,22 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
338338
}
339339
visitor.visit_opt_lifetime_ref(
340340
typ.span,
341-
&function_declaration.region,
341+
region,
342342
env.clone());
343343
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
344344
env.clone());
345345
}
346+
TyProc(ref function_declaration) => {
347+
for argument in function_declaration.decl.inputs.iter() {
348+
visitor.visit_ty(argument.ty, env.clone())
349+
}
350+
visitor.visit_ty(function_declaration.decl.output, env.clone());
351+
for bounds in function_declaration.bounds.iter() {
352+
walk_ty_param_bounds(visitor, bounds, env.clone())
353+
}
354+
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
355+
env.clone());
356+
}
346357
TyBareFn(ref function_declaration) => {
347358
for argument in function_declaration.decl.inputs.iter() {
348359
visitor.visit_ty(argument.ty, env.clone())

0 commit comments

Comments
 (0)