]> git.lizzy.rs Git - rust.git/blobdiff - src/types.rs
Fix qself rewrites without explicit casts
[rust.git] / src / types.rs
index 0c0d9e54424ae74596adc5ff05b0578db1f1f6e4..dfb7f255a987643fe2783b63adfc6d2cafdddc89 100644 (file)
@@ -42,19 +42,22 @@ pub fn rewrite_path(context: &RewriteContext,
     if let Some(ref qself) = qself {
         result.push('<');
         result.push_str(&pprust::ty_to_string(&qself.ty));
-        result.push_str(" as ");
-
-        let extra_offset = extra_offset(&result, offset);
-        // 3 = ">::".len()
-        let budget = try_opt!(width.checked_sub(extra_offset)) - 3;
-
-        result = try_opt!(rewrite_path_segments(result,
-                                                path.segments.iter().take(skip_count),
-                                                span_lo,
-                                                path.span.hi,
-                                                context,
-                                                budget,
-                                                offset + extra_offset));
+
+        if skip_count > 0 {
+            result.push_str(" as ");
+
+            let extra_offset = extra_offset(&result, offset);
+            // 3 = ">::".len()
+            let budget = try_opt!(width.checked_sub(extra_offset)) - 3;
+
+            result = try_opt!(rewrite_path_segments(result,
+                                                    path.segments.iter().take(skip_count),
+                                                    span_lo,
+                                                    path.span.hi,
+                                                    context,
+                                                    budget,
+                                                    offset + extra_offset));
+        }
 
         result.push_str(">::");
         span_lo = qself.ty.span.hi + BytePos(1);