Skip to content

Commit 77b41b0

Browse files
committed
Auto merge of #143311 - jhpratt:rollup-vjx4zoy, r=jhpratt
Rollup of 11 pull requests Successful merges: - #141829 (Specialize sleep_until implementation for unix (except mac)) - #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`) - #143038 (avoid suggesting traits from private dependencies) - #143194 (fix bitcast of single-element SIMD vectors) - #143206 (Align attr fixes) - #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 f51c987 + f609f8c commit 77b41b0

File tree

57 files changed

+696
-145
lines changed

Some content is hidden

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

57 files changed

+696
-145
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/codegen_attrs.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::{Align, ExternAbi};
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_attr_data_structures::{
7-
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, ReprAttr, UsedBy, find_attr,
7+
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, UsedBy, find_attr,
88
};
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
@@ -109,14 +109,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
109109

110110
if let hir::Attribute::Parsed(p) = attr {
111111
match p {
112-
AttributeKind::Repr(reprs) => {
113-
codegen_fn_attrs.alignment = reprs
114-
.iter()
115-
.filter_map(
116-
|(r, _)| if let ReprAttr::ReprAlign(x) = r { Some(*x) } else { None },
117-
)
118-
.max();
119-
}
120112
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
121113
AttributeKind::ExportName { name, .. } => {
122114
codegen_fn_attrs.export_name = Some(*name);

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: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15881588
&infcx_
15891589
};
15901590

1591-
tcx.all_traits()
1591+
tcx.all_traits_including_private()
15921592
.filter(|trait_def_id| {
15931593
// Consider only traits with the associated type
15941594
tcx.associated_items(*trait_def_id)
@@ -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_hir_typeck/src/method/suggest.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17251725
if unsatisfied_predicates.is_empty()
17261726
// ...or if we already suggested that name because of `rustc_confusable` annotation
17271727
&& Some(similar_candidate.name()) != confusable_suggested
1728-
// and if the we aren't in an expansion.
1728+
// and if we aren't in an expansion.
17291729
&& !span.from_expansion()
17301730
{
17311731
self.find_likely_intended_associated_item(
@@ -3481,9 +3481,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34813481
&self,
34823482
err: &mut Diag<'_>,
34833483
item_name: Ident,
3484-
valid_out_of_scope_traits: Vec<DefId>,
3484+
mut valid_out_of_scope_traits: Vec<DefId>,
34853485
explain: bool,
34863486
) -> bool {
3487+
valid_out_of_scope_traits.retain(|id| self.tcx.is_user_visible_dep(id.krate));
34873488
if !valid_out_of_scope_traits.is_empty() {
34883489
let mut candidates = valid_out_of_scope_traits;
34893490
candidates.sort_by_key(|id| self.tcx.def_path_str(id));
@@ -4388,7 +4389,7 @@ pub(crate) struct TraitInfo {
43884389
/// Retrieves all traits in this crate and any dependent crates,
43894390
/// and wraps them into `TraitInfo` for custom sorting.
43904391
pub(crate) fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
4391-
tcx.all_traits().map(|def_id| TraitInfo { def_id }).collect()
4392+
tcx.all_traits_including_private().map(|def_id| TraitInfo { def_id }).collect()
43924393
}
43934394

43944395
fn print_disambiguation_help<'tcx>(

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_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ impl<'tcx> TyCtxt<'tcx> {
22872287
}
22882288

22892289
/// All traits in the crate graph, including those not visible to the user.
2290-
pub fn all_traits(self) -> impl Iterator<Item = DefId> {
2290+
pub fn all_traits_including_private(self) -> impl Iterator<Item = DefId> {
22912291
iter::once(LOCAL_CRATE)
22922292
.chain(self.crates(()).iter().copied())
22932293
.flat_map(move |cnum| self.traits(cnum).iter().copied())

compiler/rustc_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ passes_abi_ne =
1313
passes_abi_of =
1414
fn_abi_of({$fn_name}) = {$fn_abi}
1515
16+
passes_align_attr_application =
17+
`#[align(...)]` should be applied to a function item
18+
.label = not a function item
19+
1620
passes_align_should_be_repr_align =
1721
`#[align(...)]` is not supported on {$item} items
1822
.suggestion = use `#[repr(align(...))]` instead

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18881888
/// Checks if the `#[align]` attributes on `item` are valid.
18891889
fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) {
18901890
match target {
1891-
Target::Fn | Target::Method(_) => {}
1891+
Target::Fn | Target::Method(_) | Target::ForeignFn => {}
18921892
Target::Struct | Target::Union | Target::Enum => {
18931893
self.dcx().emit_err(errors::AlignShouldBeReprAlign {
18941894
span: repr_span,
@@ -1897,10 +1897,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18971897
});
18981898
}
18991899
_ => {
1900-
self.dcx().emit_err(errors::AttrApplication::StructEnumUnion {
1901-
hint_span: repr_span,
1902-
span,
1903-
});
1900+
self.dcx().emit_err(errors::AlignAttrApplication { hint_span: repr_span, span });
19041901
}
19051902
}
19061903

compiler/rustc_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,12 @@ pub(crate) struct AlignShouldBeReprAlign {
18381838
pub item: &'static str,
18391839
pub align_bytes: u64,
18401840
}
1841+
1842+
#[derive(Diagnostic)]
1843+
#[diag(passes_align_attr_application)]
1844+
pub(crate) struct AlignAttrApplication {
1845+
#[primary_span]
1846+
pub hint_span: Span,
1847+
#[label]
1848+
pub span: Span,
1849+
}

compiler/rustc_smir/src/rustc_smir/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ impl<'tcx> SmirCtxt<'tcx> {
130130

131131
pub fn all_trait_decls(&self) -> stable_mir::TraitDecls {
132132
let mut tables = self.0.borrow_mut();
133-
tables.tcx.all_traits().map(|trait_def_id| tables.trait_def(trait_def_id)).collect()
133+
tables
134+
.tcx
135+
.all_traits_including_private()
136+
.map(|trait_def_id| tables.trait_def(trait_def_id))
137+
.collect()
134138
}
135139

136140
pub fn trait_decls(&self, crate_num: CrateNum) -> stable_mir::TraitDecls {

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_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18551855
let trait_def_id = trait_pred.def_id();
18561856
let trait_name = self.tcx.item_name(trait_def_id);
18571857
let crate_name = self.tcx.crate_name(trait_def_id.krate);
1858-
if let Some(other_trait_def_id) = self.tcx.all_traits().find(|def_id| {
1858+
if let Some(other_trait_def_id) = self.tcx.all_traits_including_private().find(|def_id| {
18591859
trait_name == self.tcx.item_name(trait_def_id)
18601860
&& trait_def_id.krate != def_id.krate
18611861
&& crate_name == self.tcx.crate_name(def_id.krate)

0 commit comments

Comments
 (0)