Skip to content

Commit 2fe50cd

Browse files
committed
Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank
rework `-Zverbose` implements the changes described in rust-lang/compiler-team#706 the first commit is only a name change from `-Zverbose` to `-Zverbose-internals` and does not change behavior. the second commit changes diagnostics. possible follow up work: - `ty::pretty` could print more info with `--verbose` than it does currently. `-Z verbose-internals` shows too much info in a way that's not helpful to users. michael had ideas about this i didn't fully understand: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408984200 - `--verbose` should imply `-Z write-long-types-to-disk=no`. the code in `ty_string_with_limit` should take `--verbose` into account (apparently this affects `Ty::sort_string`, i'm not familiar with this code). writing a file to disk should suggest passing `--verbose`. r? `@compiler-errors` cc `@estebank`
2 parents ea7ef7b + cb6d033 commit 2fe50cd

File tree

69 files changed

+160
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+160
-98
lines changed

compiler/rustc_driver_impl/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> pprust_ast::PpAnn for AstHygieneAnn<'a> {
146146
}
147147
pprust_ast::AnnNode::Crate(_) => {
148148
s.s.hardbreak();
149-
let verbose = self.sess.verbose();
149+
let verbose = self.sess.verbose_internals();
150150
s.synth_comment(rustc_span::hygiene::debug_hygiene_data(verbose));
151151
s.s.hardbreak_if_not_bol();
152152
}

compiler/rustc_hir_typeck/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
187187
expected: Expectation<'tcx>,
188188
args: &'tcx [hir::Expr<'tcx>],
189189
) -> Ty<'tcx> {
190-
if self.tcx().sess.verbose() {
191-
// make this code only run with -Zverbose because it is probably slow
190+
if self.tcx().sess.verbose_internals() {
191+
// make this code only run with -Zverbose-internals because it is probably slow
192192
if let Ok(lint_str) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
193193
if !lint_str.contains('\n') {
194194
debug!("expr text: {lint_str}");

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12121212
s.push_highlighted(mutbl.prefix_str());
12131213
}
12141214

1215+
fn maybe_highlight<T: Eq + ToString>(
1216+
t1: T,
1217+
t2: T,
1218+
(buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString),
1219+
tcx: TyCtxt<'_>,
1220+
) {
1221+
let highlight = t1 != t2;
1222+
let (t1, t2) = if highlight || tcx.sess.opts.verbose {
1223+
(t1.to_string(), t2.to_string())
1224+
} else {
1225+
// The two types are the same, elide and don't highlight.
1226+
("_".into(), "_".into())
1227+
};
1228+
buf1.push(t1, highlight);
1229+
buf2.push(t2, highlight);
1230+
}
1231+
12151232
fn cmp_ty_refs<'tcx>(
12161233
r1: ty::Region<'tcx>,
12171234
mut1: hir::Mutability,
@@ -1308,7 +1325,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13081325
if lifetimes.0 != lifetimes.1 {
13091326
values.0.push_highlighted(l1);
13101327
values.1.push_highlighted(l2);
1311-
} else if lifetimes.0.is_bound() {
1328+
} else if lifetimes.0.is_bound() || self.tcx.sess.opts.verbose {
13121329
values.0.push_normal(l1);
13131330
values.1.push_normal(l2);
13141331
} else {
@@ -1329,7 +1346,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13291346
let num_display_types = consts_offset - regions_len;
13301347
for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() {
13311348
let i = i + regions_len;
1332-
if ta1 == ta2 && !self.tcx.sess.verbose() {
1349+
if ta1 == ta2 && !self.tcx.sess.opts.verbose {
13331350
values.0.push_normal("_");
13341351
values.1.push_normal("_");
13351352
} else {
@@ -1343,13 +1360,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13431360
let const_arguments = sub1.consts().zip(sub2.consts());
13441361
for (i, (ca1, ca2)) in const_arguments.enumerate() {
13451362
let i = i + consts_offset;
1346-
if ca1 == ca2 && !self.tcx.sess.verbose() {
1347-
values.0.push_normal("_");
1348-
values.1.push_normal("_");
1349-
} else {
1350-
values.0.push_highlighted(ca1.to_string());
1351-
values.1.push_highlighted(ca2.to_string());
1352-
}
1363+
maybe_highlight(ca1, ca2, &mut values, self.tcx);
13531364
self.push_comma(&mut values.0, &mut values.1, len, i);
13541365
}
13551366

@@ -1513,16 +1524,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15131524
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
15141525

15151526
_ => {
1516-
if t1 == t2 && !self.tcx.sess.verbose() {
1517-
// The two types are the same, elide and don't highlight.
1518-
(DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_"))
1519-
} else {
1520-
// We couldn't find anything in common, highlight everything.
1521-
(
1522-
DiagnosticStyledString::highlighted(t1.to_string()),
1523-
DiagnosticStyledString::highlighted(t2.to_string()),
1524-
)
1525-
}
1527+
let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1528+
maybe_highlight(t1, t2, &mut strs, self.tcx);
1529+
strs
15261530
}
15271531
}
15281532
}

compiler/rustc_infer/src/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
1717

1818
impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
1919
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20-
if ty::tls::with(|tcx| tcx.sess.verbose()) {
20+
if ty::tls::with(|tcx| tcx.sess.verbose_internals()) {
2121
write!(
2222
f,
2323
"Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn test_unstable_options_tracking_hash() {
714714
untracked!(unpretty, Some("expanded".to_string()));
715715
untracked!(unstable_options, true);
716716
untracked!(validate_mir, true);
717-
untracked!(verbose, true);
717+
untracked!(verbose_internals, true);
718718
untracked!(write_long_types_to_disk, false);
719719
// tidy-alphabetical-end
720720

compiler/rustc_middle/src/mir/pretty.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ where
627627
w,
628628
"{:A$} // {}{}",
629629
indented_body,
630-
if tcx.sess.verbose() { format!("{current_location:?}: ") } else { String::new() },
630+
if tcx.sess.verbose_internals() {
631+
format!("{current_location:?}: ")
632+
} else {
633+
String::new()
634+
},
631635
comment(tcx, statement.source_info),
632636
A = ALIGN,
633637
)?;
@@ -652,7 +656,11 @@ where
652656
w,
653657
"{:A$} // {}{}",
654658
indented_terminator,
655-
if tcx.sess.verbose() { format!("{current_location:?}: ") } else { String::new() },
659+
if tcx.sess.verbose_internals() {
660+
format!("{current_location:?}: ")
661+
} else {
662+
String::new()
663+
},
656664
comment(tcx, data.terminator().source_info),
657665
A = ALIGN,
658666
)?;
@@ -943,7 +951,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
943951

944952
// When printing regions, add trailing space if necessary.
945953
let print_region = ty::tls::with(|tcx| {
946-
tcx.sess.verbose() || tcx.sess.opts.unstable_opts.identify_regions
954+
tcx.sess.verbose_internals() || tcx.sess.opts.unstable_opts.identify_regions
947955
});
948956
let region = if print_region {
949957
let mut region = region.to_string();
@@ -1668,7 +1676,7 @@ fn pretty_print_const_value_tcx<'tcx>(
16681676
) -> fmt::Result {
16691677
use crate::ty::print::PrettyPrinter;
16701678

1671-
if tcx.sess.verbose() {
1679+
if tcx.sess.verbose_internals() {
16721680
fmt.write_str(&format!("ConstValue({ct:?}: {ty})"))?;
16731681
return Ok(());
16741682
}

compiler/rustc_middle/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'tcx> ObligationCause<'tcx> {
177177

178178
// NOTE(flaper87): As of now, it keeps track of the whole error
179179
// chain. Ideally, we should have a way to configure this either
180-
// by using -Z verbose or just a CLI argument.
180+
// by using -Z verbose-internals or just a CLI argument.
181181
self.code =
182182
variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into();
183183
self

compiler/rustc_middle/src/ty/generics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'tcx> Generics {
326326
own_params.start = 1;
327327
}
328328

329-
let verbose = tcx.sess.verbose();
329+
let verbose = tcx.sess.verbose_internals();
330330

331331
// Filter the default arguments.
332332
//
@@ -342,7 +342,7 @@ impl<'tcx> Generics {
342342
param.default_value(tcx).is_some_and(|default| {
343343
default.instantiate(tcx, args) == args[param.index as usize]
344344
})
345-
// filter out trailing effect params, if we're not in `-Zverbose`.
345+
// filter out trailing effect params, if we're not in `-Zverbose-internals`.
346346
|| (!verbose && matches!(param.kind, GenericParamDefKind::Const { is_host_effect: true, .. }))
347347
})
348348
.count();

compiler/rustc_middle/src/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
744744
// only affect certain debug messages (e.g. messages printed
745745
// from `rustc_middle::ty` during the computation of `tcx.predicates_of`),
746746
// and should have no effect on any compiler output.
747-
// [Unless `-Zverbose` is used, e.g. in the output of
747+
// [Unless `-Zverbose-internals` is used, e.g. in the output of
748748
// `tests/ui/nll/ty-outlives/impl-trait-captures.rs`, for
749749
// example.]
750750
if self.should_print_verbose() {
@@ -829,7 +829,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
829829
}
830830
ty::CoroutineWitness(did, args) => {
831831
p!(write("{{"));
832-
if !self.tcx().sess.verbose() {
832+
if !self.tcx().sess.verbose_internals() {
833833
p!("coroutine witness");
834834
// FIXME(eddyb) should use `def_span`.
835835
if let Some(did) = did.as_local() {
@@ -1698,7 +1698,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
16981698
}
16991699

17001700
fn should_print_verbose(&self) -> bool {
1701-
self.tcx().sess.verbose()
1701+
self.tcx().sess.verbose_internals()
17021702
}
17031703
}
17041704

compiler/rustc_query_impl/src/plumbing.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,11 @@ pub(crate) fn create_query_frame<
315315
ty::print::with_forced_impl_filename_line!(do_describe(tcx, key))
316316
)
317317
);
318-
let description =
319-
if tcx.sess.verbose() { format!("{description} [{name:?}]") } else { description };
318+
let description = if tcx.sess.verbose_internals() {
319+
format!("{description} [{name:?}]")
320+
} else {
321+
description
322+
};
320323
let span = if kind == dep_graph::dep_kinds::def_span || with_no_queries() {
321324
// The `def_span` query is used to calculate `default_span`,
322325
// so exit to avoid infinite recursion.

compiler/rustc_session/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ impl Default for Options {
11161116
working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()),
11171117
color: ColorConfig::Auto,
11181118
logical_env: FxIndexMap::default(),
1119+
verbose: false,
11191120
}
11201121
}
11211122
}
@@ -2916,6 +2917,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29162917
RealFileName::LocalPath(path.into_owned())
29172918
};
29182919

2920+
let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals;
2921+
29192922
Options {
29202923
assert_incr_state,
29212924
crate_types,
@@ -2957,6 +2960,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29572960
working_dir,
29582961
color,
29592962
logical_env,
2963+
verbose,
29602964
}
29612965
}
29622966

compiler/rustc_session/src/options.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ top_level_options!(
223223
/// The (potentially remapped) working directory
224224
working_dir: RealFileName [TRACKED],
225225
color: ColorConfig [UNTRACKED],
226+
227+
verbose: bool [UNTRACKED],
226228
}
227229
);
228230

@@ -1991,8 +1993,8 @@ written to standard error output)"),
19911993
"use legacy .ctors section for initializers rather than .init_array"),
19921994
validate_mir: bool = (false, parse_bool, [UNTRACKED],
19931995
"validate MIR after each transformation"),
1994-
#[rustc_lint_opt_deny_field_access("use `Session::verbose` instead of this field")]
1995-
verbose: bool = (false, parse_bool, [UNTRACKED],
1996+
#[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]
1997+
verbose_internals: bool = (false, parse_bool, [UNTRACKED],
19961998
"in general, enable more debug printouts (default: no)"),
19971999
#[rustc_lint_opt_deny_field_access("use `Session::verify_llvm_ir` instead of this field")]
19982000
verify_llvm_ir: bool = (false, parse_bool, [TRACKED],

compiler/rustc_session/src/session.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ impl Session {
665665
// JUSTIFICATION: defn of the suggested wrapper fns
666666
#[allow(rustc::bad_opt_access)]
667667
impl Session {
668-
pub fn verbose(&self) -> bool {
669-
self.opts.unstable_opts.verbose
668+
pub fn verbose_internals(&self) -> bool {
669+
self.opts.unstable_opts.verbose_internals
670670
}
671671

672672
pub fn print_llvm_stats(&self) -> bool {

compiler/rustc_symbol_mangling/src/legacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
214214
| ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args),
215215

216216
// The `pretty_print_type` formatting of array size depends on
217-
// -Zverbose flag, so we cannot reuse it here.
217+
// -Zverbose-internals flag, so we cannot reuse it here.
218218
ty::Array(ty, size) => {
219219
self.write_str("[")?;
220220
self.print_type(ty)?;
@@ -255,7 +255,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
255255
// only print integers
256256
match (ct.kind(), ct.ty().kind()) {
257257
(ty::ConstKind::Value(ty::ValTree::Leaf(scalar)), ty::Int(_) | ty::Uint(_)) => {
258-
// The `pretty_print_const` formatting depends on -Zverbose
258+
// The `pretty_print_const` formatting depends on -Zverbose-internals
259259
// flag, so we cannot reuse it here.
260260
let signed = matches!(ct.ty().kind(), ty::Int(_));
261261
write!(

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ _Note:_ The order of these lint level arguments is taken into account, see [lint
343343
## `-Z`: set unstable options
344344

345345
This flag will allow you to set unstable options of rustc. In order to set multiple options,
346-
the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time-passes`.
346+
the -Z flag can be used multiple times. For example: `rustc -Z verbose-internals -Z time-passes`.
347347
Specifying options with -Z is only available on nightly. To view all available options
348348
run: `rustc -Z help`, or see [The Unstable Book](../unstable-book/index.html).
349349

tests/mir-opt/nll/named_lifetimes_basic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// suitable variables and that we setup the outlives relationship
55
// between R0 and R1 properly.
66

7-
// compile-flags: -Zverbose
8-
// ^^^^^^^^^ force compiler to dump more region information
7+
// compile-flags: -Zverbose-internals
8+
// ^^^^^^^^^^^^^^^^^^^ force compiler to dump more region information
99

1010
#![allow(warnings)]
1111

tests/mir-opt/nll/region_subtyping_basic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// in the type of `p` includes the points after `&v[0]` up to (but not
44
// including) the call to `use_x`. The `else` branch is not included.
55

6-
// compile-flags:-Zverbose
7-
// ^^^^^^^^^ force compiler to dump more region information
6+
// compile-flags:-Zverbose-internals
7+
// ^^^^^^^^^^^^^^^^^^^ force compiler to dump more region information
88

99
#![allow(warnings)]
1010

tests/ui/associated-types/substs-ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// revisions: verbose normal
33
//
4-
//[verbose] compile-flags: -Z verbose
4+
//[verbose] compile-flags: -Z verbose-internals
55

66
trait Foo<'b, 'c, S=u32> {
77
fn bar<'a, T>() where T: 'a {}

tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Ztrim-diagnostic-paths=off -Zverbose
1+
// compile-flags: -Ztrim-diagnostic-paths=off -Zverbose-internals
22

33
mod mod1 {
44
pub fn f<T: std::fmt::Display>(t: T)

tests/ui/closures/print/closure-print-generic-verbose-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
fn to_fn_once<F:FnOnce()>(f: F) -> F { f }
44

tests/ui/closures/print/closure-print-generic-verbose-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
mod mod1 {
44
pub fn f<T: std::fmt::Display>(t: T)

tests/ui/closures/print/closure-print-verbose.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
// Same as closure-coerce-fn-1.rs
44

tests/ui/coroutine/print/coroutine-print-verbose-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
// Same as: tests/ui/coroutine/issue-68112.stderr
44

tests/ui/coroutine/print/coroutine-print-verbose-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
// Same as test/ui/coroutine/not-send-sync.rs
44
#![feature(coroutines)]

tests/ui/coroutine/print/coroutine-print-verbose-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
#![feature(coroutines, coroutine_trait)]
44

tests/ui/fn/signature-error-reporting-under-verbose.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zverbose
1+
// compile-flags: -Zverbose-internals
22

33
fn foo(_: i32, _: i32) {}
44

tests/ui/impl-trait/erased-regions-in-hidden-ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: current next
2-
// compile-flags: -Zverbose
2+
// compile-flags: -Zverbose-internals
33
//[next] compile-flags: -Znext-solver
44
// normalize-stderr-test "DefId\([^\)]+\)" -> "DefId(..)"
55

0 commit comments

Comments
 (0)