Skip to content

Commit ed172db

Browse files
committed
Auto merge of rust-lang#125448 - matthiaskrgr:rollup-vn6nleh, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#124297 (Allow coercing functions whose signature differs in opaque types in their defining scope into a shared function pointer type) - rust-lang#124516 (Allow monomorphization time const eval failures if the cause is a type layout issue) - rust-lang#124976 (rustc: Use `tcx.used_crates(())` more) - rust-lang#125210 (Cleanup: Fix up some diagnostics) - rust-lang#125409 (Rename `FrameworkOnlyWindows` to `RawDylibOnlyWindows`) - rust-lang#125416 (Use correct param-env in `MissingCopyImplementations`) - rust-lang#125421 (Rewrite `core-no-oom-handling`, `issue-24445` and `issue-38237` `run-make` tests to new `rmake.rs` format) - rust-lang#125438 (Remove unneeded string conversion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 39d2f2a + cf92f4c commit ed172db

File tree

70 files changed

+404
-155
lines changed

Some content is hidden

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

70 files changed

+404
-155
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,12 @@ fn link_natively(
786786
if matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))
787787
&& unknown_arg_regex.is_match(&out)
788788
&& out.contains("-no-pie")
789-
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-no-pie")
789+
&& cmd.get_args().iter().any(|e| e == "-no-pie")
790790
{
791791
info!("linker output: {:?}", out);
792792
warn!("Linker does not support -no-pie command line option. Retrying without.");
793793
for arg in cmd.take_args() {
794-
if arg.to_string_lossy() != "-no-pie" {
794+
if arg != "-no-pie" {
795795
cmd.arg(arg);
796796
}
797797
}
@@ -825,7 +825,7 @@ fn link_natively(
825825
if matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))
826826
&& unknown_arg_regex.is_match(&out)
827827
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
828-
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
828+
&& cmd.get_args().iter().any(|e| e == "-static-pie")
829829
{
830830
info!("linker output: {:?}", out);
831831
warn!(
@@ -864,7 +864,7 @@ fn link_natively(
864864
assert!(pre_objects_static.is_empty() || !pre_objects_static_pie.is_empty());
865865
assert!(post_objects_static.is_empty() || !post_objects_static_pie.is_empty());
866866
for arg in cmd.take_args() {
867-
if arg.to_string_lossy() == "-static-pie" {
867+
if arg == "-static-pie" {
868868
// Replace the output kind.
869869
cmd.arg("-static");
870870
} else if pre_objects_static_pie.contains(&arg) {

Diff for: compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ fn upstream_monomorphizations_provider(
399399
tcx: TyCtxt<'_>,
400400
(): (),
401401
) -> DefIdMap<UnordMap<GenericArgsRef<'_>, CrateNum>> {
402-
let cnums = tcx.crates(());
402+
let cnums = tcx.used_crates(());
403403

404404
let mut instances: DefIdMap<UnordMap<_, _>> = Default::default();
405405

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub fn collect_debugger_visualizers_transitive(
539539
tcx.debugger_visualizers(LOCAL_CRATE)
540540
.iter()
541541
.chain(
542-
tcx.crates(())
542+
tcx.used_crates(())
543543
.iter()
544544
.filter(|&cnum| {
545545
let used_crate_source = tcx.used_crate_source(*cnum);
@@ -849,7 +849,7 @@ impl CrateInfo {
849849
// `compiler_builtins` are always placed last to ensure that they're linked correctly.
850850
used_crates.extend(compiler_builtins);
851851

852-
let crates = tcx.crates(());
852+
let crates = tcx.used_crates(());
853853
let n_crates = crates.len();
854854
let mut info = CrateInfo {
855855
target_cpu,

Diff for: compiler/rustc_const_eval/src/const_eval/error.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::mem;
22

33
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg};
44
use rustc_hir::CRATE_HIR_ID;
5-
use rustc_middle::mir::interpret::Provenance;
5+
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo};
66
use rustc_middle::mir::AssertKind;
77
use rustc_middle::query::TyCtxtAt;
88
use rustc_middle::ty::TyCtxt;
@@ -139,9 +139,10 @@ where
139139
ErrorHandled::TooGeneric(span)
140140
}
141141
err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar, span),
142-
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {
143-
ErrorHandled::Reported(guar.into(), span)
144-
}
142+
err_inval!(Layout(LayoutError::ReferencesError(guar))) => ErrorHandled::Reported(
143+
ReportedErrorInfo::tainted_by_errors(guar),
144+
span,
145+
),
145146
// Report remaining errors.
146147
_ => {
147148
let (our_span, frames) = get_span_and_frames();

Diff for: compiler/rustc_const_eval/src/interpret/eval_context.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11811181
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
11821182
M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
11831183
let const_val = val.eval(*ecx.tcx, ecx.param_env, span).map_err(|err| {
1184-
if M::ALL_CONSTS_ARE_PRECHECKED && !matches!(err, ErrorHandled::TooGeneric(..)) {
1185-
// Looks like the const is not captued by `required_consts`, that's bad.
1186-
bug!("interpret const eval failure of {val:?} which is not in required_consts");
1184+
if M::ALL_CONSTS_ARE_PRECHECKED {
1185+
match err {
1186+
ErrorHandled::TooGeneric(..) => {},
1187+
ErrorHandled::Reported(reported, span) => {
1188+
if reported.is_tainted_by_errors() {
1189+
// const-eval will return "tainted" errors if e.g. the layout cannot
1190+
// be computed as the type references non-existing names.
1191+
// See <https://github.com/rust-lang/rust/issues/124348>.
1192+
} else {
1193+
// Looks like the const is not captued by `required_consts`, that's bad.
1194+
span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");
1195+
}
1196+
}
1197+
}
11871198
}
11881199
err.emit_note(*ecx.tcx);
11891200
err

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11591159
let sig = self
11601160
.at(cause, self.param_env)
11611161
.trace(prev_ty, new_ty)
1162-
.lub(DefineOpaqueTypes::No, a_sig, b_sig)
1162+
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
11631163
.map(|ok| self.register_infer_ok_obligations(ok))?;
11641164

11651165
// Reify both sides and return the reified fn pointer type.

Diff for: compiler/rustc_infer/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ infer_compare_impl_item_obligation = ...so that the definition in impl matches t
104104
infer_consider_specifying_length = consider specifying the actual array length
105105
infer_data_flows = ...but data{$label_var1_exists ->
106106
[true] {" "}from `{$label_var1}`
107-
*[false] -> {""}
107+
*[false] {""}
108108
} flows{$label_var2_exists ->
109109
[true] {" "}into `{$label_var2}`
110-
*[false] -> {""}
110+
*[false] {""}
111111
} here
112112
113113
infer_data_lifetime_flow = ...but data with one lifetime flows into the other here

Diff for: compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
458458
}
459459
}
460460

461-
for &cnum in tcx.crates(()) {
461+
for &cnum in tcx.crates_including_speculative(()) {
462462
let source = tcx.used_crate_source(cnum);
463463
if let Some((path, _)) = &source.dylib {
464464
files.push(escape_dep_filename(&path.display().to_string()));

Diff for: compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
627627
.label = pattern not allowed in foreign function
628628
629629
lint_private_extern_crate_reexport =
630-
extern crate `{$ident}` is private, and cannot be re-exported (error E0365), consider declaring with `pub`
630+
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`
631631
632632
lint_proc_macro_back_compat = using an old version of `{$crate_name}`
633633
.note = older versions of the `{$crate_name}` crate will stop compiling in future versions of Rust; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives

Diff for: compiler/rustc_lint/src/builtin.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
674674
return;
675675
}
676676
}
677-
let param_env = ty::ParamEnv::empty();
678-
if ty.is_copy_modulo_regions(cx.tcx, param_env) {
677+
if ty.is_copy_modulo_regions(cx.tcx, cx.param_env) {
679678
return;
680679
}
681-
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) {
680+
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, cx.param_env) {
682681
return;
683682
}
684683
if def.is_variant_list_non_exhaustive()
@@ -694,7 +693,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
694693
.tcx
695694
.infer_ctxt()
696695
.build()
697-
.type_implements_trait(iter_trait, [ty], param_env)
696+
.type_implements_trait(iter_trait, [ty], cx.param_env)
698697
.must_apply_modulo_regions()
699698
{
700699
return;
@@ -711,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
711710

712711
if type_allowed_to_implement_copy(
713712
cx.tcx,
714-
param_env,
713+
cx.param_env,
715714
ty,
716715
traits::ObligationCause::misc(item.span, item.owner_id.def_id),
717716
)

Diff for: compiler/rustc_lint/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ pub struct MacroUseDeprecated;
22282228
pub struct UnusedMacroUse;
22292229

22302230
#[derive(LintDiagnostic)]
2231-
#[diag(lint_private_extern_crate_reexport)]
2231+
#[diag(lint_private_extern_crate_reexport, code = E0365)]
22322232
pub struct PrivateExternCrateReexport {
22332233
pub ident: Ident,
22342234
}

Diff for: compiler/rustc_metadata/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ metadata_found_staticlib =
9191
found staticlib `{$crate_name}` instead of rlib or dylib{$add_info}
9292
.help = please recompile that crate using --crate-type lib
9393
94-
metadata_framework_only_windows =
95-
link kind `raw-dylib` is only supported on Windows targets
96-
9794
metadata_global_alloc_required =
9895
no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
9996
@@ -233,6 +230,9 @@ metadata_profiler_builtins_needs_core =
233230
metadata_raw_dylib_no_nul =
234231
link name must not contain NUL characters if link kind is `raw-dylib`
235232
233+
metadata_raw_dylib_only_windows =
234+
link kind `raw-dylib` is only supported on Windows targets
235+
236236
metadata_renaming_no_link =
237237
renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
238238

Diff for: compiler/rustc_metadata/src/dependency_format.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
143143
&& sess.crt_static(Some(ty))
144144
&& !sess.target.crt_static_allows_dylibs)
145145
{
146-
for &cnum in tcx.crates(()).iter() {
146+
for &cnum in tcx.used_crates(()).iter() {
147147
if tcx.dep_kind(cnum).macros_only() {
148148
continue;
149149
}
@@ -164,7 +164,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
164164
// Sweep all crates for found dylibs. Add all dylibs, as well as their
165165
// dependencies, ensuring there are no conflicts. The only valid case for a
166166
// dependency to be relied upon twice is for both cases to rely on a dylib.
167-
for &cnum in tcx.crates(()).iter() {
167+
for &cnum in tcx.used_crates(()).iter() {
168168
if tcx.dep_kind(cnum).macros_only() {
169169
continue;
170170
}
@@ -182,7 +182,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
182182
}
183183

184184
// Collect what we've got so far in the return vector.
185-
let last_crate = tcx.crates(()).len();
185+
let last_crate = tcx.used_crates(()).len();
186186
let mut ret = (1..last_crate + 1)
187187
.map(|cnum| match formats.get(&CrateNum::new(cnum)) {
188188
Some(&RequireDynamic) => Linkage::Dynamic,
@@ -196,7 +196,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
196196
//
197197
// If the crate hasn't been included yet and it's not actually required
198198
// (e.g., it's an allocator) then we skip it here as well.
199-
for &cnum in tcx.crates(()).iter() {
199+
for &cnum in tcx.used_crates(()).iter() {
200200
let src = tcx.used_crate_source(cnum);
201201
if src.dylib.is_none()
202202
&& !formats.contains_key(&cnum)
@@ -284,7 +284,7 @@ fn add_library(
284284

285285
fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<DependencyList> {
286286
let all_crates_available_as_rlib = tcx
287-
.crates(())
287+
.used_crates(())
288288
.iter()
289289
.copied()
290290
.filter_map(|cnum| {
@@ -305,7 +305,7 @@ fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<De
305305
// All crates are available in an rlib format, so we're just going to link
306306
// everything in explicitly so long as it's actually required.
307307
let mut ret = tcx
308-
.crates(())
308+
.used_crates(())
309309
.iter()
310310
.map(|&cnum| match tcx.dep_kind(cnum) {
311311
CrateDepKind::Explicit => Linkage::Static,

Diff for: compiler/rustc_metadata/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ pub struct LinkFrameworkApple {
142142
}
143143

144144
#[derive(Diagnostic)]
145-
#[diag(metadata_framework_only_windows, code = E0455)]
146-
pub struct FrameworkOnlyWindows {
145+
#[diag(metadata_raw_dylib_only_windows, code = E0455)]
146+
pub struct RawDylibOnlyWindows {
147147
#[primary_span]
148148
pub span: Span,
149149
}

Diff for: compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'tcx> Collector<'tcx> {
151151
}
152152
"raw-dylib" => {
153153
if !sess.target.is_like_windows {
154-
sess.dcx().emit_err(errors::FrameworkOnlyWindows { span });
154+
sess.dcx().emit_err(errors::RawDylibOnlyWindows { span });
155155
}
156156
NativeLibKind::RawDylib
157157
}

Diff for: compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
435435
// traversal, but not globally minimal across all crates.
436436
let bfs_queue = &mut VecDeque::new();
437437

438-
for &cnum in tcx.crates(()) {
438+
for &cnum in tcx.crates_including_speculative(()) {
439439
// Ignore crates without a corresponding local `extern crate` item.
440440
if tcx.missing_extern_crate_item(cnum) {
441441
continue;
@@ -505,7 +505,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
505505
tcx.arena
506506
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
507507
},
508-
crates: |tcx, ()| {
508+
crates_including_speculative: |tcx, ()| {
509509
// The list of loaded crates is now frozen in query cache,
510510
// so make sure cstore is not mutably accessed from here on.
511511
tcx.untracked().cstore.freeze();

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18981898

18991899
let deps = self
19001900
.tcx
1901-
.crates(())
1901+
.crates_including_speculative(())
19021902
.iter()
19031903
.map(|&cnum| {
19041904
let dep = CrateDep {

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
10161016
let krate = tcx.hir_crate(());
10171017
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
10181018

1019-
let upstream_crates = upstream_crates(tcx);
1019+
let upstream_crates = upstream_crates_for_hashing(tcx);
10201020

10211021
let resolutions = tcx.resolutions(());
10221022

@@ -1085,9 +1085,9 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
10851085
Svh::new(crate_hash)
10861086
}
10871087

1088-
fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
1088+
fn upstream_crates_for_hashing(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
10891089
let mut upstream_crates: Vec<_> = tcx
1090-
.crates(())
1090+
.crates_including_speculative(())
10911091
.iter()
10921092
.map(|&cnum| {
10931093
let stable_crate_id = tcx.stable_crate_id(cnum);

Diff for: compiler/rustc_middle/src/mir/interpret/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ impl ReportedErrorInfo {
6666
pub fn tainted_by_errors(error: ErrorGuaranteed) -> ReportedErrorInfo {
6767
ReportedErrorInfo { is_tainted_by_errors: true, error }
6868
}
69+
pub fn is_tainted_by_errors(&self) -> bool {
70+
self.is_tainted_by_errors
71+
}
6972
}
7073

7174
impl From<ErrorGuaranteed> for ReportedErrorInfo {

Diff for: compiler/rustc_middle/src/query/mod.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1860,13 +1860,22 @@ rustc_queries! {
18601860
eval_always
18611861
desc { "calculating the stability index for the local crate" }
18621862
}
1863-
query crates(_: ()) -> &'tcx [CrateNum] {
1863+
/// All loaded crates, including those loaded purely for doc links or diagnostics.
1864+
/// (Diagnostics include lints, so speculatively loaded crates may occur in successful
1865+
/// compilation even without doc links.)
1866+
/// Should be used when encoding crate metadata (and therefore when generating crate hash,
1867+
/// depinfo and similar things), to avoid dangling crate references in other encoded data,
1868+
/// like source maps.
1869+
/// May also be used for diagnostics - if we are loading a crate anyway we can suggest some
1870+
/// items from it as well.
1871+
/// But otherwise, `used_crates` should generally be used.
1872+
query crates_including_speculative(_: ()) -> &'tcx [CrateNum] {
18641873
eval_always
18651874
desc { "fetching all foreign CrateNum instances" }
18661875
}
1867-
// Crates that are loaded non-speculatively (not for diagnostics or doc links).
1868-
// FIXME: This is currently only used for collecting lang items, but should be used instead of
1869-
// `crates` in most other cases too.
1876+
/// Crates that are loaded non-speculatively (not for diagnostics or doc links).
1877+
/// Should be used to maintain observable language behavior, for example when collecting lang
1878+
/// items or impls from all crates, or collecting libraries to link.
18701879
query used_crates(_: ()) -> &'tcx [CrateNum] {
18711880
eval_always
18721881
desc { "fetching `CrateNum`s for all crates loaded non-speculatively" }

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl<'tcx> TyCtxt<'tcx> {
16111611

16121612
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
16131613
iter::once(LOCAL_CRATE)
1614-
.chain(self.crates(()).iter().copied())
1614+
.chain(self.used_crates(()).iter().copied())
16151615
.flat_map(move |cnum| self.traits(cnum).iter().copied())
16161616
}
16171617

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3258,7 +3258,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
32583258
let queue = &mut Vec::new();
32593259
let mut seen_defs: DefIdSet = Default::default();
32603260

3261-
for &cnum in tcx.crates(()).iter() {
3261+
for &cnum in tcx.crates_including_speculative(()).iter() {
32623262
let def_id = cnum.as_def_id();
32633263

32643264
// Ignore crates that are not direct dependencies.

0 commit comments

Comments
 (0)