Skip to content

Commit 8401645

Browse files
committed
Auto merge of #122241 - matthiaskrgr:rollup-r8q87ok, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - #121358 (Reduce alignment of TypeId to u64 alignment) - #121813 (Misc improvements to non local defs lint implementation) - #122160 (Eagerly translate `HelpUseLatestEdition` in parser diagnostics) - #122178 (ci: add a runner for vanilla LLVM 18) - #122187 (Move metadata header and version checks together) - #122209 (fix incorrect path resolution in tidy) - #122215 (Some tweaks to the parallel query cycle handler) - #122223 (Fix typo in `VisitorResult`) - #122224 (Add missing regression tests) - #122232 (library/core: fix a comment, and a cfg(miri) warning) - #122233 (miri: do not apply aliasing restrictions to Box with custom allocator) - #122237 (Remove `Ord` from `ClosureKind`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b054da8 + 7193ce0 commit 8401645

File tree

44 files changed

+697
-171
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

+697
-171
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/src/interpret/validity.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_middle::mir::interpret::{
1717
ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance,
1818
ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*,
1919
};
20-
use rustc_middle::ty;
2120
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
21+
use rustc_middle::ty::{self, Ty};
2222
use rustc_span::symbol::{sym, Symbol};
2323
use rustc_target::abi::{
2424
Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
@@ -783,7 +783,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
783783
}
784784

785785
#[inline]
786-
fn visit_box(&mut self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
786+
fn visit_box(
787+
&mut self,
788+
_box_ty: Ty<'tcx>,
789+
op: &OpTy<'tcx, M::Provenance>,
790+
) -> InterpResult<'tcx> {
787791
self.check_safe_pointer(op, PointerKind::Box)?;
788792
Ok(())
789793
}

compiler/rustc_const_eval/src/interpret/visitor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use rustc_index::IndexVec;
55
use rustc_middle::mir::interpret::InterpResult;
6-
use rustc_middle::ty;
6+
use rustc_middle::ty::{self, Ty};
77
use rustc_target::abi::FieldIdx;
88
use rustc_target::abi::{FieldsShape, VariantIdx, Variants};
99

@@ -47,10 +47,10 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
4747
Ok(())
4848
}
4949
/// Visits the given value as the pointer of a `Box`. There is nothing to recurse into.
50-
/// The type of `v` will be a raw pointer, but this is a field of `Box<T>` and the
51-
/// pointee type is the actual `T`.
50+
/// The type of `v` will be a raw pointer to `T`, but this is a field of `Box<T>` and the
51+
/// pointee type is the actual `T`. `box_ty` provides the full type of the `Box` itself.
5252
#[inline(always)]
53-
fn visit_box(&mut self, _v: &Self::V) -> InterpResult<'tcx> {
53+
fn visit_box(&mut self, _box_ty: Ty<'tcx>, _v: &Self::V) -> InterpResult<'tcx> {
5454
Ok(())
5555
}
5656

@@ -144,7 +144,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
144144
assert_eq!(nonnull_ptr.layout().fields.count(), 1);
145145
let raw_ptr = self.ecx().project_field(&nonnull_ptr, 0)?; // the actual raw ptr
146146
// ... whose only field finally is a raw ptr we can dereference.
147-
self.visit_box(&raw_ptr)?;
147+
self.visit_box(ty, &raw_ptr)?;
148148

149149
// The second `Box` field is the allocator, which we recursively check for validity
150150
// like in regular structs.

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_hir_analysis/src/check/intrinsic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ pub fn check_intrinsic_type(
657657
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
658658
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
659659

660+
sym::retag_box_to_raw => {
661+
(2, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_mut_ptr(tcx, param(0)))
662+
}
663+
660664
other => {
661665
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
662666
return;

compiler/rustc_hir_typeck/src/closure.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_target::spec::abi::Abi;
1919
use rustc_trait_selection::traits;
2020
use rustc_trait_selection::traits::error_reporting::ArgKind;
2121
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
22-
use std::cmp;
22+
use rustc_type_ir::ClosureKind;
2323
use std::iter;
2424
use std::ops::ControlFlow;
2525

@@ -437,10 +437,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
437437
};
438438

439439
if let Some(found_kind) = found_kind {
440-
expected_kind = Some(
441-
expected_kind
442-
.map_or_else(|| found_kind, |current| cmp::min(current, found_kind)),
443-
);
440+
// always use the closure kind that is more permissive.
441+
match (expected_kind, found_kind) {
442+
(None, _) => expected_kind = Some(found_kind),
443+
(Some(ClosureKind::FnMut), ClosureKind::Fn) => {
444+
expected_kind = Some(ClosureKind::Fn)
445+
}
446+
(Some(ClosureKind::FnOnce), ClosureKind::Fn | ClosureKind::FnMut) => {
447+
expected_kind = Some(found_kind)
448+
}
449+
_ => {}
450+
}
444451
}
445452
}
446453
}

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/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
}

0 commit comments

Comments
 (0)