Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2fe50cd

Browse files
committed
Auto merge of rust-lang#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 23 additions & 19 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 2 deletions
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.

0 commit comments

Comments
 (0)