diff options
| author | bors <bors@rust-lang.org> | 2023-12-26 12:27:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-26 12:27:29 +0000 |
| commit | 2fe50cd72c476ebacdedb14893e9632b4de961c2 (patch) | |
| tree | 646eae2f31ec0a7ad1dbef7bce78bf331efda17b /compiler/rustc_infer | |
| parent | ea7ef7b6c224226a4bd9f9796de39d57b527f7f9 (diff) | |
| parent | cb6d033316bdc2a1c5c1c0e04b297fbbb81eafca (diff) | |
| download | rust-2fe50cd72c476ebacdedb14893e9632b4de961c2.tar.gz rust-2fe50cd72c476ebacdedb14893e9632b4de961c2.zip | |
Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank
rework `-Zverbose` implements the changes described in https://github.com/rust-lang/compiler-team/issues/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`
Diffstat (limited to 'compiler/rustc_infer')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 42 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/traits/structural_impls.rs | 2 |
2 files changed, 24 insertions, 20 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 0c0292f329e..b5a6374ec4b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1212,6 +1212,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { s.push_highlighted(mutbl.prefix_str()); } + fn maybe_highlight<T: Eq + ToString>( + t1: T, + t2: T, + (buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString), + tcx: TyCtxt<'_>, + ) { + let highlight = t1 != t2; + let (t1, t2) = if highlight || tcx.sess.opts.verbose { + (t1.to_string(), t2.to_string()) + } else { + // The two types are the same, elide and don't highlight. + ("_".into(), "_".into()) + }; + buf1.push(t1, highlight); + buf2.push(t2, highlight); + } + fn cmp_ty_refs<'tcx>( r1: ty::Region<'tcx>, mut1: hir::Mutability, @@ -1308,7 +1325,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if lifetimes.0 != lifetimes.1 { values.0.push_highlighted(l1); values.1.push_highlighted(l2); - } else if lifetimes.0.is_bound() { + } else if lifetimes.0.is_bound() || self.tcx.sess.opts.verbose { values.0.push_normal(l1); values.1.push_normal(l2); } else { @@ -1329,7 +1346,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let num_display_types = consts_offset - regions_len; for (i, (ta1, ta2)) in type_arguments.take(num_display_types).enumerate() { let i = i + regions_len; - if ta1 == ta2 && !self.tcx.sess.verbose() { + if ta1 == ta2 && !self.tcx.sess.opts.verbose { values.0.push_normal("_"); values.1.push_normal("_"); } else { @@ -1343,13 +1360,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let const_arguments = sub1.consts().zip(sub2.consts()); for (i, (ca1, ca2)) in const_arguments.enumerate() { let i = i + consts_offset; - if ca1 == ca2 && !self.tcx.sess.verbose() { - values.0.push_normal("_"); - values.1.push_normal("_"); - } else { - values.0.push_highlighted(ca1.to_string()); - values.1.push_highlighted(ca2.to_string()); - } + maybe_highlight(ca1, ca2, &mut values, self.tcx); self.push_comma(&mut values.0, &mut values.1, len, i); } @@ -1513,16 +1524,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2), _ => { - if t1 == t2 && !self.tcx.sess.verbose() { - // The two types are the same, elide and don't highlight. - (DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_")) - } else { - // We couldn't find anything in common, highlight everything. - ( - DiagnosticStyledString::highlighted(t1.to_string()), - DiagnosticStyledString::highlighted(t2.to_string()), - ) - } + let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); + maybe_highlight(t1, t2, &mut strs, self.tcx); + strs } } } diff --git a/compiler/rustc_infer/src/traits/structural_impls.rs b/compiler/rustc_infer/src/traits/structural_impls.rs index 8a7c59da09e..51c06c8970b 100644 --- a/compiler/rustc_infer/src/traits/structural_impls.rs +++ b/compiler/rustc_infer/src/traits/structural_impls.rs @@ -17,7 +17,7 @@ impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> { impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if ty::tls::with(|tcx| tcx.sess.verbose()) { + if ty::tls::with(|tcx| tcx.sess.verbose_internals()) { write!( f, "Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})", |
