diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-07-07 16:35:15 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-07-17 14:05:36 -0700 |
| commit | de70d76373e05fcf0f421cedb185b08de10a714c (patch) | |
| tree | ccfdaa415ce2bb947f40746a3b06a8980ab6cd16 /src/libsyntax | |
| parent | ca24abd4d2d02dd96ef323074c9a21d44b3fd202 (diff) | |
| download | rust-de70d76373e05fcf0f421cedb185b08de10a714c.tar.gz rust-de70d76373e05fcf0f421cedb185b08de10a714c.zip | |
librustc: Remove cross-borrowing of `Box<T>` to `&T` from the language,
except where trait objects are involved.
Part of issue #15349, though I'm leaving it open for trait objects.
Cross borrowing for trait objects remains because it is needed until we
have DST.
This will break code like:
fn foo(x: &int) { ... }
let a = box 3i;
foo(a);
Change this code to:
fn foo(x: &int) { ... }
let a = box 3i;
foo(&*a);
[breaking-change]
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 6 |
6 files changed, 27 insertions, 21 deletions
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 46efdccadec..f1c1784146a 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -954,7 +954,9 @@ impl<'a> MethodDef<'a> { // expressions for referencing every field of every // Self arg, assuming all are instances of VariantK. // Build up code associated with such a case. - let substructure = EnumMatching(index, variant, field_tuples); + let substructure = EnumMatching(index, + &*variant, + field_tuples); let arm_expr = self.call_substructure_method( cx, trait_, type_ident, self_args, nonself_args, &substructure); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 58689389769..a098139b36d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -166,14 +166,14 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> { ast::ExprFnBlock(fn_decl, block) => { let (rewritten_fn_decl, rewritten_block) - = expand_and_rename_fn_decl_and_block(fn_decl, block, fld); + = expand_and_rename_fn_decl_and_block(&*fn_decl, block, fld); let new_node = ast::ExprFnBlock(rewritten_fn_decl, rewritten_block); box(GC) ast::Expr{id:e.id, node: new_node, span: fld.new_span(e.span)} } ast::ExprProc(fn_decl, block) => { let (rewritten_fn_decl, rewritten_block) - = expand_and_rename_fn_decl_and_block(fn_decl, block, fld); + = expand_and_rename_fn_decl_and_block(&*fn_decl, block, fld); let new_node = ast::ExprProc(rewritten_fn_decl, rewritten_block); box(GC) ast::Expr{id:e.id, node: new_node, span: fld.new_span(e.span)} } @@ -422,7 +422,7 @@ fn expand_item_underscore(item: &ast::Item_, fld: &mut MacroExpander) -> ast::It match *item { ast::ItemFn(decl, fn_style, abi, ref generics, body) => { let (rewritten_fn_decl, rewritten_body) - = expand_and_rename_fn_decl_and_block(decl,body,fld); + = expand_and_rename_fn_decl_and_block(&*decl, body, fld); let expanded_generics = fold::fold_generics(generics,fld); ast::ItemFn(rewritten_fn_decl, fn_style, abi, expanded_generics, rewritten_body) } @@ -572,7 +572,9 @@ fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<Gc<Stmt>> { }; let expanded_stmt = match expand_mac_invoc(mac,&s.span, |r|{r.make_stmt()}, - |sts,mrk|{mark_stmt(sts,mrk)}, + |sts,mrk| { + mark_stmt(&*sts,mrk) + }, fld) { Some(stmt) => stmt, None => { @@ -628,7 +630,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander) // names, as well... but that should be okay, as long as // the new names are gensyms for the old ones. // generate fresh names, push them to a new pending list - let idents = pattern_bindings(expanded_pat); + let idents = pattern_bindings(&*expanded_pat); let mut new_pending_renames = idents.iter().map(|ident| (*ident, fresh_name(ident))).collect(); // rewrite the pattern using the new names (the old @@ -677,7 +679,7 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm { // all of the pats must have the same set of bindings, so use the // first one to extract them and generate new names: let first_pat = expanded_pats.get(0); - let idents = pattern_bindings(*first_pat); + let idents = pattern_bindings(&**first_pat); let new_renames = idents.iter().map(|id| (*id,fresh_name(id))).collect(); // apply the renaming, but only to the PatIdents: @@ -732,7 +734,7 @@ fn pattern_bindings(pat : &ast::Pat) -> Vec<ast::Ident> { fn fn_decl_arg_bindings(fn_decl: &ast::FnDecl) -> Vec<ast::Ident> { let mut pat_idents = PatIdentFinder{ident_accumulator:Vec::new()}; for arg in fn_decl.inputs.iter() { - pat_idents.visit_pat(arg.pat,()); + pat_idents.visit_pat(&*arg.pat, ()); } pat_idents.ident_accumulator } @@ -910,7 +912,7 @@ fn expand_method(m: &ast::Method, fld: &mut MacroExpander) -> SmallVector<Gc<ast match m.node { ast::MethDecl(ident, ref generics, ref explicit_self, fn_style, decl, body, vis) => { let (rewritten_fn_decl, rewritten_body) - = expand_and_rename_fn_decl_and_block(decl,body,fld); + = expand_and_rename_fn_decl_and_block(&*decl,body,fld); SmallVector::one(box(GC) ast::Method { attrs: m.attrs.iter().map(|a| fld.fold_attribute(*a)).collect(), id: id, @@ -951,12 +953,12 @@ fn expand_and_rename_fn_decl_and_block(fn_decl: &ast::FnDecl, block: Gc<ast::Blo fld: &mut MacroExpander) -> (Gc<ast::FnDecl>, Gc<ast::Block>) { let expanded_decl = fld.fold_fn_decl(fn_decl); - let idents = fn_decl_arg_bindings(expanded_decl); + let idents = fn_decl_arg_bindings(&*expanded_decl); let renames = idents.iter().map(|id : &ast::Ident| (*id,fresh_name(id))).collect(); // first, a renamer for the PatIdents, for the fn_decl: let mut rename_pat_fld = PatIdentRenamer{renames: &renames}; - let rewritten_fn_decl = rename_pat_fld.fold_fn_decl(expanded_decl); + let rewritten_fn_decl = rename_pat_fld.fold_fn_decl(&*expanded_decl); // now, a renamer for *all* idents, for the body: let mut rename_fld = IdentRenamer{renames: &renames}; let rewritten_body = fld.fold_block(rename_fld.fold_block(block)); @@ -999,7 +1001,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> { } fn fold_method(&mut self, method: Gc<ast::Method>) -> SmallVector<Gc<ast::Method>> { - expand_method(method, self) + expand_method(&*method, self) } fn new_span(&mut self, span: Span) -> Span { @@ -1660,7 +1662,7 @@ foo_module!() fn pat_idents(){ let pat = string_to_pat( "(a,Foo{x:c @ (b,9),y:Bar(4,d)})".to_string()); - let idents = pattern_bindings(pat); + let idents = pattern_bindings(&*pat); assert_eq!(idents, strs_to_idents(vec!("a","c","b","d"))); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 87c762af2e5..5467afab9f5 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -472,7 +472,7 @@ fn fold_interpolated<T: Folder>(nt : &token::Nonterminal, fld: &mut T) -> token: .expect_one("expected fold to produce exactly one item")), token::NtBlock(block) => token::NtBlock(fld.fold_block(block)), token::NtStmt(stmt) => - token::NtStmt(fld.fold_stmt(stmt) + token::NtStmt(fld.fold_stmt(&*stmt) // this is probably okay, because the only folds likely // to peek inside interpolated nodes will be renamings/markings, // which map single items to single items @@ -483,8 +483,8 @@ fn fold_interpolated<T: Folder>(nt : &token::Nonterminal, fld: &mut T) -> token: token::NtIdent(ref id, is_mod_name) => token::NtIdent(box fld.fold_ident(**id),is_mod_name), token::NtMeta(meta_item) => token::NtMeta(fold_meta_item_(meta_item,fld)), - token::NtPath(ref path) => token::NtPath(box fld.fold_path(*path)), - token::NtTT(tt) => token::NtTT(box (GC) fold_tt(tt,fld)), + token::NtPath(ref path) => token::NtPath(box fld.fold_path(&**path)), + token::NtTT(tt) => token::NtTT(box (GC) fold_tt(&*tt,fld)), // it looks to me like we can leave out the matchers: token::NtMatchers(matchers) _ => (*nt).clone() } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bdfd928cfbc..a77f24f98f8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -502,7 +502,9 @@ impl<'a> Parser<'a> { inedible: &[token::Token]) { debug!("commit_stmt {:?}", s); let _s = s; // unused, but future checks might want to inspect `s`. - if self.last_token.as_ref().map_or(false, |t| is_ident_or_path(*t)) { + if self.last_token + .as_ref() + .map_or(false, |t| is_ident_or_path(&**t)) { let expected = edible.iter().map(|x| (*x).clone()).collect::<Vec<_>>() .append(inedible.as_slice()); self.check_for_erroneous_unit_struct_expecting( diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 428a15cb8cf..10caaea86cf 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1862,7 +1862,7 @@ impl<'a> State<'a> { ast::SelfExplicit(ref typ, _) => { try!(word(&mut self.s, "self")); try!(self.word_space(":")); - try!(self.print_type(*typ)); + try!(self.print_type(&**typ)); } } return Ok(true); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6760d7a3932..cd953607ea2 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -215,7 +215,7 @@ pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V, SelfRegion(ref lifetime, _, _) => { visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env) } - SelfExplicit(ref typ, _) => visitor.visit_ty(*typ, env.clone()), + SelfExplicit(ref typ, _) => visitor.visit_ty(&**typ, env.clone()), } } @@ -565,8 +565,8 @@ pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V, MethDecl(ident, ref generics, _, _, decl, body, _) => { visitor.visit_ident(method.span, ident, env.clone()); visitor.visit_fn(&FkMethod(ident, generics, method), - decl, - body, + &*decl, + &*body, method.span, method.id, env.clone()); |
