not have a destructor.
~~~
-use std::gc::Gc;
+use std::gc::GC;
// A fixed-size array allocated in a garbage-collected box
-let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+let x = box(GC) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let y = x; // does not perform a move, unlike with `Rc`
let z = x;
-assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+assert!(*z == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
~~~
With shared ownership, mutability cannot be inherited so the boxes are always immutable. However,
#[test]
fn gc_inside() {
// see issue #11532
- use realstd::gc::Gc;
+ use std::gc::GC;
let a = Rc::new(RefCell::new(box(GC) 1));
assert!(a.try_borrow_mut().is_some());
}
mod test {
use prelude::*;
use realstd::owned::Box;
+ use realstd::gc::{Gc, GC};
fn realclone<T: ::realstd::clone::Clone>(t: &T) -> T {
use realstd::clone::Clone;
#[test]
fn test_managed_clone() {
- let a = @5i;
- let b: @int = a.clone();
- assert_eq!(a, b);
+ let a = box(GC) 5i;
+ let b: Gc<int> = realclone(&a);
+ assert!(a == b);
}
#[test]
block: ast::P<ast::Block>,
mut out: W) -> io::IoResult<()> {
let ty_cx = &analysis.ty_cx;
- let cfg = cfg::CFG::new(ty_cx, block);
+ let cfg = cfg::CFG::new(ty_cx, &*block);
let lcfg = LabelledCFG { ast_map: &ty_cx.map,
cfg: &cfg,
name: format!("block{}", block.id).to_string(), };
use syntax::{ast, fold, attr};
use syntax::codemap;
+use std::gc::Gc;
+
struct Context<'a> {
in_cfg: |attrs: &[ast::Attribute]|: 'a -> bool,
}
fn fold_item_underscore(&mut self, item: &ast::Item_) -> ast::Item_ {
fold_item_underscore(self, item)
}
- fn fold_expr(&mut self, expr: @ast::Expr) -> @ast::Expr {
+ fn fold_expr(&mut self, expr: Gc<ast::Expr>) -> Gc<ast::Expr> {
fold_expr(self, expr)
}
}
}
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
- let filtered_items: Vec<&@ast::Item> = m.items.iter()
- .filter(|&a| item_in_cfg(cx, *a))
+ let filtered_items: Vec<&Gc<ast::Item>> = m.items.iter()
+ .filter(|a| item_in_cfg(cx, &***a))
.collect();
let flattened_items = filtered_items.move_iter()
.flat_map(|&x| cx.fold_item(x).move_iter())
}
}
-fn filter_foreign_item(cx: &mut Context, item: @ast::ForeignItem)
- -> Option<@ast::ForeignItem> {
- if foreign_item_in_cfg(cx, item) {
+fn filter_foreign_item(cx: &mut Context, item: Gc<ast::ForeignItem>)
+ -> Option<Gc<ast::ForeignItem>> {
+ if foreign_item_in_cfg(cx, &*item) {
Some(item)
} else {
None
fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
let item = match *item {
ast::ItemImpl(ref a, ref b, c, ref methods) => {
- let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
+ let methods = methods.iter().filter(|m| method_in_cfg(cx, &***m))
.map(|x| *x).collect();
ast::ItemImpl((*a).clone(), (*b).clone(), c, methods)
}
.collect();
ast::ItemTrait((*a).clone(), b, (*c).clone(), methods)
}
- ast::ItemStruct(def, ref generics) => {
- ast::ItemStruct(fold_struct(cx, def), generics.clone())
+ ast::ItemStruct(ref def, ref generics) => {
+ ast::ItemStruct(fold_struct(cx, &**def), generics.clone())
}
ast::ItemEnum(ref def, ref generics) => {
let mut variants = def.variants.iter().map(|c| c.clone()).
} else {
Some(match v.node.kind {
ast::TupleVariantKind(..) => v,
- ast::StructVariantKind(def) => {
- let def = fold_struct(cx, def);
- @codemap::Spanned {
+ ast::StructVariantKind(ref def) => {
+ let def = fold_struct(cx, &**def);
+ box(GC) codemap::Spanned {
node: ast::Variant_ {
- kind: ast::StructVariantKind(def),
+ kind: ast::StructVariantKind(def.clone()),
..v.node.clone()
},
..*v
fold::noop_fold_item_underscore(&item, cx)
}
-fn fold_struct(cx: &mut Context, def: &ast::StructDef) -> @ast::StructDef {
+fn fold_struct(cx: &mut Context, def: &ast::StructDef) -> Gc<ast::StructDef> {
let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| {
(cx.in_cfg)(m.node.attrs.as_slice())
});
- @ast::StructDef {
+ box(GC) ast::StructDef {
fields: fields.collect(),
ctor_id: def.ctor_id,
super_struct: def.super_struct.clone(),
}
}
-fn retain_stmt(cx: &mut Context, stmt: @ast::Stmt) -> bool {
+fn retain_stmt(cx: &mut Context, stmt: Gc<ast::Stmt>) -> bool {
match stmt.node {
ast::StmtDecl(decl, _) => {
match decl.node {
- ast::DeclItem(item) => {
- item_in_cfg(cx, item)
+ ast::DeclItem(ref item) => {
+ item_in_cfg(cx, &**item)
}
_ => true
}
}
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
- let resulting_stmts: Vec<&@ast::Stmt> =
+ let resulting_stmts: Vec<&Gc<ast::Stmt>> =
b.stmts.iter().filter(|&a| retain_stmt(cx, *a)).collect();
let resulting_stmts = resulting_stmts.move_iter()
- .flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
+ .flat_map(|stmt| cx.fold_stmt(&**stmt).move_iter())
.collect();
let filtered_view_items = b.view_items.iter().filter_map(|a| {
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
})
}
-fn fold_expr(cx: &mut Context, expr: @ast::Expr) -> @ast::Expr {
+fn fold_expr(cx: &mut Context, expr: Gc<ast::Expr>) -> Gc<ast::Expr> {
let expr = match expr.node {
ast::ExprMatch(ref m, ref arms) => {
let arms = arms.iter()
.filter(|a| (cx.in_cfg)(a.attrs.as_slice()))
.map(|a| a.clone())
.collect();
- @ast::Expr {
+ box(GC) ast::Expr {
id: expr.id,
span: expr.span.clone(),
node: ast::ExprMatch(m.clone(), arms),
// Determine if an item should be translated in the current crate
// configuration based on the item's attributes
-fn in_cfg(cfg: &[@ast::MetaItem], attrs: &[ast::Attribute]) -> bool {
+fn in_cfg(cfg: &[Gc<ast::MetaItem>], attrs: &[ast::Attribute]) -> bool {
attr::test_cfg(cfg, attrs.iter().map(|x| *x))
}
use syntax::util::small_vector::SmallVector;
use std::mem;
+use std::gc::Gc;
pub static VERSION: &'static str = "0.11.0-pre";
krate
}
- fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
+ fn fold_item(&mut self, item: Gc<ast::Item>) -> SmallVector<Gc<ast::Item>> {
if !no_prelude(item.attrs.as_slice()) {
// only recur if there wasn't `#![no_implicit_prelude]`
// on this item, i.e. this means that the prelude is not
// implicitly imported though the whole subtree
- fold::noop_fold_item(item, self)
+ fold::noop_fold_item(&*item, self)
} else {
SmallVector::one(item)
}
}),
};
- let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
+ let vp = box(GC) codemap::dummy_spanned(ast::ViewPathGlob(prelude_path,
+ ast::DUMMY_NODE_ID));
let vi2 = ast::ViewItem {
node: ast::ViewItemUse(vp),
attrs: Vec::new(),
use front::std_inject::with_version;
use std::cell::RefCell;
+use std::gc::Gc;
use std::slice;
-use std::vec::Vec;
use std::vec;
use syntax::ast_util::*;
use syntax::attr::AttrMetaMethods;
}
}
- fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
+ fn fold_item(&mut self, i: Gc<ast::Item>) -> SmallVector<Gc<ast::Item>> {
self.cx.path.borrow_mut().push(i.ident);
debug!("current path: {}",
ast_util::path_name_i(self.cx.path.borrow().as_slice()));
}
}
- let res = fold::noop_fold_item(i, self);
+ let res = fold::noop_fold_item(&*i, self);
self.cx.path.borrow_mut().pop();
res
}
// Remove any #[main] from the AST so it doesn't clash with
// the one we're going to add. Only if compiling an executable.
- fn nomain(item: @ast::Item) -> @ast::Item {
- @ast::Item {
+ fn nomain(item: Gc<ast::Item>) -> Gc<ast::Item> {
+ box(GC) ast::Item {
attrs: item.attrs.iter().filter_map(|attr| {
if !attr.name().equiv(&("main")) {
Some(*attr)
})
}
-fn is_test_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
+fn is_test_fn(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
let has_test_attr = attr::contains_name(i.attrs.as_slice(), "test");
- fn has_test_signature(i: @ast::Item) -> bool {
+ fn has_test_signature(i: Gc<ast::Item>) -> bool {
match &i.node {
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
let no_output = match decl.output.node {
return has_test_attr && has_test_signature(i);
}
-fn is_bench_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
+fn is_bench_fn(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
let has_bench_attr = attr::contains_name(i.attrs.as_slice(), "bench");
- fn has_test_signature(i: @ast::Item) -> bool {
+ fn has_test_signature(i: Gc<ast::Item>) -> bool {
match i.node {
ast::ItemFn(ref decl, _, _, ref generics, _) => {
let input_cnt = decl.inputs.len();
return has_bench_attr && has_test_signature(i);
}
-fn is_ignored(cx: &TestCtxt, i: @ast::Item) -> bool {
+fn is_ignored(cx: &TestCtxt, i: Gc<ast::Item>) -> bool {
i.attrs.iter().any(|attr| {
// check ignore(cfg(foo, bar))
attr.check_name("ignore") && match attr.meta_item_list() {
})
}
-fn should_fail(i: @ast::Item) -> bool {
+fn should_fail(i: Gc<ast::Item>) -> bool {
attr::contains_name(i.attrs.as_slice(), "should_fail")
}
let id_test = token::str_to_ident("test");
let (vi, vis) = if cx.is_test_crate {
(ast::ViewItemUse(
- @nospan(ast::ViewPathSimple(id_test,
+ box(GC) nospan(ast::ViewPathSimple(id_test,
path_node(vec!(id_test)),
ast::DUMMY_NODE_ID))),
ast::Public)
}
}
-fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
+fn mk_test_module(cx: &TestCtxt) -> Gc<ast::Item> {
// Link to test crate
let view_items = vec!(mk_std(cx));
debug!("Synthetic test module:\n{}\n", pprust::item_to_str(&item));
- return @item;
+ box(GC) item
}
fn nospan<T>(t: T) -> codemap::Spanned<T> {
}
}
-fn mk_tests(cx: &TestCtxt) -> @ast::Item {
+fn mk_tests(cx: &TestCtxt) -> Gc<ast::Item> {
// The vector of test_descs for this crate
let test_descs = mk_test_descs(cx);
}
}
-fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
+fn mk_test_descs(cx: &TestCtxt) -> Gc<ast::Expr> {
debug!("building test vector from {} tests", cx.testfns.borrow().len());
- @ast::Expr {
+ box(GC) ast::Expr {
id: ast::DUMMY_NODE_ID,
- node: ast::ExprVstore(@ast::Expr {
+ node: ast::ExprVstore(box(GC) ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprVec(cx.testfns.borrow().iter().map(|test| {
mk_test_desc_and_fn_rec(cx, test)
}
}
-fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
+fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
let span = test.span;
let path = test.path.clone();
ast_util::path_name_i(path.as_slice()).as_slice()),
ast::CookedStr));
- let name_expr = @ast::Expr {
+ let name_expr = box(GC) ast::Expr {
id: ast::DUMMY_NODE_ID,
- node: ast::ExprLit(@name_lit),
+ node: ast::ExprLit(box(GC) name_lit),
span: span
};
let fn_path = path_node_global(path);
- let fn_expr = @ast::Expr {
+ let fn_expr = box(GC) ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprPath(fn_path),
span: span,
pub fn get_item_attrs(cstore: &cstore::CStore,
def_id: ast::DefId,
- f: |Vec<ast::Attribute> |) {
+ f: |Vec<ast::Attribute>|) {
let cdata = cstore.get_crate_data(def_id.krate);
decoder::get_item_attrs(&*cdata, def_id.node, f)
}
use middle::typeck;
use middle::astencode::vtable_decoder_helpers;
-use std::u64;
-use std::hash;
+use std::gc::Gc;
use std::hash::Hash;
-use std::io;
+use std::hash;
use std::io::extensions::u64_from_be_bytes;
-use std::option;
+use std::io;
use std::rc::Rc;
+use std::u64;
use serialize::ebml::reader;
use serialize::ebml;
use serialize::Decodable;
result
}
-fn get_meta_items(md: ebml::Doc) -> Vec<@ast::MetaItem> {
- let mut items: Vec<@ast::MetaItem> = Vec::new();
+fn get_meta_items(md: ebml::Doc) -> Vec<Gc<ast::MetaItem>> {
+ let mut items: Vec<Gc<ast::MetaItem>> = Vec::new();
reader::tagged_docs(md, tag_meta_item_word, |meta_item_doc| {
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
let n = token::intern_and_get_ident(nd.as_str_slice());
fn get_attributes(md: ebml::Doc) -> Vec<ast::Attribute> {
let mut attrs: Vec<ast::Attribute> = Vec::new();
match reader::maybe_get_doc(md, tag_attributes) {
- option::Some(attrs_d) => {
+ Some(attrs_d) => {
reader::tagged_docs(attrs_d, tag_attribute, |attr_doc| {
let meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on
true
});
}
- option::None => ()
+ None => ()
}
return attrs;
}
use util::nodemap::{NodeMap, NodeSet};
use serialize::Encodable;
-use std::mem;
use std::cell::RefCell;
-use std::hash;
+use std::gc::Gc;
use std::hash::Hash;
+use std::hash;
use std::io::MemWriter;
+use std::mem;
use std::str;
use std::collections::HashMap;
use syntax::abi;
/// * For enums, iterates through the node IDs of the variants.
///
/// * For newtype structs, iterates through the node ID of the constructor.
-fn each_auxiliary_node_id(item: @Item, callback: |NodeId| -> bool) -> bool {
+fn each_auxiliary_node_id(item: Gc<Item>, callback: |NodeId| -> bool) -> bool {
let mut continue_ = true;
match item.node {
ItemEnum(ref enum_def, _) => {
impl_path: PathElems,
is_default_impl: bool,
parent_id: NodeId,
- ast_method_opt: Option<@Method>) {
+ ast_method_opt: Option<Gc<Method>>) {
debug!("encode_info_for_method: {:?} {}", m.def_id,
token::get_ident(m.ident));
is_default_impl ||
should_inline(ast_method.attrs.as_slice()) {
encode_inlined_item(ecx, ebml_w,
- IIMethodRef(local_def(parent_id), false, ast_method));
+ IIMethodRef(local_def(parent_id), false,
+ &*ast_method));
} else {
encode_symbol(ecx, ebml_w, m.def_id.node);
}
}
encode_method_sort(ebml_w, 'p');
encode_inlined_item(ecx, ebml_w,
- IIMethodRef(def_id, true, m));
+ IIMethodRef(def_id, true, &*m));
encode_method_argument_names(ebml_w, &*m.decl);
}
}
wr.write_be_u32(n as u32);
}
-fn encode_meta_item(ebml_w: &mut Encoder, mi: @MetaItem) {
+fn encode_meta_item(ebml_w: &mut Encoder, mi: Gc<MetaItem>) {
match mi.node {
MetaWord(ref name) => {
ebml_w.start_tag(tag_meta_item_word);
use std::io::MemWriter;
use std::mem;
use std::rc::Rc;
-use std::string::String;
use serialize::ebml::reader;
use serialize::ebml;
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::print::pprust;
+#[cfg(test)] use std::gc::Gc;
struct DecodeContext<'a> {
cdata: &'a cstore::crate_metadata,
match ii {
ast::IIItem(i) => {
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
- syntax::print::pprust::item_to_str(i));
+ syntax::print::pprust::item_to_str(&*i));
}
_ => { }
}
def::DefUse(did) => def::DefUse(did.tr(xcx)),
def::DefUpvar(nid1, def, nid2, nid3) => {
def::DefUpvar(xcx.tr_id(nid1),
- @(*def).tr(xcx),
+ box(GC) (*def).tr(xcx),
xcx.tr_id(nid2),
xcx.tr_id(nid3))
}
// Testing of astencode_gen
#[cfg(test)]
-fn encode_item_ast(ebml_w: &mut Encoder, item: @ast::Item) {
+fn encode_item_ast(ebml_w: &mut Encoder, item: Gc<ast::Item>) {
ebml_w.start_tag(c::tag_tree as uint);
(*item).encode(ebml_w);
ebml_w.end_tag();
}
#[cfg(test)]
-fn decode_item_ast(par_doc: ebml::Doc) -> @ast::Item {
+fn decode_item_ast(par_doc: ebml::Doc) -> Gc<ast::Item> {
let chi_doc = par_doc.get(c::tag_tree as uint);
let mut d = reader::Decoder::new(chi_doc);
- @Decodable::decode(&mut d).unwrap()
+ box(GC) Decodable::decode(&mut d).unwrap()
}
#[cfg(test)]
}
#[cfg(test)]
-fn roundtrip(in_item: Option<@ast::Item>) {
+fn roundtrip(in_item: Option<Gc<ast::Item>>) {
use std::io::MemWriter;
let in_item = in_item.unwrap();
impl<'a> visit::Visitor<()> for StaticInitializerCtxt<'a> {
fn visit_expr(&mut self, ex: &Expr, _: ()) {
match ex.node {
- ast::ExprAddrOf(mutbl, base) => {
- let base_cmt = self.bccx.cat_expr(base);
+ ast::ExprAddrOf(mutbl, ref base) => {
+ let base_cmt = self.bccx.cat_expr(&**base);
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
// Check that we don't allow borrows of unsafe static items.
if check_aliasability(self.bccx, ex.span, euv::AddrOf,
// flow dependent conditions.
match item.node {
ast::ItemStatic(_, _, ex) => {
- gather_loans::gather_loans_in_static_initializer(this, ex);
+ gather_loans::gather_loans_in_static_initializer(this, &*ex);
}
_ => {
visit::walk_item(this, item, ());
move_data::MoveExpr => {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) {
Some(ast_map::NodeExpr(expr)) => {
- (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
+ (ty::expr_ty_adjusted(self.tcx, &*expr), expr.span)
}
r => {
self.tcx.sess.bug(format!("MoveExpr({:?}) maps to \
move_data::Captured => {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) {
Some(ast_map::NodeExpr(expr)) => {
- (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
+ (ty::expr_ty_adjusted(self.tcx, &*expr), expr.span)
}
r => {
self.tcx.sess.bug(format!("Captured({:?}) maps to \
use syntax::ast_util;
use util::nodemap::NodeMap;
+use std::gc::Gc;
+
struct CFGBuilder<'a> {
tcx: &'a ty::ctxt,
exit_map: NodeMap<CFGIndex>,
impl<'a> CFGBuilder<'a> {
fn block(&mut self, blk: &ast::Block, pred: CFGIndex) -> CFGIndex {
let mut stmts_exit = pred;
- for &stmt in blk.stmts.iter() {
- stmts_exit = self.stmt(stmt, stmts_exit);
+ for stmt in blk.stmts.iter() {
+ stmts_exit = self.stmt(stmt.clone(), stmts_exit);
}
- let expr_exit = self.opt_expr(blk.expr, stmts_exit);
+ let expr_exit = self.opt_expr(blk.expr.clone(), stmts_exit);
self.add_node(blk.id, [expr_exit])
}
- fn stmt(&mut self, stmt: @ast::Stmt, pred: CFGIndex) -> CFGIndex {
+ fn stmt(&mut self, stmt: Gc<ast::Stmt>, pred: CFGIndex) -> CFGIndex {
match stmt.node {
- ast::StmtDecl(decl, _) => {
- self.decl(decl, pred)
+ ast::StmtDecl(ref decl, _) => {
+ self.decl(&**decl, pred)
}
- ast::StmtExpr(expr, _) | ast::StmtSemi(expr, _) => {
- self.expr(expr, pred)
+ ast::StmtExpr(ref expr, _) | ast::StmtSemi(ref expr, _) => {
+ self.expr(expr.clone(), pred)
}
ast::StmtMac(..) => {
}
}
- fn decl(&mut self, decl: @ast::Decl, pred: CFGIndex) -> CFGIndex {
+ fn decl(&mut self, decl: &ast::Decl, pred: CFGIndex) -> CFGIndex {
match decl.node {
- ast::DeclLocal(local) => {
- let init_exit = self.opt_expr(local.init, pred);
- self.pat(local.pat, init_exit)
+ ast::DeclLocal(ref local) => {
+ let init_exit = self.opt_expr(local.init.clone(), pred);
+ self.pat(&*local.pat, init_exit)
}
ast::DeclItem(_) => {
}
}
- fn pat(&mut self, pat: @ast::Pat, pred: CFGIndex) -> CFGIndex {
+ fn pat(&mut self, pat: &ast::Pat, pred: CFGIndex) -> CFGIndex {
match pat.node {
ast::PatIdent(_, _, None) |
ast::PatEnum(_, None) |
self.add_node(pat.id, [pred])
}
- ast::PatBox(subpat) |
- ast::PatRegion(subpat) |
- ast::PatIdent(_, _, Some(subpat)) => {
- let subpat_exit = self.pat(subpat, pred);
+ ast::PatBox(ref subpat) |
+ ast::PatRegion(ref subpat) |
+ ast::PatIdent(_, _, Some(ref subpat)) => {
+ let subpat_exit = self.pat(&**subpat, pred);
self.add_node(pat.id, [subpat_exit])
}
ast::PatEnum(_, Some(ref subpats)) |
ast::PatTup(ref subpats) => {
let pats_exit =
- self.pats_all(subpats.iter().map(|p| *p), pred);
+ self.pats_all(subpats.iter().map(|p| p.clone()), pred);
self.add_node(pat.id, [pats_exit])
}
ast::PatStruct(_, ref subpats, _) => {
let pats_exit =
- self.pats_all(subpats.iter().map(|f| f.pat), pred);
+ self.pats_all(subpats.iter().map(|f| f.pat.clone()), pred);
self.add_node(pat.id, [pats_exit])
}
}
}
- fn pats_all<I: Iterator<@ast::Pat>>(&mut self,
+ fn pats_all<I: Iterator<Gc<ast::Pat>>>(&mut self,
pats: I,
pred: CFGIndex) -> CFGIndex {
//! Handles case where all of the patterns must match.
let mut pats = pats;
- pats.fold(pred, |pred, pat| self.pat(pat, pred))
+ pats.fold(pred, |pred, pat| self.pat(&*pat, pred))
}
fn pats_any(&mut self,
- pats: &[@ast::Pat],
+ pats: &[Gc<ast::Pat>],
pred: CFGIndex) -> CFGIndex {
//! Handles case where just one of the patterns must match.
if pats.len() == 1 {
- self.pat(pats[0], pred)
+ self.pat(&*pats[0], pred)
} else {
let collect = self.add_dummy_node([]);
for &pat in pats.iter() {
- let pat_exit = self.pat(pat, pred);
+ let pat_exit = self.pat(&*pat, pred);
self.add_contained_edge(pat_exit, collect);
}
collect
}
}
- fn expr(&mut self, expr: @ast::Expr, pred: CFGIndex) -> CFGIndex {
+ fn expr(&mut self, expr: Gc<ast::Expr>, pred: CFGIndex) -> CFGIndex {
match expr.node {
- ast::ExprBlock(blk) => {
- let blk_exit = self.block(blk, pred);
+ ast::ExprBlock(ref blk) => {
+ let blk_exit = self.block(&**blk, pred);
self.add_node(expr.id, [blk_exit])
}
- ast::ExprIf(cond, then, None) => {
+ ast::ExprIf(ref cond, ref then, None) => {
//
// [pred]
// |
// v 3 v 4
// [..expr..]
//
- let cond_exit = self.expr(cond, pred); // 1
- let then_exit = self.block(then, cond_exit); // 2
- self.add_node(expr.id, [cond_exit, then_exit]) // 3,4
+ let cond_exit = self.expr(cond.clone(), pred); // 1
+ let then_exit = self.block(&**then, cond_exit); // 2
+ self.add_node(expr.id, [cond_exit, then_exit]) // 3,4
}
- ast::ExprIf(cond, then, Some(otherwise)) => {
+ ast::ExprIf(ref cond, ref then, Some(ref otherwise)) => {
//
// [pred]
// |
// v 4 v 5
// [..expr..]
//
- let cond_exit = self.expr(cond, pred); // 1
- let then_exit = self.block(then, cond_exit); // 2
- let else_exit = self.expr(otherwise, cond_exit); // 3
- self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
+ let cond_exit = self.expr(cond.clone(), pred); // 1
+ let then_exit = self.block(&**then, cond_exit); // 2
+ let else_exit = self.expr(otherwise.clone(), cond_exit); // 3
+ self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
}
- ast::ExprWhile(cond, body) => {
+ ast::ExprWhile(ref cond, ref body) => {
//
// [pred]
// |
// may cause additional edges.
// Is the condition considered part of the loop?
- let loopback = self.add_dummy_node([pred]); // 1
- let cond_exit = self.expr(cond, loopback); // 2
- let expr_exit = self.add_node(expr.id, [cond_exit]); // 3
+ let loopback = self.add_dummy_node([pred]); // 1
+ let cond_exit = self.expr(cond.clone(), loopback); // 2
+ let expr_exit = self.add_node(expr.id, [cond_exit]); // 3
self.loop_scopes.push(LoopScope {
loop_id: expr.id,
continue_index: loopback,
break_index: expr_exit
});
- let body_exit = self.block(body, cond_exit); // 4
- self.add_contained_edge(body_exit, loopback); // 5
+ let body_exit = self.block(&**body, cond_exit); // 4
+ self.add_contained_edge(body_exit, loopback); // 5
expr_exit
}
ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
- ast::ExprLoop(body, _) => {
+ ast::ExprLoop(ref body, _) => {
//
// [pred]
// |
// Note that `break` and `loop` statements
// may cause additional edges.
- let loopback = self.add_dummy_node([pred]); // 1
- let expr_exit = self.add_node(expr.id, []); // 2
+ let loopback = self.add_dummy_node([pred]); // 1
+ let expr_exit = self.add_node(expr.id, []); // 2
self.loop_scopes.push(LoopScope {
loop_id: expr.id,
continue_index: loopback,
break_index: expr_exit,
});
- let body_exit = self.block(body, loopback); // 3
- self.add_contained_edge(body_exit, loopback); // 4
+ let body_exit = self.block(&**body, loopback); // 3
+ self.add_contained_edge(body_exit, loopback); // 4
self.loop_scopes.pop();
expr_exit
}
- ast::ExprMatch(discr, ref arms) => {
+ ast::ExprMatch(ref discr, ref arms) => {
//
// [pred]
// |
// v 5 v v
// [....expr....]
//
- let discr_exit = self.expr(discr, pred); // 1
+ let discr_exit = self.expr(discr.clone(), pred); // 1
let expr_exit = self.add_node(expr.id, []);
let mut guard_exit = discr_exit;
for arm in arms.iter() {
- guard_exit = self.opt_expr(arm.guard, guard_exit); // 2
+ guard_exit = self.opt_expr(arm.guard, guard_exit); // 2
let pats_exit = self.pats_any(arm.pats.as_slice(),
- guard_exit); // 3
- let body_exit = self.expr(arm.body, pats_exit); // 4
+ guard_exit); // 3
+ let body_exit = self.expr(arm.body.clone(), pats_exit); // 4
self.add_contained_edge(body_exit, expr_exit); // 5
}
expr_exit
}
- ast::ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
+ ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
//
// [pred]
// |
// v 3 v 4
// [..exit..]
//
- let l_exit = self.expr(l, pred); // 1
- let r_exit = self.expr(r, l_exit); // 2
+ let l_exit = self.expr(l.clone(), pred); // 1
+ let r_exit = self.expr(r.clone(), l_exit); // 2
self.add_node(expr.id, [l_exit, r_exit]) // 3,4
}
- ast::ExprRet(v) => {
- let v_exit = self.opt_expr(v, pred);
+ ast::ExprRet(ref v) => {
+ let v_exit = self.opt_expr(v.clone(), pred);
let b = self.add_node(expr.id, [v_exit]);
self.add_returning_edge(expr, b);
self.add_node(ast::DUMMY_NODE_ID, [])
self.straightline(expr, pred, elems.as_slice())
}
- ast::ExprCall(func, ref args) => {
- self.call(expr, pred, func, args.as_slice())
+ ast::ExprCall(ref func, ref args) => {
+ self.call(expr, pred, func.clone(), args.as_slice())
}
ast::ExprMethodCall(_, _, ref args) => {
self.call(expr, pred, *args.get(0), args.slice_from(1))
}
- ast::ExprIndex(l, r) |
- ast::ExprBinary(_, l, r) if self.is_method_call(expr) => {
- self.call(expr, pred, l, [r])
+ ast::ExprIndex(ref l, ref r) |
+ ast::ExprBinary(_, ref l, ref r) if self.is_method_call(&*expr) => {
+ self.call(expr, pred, l.clone(), [r.clone()])
}
- ast::ExprUnary(_, e) if self.is_method_call(expr) => {
- self.call(expr, pred, e, [])
+ ast::ExprUnary(_, ref e) if self.is_method_call(&*expr) => {
+ self.call(expr, pred, e.clone(), [])
}
ast::ExprTup(ref exprs) => {
ast::ExprStruct(_, ref fields, base) => {
let base_exit = self.opt_expr(base, pred);
- let field_exprs: Vec<@ast::Expr> =
+ let field_exprs: Vec<Gc<ast::Expr>> =
fields.iter().map(|f| f.expr).collect();
self.straightline(expr, base_exit, field_exprs.as_slice())
}
}
fn call(&mut self,
- call_expr: @ast::Expr,
+ call_expr: Gc<ast::Expr>,
pred: CFGIndex,
- func_or_rcvr: @ast::Expr,
- args: &[@ast::Expr]) -> CFGIndex {
+ func_or_rcvr: Gc<ast::Expr>,
+ args: &[Gc<ast::Expr>]) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
self.straightline(call_expr, func_or_rcvr_exit, args)
}
fn exprs(&mut self,
- exprs: &[@ast::Expr],
+ exprs: &[Gc<ast::Expr>],
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `exprs` evaluated in order
}
fn opt_expr(&mut self,
- opt_expr: Option<@ast::Expr>,
+ opt_expr: Option<Gc<ast::Expr>>,
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `opt_expr` evaluated, if Some
}
fn straightline(&mut self,
- expr: @ast::Expr,
+ expr: Gc<ast::Expr>,
pred: CFGIndex,
- subexprs: &[@ast::Expr]) -> CFGIndex {
+ subexprs: &[Gc<ast::Expr>]) -> CFGIndex {
//! Handles case of an expression that evaluates `subexprs` in order
let subexprs_exit = self.exprs(subexprs, pred);
}
fn add_exiting_edge(&mut self,
- from_expr: @ast::Expr,
+ from_expr: Gc<ast::Expr>,
from_index: CFGIndex,
to_loop: LoopScope,
to_index: CFGIndex) {
}
fn add_returning_edge(&mut self,
- _from_expr: @ast::Expr,
+ _from_expr: Gc<ast::Expr>,
from_index: CFGIndex) {
let mut data = CFGEdgeData {
exiting_scopes: vec!(),
}
fn find_scope(&self,
- expr: @ast::Expr,
+ expr: Gc<ast::Expr>,
label: Option<ast::Ident>) -> LoopScope {
match label {
None => {
fn check_item(v: &mut CheckCrateVisitor, it: &Item, _is_const: bool) {
match it.node {
ItemStatic(_, _, ex) => {
- v.visit_expr(ex, true);
+ v.visit_expr(&*ex, true);
check_item_recursion(&v.tcx.sess, &v.tcx.map, &v.tcx.def_map, it);
}
ItemEnum(ref enum_definition, _) => {
for var in (*enum_definition).variants.iter() {
for ex in var.node.disr_expr.iter() {
- v.visit_expr(*ex, true);
+ v.visit_expr(&**ex, true);
}
}
}
}
match p.node {
// Let through plain ~-string literals here
- PatLit(a) => if !is_str(a) { v.visit_expr(a, true); },
- PatRange(a, b) => {
- if !is_str(a) { v.visit_expr(a, true); }
- if !is_str(b) { v.visit_expr(b, true); }
+ PatLit(ref a) => if !is_str(&**a) { v.visit_expr(&**a, true); },
+ PatRange(ref a, ref b) => {
+ if !is_str(&**a) { v.visit_expr(&**a, true); }
+ if !is_str(&**b) { v.visit_expr(&**b, true); }
}
_ => visit::walk_pat(v, p, false)
}
match self.def_map.borrow().find(&e.id) {
Some(&DefStatic(def_id, _)) if
ast_util::is_local(def_id) => {
- self.visit_item(self.ast_map.expect_item(def_id.node), ());
+ self.visit_item(&*self.ast_map.expect_item(def_id.node), ());
}
_ => ()
}
fn visit_expr(&mut self, e: &ast::Expr, cx:Context) {
match e.node {
- ast::ExprWhile(e, b) => {
- self.visit_expr(e, cx);
- self.visit_block(b, Loop);
+ ast::ExprWhile(ref e, ref b) => {
+ self.visit_expr(&**e, cx);
+ self.visit_block(&**b, Loop);
}
- ast::ExprLoop(b, _) => {
- self.visit_block(b, Loop);
+ ast::ExprLoop(ref b, _) => {
+ self.visit_block(&**b, Loop);
}
- ast::ExprFnBlock(_, b) | ast::ExprProc(_, b) => {
- self.visit_block(b, Closure);
+ ast::ExprFnBlock(_, ref b) | ast::ExprProc(_, ref b) => {
+ self.visit_block(&**b, Closure);
}
ast::ExprBreak(_) => self.require_loop("break", cx, e.span),
ast::ExprAgain(_) => self.require_loop("continue", cx, e.span),
use util::ppaux::ty_to_str;
use std::cmp;
+use std::gc::Gc;
use std::iter;
use syntax::ast::*;
use syntax::ast_util::{is_unguarded, walk_pat};
match opt_def {
Some(DefStatic(did, false)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
- match eval_const_expr(cx.tcx, const_expr) {
+ match eval_const_expr(cx.tcx, &*const_expr) {
const_float(f) if f.is_nan() => true,
_ => false
}
}
};
- walk_pat(*pat, |p| {
+ walk_pat(&**pat, |p| {
if pat_matches_nan(p) {
cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
use the is_nan method in a guard instead");
}
}
-fn raw_pat(p: @Pat) -> @Pat {
+fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
match p.node {
PatIdent(_, _, Some(s)) => { raw_pat(s) }
_ => { p }
cx.tcx.sess.span_err(sp, msg.as_slice());
}
-type matrix = Vec<Vec<@Pat> > ;
+type matrix = Vec<Vec<Gc<Pat>>>;
#[deriving(Clone)]
enum useful {
// Note: is_useful doesn't work on empty types, as the paper notes.
// So it assumes that v is non-empty.
-fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
+fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[Gc<Pat>]) -> useful {
if m.len() == 0u {
return useful_;
}
fn is_useful_specialized(cx: &MatchCheckCtxt,
m: &matrix,
- v: &[@Pat],
+ v: &[Gc<Pat>],
ctor: ctor,
arity: uint,
lty: ty::t)
}
}
-fn pat_ctor_id(cx: &MatchCheckCtxt, p: @Pat) -> Option<ctor> {
+fn pat_ctor_id(cx: &MatchCheckCtxt, p: Gc<Pat>) -> Option<ctor> {
let pat = raw_pat(p);
match pat.node {
PatWild | PatWildMulti => { None }
Some(DefVariant(_, id, _)) => Some(variant(id)),
Some(DefStatic(did, false)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
- Some(val(eval_const_expr(cx.tcx, const_expr)))
+ Some(val(eval_const_expr(cx.tcx, &*const_expr)))
}
_ => None
}
}
- PatLit(expr) => { Some(val(eval_const_expr(cx.tcx, expr))) }
- PatRange(lo, hi) => {
- Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi)))
+ PatLit(ref expr) => { Some(val(eval_const_expr(cx.tcx, &**expr))) }
+ PatRange(ref lo, ref hi) => {
+ Some(range(eval_const_expr(cx.tcx, &**lo), eval_const_expr(cx.tcx, &**hi)))
}
PatStruct(..) => {
match cx.tcx.def_map.borrow().find(&pat.id) {
}
}
-fn is_wild(cx: &MatchCheckCtxt, p: @Pat) -> bool {
+fn is_wild(cx: &MatchCheckCtxt, p: Gc<Pat>) -> bool {
let pat = raw_pat(p);
match pat.node {
PatWild | PatWildMulti => { true }
}
}
-fn wild() -> @Pat {
- @Pat {id: 0, node: PatWild, span: DUMMY_SP}
+fn wild() -> Gc<Pat> {
+ box(GC) Pat {id: 0, node: PatWild, span: DUMMY_SP}
}
-fn wild_multi() -> @Pat {
- @Pat {id: 0, node: PatWildMulti, span: DUMMY_SP}
+fn wild_multi() -> Gc<Pat> {
+ box(GC) Pat {id: 0, node: PatWildMulti, span: DUMMY_SP}
}
fn range_covered_by_constructor(ctor_id: &ctor, from: &const_val, to: &const_val) -> Option<bool> {
}
fn specialize(cx: &MatchCheckCtxt,
- r: &[@Pat],
+ r: &[Gc<Pat>],
ctor_id: &ctor,
arity: uint,
left_ty: ty::t)
- -> Option<Vec<@Pat> > {
+ -> Option<Vec<Gc<Pat>>> {
let &Pat{id: ref pat_id, node: ref n, span: ref pat_span} = &(*raw_pat(r[0]));
- let head: Option<Vec<@Pat>> = match n {
+ let head: Option<Vec<Gc<Pat>>> = match n {
&PatWild => {
Some(Vec::from_elem(arity, wild()))
}
}
Some(DefStatic(did, _)) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
- let e_v = eval_const_expr(cx.tcx, const_expr);
+ let e_v = eval_const_expr(cx.tcx, &*const_expr);
match range_covered_by_constructor(ctor_id, &e_v, &e_v) {
Some(true) => Some(vec!()),
Some(false) => None,
match def {
DefStatic(did, _) => {
let const_expr = lookup_const_by_id(cx.tcx, did).unwrap();
- let e_v = eval_const_expr(cx.tcx, const_expr);
+ let e_v = eval_const_expr(cx.tcx, &*const_expr);
match range_covered_by_constructor(ctor_id, &e_v, &e_v) {
Some(true) => Some(vec!()),
Some(false) => None,
Some(vec!(inner.clone()))
}
&PatLit(ref expr) => {
- let expr_value = eval_const_expr(cx.tcx, *expr);
+ let expr_value = eval_const_expr(cx.tcx, &**expr);
match range_covered_by_constructor(ctor_id, &expr_value, &expr_value) {
Some(true) => Some(vec!()),
Some(false) => None,
}
}
&PatRange(ref from, ref to) => {
- let from_value = eval_const_expr(cx.tcx, *from);
- let to_value = eval_const_expr(cx.tcx, *to);
+ let from_value = eval_const_expr(cx.tcx, &**from);
+ let to_value = eval_const_expr(cx.tcx, &**to);
match range_covered_by_constructor(ctor_id, &from_value, &to_value) {
Some(true) => Some(vec!()),
Some(false) => None,
head.map(|head| head.append(r.tail()))
}
-fn default(cx: &MatchCheckCtxt, r: &[@Pat]) -> Option<Vec<@Pat> > {
+fn default(cx: &MatchCheckCtxt, r: &[Gc<Pat>]) -> Option<Vec<Gc<Pat>>> {
if is_wild(cx, r[0]) {
Some(Vec::from_slice(r.tail()))
} else {
};
let mut spans = vec![];
- find_refutable(cx, loc.pat, &mut spans);
+ find_refutable(cx, &*loc.pat, &mut spans);
for span in spans.iter() {
cx.tcx.sess.span_err(*span,
visit::walk_fn(cx, kind, decl, body, sp, ());
for input in decl.inputs.iter() {
let mut spans = vec![];
- find_refutable(cx, input.pat, &mut spans);
+ find_refutable(cx, &*input.pat, &mut spans);
for span in spans.iter() {
cx.tcx.sess.span_err(*span,
}
match pat.node {
- PatBox(sub) | PatRegion(sub) | PatIdent(_, _, Some(sub)) => {
- find_refutable(cx, sub, spans)
+ PatBox(ref sub) | PatRegion(ref sub) | PatIdent(_, _, Some(ref sub)) => {
+ find_refutable(cx, &**sub, spans)
}
PatWild | PatWildMulti | PatIdent(_, _, None) => {}
PatLit(lit) => {
PatRange(_, _) => { this_pattern!() }
PatStruct(_, ref fields, _) => {
for f in fields.iter() {
- find_refutable(cx, f.pat, spans);
+ find_refutable(cx, &*f.pat, spans);
}
}
PatTup(ref elts) | PatEnum(_, Some(ref elts))=> {
for elt in elts.iter() {
- find_refutable(cx, *elt, spans)
+ find_refutable(cx, &**elt, spans)
}
}
PatEnum(_,_) => {}
fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
has_guard: bool,
- pats: &[@Pat]) {
+ pats: &[Gc<Pat>]) {
let tcx = cx.tcx;
let def_map = &tcx.def_map;
let mut by_ref_span = None;
for pat in pats.iter() {
- pat_bindings(def_map, *pat, |bm, _, span, _path| {
+ pat_bindings(def_map, &**pat, |bm, _, span, _path| {
match bm {
BindByRef(_) => {
by_ref_span = Some(span);
})
}
- let check_move: |&Pat, Option<@Pat>| = |p, sub| {
+ let check_move: |&Pat, Option<Gc<Pat>>| = |p, sub| {
// check legality of moving out of the enum
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
- if sub.map_or(false, |p| pat_contains_bindings(def_map, p)) {
+ if sub.map_or(false, |p| pat_contains_bindings(def_map, &*p)) {
tcx.sess.span_err(
p.span,
"cannot bind by-move with sub-bindings");
};
for pat in pats.iter() {
- walk_pat(*pat, |p| {
- if pat_is_binding(def_map, p) {
+ walk_pat(&**pat, |p| {
+ if pat_is_binding(def_map, &*p) {
match p.node {
PatIdent(BindByValue(_), _, sub) => {
let pat_ty = ty::node_id_to_type(tcx, p.id);
fn visit_item(&mut self, i: &ast::Item, _is_const: bool) {
debug!("visit_item(item={})", pprust::item_to_str(i));
match i.node {
- ast::ItemStatic(_, mutability, expr) => {
+ ast::ItemStatic(_, mutability, ref expr) => {
match mutability {
ast::MutImmutable => {
- self.visit_expr(expr, true);
+ self.visit_expr(&**expr, true);
}
ast::MutMutable => {
- self.report_error(expr.span, safe_type_for_static_mut(self.tcx, expr));
+ let safe = safe_type_for_static_mut(self.tcx, &**expr);
+ self.report_error(expr.span, safe);
}
}
}
use syntax::{ast, ast_map, ast_util};
use std::rc::Rc;
+use std::gc::Gc;
//
// This pass classifies expressions by their constant-ness.
cs.fold(integral_const, |a, b| join(a, b))
}
-pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<@Expr> {
+pub fn lookup_const(tcx: &ty::ctxt, e: &Expr) -> Option<Gc<Expr>> {
let opt_def = tcx.def_map.borrow().find_copy(&e.id);
match opt_def {
Some(def::DefStatic(def_id, false)) => {
pub fn lookup_variant_by_id(tcx: &ty::ctxt,
enum_def: ast::DefId,
variant_def: ast::DefId)
- -> Option<@Expr> {
- fn variant_expr(variants: &[ast::P<ast::Variant>], id: ast::NodeId) -> Option<@Expr> {
+ -> Option<Gc<Expr>> {
+ fn variant_expr(variants: &[ast::P<ast::Variant>],
+ id: ast::NodeId) -> Option<Gc<Expr>> {
for variant in variants.iter() {
if variant.node.id == id {
return variant.node.disr_expr;
}
pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
- -> Option<@Expr> {
+ -> Option<Gc<Expr>> {
if ast_util::is_local(def_id) {
{
match tcx.map.find(def_id.node) {
None => {}
}
let cn = match e.node {
- ast::ExprLit(lit) => {
+ ast::ExprLit(ref lit) => {
match lit.node {
ast::LitStr(..) | ast::LitFloat(..) => general_const,
_ => integral_const
}
}
- ast::ExprUnary(_, inner) | ast::ExprParen(inner) =>
- self.classify(inner),
+ ast::ExprUnary(_, ref inner) | ast::ExprParen(ref inner) =>
+ self.classify(&**inner),
- ast::ExprBinary(_, a, b) =>
- join(self.classify(a), self.classify(b)),
+ ast::ExprBinary(_, ref a, ref b) =>
+ join(self.classify(&**a), self.classify(&**b)),
ast::ExprTup(ref es) |
ast::ExprVec(ref es) =>
- join_all(es.iter().map(|e| self.classify(*e))),
+ join_all(es.iter().map(|e| self.classify(&**e))),
- ast::ExprVstore(e, vstore) => {
+ ast::ExprVstore(ref e, vstore) => {
match vstore {
- ast::ExprVstoreSlice => self.classify(e),
+ ast::ExprVstoreSlice => self.classify(&**e),
ast::ExprVstoreUniq |
ast::ExprVstoreMutSlice => non_const
}
}
ast::ExprStruct(_, ref fs, None) => {
- let cs = fs.iter().map(|f| self.classify(f.expr));
+ let cs = fs.iter().map(|f| self.classify(&*f.expr));
join_all(cs)
}
- ast::ExprCast(base, _) => {
+ ast::ExprCast(ref base, _) => {
let ty = ty::expr_ty(self.tcx, e);
- let base = self.classify(base);
+ let base = self.classify(&**base);
if ty::type_is_integral(ty) {
join(integral_const, base)
} else if ty::type_is_fp(ty) {
}
}
- ast::ExprField(base, _, _) => self.classify(base),
+ ast::ExprField(ref base, _, _) => self.classify(&**base),
- ast::ExprIndex(base, idx) =>
- join(self.classify(base), self.classify(idx)),
+ ast::ExprIndex(ref base, ref idx) =>
+ join(self.classify(&**base), self.classify(&**idx)),
- ast::ExprAddrOf(ast::MutImmutable, base) => self.classify(base),
+ ast::ExprAddrOf(ast::MutImmutable, ref base) =>
+ self.classify(&**base),
// FIXME: (#3728) we can probably do something CCI-ish
// surrounding nonlocal constants. But we don't yet.
fn lookup_constness(&self, e: &Expr) -> constness {
match lookup_const(self.tcx, e) {
Some(rhs) => {
- let ty = ty::expr_ty(self.tcx, rhs);
+ let ty = ty::expr_ty(self.tcx, &*rhs);
if ty::type_is_integral(ty) {
integral_const
} else {
-> Result<const_val, String> {
fn fromb(b: bool) -> Result<const_val, String> { Ok(const_int(b as i64)) }
match e.node {
- ExprUnary(UnNeg, inner) => {
- match eval_const_expr_partial(tcx, inner) {
+ ExprUnary(UnNeg, ref inner) => {
+ match eval_const_expr_partial(tcx, &**inner) {
Ok(const_float(f)) => Ok(const_float(-f)),
Ok(const_int(i)) => Ok(const_int(-i)),
Ok(const_uint(i)) => Ok(const_uint(-i)),
ref err => ((*err).clone())
}
}
- ExprUnary(UnNot, inner) => {
- match eval_const_expr_partial(tcx, inner) {
+ ExprUnary(UnNot, ref inner) => {
+ match eval_const_expr_partial(tcx, &**inner) {
Ok(const_int(i)) => Ok(const_int(!i)),
Ok(const_uint(i)) => Ok(const_uint(!i)),
Ok(const_bool(b)) => Ok(const_bool(!b)),
_ => Err("not on float or string".to_string())
}
}
- ExprBinary(op, a, b) => {
- match (eval_const_expr_partial(tcx, a),
- eval_const_expr_partial(tcx, b)) {
+ ExprBinary(op, ref a, ref b) => {
+ match (eval_const_expr_partial(tcx, &**a),
+ eval_const_expr_partial(tcx, &**b)) {
(Ok(const_float(a)), Ok(const_float(b))) => {
match op {
BiAdd => Ok(const_float(a + b)),
_ => Err("bad operands for binary".to_string())
}
}
- ExprCast(base, target_ty) => {
+ ExprCast(ref base, ref target_ty) => {
// This tends to get called w/o the type actually having been
// populated in the ctxt, which was causing things to blow up
// (#5900). Fall back to doing a limited lookup to get past it.
let ety = ty::expr_ty_opt(tcx.ty_ctxt(), e)
- .or_else(|| astconv::ast_ty_to_prim_ty(tcx.ty_ctxt(), target_ty))
+ .or_else(|| astconv::ast_ty_to_prim_ty(tcx.ty_ctxt(), &**target_ty))
.unwrap_or_else(|| {
tcx.ty_ctxt().sess.span_fatal(target_ty.span,
"target type not found for \
const cast")
});
- let base = eval_const_expr_partial(tcx, base);
+ let base = eval_const_expr_partial(tcx, &**base);
match base {
Err(_) => base,
Ok(val) => {
}
ExprPath(_) => {
match lookup_const(tcx.ty_ctxt(), e) {
- Some(actual_e) => eval_const_expr_partial(tcx.ty_ctxt(), actual_e),
+ Some(actual_e) => eval_const_expr_partial(tcx.ty_ctxt(), &*actual_e),
None => Err("non-constant path in constant expr".to_string())
}
}
- ExprLit(lit) => Ok(lit_to_const(lit)),
+ ExprLit(ref lit) => Ok(lit_to_const(&**lit)),
// If we have a vstore, just keep going; it has to be a string
- ExprVstore(e, _) => eval_const_expr_partial(tcx, e),
- ExprParen(e) => eval_const_expr_partial(tcx, e),
+ ExprVstore(ref e, _) => eval_const_expr_partial(tcx, &**e),
+ ExprParen(ref e) => eval_const_expr_partial(tcx, &**e),
ExprBlock(ref block) => {
match block.expr {
Some(ref expr) => eval_const_expr_partial(tcx, &**expr),
use middle::ty;
use middle::typeck;
use std::io;
-use std::string::String;
+use std::gc::Gc;
use std::uint;
use syntax::ast;
use syntax::ast_util;
self.merge_with_entry_set(blk.id, in_out);
- for &stmt in blk.stmts.iter() {
- self.walk_stmt(stmt, in_out, loop_scopes);
+ for stmt in blk.stmts.iter() {
+ self.walk_stmt(stmt.clone(), in_out, loop_scopes);
}
self.walk_opt_expr(blk.expr, in_out, loop_scopes);
}
fn walk_stmt(&mut self,
- stmt: @ast::Stmt,
+ stmt: Gc<ast::Stmt>,
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
match stmt.node {
- ast::StmtDecl(decl, _) => {
- self.walk_decl(decl, in_out, loop_scopes);
+ ast::StmtDecl(ref decl, _) => {
+ self.walk_decl(decl.clone(), in_out, loop_scopes);
}
- ast::StmtExpr(expr, _) | ast::StmtSemi(expr, _) => {
- self.walk_expr(expr, in_out, loop_scopes);
+ ast::StmtExpr(ref expr, _) | ast::StmtSemi(ref expr, _) => {
+ self.walk_expr(&**expr, in_out, loop_scopes);
}
ast::StmtMac(..) => {
}
fn walk_decl(&mut self,
- decl: @ast::Decl,
+ decl: Gc<ast::Decl>,
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
match decl.node {
- ast::DeclLocal(local) => {
+ ast::DeclLocal(ref local) => {
self.walk_opt_expr(local.init, in_out, loop_scopes);
self.walk_pat(local.pat, in_out, loop_scopes);
}
// v v
// ( succ )
//
- self.walk_expr(cond, in_out, loop_scopes);
+ self.walk_expr(&*cond, in_out, loop_scopes);
let mut then_bits = in_out.to_owned();
- self.walk_block(then, then_bits, loop_scopes);
+ self.walk_block(&*then, then_bits, loop_scopes);
self.walk_opt_expr(els, in_out, loop_scopes);
join_bits(&self.dfcx.oper, then_bits, in_out);
// <--+ (break)
//
- self.walk_expr(cond, in_out, loop_scopes);
+ self.walk_expr(&*cond, in_out, loop_scopes);
let mut body_bits = in_out.to_owned();
loop_scopes.push(LoopScope {
loop_id: expr.id,
break_bits: Vec::from_slice(in_out)
});
- self.walk_block(blk, body_bits, loop_scopes);
+ self.walk_block(&*blk, body_bits, loop_scopes);
self.add_to_entry_set(expr.id, body_bits);
let new_loop_scope = loop_scopes.pop().unwrap();
copy_bits(new_loop_scope.break_bits.as_slice(), in_out);
ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
- ast::ExprLoop(blk, _) => {
+ ast::ExprLoop(ref blk, _) => {
//
// (expr) <--+
// | |
loop_id: expr.id,
break_bits: Vec::from_slice(in_out)
});
- self.walk_block(blk, body_bits, loop_scopes);
+ self.walk_block(&**blk, body_bits, loop_scopes);
self.add_to_entry_set(expr.id, body_bits);
let new_loop_scope = loop_scopes.pop().unwrap();
copy_bits(new_loop_scope.break_bits.as_slice(), in_out);
}
- ast::ExprMatch(discr, ref arms) => {
+ ast::ExprMatch(ref discr, ref arms) => {
//
// (discr)
// / | \
// ( succ )
//
//
- self.walk_expr(discr, in_out, loop_scopes);
+ self.walk_expr(&**discr, in_out, loop_scopes);
let mut guards = in_out.to_owned();
self.walk_pat_alternatives(arm.pats.as_slice(),
body,
loop_scopes);
- self.walk_expr(arm.body, body, loop_scopes);
+ self.walk_expr(&*arm.body, body, loop_scopes);
join_bits(&self.dfcx.oper, body, in_out);
}
}
self.reset(in_out);
}
- ast::ExprAssign(l, r) |
- ast::ExprAssignOp(_, l, r) => {
- self.walk_expr(r, in_out, loop_scopes);
- self.walk_expr(l, in_out, loop_scopes);
+ ast::ExprAssign(ref l, ref r) |
+ ast::ExprAssignOp(_, ref l, ref r) => {
+ self.walk_expr(&**r, in_out, loop_scopes);
+ self.walk_expr(&**l, in_out, loop_scopes);
}
ast::ExprVec(ref exprs) => {
self.walk_exprs(exprs.as_slice(), in_out, loop_scopes)
}
- ast::ExprRepeat(l, r) => {
- self.walk_expr(l, in_out, loop_scopes);
- self.walk_expr(r, in_out, loop_scopes);
+ ast::ExprRepeat(ref l, ref r) => {
+ self.walk_expr(&**l, in_out, loop_scopes);
+ self.walk_expr(&**r, in_out, loop_scopes);
}
ast::ExprStruct(_, ref fields, with_expr) => {
for field in fields.iter() {
- self.walk_expr(field.expr, in_out, loop_scopes);
+ self.walk_expr(&*field.expr, in_out, loop_scopes);
}
self.walk_opt_expr(with_expr, in_out, loop_scopes);
}
- ast::ExprCall(f, ref args) => {
- self.walk_expr(f, in_out, loop_scopes);
+ ast::ExprCall(ref f, ref args) => {
+ self.walk_expr(&**f, in_out, loop_scopes);
self.walk_call(expr.id, args.as_slice(), in_out, loop_scopes);
}
self.walk_exprs(exprs.as_slice(), in_out, loop_scopes);
}
- ast::ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
- self.walk_expr(l, in_out, loop_scopes);
+ ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
+ self.walk_expr(&**l, in_out, loop_scopes);
let temp = in_out.to_owned();
- self.walk_expr(r, in_out, loop_scopes);
+ self.walk_expr(&**r, in_out, loop_scopes);
join_bits(&self.dfcx.oper, temp, in_out);
}
ast::ExprLit(..) |
ast::ExprPath(..) => {}
- ast::ExprAddrOf(_, e) |
- ast::ExprCast(e, _) |
- ast::ExprUnary(_, e) |
- ast::ExprParen(e) |
- ast::ExprVstore(e, _) |
- ast::ExprField(e, _, _) => {
- self.walk_expr(e, in_out, loop_scopes);
+ ast::ExprAddrOf(_, ref e) |
+ ast::ExprCast(ref e, _) |
+ ast::ExprUnary(_, ref e) |
+ ast::ExprParen(ref e) |
+ ast::ExprVstore(ref e, _) |
+ ast::ExprField(ref e, _, _) => {
+ self.walk_expr(&**e, in_out, loop_scopes);
}
- ast::ExprBox(s, e) => {
- self.walk_expr(s, in_out, loop_scopes);
- self.walk_expr(e, in_out, loop_scopes);
+ ast::ExprBox(ref s, ref e) => {
+ self.walk_expr(&**s, in_out, loop_scopes);
+ self.walk_expr(&**e, in_out, loop_scopes);
}
ast::ExprInlineAsm(ref inline_asm) => {
- for &(_, expr) in inline_asm.inputs.iter() {
- self.walk_expr(expr, in_out, loop_scopes);
+ for &(_, ref expr) in inline_asm.inputs.iter() {
+ self.walk_expr(&**expr, in_out, loop_scopes);
}
- for &(_, expr) in inline_asm.outputs.iter() {
- self.walk_expr(expr, in_out, loop_scopes);
+ for &(_, ref expr) in inline_asm.outputs.iter() {
+ self.walk_expr(&**expr, in_out, loop_scopes);
}
}
- ast::ExprBlock(blk) => {
- self.walk_block(blk, in_out, loop_scopes);
+ ast::ExprBlock(ref blk) => {
+ self.walk_block(&**blk, in_out, loop_scopes);
}
ast::ExprMac(..) => {
}
fn walk_exprs(&mut self,
- exprs: &[@ast::Expr],
+ exprs: &[Gc<ast::Expr>],
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
- for &expr in exprs.iter() {
- self.walk_expr(expr, in_out, loop_scopes);
+ for expr in exprs.iter() {
+ self.walk_expr(&**expr, in_out, loop_scopes);
}
}
fn walk_opt_expr(&mut self,
- opt_expr: Option<@ast::Expr>,
+ opt_expr: Option<Gc<ast::Expr>>,
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
- for &expr in opt_expr.iter() {
- self.walk_expr(expr, in_out, loop_scopes);
+ for expr in opt_expr.iter() {
+ self.walk_expr(&**expr, in_out, loop_scopes);
}
}
fn walk_call(&mut self,
call_id: ast::NodeId,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
self.walk_exprs(args, in_out, loop_scopes);
}
fn walk_pat(&mut self,
- pat: @ast::Pat,
+ pat: Gc<ast::Pat>,
in_out: &mut [uint],
_loop_scopes: &mut Vec<LoopScope> ) {
debug!("DataFlowContext::walk_pat(pat={}, in_out={})",
pat.repr(self.dfcx.tcx), bits_to_str(in_out));
- ast_util::walk_pat(pat, |p| {
+ ast_util::walk_pat(&*pat, |p| {
debug!(" p.id={} in_out={}", p.id, bits_to_str(in_out));
self.merge_with_entry_set(p.id, in_out);
self.dfcx.apply_gen_kill(p.id, in_out);
}
fn walk_pat_alternatives(&mut self,
- pats: &[@ast::Pat],
+ pats: &[Gc<ast::Pat>],
in_out: &mut [uint],
loop_scopes: &mut Vec<LoopScope> ) {
if pats.len() == 1 {
}
});
self.live_symbols.extend(live_fields.map(|f| f.node.id));
- visit::walk_item(self, item, ());
+ visit::walk_item(self, &*item, ());
}
ast::ItemFn(..)
| ast::ItemTy(..)
| ast::ItemEnum(..)
| ast::ItemStatic(..) => {
- visit::walk_item(self, item, ());
+ visit::walk_item(self, &*item, ());
}
_ => ()
}
}
ast_map::NodeTraitMethod(trait_method) => {
- visit::walk_trait_method(self, trait_method, ());
+ visit::walk_trait_method(self, &*trait_method, ());
}
ast_map::NodeMethod(method) => {
- visit::walk_block(self, method.body, ());
+ visit::walk_block(self, &*method.body, ());
}
ast_map::NodeForeignItem(foreign_item) => {
- visit::walk_foreign_item(self, foreign_item, ());
+ visit::walk_foreign_item(self, &*foreign_item, ());
}
_ => ()
}
self.lookup_and_handle_method(expr.id, expr.span);
}
ast::ExprField(ref lhs, ref ident, _) => {
- self.handle_field_access(*lhs, ident);
+ self.handle_field_access(&**lhs, ident);
}
_ => ()
}
// Overwrite so that we don't warn the trait method itself.
fn visit_trait_method(&mut self, trait_method: &ast::TraitMethod, _: ()) {
match *trait_method {
- ast::Provided(method) => visit::walk_block(self, method.body, ()),
+ ast::Provided(ref method) => visit::walk_block(self, &*method.body, ()),
ast::Required(_) => ()
}
}
use syntax::ast;
use syntax::ast_util::local_def;
+use std::gc::Gc;
+
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum Def {
DefFn(ast::DefId, ast::FnStyle),
DefBinding(ast::NodeId, ast::BindingMode),
DefUse(ast::DefId),
DefUpvar(ast::NodeId, // id of closed over var
- @Def, // closed over def
+ Gc<Def>, // closed over def
ast::NodeId, // expr node that creates the closure
ast::NodeId), // id for the block/body of the closure expr
}
}
- fn check_str_index(&mut self, e: @ast::Expr) {
+ fn check_str_index(&mut self, e: &ast::Expr) {
let base_type = match e.node {
ast::ExprIndex(base, _) => ty::node_id_to_type(self.tcx, base.id),
_ => return
_ => {}
}
}
- ast::ExprAssign(base, _) | ast::ExprAssignOp(_, base, _) => {
- self.check_str_index(base);
+ ast::ExprAssign(ref base, _) | ast::ExprAssignOp(_, ref base, _) => {
+ self.check_str_index(&**base);
}
- ast::ExprAddrOf(ast::MutMutable, base) => {
- self.check_str_index(base);
+ ast::ExprAddrOf(ast::MutMutable, ref base) => {
+ self.check_str_index(&**base);
}
ast::ExprInlineAsm(..) => {
self.require_unsafe(expr.span, "use of inline assembly")
use syntax::codemap::{Span};
use util::ppaux::Repr;
+use std::gc::Gc;
+
///////////////////////////////////////////////////////////////////////////
// The Delegate trait
ty::ReScope(body.id), // Args live only as long as the fn body.
arg_ty);
- self.walk_pat(arg_cmt, arg.pat);
+ self.walk_pat(arg_cmt, arg.pat.clone());
}
}
self.delegate.consume(consume_id, consume_span, cmt, mode);
}
- fn consume_exprs(&mut self, exprs: &Vec<@ast::Expr>) {
- for &expr in exprs.iter() {
- self.consume_expr(expr);
+ fn consume_exprs(&mut self, exprs: &Vec<Gc<ast::Expr>>) {
+ for expr in exprs.iter() {
+ self.consume_expr(&**expr);
}
}
self.delegate_consume(expr.id, expr.span, cmt);
match expr.node {
- ast::ExprParen(subexpr) => {
+ ast::ExprParen(ref subexpr) => {
// Argh but is ExprParen horrible. So, if we consume
// `(x)`, that generally is also consuming `x`, UNLESS
// there are adjustments on the `(x)` expression
if self.typer.adjustments().borrow().contains_key(&expr.id) {
self.walk_expr(expr);
} else {
- self.consume_expr(subexpr);
+ self.consume_expr(&**subexpr);
}
}
self.walk_adjustment(expr);
match expr.node {
- ast::ExprParen(subexpr) => {
- self.walk_expr(subexpr)
+ ast::ExprParen(ref subexpr) => {
+ self.walk_expr(&**subexpr)
}
ast::ExprPath(..) => { }
- ast::ExprUnary(ast::UnDeref, base) => { // *base
- if !self.walk_overloaded_operator(expr, base, []) {
- self.select_from_expr(base);
+ ast::ExprUnary(ast::UnDeref, ref base) => { // *base
+ if !self.walk_overloaded_operator(expr, &**base, []) {
+ self.select_from_expr(&**base);
}
}
- ast::ExprField(base, _, _) => { // base.f
- self.select_from_expr(base);
+ ast::ExprField(ref base, _, _) => { // base.f
+ self.select_from_expr(&**base);
}
- ast::ExprIndex(lhs, rhs) => { // lhs[rhs]
- if !self.walk_overloaded_operator(expr, lhs, [rhs]) {
- self.select_from_expr(lhs);
- self.consume_expr(rhs);
+ ast::ExprIndex(ref lhs, ref rhs) => { // lhs[rhs]
+ if !self.walk_overloaded_operator(expr, &**lhs, [rhs.clone()]) {
+ self.select_from_expr(&**lhs);
+ self.consume_expr(&**rhs);
}
}
- ast::ExprCall(callee, ref args) => { // callee(args)
- self.walk_callee(expr, callee);
+ ast::ExprCall(ref callee, ref args) => { // callee(args)
+ self.walk_callee(expr, &**callee);
self.consume_exprs(args);
}
self.consume_exprs(args);
}
- ast::ExprStruct(_, ref fields, opt_with) => {
- self.walk_struct_expr(expr, fields, opt_with);
+ ast::ExprStruct(_, ref fields, ref opt_with) => {
+ self.walk_struct_expr(expr, fields, opt_with.clone());
}
ast::ExprTup(ref exprs) => {
self.consume_exprs(exprs);
}
- ast::ExprIf(cond_expr, then_blk, opt_else_expr) => {
- self.consume_expr(cond_expr);
- self.walk_block(then_blk);
+ ast::ExprIf(ref cond_expr, ref then_blk, ref opt_else_expr) => {
+ self.consume_expr(&**cond_expr);
+ self.walk_block(&**then_blk);
for else_expr in opt_else_expr.iter() {
- self.consume_expr(*else_expr);
+ self.consume_expr(&**else_expr);
}
}
- ast::ExprMatch(discr, ref arms) => {
+ ast::ExprMatch(ref discr, ref arms) => {
// treatment of the discriminant is handled while
// walking the arms:
- self.walk_expr(discr);
- let discr_cmt = return_if_err!(self.mc.cat_expr(discr));
+ self.walk_expr(&**discr);
+ let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));
for arm in arms.iter() {
self.walk_arm(discr_cmt.clone(), arm);
}
self.consume_exprs(exprs);
}
- ast::ExprAddrOf(m, base) => { // &base
+ ast::ExprAddrOf(m, ref base) => { // &base
// make sure that the thing we are pointing out stays valid
// for the lifetime `scope_r` of the resulting ptr:
let expr_ty = ty::expr_ty(self.tcx(), expr);
if !ty::type_is_bot(expr_ty) {
let r = ty::ty_region(self.tcx(), expr.span, expr_ty);
let bk = ty::BorrowKind::from_mutbl(m);
- self.borrow_expr(base, r, bk, AddrOf);
+ self.borrow_expr(&**base, r, bk, AddrOf);
} else {
- self.walk_expr(base);
+ self.walk_expr(&**base);
}
}
ast::ExprInlineAsm(ref ia) => {
- for &(_, input) in ia.inputs.iter() {
- self.consume_expr(input);
+ for &(_, ref input) in ia.inputs.iter() {
+ self.consume_expr(&**input);
}
- for &(_, output) in ia.outputs.iter() {
- self.mutate_expr(expr, output, JustWrite);
+ for &(_, ref output) in ia.outputs.iter() {
+ self.mutate_expr(expr, &**output, JustWrite);
}
}
ast::ExprAgain(..) |
ast::ExprLit(..) => {}
- ast::ExprLoop(blk, _) => {
- self.walk_block(blk);
+ ast::ExprLoop(ref blk, _) => {
+ self.walk_block(&**blk);
}
- ast::ExprWhile(cond_expr, blk) => {
- self.consume_expr(cond_expr);
- self.walk_block(blk);
+ ast::ExprWhile(ref cond_expr, ref blk) => {
+ self.consume_expr(&**cond_expr);
+ self.walk_block(&**blk);
}
ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
- ast::ExprUnary(_, lhs) => {
- if !self.walk_overloaded_operator(expr, lhs, []) {
- self.consume_expr(lhs);
+ ast::ExprUnary(_, ref lhs) => {
+ if !self.walk_overloaded_operator(expr, &**lhs, []) {
+ self.consume_expr(&**lhs);
}
}
- ast::ExprBinary(_, lhs, rhs) => {
- if !self.walk_overloaded_operator(expr, lhs, [rhs]) {
- self.consume_expr(lhs);
- self.consume_expr(rhs);
+ ast::ExprBinary(_, ref lhs, ref rhs) => {
+ if !self.walk_overloaded_operator(expr, &**lhs, [rhs.clone()]) {
+ self.consume_expr(&**lhs);
+ self.consume_expr(&**rhs);
}
}
- ast::ExprBlock(blk) => {
- self.walk_block(blk);
+ ast::ExprBlock(ref blk) => {
+ self.walk_block(&**blk);
}
ast::ExprRet(ref opt_expr) => {
for expr in opt_expr.iter() {
- self.consume_expr(*expr);
+ self.consume_expr(&**expr);
}
}
- ast::ExprAssign(lhs, rhs) => {
- self.mutate_expr(expr, lhs, JustWrite);
- self.consume_expr(rhs);
+ ast::ExprAssign(ref lhs, ref rhs) => {
+ self.mutate_expr(expr, &**lhs, JustWrite);
+ self.consume_expr(&**rhs);
}
- ast::ExprCast(base, _) => {
- self.consume_expr(base);
+ ast::ExprCast(ref base, _) => {
+ self.consume_expr(&**base);
}
- ast::ExprAssignOp(_, lhs, rhs) => {
+ ast::ExprAssignOp(_, ref lhs, ref rhs) => {
// This will have to change if/when we support
// overloaded operators for `+=` and so forth.
- self.mutate_expr(expr, lhs, WriteAndRead);
- self.consume_expr(rhs);
+ self.mutate_expr(expr, &**lhs, WriteAndRead);
+ self.consume_expr(&**rhs);
}
- ast::ExprRepeat(base, count) => {
- self.consume_expr(base);
- self.consume_expr(count);
+ ast::ExprRepeat(ref base, ref count) => {
+ self.consume_expr(&**base);
+ self.consume_expr(&**count);
}
ast::ExprFnBlock(..) |
self.walk_captures(expr)
}
- ast::ExprVstore(base, _) => {
- self.consume_expr(base);
+ ast::ExprVstore(ref base, _) => {
+ self.consume_expr(&**base);
}
- ast::ExprBox(place, base) => {
- self.consume_expr(place);
- self.consume_expr(base);
+ ast::ExprBox(ref place, ref base) => {
+ self.consume_expr(&**place);
+ self.consume_expr(&**base);
}
ast::ExprMac(..) => {
fn walk_stmt(&mut self, stmt: &ast::Stmt) {
match stmt.node {
- ast::StmtDecl(decl, _) => {
+ ast::StmtDecl(ref decl, _) => {
match decl.node {
- ast::DeclLocal(local) => {
- self.walk_local(local);
+ ast::DeclLocal(ref local) => {
+ self.walk_local(local.clone());
}
ast::DeclItem(_) => {
}
}
- ast::StmtExpr(expr, _) |
- ast::StmtSemi(expr, _) => {
- self.consume_expr(expr);
+ ast::StmtExpr(ref expr, _) |
+ ast::StmtSemi(ref expr, _) => {
+ self.consume_expr(&**expr);
}
ast::StmtMac(..) => {
}
}
- fn walk_local(&mut self, local: @ast::Local) {
+ fn walk_local(&mut self, local: Gc<ast::Local>) {
match local.init {
None => {
let delegate = &mut self.delegate;
- pat_util::pat_bindings(&self.typer.tcx().def_map, local.pat, |_, id, span, _| {
+ pat_util::pat_bindings(&self.typer.tcx().def_map, &*local.pat,
+ |_, id, span, _| {
delegate.decl_without_init(id, span);
})
}
- Some(expr) => {
+ Some(ref expr) => {
// Variable declarations with
// initializers are considered
// "assigns", which is handled by
// `walk_pat`:
- self.walk_expr(expr);
- let init_cmt = return_if_err!(self.mc.cat_expr(expr));
+ self.walk_expr(&**expr);
+ let init_cmt = return_if_err!(self.mc.cat_expr(&**expr));
self.walk_pat(init_cmt, local.pat);
}
}
debug!("walk_block(blk.id={:?})", blk.id);
for stmt in blk.stmts.iter() {
- self.walk_stmt(*stmt);
+ self.walk_stmt(&**stmt);
}
for tail_expr in blk.expr.iter() {
- self.consume_expr(*tail_expr);
+ self.consume_expr(&**tail_expr);
}
}
fn walk_struct_expr(&mut self,
_expr: &ast::Expr,
fields: &Vec<ast::Field>,
- opt_with: Option<@ast::Expr>) {
+ opt_with: Option<Gc<ast::Expr>>) {
// Consume the expressions supplying values for each field.
for field in fields.iter() {
- self.consume_expr(field.expr);
+ self.consume_expr(&*field.expr);
}
let with_expr = match opt_with {
- Some(w) => { w }
+ Some(ref w) => { w.clone() }
None => { return; }
};
- let with_cmt = return_if_err!(self.mc.cat_expr(with_expr));
+ let with_cmt = return_if_err!(self.mc.cat_expr(&*with_expr));
// Select just those fields of the `with`
// expression that will actually be used
// Consume those fields of the with expression that are needed.
for with_field in with_fields.iter() {
if !contains_field_named(with_field, fields) {
- let cmt_field = self.mc.cat_field(with_expr,
+ let cmt_field = self.mc.cat_field(&*with_expr,
with_cmt.clone(),
with_field.ident,
with_field.mt.ty);
fn walk_overloaded_operator(&mut self,
expr: &ast::Expr,
receiver: &ast::Expr,
- args: &[@ast::Expr])
+ args: &[Gc<ast::Expr>])
-> bool
{
if !self.typer.is_method_call(expr.id) {
let r = ty::ReScope(expr.id);
let bk = ty::ImmBorrow;
- for &arg in args.iter() {
- self.borrow_expr(arg, r, bk, OverloadedOperator);
+ for arg in args.iter() {
+ self.borrow_expr(&**arg, r, bk, OverloadedOperator);
}
return true;
}
}
for guard in arm.guard.iter() {
- self.consume_expr(*guard);
+ self.consume_expr(&**guard);
}
- self.consume_expr(arm.body);
+ self.consume_expr(&*arm.body);
}
- fn walk_pat(&mut self, cmt_discr: mc::cmt, pat: @ast::Pat) {
+ fn walk_pat(&mut self, cmt_discr: mc::cmt, pat: Gc<ast::Pat>) {
debug!("walk_pat cmt_discr={} pat={}", cmt_discr.repr(self.tcx()),
pat.repr(self.tcx()));
let mc = &self.mc;
let tcx = typer.tcx();
let def_map = &self.typer.tcx().def_map;
let delegate = &mut self.delegate;
- return_if_err!(mc.cat_pattern(cmt_discr, pat, |mc, cmt_pat, pat| {
+ return_if_err!(mc.cat_pattern(cmt_discr, &*pat, |mc, cmt_pat, pat| {
if pat_util::pat_is_binding(def_map, pat) {
let tcx = typer.tcx();
// matched.
let (slice_cmt, slice_mutbl, slice_r) = {
- match mc.cat_slice_pattern(cmt_pat, slice_pat) {
+ match mc.cat_slice_pattern(cmt_pat, &*slice_pat) {
Ok(v) => v,
Err(()) => {
tcx.sess.span_bug(slice_pat.span,
fn check_item(cx: &mut Context, item: &Item) {
if !attr::contains_name(item.attrs.as_slice(), "unsafe_destructor") {
match item.node {
- ItemImpl(_, Some(ref trait_ref), self_type, _) => {
- check_impl_of_trait(cx, item, trait_ref, self_type);
+ ItemImpl(_, Some(ref trait_ref), ref self_type, _) => {
+ check_impl_of_trait(cx, item, trait_ref, &**self_type);
}
_ => {}
}
}
match e.node {
- ExprUnary(UnBox, interior) => {
- let interior_type = ty::expr_ty(cx.tcx, interior);
+ ExprUnary(UnBox, ref interior) => {
+ let interior_type = ty::expr_ty(cx.tcx, &**interior);
let _ = check_static(cx.tcx, interior_type, interior.span);
}
- ExprCast(source, _) => {
- let source_ty = ty::expr_ty(cx.tcx, source);
+ ExprCast(ref source, _) => {
+ let source_ty = ty::expr_ty(cx.tcx, &**source);
let target_ty = ty::expr_ty(cx.tcx, e);
check_trait_cast(cx, source_ty, target_ty, source.span);
}
- ExprRepeat(element, count_expr) => {
- let count = ty::eval_repeat_count(cx.tcx, count_expr);
+ ExprRepeat(ref element, ref count_expr) => {
+ let count = ty::eval_repeat_count(cx.tcx, &**count_expr);
if count > 1 {
- let element_ty = ty::expr_ty(cx.tcx, element);
+ let element_ty = ty::expr_ty(cx.tcx, &**element);
check_copy(cx, element_ty, element.span,
"repeated element will be copied");
}
use std::i64;
use std::i8;
use std::rc::Rc;
+use std::gc::Gc;
use std::to_str::ToStr;
use std::u16;
use std::u32;
/// Return true if that's the case. Otherwise return false.
pub fn each_lint(sess: &session::Session,
attrs: &[ast::Attribute],
- f: |@ast::MetaItem, Level, InternedString| -> bool)
+ f: |Gc<ast::MetaItem>, Level, InternedString| -> bool)
-> bool {
let xs = [Allow, Warn, Deny, Forbid];
for &level in xs.iter() {
fn check_unused_casts(cx: &Context, e: &ast::Expr) {
return match e.node {
ast::ExprCast(expr, ty) => {
- let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), ty);
- if ty::get(ty::expr_ty(cx.tcx, expr)).sty == ty::get(t_t).sty {
+ let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &*ty);
+ if ty::get(ty::expr_ty(cx.tcx, &*expr)).sty == ty::get(t_t).sty {
cx.span_lint(UnnecessaryTypecast, ty.span,
"unnecessary type cast");
}
}
},
_ => {
- let t = ty::expr_ty(cx.tcx, ex);
+ let t = ty::expr_ty(cx.tcx, &*ex);
match ty::get(t).sty {
ty::ty_uint(_) => {
cx.span_lint(UnsignedNegate, e.span,
}
},
ast::ExprBinary(binop, l, r) => {
- if is_comparison(binop) && !check_limits(cx.tcx, binop, l, r) {
+ if is_comparison(binop) && !check_limits(cx.tcx, binop, &*l, &*r) {
cx.span_lint(TypeLimits, e.span,
"comparison is useless due to type limits");
}
_ => ()
}
}
- ast::TyPtr(ref mt) => { check_ty(cx, mt.ty) }
+ ast::TyPtr(ref mt) => { check_ty(cx, &*mt.ty) }
_ => {}
}
}
fn check_foreign_fn(cx: &Context, decl: &ast::FnDecl) {
for input in decl.inputs.iter() {
- check_ty(cx, input.ty);
+ check_ty(cx, &*input.ty);
}
- check_ty(cx, decl.output)
+ check_ty(cx, &*decl.output)
}
match it.node {
ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => {
for ni in nmod.items.iter() {
match ni.node {
- ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, decl),
- ast::ForeignItemStatic(t, _) => check_ty(cx, t)
+ ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, &*decl),
+ ast::ForeignItemStatic(t, _) => check_ty(cx, &*t)
}
}
}
match item.node {
ast::ItemStruct(..) | ast::ItemEnum(..) => {
let mut visitor = RawPtrDerivingVisitor { cx: cx };
- visit::walk_item(&mut visitor, item, ());
+ visit::walk_item(&mut visitor, &*item, ());
}
_ => {}
}
ast::StmtSemi(expr, _) => expr,
_ => return
};
- let t = ty::expr_ty(cx.tcx, expr);
+ let t = ty::expr_ty(cx.tcx, &*expr);
match ty::get(t).sty {
ty::ty_nil | ty::ty_bot | ty::ty_bool => return,
_ => {}
_ => {}
}
- let t = ty::expr_ty(cx.tcx, expr);
+ let t = ty::expr_ty(cx.tcx, &*expr);
let mut warned = false;
match ty::get(t).sty {
ty::ty_struct(did, _) |
ast::ExprAssignOp(_, _, value) => (value, "assigned value"),
_ => return
};
- check_unnecessary_parens_core(cx, value, msg);
+ check_unnecessary_parens_core(cx, &*value, msg);
}
fn check_unnecessary_parens_stmt(cx: &Context, s: &ast::Stmt) {
},
_ => return
};
- check_unnecessary_parens_core(cx, value, msg);
+ check_unnecessary_parens_core(cx, &*value, msg);
}
fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
}
}
-fn check_unused_mut_pat(cx: &Context, pats: &[@ast::Pat]) {
+fn check_unused_mut_pat(cx: &Context, pats: &[Gc<ast::Pat>]) {
// collect all mutable pattern and group their NodeIDs by their Identifier to
// avoid false warnings in match arms with multiple patterns
let mut mutables = HashMap::new();
for &p in pats.iter() {
- pat_util::pat_bindings(&cx.tcx.def_map, p, |mode, id, _, path| {
+ pat_util::pat_bindings(&cx.tcx.def_map, &*p, |mode, id, _, path| {
match mode {
ast::BindByValue(ast::MutMutable) => {
if path.segments.len() != 1 {
use middle::ty;
use util::nodemap::NodeMap;
-use std::mem::transmute;
use std::fmt;
+use std::gc::Gc;
use std::io;
+use std::mem::transmute;
use std::rc::Rc;
use std::str;
use std::uint;
for arg in decl.inputs.iter() {
pat_util::pat_bindings(&ir.tcx.def_map,
- arg.pat,
+ &*arg.pat,
|_bm, arg_id, _x, path| {
debug!("adding argument {}", arg_id);
let ident = ast_util::path_to_ident(path);
}
fn visit_local(ir: &mut IrMaps, local: &Local) {
- pat_util::pat_bindings(&ir.tcx.def_map, local.pat, |_, p_id, sp, path| {
+ pat_util::pat_bindings(&ir.tcx.def_map, &*local.pat, |_, p_id, sp, path| {
debug!("adding local variable {}", p_id);
let name = ast_util::path_to_ident(path);
ir.add_live_node_for_node(p_id, VarDefNode(sp));
fn visit_arm(ir: &mut IrMaps, arm: &Arm) {
for pat in arm.pats.iter() {
- pat_util::pat_bindings(&ir.tcx.def_map, *pat, |bm, p_id, sp, path| {
+ pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path| {
debug!("adding local variable {} from match with bm {:?}",
p_id, bm);
let name = ast_util::path_to_ident(path);
}
fn arm_pats_bindings(&mut self,
- pats: &[@Pat],
+ pats: &[Gc<Pat>],
f: |&mut Liveness<'a>, LiveNode, Variable, Span, NodeId|) {
// only consider the first pattern; any later patterns must have
// the same bindings, and we also consider the first pattern to be
// the "authoritative" set of ids
if !pats.is_empty() {
- self.pat_bindings(pats[0], f)
+ self.pat_bindings(&*pats[0], f)
}
}
- fn define_bindings_in_pat(&mut self, pat: @Pat, succ: LiveNode)
+ fn define_bindings_in_pat(&mut self, pat: Gc<Pat>, succ: LiveNode)
-> LiveNode {
self.define_bindings_in_arm_pats([pat], succ)
}
- fn define_bindings_in_arm_pats(&mut self, pats: &[@Pat], succ: LiveNode)
+ fn define_bindings_in_arm_pats(&mut self, pats: &[Gc<Pat>], succ: LiveNode)
-> LiveNode {
let mut succ = succ;
self.arm_pats_bindings(pats, |this, ln, var, _sp, _id| {
-> LiveNode {
let succ = self.propagate_through_opt_expr(blk.expr, succ);
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
- self.propagate_through_stmt(*stmt, succ)
+ self.propagate_through_stmt(&**stmt, succ)
})
}
fn propagate_through_stmt(&mut self, stmt: &Stmt, succ: LiveNode)
-> LiveNode {
match stmt.node {
- StmtDecl(decl, _) => {
- self.propagate_through_decl(decl, succ)
+ StmtDecl(ref decl, _) => {
+ self.propagate_through_decl(&**decl, succ)
}
- StmtExpr(expr, _) | StmtSemi(expr, _) => {
- self.propagate_through_expr(expr, succ)
+ StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => {
+ self.propagate_through_expr(&**expr, succ)
}
StmtMac(..) => {
-> LiveNode {
match decl.node {
DeclLocal(ref local) => {
- self.propagate_through_local(*local, succ)
+ self.propagate_through_local(&**local, succ)
}
DeclItem(_) => succ,
}
self.define_bindings_in_pat(local.pat, succ)
}
- fn propagate_through_exprs(&mut self, exprs: &[@Expr], succ: LiveNode)
+ fn propagate_through_exprs(&mut self, exprs: &[Gc<Expr>], succ: LiveNode)
-> LiveNode {
exprs.iter().rev().fold(succ, |succ, expr| {
- self.propagate_through_expr(*expr, succ)
+ self.propagate_through_expr(&**expr, succ)
})
}
fn propagate_through_opt_expr(&mut self,
- opt_expr: Option<@Expr>,
+ opt_expr: Option<Gc<Expr>>,
succ: LiveNode)
-> LiveNode {
opt_expr.iter().fold(succ, |succ, expr| {
- self.propagate_through_expr(*expr, succ)
+ self.propagate_through_expr(&**expr, succ)
})
}
self.access_path(expr, succ, ACC_READ | ACC_USE)
}
- ExprField(e, _, _) => {
- self.propagate_through_expr(e, succ)
+ ExprField(ref e, _, _) => {
+ self.propagate_through_expr(&**e, succ)
}
- ExprFnBlock(_, blk) | ExprProc(_, blk) => {
+ ExprFnBlock(_, ref blk) | ExprProc(_, ref blk) => {
debug!("{} is an ExprFnBlock or ExprProc", expr_to_str(expr));
/*
})
}
- ExprIf(cond, then, els) => {
+ ExprIf(ref cond, ref then, ref els) => {
//
// (cond)
// |
// v v
// ( succ )
//
- let else_ln = self.propagate_through_opt_expr(els, succ);
- let then_ln = self.propagate_through_block(then, succ);
+ let else_ln = self.propagate_through_opt_expr(els.clone(), succ);
+ let then_ln = self.propagate_through_block(&**then, succ);
let ln = self.live_node(expr.id, expr.span);
self.init_from_succ(ln, else_ln);
self.merge_from_succ(ln, then_ln, false);
- self.propagate_through_expr(cond, ln)
+ self.propagate_through_expr(&**cond, ln)
}
- ExprWhile(cond, blk) => {
- self.propagate_through_loop(expr, Some(cond), blk, succ)
+ ExprWhile(ref cond, ref blk) => {
+ self.propagate_through_loop(expr, Some(cond.clone()), &**blk, succ)
}
ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
// Note that labels have been resolved, so we don't need to look
// at the label ident
- ExprLoop(blk, _) => {
- self.propagate_through_loop(expr, None, blk, succ)
+ ExprLoop(ref blk, _) => {
+ self.propagate_through_loop(expr, None, &**blk, succ)
}
- ExprMatch(e, ref arms) => {
+ ExprMatch(ref e, ref arms) => {
//
// (e)
// |
let mut first_merge = true;
for arm in arms.iter() {
let body_succ =
- self.propagate_through_expr(arm.body, succ);
+ self.propagate_through_expr(&*arm.body, succ);
let guard_succ =
self.propagate_through_opt_expr(arm.guard, body_succ);
let arm_succ =
self.merge_from_succ(ln, arm_succ, first_merge);
first_merge = false;
};
- self.propagate_through_expr(e, ln)
+ self.propagate_through_expr(&**e, ln)
}
ExprRet(o_e) => {
}
}
- ExprAssign(l, r) => {
+ ExprAssign(ref l, ref r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
- let succ = self.write_lvalue(l, succ, ACC_WRITE);
- let succ = self.propagate_through_lvalue_components(l, succ);
- self.propagate_through_expr(r, succ)
+ let succ = self.write_lvalue(&**l, succ, ACC_WRITE);
+ let succ = self.propagate_through_lvalue_components(&**l, succ);
+ self.propagate_through_expr(&**r, succ)
}
- ExprAssignOp(_, l, r) => {
+ ExprAssignOp(_, ref l, ref r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
- let succ = self.write_lvalue(l, succ, ACC_WRITE|ACC_READ);
- let succ = self.propagate_through_expr(r, succ);
- self.propagate_through_lvalue_components(l, succ)
+ let succ = self.write_lvalue(&**l, succ, ACC_WRITE|ACC_READ);
+ let succ = self.propagate_through_expr(&**r, succ);
+ self.propagate_through_lvalue_components(&**l, succ)
}
// Uninteresting cases: just propagate in rev exec order
- ExprVstore(expr, _) => {
- self.propagate_through_expr(expr, succ)
+ ExprVstore(ref expr, _) => {
+ self.propagate_through_expr(&**expr, succ)
}
ExprVec(ref exprs) => {
self.propagate_through_exprs(exprs.as_slice(), succ)
}
- ExprRepeat(element, count) => {
- let succ = self.propagate_through_expr(count, succ);
- self.propagate_through_expr(element, succ)
+ ExprRepeat(ref element, ref count) => {
+ let succ = self.propagate_through_expr(&**count, succ);
+ self.propagate_through_expr(&**element, succ)
}
- ExprStruct(_, ref fields, with_expr) => {
- let succ = self.propagate_through_opt_expr(with_expr, succ);
+ ExprStruct(_, ref fields, ref with_expr) => {
+ let succ = self.propagate_through_opt_expr(with_expr.clone(), succ);
fields.iter().rev().fold(succ, |succ, field| {
- self.propagate_through_expr(field.expr, succ)
+ self.propagate_through_expr(&*field.expr, succ)
})
}
- ExprCall(f, ref args) => {
+ ExprCall(ref f, ref args) => {
// calling a fn with bot return type means that the fn
// will fail, and hence the successors can be ignored
let is_bot = !self.ir.tcx.is_method_call(expr.id) && {
- let t_ret = ty::ty_fn_ret(ty::expr_ty(self.ir.tcx, f));
+ let t_ret = ty::ty_fn_ret(ty::expr_ty(self.ir.tcx, &**f));
ty::type_is_bot(t_ret)
};
let succ = if is_bot {
succ
};
let succ = self.propagate_through_exprs(args.as_slice(), succ);
- self.propagate_through_expr(f, succ)
+ self.propagate_through_expr(&**f, succ)
}
ExprMethodCall(_, _, ref args) => {
self.propagate_through_exprs(exprs.as_slice(), succ)
}
- ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
- let r_succ = self.propagate_through_expr(r, succ);
+ ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
+ let r_succ = self.propagate_through_expr(&**r, succ);
let ln = self.live_node(expr.id, expr.span);
self.init_from_succ(ln, succ);
self.merge_from_succ(ln, r_succ, false);
- self.propagate_through_expr(l, ln)
+ self.propagate_through_expr(&**l, ln)
}
- ExprIndex(l, r) |
- ExprBinary(_, l, r) |
- ExprBox(l, r) => {
- self.propagate_through_exprs([l, r], succ)
+ ExprIndex(ref l, ref r) |
+ ExprBinary(_, ref l, ref r) |
+ ExprBox(ref l, ref r) => {
+ self.propagate_through_exprs([l.clone(), r.clone()], succ)
}
- ExprAddrOf(_, e) |
- ExprCast(e, _) |
- ExprUnary(_, e) |
- ExprParen(e) => {
- self.propagate_through_expr(e, succ)
+ ExprAddrOf(_, ref e) |
+ ExprCast(ref e, _) |
+ ExprUnary(_, ref e) |
+ ExprParen(ref e) => {
+ self.propagate_through_expr(&**e, succ)
}
ExprInlineAsm(ref ia) => {
- let succ = ia.outputs.iter().rev().fold(succ, |succ, &(_, expr)| {
+ let succ = ia.outputs.iter().rev().fold(succ, |succ, &(_, ref expr)| {
// see comment on lvalues in
// propagate_through_lvalue_components()
- let succ = self.write_lvalue(expr, succ, ACC_WRITE);
- self.propagate_through_lvalue_components(expr, succ)
+ let succ = self.write_lvalue(&**expr, succ, ACC_WRITE);
+ self.propagate_through_lvalue_components(&**expr, succ)
});
// Inputs are executed first. Propagate last because of rev order
- ia.inputs.iter().rev().fold(succ, |succ, &(_, expr)| {
- self.propagate_through_expr(expr, succ)
+ ia.inputs.iter().rev().fold(succ, |succ, &(_, ref expr)| {
+ self.propagate_through_expr(&**expr, succ)
})
}
succ
}
- ExprBlock(blk) => {
- self.propagate_through_block(blk, succ)
+ ExprBlock(ref blk) => {
+ self.propagate_through_block(&**blk, succ)
}
ExprMac(..) => {
match expr.node {
ExprPath(_) => succ,
- ExprField(e, _, _) => self.propagate_through_expr(e, succ),
+ ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ),
_ => self.propagate_through_expr(expr, succ)
}
}
fn propagate_through_loop(&mut self,
expr: &Expr,
- cond: Option<@Expr>,
+ cond: Option<Gc<Expr>>,
body: &Block,
succ: LiveNode)
-> LiveNode {
fn check_local(this: &mut Liveness, local: &Local) {
match local.init {
Some(_) => {
- this.warn_about_unused_or_dead_vars_in_pat(local.pat);
+ this.warn_about_unused_or_dead_vars_in_pat(&*local.pat);
},
None => {
- this.pat_bindings(local.pat, |this, ln, var, sp, id| {
+ this.pat_bindings(&*local.pat, |this, ln, var, sp, id| {
this.warn_about_unused(sp, id, ln, var);
})
}
fn check_expr(this: &mut Liveness, expr: &Expr) {
match expr.node {
- ExprAssign(l, r) => {
- this.check_lvalue(l);
- this.visit_expr(r, ());
+ ExprAssign(ref l, ref r) => {
+ this.check_lvalue(&**l);
+ this.visit_expr(&**r, ());
visit::walk_expr(this, expr, ());
}
- ExprAssignOp(_, l, _) => {
- this.check_lvalue(l);
+ ExprAssignOp(_, ref l, _) => {
+ this.check_lvalue(&**l);
visit::walk_expr(this, expr, ());
}
ExprInlineAsm(ref ia) => {
- for &(_, input) in ia.inputs.iter() {
- this.visit_expr(input, ());
+ for &(_, ref input) in ia.inputs.iter() {
+ this.visit_expr(&**input, ());
}
// Output operands must be lvalues
- for &(_, out) in ia.outputs.iter() {
- this.check_lvalue(out);
- this.visit_expr(out, ());
+ for &(_, ref out) in ia.outputs.iter() {
+ this.check_lvalue(&**out);
+ this.visit_expr(&**out, ());
}
visit::walk_expr(this, expr, ());
let ends_with_stmt = match body.expr {
None if body.stmts.len() > 0 =>
match body.stmts.last().unwrap().node {
- StmtSemi(e, _) => {
- let t_stmt = ty::expr_ty(self.ir.tcx, e);
+ StmtSemi(ref e, _) => {
+ let t_stmt = ty::expr_ty(self.ir.tcx, &**e);
ty::get(t_stmt).sty == ty::get(t_ret).sty
},
_ => false
fn warn_about_unused_args(&self, decl: &FnDecl, entry_ln: LiveNode) {
for arg in decl.inputs.iter() {
pat_util::pat_bindings(&self.ir.tcx.def_map,
- arg.pat,
+ &*arg.pat,
|_bm, p_id, sp, path| {
let var = self.variable(p_id, sp);
// Ignore unused self.
let expr_ty = if_ok!(self.expr_ty(expr));
match expr.node {
- ast::ExprUnary(ast::UnDeref, e_base) => {
- let base_cmt = if_ok!(self.cat_expr(e_base));
+ ast::ExprUnary(ast::UnDeref, ref e_base) => {
+ let base_cmt = if_ok!(self.cat_expr(&**e_base));
Ok(self.cat_deref(expr, base_cmt, 0))
}
- ast::ExprField(base, f_name, _) => {
- let base_cmt = if_ok!(self.cat_expr(base));
+ ast::ExprField(ref base, f_name, _) => {
+ let base_cmt = if_ok!(self.cat_expr(&**base));
Ok(self.cat_field(expr, base_cmt, f_name, expr_ty))
}
- ast::ExprIndex(base, _) => {
+ ast::ExprIndex(ref base, _) => {
if self.typer.is_method_call(expr.id) {
return Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty));
}
- let base_cmt = if_ok!(self.cat_expr(base));
+ let base_cmt = if_ok!(self.cat_expr(&**base));
Ok(self.cat_index(expr, base_cmt, 0))
}
self.cat_def(expr.id, expr.span, expr_ty, def)
}
- ast::ExprParen(e) => {
- self.cat_expr(e)
+ ast::ExprParen(ref e) => {
+ self.cat_expr(&**e)
}
ast::ExprAddrOf(..) | ast::ExprCall(..) |
}
};
- for (i, &subpat) in subpats.iter().enumerate() {
- let subpat_ty = if_ok!(self.pat_ty(subpat)); // see (*2)
+ for (i, subpat) in subpats.iter().enumerate() {
+ let subpat_ty = if_ok!(self.pat_ty(&**subpat)); // see (*2)
let subcmt =
self.cat_imm_interior(
pat, downcast_cmt.clone(), subpat_ty,
InteriorField(PositionalField(i)));
- if_ok!(self.cat_pattern(subcmt, subpat, |x,y,z| op(x,y,z)));
+ if_ok!(self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z)));
}
}
Some(&def::DefFn(..)) |
Some(&def::DefStruct(..)) => {
- for (i, &subpat) in subpats.iter().enumerate() {
- let subpat_ty = if_ok!(self.pat_ty(subpat)); // see (*2)
+ for (i, subpat) in subpats.iter().enumerate() {
+ let subpat_ty = if_ok!(self.pat_ty(&**subpat)); // see (*2)
let cmt_field =
self.cat_imm_interior(
pat, cmt.clone(), subpat_ty,
InteriorField(PositionalField(i)));
- if_ok!(self.cat_pattern(cmt_field, subpat, |x,y,z| op(x,y,z)));
+ if_ok!(self.cat_pattern(cmt_field, &**subpat,
+ |x,y,z| op(x,y,z)));
}
}
Some(&def::DefStatic(..)) => {
- for &subpat in subpats.iter() {
- if_ok!(self.cat_pattern(cmt.clone(), subpat, |x,y,z| op(x,y,z)));
+ for subpat in subpats.iter() {
+ if_ok!(self.cat_pattern(cmt.clone(), &**subpat, |x,y,z| op(x,y,z)));
}
}
_ => {
}
}
- ast::PatIdent(_, _, Some(subpat)) => {
- if_ok!(self.cat_pattern(cmt, subpat, op));
+ ast::PatIdent(_, _, Some(ref subpat)) => {
+ if_ok!(self.cat_pattern(cmt, &**subpat, op));
}
ast::PatIdent(_, _, None) => {
ast::PatStruct(_, ref field_pats, _) => {
// {f1: p1, ..., fN: pN}
for fp in field_pats.iter() {
- let field_ty = if_ok!(self.pat_ty(fp.pat)); // see (*2)
+ let field_ty = if_ok!(self.pat_ty(&*fp.pat)); // see (*2)
let cmt_field = self.cat_field(pat, cmt.clone(), fp.ident, field_ty);
- if_ok!(self.cat_pattern(cmt_field, fp.pat, |x,y,z| op(x,y,z)));
+ if_ok!(self.cat_pattern(cmt_field, &*fp.pat, |x,y,z| op(x,y,z)));
}
}
ast::PatTup(ref subpats) => {
// (p1, ..., pN)
- for (i, &subpat) in subpats.iter().enumerate() {
- let subpat_ty = if_ok!(self.pat_ty(subpat)); // see (*2)
+ for (i, subpat) in subpats.iter().enumerate() {
+ let subpat_ty = if_ok!(self.pat_ty(&**subpat)); // see (*2)
let subcmt =
self.cat_imm_interior(
pat, cmt.clone(), subpat_ty,
InteriorField(PositionalField(i)));
- if_ok!(self.cat_pattern(subcmt, subpat, |x,y,z| op(x,y,z)));
+ if_ok!(self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z)));
}
}
- ast::PatBox(subpat) | ast::PatRegion(subpat) => {
+ ast::PatBox(ref subpat) | ast::PatRegion(ref subpat) => {
// @p1, ~p1
let subcmt = self.cat_deref(pat, cmt, 0);
- if_ok!(self.cat_pattern(subcmt, subpat, op));
+ if_ok!(self.cat_pattern(subcmt, &**subpat, op));
}
ast::PatVec(ref before, slice, ref after) => {
let elt_cmt = self.cat_index(pat, cmt, 0);
- for &before_pat in before.iter() {
- if_ok!(self.cat_pattern(elt_cmt.clone(), before_pat, |x,y,z| op(x,y,z)));
+ for before_pat in before.iter() {
+ if_ok!(self.cat_pattern(elt_cmt.clone(), &**before_pat,
+ |x,y,z| op(x,y,z)));
}
- for &slice_pat in slice.iter() {
- let slice_ty = if_ok!(self.pat_ty(slice_pat));
+ for slice_pat in slice.iter() {
+ let slice_ty = if_ok!(self.pat_ty(&**slice_pat));
let slice_cmt = self.cat_rvalue_node(pat.id(), pat.span(), slice_ty);
- if_ok!(self.cat_pattern(slice_cmt, slice_pat, |x,y,z| op(x,y,z)));
+ if_ok!(self.cat_pattern(slice_cmt, &**slice_pat, |x,y,z| op(x,y,z)));
}
- for &after_pat in after.iter() {
- if_ok!(self.cat_pattern(elt_cmt.clone(), after_pat, |x,y,z| op(x,y,z)));
+ for after_pat in after.iter() {
+ if_ok!(self.cat_pattern(elt_cmt.clone(), &**after_pat, |x,y,z| op(x,y,z)));
}
}
//! outside their scopes. This pass will also generate a set of exported items
//! which are available for use externally when compiled as a library.
+use std::gc::Gc;
use std::mem::replace;
use metadata::csearch;
fn visit_expr(&mut self, expr: &ast::Expr, _: ()) {
match expr.node {
- ast::ExprField(base, ident, _) => {
- match ty::get(ty::expr_ty_adjusted(self.tcx, base)).sty {
+ ast::ExprField(ref base, ident, _) => {
+ match ty::get(ty::expr_ty_adjusted(self.tcx, &**base)).sty {
ty::ty_struct(id, _) => {
self.check_field(expr.span, id, NamedField(ident));
}
tcx.sess.span_err(sp, "visibility has no effect inside functions");
}
}
- let check_struct = |def: &@ast::StructDef| {
+ let check_struct = |def: &Gc<ast::StructDef>| {
for f in def.fields.iter() {
match f.node.kind {
ast::NamedField(_, p) => check_inherited(tcx, f.span, p),
at_outer_type: true,
outer_type_is_public_path: false,
};
- visitor.visit_ty(self_, ());
+ visitor.visit_ty(&*self_, ());
self_contains_private = visitor.contains_private;
self_is_public_path = visitor.outer_type_is_public_path;
}
match *trait_ref {
None => {
for method in methods.iter() {
- visit::walk_method_helper(self, *method, ())
+ visit::walk_method_helper(self, &**method, ())
}
}
Some(ref tr) => {
if method.explicit_self.node == ast::SelfStatic &&
self.exported_items.contains(&method.id) {
found_pub_static = true;
- visit::walk_method_helper(self, *method, ());
+ visit::walk_method_helper(self, &**method, ());
}
}
if found_pub_static {
{
match tcx.map.find(impl_src.node) {
Some(ast_map::NodeItem(item)) => {
- item_might_be_inlined(item)
+ item_might_be_inlined(&*item)
}
Some(..) | None => {
tcx.sess.span_bug(method.span, "impl did is not an item")
match self.tcx.map.find(node_id) {
Some(ast_map::NodeItem(item)) => {
match item.node {
- ast::ItemFn(..) => item_might_be_inlined(item),
+ ast::ItemFn(..) => item_might_be_inlined(&*item),
_ => false,
}
}
match *node {
ast_map::NodeItem(item) => {
match item.node {
- ast::ItemFn(_, _, _, _, search_block) => {
- if item_might_be_inlined(item) {
- visit::walk_block(self, search_block, ())
+ ast::ItemFn(_, _, _, _, ref search_block) => {
+ if item_might_be_inlined(&*item) {
+ visit::walk_block(self, &**search_block, ())
}
}
// Statics with insignificant addresses are not reachable
// because they're inlined specially into all other crates.
- ast::ItemStatic(_, _, init) => {
+ ast::ItemStatic(_, _, ref init) => {
if attr::contains_name(item.attrs.as_slice(),
"address_insignificant") {
self.reachable_symbols.remove(&search_item);
}
- visit::walk_expr(self, init, ());
+ visit::walk_expr(self, &**init, ());
}
// These are normal, nothing reachable about these
// Keep going, nothing to get exported
}
ast::Provided(ref method) => {
- visit::walk_block(self, method.body, ())
+ visit::walk_block(self, &*method.body, ())
}
}
}
ast_map::NodeMethod(method) => {
let did = self.tcx.map.get_parent_did(search_item);
- if method_might_be_inlined(self.tcx, method, did) {
- visit::walk_block(self, method.body, ())
+ if method_might_be_inlined(self.tcx, &*method, did) {
+ visit::walk_block(self, &*method.body, ())
}
}
// Nothing to recurse on for these
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
+use std::gc::Gc;
use syntax::codemap::Span;
use syntax::{ast, visit};
use syntax::visit::{Visitor, FnKind};
// FIXME(#6308) -- Note that `[]` patterns work more smoothly post-DST.
match local.init {
- Some(expr) => {
- record_rvalue_scope_if_borrow_expr(visitor, expr, blk_id);
+ Some(ref expr) => {
+ record_rvalue_scope_if_borrow_expr(visitor, &**expr, blk_id);
- if is_binding_pat(local.pat) || is_borrowed_ty(local.ty) {
- record_rvalue_scope(visitor, expr, blk_id);
+ if is_binding_pat(&*local.pat) || is_borrowed_ty(&*local.ty) {
+ record_rvalue_scope(visitor, &**expr, blk_id);
}
}
ast::PatIdent(ast::BindByRef(_), _, _) => true,
ast::PatStruct(_, ref field_pats, _) => {
- field_pats.iter().any(|fp| is_binding_pat(fp.pat))
+ field_pats.iter().any(|fp| is_binding_pat(&*fp.pat))
}
ast::PatVec(ref pats1, ref pats2, ref pats3) => {
- pats1.iter().any(|&p| is_binding_pat(p)) ||
- pats2.iter().any(|&p| is_binding_pat(p)) ||
- pats3.iter().any(|&p| is_binding_pat(p))
+ pats1.iter().any(|p| is_binding_pat(&**p)) ||
+ pats2.iter().any(|p| is_binding_pat(&**p)) ||
+ pats3.iter().any(|p| is_binding_pat(&**p))
}
ast::PatEnum(_, Some(ref subpats)) |
ast::PatTup(ref subpats) => {
- subpats.iter().any(|&p| is_binding_pat(p))
+ subpats.iter().any(|p| is_binding_pat(&**p))
}
- ast::PatBox(subpat) => {
- is_binding_pat(subpat)
+ ast::PatBox(ref subpat) => {
+ is_binding_pat(&**subpat)
}
_ => false,
*/
match expr.node {
- ast::ExprAddrOf(_, subexpr) => {
- record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
- record_rvalue_scope(visitor, subexpr, blk_id);
+ ast::ExprAddrOf(_, ref subexpr) => {
+ record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id);
+ record_rvalue_scope(visitor, &**subexpr, blk_id);
}
ast::ExprStruct(_, ref fields, _) => {
for field in fields.iter() {
record_rvalue_scope_if_borrow_expr(
- visitor, field.expr, blk_id);
+ visitor, &*field.expr, blk_id);
}
}
- ast::ExprVstore(subexpr, _) => {
+ ast::ExprVstore(ref subexpr, _) => {
visitor.region_maps.record_rvalue_scope(subexpr.id, blk_id);
- record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
+ record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id);
}
ast::ExprVec(ref subexprs) |
ast::ExprTup(ref subexprs) => {
- for &subexpr in subexprs.iter() {
+ for subexpr in subexprs.iter() {
record_rvalue_scope_if_borrow_expr(
- visitor, subexpr, blk_id);
+ visitor, &**subexpr, blk_id);
}
}
- ast::ExprUnary(ast::UnUniq, subexpr) => {
- record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
+ ast::ExprUnary(ast::UnUniq, ref subexpr) => {
+ record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id);
}
- ast::ExprCast(subexpr, _) |
- ast::ExprParen(subexpr) => {
- record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id)
+ ast::ExprCast(ref subexpr, _) |
+ ast::ExprParen(ref subexpr) => {
+ record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id)
}
ast::ExprBlock(ref block) => {
match block.expr {
- Some(subexpr) => {
+ Some(ref subexpr) => {
record_rvalue_scope_if_borrow_expr(
- visitor, subexpr, blk_id);
+ visitor, &**subexpr, blk_id);
}
None => { }
}
ast::ExprField(ref subexpr, _, _) |
ast::ExprIndex(ref subexpr, _) |
ast::ExprParen(ref subexpr) => {
- let subexpr: &'a @Expr = subexpr; // FIXME(#11586)
+ let subexpr: &'a Gc<Expr> = subexpr; // FIXME(#11586)
expr = &**subexpr;
}
_ => {
use std::collections::{HashMap, HashSet};
use std::cell::{Cell, RefCell};
+use std::gc::Gc;
use std::mem::replace;
use std::rc::{Rc, Weak};
-use std::string::String;
use std::uint;
// Definition mapping
name_bindings.define_type
(DefTy(local_def(item.id)), sp, is_public);
- for &variant in (*enum_definition).variants.iter() {
+ for variant in (*enum_definition).variants.iter() {
self.build_reduced_graph_for_variant(
- variant,
+ &**variant,
local_def(item.id),
parent.clone(),
is_public);
FunctionRibKind(function_id, body_id) => {
if !is_ty_param {
def = DefUpvar(def.def_id().node,
- @def,
+ box(GC) def,
function_id,
body_id);
}
// resolve the discriminator expr
// as a constant
self.with_constant_rib(|this| {
- this.resolve_expr(*dis_expr);
+ this.resolve_expr(&**dis_expr);
});
}
}
}
ItemImpl(ref generics,
- ref implemented_traits,
- self_type,
- ref methods) => {
+ ref implemented_traits,
+ ref self_type,
+ ref methods) => {
self.resolve_implementation(item.id,
generics,
implemented_traits,
- self_type,
+ &**self_type,
methods.as_slice());
}
&ty_m.generics.ty_params);
for argument in ty_m.decl.inputs.iter() {
- this.resolve_type(argument.ty);
+ this.resolve_type(&*argument.ty);
}
- this.resolve_type(ty_m.decl.output);
+ this.resolve_type(&*ty_m.decl.output);
});
}
- ast::Provided(m) => {
+ ast::Provided(ref m) => {
this.resolve_method(MethodRibKind(item.id,
Provided(m.id)),
- m,
+ &**m,
generics.ty_params.len())
}
}
generics, foreign_item.id, 0,
ItemRibKind),
|this| visit::walk_foreign_item(this,
- *foreign_item,
+ &**foreign_item,
()));
}
ForeignItemStatic(..) => {
visit::walk_foreign_item(this,
- *foreign_item,
+ &**foreign_item,
());
}
}
}
Some(declaration) => {
for argument in declaration.inputs.iter() {
- this.resolve_pattern(argument.pat,
+ this.resolve_pattern(&*argument.pat,
ArgumentIrrefutableMode,
None);
- this.resolve_type(argument.ty);
+ this.resolve_type(&*argument.ty);
debug!("(resolving function) recorded argument");
}
- this.resolve_type(declaration.output);
+ this.resolve_type(&*declaration.output);
}
}
// Resolve the function body.
- this.resolve_block(block);
+ this.resolve_block(&*block);
debug!("(resolving function) leaving function");
});
self.resolve_type_parameter_bound(type_parameter.id, bound);
}
match type_parameter.default {
- Some(ty) => self.resolve_type(ty),
+ Some(ref ty) => self.resolve_type(&**ty),
None => {}
}
}
}
UnboxedFnTyParamBound(ref unboxed_function) => {
for argument in unboxed_function.decl.inputs.iter() {
- self.resolve_type(argument.ty);
+ self.resolve_type(&*argument.ty);
}
- self.resolve_type(unboxed_function.decl.output);
+ self.resolve_type(&*unboxed_function.decl.output);
}
StaticRegionTyParamBound | OtherRegionTyParamBound(_) => {}
}
// Resolve fields.
for field in fields.iter() {
- this.resolve_type(field.node.ty);
+ this.resolve_type(&*field.node.ty);
}
});
}
generics: &Generics,
opt_trait_reference: &Option<TraitRef>,
self_type: &Ty,
- methods: &[@Method]) {
+ methods: &[Gc<Method>]) {
// If applicable, create a rib for the type parameters.
let outer_type_parameter_count = generics.ty_params.len();
self.with_type_parameter_rib(HasTypeParameters(generics,
for method in methods.iter() {
// We also need a new scope for the method-specific type parameters.
this.resolve_method(MethodRibKind(id, Provided(method.id)),
- *method,
+ &**method,
outer_type_parameter_count);
}
});
fn resolve_local(&mut self, local: &Local) {
// Resolve the type.
- self.resolve_type(local.ty);
+ self.resolve_type(&*local.ty);
// Resolve the initializer, if necessary.
match local.init {
None => {
// Nothing to do.
}
- Some(initializer) => {
- self.resolve_expr(initializer);
+ Some(ref initializer) => {
+ self.resolve_expr(&**initializer);
}
}
// Resolve the pattern.
- self.resolve_pattern(local.pat, LocalIrrefutableMode, None);
+ self.resolve_pattern(&*local.pat, LocalIrrefutableMode, None);
}
// build a map from pattern identifiers to binding-info's.
if arm.pats.len() == 0 {
return
}
- let map_0 = self.binding_mode_map(*arm.pats.get(0));
+ let map_0 = self.binding_mode_map(&**arm.pats.get(0));
for (i, p) in arm.pats.iter().enumerate() {
- let map_i = self.binding_mode_map(*p);
+ let map_i = self.binding_mode_map(&**p);
for (&key, &binding_0) in map_0.iter() {
match map_i.find(&key) {
let mut bindings_list = HashMap::new();
for pattern in arm.pats.iter() {
- self.resolve_pattern(*pattern,
+ self.resolve_pattern(&**pattern,
RefutableMode,
Some(&mut bindings_list));
}
self.check_consistent_bindings(arm);
visit::walk_expr_opt(self, arm.guard, ());
- self.resolve_expr(arm.body);
+ self.resolve_expr(&*arm.body);
self.value_ribs.borrow_mut().pop();
}
}
// Check the types in the path pattern.
- for &ty in path.segments
+ for ty in path.segments
.iter()
.flat_map(|seg| seg.types.iter()) {
- self.resolve_type(ty);
+ self.resolve_type(&**ty);
}
}
}
// Check the types in the path pattern.
- for &ty in path.segments
+ for ty in path.segments
.iter()
.flat_map(|s| s.types.iter()) {
- self.resolve_type(ty);
+ self.resolve_type(&**ty);
}
}
}
// Check the types in the path pattern.
- for &ty in path.segments
+ for ty in path.segments
.iter()
.flat_map(|s| s.types.iter()) {
- self.resolve_type(ty);
+ self.resolve_type(&**ty);
}
}
- PatLit(expr) => {
- self.resolve_expr(expr);
+ PatLit(ref expr) => {
+ self.resolve_expr(&**expr);
}
- PatRange(first_expr, last_expr) => {
- self.resolve_expr(first_expr);
- self.resolve_expr(last_expr);
+ PatRange(ref first_expr, ref last_expr) => {
+ self.resolve_expr(&**first_expr);
+ self.resolve_expr(&**last_expr);
}
PatStruct(ref path, _, _) => {
namespace: Namespace,
check_ribs: bool) -> Option<(Def, LastPrivate)> {
// First, resolve the types.
- for &ty in path.segments.iter().flat_map(|s| s.types.iter()) {
- self.resolve_type(ty);
+ for ty in path.segments.iter().flat_map(|s| s.types.iter()) {
+ self.resolve_type(&**ty);
}
if path.global {
-> Option<(Path, NodeId, FallbackChecks)> {
match t.node {
TyPath(ref path, _, node_id) => Some((path.clone(), node_id, allow)),
- TyPtr(mut_ty) => extract_path_and_node_id(mut_ty.ty, OnlyTraitAndStatics),
- TyRptr(_, mut_ty) => extract_path_and_node_id(mut_ty.ty, allow),
+ TyPtr(mut_ty) => extract_path_and_node_id(&*mut_ty.ty, OnlyTraitAndStatics),
+ TyRptr(_, mut_ty) => extract_path_and_node_id(&*mut_ty.ty, allow),
// This doesn't handle the remaining `Ty` variants as they are not
// that commonly the self_type, it might be interesting to provide
// support for those in future.
use std::collections::HashMap;
use std::cell::Cell;
use std::rc::Rc;
+use std::gc::Gc;
use syntax::ast;
use syntax::ast::Ident;
use syntax::ast_util::path_to_ident;
// expression.
enum Lit {
UnitLikeStructLit(ast::NodeId), // the node ID of the pattern
- ExprLit(@ast::Expr),
+ ExprLit(Gc<ast::Expr>),
ConstLit(ast::DefId), // the def ID of the constant
}
enum Opt {
lit(Lit),
var(ty::Disr, Rc<adt::Repr>),
- range(@ast::Expr, @ast::Expr),
+ range(Gc<ast::Expr>, Gc<ast::Expr>),
vec_len(/* length */ uint, VecLenOpt, /*range of matches*/(uint, uint))
}
-fn lit_to_expr(tcx: &ty::ctxt, a: &Lit) -> @ast::Expr {
+fn lit_to_expr(tcx: &ty::ctxt, a: &Lit) -> Gc<ast::Expr> {
match *a {
ExprLit(existing_a_expr) => existing_a_expr,
ConstLit(a_const) => const_eval::lookup_const_by_id(tcx, a_const).unwrap(),
(&lit(a), &lit(b)) => {
let a_expr = lit_to_expr(tcx, &a);
let b_expr = lit_to_expr(tcx, &b);
- match const_eval::compare_lit_exprs(tcx, a_expr, b_expr) {
+ match const_eval::compare_lit_exprs(tcx, &*a_expr, &*b_expr) {
Some(val1) => val1 == 0,
None => fail!("compare_list_exprs: type mismatch"),
}
}
- (&range(a1, a2), &range(b1, b2)) => {
- let m1 = const_eval::compare_lit_exprs(tcx, a1, b1);
- let m2 = const_eval::compare_lit_exprs(tcx, a2, b2);
+ (&range(ref a1, ref a2), &range(ref b1, ref b2)) => {
+ let m1 = const_eval::compare_lit_exprs(tcx, &**a1, &**b1);
+ let m2 = const_eval::compare_lit_exprs(tcx, &**a2, &**b2);
match (m1, m2) {
(Some(val1), Some(val2)) => (val1 == 0 && val2 == 0),
_ => fail!("compare_list_exprs: type mismatch"),
let ccx = bcx.ccx();
let mut bcx = bcx;
match *o {
- lit(ExprLit(lit_expr)) => {
- let lit_datum = unpack_datum!(bcx, expr::trans(bcx, lit_expr));
+ lit(ExprLit(ref lit_expr)) => {
+ let lit_datum = unpack_datum!(bcx, expr::trans(bcx, &**lit_expr));
let lit_datum = lit_datum.assert_rvalue(bcx); // literals are rvalues
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
return single_result(Result::new(bcx, lit_datum.val));
var(disr_val, ref repr) => {
return adt::trans_case(bcx, &**repr, disr_val);
}
- range(l1, l2) => {
- let (l1, _) = consts::const_expr(ccx, l1, true);
- let (l2, _) = consts::const_expr(ccx, l2, true);
+ range(ref l1, ref l2) => {
+ let (l1, _) = consts::const_expr(ccx, &**l1, true);
+ let (l2, _) = consts::const_expr(ccx, &**l2, true);
return range_result(Result::new(bcx, l1), Result::new(bcx, l2));
}
vec_len(n, vec_len_eq, _) => {
* these pointers are stored in llmatch variables just before executing `data` arm.
*/
struct Match<'a, 'b> {
- pats: Vec<@ast::Pat>,
+ pats: Vec<Gc<ast::Pat>>,
data: &'a ArmData<'a, 'b>,
bound_ptrs: Vec<(Ident, ValueRef)>
}
}).collect()
}
-fn assert_is_binding_or_wild(bcx: &Block, p: @ast::Pat) {
- if !pat_is_binding_or_wild(&bcx.tcx().def_map, p) {
+fn assert_is_binding_or_wild(bcx: &Block, p: Gc<ast::Pat>) {
+ if !pat_is_binding_or_wild(&bcx.tcx().def_map, &*p) {
bcx.sess().span_bug(
p.span,
format!("expected an identifier pattern but found p: {}",
}
}
-type enter_pat<'a> = |@ast::Pat|: 'a -> Option<Vec<@ast::Pat>>;
+type enter_pat<'a> = |Gc<ast::Pat>|: 'a -> Option<Vec<Gc<ast::Pat>>>;
fn enter_match<'a, 'b>(
bcx: &'b Block<'b>,
let mut bound_ptrs = br.bound_ptrs.clone();
match this.node {
ast::PatIdent(_, ref path, None) => {
- if pat_is_binding(dm, this) {
+ if pat_is_binding(dm, &*this) {
bound_ptrs.push((path_to_ident(path), val));
}
}
let matches = enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatWild | ast::PatWildMulti => Some(Vec::new()),
- ast::PatIdent(_, _, None) if pat_is_binding(dm, p) => Some(Vec::new()),
+ ast::PatIdent(_, _, None) if pat_is_binding(dm, &*p) => Some(Vec::new()),
_ => None
}
});
let _indenter = indenter();
let tcx = bcx.tcx();
- let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
+ let dummy = box(GC) ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
let mut i = 0;
enter_match(bcx, &tcx.def_map, m, col, val, |p| {
let answer = match p.node {
ast::PatEnum(..) |
- ast::PatIdent(_, _, None) if pat_is_const(&tcx.def_map, p) => {
+ ast::PatIdent(_, _, None) if pat_is_const(&tcx.def_map, &*p) => {
let const_def = tcx.def_map.borrow().get_copy(&p.id);
let const_def_id = const_def.def_id();
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
}
}
ast::PatIdent(_, _, None)
- if pat_is_variant_or_struct(&tcx.def_map, p) => {
+ if pat_is_variant_or_struct(&tcx.def_map, &*p) => {
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
Some(Vec::new())
} else {
bcx.val_to_str(val));
let _indenter = indenter();
- let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
+ let dummy = box(GC) ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatStruct(_, ref fpats, _) => {
bcx.val_to_str(val));
let _indenter = indenter();
- let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
+ let dummy = box(GC) ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatTup(ref elts) => {
bcx.val_to_str(val));
let _indenter = indenter();
- let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
+ let dummy = box(GC) ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatEnum(_, Some(ref elts)) => {
bcx.val_to_str(val));
let _indenter = indenter();
- let dummy = @ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
+ let dummy = box(GC) ast::Pat {id: 0, node: ast::PatWild, span: DUMMY_SP};
enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatBox(sub) => {
bcx.val_to_str(val));
let _indenter = indenter();
- let dummy = @ast::Pat { id: 0, node: ast::PatWild, span: DUMMY_SP };
+ let dummy = box(GC) ast::Pat { id: 0, node: ast::PatWild, span: DUMMY_SP };
enter_match(bcx, dm, m, col, val, |p| {
match p.node {
ast::PatRegion(sub) => {
fn score(p: &ast::Pat) -> uint {
match p.node {
ast::PatLit(_) | ast::PatEnum(_, _) | ast::PatRange(_, _) => 1u,
- ast::PatIdent(_, _, Some(p)) => score(p),
+ ast::PatIdent(_, _, Some(ref p)) => score(&**p),
_ => 0u
}
}
let mut scores = Vec::from_elem(m[0].pats.len(), 0u);
for br in m.iter() {
- for (i, p) in br.pats.iter().enumerate() {
- *scores.get_mut(i) += score(*p);
+ for (i, ref p) in br.pats.iter().enumerate() {
+ *scores.get_mut(i) += score(&***p);
}
}
let mut max_score = 0u;
Store(bcx, *value_ptr, llmatch);
}
match data.arm.guard {
- Some(guard_expr) => {
+ Some(ref guard_expr) => {
bcx = compile_guard(bcx,
- guard_expr,
+ &**guard_expr,
m[0].data,
m.slice(1, m.len()),
vals,
trans_match_inner(bcx, match_expr.id, discr_expr, arms, dest)
}
-fn create_bindings_map(bcx: &Block, pat: @ast::Pat) -> BindingsMap {
+fn create_bindings_map(bcx: &Block, pat: Gc<ast::Pat>) -> BindingsMap {
// Create the bindings map, which is a mapping from each binding name
// to an alloca() that will be the value for that local variable.
// Note that we use the names because each binding will have many ids
let ccx = bcx.ccx();
let tcx = bcx.tcx();
let mut bindings_map = HashMap::new();
- pat_bindings(&tcx.def_map, pat, |bm, p_id, span, path| {
+ pat_bindings(&tcx.def_map, &*pat, |bm, p_id, span, path| {
let ident = path_to_ident(path);
let variable_ty = node_id_type(bcx, p_id);
let llvariable_ty = type_of::type_of(ccx, variable_ty);
let cleanup_scope = fcx.push_custom_cleanup_scope();
bcx = insert_lllocals(bcx, &arm_data.bindings_map,
cleanup::CustomScope(cleanup_scope));
- bcx = expr::trans_into(bcx, arm_data.arm.body, dest);
+ bcx = expr::trans_into(bcx, &*arm_data.arm.body, dest);
bcx = fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
arm_cxs.push(bcx);
}
//
// In such cases, the more general path is unsafe, because
// it assumes it is matching against a valid value.
- match simple_identifier(pat) {
+ match simple_identifier(&*pat) {
Some(path) => {
let var_scope = cleanup::var_scope(tcx, local.id);
return mk_binding_alloca(
bcx, pat.id, path, BindLocal, var_scope, (),
- |(), bcx, v, _| expr::trans_into(bcx, init_expr,
+ |(), bcx, v, _| expr::trans_into(bcx, &*init_expr,
expr::SaveIn(v)));
}
// General path.
let init_datum =
- unpack_datum!(bcx, expr::trans_to_lvalue(bcx, init_expr, "let"));
- if ty::type_is_bot(expr_ty(bcx, init_expr)) {
+ unpack_datum!(bcx, expr::trans_to_lvalue(bcx, &*init_expr, "let"));
+ if ty::type_is_bot(expr_ty(bcx, &*init_expr)) {
create_dummy_locals(bcx, pat)
} else {
if bcx.sess().asm_comments() {
};
fn create_dummy_locals<'a>(mut bcx: &'a Block<'a>,
- pat: @ast::Pat)
+ pat: Gc<ast::Pat>)
-> &'a Block<'a> {
// create dummy memory for the variables if we have no
// value to store into them immediately
let tcx = bcx.tcx();
- pat_bindings(&tcx.def_map, pat, |_, p_id, _, path| {
+ pat_bindings(&tcx.def_map, &*pat, |_, p_id, _, path| {
let scope = cleanup::var_scope(tcx, p_id);
bcx = mk_binding_alloca(
bcx, p_id, path, BindLocal, scope, (),
}
pub fn store_arg<'a>(mut bcx: &'a Block<'a>,
- pat: @ast::Pat,
+ pat: Gc<ast::Pat>,
arg: Datum<Rvalue>,
arg_scope: cleanup::ScopeId)
-> &'a Block<'a> {
let _icx = push_ctxt("match::store_arg");
- match simple_identifier(pat) {
+ match simple_identifier(&*pat) {
Some(path) => {
// Generate nicer LLVM for the common case of fn a pattern
// like `x: T`
fn bind_irrefutable_pat<'a>(
bcx: &'a Block<'a>,
- pat: @ast::Pat,
+ pat: Gc<ast::Pat>,
val: ValueRef,
binding_mode: IrrefutablePatternBindingMode,
cleanup_scope: cleanup::ScopeId)
let ccx = bcx.ccx();
match pat.node {
ast::PatIdent(pat_binding_mode, ref path, inner) => {
- if pat_is_binding(&tcx.def_map, pat) {
+ if pat_is_binding(&tcx.def_map, &*pat) {
// Allocate the stack slot where the value of this
// binding will live and place it into the appropriate
// map.
let temp_scope = fcx.push_custom_cleanup_scope();
// Prepare the output operands
- let outputs = ia.outputs.iter().map(|&(ref c, out)| {
+ let outputs = ia.outputs.iter().map(|&(ref c, ref out)| {
constraints.push((*c).clone());
- let out_datum = unpack_datum!(bcx, expr::trans(bcx, out));
+ let out_datum = unpack_datum!(bcx, expr::trans(bcx, &**out));
output_types.push(type_of::type_of(bcx.ccx(), out_datum.ty));
out_datum.val
}).collect::<Vec<_>>();
// Now the input operands
- let inputs = ia.inputs.iter().map(|&(ref c, input)| {
+ let inputs = ia.inputs.iter().map(|&(ref c, ref input)| {
constraints.push((*c).clone());
- let in_datum = unpack_datum!(bcx, expr::trans(bcx, input));
+ let in_datum = unpack_datum!(bcx, expr::trans(bcx, &**input));
unpack_result!(bcx, {
callee::trans_arg_datum(bcx,
- expr_ty(bcx, input),
+ expr_ty(bcx, &**input),
in_datum,
cleanup::CustomScope(temp_scope),
callee::DontAutorefArg)
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::{i8, i16, i32, i64};
+use std::gc::Gc;
use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic};
use syntax::ast_util::{local_def, is_local};
use syntax::attr::AttrMetaMethods;
if ignore_lhs(bcx, local) {
// Handle let _ = e; just like e;
match local.init {
- Some(init) => {
- return controlflow::trans_stmt_semi(bcx, init)
+ Some(ref init) => {
+ return controlflow::trans_stmt_semi(bcx, &**init)
}
None => { return bcx; }
}
fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
sp: Span, id: ast::NodeId, vi: &[Rc<ty::VariantInfo>],
i: &mut uint) {
- for &variant in enum_definition.variants.iter() {
+ for variant in enum_definition.variants.iter() {
let disr_val = vi[*i].disr_val;
*i += 1;
match variant.node.kind {
ast::TupleVariantKind(ref args) if args.len() > 0 => {
let llfn = get_item_val(ccx, variant.node.id);
- trans_enum_variant(ccx, id, variant, args.as_slice(),
+ trans_enum_variant(ccx, id, &**variant, args.as_slice(),
disr_val, ¶m_substs::empty(), llfn);
}
ast::TupleVariantKind(_) => {
pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item");
match item.node {
- ast::ItemFn(decl, _fn_style, abi, ref generics, body) => {
+ ast::ItemFn(ref decl, _fn_style, abi, ref generics, ref body) => {
if abi != Rust {
let llfndecl = get_item_val(ccx, item.id);
foreign::trans_rust_fn_with_foreign_abi(
- ccx, decl, body, item.attrs.as_slice(), llfndecl, item.id);
+ ccx, &**decl, &**body, item.attrs.as_slice(), llfndecl, item.id);
} else if !generics.is_type_parameterized() {
let llfn = get_item_val(ccx, item.id);
trans_fn(ccx,
- decl,
- body,
+ &**decl,
+ &**body,
llfn,
¶m_substs::empty(),
item.id,
// Be sure to travel more than just one layer deep to catch nested
// items in blocks and such.
let mut v = TransItemVisitor{ ccx: ccx };
- v.visit_block(body, ());
+ v.visit_block(&**body, ());
}
}
ast::ItemImpl(ref generics, _, _, ref ms) => {
trans_enum_def(ccx, enum_definition, item.span, item.id, vi.as_slice(), &mut i);
}
}
- ast::ItemStatic(_, m, expr) => {
+ ast::ItemStatic(_, m, ref expr) => {
// Recurse on the expression to catch items in blocks
let mut v = TransItemVisitor{ ccx: ccx };
- v.visit_expr(expr, ());
+ v.visit_expr(&**expr, ());
consts::trans_const(ccx, m, item.id);
// Do static_assert checking. It can't really be done much earlier
// because we need to get the value of the bool out of LLVM
}
}
-pub fn trans_struct_def(ccx: &CrateContext, struct_def: @ast::StructDef) {
+pub fn trans_struct_def(ccx: &CrateContext, struct_def: Gc<ast::StructDef>) {
// If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id {
// We only need to translate a constructor if there are fields;
pub fn trans_mod(ccx: &CrateContext, m: &ast::Mod) {
let _icx = push_ctxt("trans_mod");
for item in m.items.iter() {
- trans_item(ccx, *item);
+ trans_item(ccx, &**item);
}
}
let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
let v = match i.node {
- ast::ItemStatic(_, _, expr) => {
+ ast::ItemStatic(_, _, ref expr) => {
// If this static came from an external crate, then
// we need to get the symbol from csearch instead of
// using the current crate's name/version
// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
- let (v, inlineable) = consts::const_expr(ccx, expr, is_local);
+ let (v, inlineable) = consts::const_expr(ccx, &**expr, is_local);
ccx.const_values.borrow_mut().insert(id, v);
let mut inlineable = inlineable;
get_item_val()");
}
ast::Provided(m) => {
- register_method(ccx, id, m)
+ register_method(ccx, id, &*m)
}
}
}
ast_map::NodeMethod(m) => {
- register_method(ccx, id, m)
+ register_method(ccx, id, &*m)
}
ast_map::NodeForeignItem(ni) => {
ast::ForeignItemFn(..) => {
let abi = ccx.tcx.map.get_foreign_abi(id);
let ty = ty::node_id_to_type(ccx.tcx(), ni.id);
- let name = foreign::link_name(ni);
+ let name = foreign::link_name(&*ni);
foreign::register_foreign_item_fn(ccx, abi, ty,
name.get().as_slice(),
Some(ni.span))
}
ast::ForeignItemStatic(..) => {
- foreign::register_static(ccx, ni)
+ foreign::register_static(ccx, &*ni)
}
}
}
use synabi = syntax::abi;
use syntax::ast_map;
+use std::gc::Gc;
+
pub struct MethodData {
pub llfn: ValueRef,
pub llself: ValueRef,
let mut llargs = Vec::new();
let arg_tys = match args {
- ArgExprs(a) => a.iter().map(|x| expr_ty(bcx, *x)).collect(),
+ ArgExprs(a) => a.iter().map(|x| expr_ty(bcx, &**x)).collect(),
_ => fail!("expected arg exprs.")
};
bcx = trans_args(bcx, args, callee_ty, &mut llargs,
pub enum CallArgs<'a> {
// Supply value of arguments as a list of expressions that must be
// translated. This is used in the common case of `foo(bar, qux)`.
- ArgExprs(&'a [@ast::Expr]),
+ ArgExprs(&'a [Gc<ast::Expr>]),
// Supply value of arguments as a list of LLVM value refs; frequently
// used with lang items and so forth, when the argument is an internal
match args {
ArgExprs(arg_exprs) => {
let num_formal_args = arg_tys.len();
- for (i, &arg_expr) in arg_exprs.iter().enumerate() {
+ for (i, arg_expr) in arg_exprs.iter().enumerate() {
if i == 0 && ignore_self {
continue;
}
let arg_ty = if i >= num_formal_args {
assert!(variadic);
- expr_ty_adjusted(cx, arg_expr)
+ expr_ty_adjusted(cx, &**arg_expr)
} else {
*arg_tys.get(i)
};
- let arg_datum = unpack_datum!(bcx, expr::trans(bcx, arg_expr));
+ let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &**arg_expr));
llargs.push(unpack_result!(bcx, {
trans_arg_datum(bcx, arg_ty, arg_datum,
arg_cleanup_scope,
use util::ppaux::{Repr, ty_to_str};
use std::c_str::ToCStr;
+use std::gc::Gc;
use std::vec;
-use std::vec::Vec;
use libc::c_uint;
use syntax::{ast, ast_util};
}
fn const_vec(cx: &CrateContext, e: &ast::Expr,
- es: &[@ast::Expr], is_local: bool) -> (ValueRef, Type, bool) {
+ es: &[Gc<ast::Expr>], is_local: bool) -> (ValueRef, Type, bool) {
let vec_ty = ty::expr_ty(cx.tcx(), e);
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
let llunitty = type_of::type_of(cx, unit_ty);
- let (vs, inlineable) = vec::unzip(es.iter().map(|e| const_expr(cx, *e, is_local)));
+ let (vs, inlineable) = vec::unzip(es.iter().map(|e| const_expr(cx, &**e, is_local)));
// If the vector contains enums, an LLVM array won't work.
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
C_struct(cx, vs.as_slice(), false)
// if it's assigned to a static.
fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
is_local: bool) -> (ValueRef, bool) {
- let map_list = |exprs: &[@ast::Expr]| {
- exprs.iter().map(|&e| const_expr(cx, e, is_local))
+ let map_list = |exprs: &[Gc<ast::Expr>]| {
+ exprs.iter().map(|e| const_expr(cx, &**e, is_local))
.fold((Vec::new(), true),
|(l, all_inlineable), (val, inlineable)| {
(l.append_one(val), all_inlineable && inlineable)
unsafe {
let _icx = push_ctxt("const_expr");
return match e.node {
- ast::ExprLit(lit) => {
- (consts::const_lit(cx, e, (*lit).clone()), true)
+ ast::ExprLit(ref lit) => {
+ (consts::const_lit(cx, e, (**lit).clone()), true)
}
- ast::ExprBinary(b, e1, e2) => {
- let (te1, _) = const_expr(cx, e1, is_local);
- let (te2, _) = const_expr(cx, e2, is_local);
+ ast::ExprBinary(b, ref e1, ref e2) => {
+ let (te1, _) = const_expr(cx, &**e1, is_local);
+ let (te2, _) = const_expr(cx, &**e2, is_local);
let te2 = base::cast_shift_const_rhs(b, te1, te2);
/* Neither type is bottom, and we expect them to be unified
* already, so the following is safe. */
- let ty = ty::expr_ty(cx.tcx(), e1);
+ let ty = ty::expr_ty(cx.tcx(), &**e1);
let is_float = ty::type_is_fp(ty);
let signed = ty::type_is_signed(ty);
return (match b {
},
}, true)
},
- ast::ExprUnary(u, e) => {
- let (te, _) = const_expr(cx, e, is_local);
- let ty = ty::expr_ty(cx.tcx(), e);
+ ast::ExprUnary(u, ref e) => {
+ let (te, _) = const_expr(cx, &**e, is_local);
+ let ty = ty::expr_ty(cx.tcx(), &**e);
let is_float = ty::type_is_fp(ty);
return (match u {
ast::UnBox | ast::UnUniq | ast::UnDeref => {
}
}, true)
}
- ast::ExprField(base, field, _) => {
- let bt = ty::expr_ty_adjusted(cx.tcx(), base);
+ ast::ExprField(ref base, field, _) => {
+ let bt = ty::expr_ty_adjusted(cx.tcx(), &**base);
let brepr = adt::represent_type(cx, bt);
- let (bv, inlineable) = const_expr(cx, base, is_local);
+ let (bv, inlineable) = const_expr(cx, &**base, is_local);
expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| {
let ix = ty::field_idx_strict(cx.tcx(), field.name, field_tys);
(adt::const_get_field(cx, &*brepr, bv, discr, ix), inlineable)
})
}
- ast::ExprIndex(base, index) => {
- let bt = ty::expr_ty_adjusted(cx.tcx(), base);
- let (bv, inlineable) = const_expr(cx, base, is_local);
- let iv = match const_eval::eval_const_expr(cx.tcx(), index) {
+ ast::ExprIndex(ref base, ref index) => {
+ let bt = ty::expr_ty_adjusted(cx.tcx(), &**base);
+ let (bv, inlineable) = const_expr(cx, &**base, is_local);
+ let iv = match const_eval::eval_const_expr(cx.tcx(), &**index) {
const_eval::const_int(i) => i as u64,
const_eval::const_uint(u) => u,
_ => cx.sess().span_bug(index.span,
}
(const_get_elt(cx, arr, [iv as c_uint]), inlineable)
}
- ast::ExprCast(base, _) => {
+ ast::ExprCast(ref base, _) => {
let ety = ty::expr_ty(cx.tcx(), e);
let llty = type_of::type_of(cx, ety);
- let basety = ty::expr_ty(cx.tcx(), base);
- let (v, inlineable) = const_expr(cx, base, is_local);
+ let basety = ty::expr_ty(cx.tcx(), &**base);
+ let (v, inlineable) = const_expr(cx, &**base, is_local);
return (match (expr::cast_type_kind(basety),
expr::cast_type_kind(ety)) {
}
}, inlineable)
}
- ast::ExprAddrOf(ast::MutImmutable, sub) => {
- let (e, _) = const_expr(cx, sub, is_local);
+ ast::ExprAddrOf(ast::MutImmutable, ref sub) => {
+ let (e, _) = const_expr(cx, &**sub, is_local);
(const_addr_of(cx, e), false)
}
ast::ExprTup(ref es) => {
let tcx = cx.tcx();
let base_val = match *base_opt {
- Some(base) => Some(const_expr(cx, base, is_local)),
+ Some(ref base) => Some(const_expr(cx, &**base, is_local)),
None => None
};
let (cs, inlineable) = vec::unzip(field_tys.iter().enumerate()
.map(|(ix, &field_ty)| {
match fs.iter().find(|f| field_ty.ident.name == f.ident.node.name) {
- Some(f) => const_expr(cx, (*f).expr, is_local),
+ Some(ref f) => const_expr(cx, &*f.expr, is_local),
None => {
match base_val {
Some((bv, inlineable)) => {
is_local);
(v, inlineable)
}
- ast::ExprVstore(sub, store @ ast::ExprVstoreSlice) |
- ast::ExprVstore(sub, store @ ast::ExprVstoreMutSlice) => {
+ ast::ExprVstore(ref sub, store @ ast::ExprVstoreSlice) |
+ ast::ExprVstore(ref sub, store @ ast::ExprVstoreMutSlice) => {
match sub.node {
ast::ExprLit(ref lit) => {
match lit.node {
- ast::LitStr(..) => { const_expr(cx, sub, is_local) }
+ ast::LitStr(..) => { const_expr(cx, &**sub, is_local) }
_ => { cx.sess().span_bug(e.span, "bad const-slice lit") }
}
}
_ => cx.sess().span_bug(e.span, "bad const-slice expr")
}
}
- ast::ExprRepeat(elem, count) => {
+ ast::ExprRepeat(ref elem, ref count) => {
let vec_ty = ty::expr_ty(cx.tcx(), e);
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
let llunitty = type_of::type_of(cx, unit_ty);
- let n = match const_eval::eval_const_expr(cx.tcx(), count) {
+ let n = match const_eval::eval_const_expr(cx.tcx(), &**count) {
const_eval::const_int(i) => i as uint,
const_eval::const_uint(i) => i as uint,
_ => cx.sess().span_bug(count.span, "count must be integral const expression.")
};
- let vs = Vec::from_elem(n, const_expr(cx, elem, is_local).val0());
+ let vs = Vec::from_elem(n, const_expr(cx, &**elem, is_local).val0());
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
C_struct(cx, vs.as_slice(), false)
} else {
_ => cx.sess().span_bug(e.span, "expected a struct or variant def")
}
}
- ast::ExprParen(e) => { const_expr(cx, e, is_local) }
+ ast::ExprParen(ref e) => { const_expr(cx, &**e, is_local) }
ast::ExprBlock(ref block) => {
match block.expr {
Some(ref expr) => const_expr(cx, &**expr, is_local),
use syntax::parse::token;
use syntax::visit::Visitor;
+use std::gc::Gc;
+
pub fn trans_stmt<'a>(cx: &'a Block<'a>,
s: &ast::Stmt)
-> &'a Block<'a> {
fcx.push_ast_cleanup_scope(id);
match s.node {
- ast::StmtExpr(e, _) | ast::StmtSemi(e, _) => {
- bcx = trans_stmt_semi(bcx, e);
+ ast::StmtExpr(ref e, _) | ast::StmtSemi(ref e, _) => {
+ bcx = trans_stmt_semi(bcx, &**e);
}
ast::StmtDecl(d, _) => {
match d.node {
ast::DeclLocal(ref local) => {
- bcx = init_local(bcx, *local);
+ bcx = init_local(bcx, &**local);
if cx.sess().opts.debuginfo == FullDebugInfo {
- debuginfo::create_local_var_metadata(bcx, *local);
+ debuginfo::create_local_var_metadata(bcx, &**local);
}
}
- ast::DeclItem(i) => trans_item(cx.fcx.ccx, i)
+ ast::DeclItem(ref i) => trans_item(cx.fcx.ccx, &**i)
}
}
ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro")
fcx.push_ast_cleanup_scope(b.id);
for s in b.stmts.iter() {
- bcx = trans_stmt(bcx, *s);
+ bcx = trans_stmt(bcx, &**s);
}
if dest != expr::Ignore {
}
match b.expr {
- Some(e) => {
- bcx = expr::trans_into(bcx, e, dest);
+ Some(ref e) => {
+ bcx = expr::trans_into(bcx, &**e, dest);
}
None => {
assert!(dest == expr::Ignore || bcx.unreachable.get());
if_id: ast::NodeId,
cond: &ast::Expr,
thn: ast::P<ast::Block>,
- els: Option<@ast::Expr>,
+ els: Option<Gc<ast::Expr>>,
dest: expr::Dest)
-> &'a Block<'a> {
debug!("trans_if(bcx={}, if_id={}, cond={}, thn={:?}, dest={})",
match els {
Some(elexpr) => {
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx };
- trans.visit_expr(elexpr, ());
+ trans.visit_expr(&*elexpr, ());
}
None => {}
}
// if true { .. } [else { .. }]
- bcx = trans_block(bcx, thn, dest);
+ bcx = trans_block(bcx, &*thn, dest);
debuginfo::clear_source_location(bcx.fcx);
} else {
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
- trans.visit_block(thn, ());
+ trans.visit_block(&*thn, ());
match els {
// if false { .. } else { .. }
Some(elexpr) => {
- bcx = expr::trans_into(bcx, elexpr, dest);
+ bcx = expr::trans_into(bcx, &*elexpr, dest);
debuginfo::clear_source_location(bcx.fcx);
}
let name = format!("then-block-{}-", thn.id);
let then_bcx_in = bcx.fcx.new_id_block(name.as_slice(), thn.id);
- let then_bcx_out = trans_block(then_bcx_in, thn, dest);
+ let then_bcx_out = trans_block(then_bcx_in, &*thn, dest);
debuginfo::clear_source_location(bcx.fcx);
let next_bcx;
match els {
Some(elexpr) => {
let else_bcx_in = bcx.fcx.new_id_block("else-block", elexpr.id);
- let else_bcx_out = expr::trans_into(else_bcx_in, elexpr, dest);
+ let else_bcx_out = expr::trans_into(else_bcx_in, &*elexpr, dest);
next_bcx = bcx.fcx.join_blocks(if_id,
[then_bcx_out, else_bcx_out]);
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
}
pub fn trans_ret<'a>(bcx: &'a Block<'a>,
- e: Option<@ast::Expr>)
+ e: Option<Gc<ast::Expr>>)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_ret");
let fcx = bcx.fcx;
};
match e {
Some(x) => {
- bcx = expr::trans_into(bcx, x, dest);
+ bcx = expr::trans_into(bcx, &*x, dest);
}
_ => {}
}
use middle::pat_util;
use util::ppaux;
+use libc::{c_uint, c_ulonglong, c_longlong};
use std::c_str::{CString, ToCStr};
use std::cell::{Cell, RefCell};
-use std::rc::{Rc, Weak};
use std::collections::HashMap;
use std::collections::HashSet;
-use libc::{c_uint, c_ulonglong, c_longlong};
+use std::gc::Gc;
use std::ptr;
-use std::string::String;
+use std::rc::{Rc, Weak};
use std::sync::atomics;
use syntax::codemap::{Span, Pos};
use syntax::{abi, ast, codemap, ast_util, ast_map};
let cx = bcx.ccx();
let def_map = &cx.tcx.def_map;
- pat_util::pat_bindings(def_map, local.pat, |_, node_id, span, path_ref| {
+ pat_util::pat_bindings(def_map, &*local.pat, |_, node_id, span, path_ref| {
let var_ident = ast_util::path_to_ident(path_ref);
let datum = match bcx.fcx.lllocals.borrow().find_copy(&node_id) {
let def_map = &cx.tcx.def_map;
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, arg.pat.span).fn_metadata;
- pat_util::pat_bindings(def_map, arg.pat, |_, node_id, span, path_ref| {
+ pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, span, path_ref| {
let llarg = match bcx.fcx.llargs.borrow().find_copy(&node_id) {
Some(v) => v,
None => {
let file_metadata = file_metadata(cx, loc.file.name.as_slice());
let function_type_metadata = unsafe {
- let fn_signature = get_function_signature(cx, fn_ast_id, fn_decl, param_substs, span);
+ let fn_signature = get_function_signature(cx, fn_ast_id, &*fn_decl, param_substs, span);
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
};
let arg_pats = fn_decl.inputs.iter().map(|arg_ref| arg_ref.pat).collect::<Vec<_>>();
populate_scope_map(cx,
arg_pats.as_slice(),
- top_level_block,
+ &*top_level_block,
fn_metadata,
&mut *fn_debug_context.scope_map.borrow_mut());
// descriptors where necessary. These artificial scopes allow GDB to correctly handle name
// shadowing.
fn populate_scope_map(cx: &CrateContext,
- arg_pats: &[@ast::Pat],
+ arg_pats: &[Gc<ast::Pat>],
fn_entry_block: &ast::Block,
fn_metadata: DISubprogram,
scope_map: &mut HashMap<ast::NodeId, DIScope>) {
// Push argument identifiers onto the stack so arguments integrate nicely with variable
// shadowing.
for &arg_pat in arg_pats.iter() {
- pat_util::pat_bindings(def_map, arg_pat, |_, _, _, path_ref| {
+ pat_util::pat_bindings(def_map, &*arg_pat, |_, _, _, path_ref| {
let ident = ast_util::path_to_ident(path_ref);
scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata, ident: Some(ident) });
})
// The interesting things here are statements and the concluding expression.
for statement in block.stmts.iter() {
- scope_map.insert(ast_util::stmt_id(*statement),
+ scope_map.insert(ast_util::stmt_id(&**statement),
scope_stack.last().unwrap().scope_metadata);
match statement.node {
- ast::StmtDecl(decl, _) => walk_decl(cx, decl, scope_stack, scope_map),
- ast::StmtExpr(exp, _) |
- ast::StmtSemi(exp, _) => walk_expr(cx, exp, scope_stack, scope_map),
+ ast::StmtDecl(ref decl, _) =>
+ walk_decl(cx, &**decl, scope_stack, scope_map),
+ ast::StmtExpr(ref exp, _) |
+ ast::StmtSemi(ref exp, _) =>
+ walk_expr(cx, &**exp, scope_stack, scope_map),
ast::StmtMac(..) => () // ignore macros (which should be expanded anyway)
}
}
for exp in block.expr.iter() {
- walk_expr(cx, *exp, scope_stack, scope_map);
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
}
walk_pattern(cx, local.pat, scope_stack, scope_map);
for exp in local.init.iter() {
- walk_expr(cx, *exp, scope_stack, scope_map);
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
}
_ => ()
}
fn walk_pattern(cx: &CrateContext,
- pat: @ast::Pat,
+ pat: Gc<ast::Pat>,
scope_stack: &mut Vec<ScopeStackEntry> ,
scope_map: &mut HashMap<ast::NodeId, DIScope>) {
// Check if this is a binding. If so we need to put it on the scope stack and maybe
// introduce an artificial scope
- if pat_util::pat_is_binding(def_map, pat) {
+ if pat_util::pat_is_binding(def_map, &*pat) {
let ident = ast_util::path_to_ident(path_ref);
ast::PatTup(ref sub_pats) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
- for &sub_pat in sub_pats.iter() {
- walk_pattern(cx, sub_pat, scope_stack, scope_map);
+ for sub_pat in sub_pats.iter() {
+ walk_pattern(cx, sub_pat.clone(), scope_stack, scope_map);
}
}
- ast::PatBox(sub_pat) | ast::PatRegion(sub_pat) => {
+ ast::PatBox(ref sub_pat) | ast::PatRegion(ref sub_pat) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
- walk_pattern(cx, sub_pat, scope_stack, scope_map);
+ walk_pattern(cx, sub_pat.clone(), scope_stack, scope_map);
}
- ast::PatLit(exp) => {
+ ast::PatLit(ref exp) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
- walk_expr(cx, exp, scope_stack, scope_map);
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
- ast::PatRange(exp1, exp2) => {
+ ast::PatRange(ref exp1, ref exp2) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
- walk_expr(cx, exp1, scope_stack, scope_map);
- walk_expr(cx, exp2, scope_stack, scope_map);
+ walk_expr(cx, &**exp1, scope_stack, scope_map);
+ walk_expr(cx, &**exp2, scope_stack, scope_map);
}
ast::PatVec(ref front_sub_pats, ref middle_sub_pats, ref back_sub_pats) => {
ast::ExprAgain(_) |
ast::ExprPath(_) => {}
- ast::ExprVstore(sub_exp, _) |
- ast::ExprCast(sub_exp, _) |
- ast::ExprAddrOf(_, sub_exp) |
- ast::ExprField(sub_exp, _, _) |
- ast::ExprParen(sub_exp) => walk_expr(cx, sub_exp, scope_stack, scope_map),
+ ast::ExprVstore(ref sub_exp, _) |
+ ast::ExprCast(ref sub_exp, _) |
+ ast::ExprAddrOf(_, ref sub_exp) |
+ ast::ExprField(ref sub_exp, _, _) |
+ ast::ExprParen(ref sub_exp) =>
+ walk_expr(cx, &**sub_exp, scope_stack, scope_map),
- ast::ExprBox(place, sub_expr) => {
- walk_expr(cx, place, scope_stack, scope_map);
- walk_expr(cx, sub_expr, scope_stack, scope_map);
+ ast::ExprBox(ref place, ref sub_expr) => {
+ walk_expr(cx, &**place, scope_stack, scope_map);
+ walk_expr(cx, &**sub_expr, scope_stack, scope_map);
}
ast::ExprRet(exp_opt) => match exp_opt {
- Some(sub_exp) => walk_expr(cx, sub_exp, scope_stack, scope_map),
+ Some(sub_exp) => walk_expr(cx, &*sub_exp, scope_stack, scope_map),
None => ()
},
- ast::ExprUnary(_, sub_exp) => {
- walk_expr(cx, sub_exp, scope_stack, scope_map);
+ ast::ExprUnary(_, ref sub_exp) => {
+ walk_expr(cx, &**sub_exp, scope_stack, scope_map);
}
- ast::ExprAssignOp(_, lhs, rhs) |
- ast::ExprIndex(lhs, rhs) |
- ast::ExprBinary(_, lhs, rhs) => {
- walk_expr(cx, lhs, scope_stack, scope_map);
- walk_expr(cx, rhs, scope_stack, scope_map);
+ ast::ExprAssignOp(_, ref lhs, ref rhs) |
+ ast::ExprIndex(ref lhs, ref rhs) |
+ ast::ExprBinary(_, ref lhs, ref rhs) => {
+ walk_expr(cx, &**lhs, scope_stack, scope_map);
+ walk_expr(cx, &**rhs, scope_stack, scope_map);
}
ast::ExprVec(ref init_expressions) |
ast::ExprTup(ref init_expressions) => {
for ie in init_expressions.iter() {
- walk_expr(cx, *ie, scope_stack, scope_map);
+ walk_expr(cx, &**ie, scope_stack, scope_map);
}
}
- ast::ExprAssign(sub_exp1, sub_exp2) |
- ast::ExprRepeat(sub_exp1, sub_exp2) => {
- walk_expr(cx, sub_exp1, scope_stack, scope_map);
- walk_expr(cx, sub_exp2, scope_stack, scope_map);
+ ast::ExprAssign(ref sub_exp1, ref sub_exp2) |
+ ast::ExprRepeat(ref sub_exp1, ref sub_exp2) => {
+ walk_expr(cx, &**sub_exp1, scope_stack, scope_map);
+ walk_expr(cx, &**sub_exp2, scope_stack, scope_map);
}
- ast::ExprIf(cond_exp, then_block, ref opt_else_exp) => {
- walk_expr(cx, cond_exp, scope_stack, scope_map);
+ ast::ExprIf(ref cond_exp, ref then_block, ref opt_else_exp) => {
+ walk_expr(cx, &**cond_exp, scope_stack, scope_map);
with_new_scope(cx,
then_block.span,
scope_stack,
scope_map,
|cx, scope_stack, scope_map| {
- walk_block(cx, then_block, scope_stack, scope_map);
+ walk_block(cx, &**then_block, scope_stack, scope_map);
});
match *opt_else_exp {
- Some(else_exp) => walk_expr(cx, else_exp, scope_stack, scope_map),
+ Some(ref else_exp) =>
+ walk_expr(cx, &**else_exp, scope_stack, scope_map),
_ => ()
}
}
- ast::ExprWhile(cond_exp, loop_body) => {
- walk_expr(cx, cond_exp, scope_stack, scope_map);
+ ast::ExprWhile(ref cond_exp, ref loop_body) => {
+ walk_expr(cx, &**cond_exp, scope_stack, scope_map);
with_new_scope(cx,
loop_body.span,
scope_stack,
scope_map,
|cx, scope_stack, scope_map| {
- walk_block(cx, loop_body, scope_stack, scope_map);
+ walk_block(cx, &**loop_body, scope_stack, scope_map);
})
}
Found unexpanded macro.");
}
- ast::ExprLoop(block, _) |
- ast::ExprBlock(block) => {
+ ast::ExprLoop(ref block, _) |
+ ast::ExprBlock(ref block) => {
with_new_scope(cx,
block.span,
scope_stack,
scope_map,
|cx, scope_stack, scope_map| {
- walk_block(cx, block, scope_stack, scope_map);
+ walk_block(cx, &**block, scope_stack, scope_map);
})
}
- ast::ExprFnBlock(decl, block) |
- ast::ExprProc(decl, block) => {
+ ast::ExprFnBlock(ref decl, ref block) |
+ ast::ExprProc(ref decl, ref block) => {
with_new_scope(cx,
block.span,
scope_stack,
scope_map,
|cx, scope_stack, scope_map| {
- for &ast::Arg { pat: pattern, .. } in decl.inputs.iter() {
- walk_pattern(cx, pattern, scope_stack, scope_map);
+ for &ast::Arg { pat: ref pattern, .. } in decl.inputs.iter() {
+ walk_pattern(cx, pattern.clone(), scope_stack, scope_map);
}
- walk_block(cx, block, scope_stack, scope_map);
+ walk_block(cx, &**block, scope_stack, scope_map);
})
}
- ast::ExprCall(fn_exp, ref args) => {
- walk_expr(cx, fn_exp, scope_stack, scope_map);
+ ast::ExprCall(ref fn_exp, ref args) => {
+ walk_expr(cx, &**fn_exp, scope_stack, scope_map);
for arg_exp in args.iter() {
- walk_expr(cx, *arg_exp, scope_stack, scope_map);
+ walk_expr(cx, &**arg_exp, scope_stack, scope_map);
}
}
ast::ExprMethodCall(_, _, ref args) => {
for arg_exp in args.iter() {
- walk_expr(cx, *arg_exp, scope_stack, scope_map);
+ walk_expr(cx, &**arg_exp, scope_stack, scope_map);
}
}
- ast::ExprMatch(discriminant_exp, ref arms) => {
- walk_expr(cx, discriminant_exp, scope_stack, scope_map);
+ ast::ExprMatch(ref discriminant_exp, ref arms) => {
+ walk_expr(cx, &**discriminant_exp, scope_stack, scope_map);
// for each arm we have to first walk the pattern as these might introduce new
// artificial scopes. It should be sufficient to walk only one pattern per arm, as
}
for guard_exp in arm_ref.guard.iter() {
- walk_expr(cx, *guard_exp, scope_stack, scope_map)
+ walk_expr(cx, &**guard_exp, scope_stack, scope_map)
}
- walk_expr(cx, arm_ref.body, scope_stack, scope_map);
+ walk_expr(cx, &*arm_ref.body, scope_stack, scope_map);
})
}
}
ast::ExprStruct(_, ref fields, ref base_exp) => {
- for &ast::Field { expr: exp, .. } in fields.iter() {
- walk_expr(cx, exp, scope_stack, scope_map);
+ for &ast::Field { expr: ref exp, .. } in fields.iter() {
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
match *base_exp {
- Some(exp) => walk_expr(cx, exp, scope_stack, scope_map),
+ Some(ref exp) => walk_expr(cx, &**exp, scope_stack, scope_map),
None => ()
}
}
ast::ExprInlineAsm(ast::InlineAsm { inputs: ref inputs,
outputs: ref outputs,
.. }) => {
- // inputs, outputs: ~[(String, @expr)]
- for &(_, exp) in inputs.iter() {
- walk_expr(cx, exp, scope_stack, scope_map);
+ // inputs, outputs: ~[(String, Gc<expr>)]
+ for &(_, ref exp) in inputs.iter() {
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
- for &(_, exp) in outputs.iter() {
- walk_expr(cx, exp, scope_stack, scope_map);
+ for &(_, ref exp) in outputs.iter() {
+ walk_expr(cx, &**exp, scope_stack, scope_map);
}
}
}
use syntax::codemap;
use syntax::print::pprust::{expr_to_str};
+use std::gc::Gc;
+
// Destinations
// These are passed around by the code generating functions to track the
let _icx = push_ctxt("trans_datum_unadjusted");
match expr.node {
- ast::ExprParen(e) => {
- trans(bcx, e)
+ ast::ExprParen(ref e) => {
+ trans(bcx, &**e)
}
ast::ExprPath(_) => {
trans_def(bcx, expr, bcx.def(expr.id))
}
- ast::ExprField(base, ident, _) => {
- trans_rec_field(bcx, base, ident)
+ ast::ExprField(ref base, ident, _) => {
+ trans_rec_field(bcx, &**base, ident)
}
- ast::ExprIndex(base, idx) => {
- trans_index(bcx, expr, base, idx)
+ ast::ExprIndex(ref base, ref idx) => {
+ trans_index(bcx, expr, &**base, &**idx)
}
- ast::ExprVstore(contents, ast::ExprVstoreUniq) => {
+ ast::ExprVstore(ref contents, ast::ExprVstoreUniq) => {
fcx.push_ast_cleanup_scope(contents.id);
let datum = unpack_datum!(
- bcx, tvec::trans_uniq_vstore(bcx, expr, contents));
+ bcx, tvec::trans_uniq_vstore(bcx, expr, &**contents));
bcx = fcx.pop_and_trans_ast_cleanup_scope(bcx, contents.id);
DatumBlock::new(bcx, datum)
}
"expected unique or managed box")
}
}
- ast::ExprLit(lit) => trans_immediate_lit(bcx, expr, (*lit).clone()),
- ast::ExprBinary(op, lhs, rhs) => {
- trans_binary(bcx, expr, op, lhs, rhs)
+ ast::ExprLit(ref lit) => trans_immediate_lit(bcx, expr, (**lit).clone()),
+ ast::ExprBinary(op, ref lhs, ref rhs) => {
+ trans_binary(bcx, expr, op, &**lhs, &**rhs)
}
- ast::ExprUnary(op, x) => {
- trans_unary(bcx, expr, op, x)
+ ast::ExprUnary(op, ref x) => {
+ trans_unary(bcx, expr, op, &**x)
}
- ast::ExprAddrOf(_, x) => {
- trans_addr_of(bcx, expr, x)
+ ast::ExprAddrOf(_, ref x) => {
+ trans_addr_of(bcx, expr, &**x)
}
- ast::ExprCast(val, _) => {
+ ast::ExprCast(ref val, _) => {
// Datum output mode means this is a scalar cast:
- trans_imm_cast(bcx, val, expr.id)
+ trans_imm_cast(bcx, &**val, expr.id)
}
_ => {
bcx.tcx().sess.span_bug(
}
match expr.node {
- ast::ExprParen(e) => {
- trans_into(bcx, e, Ignore)
+ ast::ExprParen(ref e) => {
+ trans_into(bcx, &**e, Ignore)
}
ast::ExprBreak(label_opt) => {
controlflow::trans_break(bcx, expr.id, label_opt)
ast::ExprRet(ex) => {
controlflow::trans_ret(bcx, ex)
}
- ast::ExprWhile(cond, body) => {
- controlflow::trans_while(bcx, expr.id, cond, body)
+ ast::ExprWhile(ref cond, ref body) => {
+ controlflow::trans_while(bcx, expr.id, &**cond, &**body)
}
- ast::ExprLoop(body, _) => {
- controlflow::trans_loop(bcx, expr.id, body)
+ ast::ExprLoop(ref body, _) => {
+ controlflow::trans_loop(bcx, expr.id, &**body)
}
- ast::ExprAssign(dst, src) => {
- let src_datum = unpack_datum!(bcx, trans(bcx, src));
- let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, dst, "assign"));
+ ast::ExprAssign(ref dst, ref src) => {
+ let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
+ let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &**dst, "assign"));
if ty::type_needs_drop(bcx.tcx(), dst_datum.ty) {
// If there are destructors involved, make sure we
src_datum.store_to(bcx, dst_datum.val)
}
}
- ast::ExprAssignOp(op, dst, src) => {
- trans_assign_op(bcx, expr, op, dst, src)
+ ast::ExprAssignOp(op, ref dst, ref src) => {
+ trans_assign_op(bcx, expr, op, &**dst, src.clone())
}
ast::ExprInlineAsm(ref a) => {
asm::trans_inline_asm(bcx, a)
let fcx = bcx.fcx;
match expr.node {
- ast::ExprParen(e) => {
- trans_into(bcx, e, dest)
+ ast::ExprParen(ref e) => {
+ trans_into(bcx, &**e, dest)
}
ast::ExprPath(_) => {
trans_def_dps_unadjusted(bcx, expr, bcx.def(expr.id), dest)
}
- ast::ExprIf(cond, thn, els) => {
- controlflow::trans_if(bcx, expr.id, cond, thn, els, dest)
+ ast::ExprIf(ref cond, ref thn, els) => {
+ controlflow::trans_if(bcx, expr.id, &**cond, thn.clone(), els, dest)
}
- ast::ExprMatch(discr, ref arms) => {
- _match::trans_match(bcx, expr, discr, arms.as_slice(), dest)
+ ast::ExprMatch(ref discr, ref arms) => {
+ _match::trans_match(bcx, expr, &**discr, arms.as_slice(), dest)
}
- ast::ExprBlock(blk) => {
- controlflow::trans_block(bcx, blk, dest)
+ ast::ExprBlock(ref blk) => {
+ controlflow::trans_block(bcx, &**blk, dest)
}
ast::ExprStruct(_, ref fields, base) => {
trans_rec_or_struct(bcx,
}
ast::ExprTup(ref args) => {
let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr));
- let numbered_fields: Vec<(uint, @ast::Expr)> =
+ let numbered_fields: Vec<(uint, Gc<ast::Expr>)> =
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
trans_adt(bcx, &*repr, 0, numbered_fields.as_slice(), None, dest)
}
}
}
}
- ast::ExprVstore(contents, ast::ExprVstoreSlice) |
- ast::ExprVstore(contents, ast::ExprVstoreMutSlice) => {
+ ast::ExprVstore(ref contents, ast::ExprVstoreSlice) |
+ ast::ExprVstore(ref contents, ast::ExprVstoreMutSlice) => {
fcx.push_ast_cleanup_scope(contents.id);
- bcx = tvec::trans_slice_vstore(bcx, expr, contents, dest);
+ bcx = tvec::trans_slice_vstore(bcx, expr, &**contents, dest);
fcx.pop_and_trans_ast_cleanup_scope(bcx, contents.id)
}
ast::ExprVec(..) | ast::ExprRepeat(..) => {
tvec::trans_fixed_vstore(bcx, expr, expr, dest)
}
- ast::ExprFnBlock(decl, body) |
- ast::ExprProc(decl, body) => {
+ ast::ExprFnBlock(ref decl, ref body) |
+ ast::ExprProc(ref decl, ref body) => {
let expr_ty = expr_ty(bcx, expr);
let store = ty::ty_closure_store(expr_ty);
debug!("translating block function {} with type {}",
expr_to_str(expr), expr_ty.repr(tcx));
- closure::trans_expr_fn(bcx, store, decl, body, expr.id, dest)
+ closure::trans_expr_fn(bcx, store, &**decl, &**body, expr.id, dest)
}
- ast::ExprCall(f, ref args) => {
+ ast::ExprCall(ref f, ref args) => {
if bcx.tcx().is_method_call(expr.id) {
- let callee_datum = unpack_datum!(bcx, trans(bcx, f));
+ let callee_datum = unpack_datum!(bcx, trans(bcx, &**f));
trans_overloaded_call(bcx,
expr,
callee_datum,
} else {
callee::trans_call(bcx,
expr,
- f,
+ &**f,
callee::ArgExprs(args.as_slice()),
dest)
}
ast::ExprMethodCall(_, _, ref args) => {
callee::trans_method_call(bcx,
expr,
- *args.get(0),
+ &**args.get(0),
callee::ArgExprs(args.as_slice()),
dest)
}
- ast::ExprBinary(_, lhs, rhs) => {
+ ast::ExprBinary(_, ref lhs, ref rhs) => {
// if not overloaded, would be RvalueDatumExpr
- let lhs = unpack_datum!(bcx, trans(bcx, lhs));
- let rhs_datum = unpack_datum!(bcx, trans(bcx, rhs));
+ let lhs = unpack_datum!(bcx, trans(bcx, &**lhs));
+ let rhs_datum = unpack_datum!(bcx, trans(bcx, &**rhs));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), lhs,
Some((rhs_datum, rhs.id)), Some(dest)).bcx
}
- ast::ExprUnary(_, subexpr) => {
+ ast::ExprUnary(_, ref subexpr) => {
// if not overloaded, would be RvalueDatumExpr
- let arg = unpack_datum!(bcx, trans(bcx, subexpr));
+ let arg = unpack_datum!(bcx, trans(bcx, &**subexpr));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id),
arg, None, Some(dest)).bcx
}
- ast::ExprIndex(base, idx) => {
+ ast::ExprIndex(ref base, ref idx) => {
// if not overloaded, would be RvalueDatumExpr
- let base = unpack_datum!(bcx, trans(bcx, base));
- let idx_datum = unpack_datum!(bcx, trans(bcx, idx));
+ let base = unpack_datum!(bcx, trans(bcx, &**base));
+ let idx_datum = unpack_datum!(bcx, trans(bcx, &**idx));
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), base,
Some((idx_datum, idx.id)), Some(dest)).bcx
}
- ast::ExprCast(val, _) => {
+ ast::ExprCast(ref val, _) => {
// DPS output mode means this is a trait cast:
match ty::get(node_id_type(bcx, expr.id)).sty {
ty::ty_trait(..) => {
- let datum = unpack_datum!(bcx, trans(bcx, val));
+ let datum = unpack_datum!(bcx, trans(bcx, &**val));
meth::trans_trait_cast(bcx, datum, expr.id, dest)
}
_ => {
}
}
}
- ast::ExprAssignOp(op, dst, src) => {
- trans_assign_op(bcx, expr, op, dst, src)
+ ast::ExprAssignOp(op, ref dst, ref src) => {
+ trans_assign_op(bcx, expr, op, &**dst, src.clone())
}
_ => {
bcx.tcx().sess.span_bug(
fn trans_rec_or_struct<'a>(
bcx: &'a Block<'a>,
fields: &[ast::Field],
- base: Option<@ast::Expr>,
+ base: Option<Gc<ast::Expr>>,
expr_span: codemap::Span,
id: ast::NodeId,
dest: Dest)
*/
struct StructBaseInfo {
/// The base expression; will be evaluated after all explicit fields.
- expr: @ast::Expr,
+ expr: Gc<ast::Expr>,
/// The indices of fields to copy paired with their types.
fields: Vec<(uint, ty::t)> }
bcx: &'a Block<'a>,
repr: &adt::Repr,
discr: ty::Disr,
- fields: &[(uint, @ast::Expr)],
+ fields: &[(uint, Gc<ast::Expr>)],
optbase: Option<StructBaseInfo>,
dest: Dest)
-> &'a Block<'a> {
let mut bcx = bcx;
let addr = match dest {
Ignore => {
- for &(_i, e) in fields.iter() {
- bcx = trans_into(bcx, e, Ignore);
+ for &(_i, ref e) in fields.iter() {
+ bcx = trans_into(bcx, &**e, Ignore);
}
for sbi in optbase.iter() {
// FIXME #7261: this moves entire base, not just certain fields
- bcx = trans_into(bcx, sbi.expr, Ignore);
+ bcx = trans_into(bcx, &*sbi.expr, Ignore);
}
return bcx;
}
adt::trans_start_init(bcx, repr, addr, discr);
- for &(i, e) in fields.iter() {
+ for &(i, ref e) in fields.iter() {
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
- let e_ty = expr_ty_adjusted(bcx, e);
- bcx = trans_into(bcx, e, SaveIn(dest));
+ let e_ty = expr_ty_adjusted(bcx, &**e);
+ bcx = trans_into(bcx, &**e, SaveIn(dest));
fcx.schedule_drop_mem(cleanup::CustomScope(custom_cleanup_scope),
dest, e_ty);
}
for base in optbase.iter() {
// FIXME #6573: is it sound to use the destination's repr on the base?
// And, would it ever be reasonable to be here with discr != 0?
- let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, base.expr, "base"));
+ let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &*base.expr, "base"));
for &(i, t) in base.fields.iter() {
let datum = base_datum.get_element(
t,
mut bcx: &'a Block<'a>,
expr: &ast::Expr,
callee: Datum<Expr>,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
dest: Option<Dest>)
-> &'a Block<'a> {
// Evaluate and tuple the arguments.
let tuple_type = ty::mk_tup(bcx.tcx(),
args.iter()
- .map(|e| expr_ty(bcx, *e))
+ .map(|e| expr_ty(bcx, &**e))
.collect());
let repr = adt::represent_type(bcx.ccx(), tuple_type);
- let numbered_fields: Vec<(uint, @ast::Expr)> =
+ let numbered_fields: Vec<(uint, Gc<ast::Expr>)> =
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
let argument_scope = bcx.fcx.push_custom_cleanup_scope();
let tuple_datum =
expr: &ast::Expr,
op: ast::BinOp,
dst: &ast::Expr,
- src: @ast::Expr)
+ src: Gc<ast::Expr>)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_assign_op");
let mut bcx = bcx;
let dst = Load(bcx, dst_datum.val);
// Evaluate RHS
- let rhs_datum = unpack_datum!(bcx, trans(bcx, src));
+ let rhs_datum = unpack_datum!(bcx, trans(bcx, &*src));
let rhs_ty = rhs_datum.ty;
let rhs = rhs_datum.to_llscalarish(bcx);
pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
let _icx = push_ctxt("foreign::trans_foreign_mod");
- for &foreign_item in foreign_mod.items.iter() {
- let lname = link_name(foreign_item);
+ for foreign_item in foreign_mod.items.iter() {
+ let lname = link_name(&**foreign_item);
match foreign_item.node {
ast::ForeignItemFn(..) => {
ccx.external_srcs.borrow_mut().insert(item.id, fn_id);
ccx.stats.n_inlines.set(ccx.stats.n_inlines.get() + 1);
- trans_item(ccx, item);
+ trans_item(ccx, &*item);
// We're bringing an external global into this crate, but we don't
// want to create two copies of the global. If we do this, then if
_ => ccx.sess().bug("maybe_instantiate_inline: item has a \
non-enum, non-struct parent")
}
- trans_item(ccx, item);
+ trans_item(ccx, &*item);
local_def(my_id)
}
csearch::found_parent(_, _) => {
if num_type_params == 0 {
let llfn = get_item_val(ccx, mth.id);
- trans_fn(ccx, mth.decl, mth.body, llfn,
+ trans_fn(ccx, &*mth.decl, &*mth.body, llfn,
¶m_substs::empty(), mth.id, []);
}
local_def(mth.id)
use util::ppaux::Repr;
use std::c_str::ToCStr;
+use std::gc::Gc;
use syntax::abi::Rust;
use syntax::parse::token;
use syntax::{ast, ast_map, visit};
*/
pub fn trans_impl(ccx: &CrateContext,
name: ast::Ident,
- methods: &[@ast::Method],
+ methods: &[Gc<ast::Method>],
generics: &ast::Generics,
id: ast::NodeId) {
let _icx = push_ctxt("meth::trans_impl");
if !generics.ty_params.is_empty() {
let mut v = TransItemVisitor{ ccx: ccx };
for method in methods.iter() {
- visit::walk_method_helper(&mut v, *method, ());
+ visit::walk_method_helper(&mut v, &**method, ());
}
return;
}
for method in methods.iter() {
if method.generics.ty_params.len() == 0u {
let llfn = get_item_val(ccx, method.id);
- trans_fn(ccx, method.decl, method.body,
+ trans_fn(ccx, &*method.decl, &*method.body,
llfn, ¶m_substs::empty(), method.id, []);
} else {
let mut v = TransItemVisitor{ ccx: ccx };
- visit::walk_method_helper(&mut v, *method, ());
+ visit::walk_method_helper(&mut v, &**method, ());
}
}
}
ast_map::NodeItem(i) => {
match *i {
ast::Item {
- node: ast::ItemFn(decl, _, _, _, body),
+ node: ast::ItemFn(ref decl, _, _, _, ref body),
..
} => {
let d = mk_lldecl();
set_llvm_fn_attrs(i.attrs.as_slice(), d);
- trans_fn(ccx, decl, body, d, &psubsts, fn_id.node, []);
+ trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, []);
d
}
_ => {
}
}
ast_map::NodeForeignItem(i) => {
- let simple = intrinsic::get_simple_intrinsic(ccx, i);
+ let simple = intrinsic::get_simple_intrinsic(ccx, &*i);
match simple {
Some(decl) => decl,
None => {
let d = mk_lldecl();
- intrinsic::trans_intrinsic(ccx, d, i, &psubsts, ref_id);
+ intrinsic::trans_intrinsic(ccx, d, &*i, &psubsts, ref_id);
d
}
}
ast::TupleVariantKind(ref args) => {
trans_enum_variant(ccx,
parent,
- v,
+ &*v,
args.as_slice(),
this_tv.disr_val,
&psubsts,
ast_map::NodeMethod(mth) => {
let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
- trans_fn(ccx, mth.decl, mth.body, d, &psubsts, mth.id, []);
+ trans_fn(ccx, &*mth.decl, &*mth.body, d, &psubsts, mth.id, []);
d
}
ast_map::NodeTraitMethod(method) => {
ast::Provided(mth) => {
let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
- trans_fn(ccx, mth.decl, mth.body, d, &psubsts, mth.id, []);
+ trans_fn(ccx, &*mth.decl, &*mth.body, d, &psubsts, mth.id, []);
d
}
_ => {
match dest {
Ignore => {
for element in elements.iter() {
- bcx = expr::trans_into(bcx, *element, Ignore);
+ bcx = expr::trans_into(bcx, &**element, Ignore);
}
}
let lleltptr = GEPi(bcx, lldest, [i]);
debug!("writing index {:?} with lleltptr={:?}",
i, bcx.val_to_str(lleltptr));
- bcx = expr::trans_into(bcx, *element,
+ bcx = expr::trans_into(bcx, &**element,
SaveIn(lleltptr));
fcx.schedule_drop_mem(
cleanup::CustomScope(temp_scope),
}
return bcx;
}
- ast::ExprRepeat(element, count_expr) => {
+ ast::ExprRepeat(ref element, ref count_expr) => {
match dest {
Ignore => {
- return expr::trans_into(bcx, element, Ignore);
+ return expr::trans_into(bcx, &**element, Ignore);
}
SaveIn(lldest) => {
- let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
+ let count = ty::eval_repeat_count(bcx.tcx(), &**count_expr);
if count == 0 {
return bcx;
}
// this can only happen as a result of OOM. So we just skip out on the
// cleanup since things would *probably* be broken at that point anyways.
- let elem = unpack_datum!(bcx, expr::trans(bcx, element));
+ let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));
let bcx = iter_vec_loop(bcx, lldest, vt,
}
},
ast::ExprVec(ref es) => es.len(),
- ast::ExprRepeat(_, count_expr) => {
- ty::eval_repeat_count(bcx.tcx(), count_expr)
+ ast::ExprRepeat(_, ref count_expr) => {
+ ty::eval_repeat_count(bcx.tcx(), &**count_expr)
}
_ => bcx.tcx().sess.span_bug(content_expr.span,
"unexpected vec content")
use std::fmt::Show;
use std::fmt;
use std::hash::{Hash, sip, Writer};
+use std::gc::Gc;
use std::iter::AdditiveIterator;
use std::mem;
use std::ops;
/// These two caches are used by const_eval when decoding external statics
/// and variants that are found.
- pub extern_const_statics: RefCell<DefIdMap<Option<@ast::Expr>>>,
- pub extern_const_variants: RefCell<DefIdMap<Option<@ast::Expr>>>,
+ pub extern_const_statics: RefCell<DefIdMap<Option<Gc<ast::Expr>>>>,
+ pub extern_const_variants: RefCell<DefIdMap<Option<Gc<ast::Expr>>>>,
pub method_map: typeck::MethodMap,
pub vtable_map: typeck::vtable_map,
}
}
- ast::ExprParen(e) => expr_kind(tcx, e),
+ ast::ExprParen(ref e) => expr_kind(tcx, &**e),
ast::ExprMac(..) => {
tcx.sess.span_bug(
}
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
- ty_box(_) => "@-ptr".to_string(),
+ ty_box(_) => "Gc-ptr".to_string(),
ty_uniq(_) => "box".to_string(),
ty_vec(_, _) => "vector".to_string(),
ty_ptr(_) => "*-ptr".to_string(),
};
match variant.node.disr_expr {
- Some(e) => match const_eval::eval_const_expr_partial(cx, e) {
+ Some(ref e) => match const_eval::eval_const_expr_partial(cx, &**e) {
Ok(const_eval::const_int(val)) => {
discriminant = val as Disr
}
};
last_discriminant = Some(discriminant);
- Rc::new(VariantInfo::from_ast_variant(cx, variant,
+ Rc::new(VariantInfo::from_ast_variant(cx, &*variant,
discriminant))
}).collect())
}
}
let tps = path.segments.iter().flat_map(|s| s.types.iter())
- .map(|&a_t| ast_ty_to_ty(this, rscope, a_t))
+ .map(|a_t| ast_ty_to_ty(this, rscope, &**a_t))
.collect();
let mut substs = subst::Substs {
supplied to `Box<T>`");
Some(ty::mk_err())
}
- ast::DefTy(did) | ast::DefStruct(did)
+ def::DefTy(did) | def::DefStruct(did)
if Some(did) == this.tcx().lang_items.gc() => {
if path.segments
.iter()
.flat_map(|s| s.types.iter())
- .len() > 1 {
+ .count() > 1 {
this.tcx()
.sess
.span_err(path.span,
.inputs
.iter()
.map(|input| {
- ast_ty_to_ty(this, rscope, input.ty)
+ ast_ty_to_ty(this, rscope, &*input.ty)
}).collect::<Vec<_>>();
let input_tuple = ty::mk_tup(this.tcx(), input_types);
let output_type = ast_ty_to_ty(this,
rscope,
- unboxed_function.decl.output);
+ &*unboxed_function.decl.output);
let substs = subst::Substs {
self_ty: None,
tps: vec!(input_tuple, output_type),
debug!("mk_pointer(ptr_ty={:?})", ptr_ty);
match a_seq_ty.ty.node {
- ast::TyVec(ty) => {
- let mut mt = ast_ty_to_mt(this, rscope, ty);
+ ast::TyVec(ref ty) => {
+ let mut mt = ast_ty_to_mt(this, rscope, &**ty);
if a_seq_ty.mutbl == ast::MutMutable {
mt.mutbl = ast::MutMutable;
}
substs
} = trait_ref_for_unboxed_function(this,
rscope,
- *unboxed_function);
+ &**unboxed_function);
return ty::mk_trait(this.tcx(),
def_id,
substs,
_ => {}
}
- constr(ast_ty_to_ty(this, rscope, a_seq_ty.ty))
+ constr(ast_ty_to_ty(this, rscope, &*a_seq_ty.ty))
}
// Parses the programmer's textual representation of a type into our
ast::TyVec(ty) => {
tcx.sess.span_err(ast_ty.span, "bare `[]` is not a type");
// return /something/ so they can at least get more errors
- let vec_ty = ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, ty), None);
+ let vec_ty = ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, &*ty), None);
ty::mk_uniq(tcx, vec_ty)
}
ast::TyPtr(ref mt) => {
ty::mk_ptr(tcx, ty::mt {
- ty: ast_ty_to_ty(this, rscope, mt.ty),
+ ty: ast_ty_to_ty(this, rscope, &*mt.ty),
mutbl: mt.mutbl
})
}
}
ast::TyTup(ref fields) => {
let flds = fields.iter()
- .map(|&t| ast_ty_to_ty(this, rscope, t))
+ .map(|t| ast_ty_to_ty(this, rscope, &**t))
.collect();
ty::mk_tup(tcx, flds)
}
"variadic function must have C calling convention");
}
ty::mk_bare_fn(tcx, ty_of_bare_fn(this, ast_ty.id, bf.fn_style,
- bf.abi, bf.decl))
+ bf.abi, &*bf.decl))
}
ast::TyClosure(ref f, ref region) => {
f.onceness,
bounds,
store,
- f.decl,
+ &*f.decl,
None);
ty::mk_closure(tcx, fn_decl)
}
f.onceness,
bounds,
ty::UniqTraitStore,
- f.decl,
+ &*f.decl,
None);
ty::mk_closure(tcx, fn_decl)
}
}
}
ast::TyFixedLengthVec(ty, e) => {
- match const_eval::eval_const_expr_partial(tcx, e) {
+ match const_eval::eval_const_expr_partial(tcx, &*e) {
Ok(ref r) => {
match *r {
const_eval::const_int(i) =>
- ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, ty),
+ ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, &*ty),
Some(i as uint)),
const_eval::const_uint(i) =>
- ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, ty),
+ ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, &*ty),
Some(i as uint)),
_ => {
tcx.sess.span_fatal(
match a.ty.node {
ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
ast::TyInfer => this.ty_infer(a.ty.span),
- _ => ast_ty_to_ty(this, rscope, a.ty),
+ _ => ast_ty_to_ty(this, rscope, &*a.ty),
}
}
let output_ty = match decl.output.node {
ast::TyInfer => this.ty_infer(decl.output.span),
- _ => ast_ty_to_ty(this, &rb, decl.output)
+ _ => ast_ty_to_ty(this, &rb, &*decl.output)
};
return ty::BareFnTy {
let output_ty = match decl.output.node {
ast::TyInfer if expected_ret_ty.is_some() => expected_ret_ty.unwrap(),
ast::TyInfer => this.ty_infer(decl.output.span),
- _ => ast_ty_to_ty(this, &rb, decl.output)
+ _ => ast_ty_to_ty(this, &rb, &*decl.output)
};
ty::ClosureTy {
use middle::typeck::require_same_types;
use std::collections::{HashMap, HashSet};
+use std::gc::Gc;
use syntax::ast;
use syntax::ast_util;
use syntax::parse::token;
for arm in arms.iter() {
let mut pcx = pat_ctxt {
fcx: fcx,
- map: pat_id_map(&tcx.def_map, *arm.pats.get(0)),
+ map: pat_id_map(&tcx.def_map, &**arm.pats.get(0)),
};
- for p in arm.pats.iter() { check_pat(&mut pcx, *p, discrim_ty);}
+ for p in arm.pats.iter() { check_pat(&mut pcx, &**p, discrim_ty);}
}
// The result of the match is the common supertype of all the
let mut guard_err = false;
let mut guard_bot = false;
match arm.guard {
- Some(e) => {
- check_expr_has_type(fcx, e, ty::mk_bool());
- let e_ty = fcx.expr_ty(e);
+ Some(ref e) => {
+ check_expr_has_type(fcx, &**e, ty::mk_bool());
+ let e_ty = fcx.expr_ty(&**e);
if ty::type_is_error(e_ty) {
guard_err = true;
}
},
None => ()
}
- check_expr(fcx, arm.body);
+ check_expr(fcx, &*arm.body);
let bty = fcx.node_ty(arm.body.id);
saw_err = saw_err || ty::type_is_error(bty);
if guard_err {
}
pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
- subpats: &Option<Vec<@ast::Pat>>, expected: ty::t) {
+ subpats: &Option<Vec<Gc<ast::Pat>>>, expected: ty::t) {
// Typecheck the path.
let fcx = pcx.fcx;
if !error_happened {
for pats in subpats.iter() {
for (subpat, arg_ty) in pats.iter().zip(arg_types.iter()) {
- check_pat(pcx, *subpat, *arg_ty);
+ check_pat(pcx, &**subpat, *arg_ty);
}
}
}
if error_happened {
for pats in subpats.iter() {
for pat in pats.iter() {
- check_pat(pcx, *pat, ty::mk_err());
+ check_pat(pcx, &**pat, ty::mk_err());
}
}
}
class_id,
class_field.id,
substitutions);
- check_pat(pcx, field.pat, field_type);
+ check_pat(pcx, &*field.pat, field_type);
found_fields.insert(index);
}
None => {
// Check the pattern anyway, so that attempts to look
// up its type won't fail
- check_pat(pcx, field.pat, ty::mk_err());
+ check_pat(pcx, &*field.pat, ty::mk_err());
tcx.sess.span_err(span,
format!("struct `{}` does not have a field named `{}`",
ty::item_path_str(tcx, class_id),
ast::PatWild | ast::PatWildMulti => {
fcx.write_ty(pat.id, expected);
}
- ast::PatLit(lt) => {
- check_expr_has_type(fcx, lt, expected);
- fcx.write_ty(pat.id, fcx.expr_ty(lt));
+ ast::PatLit(ref lt) => {
+ check_expr_has_type(fcx, &**lt, expected);
+ fcx.write_ty(pat.id, fcx.expr_ty(&**lt));
}
- ast::PatRange(begin, end) => {
- check_expr_has_type(fcx, begin, expected);
- check_expr_has_type(fcx, end, expected);
+ ast::PatRange(ref begin, ref end) => {
+ check_expr_has_type(fcx, &**begin, expected);
+ check_expr_has_type(fcx, &**end, expected);
let b_ty =
- fcx.infcx().resolve_type_vars_if_possible(fcx.expr_ty(begin));
+ fcx.infcx().resolve_type_vars_if_possible(fcx.expr_ty(&**begin));
let e_ty =
- fcx.infcx().resolve_type_vars_if_possible(fcx.expr_ty(end));
+ fcx.infcx().resolve_type_vars_if_possible(fcx.expr_ty(&**end));
debug!("pat_range beginning type: {:?}", b_ty);
debug!("pat_range ending type: {:?}", e_ty);
if !require_same_types(
tcx.sess.span_err(pat.span,
"only char and numeric types are allowed in range");
} else {
- match valid_range_bounds(fcx.ccx, begin, end) {
+ match valid_range_bounds(fcx.ccx, &**begin, &**end) {
Some(false) => {
tcx.sess.span_err(begin.span,
"lower range bound must be less than upper");
debug!("(checking match) writing type for pat id {}", pat.id);
match sub {
- Some(p) => check_pat(pcx, p, expected),
+ Some(ref p) => check_pat(pcx, &**p, expected),
_ => ()
}
}
match *s {
ty::ty_tup(ref ex_elts) if e_count == ex_elts.len() => {
for (i, elt) in elts.iter().enumerate() {
- check_pat(pcx, *elt, *ex_elts.get(i));
+ check_pat(pcx, &**elt, *ex_elts.get(i));
}
fcx.write_ty(pat.id, expected);
}
_ => {
for elt in elts.iter() {
- check_pat(pcx, *elt, ty::mk_err());
+ check_pat(pcx, &**elt, ty::mk_err());
}
// use terr_tuple_size if both types are tuples
let type_error = match *s {
}
}
}
- ast::PatBox(inner) => {
- check_pointer_pat(pcx, Send, inner, pat.id, pat.span, expected);
+ ast::PatBox(ref inner) => {
+ check_pointer_pat(pcx, Send, &**inner, pat.id, pat.span, expected);
}
- ast::PatRegion(inner) => {
- check_pointer_pat(pcx, Borrowed, inner, pat.id, pat.span, expected);
+ ast::PatRegion(ref inner) => {
+ check_pointer_pat(pcx, Borrowed, &**inner, pat.id, pat.span, expected);
}
ast::PatVec(ref before, slice, ref after) => {
let default_region_var =
infer::PatternRegion(pat.span));
let check_err = || {
- for &elt in before.iter() {
- check_pat(pcx, elt, ty::mk_err());
+ for elt in before.iter() {
+ check_pat(pcx, &**elt, ty::mk_err());
}
- for &elt in slice.iter() {
- check_pat(pcx, elt, ty::mk_err());
+ for elt in slice.iter() {
+ check_pat(pcx, &**elt, ty::mk_err());
}
- for &elt in after.iter() {
- check_pat(pcx, elt, ty::mk_err());
+ for elt in after.iter() {
+ check_pat(pcx, &**elt, ty::mk_err());
}
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
fcx.infcx().type_error_message_str_with_expected(
}
};
for elt in before.iter() {
- check_pat(pcx, *elt, elt_type);
+ check_pat(pcx, &**elt, elt_type);
}
match slice {
- Some(slice_pat) => {
+ Some(ref slice_pat) => {
let slice_ty = ty::mk_slice(tcx,
region_var,
ty::mt {ty: elt_type, mutbl: mutbl});
- check_pat(pcx, slice_pat, slice_ty);
+ check_pat(pcx, &**slice_pat, slice_ty);
}
None => ()
}
for elt in after.iter() {
- check_pat(pcx, *elt, elt_type);
+ check_pat(pcx, &**elt, elt_type);
}
fcx.write_ty(pat.id, expected);
}
}
}
-// Helper function to check @, box and & patterns
+// Helper function to check gc, box and & patterns
pub fn check_pointer_pat(pcx: &pat_ctxt,
pointer_kind: PointerKind,
inner: &ast::Pat,
use middle::const_eval;
use middle::def;
-use middle::lang_items::{ExchangeHeapLangItem, GcLangItem};
-use middle::lang_items::{ManagedHeapLangItem};
use middle::lint::UnreachableCode;
use middle::pat_util::pat_id_map;
use middle::pat_util;
use std::collections::HashMap;
use std::mem::replace;
use std::rc::Rc;
-use std::vec::Vec;
+use std::gc::Gc;
use syntax::abi;
use syntax::ast::{Provided, Required};
use syntax::ast;
fn visit_local(&mut self, local: &ast::Local, _: ()) {
let o_ty = match local.ty.node {
ast::TyInfer => None,
- _ => Some(self.fcx.to_ty(local.ty))
+ _ => Some(self.fcx.to_ty(&*local.ty))
};
self.assign(local.id, o_ty);
debug!("Local variable {} is assigned type {}",
- self.fcx.pat_to_str(local.pat),
+ self.fcx.pat_to_str(&*local.pat),
self.fcx.infcx().ty_to_str(
self.fcx.inh.locals.borrow().get_copy(&local.id)));
visit::walk_local(self, local, ());
for (arg_ty, input) in arg_tys.iter().zip(decl.inputs.iter()) {
// Create type variables for each argument.
pat_util::pat_bindings(&tcx.def_map,
- input.pat,
+ &*input.pat,
|_bm, pat_id, _sp, _path| {
visit.assign(pat_id, None);
});
// Check the pattern.
let pcx = pat_ctxt {
fcx: &fcx,
- map: pat_id_map(&tcx.def_map, input.pat),
+ map: pat_id_map(&tcx.def_map, &*input.pat),
};
- _match::check_pat(&pcx, input.pat, *arg_ty);
+ _match::check_pat(&pcx, &*input.pat, *arg_ty);
}
visit.visit_block(body, ());
// We unify the tail expr's type with the
// function result type, if there is a tail expr.
match body.expr {
- Some(tail_expr) => {
+ Some(ref tail_expr) => {
// Special case: we print a special error if there appears
// to be do-block/for-loop confusion
demand::suptype_with_fn(&fcx, tail_expr.span, false,
- fcx.ret_ty, fcx.expr_ty(tail_expr),
+ fcx.ret_ty, fcx.expr_ty(&**tail_expr),
|sp, e, a, s| {
fcx.report_mismatched_return_types(sp, e, a, s);
});
enum_definition.variants.as_slice());
}
ast::ItemStruct(..) => {
- check_fields_sized(ccx.tcx, ccx.tcx.map.expect_struct(it.id));
+ check_fields_sized(ccx.tcx, &*ccx.tcx.map.expect_struct(it.id));
}
_ => {}
}
let _indenter = indenter();
match it.node {
- ast::ItemStatic(_, _, e) => check_const(ccx, it.span, e, it.id),
+ ast::ItemStatic(_, _, ref e) => check_const(ccx, it.span, &**e, it.id),
ast::ItemEnum(ref enum_definition, _) => {
check_enum_variants(ccx,
it.span,
enum_definition.variants.as_slice(),
it.id);
}
- ast::ItemFn(decl, _, _, _, body) => {
+ ast::ItemFn(ref decl, _, _, _, ref body) => {
let fn_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
let param_env = ty::construct_parameter_environment(
fn_tpt.generics.region_param_defs.as_slice(),
body.id);
- check_bare_fn(ccx, decl, body, it.id, fn_tpt.ty, param_env);
+ check_bare_fn(ccx, &**decl, &**body, it.id, fn_tpt.ty, param_env);
}
ast::ItemImpl(_, ref opt_trait_ref, _, ref ms) => {
debug!("ItemImpl {} with id {}", token::get_ident(it.ident), it.id);
let impl_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
for m in ms.iter() {
- check_method_body(ccx, &impl_tpt.generics, None, *m);
+ check_method_body(ccx, &impl_tpt.generics, None, &**m);
}
match *opt_trait_ref {
}
Provided(m) => {
check_method_body(ccx, &trait_def.generics,
- Some(trait_def.trait_ref.clone()), m);
+ Some(trait_def.trait_ref.clone()), &*m);
}
}
}
ast::ItemForeignMod(ref m) => {
if m.abi == abi::RustIntrinsic {
for item in m.items.iter() {
- check_intrinsic_type(ccx, *item);
+ check_intrinsic_type(ccx, &**item);
}
} else {
for item in m.items.iter() {
let fty = ty::node_id_to_type(ccx.tcx, method.id);
- check_bare_fn(ccx, method.decl, method.body, method.id, fty, param_env);
+ check_bare_fn(ccx, &*method.decl, &*method.body, method.id, fty, param_env);
}
fn check_impl_methods_against_trait(ccx: &CrateCtxt,
impl_generics: &ty::Generics,
ast_trait_ref: &ast::TraitRef,
impl_trait_ref: &ty::TraitRef,
- impl_methods: &[@ast::Method]) {
+ impl_methods: &[Gc<ast::Method>]) {
// Locate trait methods
let tcx = ccx.tcx;
let trait_methods = ty::trait_methods(tcx, impl_trait_ref.def_id);
/// Attempts to resolve a call expression as an overloaded call.
fn try_overloaded_call(fcx: &FnCtxt,
call_expression: &ast::Expr,
- callee: @ast::Expr,
+ callee: Gc<ast::Expr>,
callee_type: ty::t,
- args: &[@ast::Expr])
+ args: &[Gc<ast::Expr>])
-> bool {
// Try `FnOnce`, then `FnMut`, then `Fn`.
for &(maybe_function_trait, method_name) in [
sp: Span,
method_fn_ty: ty::t,
callee_expr: &ast::Expr,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
deref_args: DerefArgs,
tuple_arguments: TupleArgumentsFlag)
-> ty::t {
sp: Span,
fn_inputs: &[ty::t],
callee_expr: &ast::Expr,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
deref_args: DerefArgs,
variadic: bool,
tuple_arguments: TupleArgumentsFlag) {
DontDerefArgs => {}
}
- check_expr_coercable_to_type(fcx, *arg, formal_ty);
+ check_expr_coercable_to_type(fcx, &**arg, formal_ty);
}
}
// arguments which we skipped above.
if variadic {
for arg in args.iter().skip(expected_arg_count) {
- check_expr(fcx, *arg);
+ check_expr(fcx, &**arg);
// There are a few types which get autopromoted when passed via varargs
// in C but we just error out instead and require explicit casts.
- let arg_ty = structurally_resolved_type(fcx, arg.span, fcx.expr_ty(*arg));
+ let arg_ty = structurally_resolved_type(fcx, arg.span,
+ fcx.expr_ty(&**arg));
match ty::get(arg_ty).sty {
ty::ty_float(ast::TyF32) => {
fcx.type_error_message(arg.span,
fn check_call(fcx: &FnCtxt,
call_expr: &ast::Expr,
f: &ast::Expr,
- args: &[@ast::Expr]) {
+ args: &[Gc<ast::Expr>]) {
// Store the type of `f` as the type of the callee
let fn_ty = fcx.expr_ty(f);
fn check_method_call(fcx: &FnCtxt,
expr: &ast::Expr,
method_name: ast::SpannedIdent,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
tps: &[ast::P<ast::Ty>]) {
- let rcvr = args[0];
+ let rcvr = args[0].clone();
// We can't know if we need &mut self before we look up the method,
// so treat the receiver as mutable just in case - only explicit
// overloaded dereferences care about the distinction.
- check_expr_with_lvalue_pref(fcx, rcvr, PreferMutLvalue);
+ check_expr_with_lvalue_pref(fcx, &*rcvr, PreferMutLvalue);
// no need to check for bot/err -- callee does that
let expr_t = structurally_resolved_type(fcx,
expr.span,
- fcx.expr_ty(rcvr));
+ fcx.expr_ty(&*rcvr));
- let tps = tps.iter().map(|&ast_ty| fcx.to_ty(ast_ty)).collect::<Vec<_>>();
- let fn_ty = match method::lookup(fcx, expr, rcvr,
+ let tps = tps.iter().map(|ast_ty| fcx.to_ty(&**ast_ty)).collect::<Vec<_>>();
+ let fn_ty = match method::lookup(fcx, expr, &*rcvr,
method_name.node.name,
expr_t, tps.as_slice(),
DontDerefArgs,
// Check for potential static matches (missing self parameters)
method::lookup(fcx,
expr,
- rcvr,
+ &*rcvr,
method_name.node.name,
expr_t,
tps.as_slice(),
fn check_then_else(fcx: &FnCtxt,
cond_expr: &ast::Expr,
then_blk: &ast::Block,
- opt_else_expr: Option<@ast::Expr>,
+ opt_else_expr: Option<Gc<ast::Expr>>,
id: ast::NodeId,
sp: Span,
expected: Option<ty::t>) {
check_expr_has_type(fcx, cond_expr, ty::mk_bool());
let branches_ty = match opt_else_expr {
- Some(else_expr) => {
+ Some(ref else_expr) => {
check_block_with_expected(fcx, then_blk, expected);
let then_ty = fcx.node_ty(then_blk.id);
- check_expr_with_opt_hint(fcx, else_expr, expected);
- let else_ty = fcx.expr_ty(else_expr);
+ check_expr_with_opt_hint(fcx, &**else_expr, expected);
+ let else_ty = fcx.expr_ty(&**else_expr);
infer::common_supertype(fcx.infcx(),
infer::IfExpression(sp),
true,
self_t: ty::t,
opname: ast::Name,
trait_did: Option<ast::DefId>,
- args: &[@ast::Expr],
+ args: &[Gc<ast::Expr>],
autoderef_receiver: AutoderefReceiverFlag,
unbound_method: ||) -> ty::t {
let method = match trait_did {
fn check_binop(fcx: &FnCtxt,
expr: &ast::Expr,
op: ast::BinOp,
- lhs: @ast::Expr,
- rhs: @ast::Expr,
+ lhs: Gc<ast::Expr>,
+ rhs: Gc<ast::Expr>,
is_binop_assignment: IsBinopAssignment) {
let tcx = fcx.ccx.tcx;
BinopAssignment => PreferMutLvalue,
SimpleBinop => NoPreference
};
- check_expr_with_lvalue_pref(fcx, lhs, lvalue_pref);
+ check_expr_with_lvalue_pref(fcx, &*lhs, lvalue_pref);
// Callee does bot / err checking
let lhs_t = structurally_resolved_type(fcx, lhs.span,
- fcx.expr_ty(lhs));
+ fcx.expr_ty(&*lhs));
if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op) {
// Shift is a special case: rhs can be any integral type
- check_expr(fcx, rhs);
- let rhs_t = fcx.expr_ty(rhs);
+ check_expr(fcx, &*rhs);
+ let rhs_t = fcx.expr_ty(&*rhs);
require_integral(fcx, rhs.span, rhs_t);
fcx.write_ty(expr.id, lhs_t);
return;
if ty::is_binopable(tcx, lhs_t, op) {
let tvar = fcx.infcx().next_ty_var();
demand::suptype(fcx, expr.span, tvar, lhs_t);
- check_expr_has_type(fcx, rhs, tvar);
+ check_expr_has_type(fcx, &*rhs, tvar);
let result_t = match op {
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiLe | ast::BiGe |
},
lhs_t,
None);
- check_expr(fcx, rhs);
+ check_expr(fcx, &*rhs);
ty::mk_err()
};
fn check_user_binop(fcx: &FnCtxt,
ex: &ast::Expr,
- lhs_expr: @ast::Expr,
+ lhs_expr: Gc<ast::Expr>,
lhs_resolved_t: ty::t,
op: ast::BinOp,
- rhs: @ast::Expr) -> ty::t {
+ rhs: Gc<ast::Expr>) -> ty::t {
let tcx = fcx.ccx.tcx;
let lang = &tcx.lang_items;
let (name, trait_did) = match op {
ast::BiEq => ("eq", lang.eq_trait()),
ast::BiNe => ("ne", lang.eq_trait()),
ast::BiAnd | ast::BiOr => {
- check_expr(fcx, rhs);
+ check_expr(fcx, &*rhs);
return ty::mk_err();
}
};
mname: &str,
trait_did: Option<ast::DefId>,
ex: &ast::Expr,
- rhs_expr: @ast::Expr,
+ rhs_expr: Gc<ast::Expr>,
rhs_t: ty::t) -> ty::t {
lookup_op_method(fcx, ex, rhs_t, token::intern(mname),
trait_did, [rhs_expr], DontAutoderefReceiver, || {
};
check_fn(fcx.ccx, inherited_style, &fty_sig,
- decl, id, body, fcx.inh);
+ &*decl, id, &*body, fcx.inh);
}
None => {}
}
- let tps: Vec<ty::t> = tys.iter().map(|&ty| fcx.to_ty(ty)).collect();
+ let tps: Vec<ty::t> = tys.iter().map(|ty| fcx.to_ty(&**ty)).collect();
match method::lookup(fcx,
expr,
base,
// an error, so we can continue typechecking
check_expr_coercable_to_type(
fcx,
- field.expr,
+ &*field.expr,
expected_field_type);
}
span: codemap::Span,
class_id: ast::DefId,
fields: &[ast::Field],
- base_expr: Option<@ast::Expr>) {
+ base_expr: Option<Gc<ast::Expr>>) {
let tcx = fcx.ccx.tcx;
// Look up the number of type parameters and the raw type, and
match base_expr {
None => {}
Some(base_expr) => {
- check_expr_has_type(fcx, base_expr, struct_type);
+ check_expr_has_type(fcx, &*base_expr, struct_type);
if ty::type_is_bot(fcx.node_ty(base_expr.id)) {
struct_type = ty::mk_bot();
}
let mut any_bot = false;
let t: ty::t = fcx.infcx().next_ty_var();
for e in args.iter() {
- check_expr_has_type(fcx, *e, t);
- let arg_t = fcx.expr_ty(*e);
+ check_expr_has_type(fcx, &**e, t);
+ let arg_t = fcx.expr_ty(&**e);
if ty::type_is_error(arg_t) {
any_error = true;
}
} else if any_bot {
ty::mk_bot()
} else {
- ast_expr_vstore_to_ty(fcx, ev, vst, ||
+ ast_expr_vstore_to_ty(fcx, &*ev, vst, ||
ty::mt{ ty: ty::mk_vec(tcx,
ty::mt {ty: t, mutbl: mutability},
None),
mutbl: mutability })
}
}
- ast::ExprRepeat(element, count_expr) => {
- check_expr_with_hint(fcx, count_expr, ty::mk_uint());
- let _ = ty::eval_repeat_count(fcx, count_expr);
+ ast::ExprRepeat(ref element, ref count_expr) => {
+ check_expr_with_hint(fcx, &**count_expr, ty::mk_uint());
+ let _ = ty::eval_repeat_count(fcx, &**count_expr);
let mutability = match vst {
ast::ExprVstoreMutSlice => ast::MutMutable,
_ => ast::MutImmutable,
};
let t = fcx.infcx().next_ty_var();
- check_expr_has_type(fcx, element, t);
- let arg_t = fcx.expr_ty(element);
+ check_expr_has_type(fcx, &**element, t);
+ let arg_t = fcx.expr_ty(&**element);
if ty::type_is_error(arg_t) {
ty::mk_err()
} else if ty::type_is_bot(arg_t) {
ty::mk_bot()
} else {
- ast_expr_vstore_to_ty(fcx, ev, vst, ||
+ ast_expr_vstore_to_ty(fcx, &*ev, vst, ||
ty::mt{ ty: ty::mk_vec(tcx,
ty::mt {ty: t, mutbl: mutability},
None),
fcx.write_ty(id, typ);
}
- ast::ExprBox(place, subexpr) => {
- check_expr(fcx, place);
- check_expr(fcx, subexpr);
+ ast::ExprBox(ref place, ref subexpr) => {
+ check_expr(fcx, &**place);
+ check_expr(fcx, &**subexpr);
let mut checked = false;
match place.node {
}
}
- ast::ExprLit(lit) => {
- let typ = check_lit(fcx, lit);
+ ast::ExprLit(ref lit) => {
+ let typ = check_lit(fcx, &**lit);
fcx.write_ty(id, typ);
}
- ast::ExprBinary(op, lhs, rhs) => {
- check_binop(fcx, expr, op, lhs, rhs, SimpleBinop);
+ ast::ExprBinary(op, ref lhs, ref rhs) => {
+ check_binop(fcx, expr, op, lhs.clone(), rhs.clone(), SimpleBinop);
- let lhs_ty = fcx.expr_ty(lhs);
- let rhs_ty = fcx.expr_ty(rhs);
+ let lhs_ty = fcx.expr_ty(&**lhs);
+ let rhs_ty = fcx.expr_ty(&**rhs);
if ty::type_is_error(lhs_ty) ||
ty::type_is_error(rhs_ty) {
fcx.write_error(id);
fcx.write_bot(id);
}
}
- ast::ExprAssignOp(op, lhs, rhs) => {
- check_binop(fcx, expr, op, lhs, rhs, BinopAssignment);
+ ast::ExprAssignOp(op, ref lhs, ref rhs) => {
+ check_binop(fcx, expr, op, lhs.clone(), rhs.clone(), BinopAssignment);
- let lhs_t = fcx.expr_ty(lhs);
+ let lhs_t = fcx.expr_ty(&**lhs);
let result_t = fcx.expr_ty(expr);
demand::suptype(fcx, expr.span, result_t, lhs_t);
let tcx = fcx.tcx();
- if !ty::expr_is_lval(tcx, lhs) {
+ if !ty::expr_is_lval(tcx, &**lhs) {
tcx.sess.span_err(lhs.span, "illegal left-hand side expression");
}
fcx.write_nil(expr.id);
}
}
- ast::ExprUnary(unop, oprnd) => {
+ ast::ExprUnary(unop, ref oprnd) => {
let exp_inner = unpack_expected(fcx, expected, |sty| {
match unop {
ast::UnBox | ast::UnUniq => match *sty {
ast::UnDeref => lvalue_pref,
_ => NoPreference
};
- check_expr_with_opt_hint_and_lvalue_pref(fcx, oprnd, exp_inner, lvalue_pref);
- let mut oprnd_t = fcx.expr_ty(oprnd);
+ check_expr_with_opt_hint_and_lvalue_pref(fcx, &**oprnd, exp_inner, lvalue_pref);
+ let mut oprnd_t = fcx.expr_ty(&**oprnd);
if !ty::type_is_error(oprnd_t) && !ty::type_is_bot(oprnd_t) {
match unop {
ast::UnBox => {
Some(mt) => mt.ty,
None => match try_overloaded_deref(fcx, expr.span,
Some(MethodCall::expr(expr.id)),
- Some(&*oprnd), oprnd_t, lvalue_pref) {
+ Some(&**oprnd), oprnd_t, lvalue_pref) {
Some(mt) => mt.ty,
None => {
let is_newtype = match ty::get(oprnd_t).sty {
ty::get(oprnd_t).sty == ty::ty_bool) {
oprnd_t = check_user_unop(fcx, "!", "not",
tcx.lang_items.not_trait(),
- expr, oprnd, oprnd_t);
+ expr, oprnd.clone(), oprnd_t);
}
}
ast::UnNeg => {
ty::type_is_fp(oprnd_t)) {
oprnd_t = check_user_unop(fcx, "-", "neg",
tcx.lang_items.neg_trait(),
- expr, oprnd, oprnd_t);
+ expr, oprnd.clone(), oprnd_t);
}
}
}
}
fcx.write_ty(id, oprnd_t);
}
- ast::ExprAddrOf(mutbl, oprnd) => {
+ ast::ExprAddrOf(mutbl, ref oprnd) => {
let hint = unpack_expected(
fcx, expected,
|sty| match *sty { ty::ty_rptr(_, ref mt) => Some(mt.ty),
ast::MutMutable => PreferMutLvalue,
ast::MutImmutable => NoPreference
};
- check_expr_with_opt_hint_and_lvalue_pref(fcx, oprnd, hint, lvalue_pref);
+ check_expr_with_opt_hint_and_lvalue_pref(fcx, &**oprnd, hint, lvalue_pref);
// Note: at this point, we cannot say what the best lifetime
// is to use for resulting pointer. We want to use the
let region = fcx.infcx().next_region_var(
infer::AddrOfRegion(expr.span));
- let tm = ty::mt { ty: fcx.expr_ty(oprnd), mutbl: mutbl };
+ let tm = ty::mt { ty: fcx.expr_ty(&**oprnd), mutbl: mutbl };
let oprnd_t = if ty::type_is_error(tm.ty) {
ty::mk_err()
} else if ty::type_is_bot(tm.ty) {
instantiate_path(fcx, pth, tpt, defn, expr.span, expr.id);
}
ast::ExprInlineAsm(ref ia) => {
- for &(_, input) in ia.inputs.iter() {
- check_expr(fcx, input);
+ for &(_, ref input) in ia.inputs.iter() {
+ check_expr(fcx, &**input);
}
- for &(_, out) in ia.outputs.iter() {
- check_expr(fcx, out);
+ for &(_, ref out) in ia.outputs.iter() {
+ check_expr(fcx, &**out);
}
fcx.write_nil(id);
}
ast::ExprMac(_) => tcx.sess.bug("unexpanded macro"),
ast::ExprBreak(_) => { fcx.write_bot(id); }
ast::ExprAgain(_) => { fcx.write_bot(id); }
- ast::ExprRet(expr_opt) => {
+ ast::ExprRet(ref expr_opt) => {
let ret_ty = fcx.ret_ty;
- match expr_opt {
+ match *expr_opt {
None => match fcx.mk_eqty(false, infer::Misc(expr.span),
ret_ty, ty::mk_nil()) {
Ok(_) => { /* fall through */ }
"`return;` in function returning non-nil");
}
},
- Some(e) => {
- check_expr_has_type(fcx, e, ret_ty);
+ Some(ref e) => {
+ check_expr_has_type(fcx, &**e, ret_ty);
}
}
fcx.write_bot(id);
}
- ast::ExprParen(a) => {
- check_expr_with_opt_hint_and_lvalue_pref(fcx, a, expected, lvalue_pref);
- fcx.write_ty(id, fcx.expr_ty(a));
+ ast::ExprParen(ref a) => {
+ check_expr_with_opt_hint_and_lvalue_pref(fcx, &**a, expected, lvalue_pref);
+ fcx.write_ty(id, fcx.expr_ty(&**a));
}
- ast::ExprAssign(lhs, rhs) => {
- check_expr_with_lvalue_pref(fcx, lhs, PreferMutLvalue);
+ ast::ExprAssign(ref lhs, ref rhs) => {
+ check_expr_with_lvalue_pref(fcx, &**lhs, PreferMutLvalue);
let tcx = fcx.tcx();
- if !ty::expr_is_lval(tcx, lhs) {
+ if !ty::expr_is_lval(tcx, &**lhs) {
tcx.sess.span_err(lhs.span, "illegal left-hand side expression");
}
- let lhs_ty = fcx.expr_ty(lhs);
- check_expr_has_type(fcx, rhs, lhs_ty);
- let rhs_ty = fcx.expr_ty(rhs);
+ let lhs_ty = fcx.expr_ty(&**lhs);
+ check_expr_has_type(fcx, &**rhs, lhs_ty);
+ let rhs_ty = fcx.expr_ty(&**rhs);
if ty::type_is_error(lhs_ty) || ty::type_is_error(rhs_ty) {
fcx.write_error(id);
fcx.write_nil(id);
}
}
- ast::ExprIf(cond, then_blk, opt_else_expr) => {
- check_then_else(fcx, cond, then_blk, opt_else_expr,
+ ast::ExprIf(ref cond, ref then_blk, ref opt_else_expr) => {
+ check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.clone(),
id, expr.span, expected);
}
- ast::ExprWhile(cond, body) => {
- check_expr_has_type(fcx, cond, ty::mk_bool());
- check_block_no_value(fcx, body);
- let cond_ty = fcx.expr_ty(cond);
+ ast::ExprWhile(ref cond, ref body) => {
+ check_expr_has_type(fcx, &**cond, ty::mk_bool());
+ check_block_no_value(fcx, &**body);
+ let cond_ty = fcx.expr_ty(&**cond);
let body_ty = fcx.node_ty(body.id);
if ty::type_is_error(cond_ty) || ty::type_is_error(body_ty) {
fcx.write_error(id);
}
ast::ExprForLoop(..) =>
fail!("non-desugared expr_for_loop"),
- ast::ExprLoop(body, _) => {
- check_block_no_value(fcx, (body));
- if !may_break(tcx, expr.id, body) {
+ ast::ExprLoop(ref body, _) => {
+ check_block_no_value(fcx, &**body);
+ if !may_break(tcx, expr.id, body.clone()) {
fcx.write_bot(id);
}
else {
fcx.write_nil(id);
}
}
- ast::ExprMatch(discrim, ref arms) => {
- _match::check_match(fcx, expr, discrim, arms.as_slice());
+ ast::ExprMatch(ref discrim, ref arms) => {
+ _match::check_match(fcx, expr, &**discrim, arms.as_slice());
}
- ast::ExprFnBlock(decl, body) => {
+ ast::ExprFnBlock(ref decl, ref body) => {
let region = astconv::opt_ast_region_to_region(fcx,
fcx.infcx(),
expr.span,
check_expr_fn(fcx,
expr,
ty::RegionTraitStore(region, ast::MutMutable),
- decl,
- body,
+ &**decl,
+ body.clone(),
expected);
}
- ast::ExprProc(decl, body) => {
+ ast::ExprProc(ref decl, ref body) => {
check_expr_fn(fcx,
expr,
ty::UniqTraitStore,
- decl,
- body,
+ &**decl,
+ body.clone(),
expected);
}
- ast::ExprBlock(b) => {
- check_block_with_expected(fcx, b, expected);
+ ast::ExprBlock(ref b) => {
+ check_block_with_expected(fcx, &**b, expected);
fcx.write_ty(id, fcx.node_ty(b.id));
}
- ast::ExprCall(f, ref args) => {
+ ast::ExprCall(ref f, ref args) => {
// Index expressions need to be handled separately, to inform them
// that they appear in call position.
- check_expr(fcx, f);
- let f_ty = fcx.expr_ty(f);
+ check_expr(fcx, &**f);
+ let f_ty = fcx.expr_ty(&**f);
- if !try_overloaded_call(fcx, expr, f, f_ty, args.as_slice()) {
- check_call(fcx, expr, f, args.as_slice());
+ if !try_overloaded_call(fcx, expr, f.clone(), f_ty, args.as_slice()) {
+ check_call(fcx, expr, &**f, args.as_slice());
let (args_bot, args_err) = args.iter().fold((false, false),
|(rest_bot, rest_err), a| {
// is this not working?
- let a_ty = fcx.expr_ty(*a);
+ let a_ty = fcx.expr_ty(&**a);
(rest_bot || ty::type_is_bot(a_ty),
rest_err || ty::type_is_error(a_ty))});
if ty::type_is_error(f_ty) || args_err {
}
ast::ExprMethodCall(ident, ref tps, ref args) => {
check_method_call(fcx, expr, ident, args.as_slice(), tps.as_slice());
- let mut arg_tys = args.iter().map(|a| fcx.expr_ty(*a));
+ let mut arg_tys = args.iter().map(|a| fcx.expr_ty(&**a));
let (args_bot, args_err) = arg_tys.fold((false, false),
|(rest_bot, rest_err), a| {
(rest_bot || ty::type_is_bot(a),
fcx.write_bot(id);
}
}
- ast::ExprCast(e, t) => {
- check_expr(fcx, e);
- let t_1 = fcx.to_ty(t);
- let t_e = fcx.expr_ty(e);
+ ast::ExprCast(ref e, ref t) => {
+ check_expr(fcx, &**e);
+ let t_1 = fcx.to_ty(&**t);
+ let t_e = fcx.expr_ty(&**e);
debug!("t_1={}", fcx.infcx().ty_to_str(t_1));
debug!("t_e={}", fcx.infcx().ty_to_str(t_e));
/* this case is allowed */
}
_ => {
- demand::coerce(fcx, e.span, t_1, e);
+ demand::coerce(fcx, e.span, t_1, &**e);
}
}
} else if !(type_is_scalar(fcx,expr.span,t_e)
ast::ExprVec(ref args) => {
let t: ty::t = fcx.infcx().next_ty_var();
for e in args.iter() {
- check_expr_has_type(fcx, *e, t);
+ check_expr_has_type(fcx, &**e, t);
}
let typ = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: ast::MutImmutable},
Some(args.len()));
fcx.write_ty(id, typ);
}
- ast::ExprRepeat(element, count_expr) => {
- check_expr_with_hint(fcx, count_expr, ty::mk_uint());
- let count = ty::eval_repeat_count(fcx, count_expr);
+ ast::ExprRepeat(ref element, ref count_expr) => {
+ check_expr_with_hint(fcx, &**count_expr, ty::mk_uint());
+ let count = ty::eval_repeat_count(fcx, &**count_expr);
let t: ty::t = fcx.infcx().next_ty_var();
- check_expr_has_type(fcx, element, t);
- let element_ty = fcx.expr_ty(element);
+ check_expr_has_type(fcx, &**element, t);
+ let element_ty = fcx.expr_ty(&**element);
if ty::type_is_error(element_ty) {
fcx.write_error(id);
}
Some(ref fs) if i < fs.len() => Some(*fs.get(i)),
_ => None
};
- check_expr_with_opt_hint(fcx, *e, opt_hint);
- let t = fcx.expr_ty(*e);
+ check_expr_with_opt_hint(fcx, &**e, opt_hint);
+ let t = fcx.expr_ty(&**e);
err_field = err_field || ty::type_is_error(t);
bot_field = bot_field || ty::type_is_bot(t);
t
}
}
}
- ast::ExprField(base, field, ref tys) => {
- check_field(fcx, expr, lvalue_pref, base, field.name, tys.as_slice());
+ ast::ExprField(ref base, ref field, ref tys) => {
+ check_field(fcx, expr, lvalue_pref, &**base, field.name, tys.as_slice());
}
- ast::ExprIndex(base, idx) => {
- check_expr_with_lvalue_pref(fcx, base, lvalue_pref);
- check_expr(fcx, idx);
- let raw_base_t = fcx.expr_ty(base);
- let idx_t = fcx.expr_ty(idx);
+ ast::ExprIndex(ref base, ref idx) => {
+ check_expr_with_lvalue_pref(fcx, &**base, lvalue_pref);
+ check_expr(fcx, &**idx);
+ let raw_base_t = fcx.expr_ty(&**base);
+ let idx_t = fcx.expr_ty(&**idx);
if ty::type_is_error(raw_base_t) || ty::type_is_bot(raw_base_t) {
fcx.write_ty(id, raw_base_t);
} else if ty::type_is_error(idx_t) || ty::type_is_bot(idx_t) {
lvalue_pref, |base_t, _| ty::index(base_t));
match field_ty {
Some(mt) => {
- check_expr_has_type(fcx, idx, ty::mk_uint());
+ check_expr_has_type(fcx, &**idx, ty::mk_uint());
fcx.write_ty(id, mt.ty);
fcx.write_autoderef_adjustment(base.id, autoderefs);
}
resolved,
token::intern("index"),
tcx.lang_items.index_trait(),
- [base, idx],
+ [base.clone(), idx.clone()],
AutoderefReceiver,
|| {
fcx.type_error_message(expr.span,
fcx.write_ty(local.id, t);
match local.init {
- Some(init) => {
- check_decl_initializer(fcx, local.id, init);
- let init_ty = fcx.expr_ty(init);
+ Some(ref init) => {
+ check_decl_initializer(fcx, local.id, &**init);
+ let init_ty = fcx.expr_ty(&**init);
if ty::type_is_error(init_ty) || ty::type_is_bot(init_ty) {
fcx.write_ty(local.id, init_ty);
}
let pcx = pat_ctxt {
fcx: fcx,
- map: pat_id_map(&tcx.def_map, local.pat),
+ map: pat_id_map(&tcx.def_map, &*local.pat),
};
- _match::check_pat(&pcx, local.pat, t);
+ _match::check_pat(&pcx, &*local.pat, t);
let pat_ty = fcx.node_ty(local.pat.id);
if ty::type_is_error(pat_ty) || ty::type_is_bot(pat_ty) {
fcx.write_ty(local.id, pat_ty);
node_id = id;
match decl.node {
ast::DeclLocal(ref l) => {
- check_decl_local(fcx, *l);
+ check_decl_local(fcx, &**l);
let l_t = fcx.node_ty(l.id);
saw_bot = saw_bot || ty::type_is_bot(l_t);
saw_err = saw_err || ty::type_is_error(l_t);
ast::DeclItem(_) => {/* ignore for now */ }
}
}
- ast::StmtExpr(expr, id) => {
+ ast::StmtExpr(ref expr, id) => {
node_id = id;
// Check with expected type of ()
- check_expr_has_type(fcx, expr, ty::mk_nil());
- let expr_ty = fcx.expr_ty(expr);
+ check_expr_has_type(fcx, &**expr, ty::mk_nil());
+ let expr_ty = fcx.expr_ty(&**expr);
saw_bot = saw_bot || ty::type_is_bot(expr_ty);
saw_err = saw_err || ty::type_is_error(expr_ty);
}
- ast::StmtSemi(expr, id) => {
+ ast::StmtSemi(ref expr, id) => {
node_id = id;
- check_expr(fcx, expr);
- let expr_ty = fcx.expr_ty(expr);
+ check_expr(fcx, &**expr);
+ let expr_ty = fcx.expr_ty(&**expr);
saw_bot |= ty::type_is_bot(expr_ty);
saw_err |= ty::type_is_error(expr_ty);
}
let mut any_bot = false;
let mut any_err = false;
for s in blk.stmts.iter() {
- check_stmt(fcx, *s);
- let s_id = ast_util::stmt_id(*s);
+ check_stmt(fcx, &**s);
+ let s_id = ast_util::stmt_id(&**s);
let s_ty = fcx.node_ty(s_id);
if last_was_bot && !warned && match s.node {
ast::StmtDecl(decl, _) => {
e.span,
"unreachable expression".to_string());
}
- check_expr_with_opt_hint(fcx, e, expected);
- let ety = fcx.expr_ty(e);
+ check_expr_with_opt_hint(fcx, &*e, expected);
+ let ety = fcx.expr_ty(&*e);
fcx.write_ty(blk.id, ety);
if any_err {
fcx.write_error(blk.id);
}
}
},
- ast::StructVariantKind(struct_def) => check_fields_sized(ccx.tcx, struct_def),
+ ast::StructVariantKind(struct_def) => check_fields_sized(ccx.tcx, &*struct_def),
_ => {}
}
}
match v.node.disr_expr {
Some(e) => {
- debug!("disr expr, checking {}", pprust::expr_to_str(e));
+ debug!("disr expr, checking {}", pprust::expr_to_str(&*e));
let inh = blank_inherited_fields(ccx);
let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id);
let declty = ty::mk_int_var(ccx.tcx, fcx.infcx().next_int_var_id());
- check_const_with_ty(&fcx, e.span, e, declty);
+ check_const_with_ty(&fcx, e.span, &*e, declty);
// check_expr (from check_const pass) doesn't guarantee
// that the expression is in a form that eval_const_expr can
// handle, so we may still get an internal compiler error
- match const_eval::eval_const_expr_partial(ccx.tcx, e) {
+ match const_eval::eval_const_expr_partial(ccx.tcx, &*e) {
Ok(const_eval::const_int(val)) => current_disr_val = val as Disr,
Ok(const_eval::const_uint(val)) => current_disr_val = val as Disr,
Ok(_) => {
}
disr_vals.push(current_disr_val);
- let variant_info = Rc::new(VariantInfo::from_ast_variant(ccx.tcx, v,
+ let variant_info = Rc::new(VariantInfo::from_ast_variant(ccx.tcx, &*v,
current_disr_val));
prev_disr_val = Some(current_disr_val);
let mut pushed = false;
for (i, ty) in pth.segments.iter()
.flat_map(|segment| segment.types.iter())
- .map(|&ast_type| fcx.to_ty(ast_type))
+ .map(|ast_type| fcx.to_ty(&**ast_type))
.enumerate() {
match self_parameter_index {
Some(index) if index == i => {
pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: ast::P<ast::Block>) -> bool {
// First: is there an unlabeled break immediately
// inside the loop?
- (loop_query(b, |e| {
+ (loop_query(&*b, |e| {
match *e {
ast::ExprBreak(_) => true,
_ => false
use syntax::visit::Visitor;
use std::cell::RefCell;
+use std::gc::Gc;
// If mem categorization results in an error, it's because the type
// check failed (or will fail, when the error is uncovered and
fn visit_arm(rcx: &mut Rcx, arm: &ast::Arm) {
// see above
- for &p in arm.pats.iter() {
- constrain_bindings_in_pat(p, rcx);
+ for p in arm.pats.iter() {
+ constrain_bindings_in_pat(&**p, rcx);
}
visit::walk_arm(rcx, arm, ());
fn visit_local(rcx: &mut Rcx, l: &ast::Local) {
// see above
- constrain_bindings_in_pat(l.pat, rcx);
+ constrain_bindings_in_pat(&*l.pat, rcx);
link_local(rcx, l);
visit::walk_local(rcx, l, ());
}
}
match expr.node {
- ast::ExprCall(callee, ref args) => {
+ ast::ExprCall(ref callee, ref args) => {
if !has_method_map {
- constrain_callee(rcx, callee.id, expr, callee);
+ constrain_callee(rcx, callee.id, expr, &**callee);
constrain_call(rcx,
Some(callee.id),
expr,
visit::walk_expr(rcx, expr, ());
}
- ast::ExprAssign(lhs, _) => {
- adjust_borrow_kind_for_assignment_lhs(rcx, lhs);
+ ast::ExprAssign(ref lhs, _) => {
+ adjust_borrow_kind_for_assignment_lhs(rcx, &**lhs);
visit::walk_expr(rcx, expr, ());
}
- ast::ExprAssignOp(_, lhs, rhs) => {
+ ast::ExprAssignOp(_, ref lhs, ref rhs) => {
if has_method_map {
- constrain_call(rcx, None, expr, Some(lhs), [rhs], true);
+ constrain_call(rcx, None, expr, Some(lhs.clone()),
+ [rhs.clone()], true);
}
- adjust_borrow_kind_for_assignment_lhs(rcx, lhs);
+ adjust_borrow_kind_for_assignment_lhs(rcx, &**lhs);
visit::walk_expr(rcx, expr, ());
}
- ast::ExprIndex(lhs, rhs) |
- ast::ExprBinary(_, lhs, rhs) if has_method_map => {
+ ast::ExprIndex(ref lhs, ref rhs) |
+ ast::ExprBinary(_, ref lhs, ref rhs) if has_method_map => {
// As `expr_method_call`, but the call is via an
// overloaded op. Note that we (sadly) currently use an
// implicit "by ref" sort of passing style here. This
// should be converted to an adjustment!
- constrain_call(rcx, None, expr, Some(lhs), [rhs], true);
+ constrain_call(rcx, None, expr, Some(lhs.clone()),
+ [rhs.clone()], true);
visit::walk_expr(rcx, expr, ());
}
- ast::ExprUnary(_, lhs) if has_method_map => {
+ ast::ExprUnary(_, ref lhs) if has_method_map => {
// As above.
- constrain_call(rcx, None, expr, Some(lhs), [], true);
+ constrain_call(rcx, None, expr, Some(lhs.clone()), [], true);
visit::walk_expr(rcx, expr, ());
}
- ast::ExprUnary(ast::UnDeref, base) => {
+ ast::ExprUnary(ast::UnDeref, ref base) => {
// For *a, the lifetime of a must enclose the deref
let method_call = MethodCall::expr(expr.id);
let base_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) {
Some(method) => {
- constrain_call(rcx, None, expr, Some(base), [], true);
+ constrain_call(rcx, None, expr, Some(base.clone()), [], true);
ty::ty_fn_ret(method.ty)
}
None => rcx.resolve_node_type(base.id)
visit::walk_expr(rcx, expr, ());
}
- ast::ExprIndex(vec_expr, _) => {
+ ast::ExprIndex(ref vec_expr, _) => {
// For a[b], the lifetime of a must enclose the deref
- let vec_type = rcx.resolve_expr_type_adjusted(vec_expr);
+ let vec_type = rcx.resolve_expr_type_adjusted(&**vec_expr);
constrain_index(rcx, expr, vec_type);
visit::walk_expr(rcx, expr, ());
}
- ast::ExprCast(source, _) => {
+ ast::ExprCast(ref source, _) => {
// Determine if we are casting `source` to a trait
// instance. If so, we have to be sure that the type of
// the source obeys the trait's region bound.
ty::ty_trait(box ty::TyTrait {
store: ty::RegionTraitStore(trait_region, _), ..
}) => {
- let source_ty = rcx.resolve_expr_type_adjusted(source);
+ let source_ty = rcx.resolve_expr_type_adjusted(&**source);
constrain_regions_in_type(
rcx,
trait_region,
visit::walk_expr(rcx, expr, ());
}
- ast::ExprAddrOf(m, base) => {
- link_addr_of(rcx, expr, m, base);
+ ast::ExprAddrOf(m, ref base) => {
+ link_addr_of(rcx, expr, m, &**base);
// Require that when you write a `&expr` expression, the
// resulting pointer has a lifetime that encompasses the
visit::walk_expr(rcx, expr, ());
}
- ast::ExprMatch(discr, ref arms) => {
- link_match(rcx, discr, arms.as_slice());
+ ast::ExprMatch(ref discr, ref arms) => {
+ link_match(rcx, &**discr, arms.as_slice());
visit::walk_expr(rcx, expr, ());
}
check_expr_fn_block(rcx, expr, &**body);
}
- ast::ExprLoop(body, _) => {
+ ast::ExprLoop(ref body, _) => {
let repeating_scope = rcx.set_repeating_scope(body.id);
visit::walk_expr(rcx, expr, ());
rcx.set_repeating_scope(repeating_scope);
}
- ast::ExprWhile(cond, body) => {
+ ast::ExprWhile(ref cond, ref body) => {
let repeating_scope = rcx.set_repeating_scope(cond.id);
- rcx.visit_expr(cond, ());
+ rcx.visit_expr(&**cond, ());
rcx.set_repeating_scope(body.id);
- rcx.visit_block(body, ());
+ rcx.visit_block(&**body, ());
rcx.set_repeating_scope(repeating_scope);
}
// operator
fn_expr_id: Option<ast::NodeId>,
call_expr: &ast::Expr,
- receiver: Option<@ast::Expr>,
- arg_exprs: &[@ast::Expr],
+ receiver: Option<Gc<ast::Expr>>,
+ arg_exprs: &[Gc<ast::Expr>],
implicitly_ref_args: bool) {
//! Invoked on every call site (i.e., normal calls, method calls,
//! and overloaded operators). Constrains the regions which appear
let callee_scope = call_expr.id;
let callee_region = ty::ReScope(callee_scope);
- for &arg_expr in arg_exprs.iter() {
+ for arg_expr in arg_exprs.iter() {
debug!("Argument");
// ensure that any regions appearing in the argument type are
// result. modes are going away and the "DerefArgs" code
// should be ported to use adjustments
if implicitly_ref_args {
- link_by_ref(rcx, arg_expr, callee_scope);
+ link_by_ref(rcx, &**arg_expr, callee_scope);
}
}
// as loop above, but for receiver
- for &r in receiver.iter() {
+ for r in receiver.iter() {
debug!("Receiver");
constrain_regions_in_type_of_node(
rcx, r.id, callee_region, infer::CallRcvr(r.span));
if implicitly_ref_args {
- link_by_ref(rcx, r, callee_scope);
+ link_by_ref(rcx, &**r, callee_scope);
}
}
debug!("regionck::for_local()");
let init_expr = match local.init {
None => { return; }
- Some(expr) => expr,
+ Some(ref expr) => expr,
};
let mc = mc::MemCategorizationContext::new(rcx);
- let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
- link_pattern(rcx, mc, discr_cmt, local.pat);
+ let discr_cmt = ignore_err!(mc.cat_expr(&**init_expr));
+ link_pattern(rcx, mc, discr_cmt, &*local.pat);
}
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
let discr_cmt = ignore_err!(mc.cat_expr(discr));
debug!("discr_cmt={}", discr_cmt.repr(rcx.tcx()));
for arm in arms.iter() {
- for &root_pat in arm.pats.iter() {
- link_pattern(rcx, mc, discr_cmt.clone(), root_pat);
+ for root_pat in arm.pats.iter() {
+ link_pattern(rcx, mc, discr_cmt.clone(), &**root_pat);
}
}
}
}
// `[_, ..slice, _]` pattern
- ast::PatVec(_, Some(slice_pat), _) => {
- match mc.cat_slice_pattern(sub_cmt, slice_pat) {
+ ast::PatVec(_, Some(ref slice_pat), _) => {
+ match mc.cat_slice_pattern(sub_cmt, &**slice_pat) {
Ok((slice_cmt, slice_mutbl, slice_r)) => {
link_region(rcx, sub_pat.span, slice_r,
ty::BorrowKind::from_mutbl(slice_mutbl),
None => {}
}
}
- ast::ExprCast(src, _) => {
+ ast::ExprCast(ref src, _) => {
debug!("vtable resolution on expr {}", ex.repr(fcx.tcx()));
let target_ty = fcx.expr_ty(ex);
- resolve_object_cast(src, target_ty);
+ resolve_object_cast(&**src, target_ty);
}
_ => ()
}
let mut wbcx = WritebackCx::new(fcx);
wbcx.visit_block(blk, ());
for arg in decl.inputs.iter() {
- wbcx.visit_pat(arg.pat, ());
+ wbcx.visit_pat(&*arg.pat, ());
// Privacy needs the type for the whole pattern, not just each binding
- if !pat_util::pat_is_binding(&fcx.tcx().def_map, arg.pat) {
+ if !pat_util::pat_is_binding(&fcx.tcx().def_map, &*arg.pat) {
wbcx.visit_node_id(ResolvingPattern(arg.pat.span),
arg.pat.id);
}
// Then visit the module items.
visit::walk_mod(self, module_, ());
}
- ItemImpl(_, None, ast_ty, _) => {
- if !self.cc.ast_type_is_defined_in_local_crate(ast_ty) {
+ ItemImpl(_, None, ref ast_ty, _) => {
+ if !self.cc.ast_type_is_defined_in_local_crate(&**ast_ty) {
// This is an error.
let session = &self.cc.crate_context.tcx.sess;
session.span_err(item.span,
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
+use std::gc::Gc;
+
use syntax::abi;
use syntax::ast::{StaticRegionTyParamBound, OtherRegionTyParamBound};
use syntax::ast::{TraitTyParamBound, UnboxedFnTyParamBound};
}
match self.tcx.map.find(id.node) {
- Some(ast_map::NodeItem(item)) => ty_of_item(self, item),
+ Some(ast_map::NodeItem(item)) => ty_of_item(self, &*item),
Some(ast_map::NodeForeignItem(foreign_item)) => {
let abi = self.tcx.map.get_foreign_abi(id.node);
- ty_of_foreign_item(self, foreign_item, abi)
+ ty_of_foreign_item(self, &*foreign_item, abi)
}
x => {
self.tcx.sess.bug(format!("unexpected sort of node \
let result_ty = match variant.node.kind {
ast::TupleVariantKind(ref args) if args.len() > 0 => {
let rs = ExplicitRscope;
- let input_tys: Vec<_> = args.iter().map(|va| ccx.to_ty(&rs, va.ty)).collect();
+ let input_tys: Vec<_> = args.iter().map(|va| ccx.to_ty(&rs, &*va.ty)).collect();
ty::mk_ctor_fn(tcx, scope, input_tys.as_slice(), enum_ty)
}
ty: enum_ty
};
- convert_struct(ccx, struct_def, tpt, variant.node.id);
+ convert_struct(ccx, &*struct_def, tpt, variant.node.id);
let input_tys: Vec<_> = struct_def.fields.iter().map(
|f| ty::node_id_to_type(ccx.tcx, f.node.id)).collect();
ty_method_of_trait_method(
ccx, trait_id, &trait_ty_generics,
&m.id, &m.ident, &m.explicit_self,
- &m.generics, &m.fn_style, m.decl)
+ &m.generics, &m.fn_style, &*m.decl)
}
&ast::Provided(ref m) => {
ty_method_of_trait_method(
ccx, trait_id, &trait_ty_generics,
&m.id, &m.ident, &m.explicit_self,
- &m.generics, &m.fn_style, m.decl)
+ &m.generics, &m.fn_style, &*m.decl)
}
});
struct_generics: &ty::Generics,
v: &ast::StructField,
origin: ast::DefId) -> ty::field_ty {
- let tt = ccx.to_ty(&ExplicitRscope, v.node.ty);
+ let tt = ccx.to_ty(&ExplicitRscope, &*v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */
ccx.tcx.tcache.borrow_mut().insert(local_def(v.node.id),
fn convert_methods(ccx: &CrateCtxt,
container: MethodContainer,
- ms: &[@ast::Method],
+ ms: &[Gc<ast::Method>],
untransformed_rcvr_ty: ty::t,
rcvr_ty_generics: &ty::Generics,
rcvr_ast_generics: &ast::Generics,
num_rcvr_ty_params);
let mty = Rc::new(ty_of_method(ccx,
container,
- *m,
+ &**m,
untransformed_rcvr_ty,
rcvr_ast_generics,
rcvr_visibility));
{
let fty = astconv::ty_of_method(ccx, m.id, m.fn_style,
untransformed_rcvr_ty,
- m.explicit_self, m.decl);
+ m.explicit_self, &*m.decl);
// if the method specifies a visibility, use that, otherwise
// inherit the visibility from the impl (so `foo` in `pub impl
},
ast::ItemImpl(ref generics, ref opt_trait_ref, selfty, ref ms) => {
let ty_generics = ty_generics_for_type(ccx, generics);
- let selfty = ccx.to_ty(&ExplicitRscope, selfty);
+ let selfty = ccx.to_ty(&ExplicitRscope, &*selfty);
write_ty_to_tcx(tcx, it.id, selfty);
tcx.tcache.borrow_mut().insert(local_def(it.id),
// Write the super-struct type, if it exists.
match struct_def.super_struct {
Some(ty) => {
- let supserty = ccx.to_ty(&ExplicitRscope, ty);
+ let supserty = ccx.to_ty(&ExplicitRscope, &*ty);
write_ty_to_tcx(tcx, it.id, supserty);
},
_ => {},
}
- convert_struct(ccx, struct_def, tpt, it.id);
+ convert_struct(ccx, &*struct_def, tpt, it.id);
},
ast::ItemTy(_, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
}
match ccx.tcx.map.get(trait_id.node) {
- ast_map::NodeItem(item) => trait_def_of_item(ccx, item),
+ ast_map::NodeItem(item) => trait_def_of_item(ccx, &*item),
_ => {
ccx.tcx.sess.bug(format!("get_trait_def({}): not an item",
trait_id.node).as_slice())
}
match it.node {
ast::ItemStatic(t, _, _) => {
- let typ = ccx.to_ty(&ExplicitRscope, t);
+ let typ = ccx.to_ty(&ExplicitRscope, &*t);
let tpt = no_params(typ);
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
it.id,
fn_style,
abi,
- decl);
+ &*decl);
let tpt = ty_param_bounds_and_ty {
generics: ty_generics,
ty: ty::mk_bare_fn(ccx.tcx, tofd)
}
let tpt = {
- let ty = ccx.to_ty(&ExplicitRscope, t);
+ let ty = ccx.to_ty(&ExplicitRscope, &*t);
ty_param_bounds_and_ty {
generics: ty_generics_for_type(ccx, generics),
ty: ty
match it.node {
ast::ForeignItemFn(fn_decl, ref generics) => {
ty_of_foreign_fn_decl(ccx,
- fn_decl,
+ &*fn_decl,
local_def(it.id),
generics,
abi)
type_param_defs: Rc::new(Vec::new()),
region_param_defs: Rc::new(Vec::new()),
},
- ty: ast_ty_to_ty(ccx, &ExplicitRscope, t)
+ ty: ast_ty_to_ty(ccx, &ExplicitRscope, &*t)
}
}
}
param.ident,
param.span));
let default = param.default.map(|path| {
- let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
+ let ty = ast_ty_to_ty(ccx, &ExplicitRscope, &*path);
let cur_idx = param_ty.idx;
ty::walk_ty(ty, |t| {
.map(|a| ty_of_arg(ccx, &rb, a, None))
.collect();
- let output_ty = ast_ty_to_ty(ccx, &rb, decl.output);
+ let output_ty = ast_ty_to_ty(ccx, &rb, &*decl.output);
let t_fn = ty::mk_bare_fn(
ccx.tcx,
}
ref other => other.clone()
};
- @ast::Ty { id: from.id, node: new_node, span: from.span }
+ box(GC) ast::Ty { id: from.id, node: new_node, span: from.span }
}
let new_ty_node = match to.node {
}
_ => fail!("expect ast::TyRptr or ast::TyPath")
};
- let new_ty = @ast::Ty {
+ let new_ty = box(GC) ast::Ty {
id: to.id,
node: new_ty_node,
span: to.span
// `ty::VariantInfo::from_ast_variant()` ourselves
// here, mainly so as to mask the differences between
// struct-like enums and so forth.
- for &ast_variant in enum_definition.variants.iter() {
+ for ast_variant in enum_definition.variants.iter() {
let variant =
ty::VariantInfo::from_ast_variant(tcx,
- ast_variant,
+ &**ast_variant,
/*discriminant*/ 0);
- for &arg_ty in variant.args.iter() {
- self.add_constraints_from_ty(arg_ty, self.covariant);
+ for arg_ty in variant.args.iter() {
+ self.add_constraints_from_ty(*arg_ty, self.covariant);
}
}
}
p: p,
flag: false,
};
- visit::walk_block(&mut v, b, ());
+ visit::walk_block(&mut v, &*b, ());
return v.flag;
}
use middle::typeck;
use std::rc::Rc;
-use std::string::String;
+use std::gc::Gc;
use syntax::abi;
use syntax::ast_map;
use syntax::codemap::{Span, Pos};
use std::rc::Rc;
use std::u32;
+use std::gc::Gc;
use core;
use doctree;
}
}
-impl<T: Clean<U>, U> Clean<U> for @T {
+impl<T: Clean<U>, U> Clean<U> for Gc<T> {
fn clean(&self) -> U {
(**self).clean()
}
_ => None,
}
}
- fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
+ fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
}
impl<'a> attr::AttrMetaMethods for &'a Attribute {
fn name(&self) -> InternedString { (**self).name() }
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
- fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
+ fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
}
#[deriving(Clone, Encodable, Decodable)]
impl Clean<Argument> for ast::Arg {
fn clean(&self) -> Argument {
Argument {
- name: name_from_pat(self.pat),
+ name: name_from_pat(&*self.pat),
type_: (self.ty.clean()),
id: self.id
}
remaining,
b.clone());
let path = syntax::codemap::dummy_spanned(path);
- ret.push(convert(&ast::ViewItemUse(@path)));
+ ret.push(convert(&ast::ViewItemUse(box(GC) path)));
}
}
ast::ViewPathSimple(_, _, id) => {
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
which is not allowed in function arguments"),
PatTup(..) => "(tuple arg NYI)".to_string(),
- PatBox(p) => name_from_pat(p),
- PatRegion(p) => name_from_pat(p),
+ PatBox(p) => name_from_pat(&*p),
+ PatRegion(p) => name_from_pat(&*p),
PatLit(..) => {
warn!("tried to get argument name from PatLit, \
which is silly in function arguments");
let mut cfg = build_configuration(&sess);
for cfg_ in cfgs.move_iter() {
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
- cfg.push(@dummy_spanned(ast::MetaWord(cfg_)));
+ cfg.push(box(GC) dummy_spanned(ast::MetaWord(cfg_)));
}
let krate = phase_1_parse_input(&sess, cfg, &input);
pub fn run_core(libs: HashSet<Path>, cfgs: Vec<String>, path: &Path)
-> (clean::Crate, CrateAnalysis) {
let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs);
- let ctxt = @ctxt;
+ let ctxt = box(GC) ctxt;
super::ctxtkey.replace(Some(ctxt));
let krate = {
- let mut v = RustdocVisitor::new(ctxt, Some(&analysis));
+ let mut v = RustdocVisitor::new(&*ctxt, Some(&analysis));
v.visit(&ctxt.krate);
v.clean()
};
use syntax::ast;
use syntax::ast::{Ident, NodeId};
+use std::gc::Gc;
+
pub struct Module {
pub name: Option<Ident>,
pub attrs: Vec<ast::Attribute>,
pub struct Static {
pub type_: ast::P<ast::Ty>,
pub mutability: ast::Mutability,
- pub expr: @ast::Expr,
+ pub expr: Gc<ast::Expr>,
pub name: Ident,
pub attrs: Vec<ast::Attribute>,
pub vis: ast::Visibility,
pub generics: ast::Generics,
pub trait_: Option<ast::TraitRef>,
pub for_: ast::P<ast::Ty>,
- pub methods: Vec<@ast::Method>,
+ pub methods: Vec<Gc<ast::Method>>,
pub attrs: Vec<ast::Attribute>,
pub where: Span,
pub vis: ast::Visibility,
use std::io;
use std::io::{File, MemWriter};
use std::str;
+use std::gc::Gc;
use serialize::{json, Decodable, Encodable};
// reexported from `clean` so it can be easily updated with the mod itself
"unindent-comments",
];
-local_data_key!(pub ctxtkey: @core::DocContext)
+local_data_key!(pub ctxtkey: Gc<core::DocContext>)
local_data_key!(pub analysiskey: core::CrateAnalysis)
type Output = (clean::Crate, Vec<plugins::PluginJson> );
let mut cfg = config::build_configuration(&sess);
cfg.extend(cfgs.move_iter().map(|cfg_| {
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
- @dummy_spanned(ast::MetaWord(cfg_))
+ box(GC) dummy_spanned(ast::MetaWord(cfg_))
}));
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
&from_str("rustdoc-test").unwrap());
- let ctx = @core::DocContext {
+ let ctx = box(GC) core::DocContext {
krate: krate,
maybe_typed: core::NotTyped(sess),
src: input_path,
};
super::ctxtkey.replace(Some(ctx));
- let mut v = RustdocVisitor::new(ctx, None);
+ let mut v = RustdocVisitor::new(&*ctx, None);
v.visit(&ctx.krate);
let krate = v.clean();
let (krate, _) = passes::unindent_comments(krate);
use syntax::attr::AttrMetaMethods;
use syntax::codemap::Span;
+use std::gc::Gc;
+
use core;
use doctree::*;
self.module.is_crate = true;
}
- pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,
+ pub fn visit_struct_def(&mut self, item: &ast::Item, sd: Gc<ast::StructDef>,
generics: &ast::Generics) -> Struct {
debug!("Visiting struct");
- let struct_type = struct_type_from_def(sd);
+ let struct_type = struct_type_from_def(&*sd);
Struct {
id: item.id,
struct_type: struct_type,
om.vis = vis;
om.id = id;
for i in m.items.iter() {
- self.visit_item(*i, &mut om);
+ self.visit_item(&**i, &mut om);
}
om
}
om.view_items.push(item);
}
- fn visit_view_path(&mut self, path: @ast::ViewPath,
+ fn visit_view_path(&mut self, path: Gc<ast::ViewPath>,
om: &mut Module,
- please_inline: bool) -> Option<@ast::ViewPath> {
+ please_inline: bool) -> Option<Gc<ast::ViewPath>> {
match path.node {
ast::ViewPathSimple(_, _, id) => {
if self.resolve_id(id, false, om, please_inline) { return None }
}
if mine.len() == 0 { return None }
- return Some(@::syntax::codemap::Spanned {
+ return Some(box(GC) ::syntax::codemap::Spanned {
node: ast::ViewPathList(p.clone(), mine, b.clone()),
span: path.span,
})
self.visit_view_item(vi, om);
}
for i in m.items.iter() {
- self.visit_item(*i, om);
+ self.visit_item(&**i, om);
}
}
_ => { fail!("glob not mapped to a module"); }
}
} else {
- self.visit_item(it, om);
+ self.visit_item(&*it, om);
}
true
}
om.enums.push(self.visit_enum_def(item, ed, gen)),
ast::ItemStruct(sd, ref gen) =>
om.structs.push(self.visit_struct_def(item, sd, gen)),
- ast::ItemFn(fd, ref pur, ref abi, ref gen, _) =>
- om.fns.push(self.visit_fn(item, fd, pur, abi, gen)),
+ ast::ItemFn(ref fd, ref pur, ref abi, ref gen, _) =>
+ om.fns.push(self.visit_fn(item, &**fd, pur, abi, gen)),
ast::ItemTy(ty, ref gen) => {
let t = Typedef {
ty: ty,
#![allow(experimental)]
use clone::Clone;
-use cmp::{TotalOrd, Ord, Ordering, TotalEq, Eq};
+use cmp::{Ord, PartialOrd, Ordering, Eq, PartialEq};
use default::Default;
use fmt;
-use hash::Hash;
-use io::Writer;
+use hash;
use kinds::marker;
use ops::Deref;
use raw;
#[cfg(stage0)]
ptr: @T,
#[cfg(not(stage0))]
- ptr: *T,
+ _ptr: *T,
marker: marker::NoSend,
}
-impl<T: 'static> Clone for Gc<T> {
+impl<T> Clone for Gc<T> {
/// Clone the pointer only
#[inline]
fn clone(&self) -> Gc<T> { *self }
#[cfg(not(test))]
pub static GC: () = ();
-impl<T: Eq + 'static> Eq for Gc<T> {
+impl<T: PartialEq + 'static> PartialEq for Gc<T> {
#[inline]
fn eq(&self, other: &Gc<T>) -> bool { *(*self) == *(*other) }
#[inline]
fn ne(&self, other: &Gc<T>) -> bool { *(*self) != *(*other) }
}
-impl<T: Ord + 'static> Ord for Gc<T> {
+impl<T: PartialOrd + 'static> PartialOrd for Gc<T> {
#[inline]
fn lt(&self, other: &Gc<T>) -> bool { *(*self) < *(*other) }
#[inline]
#[inline]
fn gt(&self, other: &Gc<T>) -> bool { *(*self) > *(*other) }
}
-impl<T: TotalOrd + 'static> TotalOrd for Gc<T> {
+impl<T: Ord + 'static> Ord for Gc<T> {
#[inline]
fn cmp(&self, other: &Gc<T>) -> Ordering { (**self).cmp(&**other) }
}
-impl<T: TotalEq + 'static> TotalEq for Gc<T> {}
+impl<T: Eq + 'static> Eq for Gc<T> {}
impl<T: 'static> Deref<T> for Gc<T> {
#[cfg(stage0)]
impl<T: 'static> raw::Repr<*raw::Box<T>> for Gc<T> {}
-impl<S: Writer, T: Hash<S> + 'static> Hash<S> for Gc<T> {
+impl<S: hash::Writer, T: hash::Hash<S> + 'static> hash::Hash<S> for Gc<T> {
fn hash(&self, s: &mut S) {
(**self).hash(s)
}
None
}
/// Create a pattern.
- fn make_pat(&self) -> Option<@ast::Pat> {
+ fn make_pat(&self) -> Option<Gc<ast::Pat>> {
None
}
}
/// A convenience type for macros that return a single pattern.
pub struct MacPat {
- p: @ast::Pat
+ p: Gc<ast::Pat>,
}
impl MacPat {
- pub fn new(p: @ast::Pat) -> Box<MacResult> {
+ pub fn new(p: Gc<ast::Pat>) -> Box<MacResult> {
box MacPat { p: p } as Box<MacResult>
}
}
impl MacResult for MacPat {
- fn make_pat(&self) -> Option<@ast::Pat> {
+ fn make_pat(&self) -> Option<Gc<ast::Pat>> {
Some(self.p)
}
}
}
/// A plain dummy pattern.
- pub fn raw_pat(sp: Span) -> @ast::Pat {
- @ast::Pat {
+ pub fn raw_pat(sp: Span) -> Gc<ast::Pat> {
+ box(GC) ast::Pat {
id: ast::DUMMY_NODE_ID,
node: ast::PatWild,
span: sp,
let value_ident = token::gensym_ident("__value");
// this is careful to use src_pat.span so that error
// messages point exact at that.
- let local = @ast::Local {
+ let local = box(GC) ast::Local {
ty: fld.cx.ty_infer(src_pat.span),
pat: src_pat,
init: Some(fld.cx.expr_ident(src_pat.span, value_ident)),
source: ast::LocalFor
};
let local = codemap::respan(src_pat.span, ast::DeclLocal(local));
- let local = @codemap::respan(span, ast::StmtDecl(@local, ast::DUMMY_NODE_ID));
+ let local = box(GC) codemap::respan(span, ast::StmtDecl(box(GC) local,
+ ast::DUMMY_NODE_ID));
// { let ...; <src_loop_block> }
let block = fld.cx.block(span, vec![local],
})
}
-pub fn expand_pat(p: @ast::Pat, fld: &mut MacroExpander) -> @ast::Pat {
+pub fn expand_pat(p: Gc<ast::Pat>, fld: &mut MacroExpander) -> Gc<ast::Pat> {
let (pth, tts) = match p.node {
PatMac(ref mac) => {
match mac.node {
fld.fold_pat(marked_after).node.clone();
fld.cx.bt_pop();
- @ast::Pat {
+ box(GC) ast::Pat {
id: ast::DUMMY_NODE_ID,
node: fully_expanded,
span: p.span,
}
// apply a given mark to the given pattern. Used following the expansion of a macro.
-fn mark_pat(pat: @ast::Pat, m: Mrk) -> @ast::Pat {
+fn mark_pat(pat: Gc<ast::Pat>, m: Mrk) -> Gc<ast::Pat> {
new_mark_folder(m).fold_pat(pat)
}
impl ToSource for Gc<ast::Item> {
fn to_source(&self) -> String {
- pprust::item_to_str(*self)
+ pprust::item_to_str(&**self)
}
}
impl ToSource for Gc<ast::Expr> {
fn to_source(&self) -> String {
- pprust::expr_to_str(*self)
+ pprust::expr_to_str(&**self)
}
}
})
}
TyUnboxedFn(ref f) => {
- TyUnboxedFn(@UnboxedFnTy {
- decl: self.fold_fn_decl(f.decl),
+ TyUnboxedFn(box(GC) UnboxedFnTy {
+ decl: self.fold_fn_decl(&*f.decl),
})
}
TyTup(ref tys) => TyTup(tys.iter().map(|&ty| self.fold_ty(ty)).collect()),
StaticRegionTyParamBound => StaticRegionTyParamBound,
UnboxedFnTyParamBound(ref unboxed_function_type) => {
UnboxedFnTyParamBound(UnboxedFnTy {
- decl: fld.fold_fn_decl(unboxed_function_type.decl),
+ decl: fld.fold_fn_decl(&*unboxed_function_type.decl),
})
}
OtherRegionTyParamBound(s) => OtherRegionTyParamBound(s)
struct ParsedItemsAndViewItems {
attrs_remaining: Vec<Attribute>,
view_items: Vec<ViewItem>,
- items: Vec<@Item>,
- foreign_items: Vec<@ForeignItem>
+ items: Vec<Gc<Item>>,
+ foreign_items: Vec<Gc<ForeignItem>>
}
/* ident is handled by common.rs */
&None,
ast::NormalFn,
ast::Many,
- unboxed_function_type.decl,
+ &*unboxed_function_type.decl,
None,
&None,
None,
pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E) {
visitor.visit_ident(item.span, item.ident, env.clone());
match item.node {
- ItemStatic(typ, _, expr) => {
- visitor.visit_ty(&*typ, env.clone());
- visitor.visit_expr(&*expr, env);
+ ItemStatic(ref typ, _, ref expr) => {
+ visitor.visit_ty(&**typ, env.clone());
+ visitor.visit_expr(&**expr, env.clone());
}
ItemFn(declaration, fn_style, abi, ref generics, body) => {
visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi),
visitor.visit_foreign_item(&**foreign_item, env.clone())
}
}
- ItemTy(typ, ref type_parameters) => {
- visitor.visit_ty(&*typ, env.clone());
- visitor.visit_generics(type_parameters, env)
+ ItemTy(ref typ, ref type_parameters) => {
+ visitor.visit_ty(&**typ, env.clone());
+ visitor.visit_generics(type_parameters, env.clone())
}
ItemEnum(ref enum_definition, ref type_parameters) => {
visitor.visit_generics(type_parameters, env.clone());
}
TyUnboxedFn(ref function_declaration) => {
for argument in function_declaration.decl.inputs.iter() {
- visitor.visit_ty(argument.ty, env.clone())
+ visitor.visit_ty(&*argument.ty, env.clone())
}
- visitor.visit_ty(function_declaration.decl.output, env.clone());
+ visitor.visit_ty(&*function_declaration.decl.output, env.clone());
}
TyPath(ref path, ref bounds, id) => {
visitor.visit_path(path, id, env.clone());
walk_fn_decl(visitor, &**function_declaration, env.clone());
visitor.visit_generics(generics, env.clone())
}
- ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env.clone()),
+ ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ, env.clone()),
}
for attr in foreign_item.attrs.iter() {
StaticRegionTyParamBound => {}
UnboxedFnTyParamBound(ref function_declaration) => {
for argument in function_declaration.decl.inputs.iter() {
- visitor.visit_ty(argument.ty, env.clone())
+ visitor.visit_ty(&*argument.ty, env.clone())
}
- visitor.visit_ty(function_declaration.decl.output,
+ visitor.visit_ty(&*function_declaration.decl.output,
env.clone());
}
OtherRegionTyParamBound(..) => {}
visitor.visit_ty(&*argument_type.ty, env.clone())
}
visitor.visit_generics(&method_type.generics, env.clone());
- visitor.visit_ty(method_type.decl.output, env.clone());
+ visitor.visit_ty(&*method_type.decl.output, env.clone());
for attr in method_type.attrs.iter() {
visitor.visit_attribute(attr, env.clone());
}
_ => {}
}
- visitor.visit_ty(struct_field.node.ty, env.clone());
+ visitor.visit_ty(&*struct_field.node.ty, env.clone());
for attr in struct_field.node.attrs.iter() {
visitor.visit_attribute(attr, env.clone());
visitor.visit_pat(&**pattern, env.clone())
}
walk_expr_opt(visitor, arm.guard, env.clone());
- visitor.visit_expr(arm.body, env.clone());
+ visitor.visit_expr(&*arm.body, env.clone());
for attr in arm.attrs.iter() {
visitor.visit_attribute(attr, env.clone());
}
use std::os;
use std::task;
use std::vec;
+use std::gc::Gc;
#[deriving(Clone)]
enum List<T> {
- Nil, Cons(T, @List<T>)
+ Nil, Cons(T, Gc<List<T>>)
}
enum UniqueList {
}
struct r {
- _l: @nillist,
+ _l: Gc<nillist>,
}
#[unsafe_destructor]
fn drop(&mut self) {}
}
-fn r(l: @nillist) -> r {
+fn r(l: Gc<nillist>) -> r {
r {
_l: l
}
let st = match st {
None => {
State {
- managed: @Nil,
+ managed: box(GC) Nil,
unique: box Nil,
- tuple: (@Nil, box Nil),
- vec: vec!(@Nil),
- res: r(@Nil)
+ tuple: (box(GC) Nil, box Nil),
+ vec: vec!(box(GC) Nil),
+ res: r(box(GC) Nil)
}
}
Some(st) => {
State {
- managed: @Cons((), st.managed),
- unique: box Cons((), @*st.unique),
- tuple: (@Cons((), st.tuple.ref0().clone()),
- box Cons((), @*st.tuple.ref1().clone())),
- vec: st.vec.clone().append(&[@Cons((), *st.vec.last().unwrap())]),
- res: r(@Cons((), st.res._l))
+ managed: box(GC) Cons((), st.managed),
+ unique: box Cons((), box(GC) *st.unique),
+ tuple: (box(GC) Cons((), st.tuple.ref0().clone()),
+ box Cons((), box(GC) *st.tuple.ref1().clone())),
+ vec: st.vec.clone().append(
+ &[box(GC) Cons((), *st.vec.last().unwrap())]),
+ res: r(box(GC) Cons((), st.res._l))
}
}
};
fn want_foo(f: foo) {}
fn have_bar(b: bar) {
- want_foo(b); //~ ERROR (expected struct foo but found @-ptr)
+ want_foo(b); //~ ERROR (expected struct foo but found Gc-ptr)
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-pretty FIXME(#14193)
+
#![feature(managed_boxes)]
enum list<T> { cons(@T, @list<T>), nil, }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-pretty FIXME(#14193)
+
#![feature(managed_boxes)]
// Test cyclic detector when using trait instances.
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-pretty FIXME(#14193)
+
#![feature(managed_boxes)]
use std::cell::RefCell;