sess: stabilize --terminal-width

Formerly `-Zterminal-width`, `--terminal-width` allows the user or build
tool to inform rustc of the width of the terminal so that diagnostics
can be truncated.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-02-14 06:01:38 +00:00
parent 5b8cf49c51
commit e5288842fa
13 changed files with 66 additions and 11 deletions
compiler
rustc_interface/src
rustc_session/src
src

@ -689,7 +689,6 @@ fn test_debugging_options_tracking_hash() {
untracked!(span_debug, true);
untracked!(span_free_formats, true);
untracked!(temps_dir, Some(String::from("abc")));
untracked!(terminal_width, Some(80));
untracked!(threads, 99);
untracked!(time, true);
untracked!(time_llvm_passes, true);

@ -726,6 +726,7 @@ impl Default for Options {
prints: Vec::new(),
cg: Default::default(),
error_format: ErrorOutputType::default(),
terminal_width: None,
externs: Externs(BTreeMap::new()),
crate_name: None,
libs: Vec::new(),
@ -1427,6 +1428,12 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
never = never colorize output",
"auto|always|never",
),
opt::opt_s(
"",
"terminal-width",
"Inform rustc of the width of the terminal so that errors can be truncated",
"WIDTH",
),
opt::multi_s(
"",
"remap-path-prefix",
@ -2202,6 +2209,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let error_format = parse_error_format(matches, color, json_rendered);
let terminal_width = matches.opt_get("terminal-width").unwrap_or_else(|_| {
early_error(error_format, "`--terminal-width` must be an positive integer");
});
let unparsed_crate_types = matches.opt_strs("crate-type");
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
.unwrap_or_else(|e| early_error(error_format, &e));
@ -2474,6 +2485,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
prints,
cg,
error_format,
terminal_width,
externs,
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
crate_name,

@ -170,6 +170,7 @@ top_level_options!(
test: bool [TRACKED],
error_format: ErrorOutputType [UNTRACKED],
terminal_width: Option<usize> [UNTRACKED],
/// If `Some`, enable incremental compilation, using the given
/// directory to store intermediate results.

@ -1162,7 +1162,7 @@ fn default_emitter(
fallback_bundle,
short,
sopts.debugging_opts.teach,
sopts.debugging_opts.terminal_width,
sopts.terminal_width,
macro_backtrace,
),
Some(dst) => EmitterWriter::new(
@ -1188,7 +1188,7 @@ fn default_emitter(
fallback_bundle,
pretty,
json_rendered,
sopts.debugging_opts.terminal_width,
sopts.terminal_width,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing),
@ -1202,7 +1202,7 @@ fn default_emitter(
fallback_bundle,
pretty,
json_rendered,
sopts.debugging_opts.terminal_width,
sopts.terminal_width,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing),

@ -73,6 +73,8 @@ pub(crate) struct Options {
pub(crate) proc_macro_crate: bool,
/// How to format errors and warnings.
pub(crate) error_format: ErrorOutputType,
/// Width of terminal to truncate errors appropriately.
pub(crate) terminal_width: Option<usize>,
/// Library search paths to hand to the compiler.
pub(crate) libs: Vec<SearchPath>,
/// Library search paths strings to hand to the compiler.
@ -334,11 +336,12 @@ impl Options {
let config::JsonConfig { json_rendered, json_unused_externs, .. } =
config::parse_json(matches);
let error_format = config::parse_error_format(matches, color, json_rendered);
let terminal_width = matches.opt_get("terminal-width").unwrap_or_default();
let codegen_options = CodegenOptions::build(matches, error_format);
let debugging_opts = DebuggingOptions::build(matches, error_format);
let diag = new_handler(error_format, None, &debugging_opts);
let diag = new_handler(error_format, None, terminal_width, &debugging_opts);
// check for deprecated options
check_deprecated_options(matches, &diag);
@ -702,6 +705,7 @@ impl Options {
input,
proc_macro_crate,
error_format,
terminal_width,
libs,
lib_strs,
externs,

@ -154,6 +154,7 @@ impl<'tcx> DocContext<'tcx> {
pub(crate) fn new_handler(
error_format: ErrorOutputType,
source_map: Option<Lrc<source_map::SourceMap>>,
terminal_width: Option<usize>,
debugging_opts: &DebuggingOptions,
) -> rustc_errors::Handler {
let fallback_bundle =
@ -169,7 +170,7 @@ pub(crate) fn new_handler(
fallback_bundle,
short,
debugging_opts.teach,
debugging_opts.terminal_width,
terminal_width,
false,
)
.ui_testing(debugging_opts.ui_testing),
@ -187,7 +188,7 @@ pub(crate) fn new_handler(
fallback_bundle,
pretty,
json_rendered,
debugging_opts.terminal_width,
terminal_width,
false,
)
.ui_testing(debugging_opts.ui_testing),
@ -208,6 +209,7 @@ pub(crate) fn create_config(
crate_name,
proc_macro_crate,
error_format,
terminal_width,
libs,
externs,
mut cfgs,
@ -266,6 +268,7 @@ pub(crate) fn create_config(
actually_rustdoc: true,
debugging_opts,
error_format,
terminal_width,
edition,
describe_lints,
crate_name,

@ -462,6 +462,14 @@ fn opts() -> Vec<RustcOptGroup> {
"human|json|short",
)
}),
unstable("terminal-width", |o| {
o.optopt(
"",
"terminal-width",
"Provide width of the terminal for truncated error messages",
"WIDTH",
)
}),
stable("json", |o| {
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
}),
@ -733,7 +741,12 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
}
fn main_options(options: config::Options) -> MainResult {
let diag = core::new_handler(options.error_format, None, &options.debugging_opts);
let diag = core::new_handler(
options.error_format,
None,
options.terminal_width,
&options.debugging_opts,
);
match (options.should_test, options.markdown_input()) {
(true, true) => return wrap_return(&diag, markdown::test(options)),

@ -110,6 +110,9 @@ Options:
never = never colorize output
--error-format human|json|short
How errors and other messages are produced
--terminal-width WIDTH
Provide width of the terminal for truncated error
messages
--json CONFIG Configure the structure of JSON diagnostics
--disable-minification
Disable minification applied on JS files

@ -0,0 +1,5 @@
// compile-flags: -Zunstable-options --terminal-width=10
#![deny(rustdoc::bare_urls)]
/// This is a long line that contains a http://link.com
pub struct Foo; //~^ ERROR

@ -0,0 +1,15 @@
error: this URL is not a hyperlink
--> $DIR/terminal-width.rs:4:41
|
LL | ... a http://link.com
| ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://link.com>`
|
note: the lint level is defined here
--> $DIR/terminal-width.rs:2:9
|
LL | ...ny(rustdoc::bare_url...
| ^^^^^^^^^^^^^^^^^^
= note: bare URLs are not automatically turned into clickable links
error: aborting due to previous error

@ -1,4 +1,4 @@
// compile-flags: -Z terminal-width=20
// compile-flags: --terminal-width=20
// This test checks that `-Z terminal-width` effects the human error output by restricting it to an
// arbitrarily low value so that the effect is visible.

@ -1,4 +1,4 @@
// compile-flags: -Z terminal-width=20 --error-format=json
// compile-flags: --terminal-width=20 --error-format=json
// This test checks that `-Z terminal-width` effects the JSON error output by restricting it to an
// arbitrarily low value so that the effect is visible.

@ -24,7 +24,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/flag-json.rs","byte_start":244,"byte_end":246,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":" let _: () = 42;","highlight_start":17,"highlight_end":19}],"label":"expected `()`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/flag-json.rs","byte_start":239,"byte_end":241,"line_start":7,"line_end":7,"column_start":12,"column_end":14,"is_primary":false,"text":[{"text":" let _: () = 42;","highlight_start":12,"highlight_end":14}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0308]: mismatched types
"},"level":"error","spans":[{"file_name":"$DIR/flag-json.rs","byte_start":243,"byte_end":245,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":" let _: () = 42;","highlight_start":17,"highlight_end":19}],"label":"expected `()`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/flag-json.rs","byte_start":238,"byte_end":240,"line_start":7,"line_end":7,"column_start":12,"column_end":14,"is_primary":false,"text":[{"text":" let _: () = 42;","highlight_start":12,"highlight_end":14}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0308]: mismatched types
--> $DIR/flag-json.rs:7:17
|
LL | ..._: () = 42;