Skip to content

Commit

Permalink
adjust how closure/generator types are printed
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 9, 2023
1 parent 5ede940 commit d9d80be
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// | expected `()`, found closure
// |
// = note: expected unit type `()`
// found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
// found closure `{closure@$DIR/issue-20862.rs:2:5: 2:14 x:_}`
//
// Also ignore opaque `Future`s that come from async fns.
if !self.ignore_span.overlaps(span)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,11 +2174,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
AggregateKind::Closure(def_id, args) => ty::tls::with(|tcx| {
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
let args = tcx.lift(args).unwrap();
format!("[closure@{}]", tcx.def_path_str_with_args(def_id, args),)
format!("{{closure@{}}}", tcx.def_path_str_with_args(def_id, args),)
} else {
let span = tcx.def_span(def_id);
format!(
"[closure@{}]",
"{{closure@{}}}",
tcx.sess.source_map().span_to_diagnostic_string(span)
)
};
Expand All @@ -2202,7 +2202,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}),

AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
let name = format!("[generator@{:?}]", tcx.def_span(def_id));
let name = format!("{{generator@{:?}}}", tcx.def_span(def_id));
let mut struct_fmt = fmt.debug_struct(&name);

// FIXME(project-rfc-2229#48): This should be a list of capture names/places
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ pub trait PrettyPrinter<'tcx>:
}

for (assoc_item_def_id, term) in assoc_items {
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
// Skip printing `<{generator@} as Generator<_>>::Return` from async blocks,
// unless we can find out what generator return type it comes from.
let term = if let Some(ty) = term.skip_binder().ty()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,7 @@ impl<'tcx> Ty<'tcx> {

/// Checks whether a type recursively contains any closure
///
/// Example: `Option<[[email protected]:4:20]>` returns true
/// Example: `Option<{[email protected]:4:20}>` returns true
pub fn contains_closure(self) -> bool {
struct ContainsClosureVisitor;

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/inline/inline_closure.foo.Inline.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn foo(_1: T, _2: i32) -> i32 {

bb0: {
StorageLive(_3);
_3 = [closure@foo::<T>::{closure#0}];
_3 = {closure@foo::<T>::{closure#0}};
StorageLive(_4);
_4 = &_3;
StorageLive(_5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn foo(_1: T, _2: &i32) -> i32 {

bb0: {
StorageLive(_3);
_3 = [closure@foo::<T>::{closure#0}];
_3 = {closure@foo::<T>::{closure#0}};
StorageLive(_4);
_4 = &_3;
StorageLive(_5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
_4 = &_2;
StorageLive(_5);
_5 = &_1;
_3 = [closure@foo::<T>::{closure#0}] { q: move _4, t: move _5 };
_3 = {closure@foo::<T>::{closure#0}} { q: move _4, t: move _5 };
StorageDead(_5);
StorageDead(_4);
StorageLive(_6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- }
-
- bb1: {
+ _4 = [generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)];
+ _4 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
_3 = &mut _4;
- _2 = Pin::<&mut [generator@$DIR/inline_generator.rs:16:5: 16:8]>::new(move _3) -> [return: bb2, unwind unreachable];
- }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- }
-
- bb1: {
+ _4 = [generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)];
+ _4 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
_3 = &mut _4;
- _2 = Pin::<&mut [generator@$DIR/inline_generator.rs:16:5: 16:8]>::new(move _3) -> [return: bb2, unwind: bb4];
- }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> () {

bb0: {
StorageLive(_1);
_1 = [closure@$DIR/issue_76997_inline_scopes_parenting.rs:5:13: 5:16];
_1 = {closure@$DIR/issue_76997_inline_scopes_parenting.rs:5:13: 5:16};
StorageLive(_2);
_2 = &_1;
StorageLive(_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn main() -> () {
StorageDead(_2);
StorageLive(_13);
StorageLive(_14);
_14 = [closure@main::{closure#0}];
_14 = {closure@main::{closure#0}};
Retag(_14);
_13 = move _14 as for<'a> fn(&'a i32) -> &'a i32 (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_14);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn main() -> () {
StorageDead(_2);
StorageLive(_13);
StorageLive(_14);
_14 = [closure@main::{closure#0}];
_14 = {closure@main::{closure#0}};
Retag(_14);
_13 = move _14 as for<'a> fn(&'a i32) -> &'a i32 (PointerCoercion(ClosureFnPointer(Normal)));
StorageDead(_14);
Expand Down

0 comments on commit d9d80be

Please sign in to comment.