]> git.lizzy.rs Git - rust.git/commitdiff
rustc: always rely on '_ to be not printed by ty::Region itself.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 10 Dec 2018 15:36:24 +0000 (17:36 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 07:26:13 +0000 (09:26 +0200)
src/librustc/traits/specialize/mod.rs
src/librustc/ty/structural_impls.rs
src/librustc/util/ppaux.rs
src/test/ui/issues/issue-17905-2.stderr
src/test/ui/nll/closure-requirements/escape-argument-callee.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr
src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr

index a2924cb993fbf6f2039b5eeeb1e07663c3ea5a8b..69d5492c0f4502a5244604995b3a4d1e34c58329 100644 (file)
@@ -411,7 +411,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_, '_, '_>, impl_def_id: DefId) -> Option<
         w.push('<');
         w.push_str(&substs.iter()
             .map(|k| k.to_string())
-            .filter(|k| &k[..] != "'_")
+            .filter(|k| !k.is_empty())
             .collect::<Vec<_>>().join(", "));
         w.push('>');
     }
index a19eb1d9545a23e8a2e2eb0a8d1fec9a4770e0ae..43ab32237dea5b69c2152c69354598a8b897d63f 100644 (file)
@@ -55,6 +55,7 @@
     crate::ty::IntVarValue,
     crate::ty::ParamConst,
     crate::ty::ParamTy,
+    crate::ty::RegionVid,
     crate::ty::UniverseIndex,
     crate::ty::Variance,
     ::syntax_pos::Span,
index 6667d37873310e23ca87aed04ea9f8a543eab416..2a03f32fdccdff68efd47040ff61b4d383238c9a 100644 (file)
@@ -120,17 +120,6 @@ pub fn highlighting_region_vid<R>(
         Self::highlighting_region(&ty::ReVar(vid), number, op)
     }
 
-    /// Returns `true` if any placeholders are highlighted, and `false` otherwise.
-    fn any_region_vids_highlighted(&self) -> bool {
-        Self::get()
-            .highlight_regions
-            .iter()
-            .any(|h| match h {
-                Some((ty::ReVar(_), _)) => true,
-                _ => false,
-            })
-    }
-
     /// Returns `Some(n)` with the number to use for the given region, if any.
     fn region_highlighted(&self, region: ty::Region<'_>) -> Option<usize> {
         Self::get()
@@ -163,17 +152,6 @@ pub fn highlighting_bound_region<R>(
         )
     }
 
-    /// Returns `true` if any placeholders are highlighted, and `false` otherwise.
-    pub fn any_placeholders_highlighted(&self) -> bool {
-        Self::get()
-            .highlight_regions
-            .iter()
-            .any(|h| match h {
-                Some((ty::RePlaceholder(_), _)) => true,
-                _ => false,
-            })
-    }
-
     /// Returns `Some(N)` if the placeholder `p` is highlighted to print as "`'N`".
     pub fn placeholder_highlight(&self, p: ty::PlaceholderRegion) -> Option<usize> {
         self.region_highlighted(&ty::RePlaceholder(p))
@@ -421,7 +399,7 @@ fn parameterized<F: fmt::Write>(
                     if self.is_verbose {
                         write!(f, "{:?}", region)?;
                     } else {
-                        let s = region.to_string();
+                        let s = region.print_display_to_string(self);
                         if s.is_empty() {
                             // This happens when the value of the region
                             // parameter is not easily serialized. This may be
@@ -720,19 +698,20 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 return self.print_debug(f, cx);
             }
 
-            if let Some((region, counter)) = RegionHighlightMode::get().highlight_bound_region {
-                if *self == region {
-                    return match *self {
-                        BrNamed(_, name) => write!(f, "{}", name),
-                        BrAnon(_) | BrFresh(_) | BrEnv => write!(f, "'{}", counter)
-                    };
+            if let BrNamed(_, name) = *self {
+                if name != "" && name != "'_" {
+                    return write!(f, "{}", name);
                 }
             }
 
-            match *self {
-                BrNamed(_, name) => write!(f, "{}", name),
-                BrAnon(_) | BrFresh(_) | BrEnv => Ok(())
+            let highlight = RegionHighlightMode::get();
+            if let Some((region, counter)) = highlight.highlight_bound_region {
+                if *self == region {
+                    return write!(f, "'{}", counter);
+                }
             }
+
+            Ok(())
         }
         debug {
             return match *self {
@@ -757,12 +736,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
             let highlight = RegionHighlightMode::get();
             if let Some(counter) = highlight.placeholder_highlight(*self) {
-                write!(f, "'{}", counter)
-            } else if highlight.any_placeholders_highlighted() {
-                write!(f, "'_")
-            } else {
-                write!(f, "{}", self.name)
+                return write!(f, "'{}", counter);
             }
+
+            write!(f, "{}", self.name)
         }
     }
 }
@@ -785,7 +762,11 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
             // `explain_region()` or `note_and_explain_region()`.
             match *self {
                 ty::ReEarlyBound(ref data) => {
-                    write!(f, "{}", data.name)
+                    if data.name != "'_" {
+                        write!(f, "{}", data.name)
+                    } else {
+                        Ok(())
+                    }
                 }
                 ty::ReLateBound(_, br) |
                 ty::ReFree(ty::FreeRegion { bound_region: br, .. }) => {
@@ -812,14 +793,11 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                         ),
                     }
                 }
+                ty::ReVar(region_vid) if cx.identify_regions => {
+                    write!(f, "{:?}", region_vid)
+                }
                 ty::ReVar(region_vid) => {
-                    if RegionHighlightMode::get().any_region_vids_highlighted() {
-                        write!(f, "{:?}", region_vid)
-                    } else if cx.identify_regions {
-                        write!(f, "'{}rv", region_vid.index())
-                    } else {
-                        Ok(())
-                    }
+                    write!(f, "{}", region_vid)
                 }
                 ty::ReScope(_) |
                 ty::ReErased => Ok(()),
@@ -938,15 +916,30 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-impl fmt::Debug for ty::RegionVid {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        if let Some(counter) = RegionHighlightMode::get().region_highlighted(&ty::ReVar(*self)) {
-            return write!(f, "'{:?}", counter);
-        } else if RegionHighlightMode::get().any_region_vids_highlighted() {
-            return write!(f, "'_");
+define_print! {
+    () ty::RegionVid, (self, f, cx) {
+        display {
+            if cx.is_verbose {
+                return self.print_debug(f, cx);
+            }
+
+            let highlight = RegionHighlightMode::get();
+            if let Some(counter) = highlight.region_highlighted(&ty::ReVar(*self)) {
+                return write!(f, "'{:?}", counter);
+            }
+
+            Ok(())
         }
+        debug {
+            // HACK(eddyb) this is duplicated from `display` printing,
+            // to keep NLL borrowck working even with `-Zverbose`.
+            let highlight = RegionHighlightMode::get();
+            if let Some(counter) = highlight.region_highlighted(&ty::ReVar(*self)) {
+                return write!(f, "'{:?}", counter);
+            }
 
-        write!(f, "'_#{}r", self.index())
+            write!(f, "'_#{}r", self.index())
+        }
     }
 }
 
@@ -954,16 +947,15 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     () ty::InferTy, (self, f, cx) {
         display {
             if cx.is_verbose {
-                print!(f, cx, print_debug(self))
-            } else {
-                match *self {
-                    ty::TyVar(_) => write!(f, "_"),
-                    ty::IntVar(_) => write!(f, "{}", "{integer}"),
-                    ty::FloatVar(_) => write!(f, "{}", "{float}"),
-                    ty::FreshTy(v) => write!(f, "FreshTy({})", v),
-                    ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
-                    ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)
-                }
+                return self.print_debug(f, cx);
+            }
+            match *self {
+                ty::TyVar(_) => write!(f, "_"),
+                ty::IntVar(_) => write!(f, "{}", "{integer}"),
+                ty::FloatVar(_) => write!(f, "{}", "{float}"),
+                ty::FreshTy(v) => write!(f, "FreshTy({})", v),
+                ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
+                ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)
             }
         }
         debug {
@@ -1061,12 +1053,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 }
                 Ref(r, ty, mutbl) => {
                     write!(f, "&")?;
-                    let s = r.print_to_string(cx);
-                    if s != "'_" {
-                        write!(f, "{}", s)?;
-                        if !s.is_empty() {
-                            write!(f, " ")?;
-                        }
+                    let s = r.print_display_to_string(cx);
+                    if !s.is_empty() {
+                        write!(f, "{} ", s)?;
                     }
                     ty::TypeAndMut { ty, mutbl }.print(f, cx)
                 }
@@ -1112,7 +1101,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 }
                 Adt(def, substs) => cx.parameterized(f, def.did, substs, iter::empty()),
                 Dynamic(data, r) => {
-                    let r = r.print_to_string(cx);
+                    let r = r.print_display_to_string(cx);
                     if !r.is_empty() {
                         write!(f, "(")?;
                     }
index f185f49b9b9224242ad675be87ae12022bd34fe9..e3909e0c1253f3fdedf97fa095bb45c6013240fd 100644 (file)
@@ -4,7 +4,7 @@ error[E0308]: mismatched method receiver
 LL |     fn say(self: &Pair<&str, isize>) {
    |                  ^^^^^^^^^^^^^^^^^^ lifetime mismatch
    |
-   = note: expected type `Pair<&'_ str, _>`
+   = note: expected type `Pair<&str, _>`
               found type `Pair<&str, _>`
 note: the anonymous lifetime #2 defined on the method body at 8:5...
   --> $DIR/issue-17905-2.rs:8:5
@@ -27,7 +27,7 @@ error[E0308]: mismatched method receiver
 LL |     fn say(self: &Pair<&str, isize>) {
    |                  ^^^^^^^^^^^^^^^^^^ lifetime mismatch
    |
-   = note: expected type `Pair<&'_ str, _>`
+   = note: expected type `Pair<&str, _>`
               found type `Pair<&str, _>`
 note: the lifetime '_ as defined on the impl at 5:5...
   --> $DIR/issue-17905-2.rs:5:5
index 8e407070342cfc690304d6b42d872f8b4fcb50ee..46de13dbbbd9bbe944fd2c92781e4f1c77292fd8 100644 (file)
@@ -16,7 +16,7 @@ LL |         let mut closure = expect_sig(|p, y| *p = y);
    |                                       -  -  ^^^^^^ assignment requires that `'1` must outlive `'2`
    |                                       |  |
    |                                       |  has type `&'1 i32`
-   |                                       has type `&mut &'2 i32`
+   |                                       has type `&'_#2r mut &'2 i32`
 
 note: No external requirements
   --> $DIR/escape-argument-callee.rs:20:1
index 067bd08220df4de97ae00bcc637304b21368a29b..7eb4d96fc5f752c50901280f907cd7547531d86e 100644 (file)
@@ -20,9 +20,9 @@ error: lifetime may not live long enough
   --> $DIR/propagate-approximated-fail-no-postdom.rs:46:13
    |
 LL |         |_outlives1, _outlives2, _outlives3, x, y| {
-   |          ----------              ---------- has type `std::cell::Cell<&'2 &u32>`
+   |          ----------              ---------- has type `std::cell::Cell<&'2 &'_#3r u32>`
    |          |
-   |          has type `std::cell::Cell<&&'1 u32>`
+   |          has type `std::cell::Cell<&'_#1r &'1 u32>`
 ...
 LL |             demand_y(x, y, p)
    |             ^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
index 5cf37bedb8853d2d2bf4633d69700190938fe33e..f8b6bfa003b32fc6a4da19cd6f66c4269926ffda 100644 (file)
@@ -20,9 +20,9 @@ error: lifetime may not live long enough
   --> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:37:9
    |
 LL |     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-   |                                                ---------  - has type `&std::cell::Cell<&'1 u32>`
+   |                                                ---------  - has type `&'_#7r std::cell::Cell<&'1 u32>`
    |                                                |
-   |                                                has type `&std::cell::Cell<&'2 &u32>`
+   |                                                has type `&'_#5r std::cell::Cell<&'2 &'_#1r u32>`
 LL |         // Only works if 'x: 'y:
 LL |         demand_y(x, y, x.get())
    |         ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
index 671a8b9a93575c7a76f66828a689889b6b9b2386..7e7429405fa068d5434e5c20d055744451b07fb8 100644 (file)
@@ -20,9 +20,9 @@ error: lifetime may not live long enough
   --> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:41:9
    |
 LL |     establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
-   |                                                ----------  ---------- has type `&std::cell::Cell<&'2 &u32>`
+   |                                                ----------  ---------- has type `&'_#8r std::cell::Cell<&'2 &'_#2r u32>`
    |                                                |
-   |                                                has type `&std::cell::Cell<&'1 &u32>`
+   |                                                has type `&'_#6r std::cell::Cell<&'1 &'_#1r u32>`
 LL |         // Only works if 'x: 'y:
 LL |         demand_y(x, y, x.get())
    |         ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`