Skip to content

Commit

Permalink
Rollup merge of rust-lang#66850 - eddyb:span-free-formats, r=oli-obk
Browse files Browse the repository at this point in the history
rustc: hide HirId's fmt::Debug output from -Z span_free_formats.

This replaces the only occurrences of `HirId {...}` from tests with paths, i.e.:
```rust
[closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T]
```
becomes, after this PR:
```rust
[closure@foo<T>::{{closure}}#0 q:&i32, t:&T]
```

r? @oli-obk cc @michaelwoerister
  • Loading branch information
Centril authored Dec 2, 2019
2 parents fd09fad + 7171060 commit dbe880e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,10 +2313,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
}

AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
format!("[closure@{:?}]", hir_id)
let substs = tcx.lift(&substs).unwrap();
format!(
"[closure@{}]",
tcx.def_path_str_with_substs(def_id, substs),
)
} else {
format!("[closure@{:?}]", tcx.hir().span(hir_id))
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
if self.tcx().sess.opts.debugging_opts.span_free_formats {
p!(write("@{:?}", hir_id));
p!(write("@"), print_def_path(did, substs));
} else {
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/inline-closure-borrows-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
// debug _t => _1;
// debug q => _2;
// let mut _0: i32;
// let _3: [closure@HirId { owner: DefIndex(4), local_id: 31 }];
// let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 31 }];
// let _3: [closure@foo<T>::{{closure}}#0];
// let mut _4: &[closure@foo<T>::{{closure}}#0];
// let mut _5: (&i32, &i32);
// let mut _6: &i32;
// let mut _7: &i32;
Expand All @@ -40,7 +40,7 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
// }
// bb0: {
// ...
// _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }];
// _3 = [closure@foo::<T>::{{closure}}#0];
// ...
// _4 = &_3;
// ...
Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/inline-closure-captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fn foo<T: Copy>(t: T, q: i32) -> (i32, T) {
// debug t => _1;
// debug q => _2;
// let mut _0: (i32, T);
// let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T];
// let _3: [closure@foo<T>::{{closure}}#0 q:&i32, t:&T];
// let mut _4: &i32;
// let mut _5: &T;
// let mut _6: &[closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T];
// let mut _6: &[closure@foo<T>::{{closure}}#0 q:&i32, t:&T];
// let mut _7: (i32,);
// let mut _8: i32;
// let mut _11: i32;
Expand All @@ -39,7 +39,7 @@ fn foo<T: Copy>(t: T, q: i32) -> (i32, T) {
// _4 = &_2;
// ...
// _5 = &_1;
// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }] { q: move _4, t: move _5 };
// _3 = [closure@foo::<T>::{{closure}}#0] { q: move _4, t: move _5 };
// ...
// _6 = &_3;
// ...
Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/inline-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn foo<T: Copy>(_t: T, q: i32) -> i32 {
// debug _t => _1;
// debug q => _2;
// let mut _0: i32;
// let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 }];
// let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 15 }];
// let _3: [closure@foo<T>::{{closure}}#0];
// let mut _4: &[closure@foo<T>::{{closure}}#0];
// let mut _5: (i32, i32);
// let mut _6: i32;
// let mut _7: i32;
Expand All @@ -33,7 +33,7 @@ fn foo<T: Copy>(_t: T, q: i32) -> i32 {
// }
// bb0: {
// ...
// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }];
// _3 = [closure@foo::<T>::{{closure}}#0];
// ...
// _4 = &_3;
// ...
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/retag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn main() {
// }
// END rustc.main.EraseRegions.after.mir
// START rustc.main-{{closure}}.EraseRegions.after.mir
// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(13), local_id: 72 }], _2: &i32) -> &i32 {
// fn main::{{closure}}#0(_1: &[closure@main::{{closure}}#0], _2: &i32) -> &i32 {
// ...
// bb0: {
// Retag([fn entry] _1);
Expand Down

0 comments on commit dbe880e

Please sign in to comment.