diff options
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 42 | ||||
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 2 | ||||
| -rw-r--r-- | tests/mir-opt/nll/named_lifetimes_basic.rs | 2 | ||||
| -rw-r--r-- | tests/mir-opt/nll/region_subtyping_basic.rs | 2 | ||||
| -rw-r--r-- | tests/ui/type/verbose.normal.stderr | 14 | ||||
| -rw-r--r-- | tests/ui/type/verbose.rs | 13 | ||||
| -rw-r--r-- | tests/ui/type/verbose.verbose.stderr | 14 |
8 files changed, 72 insertions, 21 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index a799a008a82..85a842df966 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1206,6 +1206,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, @@ -1302,7 +1319,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 { @@ -1323,7 +1340,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_internals() { + if ta1 == ta2 && !self.tcx.sess.opts.verbose { values.0.push_normal("_"); values.1.push_normal("_"); } else { @@ -1337,13 +1354,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_internals() { - 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); } @@ -1507,16 +1518,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2), _ => { - if t1 == t2 && !self.tcx.sess.verbose_internals() { - // 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_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0c21e4eb43e..ddccbc23627 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1116,6 +1116,7 @@ impl Default for Options { working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()), color: ColorConfig::Auto, logical_env: FxIndexMap::default(), + verbose: false, } } } @@ -2916,6 +2917,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M RealFileName::LocalPath(path.into_owned()) }; + let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals; + Options { assert_incr_state, crate_types, @@ -2957,6 +2960,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M working_dir, color, logical_env, + verbose, } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a0e713a3d9d..61996d9b672 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -223,6 +223,8 @@ top_level_options!( /// The (potentially remapped) working directory working_dir: RealFileName [TRACKED], color: ColorConfig [UNTRACKED], + + verbose: bool [UNTRACKED], } ); diff --git a/tests/mir-opt/nll/named_lifetimes_basic.rs b/tests/mir-opt/nll/named_lifetimes_basic.rs index 5b6cc421ab8..bb22ce0ed95 100644 --- a/tests/mir-opt/nll/named_lifetimes_basic.rs +++ b/tests/mir-opt/nll/named_lifetimes_basic.rs @@ -5,7 +5,7 @@ // between R0 and R1 properly. // compile-flags: -Zverbose-internals -// ^^^^^^^^^ force compiler to dump more region information +// ^^^^^^^^^^^^^^^^^^^ force compiler to dump more region information #![allow(warnings)] diff --git a/tests/mir-opt/nll/region_subtyping_basic.rs b/tests/mir-opt/nll/region_subtyping_basic.rs index 0d3139a0ffd..940f8d17344 100644 --- a/tests/mir-opt/nll/region_subtyping_basic.rs +++ b/tests/mir-opt/nll/region_subtyping_basic.rs @@ -4,7 +4,7 @@ // including) the call to `use_x`. The `else` branch is not included. // compile-flags:-Zverbose-internals -// ^^^^^^^^^ force compiler to dump more region information +// ^^^^^^^^^^^^^^^^^^^ force compiler to dump more region information #![allow(warnings)] diff --git a/tests/ui/type/verbose.normal.stderr b/tests/ui/type/verbose.normal.stderr new file mode 100644 index 00000000000..6cb26403336 --- /dev/null +++ b/tests/ui/type/verbose.normal.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/verbose.rs:7:28 + | +LL | let _: Foo<u32, i32> = Foo::<i32, i32> { x: 0, y: 0 }; + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo<u32, i32>`, found `Foo<i32, i32>` + | | + | expected due to this + | + = note: expected struct `Foo<u32, _>` + found struct `Foo<i32, _>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/verbose.rs b/tests/ui/type/verbose.rs new file mode 100644 index 00000000000..4ebd5cdccfc --- /dev/null +++ b/tests/ui/type/verbose.rs @@ -0,0 +1,13 @@ +// revisions:verbose normal +// [verbose]compile-flags:--verbose +#![crate_type = "lib"] + +struct Foo<T, U> { x: T, y: U } +fn bar() { + let _: Foo<u32, i32> = Foo::<i32, i32> { x: 0, y: 0 }; + //~^ ERROR mismatched types + //[verbose]~| NOTE expected struct `Foo<u32, i32>` + //[normal]~| NOTE expected struct `Foo<u32, _>` + //~| NOTE expected `Foo<u32, i32>` + //~| NOTE expected due to this +} diff --git a/tests/ui/type/verbose.verbose.stderr b/tests/ui/type/verbose.verbose.stderr new file mode 100644 index 00000000000..7cc7a16cdb1 --- /dev/null +++ b/tests/ui/type/verbose.verbose.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/verbose.rs:7:28 + | +LL | let _: Foo<u32, i32> = Foo::<i32, i32> { x: 0, y: 0 }; + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo<u32, i32>`, found `Foo<i32, i32>` + | | + | expected due to this + | + = note: expected struct `Foo<u32, i32>` + found struct `Foo<i32, i32>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. |
