about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-24 17:38:09 +0000
committerbors <bors@rust-lang.org>2015-03-24 17:38:09 +0000
commited810385045ab0db90303574ba3ea47dfa2a36d5 (patch)
tree161242c800aca625a26c56551fa5adb446c0089f /src/libsyntax
parent28a0b25f424090255966273994748a9f9901059f (diff)
parentd252d0ad5434bcf77076729ab766eeff98f20ead (diff)
downloadrust-ed810385045ab0db90303574ba3ea47dfa2a36d5.tar.gz
rust-ed810385045ab0db90303574ba3ea47dfa2a36d5.zip
Auto merge of #23654 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs3
-rw-r--r--src/libsyntax/ext/deriving/mod.rs10
-rw-r--r--src/libsyntax/ext/format.rs2
-rw-r--r--src/libsyntax/ext/source_util.rs2
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs4
-rw-r--r--src/libsyntax/feature_gate.rs9
-rw-r--r--src/libsyntax/lib.rs2
-rw-r--r--src/libsyntax/parse/obsolete.rs19
-rw-r--r--src/libsyntax/parse/parser.rs280
-rw-r--r--src/libsyntax/print/pprust.rs14
10 files changed, 45 insertions, 300 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 70aab26092c..1abe8d0a3c1 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -351,8 +351,7 @@ impl Encodable for FileMap {
                         let max_line_length = if lines.len() == 1 {
                             0
                         } else {
-                            lines.as_slice()
-                                 .windows(2)
+                            lines.windows(2)
                                  .map(|w| w[1] - w[0])
                                  .map(|bp| bp.to_usize())
                                  .max()
diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs
index 2631c28cf2f..d8c50b5a094 100644
--- a/src/libsyntax/ext/deriving/mod.rs
+++ b/src/libsyntax/ext/deriving/mod.rs
@@ -78,14 +78,6 @@ pub mod totalord;
 
 pub mod generic;
 
-fn expand_deprecated_deriving(cx: &mut ExtCtxt,
-                              span: Span,
-                              _: &MetaItem,
-                              _: &Item,
-                              _: &mut FnMut(P<Item>)) {
-    cx.span_err(span, "`deriving` has been renamed to `derive`");
-}
-
 fn expand_derive(cx: &mut ExtCtxt,
                  _: Span,
                  mitem: &MetaItem,
@@ -151,8 +143,6 @@ macro_rules! derive_traits {
 
             env.insert(intern("derive"),
                        Modifier(Box::new(expand_derive)));
-            env.insert(intern("deriving"),
-                       Decorator(Box::new(expand_deprecated_deriving)));
         }
 
         fn is_builtin_trait(name: &str) -> bool {
diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs
index 0eaca9af4f0..2fe77bf7a54 100644
--- a/src/libsyntax/ext/format.rs
+++ b/src/libsyntax/ext/format.rs
@@ -513,7 +513,7 @@ impl<'a, 'b> Context<'a, 'b> {
             let lname = self.ecx.ident_of(&format!("__arg{}",
                                                   *name));
             pats.push(self.ecx.pat_ident(e.span, lname));
-            names[self.name_positions[*name]] =
+            names[*self.name_positions.get(name).unwrap()] =
                 Some(Context::format_arg(self.ecx, e.span, arg_ty,
                                          self.ecx.expr_ident(e.span, lname)));
             heads.push(self.ecx.expr_addr_of(e.span, e));
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index c61aec0069d..31d8b207bb9 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -194,7 +194,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
 fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> PathBuf {
     // NB: relative paths are resolved relative to the compilation unit
     if !arg.is_absolute() {
-        let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp));
+        let mut cu = PathBuf::from(&cx.codemap().span_to_filename(sp));
         cu.pop();
         cu.push(arg);
         cu
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 7a2ae55e914..5940b791843 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -236,7 +236,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
                                      argument_gram);
 
     // Extract the arguments:
-    let lhses = match *argument_map[lhs_nm] {
+    let lhses = match **argument_map.get(&lhs_nm).unwrap() {
         MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
         _ => cx.span_bug(def.span, "wrong-structured lhs")
     };
@@ -245,7 +245,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
         check_lhs_nt_follows(cx, &**lhs, def.span);
     }
 
-    let rhses = match *argument_map[rhs_nm] {
+    let rhses = match **argument_map.get(&rhs_nm).unwrap() {
         MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
         _ => cx.span_bug(def.span, "wrong-structured rhs")
     };
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 0a9980c8925..60f81dac1e9 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -201,7 +201,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
     ("no_mangle", Normal),
     ("no_link", Normal),
     ("derive", Normal),
-    ("deriving", Normal), // deprecation err in expansion
     ("should_fail", Normal),
     ("should_panic", Normal),
     ("ignore", Normal),
@@ -259,7 +258,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
     ("link_section", Whitelisted),
     ("no_builtins", Whitelisted),
     ("no_mangle", Whitelisted),
-    ("no_split_stack", Whitelisted),
     ("no_stack_check", Whitelisted),
     ("packed", Whitelisted),
     ("static_assert", Gated("static_assert",
@@ -563,6 +561,13 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
                 }
             }
 
+            ast::ItemDefaultImpl(..) => {
+                self.gate_feature("optin_builtin_traits",
+                                  i.span,
+                                  "default trait implementations are experimental \
+                                   and possibly buggy");
+            }
+
             ast::ItemImpl(_, polarity, _, _, _, _) => {
                 match polarity {
                     ast::ImplPolarity::Negative => {
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index 9f217bba00a..9af7b9ab633 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -39,6 +39,8 @@
 #![feature(unicode)]
 #![feature(path_ext)]
 #![feature(str_char)]
+#![feature(convert)]
+#![feature(into_cow)]
 
 extern crate arena;
 extern crate fmt_macros;
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index ee646d95f35..7da0a6de547 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -22,9 +22,6 @@ use ptr::P;
 /// The specific types of unsupported syntax
 #[derive(Copy, PartialEq, Eq, Hash)]
 pub enum ObsoleteSyntax {
-    Sized,
-    ForSized,
-    ClosureType,
     ClosureKind,
     EmptyIndex,
 }
@@ -49,27 +46,11 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
     /// Reports an obsolete syntax non-fatal error.
     fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
         let (kind_str, desc, error) = match kind {
-            ObsoleteSyntax::ForSized => (
-                "for Sized?",
-                "no longer required. Traits (and their `Self` type) do not have the `Sized` bound \
-                 by default",
-                true,
-            ),
-            ObsoleteSyntax::ClosureType => (
-                "`|usize| -> bool` closure type",
-                "use unboxed closures instead, no type annotation needed",
-                true,
-            ),
             ObsoleteSyntax::ClosureKind => (
                 "`:`, `&mut:`, or `&:`",
                 "rely on inference instead",
                 true,
             ),
-            ObsoleteSyntax::Sized => (
-                "`Sized? T` for removing the `Sized` bound",
-                "write `T: ?Sized` instead",
-                true,
-            ),
             ObsoleteSyntax::EmptyIndex => (
                 "[]",
                 "write `[..]` instead",
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 667af642744..4ae5e0faa31 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -516,11 +516,7 @@ impl<'a> Parser<'a> {
 
     pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
         let lo = self.span.lo;
-        let node = if self.eat_keyword_noexpect(keywords::Mod) {
-            let span = self.last_span;
-            self.span_warn(span, "deprecated syntax; use the `self` keyword now");
-            ast::PathListMod { id: ast::DUMMY_NODE_ID }
-        } else if self.eat_keyword(keywords::SelfValue) {
+        let node = if self.eat_keyword(keywords::SelfValue) {
             ast::PathListMod { id: ast::DUMMY_NODE_ID }
         } else {
             let ident = self.parse_ident();
@@ -619,23 +615,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Expect and consume a `|`. If `||` is seen, replace it with a single
-    /// `|` and continue. If a `|` is not seen, signal an error.
-    fn expect_or(&mut self) {
-        self.expected_tokens.push(TokenType::Token(token::BinOp(token::Or)));
-        match self.token {
-            token::BinOp(token::Or) => self.bump(),
-            token::OrOr => {
-                let span = self.span;
-                let lo = span.lo + BytePos(1);
-                self.replace_token(token::BinOp(token::Or), lo, span.hi)
-            }
-            _ => {
-                self.expect_one_of(&[], &[]);
-            }
-        }
-    }
-
     pub fn expect_no_suffix(&self, sp: Span, kind: &str, suffix: Option<ast::Name>) {
         match suffix {
             None => {/* everything ok */}
@@ -675,28 +654,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Parse a sequence bracketed by `|` and `|`, stopping before the `|`.
-    fn parse_seq_to_before_or<T, F>(&mut self,
-                                    sep: &token::Token,
-                                    mut f: F)
-                                    -> Vec<T> where
-        F: FnMut(&mut Parser) -> T,
-    {
-        let mut first = true;
-        let mut vector = Vec::new();
-        while self.token != token::BinOp(token::Or) &&
-                self.token != token::OrOr {
-            if first {
-                first = false
-            } else {
-                self.expect(sep)
-            }
-
-            vector.push(f(self))
-        }
-        vector
-    }
-
     /// Expect and consume a GT. if a >> is seen, replace it
     /// with a single > and continue. If a GT is not seen,
     /// signal an error.
@@ -1008,11 +965,6 @@ impl<'a> Parser<'a> {
             self.check_keyword(keywords::Extern)
     }
 
-    /// Is the current token one of the keywords that signals a closure type?
-    pub fn token_is_closure_keyword(&mut self) -> bool {
-        self.check_keyword(keywords::Unsafe)
-    }
-
     pub fn get_lifetime(&mut self) -> ast::Ident {
         match self.token {
             token::Lifetime(ref ident) => *ident,
@@ -1042,12 +994,9 @@ impl<'a> Parser<'a> {
         let lifetime_defs = self.parse_late_bound_lifetime_defs();
 
         // examine next token to decide to do
-        if self.token_is_bare_fn_keyword() || self.token_is_closure_keyword() {
-            self.parse_ty_bare_fn_or_ty_closure(lifetime_defs)
-        } else if self.check(&token::ModSep) ||
-                  self.token.is_ident() ||
-                  self.token.is_path()
-        {
+        if self.token_is_bare_fn_keyword() {
+            self.parse_ty_bare_fn(lifetime_defs)
+        } else {
             let hi = self.span.hi;
             let trait_ref = self.parse_trait_ref();
             let poly_trait_ref = ast::PolyTraitRef { bound_lifetimes: lifetime_defs,
@@ -1063,8 +1012,6 @@ impl<'a> Parser<'a> {
                 .chain(other_bounds.into_vec().into_iter())
                 .collect();
             ast::TyPolyTraitRef(all_bounds)
-        } else {
-            self.parse_ty_closure(lifetime_defs)
         }
     }
 
@@ -1094,7 +1041,6 @@ impl<'a> Parser<'a> {
         };
 
         self.expect_keyword(keywords::Fn);
-        let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
         let (inputs, variadic) = self.parse_fn_args(false, true);
         let ret_ty = self.parse_ret_ty();
         let decl = P(FnDecl {
@@ -1139,71 +1085,6 @@ impl<'a> Parser<'a> {
          self.obsolete(span, ObsoleteSyntax::ClosureKind);
     }
 
-    pub fn parse_ty_bare_fn_or_ty_closure(&mut self, lifetime_defs: Vec<LifetimeDef>) -> Ty_ {
-        // Both bare fns and closures can begin with stuff like unsafe
-        // and extern. So we just scan ahead a few tokens to see if we see
-        // a `fn`.
-        //
-        // Closure:  [unsafe] <'lt> |S| [:Bounds] -> T
-        // Fn:       [unsafe] [extern "ABI"] fn <'lt> (S) -> T
-
-        if self.check_keyword(keywords::Fn) {
-            self.parse_ty_bare_fn(lifetime_defs)
-        } else if self.check_keyword(keywords::Extern) {
-            self.parse_ty_bare_fn(lifetime_defs)
-        } else if self.check_keyword(keywords::Unsafe) {
-            if self.look_ahead(1, |t| t.is_keyword(keywords::Fn) ||
-                                      t.is_keyword(keywords::Extern)) {
-                self.parse_ty_bare_fn(lifetime_defs)
-            } else {
-                self.parse_ty_closure(lifetime_defs)
-            }
-        } else {
-            self.parse_ty_closure(lifetime_defs)
-        }
-    }
-
-    /// Parse a TyClosure type
-    pub fn parse_ty_closure(&mut self, lifetime_defs: Vec<ast::LifetimeDef>) -> Ty_ {
-        /*
-
-        [unsafe] <'lt> |S| [:Bounds] -> T
-        ^~~~~~~^ ^~~~^  ^  ^~~~~~~~^    ^
-          |        |       |      |        |
-          |        |       |      |      Return type
-          |        |       |  Closure bounds
-          |        |     Argument types
-          |      Deprecated lifetime defs
-          |
-        Function Style
-
-        */
-
-        let ty_closure_span = self.last_span;
-
-        // To be helpful, parse the closure type as ever
-        let _ = self.parse_unsafety();
-
-        let _ = self.parse_legacy_lifetime_defs(lifetime_defs);
-
-        if !self.eat(&token::OrOr) {
-            self.expect_or();
-
-            let _ = self.parse_seq_to_before_or(
-                &token::Comma,
-                |p| p.parse_arg_general(false));
-            self.expect_or();
-        }
-
-        let _ = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare);
-
-        let _ = self.parse_ret_ty();
-
-        self.obsolete(ty_closure_span, ObsoleteSyntax::ClosureType);
-
-        TyInfer
-    }
-
     pub fn parse_unsafety(&mut self) -> Unsafety {
         if self.eat_keyword(keywords::Unsafe) {
             return Unsafety::Unsafe;
@@ -1212,27 +1093,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Parses `[ 'for' '<' lifetime_defs '>' ]'
-    fn parse_legacy_lifetime_defs(&mut self,
-                                  lifetime_defs: Vec<ast::LifetimeDef>)
-                                  -> Vec<ast::LifetimeDef>
-    {
-        if self.token == token::Lt {
-            self.bump();
-            if lifetime_defs.is_empty() {
-                self.warn("deprecated syntax; use the `for` keyword now \
-                            (e.g. change `fn<'a>` to `for<'a> fn`)");
-                let lifetime_defs = self.parse_lifetime_defs();
-                self.expect_gt();
-                lifetime_defs
-            } else {
-                self.fatal("cannot use new `for` keyword and older syntax together");
-            }
-        } else {
-            lifetime_defs
-        }
-    }
-
     /// Parse the items in a trait declaration
     pub fn parse_trait_items(&mut self) -> Vec<P<TraitItem>> {
         self.parse_unspanned_seq(
@@ -1321,19 +1181,7 @@ impl<'a> Parser<'a> {
             if self.eat(&token::Not) {
                 NoReturn(self.span)
             } else {
-                let t = self.parse_ty();
-
-                // We used to allow `fn foo() -> &T + U`, but don't
-                // anymore. If we see it, report a useful error.  This
-                // only makes sense because `parse_ret_ty` is only
-                // used in fn *declarations*, not fn types or where
-                // clauses (i.e., not when parsing something like
-                // `FnMut() -> T + Send`, where the `+` is legal).
-                if self.token == token::BinOp(token::Plus) {
-                    self.warn("deprecated syntax: `()` are required, see RFC 438 for details");
-                }
-
-                Return(t)
+                Return(self.parse_ty())
             }
         } else {
             let pos = self.span.lo;
@@ -1421,18 +1269,9 @@ impl<'a> Parser<'a> {
             self.parse_borrowed_pointee()
         } else if self.check_keyword(keywords::For) {
             self.parse_for_in_type()
-        } else if self.token_is_bare_fn_keyword() ||
-                  self.token_is_closure_keyword() {
-            // BARE FUNCTION OR CLOSURE
-            self.parse_ty_bare_fn_or_ty_closure(Vec::new())
-        } else if self.check(&token::BinOp(token::Or)) ||
-                  self.token == token::OrOr ||
-                  (self.token == token::Lt &&
-                   self.look_ahead(1, |t| {
-                       *t == token::Gt || t.is_lifetime()
-                   })) {
-            // CLOSURE
-            self.parse_ty_closure(Vec::new())
+        } else if self.token_is_bare_fn_keyword() {
+            // BARE FUNCTION
+            self.parse_ty_bare_fn(Vec::new())
         } else if self.eat_keyword_noexpect(keywords::Typeof) {
             // TYPEOF
             // In order to not be ambiguous, the type must be surrounded by parens.
@@ -3974,56 +3813,19 @@ impl<'a> Parser<'a> {
         return OwnedSlice::from_vec(result);
     }
 
-    fn trait_ref_from_ident(ident: Ident, span: Span) -> TraitRef {
-        let segment = ast::PathSegment {
-            identifier: ident,
-            parameters: ast::PathParameters::none()
-        };
-        let path = ast::Path {
-            span: span,
-            global: false,
-            segments: vec![segment],
-        };
-        ast::TraitRef {
-            path: path,
-            ref_id: ast::DUMMY_NODE_ID,
-        }
-    }
-
-    /// Matches typaram = (unbound `?`)? IDENT (`?` unbound)? optbounds ( EQ ty )?
+    /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )?
     fn parse_ty_param(&mut self) -> TyParam {
-        // This is a bit hacky. Currently we are only interested in a single
-        // unbound, and it may only be `Sized`. To avoid backtracking and other
-        // complications, we parse an ident, then check for `?`. If we find it,
-        // we use the ident as the unbound, otherwise, we use it as the name of
-        // type param. Even worse, we need to check for `?` before or after the
-        // bound.
-        let mut span = self.span;
-        let mut ident = self.parse_ident();
-        let mut unbound = None;
-        if self.eat(&token::Question) {
-            let tref = Parser::trait_ref_from_ident(ident, span);
-            unbound = Some(tref);
-            span = self.span;
-            ident = self.parse_ident();
-            self.obsolete(span, ObsoleteSyntax::Sized);
-        }
+        let span = self.span;
+        let ident = self.parse_ident();
 
-        let mut bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified);
-        if let Some(unbound) = unbound {
-            let mut bounds_as_vec = bounds.into_vec();
-            bounds_as_vec.push(TraitTyParamBound(PolyTraitRef { bound_lifetimes: vec![],
-                                                                trait_ref: unbound,
-                                                                span: span },
-                                                 TraitBoundModifier::Maybe));
-            bounds = OwnedSlice::from_vec(bounds_as_vec);
-        };
+        let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified);
 
         let default = if self.check(&token::Eq) {
             self.bump();
             Some(self.parse_ty_sum())
-        }
-        else { None };
+        } else {
+            None
+        };
 
         TyParam {
             ident: ident,
@@ -4654,22 +4456,9 @@ impl<'a> Parser<'a> {
 
         let ident = self.parse_ident();
         let mut tps = self.parse_generics();
-        // This is not very accurate, but since unbound only exists to catch
-        // obsolete syntax, the span is unlikely to ever be used.
-        let unbound_span = self.span;
-        let unbound = self.parse_for_sized();
 
         // Parse supertrait bounds.
-        let mut bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare);
-
-        if let Some(unbound) = unbound {
-            let mut bounds_as_vec = bounds.into_vec();
-            bounds_as_vec.push(TraitTyParamBound(PolyTraitRef { bound_lifetimes: vec![],
-                                                                trait_ref: unbound,
-                                                                span:  unbound_span },
-                                                 TraitBoundModifier::Maybe));
-            bounds = OwnedSlice::from_vec(bounds_as_vec);
-        };
+        let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare);
 
         self.parse_where_clause(&mut tps);
 
@@ -4956,39 +4745,6 @@ impl<'a> Parser<'a> {
         else { Inherited }
     }
 
-    fn parse_for_sized(&mut self) -> Option<ast::TraitRef> {
-        // FIXME, this should really use TraitBoundModifier, but it will get
-        // re-jigged shortly in any case, so leaving the hacky version for now.
-        if self.eat_keyword(keywords::For) {
-            let span = self.span;
-
-            let mut ate_question = false;
-            if self.eat(&token::Question) {
-                ate_question = true;
-            }
-            let ident = self.parse_ident();
-            if self.eat(&token::Question) {
-                if ate_question {
-                    self.span_err(span,
-                        "unexpected `?`");
-                }
-                ate_question = true;
-            }
-            if !ate_question {
-                self.span_err(span,
-                    "expected `?Sized` after `for` in trait item");
-                return None;
-            }
-            let _tref = Parser::trait_ref_from_ident(ident, span);
-
-            self.obsolete(span, ObsoleteSyntax::ForSized);
-
-            None
-        } else {
-            None
-        }
-    }
-
     /// Given a termination token, parse all of the items in a module
     fn parse_mod_items(&mut self, term: &token::Token, inner_lo: BytePos) -> Mod {
         let mut items = vec![];
@@ -5064,8 +4820,8 @@ impl<'a> Parser<'a> {
                     outer_attrs: &[ast::Attribute],
                     id_sp: Span)
                     -> (ast::Item_, Vec<ast::Attribute> ) {
-        let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm
-                                           .span_to_filename(self.span));
+        let mut prefix = PathBuf::from(&self.sess.span_diagnostic.cm
+                                            .span_to_filename(self.span));
         prefix.pop();
         let mut dir_path = prefix;
         for part in &self.mod_path_stack {
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 239fea57d94..828d085fd43 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2712,8 +2712,20 @@ impl<'a> State<'a> {
                        opt_explicit_self: Option<&ast::ExplicitSelf_>)
                        -> io::Result<()> {
         try!(self.ibox(indent_unit));
+        if generics.lifetimes.len() > 0 || generics.ty_params.len() > 0 {
+            try!(word(&mut self.s, "for"));
+            try!(self.print_generics(generics));
+        }
+        let generics = ast::Generics {
+            lifetimes: Vec::new(),
+            ty_params: OwnedSlice::empty(),
+            where_clause: ast::WhereClause {
+                id: ast::DUMMY_NODE_ID,
+                predicates: Vec::new(),
+            },
+        };
         try!(self.print_fn(decl, unsafety, abi, name,
-                           generics, opt_explicit_self,
+                           &generics, opt_explicit_self,
                            ast::Inherited));
         self.end()
     }