Skip to content

Commit 79a1e77

Browse files
committed
Auto merge of #152035 - Zalathar:rollup-Ur7QmrJ, r=Zalathar
Rollup of 7 pull requests Successful merges: - #152008 (`rust-analyzer` subtree update) - #151109 (fN::BITS constants for feature float_bits_const) - #151976 (Rename `collect_active_jobs` to several distinct names) - #151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`) - #151919 (fix: Make `--color always` always print color with `--explain`) - #152017 (Remove `with_no_trimmed_paths` use in query macro) - #152028 (Convert to inline diagnostics in `rustc_driver_impl`)
2 parents 46c86ae + b0552e6 commit 79a1e77

234 files changed

Lines changed: 7696 additions & 2224 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3789,7 +3789,6 @@ dependencies = [
37893789
"rustc_errors",
37903790
"rustc_expand",
37913791
"rustc_feature",
3792-
"rustc_fluent_macro",
37933792
"rustc_hir_analysis",
37943793
"rustc_hir_pretty",
37953794
"rustc_hir_typeck",

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
2121
rustc_errors = { path = "../rustc_errors" }
2222
rustc_expand = { path = "../rustc_expand" }
2323
rustc_feature = { path = "../rustc_feature" }
24-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
2524
rustc_hir_analysis = { path = "../rustc_hir_analysis" }
2625
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
2726
rustc_hir_typeck = { path = "../rustc_hir_typeck" }

compiler/rustc_driver_impl/messages.ftl

Lines changed: 0 additions & 29 deletions
This file was deleted.

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,12 @@ use crate::session_diagnostics::{
108108
RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead, UnstableFeatureUsage,
109109
};
110110

111-
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
112-
113111
pub fn default_translator() -> Translator {
114112
Translator::with_fallback_bundle(DEFAULT_LOCALE_RESOURCES.to_vec(), false)
115113
}
116114

117115
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
118116
// tidy-alphabetical-start
119-
crate::DEFAULT_LOCALE_RESOURCE,
120117
rustc_ast_lowering::DEFAULT_LOCALE_RESOURCE,
121118
rustc_ast_passes::DEFAULT_LOCALE_RESOURCE,
122119
rustc_attr_parsing::DEFAULT_LOCALE_RESOURCE,
@@ -491,10 +488,18 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
491488
}
492489
text.push('\n');
493490
}
491+
492+
// If output is a terminal, use a pager to display the content.
494493
if io::stdout().is_terminal() {
495494
show_md_content_with_pager(&text, color);
496495
} else {
497-
safe_print!("{text}");
496+
// Otherwise, if the user has requested colored output
497+
// print the content in color, else print the md content.
498+
if color == ColorConfig::Always {
499+
show_colored_md_content(&text);
500+
} else {
501+
safe_print!("{text}");
502+
}
498503
}
499504
} else {
500505
early_dcx.early_fatal(format!("{code} is not a valid error code"));
@@ -564,6 +569,33 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
564569
safe_print!("{content}");
565570
}
566571

572+
/// Prints the markdown content with colored output.
573+
///
574+
/// This function is used when the output is not a terminal,
575+
/// but the user has requested colored output with `--color=always`.
576+
fn show_colored_md_content(content: &str) {
577+
// Try to prettify the raw markdown text.
578+
let mut pretty_data = {
579+
let mdstream = markdown::MdStream::parse_str(content);
580+
let bufwtr = markdown::create_stdout_bufwtr();
581+
let mut mdbuf = Vec::new();
582+
if mdstream.write_anstream_buf(&mut mdbuf, Some(&highlighter::highlight)).is_ok() {
583+
Some((bufwtr, mdbuf))
584+
} else {
585+
None
586+
}
587+
};
588+
589+
if let Some((bufwtr, mdbuf)) = &mut pretty_data
590+
&& bufwtr.write_all(&mdbuf).is_ok()
591+
{
592+
return;
593+
}
594+
595+
// Everything failed. Print the raw markdown text.
596+
safe_print!("{content}");
597+
}
598+
567599
fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
568600
assert!(sess.opts.unstable_opts.link_only);
569601
let dcx = sess.dcx();

compiler/rustc_driver_impl/src/session_diagnostics.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,88 @@ use std::error::Error;
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44

55
#[derive(Diagnostic)]
6-
#[diag(driver_impl_cant_emit_mir)]
6+
#[diag("could not emit MIR: {$error}")]
77
pub struct CantEmitMIR {
88
pub error: std::io::Error,
99
}
1010

1111
#[derive(Diagnostic)]
12-
#[diag(driver_impl_rlink_unable_to_read)]
12+
#[diag("failed to read rlink file: `{$err}`")]
1313
pub(crate) struct RlinkUnableToRead {
1414
pub err: std::io::Error,
1515
}
1616

1717
#[derive(Diagnostic)]
18-
#[diag(driver_impl_rlink_wrong_file_type)]
18+
#[diag("the input does not look like a .rlink file")]
1919
pub(crate) struct RLinkWrongFileType;
2020

2121
#[derive(Diagnostic)]
22-
#[diag(driver_impl_rlink_empty_version_number)]
22+
#[diag("the input does not contain version number")]
2323
pub(crate) struct RLinkEmptyVersionNumber;
2424

2525
#[derive(Diagnostic)]
26-
#[diag(driver_impl_rlink_encoding_version_mismatch)]
26+
#[diag(
27+
".rlink file was produced with encoding version `{$version_array}`, but the current version is `{$rlink_version}`"
28+
)]
2729
pub(crate) struct RLinkEncodingVersionMismatch {
2830
pub version_array: String,
2931
pub rlink_version: u32,
3032
}
3133

3234
#[derive(Diagnostic)]
33-
#[diag(driver_impl_rlink_rustc_version_mismatch)]
35+
#[diag(
36+
".rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`"
37+
)]
3438
pub(crate) struct RLinkRustcVersionMismatch<'a> {
3539
pub rustc_version: String,
3640
pub current_version: &'a str,
3741
}
3842

3943
#[derive(Diagnostic)]
40-
#[diag(driver_impl_rlink_no_a_file)]
44+
#[diag("rlink must be a file")]
4145
pub(crate) struct RlinkNotAFile;
4246

4347
#[derive(Diagnostic)]
44-
#[diag(driver_impl_rlink_corrupt_file)]
48+
#[diag("corrupt metadata encountered in `{$file}`")]
4549
pub(crate) struct RlinkCorruptFile<'a> {
4650
pub file: &'a std::path::Path,
4751
}
4852

4953
#[derive(Diagnostic)]
50-
#[diag(driver_impl_ice)]
54+
#[diag("the compiler unexpectedly panicked. this is a bug.")]
5155
pub(crate) struct Ice;
5256

5357
#[derive(Diagnostic)]
54-
#[diag(driver_impl_ice_bug_report)]
58+
#[diag("we would appreciate a bug report: {$bug_report_url}")]
5559
pub(crate) struct IceBugReport<'a> {
5660
pub bug_report_url: &'a str,
5761
}
5862

5963
#[derive(Diagnostic)]
60-
#[diag(driver_impl_ice_bug_report_update_note)]
64+
#[diag("please make sure that you have updated to the latest nightly")]
6165
pub(crate) struct UpdateNightlyNote;
6266

6367
#[derive(Diagnostic)]
64-
#[diag(driver_impl_ice_bug_report_internal_feature)]
68+
#[diag(
69+
"using internal features is not supported and expected to cause internal compiler errors when used incorrectly"
70+
)]
6571
pub(crate) struct IceBugReportInternalFeature;
6672

6773
#[derive(Diagnostic)]
68-
#[diag(driver_impl_ice_version)]
74+
#[diag("rustc {$version} running on {$triple}")]
6975
pub(crate) struct IceVersion<'a> {
7076
pub version: &'a str,
7177
pub triple: &'a str,
7278
}
7379

7480
#[derive(Diagnostic)]
75-
#[diag(driver_impl_ice_path)]
81+
#[diag("please attach the file at `{$path}` to your bug report")]
7682
pub(crate) struct IcePath {
7783
pub path: std::path::PathBuf,
7884
}
7985

8086
#[derive(Diagnostic)]
81-
#[diag(driver_impl_ice_path_error)]
87+
#[diag("the ICE couldn't be written to `{$path}`: {$error}")]
8288
pub(crate) struct IcePathError {
8389
pub path: std::path::PathBuf,
8490
pub error: String,
@@ -87,23 +93,23 @@ pub(crate) struct IcePathError {
8793
}
8894

8995
#[derive(Subdiagnostic)]
90-
#[note(driver_impl_ice_path_error_env)]
96+
#[note("the environment variable `RUSTC_ICE` is set to `{$env_var}`")]
9197
pub(crate) struct IcePathErrorEnv {
9298
pub env_var: std::path::PathBuf,
9399
}
94100

95101
#[derive(Diagnostic)]
96-
#[diag(driver_impl_ice_flags)]
102+
#[diag("compiler flags: {$flags}")]
97103
pub(crate) struct IceFlags {
98104
pub flags: String,
99105
}
100106

101107
#[derive(Diagnostic)]
102-
#[diag(driver_impl_ice_exclude_cargo_defaults)]
108+
#[diag("some of the compiler flags provided by cargo are hidden")]
103109
pub(crate) struct IceExcludeCargoDefaults;
104110

105111
#[derive(Diagnostic)]
106-
#[diag(driver_impl_unstable_feature_usage)]
112+
#[diag("cannot dump feature usage metrics: {$error}")]
107113
pub(crate) struct UnstableFeatureUsage {
108114
pub error: Box<dyn Error>,
109115
}

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ internal compiler error: query cycle handler thread panicked, aborting process";
254254
|| {
255255
// Ensure there were no errors collecting all active jobs.
256256
// We need the complete map to ensure we find a cycle to break.
257-
QueryCtxt::new(tcx).collect_active_jobs(false).expect(
257+
QueryCtxt::new(tcx).collect_active_jobs_from_all_queries(false).expect(
258258
"failed to collect active queries in deadlock handler",
259259
)
260260
},

compiler/rustc_macros/src/query.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ fn add_query_desc_cached_impl(
303303
#[allow(unused_variables)]
304304
pub fn #name<'tcx>(tcx: TyCtxt<'tcx>, key: crate::query::queries::#name::Key<'tcx>) -> String {
305305
let (#tcx, #key) = (tcx, key);
306-
::rustc_middle::ty::print::with_no_trimmed_paths!(
307-
format!(#desc)
308-
)
306+
format!(#desc)
309307
}
310308
};
311309

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ impl<'tcx> QueryCtxt<'tcx> {
5050
}
5151

5252
fn depth_limit_error(self, job: QueryJobId) {
53-
let query_map = self.collect_active_jobs(true).expect("failed to collect active queries");
53+
let query_map = self
54+
.collect_active_jobs_from_all_queries(true)
55+
.expect("failed to collect active queries");
5456
let (info, depth) = job.find_dep_kind_root(query_map);
5557

5658
let suggested_limit = match self.tcx.recursion_limit() {
@@ -98,7 +100,7 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
98100
tls::with_related_context(self.tcx, |icx| icx.query)
99101
}
100102

101-
/// Returns a map of currently active query jobs.
103+
/// Returns a map of currently active query jobs, collected from all queries.
102104
///
103105
/// If `require_complete` is `true`, this function locks all shards of the
104106
/// query results to produce a complete map, which always returns `Ok`.
@@ -108,12 +110,15 @@ impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
108110
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
109111
/// especially when called from within a deadlock handler, unless a
110112
/// complete map is needed and no deadlock is possible at this call site.
111-
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap<'tcx>, QueryMap<'tcx>> {
113+
fn collect_active_jobs_from_all_queries(
114+
self,
115+
require_complete: bool,
116+
) -> Result<QueryMap<'tcx>, QueryMap<'tcx>> {
112117
let mut jobs = QueryMap::default();
113118
let mut complete = true;
114119

115-
for collect in super::COLLECT_ACTIVE_JOBS.iter() {
116-
if collect(self.tcx, &mut jobs, require_complete).is_none() {
120+
for gather_fn in crate::PER_QUERY_GATHER_ACTIVE_JOBS_FNS.iter() {
121+
if gather_fn(self.tcx, &mut jobs, require_complete).is_none() {
117122
complete = false;
118123
}
119124
}
@@ -731,7 +736,10 @@ macro_rules! define_queries {
731736
}
732737
}
733738

734-
pub(crate) fn collect_active_jobs<'tcx>(
739+
/// Internal per-query plumbing for collecting the set of active jobs for this query.
740+
///
741+
/// Should only be called through `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`.
742+
pub(crate) fn gather_active_jobs<'tcx>(
735743
tcx: TyCtxt<'tcx>,
736744
qmap: &mut QueryMap<'tcx>,
737745
require_complete: bool,
@@ -741,12 +749,15 @@ macro_rules! define_queries {
741749
let name = stringify!($name);
742750
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name)
743751
};
744-
let res = tcx.query_system.states.$name.collect_active_jobs(
752+
753+
// Call `gather_active_jobs_inner` to do the actual work.
754+
let res = tcx.query_system.states.$name.gather_active_jobs_inner(
745755
tcx,
746756
make_frame,
747757
qmap,
748758
require_complete,
749759
);
760+
750761
// this can be called during unwinding, and the function has a `try_`-prefix, so
751762
// don't `unwrap()` here, just manually check for `None` and do best-effort error
752763
// reporting.
@@ -816,10 +827,17 @@ macro_rules! define_queries {
816827

817828
// These arrays are used for iteration and can't be indexed by `DepKind`.
818829

819-
const COLLECT_ACTIVE_JOBS: &[
820-
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<'tcx>, bool) -> Option<()>
821-
] =
822-
&[$(query_impl::$name::collect_active_jobs),*];
830+
/// Used by `collect_active_jobs_from_all_queries` to iterate over all
831+
/// queries, and gather the active jobs for each query.
832+
///
833+
/// (We arbitrarily use the word "gather" when collecting the jobs for
834+
/// each individual query, so that we have distinct function names to
835+
/// grep for.)
836+
const PER_QUERY_GATHER_ACTIVE_JOBS_FNS: &[
837+
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<'tcx>, require_complete: bool) -> Option<()>
838+
] = &[
839+
$(query_impl::$name::gather_active_jobs),*
840+
];
823841

824842
const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[
825843
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache)

compiler/rustc_query_system/src/query/job.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ impl<'tcx> QueryInfo<QueryStackDeferred<'tcx>> {
3232
}
3333
}
3434

35+
/// Map from query job IDs to job information collected by
36+
/// [`QueryContext::collect_active_jobs_from_all_queries`].
3537
pub type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<'tcx>>;
3638

3739
/// A value uniquely identifying an active query job.
@@ -613,7 +615,7 @@ pub fn print_query_stack<'tcx, Qcx: QueryContext<'tcx>>(
613615
let mut count_total = 0;
614616

615617
// Make use of a partial query map if we fail to take locks collecting active queries.
616-
let query_map = match qcx.collect_active_jobs(false) {
618+
let query_map = match qcx.collect_active_jobs_from_all_queries(false) {
617619
Ok(query_map) => query_map,
618620
Err(query_map) => query_map,
619621
};

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ pub trait QueryContext<'tcx>: HasDepContext {
166166
/// Get the query information from the TLS context.
167167
fn current_query_job(self) -> Option<QueryJobId>;
168168

169-
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap<'tcx>, QueryMap<'tcx>>;
169+
fn collect_active_jobs_from_all_queries(
170+
self,
171+
require_complete: bool,
172+
) -> Result<QueryMap<'tcx>, QueryMap<'tcx>>;
170173

171174
/// Load a side effect associated to the node in the previous session.
172175
fn load_side_effect(

0 commit comments

Comments
 (0)