Skip to content

Commit 58dd450

Browse files
committed
Auto merge of #143322 - matthiaskrgr:rollup-h6xw7i5, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions) - #142138 (Add `Vec::into_chunks`) - #142321 (Expose elf abi on ppc64 targets) - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`) - #143194 (fix bitcast of single-element SIMD vectors) - #143231 (Suggest use another lifetime specifier instead of underscore lifetime) - #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest) - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition) - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic) - #143274 (ci: support optional jobs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b94bd12 + 87e28ff commit 58dd450

File tree

43 files changed

+317
-138
lines changed

Some content is hidden

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

43 files changed

+317
-138
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,18 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
219219

220220
// Mark allocator shim symbols as exported only if they were generated.
221221
if allocator_kind_for_codegen(tcx).is_some() {
222-
for symbol_name in ALLOCATOR_METHODS
222+
for (symbol_name, export_kind) in ALLOCATOR_METHODS
223223
.iter()
224-
.map(|method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
224+
.map(|method| {
225+
(
226+
mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()),
227+
SymbolExportKind::Text,
228+
)
229+
})
225230
.chain([
226-
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
227-
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
228-
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
231+
(mangle_internal_symbol(tcx, "__rust_alloc_error_handler"), SymbolExportKind::Text),
232+
(mangle_internal_symbol(tcx, OomStrategy::SYMBOL), SymbolExportKind::Data),
233+
(mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE), SymbolExportKind::Text),
229234
])
230235
{
231236
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
@@ -234,7 +239,7 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
234239
exported_symbol,
235240
SymbolExportInfo {
236241
level: SymbolExportLevel::Rust,
237-
kind: SymbolExportKind::Text,
242+
kind: export_kind,
238243
used: false,
239244
rustc_std_internal_symbol: true,
240245
},

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ pub(super) fn transmute_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
11171117
// While optimizations will remove no-op transmutes, they might still be
11181118
// there in debug or things that aren't no-op in MIR because they change
11191119
// the Rust type but not the underlying layout/niche.
1120-
if from_scalar == to_scalar {
1120+
if from_scalar == to_scalar && from_backend_ty == to_backend_ty {
11211121
return imm;
11221122
}
11231123

@@ -1136,13 +1136,7 @@ pub(super) fn transmute_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
11361136
assume_scalar_range(bx, imm, from_scalar, from_backend_ty);
11371137

11381138
imm = match (from_scalar.primitive(), to_scalar.primitive()) {
1139-
(Int(..) | Float(_), Int(..) | Float(_)) => {
1140-
if from_backend_ty == to_backend_ty {
1141-
imm
1142-
} else {
1143-
bx.bitcast(imm, to_backend_ty)
1144-
}
1145-
}
1139+
(Int(..) | Float(_), Int(..) | Float(_)) => bx.bitcast(imm, to_backend_ty),
11461140
(Pointer(..), Pointer(..)) => bx.pointercast(imm, to_backend_ty),
11471141
(Int(..), Pointer(..)) => bx.ptradd(bx.const_null(bx.type_ptr()), imm),
11481142
(Pointer(..), Int(..)) => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,13 +2459,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24592459
// type a projection.
24602460
let in_trait = match opaque_ty.origin {
24612461
hir::OpaqueTyOrigin::FnReturn {
2462+
parent,
24622463
in_trait_or_impl: Some(hir::RpitContext::Trait),
24632464
..
24642465
}
24652466
| hir::OpaqueTyOrigin::AsyncFn {
2467+
parent,
24662468
in_trait_or_impl: Some(hir::RpitContext::Trait),
24672469
..
2468-
} => true,
2470+
} => Some(parent),
24692471
hir::OpaqueTyOrigin::FnReturn {
24702472
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
24712473
..
@@ -2474,7 +2476,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24742476
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
24752477
..
24762478
}
2477-
| hir::OpaqueTyOrigin::TyAlias { .. } => false,
2479+
| hir::OpaqueTyOrigin::TyAlias { .. } => None,
24782480
};
24792481

24802482
self.lower_opaque_ty(opaque_ty.def_id, in_trait)
@@ -2594,17 +2596,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25942596

25952597
/// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
25962598
#[instrument(level = "debug", skip(self), ret)]
2597-
fn lower_opaque_ty(&self, def_id: LocalDefId, in_trait: bool) -> Ty<'tcx> {
2599+
fn lower_opaque_ty(&self, def_id: LocalDefId, in_trait: Option<LocalDefId>) -> Ty<'tcx> {
25982600
let tcx = self.tcx();
25992601

26002602
let lifetimes = tcx.opaque_captured_lifetimes(def_id);
26012603
debug!(?lifetimes);
26022604

2603-
// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
2604-
// generate the def_id of an associated type for the trait and return as
2605-
// type a projection.
2606-
let def_id = if in_trait {
2607-
tcx.associated_type_for_impl_trait_in_trait(def_id).to_def_id()
2605+
// If this is an RPITIT and we are using the new RPITIT lowering scheme,
2606+
// do a linear search to map this to the synthetic associated type that
2607+
// it will be lowered to.
2608+
let def_id = if let Some(parent_def_id) = in_trait {
2609+
*tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id)
2610+
.iter()
2611+
.find(|rpitit| match tcx.opt_rpitit_info(**rpitit) {
2612+
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
2613+
opaque_def_id.expect_local() == def_id
2614+
}
2615+
_ => unreachable!(),
2616+
})
2617+
.unwrap()
26082618
} else {
26092619
def_id.to_def_id()
26102620
};
@@ -2627,7 +2637,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26272637
});
26282638
debug!(?args);
26292639

2630-
if in_trait {
2640+
if in_trait.is_some() {
26312641
Ty::new_projection_from_args(tcx, def_id, args)
26322642
} else {
26332643
Ty::new_opaque(tcx, def_id, args)

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,13 +1093,6 @@ rustc_queries! {
10931093
separate_provide_extern
10941094
}
10951095

1096-
/// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
1097-
/// associated item.
1098-
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
1099-
desc { |tcx| "creating the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
1100-
cache_on_disk_if { true }
1101-
}
1102-
11031096
/// Given an `impl_id`, return the trait it implements along with some header information.
11041097
/// Return `None` if this is an inherent impl.
11051098
query impl_trait_header(impl_id: DefId) -> Option<ty::ImplTraitHeader<'tcx>> {

compiler/rustc_resolve/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ resolve_undeclared_label =
432432
433433
resolve_underscore_lifetime_is_reserved = `'_` cannot be used here
434434
.label = `'_` is a reserved lifetime name
435+
.help = use another lifetime specifier
435436
436437
resolve_unexpected_res_change_ty_to_const_param_sugg =
437438
you might have meant to write a const parameter here

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ pub(crate) struct ImplicitElidedLifetimeNotAllowedHere {
934934

935935
#[derive(Diagnostic)]
936936
#[diag(resolve_underscore_lifetime_is_reserved, code = E0637)]
937+
#[help]
937938
pub(crate) struct UnderscoreLifetimeIsReserved {
938939
#[primary_span]
939940
#[label]

compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.abi = "elfv2".into();
1314
base.llvm_abiname = "elfv2".into();
1415

1516
Target {

compiler/rustc_target/src/spec/targets/powerpc64_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.abi = "elfv1".into();
1314
base.llvm_abiname = "elfv1".into();
1415

1516
Target {

compiler/rustc_target/src/spec/targets/powerpc64_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) fn target() -> Target {
1212
base.stack_probes = StackProbeType::Inline;
1313
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
1414
base.crt_static_default = true;
15+
base.abi = "elfv2".into();
1516
base.llvm_abiname = "elfv2".into();
1617

1718
Target {

compiler/rustc_target/src/spec/targets/powerpc64_unknown_openbsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.abi = "elfv2".into();
1314
base.llvm_abiname = "elfv2".into();
1415

1516
Target {

compiler/rustc_target/src/spec/targets/powerpc64_wrs_vxworks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.abi = "elfv1".into();
1314
base.llvm_abiname = "elfv1".into();
1415

1516
Target {

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
99
base.max_atomic_width = Some(64);
1010
base.stack_probes = StackProbeType::Inline;
11+
base.abi = "elfv2".into();
1112
base.llvm_abiname = "elfv2".into();
1213

1314
Target {

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
99
base.max_atomic_width = Some(64);
1010
base.stack_probes = StackProbeType::Inline;
11+
base.abi = "elfv2".into();
1112
base.llvm_abiname = "elfv2".into();
1213

1314
Target {

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.stack_probes = StackProbeType::Inline;
1111
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
1212
base.crt_static_default = true;
13+
base.abi = "elfv2".into();
1314
base.llvm_abiname = "elfv2".into();
1415

1516
Target {

compiler/rustc_ty_utils/src/assoc.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use rustc_data_structures::fx::FxIndexSet;
1+
use rustc_hir as hir;
22
use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
44
use rustc_hir::definitions::{DefPathData, DisambiguatorState};
55
use rustc_hir::intravisit::{self, Visitor};
6-
use rustc_hir::{self as hir, AmbigArg};
76
use rustc_middle::query::Providers;
87
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt};
98
use rustc_middle::{bug, span_bug};
@@ -14,7 +13,6 @@ pub(crate) fn provide(providers: &mut Providers) {
1413
associated_item_def_ids,
1514
associated_items,
1615
associated_types_for_impl_traits_in_associated_fn,
17-
associated_type_for_impl_trait_in_trait,
1816
impl_item_implementor_ids,
1917
..*providers
2018
};
@@ -160,20 +158,22 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
160158
container: ty::AssocItemContainer::Impl,
161159
}
162160
}
163-
struct RPITVisitor {
164-
rpits: FxIndexSet<LocalDefId>,
161+
struct RPITVisitor<'tcx> {
162+
tcx: TyCtxt<'tcx>,
163+
synthetics: Vec<LocalDefId>,
164+
data: DefPathData,
165+
disambiguator: DisambiguatorState,
165166
}
166167

167-
impl<'tcx> Visitor<'tcx> for RPITVisitor {
168-
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
169-
if let hir::TyKind::OpaqueDef(opaq) = ty.kind
170-
&& self.rpits.insert(opaq.def_id)
171-
{
172-
for bound in opaq.bounds {
173-
intravisit::walk_param_bound(self, bound);
174-
}
175-
}
176-
intravisit::walk_ty(self, ty)
168+
impl<'tcx> Visitor<'tcx> for RPITVisitor<'tcx> {
169+
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) -> Self::Result {
170+
self.synthetics.push(associated_type_for_impl_trait_in_trait(
171+
self.tcx,
172+
opaque.def_id,
173+
self.data,
174+
&mut self.disambiguator,
175+
));
176+
intravisit::walk_opaque_ty(self, opaque)
177177
}
178178
}
179179

@@ -194,14 +194,18 @@ fn associated_types_for_impl_traits_in_associated_fn(
194194

195195
match tcx.def_kind(parent_def_id) {
196196
DefKind::Trait => {
197-
let mut visitor = RPITVisitor { rpits: FxIndexSet::default() };
198-
199197
if let Some(output) = tcx.hir_get_fn_output(fn_def_id) {
198+
let data = DefPathData::AnonAssocTy(tcx.item_name(fn_def_id.to_def_id()));
199+
let mut visitor = RPITVisitor {
200+
tcx,
201+
synthetics: vec![],
202+
data,
203+
disambiguator: DisambiguatorState::with(parent_def_id, data, 0),
204+
};
200205
visitor.visit_fn_ret_ty(output);
201-
202-
tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| {
203-
tcx.associated_type_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id()
204-
}))
206+
tcx.arena.alloc_from_iter(
207+
visitor.synthetics.into_iter().map(|def_id| def_id.to_def_id()),
208+
)
205209
} else {
206210
&[]
207211
}
@@ -211,7 +215,6 @@ fn associated_types_for_impl_traits_in_associated_fn(
211215
let Some(trait_fn_def_id) = tcx.associated_item(fn_def_id).trait_item_def_id else {
212216
return &[];
213217
};
214-
215218
tcx.arena.alloc_from_iter(
216219
tcx.associated_types_for_impl_traits_in_associated_fn(trait_fn_def_id).iter().map(
217220
move |&trait_assoc_def_id| {
@@ -236,6 +239,8 @@ fn associated_types_for_impl_traits_in_associated_fn(
236239
fn associated_type_for_impl_trait_in_trait(
237240
tcx: TyCtxt<'_>,
238241
opaque_ty_def_id: LocalDefId,
242+
data: DefPathData,
243+
disambiguator: &mut DisambiguatorState,
239244
) -> LocalDefId {
240245
let (hir::OpaqueTyOrigin::FnReturn { parent: fn_def_id, .. }
241246
| hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, .. }) =
@@ -246,22 +251,15 @@ fn associated_type_for_impl_trait_in_trait(
246251
let trait_def_id = tcx.local_parent(fn_def_id);
247252
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
248253

249-
// Collect all opaque types in return position for the method and use
250-
// the index as the disambiguator to make an unique def path.
251-
let mut visitor = RPITVisitor { rpits: FxIndexSet::default() };
252-
visitor.visit_fn_ret_ty(tcx.hir_get_fn_output(fn_def_id).unwrap());
253-
let disambiguator = visitor.rpits.get_index_of(&opaque_ty_def_id).unwrap().try_into().unwrap();
254-
255254
let span = tcx.def_span(opaque_ty_def_id);
256255
// Also use the method name to create an unique def path.
257-
let data = DefPathData::AnonAssocTy(tcx.item_name(fn_def_id.to_def_id()));
258256
let trait_assoc_ty = tcx.at(span).create_def(
259257
trait_def_id,
260258
// No name because this is an anonymous associated type.
261259
None,
262260
DefKind::AssocTy,
263261
Some(data),
264-
&mut DisambiguatorState::with(trait_def_id, data, disambiguator),
262+
disambiguator,
265263
);
266264

267265
let local_def_id = trait_assoc_ty.def_id();

library/alloc/src/vec/mod.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,61 @@ impl<T, A: Allocator> Vec<T, A> {
30313031
(initialized, spare, &mut self.len)
30323032
}
30333033
}
3034+
3035+
/// Groups every `N` elements in the `Vec<T>` into chunks to produce a `Vec<[T; N]>`, dropping
3036+
/// elements in the remainder. `N` must be greater than zero.
3037+
///
3038+
/// If the capacity is not a multiple of the chunk size, the buffer will shrink down to the
3039+
/// nearest multiple with a reallocation or deallocation.
3040+
///
3041+
/// This function can be used to reverse [`Vec::into_flattened`].
3042+
///
3043+
/// # Examples
3044+
///
3045+
/// ```
3046+
/// #![feature(vec_into_chunks)]
3047+
///
3048+
/// let vec = vec![0, 1, 2, 3, 4, 5, 6, 7];
3049+
/// assert_eq!(vec.into_chunks::<3>(), [[0, 1, 2], [3, 4, 5]]);
3050+
///
3051+
/// let vec = vec![0, 1, 2, 3];
3052+
/// let chunks: Vec<[u8; 10]> = vec.into_chunks();
3053+
/// assert!(chunks.is_empty());
3054+
///
3055+
/// let flat = vec![0; 8 * 8 * 8];
3056+
/// let reshaped: Vec<[[[u8; 8]; 8]; 8]> = flat.into_chunks().into_chunks().into_chunks();
3057+
/// assert_eq!(reshaped.len(), 1);
3058+
/// ```
3059+
#[cfg(not(no_global_oom_handling))]
3060+
#[unstable(feature = "vec_into_chunks", issue = "142137")]
3061+
pub fn into_chunks<const N: usize>(mut self) -> Vec<[T; N], A> {
3062+
const {
3063+
assert!(N != 0, "chunk size must be greater than zero");
3064+
}
3065+
3066+
let (len, cap) = (self.len(), self.capacity());
3067+
3068+
let len_remainder = len % N;
3069+
if len_remainder != 0 {
3070+
self.truncate(len - len_remainder);
3071+
}
3072+
3073+
let cap_remainder = cap % N;
3074+
if !T::IS_ZST && cap_remainder != 0 {
3075+
self.buf.shrink_to_fit(cap - cap_remainder);
3076+
}
3077+
3078+
let (ptr, _, _, alloc) = self.into_raw_parts_with_alloc();
3079+
3080+
// SAFETY:
3081+
// - `ptr` and `alloc` were just returned from `self.into_raw_parts_with_alloc()`
3082+
// - `[T; N]` has the same alignment as `T`
3083+
// - `size_of::<[T; N]>() * cap / N == size_of::<T>() * cap`
3084+
// - `len / N <= cap / N` because `len <= cap`
3085+
// - the allocated memory consists of `len / N` valid values of type `[T; N]`
3086+
// - `cap / N` fits the size of the allocated memory after shrinking
3087+
unsafe { Vec::from_raw_parts_in(ptr.cast(), len / N, cap / N, alloc) }
3088+
}
30343089
}
30353090

30363091
impl<T: Clone, A: Allocator> Vec<T, A> {

0 commit comments

Comments
 (0)