Skip to content

Commit cfc2310

Browse files
committed
Auto merge of #122236 - matthiaskrgr:rollup-cg2zzhq, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #121567 (Avoid some interning in bootstrap) - #121813 (Misc improvements to non local defs lint implementation) - #121860 (Add a tidy check that checks whether the fluent slugs only appear once) - #121907 (skip sanity check for non-host targets in `check` builds) - #122160 (Eagerly translate `HelpUseLatestEdition` in parser diagnostics) - #122178 (ci: add a runner for vanilla LLVM 18) - #122186 (Remove a workaround for a bug) - #122187 (Move metadata header and version checks together) - #122215 (Some tweaks to the parallel query cycle handler) - #122223 (Fix typo in `VisitorResult`) - #122232 (library/core: fix a comment, and a cfg(miri) warning) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b054da8 + 28fca59 commit cfc2310

File tree

44 files changed

+513
-308
lines changed

Some content is hidden

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

44 files changed

+513
-308
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ jobs:
315315
- name: x86_64-gnu-distcheck
316316
os: ubuntu-20.04-8core-32gb
317317
env: {}
318+
- name: x86_64-gnu-llvm-18
319+
env:
320+
RUST_BACKTRACE: 1
321+
os: ubuntu-20.04-8core-32gb
318322
- name: x86_64-gnu-llvm-17
319323
env:
320324
RUST_BACKTRACE: 1

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4133,7 +4133,6 @@ dependencies = [
41334133
"rustc_target",
41344134
"rustc_trait_selection",
41354135
"rustc_type_ir",
4136-
"smallvec",
41374136
"tracing",
41384137
"unicode-security",
41394138
]

compiler/rustc_ast_ir/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl VisitorResult for () {
1414
type Residual = !;
1515

1616
#[cfg(not(feature = "nightly"))]
17-
type Residual = core::ops::Infallible;
17+
type Residual = core::convert::Infallible;
1818

1919
fn output() -> Self {}
2020
fn from_residual(_: Self::Residual) -> Self {}

compiler/rustc_const_eval/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ const_eval_intern_kind = {$kind ->
146146
*[other] {""}
147147
}
148148
149-
const_eval_invalid_align =
150-
align has to be a power of 2
151-
152149
const_eval_invalid_align_details =
153150
invalid align passed to `{$name}`: {$align} is {$err_kind ->
154151
[not_power_of_two] not a power of 2

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ fn list_metadata(early_dcx: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dy
676676
metadata_loader,
677677
&mut v,
678678
&sess.opts.unstable_opts.ls,
679+
sess.cfg_version,
679680
)
680681
.unwrap();
681682
safe_println!("{}", String::from_utf8(v).unwrap());

compiler/rustc_infer/messages.ftl

-8
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,6 @@ infer_more_targeted = {$has_param_name ->
181181
182182
infer_msl_introduces_static = introduces a `'static` lifetime requirement
183183
infer_msl_unmet_req = because this has an unmet lifetime requirement
184-
infer_need_type_info_in_coroutine =
185-
type inside {$coroutine_kind ->
186-
[async_block] `async` block
187-
[async_closure] `async` closure
188-
[async_fn] `async fn` body
189-
*[coroutine] coroutine
190-
} must be known in this context
191-
192184
193185
infer_nothing = {""}
194186

compiler/rustc_interface/src/util.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
101101
threads: usize,
102102
f: F,
103103
) -> R {
104-
use rustc_data_structures::{jobserver, sync::FromDyn};
104+
use rustc_data_structures::{defer, jobserver, sync::FromDyn};
105105
use rustc_middle::ty::tls;
106106
use rustc_query_impl::QueryCtxt;
107-
use rustc_query_system::query::{deadlock, QueryContext};
107+
use rustc_query_system::query::{break_query_cycles, QueryContext};
108+
use std::process;
108109

109110
let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());
110111

@@ -128,7 +129,19 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
128129
let query_map =
129130
FromDyn::from(tls::with(|tcx| QueryCtxt::new(tcx).collect_active_jobs()));
130131
let registry = rayon_core::Registry::current();
131-
thread::spawn(move || deadlock(query_map.into_inner(), &registry));
132+
thread::Builder::new()
133+
.name("rustc query cycle handler".to_string())
134+
.spawn(move || {
135+
let on_panic = defer(|| {
136+
eprintln!("query cycle handler thread panicked, aborting process");
137+
// We need to abort here as we failed to resolve the deadlock,
138+
// otherwise the compiler could just hang,
139+
process::abort();
140+
});
141+
break_query_cycles(query_map.into_inner(), &registry);
142+
on_panic.disable();
143+
})
144+
.unwrap();
132145
});
133146
if let Some(size) = get_stack_size() {
134147
builder = builder.stack_size(size);

compiler/rustc_lint/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ rustc_span = { path = "../rustc_span" }
2323
rustc_target = { path = "../rustc_target" }
2424
rustc_trait_selection = { path = "../rustc_trait_selection" }
2525
rustc_type_ir = { path = "../rustc_type_ir" }
26-
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2726
tracing = "0.1"
2827
unicode-security = "0.1.0"
2928
# tidy-alphabetical-end

compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ lint_suspicious_double_ref_clone =
562562
lint_suspicious_double_ref_deref =
563563
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
564564
565-
lint_trivial_untranslatable_diag = diagnostic with static strings only
566-
567565
lint_ty_qualified = usage of qualified `ty::{$ty}`
568566
.suggestion = try importing it and using it unqualified
569567

compiler/rustc_lint/src/non_local_def.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, Path, QPath, TyKind};
22
use rustc_span::def_id::{DefId, LOCAL_CRATE};
33
use rustc_span::{sym, symbol::kw, ExpnKind, MacroKind};
44

5-
use smallvec::{smallvec, SmallVec};
6-
75
use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag};
86
use crate::{LateContext, LateLintPass, LintContext};
97

@@ -85,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
8583
if let Some(def_id) = oexpn.macro_def_id
8684
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
8785
&& def_id.krate != LOCAL_CRATE
88-
&& std::env::var_os("CARGO").is_some()
86+
&& rustc_session::utils::was_invoked_from_cargo()
8987
{
9088
Some(NonLocalDefinitionsCargoUpdateNote {
9189
macro_kind: macro_kind.descr(),
@@ -114,25 +112,25 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
114112
// is using local items and so we don't lint on it.
115113

116114
// We also ignore anon-const in item by including the anon-const
117-
// parent as well; and since it's quite uncommon, we use smallvec
118-
// to avoid unnecessary heap allocations.
119-
let local_parents: SmallVec<[DefId; 1]> = if parent_def_kind == DefKind::Const
115+
// parent as well.
116+
let parent_parent = if parent_def_kind == DefKind::Const
120117
&& parent_opt_item_name == Some(kw::Underscore)
121118
{
122-
smallvec![parent, cx.tcx.parent(parent)]
119+
Some(cx.tcx.parent(parent))
123120
} else {
124-
smallvec![parent]
121+
None
125122
};
126123

127124
let self_ty_has_local_parent = match impl_.self_ty.kind {
128125
TyKind::Path(QPath::Resolved(_, ty_path)) => {
129-
path_has_local_parent(ty_path, cx, &*local_parents)
126+
path_has_local_parent(ty_path, cx, parent, parent_parent)
130127
}
131128
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
132129
path_has_local_parent(
133130
principle_poly_trait_ref.trait_ref.path,
134131
cx,
135-
&*local_parents,
132+
parent,
133+
parent_parent,
136134
)
137135
}
138136
TyKind::TraitObject([], _, _)
@@ -154,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
154152

155153
let of_trait_has_local_parent = impl_
156154
.of_trait
157-
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
155+
.map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent))
158156
.unwrap_or(false);
159157

160158
// If none of them have a local parent (LOGICAL NOR) this means that
@@ -218,6 +216,16 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
218216
/// std::convert::PartialEq<Foo<Bar>>
219217
/// ^^^^^^^^^^^^^^^^^^^^^^^
220218
/// ```
221-
fn path_has_local_parent(path: &Path<'_>, cx: &LateContext<'_>, local_parents: &[DefId]) -> bool {
222-
path.res.opt_def_id().is_some_and(|did| local_parents.contains(&cx.tcx.parent(did)))
219+
fn path_has_local_parent(
220+
path: &Path<'_>,
221+
cx: &LateContext<'_>,
222+
impl_parent: DefId,
223+
impl_parent_parent: Option<DefId>,
224+
) -> bool {
225+
path.res.opt_def_id().is_some_and(|did| {
226+
did.is_local() && {
227+
let res_parent = cx.tcx.parent(did);
228+
res_parent == impl_parent || Some(res_parent) == impl_parent_parent
229+
}
230+
})
223231
}

compiler/rustc_metadata/src/locator.rs

+60-67
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ use std::{cmp, fmt};
243243
pub(crate) struct CrateLocator<'a> {
244244
// Immutable per-session configuration.
245245
only_needs_metadata: bool,
246-
sysroot: &'a Path,
247246
metadata_loader: &'a dyn MetadataLoader,
248247
cfg_version: &'static str,
249248

@@ -319,7 +318,6 @@ impl<'a> CrateLocator<'a> {
319318

320319
CrateLocator {
321320
only_needs_metadata,
322-
sysroot: &sess.sysroot,
323321
metadata_loader,
324322
cfg_version: sess.cfg_version,
325323
crate_name,
@@ -569,31 +567,47 @@ impl<'a> CrateLocator<'a> {
569567
debug!("skipping empty file");
570568
continue;
571569
}
572-
let (hash, metadata) =
573-
match get_metadata_section(self.target, flavor, &lib, self.metadata_loader) {
574-
Ok(blob) => {
575-
if let Some(h) = self.crate_matches(&blob, &lib) {
576-
(h, blob)
577-
} else {
578-
info!("metadata mismatch");
579-
continue;
580-
}
581-
}
582-
Err(MetadataError::LoadFailure(err)) => {
583-
info!("no metadata found: {}", err);
584-
// The file was present and created by the same compiler version, but we
585-
// couldn't load it for some reason. Give a hard error instead of silently
586-
// ignoring it, but only if we would have given an error anyway.
587-
self.crate_rejections
588-
.via_invalid
589-
.push(CrateMismatch { path: lib, got: err });
590-
continue;
591-
}
592-
Err(err @ MetadataError::NotPresent(_)) => {
593-
info!("no metadata found: {}", err);
570+
let (hash, metadata) = match get_metadata_section(
571+
self.target,
572+
flavor,
573+
&lib,
574+
self.metadata_loader,
575+
self.cfg_version,
576+
) {
577+
Ok(blob) => {
578+
if let Some(h) = self.crate_matches(&blob, &lib) {
579+
(h, blob)
580+
} else {
581+
info!("metadata mismatch");
594582
continue;
595583
}
596-
};
584+
}
585+
Err(MetadataError::VersionMismatch { expected_version, found_version }) => {
586+
// The file was present and created by the same compiler version, but we
587+
// couldn't load it for some reason. Give a hard error instead of silently
588+
// ignoring it, but only if we would have given an error anyway.
589+
info!(
590+
"Rejecting via version: expected {} got {}",
591+
expected_version, found_version
592+
);
593+
self.crate_rejections
594+
.via_version
595+
.push(CrateMismatch { path: lib, got: found_version });
596+
continue;
597+
}
598+
Err(MetadataError::LoadFailure(err)) => {
599+
info!("no metadata found: {}", err);
600+
// The file was present and created by the same compiler version, but we
601+
// couldn't load it for some reason. Give a hard error instead of silently
602+
// ignoring it, but only if we would have given an error anyway.
603+
self.crate_rejections.via_invalid.push(CrateMismatch { path: lib, got: err });
604+
continue;
605+
}
606+
Err(err @ MetadataError::NotPresent(_)) => {
607+
info!("no metadata found: {}", err);
608+
continue;
609+
}
610+
};
597611
// If we see multiple hashes, emit an error about duplicate candidates.
598612
if slot.as_ref().is_some_and(|s| s.0 != hash) {
599613
if let Some(candidates) = err_data {
@@ -610,32 +624,6 @@ impl<'a> CrateLocator<'a> {
610624
continue;
611625
}
612626

613-
// Ok so at this point we've determined that `(lib, kind)` above is
614-
// a candidate crate to load, and that `slot` is either none (this
615-
// is the first crate of its kind) or if some the previous path has
616-
// the exact same hash (e.g., it's the exact same crate).
617-
//
618-
// In principle these two candidate crates are exactly the same so
619-
// we can choose either of them to link. As a stupidly gross hack,
620-
// however, we favor crate in the sysroot.
621-
//
622-
// You can find more info in rust-lang/rust#39518 and various linked
623-
// issues, but the general gist is that during testing libstd the
624-
// compilers has two candidates to choose from: one in the sysroot
625-
// and one in the deps folder. These two crates are the exact same
626-
// crate but if the compiler chooses the one in the deps folder
627-
// it'll cause spurious errors on Windows.
628-
//
629-
// As a result, we favor the sysroot crate here. Note that the
630-
// candidates are all canonicalized, so we canonicalize the sysroot
631-
// as well.
632-
if let Some((prev, _)) = &ret {
633-
let sysroot = self.sysroot;
634-
let sysroot = try_canonicalize(sysroot).unwrap_or_else(|_| sysroot.to_path_buf());
635-
if prev.starts_with(&sysroot) {
636-
continue;
637-
}
638-
}
639627
*slot = Some((hash, metadata, lib.clone()));
640628
ret = Some((lib, kind));
641629
}
@@ -648,16 +636,6 @@ impl<'a> CrateLocator<'a> {
648636
}
649637

650638
fn crate_matches(&mut self, metadata: &MetadataBlob, libpath: &Path) -> Option<Svh> {
651-
let rustc_version = rustc_version(self.cfg_version);
652-
let found_version = metadata.get_rustc_version();
653-
if found_version != rustc_version {
654-
info!("Rejecting via version: expected {} got {}", rustc_version, found_version);
655-
self.crate_rejections
656-
.via_version
657-
.push(CrateMismatch { path: libpath.to_path_buf(), got: found_version });
658-
return None;
659-
}
660-
661639
let header = metadata.get_header();
662640
if header.is_proc_macro_crate != self.is_proc_macro {
663641
info!(
@@ -770,6 +748,7 @@ fn get_metadata_section<'p>(
770748
flavor: CrateFlavor,
771749
filename: &'p Path,
772750
loader: &dyn MetadataLoader,
751+
cfg_version: &'static str,
773752
) -> Result<MetadataBlob, MetadataError<'p>> {
774753
if !filename.exists() {
775754
return Err(MetadataError::NotPresent(filename));
@@ -847,13 +826,18 @@ fn get_metadata_section<'p>(
847826
}
848827
};
849828
let blob = MetadataBlob(raw_bytes);
850-
if blob.is_compatible() {
851-
Ok(blob)
852-
} else {
853-
Err(MetadataError::LoadFailure(format!(
829+
match blob.check_compatibility(cfg_version) {
830+
Ok(()) => Ok(blob),
831+
Err(None) => Err(MetadataError::LoadFailure(format!(
854832
"invalid metadata version found: {}",
855833
filename.display()
856-
)))
834+
))),
835+
Err(Some(found_version)) => {
836+
return Err(MetadataError::VersionMismatch {
837+
expected_version: rustc_version(cfg_version),
838+
found_version,
839+
});
840+
}
857841
}
858842
}
859843

@@ -864,9 +848,10 @@ pub fn list_file_metadata(
864848
metadata_loader: &dyn MetadataLoader,
865849
out: &mut dyn Write,
866850
ls_kinds: &[String],
851+
cfg_version: &'static str,
867852
) -> IoResult<()> {
868853
let flavor = get_flavor_from_path(path);
869-
match get_metadata_section(target, flavor, path, metadata_loader) {
854+
match get_metadata_section(target, flavor, path, metadata_loader, cfg_version) {
870855
Ok(metadata) => metadata.list_crate_metadata(out, ls_kinds),
871856
Err(msg) => write!(out, "{msg}\n"),
872857
}
@@ -932,6 +917,8 @@ enum MetadataError<'a> {
932917
NotPresent(&'a Path),
933918
/// The file was present and invalid.
934919
LoadFailure(String),
920+
/// The file was present, but compiled with a different rustc version.
921+
VersionMismatch { expected_version: String, found_version: String },
935922
}
936923

937924
impl fmt::Display for MetadataError<'_> {
@@ -941,6 +928,12 @@ impl fmt::Display for MetadataError<'_> {
941928
f.write_str(&format!("no such file: '{}'", filename.display()))
942929
}
943930
MetadataError::LoadFailure(msg) => f.write_str(msg),
931+
MetadataError::VersionMismatch { expected_version, found_version } => {
932+
f.write_str(&format!(
933+
"rustc version mismatch. expected {}, found {}",
934+
expected_version, found_version,
935+
))
936+
}
944937
}
945938
}
946939
}

0 commit comments

Comments
 (0)