提交 329b8ca8 编写于 作者: E Eduard-Mihai Burtescu

rustc: always rely on '_ to be not printed by ty::Region itself.

上级 387cacf7
......@@ -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('>');
}
......
......@@ -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,
......
......@@ -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, "(")?;
}
......
......@@ -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
......
......@@ -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
......
......@@ -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`
......
......@@ -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`
......
......@@ -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`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册