Skip to content

rustup backports #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,17 @@ fn print_crate_info(
// Any output here interferes with Cargo's parsing of other printed output
NativeStaticLibs => {}
LinkArgs => {}
SplitDebuginfo => {
use rustc_target::spec::SplitDebuginfo::{Off, Packed, Unpacked};

for split in &[Off, Packed, Unpacked] {
let stable = true; // sess.target.options.supported_split_debuginfo.contains(split);
let unstable_ok = sess.unstable_options();
if stable || unstable_ok {
println!("{}", split);
}
}
}
}
}
Compilation::Stop
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl HumanReadableErrorType {
bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
teach: bool,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> EmitterWriter {
let (short, color_config) = self.unzip();
Expand All @@ -75,7 +75,7 @@ impl HumanReadableErrorType {
short,
teach,
color,
terminal_width,
diagnostic_width,
macro_backtrace,
)
}
Expand Down Expand Up @@ -699,7 +699,7 @@ pub struct EmitterWriter {
short_message: bool,
teach: bool,
ui_testing: bool,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,

macro_backtrace: bool,
}
Expand All @@ -719,7 +719,7 @@ impl EmitterWriter {
fallback_bundle: Lrc<FluentBundle>,
short_message: bool,
teach: bool,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> EmitterWriter {
let dst = Destination::from_stderr(color_config);
Expand All @@ -731,7 +731,7 @@ impl EmitterWriter {
short_message,
teach,
ui_testing: false,
terminal_width,
diagnostic_width,
macro_backtrace,
}
}
Expand All @@ -744,7 +744,7 @@ impl EmitterWriter {
short_message: bool,
teach: bool,
colored: bool,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> EmitterWriter {
EmitterWriter {
Expand All @@ -755,7 +755,7 @@ impl EmitterWriter {
short_message,
teach,
ui_testing: false,
terminal_width,
diagnostic_width,
macro_backtrace,
}
}
Expand Down Expand Up @@ -1593,7 +1593,7 @@ impl EmitterWriter {
width_offset + annotated_file.multiline_depth + 1
};

let column_width = if let Some(width) = self.terminal_width {
let column_width = if let Some(width) = self.diagnostic_width {
width.saturating_sub(code_offset)
} else if self.ui_testing {
DEFAULT_COLUMN_WIDTH
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct JsonEmitter {
pretty: bool,
ui_testing: bool,
json_rendered: HumanReadableErrorType,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
}

Expand All @@ -54,7 +54,7 @@ impl JsonEmitter {
fallback_bundle: Lrc<FluentBundle>,
pretty: bool,
json_rendered: HumanReadableErrorType,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> JsonEmitter {
JsonEmitter {
Expand All @@ -66,7 +66,7 @@ impl JsonEmitter {
pretty,
ui_testing: false,
json_rendered,
terminal_width,
diagnostic_width,
macro_backtrace,
}
}
Expand All @@ -76,7 +76,7 @@ impl JsonEmitter {
json_rendered: HumanReadableErrorType,
fluent_bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: Lrc<FluentBundle>,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> JsonEmitter {
let file_path_mapping = FilePathMapping::empty();
Expand All @@ -87,7 +87,7 @@ impl JsonEmitter {
fallback_bundle,
pretty,
json_rendered,
terminal_width,
diagnostic_width,
macro_backtrace,
)
}
Expand All @@ -100,7 +100,7 @@ impl JsonEmitter {
fallback_bundle: Lrc<FluentBundle>,
pretty: bool,
json_rendered: HumanReadableErrorType,
terminal_width: Option<usize>,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
) -> JsonEmitter {
JsonEmitter {
Expand All @@ -112,7 +112,7 @@ impl JsonEmitter {
pretty,
ui_testing: false,
json_rendered,
terminal_width,
diagnostic_width,
macro_backtrace,
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ impl Diagnostic {
je.fluent_bundle.clone(),
je.fallback_bundle.clone(),
false,
je.terminal_width,
je.diagnostic_width,
je.macro_backtrace,
)
.ui_testing(je.ui_testing)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,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);
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ pub enum PrintRequest {
NativeStaticLibs,
StackProtectorStrategies,
LinkArgs,
SplitDebuginfo,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -784,6 +785,7 @@ impl Default for Options {
borrowck_mode: BorrowckMode::Migrate,
cg: Default::default(),
error_format: ErrorOutputType::default(),
diagnostic_width: None,
externs: Externs(BTreeMap::new()),
extern_dep_specs: ExternDepSpecs(BTreeMap::new()),
crate_name: None,
Expand Down Expand Up @@ -1478,6 +1480,12 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
never = never colorize output",
"auto|always|never",
),
opt::opt_s(
"",
"diagnostic-width",
"Inform rustc of the width of the terminal so that errors can be truncated",
"WIDTH",
),
opt::multi_s(
"",
"remap-path-prefix",
Expand Down Expand Up @@ -1830,6 +1838,7 @@ fn collect_print_requests(
}
}
"link-args" => PrintRequest::LinkArgs,
"split-debuginfo" => PrintRequest::SplitDebuginfo,
req => early_error(error_format, &format!("unknown print request `{req}`")),
}));

Expand Down Expand Up @@ -2323,6 +2332,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {

let error_format = parse_error_format(matches, color, json_rendered);

let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_else(|_| {
early_error(error_format, "`--diagnostic-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));
Expand Down Expand Up @@ -2599,6 +2612,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
borrowck_mode,
cg,
error_format,
diagnostic_width,
externs,
unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()),
extern_dep_specs,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ top_level_options!(

test: bool [TRACKED],
error_format: ErrorOutputType [UNTRACKED],
diagnostic_width: Option<usize> [UNTRACKED],

/// If `Some`, enable incremental compilation, using the given
/// directory to store intermediate results.
Expand Down Expand Up @@ -1475,7 +1476,7 @@ options! {
"show extended diagnostic help (default: no)"),
temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
"the directory the intermediate files are written to"),
terminal_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
diagnostic_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
"set the current terminal width"),
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
// alongside query results and changes to translation options can affect diagnostics - so
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ fn default_emitter(
fallback_bundle,
short,
sopts.debugging_opts.teach,
sopts.debugging_opts.terminal_width,
sopts.diagnostic_width,
macro_backtrace,
),
Some(dst) => EmitterWriter::new(
Expand All @@ -1132,7 +1132,7 @@ fn default_emitter(
fallback_bundle,
pretty,
json_rendered,
sopts.debugging_opts.terminal_width,
sopts.diagnostic_width,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing),
Expand All @@ -1146,7 +1146,7 @@ fn default_emitter(
fallback_bundle,
pretty,
json_rendered,
sopts.debugging_opts.terminal_width,
sopts.diagnostic_width,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing),
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ crate struct Options {
crate proc_macro_crate: bool,
/// How to format errors and warnings.
crate error_format: ErrorOutputType,
/// Width of terminal to truncate errors appropriately.
crate diagnostic_width: Option<usize>,
/// Library search paths to hand to the compiler.
crate libs: Vec<SearchPath>,
/// Library search paths strings to hand to the compiler.
Expand Down Expand Up @@ -324,11 +326,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 diagnostic_width = matches.opt_get("diagnostic-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, diagnostic_width, &debugging_opts);

// check for deprecated options
check_deprecated_options(matches, &diag);
Expand Down Expand Up @@ -675,6 +678,7 @@ impl Options {
input,
proc_macro_crate,
error_format,
diagnostic_width,
libs,
lib_strs,
externs,
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl<'tcx> DocContext<'tcx> {
crate fn new_handler(
error_format: ErrorOutputType,
source_map: Option<Lrc<source_map::SourceMap>>,
diagnostic_width: Option<usize>,
debugging_opts: &DebuggingOptions,
) -> rustc_errors::Handler {
let fallback_bundle =
Expand All @@ -158,7 +159,7 @@ crate fn new_handler(
fallback_bundle,
short,
debugging_opts.teach,
debugging_opts.terminal_width,
diagnostic_width,
false,
)
.ui_testing(debugging_opts.ui_testing),
Expand All @@ -176,7 +177,7 @@ crate fn new_handler(
fallback_bundle,
pretty,
json_rendered,
debugging_opts.terminal_width,
diagnostic_width,
false,
)
.ui_testing(debugging_opts.ui_testing),
Expand All @@ -197,6 +198,7 @@ crate fn create_config(
crate_name,
proc_macro_crate,
error_format,
diagnostic_width,
libs,
externs,
mut cfgs,
Expand Down Expand Up @@ -253,6 +255,7 @@ crate fn create_config(
actually_rustdoc: true,
debugging_opts,
error_format,
diagnostic_width,
edition,
describe_lints,
crate_name,
Expand Down
15 changes: 14 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ fn opts() -> Vec<RustcOptGroup> {
"human|json|short",
)
}),
unstable("diagnostic-width", |o| {
o.optopt(
"",
"diagnostic-width",
"Provide width of the terminal for truncated error messages",
"WIDTH",
)
}),
stable("json", |o| {
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
}),
Expand Down Expand Up @@ -739,7 +747,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.diagnostic_width,
&options.debugging_opts,
);

match (options.should_test, options.markdown_input()) {
(true, true) => return wrap_return(&diag, markdown::test(options)),
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-ui/terminal-width.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// compile-flags: -Zunstable-options --diagnostic-width=10
#![deny(rustdoc::bare_urls)]

/// This is a long line that contains a http://link.com
pub struct Foo; //~^ ERROR
15 changes: 15 additions & 0 deletions src/test/rustdoc-ui/terminal-width.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: this URL is not a hyperlink
--> $DIR/diagnostic-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/diagnostic-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

Loading