diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-07-27 20:42:07 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-07-28 11:59:54 +0200 |
| commit | 7cf7ead0bc840b097b770773b7a58d99bf3f5bdf (patch) | |
| tree | becd6260027a919dbdf48a5580e37d1f0b8fb84d /compiler/rustc_middle/src | |
| parent | 2643b16468fda787470340890212591d8bc832b7 (diff) | |
| download | rust-7cf7ead0bc840b097b770773b7a58d99bf3f5bdf.tar.gz rust-7cf7ead0bc840b097b770773b7a58d99bf3f5bdf.zip | |
Use line numbers relative to function in mir opt tests
This adds a new option, `-Zmir-pretty-relative-line-numbers`, that is then used in compiletest for the mir-opt tests.
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/mir/pretty.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 78b5131bac6..0ce41337b91 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -360,7 +360,7 @@ where "{:A$} // {}{}", indented_body, if tcx.sess.verbose() { format!("{:?}: ", current_location) } else { String::new() }, - comment(tcx, statement.source_info), + comment(tcx, statement.source_info, body.span), A = ALIGN, )?; @@ -381,7 +381,7 @@ where "{:A$} // {}{}", indented_terminator, if tcx.sess.verbose() { format!("{:?}: ", current_location) } else { String::new() }, - comment(tcx, data.terminator().source_info), + comment(tcx, data.terminator().source_info, body.span), A = ALIGN, )?; @@ -518,8 +518,14 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { } } -fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo) -> String { - format!("scope {} at {}", scope.index(), tcx.sess.source_map().span_to_embeddable_string(span)) +fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo, function_span: Span) -> String { + let location = if tcx.sess.opts.unstable_opts.mir_pretty_relative_line_numbers { + tcx.sess.source_map().span_to_relative_line_string(span, function_span) + } else { + tcx.sess.source_map().span_to_embeddable_string(span) + }; + + format!("scope {} at {}", scope.index(), location,) } /// Prints local variables in a scope tree. @@ -550,7 +556,7 @@ fn write_scope_tree( "{0:1$} // in {2}", indented_debug_info, ALIGN, - comment(tcx, var_debug_info.source_info), + comment(tcx, var_debug_info.source_info, body.span), )?; } @@ -585,7 +591,7 @@ fn write_scope_tree( indented_decl, ALIGN, local_name, - comment(tcx, local_decl.source_info), + comment(tcx, local_decl.source_info, body.span), )?; } |
