Skip to content

Commit 0b439b1

Browse files
committed
Auto merge of rust-lang#107989 - matthiaskrgr:rollup-jklrd5g, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#107340 (rustdoc: merge doctest tooltip with notable traits tooltip) - rust-lang#107838 (Introduce `-Zterminal-urls` to use OSC8 for error codes) - rust-lang#107922 (Print disk usage in PGO CI script) - rust-lang#107931 (Intern span when length is MAX_LEN with parent.) - rust-lang#107935 (rustc_ast: Merge impls and reorder methods for attributes and meta items) - rust-lang#107986 (layout: deal with placeholders, ICE on bound types) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2d91939 + 8701e80 commit 0b439b1

File tree

33 files changed

+630
-568
lines changed

33 files changed

+630
-568
lines changed

compiler/rustc_ast/src/attr/mod.rs

+311-315
Large diffs are not rendered by default.

compiler/rustc_driver_impl/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
2323
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
2424
use rustc_data_structures::sync::SeqCst;
2525
use rustc_errors::registry::{InvalidErrorCode, Registry};
26-
use rustc_errors::{ErrorGuaranteed, PResult};
26+
use rustc_errors::{ErrorGuaranteed, PResult, TerminalUrl};
2727
use rustc_feature::find_gated_cfg;
2828
use rustc_hir::def_id::LOCAL_CRATE;
2929
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
@@ -1191,6 +1191,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
11911191
None,
11921192
false,
11931193
false,
1194+
TerminalUrl::No,
11941195
));
11951196
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
11961197

compiler/rustc_errors/src/emitter.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::translation::{to_fluent_args, Translate};
1818
use crate::{
1919
diagnostic::DiagnosticLocation, CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage,
2020
FluentBundle, Handler, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic,
21-
SubstitutionHighlight, SuggestionStyle,
21+
SubstitutionHighlight, SuggestionStyle, TerminalUrl,
2222
};
2323
use rustc_lint_defs::pluralize;
2424

@@ -66,6 +66,7 @@ impl HumanReadableErrorType {
6666
diagnostic_width: Option<usize>,
6767
macro_backtrace: bool,
6868
track_diagnostics: bool,
69+
terminal_url: TerminalUrl,
6970
) -> EmitterWriter {
7071
let (short, color_config) = self.unzip();
7172
let color = color_config.suggests_using_colors();
@@ -80,6 +81,7 @@ impl HumanReadableErrorType {
8081
diagnostic_width,
8182
macro_backtrace,
8283
track_diagnostics,
84+
terminal_url,
8385
)
8486
}
8587
}
@@ -652,6 +654,7 @@ pub struct EmitterWriter {
652654

653655
macro_backtrace: bool,
654656
track_diagnostics: bool,
657+
terminal_url: TerminalUrl,
655658
}
656659

657660
#[derive(Debug)]
@@ -672,6 +675,7 @@ impl EmitterWriter {
672675
diagnostic_width: Option<usize>,
673676
macro_backtrace: bool,
674677
track_diagnostics: bool,
678+
terminal_url: TerminalUrl,
675679
) -> EmitterWriter {
676680
let dst = Destination::from_stderr(color_config);
677681
EmitterWriter {
@@ -685,6 +689,7 @@ impl EmitterWriter {
685689
diagnostic_width,
686690
macro_backtrace,
687691
track_diagnostics,
692+
terminal_url,
688693
}
689694
}
690695

@@ -699,6 +704,7 @@ impl EmitterWriter {
699704
diagnostic_width: Option<usize>,
700705
macro_backtrace: bool,
701706
track_diagnostics: bool,
707+
terminal_url: TerminalUrl,
702708
) -> EmitterWriter {
703709
EmitterWriter {
704710
dst: Raw(dst, colored),
@@ -711,6 +717,7 @@ impl EmitterWriter {
711717
diagnostic_width,
712718
macro_backtrace,
713719
track_diagnostics,
720+
terminal_url,
714721
}
715722
}
716723

@@ -1378,7 +1385,13 @@ impl EmitterWriter {
13781385
// only render error codes, not lint codes
13791386
if let Some(DiagnosticId::Error(ref code)) = *code {
13801387
buffer.append(0, "[", Style::Level(*level));
1381-
buffer.append(0, code, Style::Level(*level));
1388+
let code = if let TerminalUrl::Yes = self.terminal_url {
1389+
let path = "https://doc.rust-lang.org/error_codes";
1390+
format!("\x1b]8;;{path}/{code}.html\x07{code}\x1b]8;;\x07")
1391+
} else {
1392+
code.clone()
1393+
};
1394+
buffer.append(0, &code, Style::Level(*level));
13821395
buffer.append(0, "]", Style::Level(*level));
13831396
label_width += 2 + code.len();
13841397
}

compiler/rustc_errors/src/json.rs

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::translation::{to_fluent_args, Translate};
1717
use crate::DiagnosticId;
1818
use crate::{
1919
CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, SubDiagnostic,
20+
TerminalUrl,
2021
};
2122
use rustc_lint_defs::Applicability;
2223

@@ -47,6 +48,7 @@ pub struct JsonEmitter {
4748
diagnostic_width: Option<usize>,
4849
macro_backtrace: bool,
4950
track_diagnostics: bool,
51+
terminal_url: TerminalUrl,
5052
}
5153

5254
impl JsonEmitter {
@@ -60,6 +62,7 @@ impl JsonEmitter {
6062
diagnostic_width: Option<usize>,
6163
macro_backtrace: bool,
6264
track_diagnostics: bool,
65+
terminal_url: TerminalUrl,
6366
) -> JsonEmitter {
6467
JsonEmitter {
6568
dst: Box::new(io::BufWriter::new(io::stderr())),
@@ -73,6 +76,7 @@ impl JsonEmitter {
7376
diagnostic_width,
7477
macro_backtrace,
7578
track_diagnostics,
79+
terminal_url,
7680
}
7781
}
7882

@@ -84,6 +88,7 @@ impl JsonEmitter {
8488
diagnostic_width: Option<usize>,
8589
macro_backtrace: bool,
8690
track_diagnostics: bool,
91+
terminal_url: TerminalUrl,
8792
) -> JsonEmitter {
8893
let file_path_mapping = FilePathMapping::empty();
8994
JsonEmitter::stderr(
@@ -96,6 +101,7 @@ impl JsonEmitter {
96101
diagnostic_width,
97102
macro_backtrace,
98103
track_diagnostics,
104+
terminal_url,
99105
)
100106
}
101107

@@ -110,6 +116,7 @@ impl JsonEmitter {
110116
diagnostic_width: Option<usize>,
111117
macro_backtrace: bool,
112118
track_diagnostics: bool,
119+
terminal_url: TerminalUrl,
113120
) -> JsonEmitter {
114121
JsonEmitter {
115122
dst,
@@ -123,6 +130,7 @@ impl JsonEmitter {
123130
diagnostic_width,
124131
macro_backtrace,
125132
track_diagnostics,
133+
terminal_url,
126134
}
127135
}
128136

@@ -360,6 +368,7 @@ impl Diagnostic {
360368
je.diagnostic_width,
361369
je.macro_backtrace,
362370
je.track_diagnostics,
371+
je.terminal_url,
363372
)
364373
.ui_testing(je.ui_testing)
365374
.emit_diagnostic(diag);

compiler/rustc_errors/src/json/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::json::JsonEmitter;
44
use rustc_span::source_map::{FilePathMapping, SourceMap};
55

66
use crate::emitter::{ColorConfig, HumanReadableErrorType};
7-
use crate::Handler;
7+
use crate::{Handler, TerminalUrl};
88
use rustc_span::{BytePos, Span};
99

1010
use std::str;
@@ -60,6 +60,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
6060
None,
6161
false,
6262
false,
63+
TerminalUrl::No,
6364
);
6465

6566
let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1));

compiler/rustc_errors/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ impl Handler {
573573
None,
574574
flags.macro_backtrace,
575575
flags.track_diagnostics,
576+
TerminalUrl::No,
576577
));
577578
Self::with_emitter_and_flags(emitter, flags)
578579
}
@@ -1838,6 +1839,13 @@ pub fn add_elided_lifetime_in_path_suggestion(
18381839
);
18391840
}
18401841

1842+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
1843+
pub enum TerminalUrl {
1844+
No,
1845+
Yes,
1846+
Auto,
1847+
}
1848+
18411849
/// Useful type to use with `Result<>` indicate that an error has already
18421850
/// been reported to the user, so no need to continue checking.
18431851
#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq, PartialOrd, Ord)]

compiler/rustc_expand/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{BytePos, Span};
88

99
use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::emitter::EmitterWriter;
11-
use rustc_errors::{Handler, MultiSpan, PResult};
11+
use rustc_errors::{Handler, MultiSpan, PResult, TerminalUrl};
1212

1313
use std::io;
1414
use std::io::prelude::*;
@@ -152,6 +152,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
152152
None,
153153
false,
154154
false,
155+
TerminalUrl::No,
155156
);
156157
let handler = Handler::with_emitter(true, None, Box::new(emitter));
157158
#[allow(rustc::untranslatable_diagnostic)]

compiler/rustc_session/src/options.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::early_error;
44
use crate::lint;
55
use crate::search_paths::SearchPath;
66
use crate::utils::NativeLib;
7-
use rustc_errors::LanguageIdentifier;
7+
use rustc_errors::{LanguageIdentifier, TerminalUrl};
88
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, SanitizerSet};
99
use rustc_target::spec::{
1010
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
@@ -402,6 +402,8 @@ mod desc {
402402
pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
403403
pub const parse_tls_model: &str = "one of supported TLS models (`rustc --print tls-models`)";
404404
pub const parse_target_feature: &str = parse_string;
405+
pub const parse_terminal_url: &str =
406+
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto`";
405407
pub const parse_wasi_exec_model: &str = "either `command` or `reactor`";
406408
pub const parse_split_debuginfo: &str =
407409
"one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
@@ -1044,6 +1046,16 @@ mod parse {
10441046
true
10451047
}
10461048

1049+
pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool {
1050+
*slot = match v {
1051+
Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes,
1052+
Some("off" | "no" | "n") => TerminalUrl::No,
1053+
Some("auto") => TerminalUrl::Auto,
1054+
_ => return false,
1055+
};
1056+
true
1057+
}
1058+
10471059
pub(crate) fn parse_symbol_mangling_version(
10481060
slot: &mut Option<SymbolManglingVersion>,
10491061
v: Option<&str>,
@@ -1675,6 +1687,8 @@ options! {
16751687
"show extended diagnostic help (default: no)"),
16761688
temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
16771689
"the directory the intermediate files are written to"),
1690+
terminal_urls: TerminalUrl = (TerminalUrl::No, parse_terminal_url, [UNTRACKED],
1691+
"use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output"),
16781692
#[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
16791693
thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
16801694
"enable ThinLTO when possible"),

compiler/rustc_session/src/session.rs

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_errors::registry::Registry;
2424
use rustc_errors::{
2525
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
2626
ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan, Noted,
27+
TerminalUrl,
2728
};
2829
use rustc_macros::HashStable_Generic;
2930
pub use rustc_span::def_id::StableCrateId;
@@ -1273,6 +1274,19 @@ fn default_emitter(
12731274
) -> Box<dyn Emitter + sync::Send> {
12741275
let macro_backtrace = sopts.unstable_opts.macro_backtrace;
12751276
let track_diagnostics = sopts.unstable_opts.track_diagnostics;
1277+
let terminal_url = match sopts.unstable_opts.terminal_urls {
1278+
TerminalUrl::Auto => {
1279+
match (std::env::var("COLORTERM").as_deref(), std::env::var("TERM").as_deref()) {
1280+
(Ok("truecolor"), Ok("xterm-256color"))
1281+
if sopts.unstable_features.is_nightly_build() =>
1282+
{
1283+
TerminalUrl::Yes
1284+
}
1285+
_ => TerminalUrl::No,
1286+
}
1287+
}
1288+
t => t,
1289+
};
12761290
match sopts.error_format {
12771291
config::ErrorOutputType::HumanReadable(kind) => {
12781292
let (short, color_config) = kind.unzip();
@@ -1297,6 +1311,7 @@ fn default_emitter(
12971311
sopts.diagnostic_width,
12981312
macro_backtrace,
12991313
track_diagnostics,
1314+
terminal_url,
13001315
);
13011316
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
13021317
}
@@ -1312,6 +1327,7 @@ fn default_emitter(
13121327
sopts.diagnostic_width,
13131328
macro_backtrace,
13141329
track_diagnostics,
1330+
terminal_url,
13151331
)
13161332
.ui_testing(sopts.unstable_opts.ui_testing),
13171333
),
@@ -1628,6 +1644,7 @@ fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler
16281644
None,
16291645
false,
16301646
false,
1647+
TerminalUrl::No,
16311648
))
16321649
}
16331650
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
@@ -1638,6 +1655,7 @@ fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler
16381655
None,
16391656
false,
16401657
false,
1658+
TerminalUrl::No,
16411659
)),
16421660
};
16431661
rustc_errors::Handler::with_emitter(true, None, emitter)

compiler/rustc_span/src/span_encoding.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,16 @@ impl Span {
110110
// Inline format with parent.
111111
let len_or_tag = len_or_tag | PARENT_MASK;
112112
let parent2 = parent.local_def_index.as_u32();
113-
if ctxt2 == SyntaxContext::root().as_u32() && parent2 <= MAX_CTXT {
113+
if ctxt2 == SyntaxContext::root().as_u32()
114+
&& parent2 <= MAX_CTXT
115+
&& len_or_tag < LEN_TAG
116+
{
117+
debug_assert_ne!(len_or_tag, LEN_TAG);
114118
return Span { base_or_index: base, len_or_tag, ctxt_or_tag: parent2 as u16 };
115119
}
116120
} else {
117121
// Inline format with ctxt.
122+
debug_assert_ne!(len_or_tag, LEN_TAG);
118123
return Span {
119124
base_or_index: base,
120125
len_or_tag: len as u16,

compiler/rustc_ty_utils/src/layout.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,11 @@ fn layout_of_uncached<'tcx>(
470470
return Err(LayoutError::Unknown(ty));
471471
}
472472

473-
ty::Placeholder(..)
474-
| ty::GeneratorWitness(..)
475-
| ty::GeneratorWitnessMIR(..)
476-
| ty::Infer(_) => {
473+
ty::Bound(..) | ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) | ty::Infer(_) => {
477474
bug!("Layout::compute: unexpected type `{}`", ty)
478475
}
479476

480-
ty::Bound(..) | ty::Param(_) | ty::Error(_) => {
477+
ty::Placeholder(..) | ty::Param(_) | ty::Error(_) => {
481478
return Err(LayoutError::Unknown(ty));
482479
}
483480
})

0 commit comments

Comments
 (0)