]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/print.rs
Fix impl Trait Lifetime Handling
[rust.git] / src / librustc / hir / print.rs
index 7b4881f5486dc0b756ad233a7a16176a5a10e951..d94dd24af3edc74277110793b5c7a9e6449ee334 100644 (file)
@@ -421,8 +421,11 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
                     self.print_lifetime(lifetime)?;
                 }
             }
-            hir::TyImplTrait(ref bounds) => {
-                self.print_bounds("impl ", &bounds[..])?;
+            hir::TyImplTraitExistential(ref existty, ref _lifetimes) => {
+                self.print_bounds("impl", &existty.bounds[..])?;
+            }
+            hir::TyImplTraitUniversal(_, ref bounds) => {
+                self.print_bounds("impl", &bounds[..])?;
             }
             hir::TyArray(ref ty, v) => {
                 self.s.word("[")?;
@@ -1254,6 +1257,15 @@ fn print_expr_binary(&mut self,
             Fixity::None => (prec + 1, prec + 1),
         };
 
+        let left_prec = match (&lhs.node, op.node) {
+            // These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
+            // the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
+            // of `(x as i32) < ...`. We need to convince it _not_ to do that.
+            (&hir::ExprCast { .. }, hir::BinOp_::BiLt) |
+            (&hir::ExprCast { .. }, hir::BinOp_::BiShl) => parser::PREC_FORCE_PAREN,
+            _ => left_prec,
+        };
+
         self.print_expr_maybe_paren(lhs, left_prec)?;
         self.s.space()?;
         self.word_space(op.node.as_str())?;