Skip to content

Rollup of 12 pull requests #143305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e95751a
Explain TOCTOU on the top of `std::fs`, and ref it in functions
xizheyin Jun 1, 2025
230b55d
Add `into_chunks`
ashivaram23 Jun 7, 2025
e4e7773
put feature attribute in example
ashivaram23 Jun 7, 2025
343db27
cfg for no no_global_oom_handling
ashivaram23 Jun 7, 2025
c1d32d8
fix wording in assert
ashivaram23 Jun 7, 2025
cfa6731
expose abi information on ppc64 targets
ostylk Jun 16, 2025
45538e0
ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`
Enselic Jun 22, 2025
7539730
Use the .drectve section for exporting symbols from dlls on Windows
bjorn3 Jun 16, 2025
4238e5e
sleep_until: add platform specific implementations
dvdsk May 31, 2025
395aaf8
sleep_until: add reason to allow(unused)
dvdsk Jun 3, 2025
168a1a1
sleep_until: handle 32bit time_t targets
dvdsk Jun 3, 2025
1626d55
sleep_until: improve maintainability
dvdsk Jun 5, 2025
f1f39d1
sleep_until: Fix error handling + improve maintainablity
dvdsk Jun 11, 2025
e86fddc
fix bitcast of single-element SIMD vectors
folkertdev Jun 29, 2025
08278eb
Don't recompute DisambiguatorState for every RPITIT in trait definition
compiler-errors Jun 30, 2025
c073286
Use the correct export kind for __rust_alloc_error_handler_should_panic
dpaoliello Jun 30, 2025
3bf650f
add failing test, bless incorrect output
Qelxiros Jun 30, 2025
1e6e4bb
make compiler_builtins a private dependency
Qelxiros Jun 30, 2025
51aa76f
avoid suggesting traits from private dependencies
Qelxiros Jul 1, 2025
311a99c
ci: support optional jobs
marcoieni Jul 1, 2025
308ef8d
Remove `repr(align)` code
Jules-Bertholet Jun 29, 2025
278f4f4
Support `#[align(…)]` on fns in `extern` blocks
Jules-Bertholet Jun 29, 2025
55d0210
Test `async fn`
Jules-Bertholet Jun 29, 2025
0382357
Add test for `dyn` alignment
Jules-Bertholet Jun 29, 2025
233e2ef
Add FIXME for gen et al
Jules-Bertholet Jul 1, 2025
440bf29
Add more tests for invalid alignments
Jules-Bertholet Jul 1, 2025
b0a9446
Rollup merge of #141829 - dvdsk:sleep_until_linux, r=cuviper
jhpratt Jul 1, 2025
c43faef
Rollup merge of #141847 - xizheyin:141837, r=jhpratt
jhpratt Jul 1, 2025
31e6410
Rollup merge of #142138 - ashivaram23:vec_into_chunks, r=scottmcm
jhpratt Jul 1, 2025
0d9142e
Rollup merge of #142321 - ostylk:fix/ppc64_abi, r=workingjubilee
jhpratt Jul 1, 2025
3336cf6
Rollup merge of #142568 - bjorn3:windows_symbols_o_export, r=wesleywiser
jhpratt Jul 1, 2025
f7231b3
Rollup merge of #142886 - Enselic:aarch64-panic, r=cuviper
jhpratt Jul 1, 2025
2f39595
Rollup merge of #143038 - Qelxiros:142676-private-dependency-traits, …
jhpratt Jul 1, 2025
fc13275
Rollup merge of #143194 - folkertdev:fix-single-element-simd-bitcast,…
jhpratt Jul 1, 2025
67a5073
Rollup merge of #143206 - Jules-Bertholet:align-attr-fixes, r=working…
jhpratt Jul 1, 2025
c017748
Rollup merge of #143258 - compiler-errors:disambiguator-state, r=oli-obk
jhpratt Jul 1, 2025
932d198
Rollup merge of #143260 - dpaoliello:arm64eclinkagain, r=bjorn3
jhpratt Jul 1, 2025
9a07698
Rollup merge of #143274 - marcoieni:optional-jobs, r=Kobzol
jhpratt Jul 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,9 +1957,11 @@ fn add_linked_symbol_object(
cmd: &mut dyn Linker,
sess: &Session,
tmpdir: &Path,
symbols: &[(String, SymbolExportKind)],
crate_type: CrateType,
linked_symbols: &[(String, SymbolExportKind)],
exported_symbols: &[(String, SymbolExportKind)],
) {
if symbols.is_empty() {
if linked_symbols.is_empty() && exported_symbols.is_empty() {
return;
}

Expand Down Expand Up @@ -1996,7 +1998,7 @@ fn add_linked_symbol_object(
None
};

for (sym, kind) in symbols.iter() {
for (sym, kind) in linked_symbols.iter() {
let symbol = file.add_symbol(object::write::Symbol {
name: sym.clone().into(),
value: 0,
Expand Down Expand Up @@ -2054,6 +2056,41 @@ fn add_linked_symbol_object(
}
}

if sess.target.is_like_msvc {
// Symbol visibility takes care of this for executables typically
let should_filter_symbols = if crate_type == CrateType::Executable {
sess.opts.unstable_opts.export_executable_symbols
} else {
true
};
if should_filter_symbols {
// Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
// export symbols from a dynamic library. When building a dynamic library,
// however, we're going to want some symbols exported, so this adds a
// `.drectve` section which lists all the symbols using /EXPORT arguments.
//
// The linker will read these arguments from the `.drectve` section and
// export all the symbols from the dynamic library. Note that this is not
// as simple as just exporting all the symbols in the current crate (as
// specified by `codegen.reachable`) but rather we also need to possibly
// export the symbols of upstream crates. Upstream rlibs may be linked
// statically to this dynamic library, in which case they may continue to
// transitively be used and hence need their symbols exported.
let drectve = exported_symbols
.into_iter()
.map(|(sym, kind)| match kind {
SymbolExportKind::Text | SymbolExportKind::Tls => format!(" /EXPORT:\"{sym}\""),
SymbolExportKind::Data => format!(" /EXPORT:\"{sym}\",DATA"),
})
.collect::<Vec<_>>()
.join("");

let section =
file.add_section(vec![], b".drectve".to_vec(), object::SectionKind::Linker);
file.append_section_data(section, drectve.as_bytes(), 1);
}
}

let path = tmpdir.join("symbols.o");
let result = std::fs::write(&path, file.write().unwrap());
if let Err(error) = result {
Expand Down Expand Up @@ -2228,7 +2265,9 @@ fn linker_with_args(
cmd,
sess,
tmpdir,
crate_type,
&codegen_results.crate_info.linked_symbols[&crate_type],
&codegen_results.crate_info.exported_symbols[&crate_type],
);

// Sanitizer libraries.
Expand Down
48 changes: 4 additions & 44 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,53 +1097,13 @@ impl<'a> Linker for MsvcLinker<'a> {
}
}

// Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
// export symbols from a dynamic library. When building a dynamic library,
// however, we're going to want some symbols exported, so this function
// generates a DEF file which lists all the symbols.
//
// The linker will read this `*.def` file and export all the symbols from
// the dynamic library. Note that this is not as simple as just exporting
// all the symbols in the current crate (as specified by `codegen.reachable`)
// but rather we also need to possibly export the symbols of upstream
// crates. Upstream rlibs may be linked statically to this dynamic library,
// in which case they may continue to transitively be used and hence need
// their symbols exported.
fn export_symbols(
&mut self,
tmpdir: &Path,
crate_type: CrateType,
symbols: &[(String, SymbolExportKind)],
_tmpdir: &Path,
_crate_type: CrateType,
_symbols: &[(String, SymbolExportKind)],
) {
// Symbol visibility takes care of this typically
if crate_type == CrateType::Executable {
let should_export_executable_symbols =
self.sess.opts.unstable_opts.export_executable_symbols;
if !should_export_executable_symbols {
return;
}
}

let path = tmpdir.join("lib.def");
let res: io::Result<()> = try {
let mut f = File::create_buffered(&path)?;

// Start off with the standard module name header and then go
// straight to exports.
writeln!(f, "LIBRARY")?;
writeln!(f, "EXPORTS")?;
for (symbol, kind) in symbols {
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
debug!(" _{symbol}");
writeln!(f, " {symbol}{kind_marker}")?;
}
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
let mut arg = OsString::from("/DEF:");
arg.push(path);
self.link_arg(&arg);
// We already add /EXPORT arguments to the .drectve section of symbols.o.
}

fn subsystem(&mut self, subsystem: &str) {
Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,18 @@ fn exported_non_generic_symbols_provider_local<'tcx>(

// Mark allocator shim symbols as exported only if they were generated.
if allocator_kind_for_codegen(tcx).is_some() {
for symbol_name in ALLOCATOR_METHODS
for (symbol_name, export_kind) in ALLOCATOR_METHODS
.iter()
.map(|method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
.map(|method| {
(
mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()),
SymbolExportKind::Text,
)
})
.chain([
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
(mangle_internal_symbol(tcx, "__rust_alloc_error_handler"), SymbolExportKind::Text),
(mangle_internal_symbol(tcx, OomStrategy::SYMBOL), SymbolExportKind::Data),
(mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE), SymbolExportKind::Text),
])
{
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
Expand All @@ -234,7 +239,7 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
kind: export_kind,
used: false,
rustc_std_internal_symbol: true,
},
Expand Down
10 changes: 1 addition & 9 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_abi::{Align, ExternAbi};
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
use rustc_attr_data_structures::{
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, ReprAttr, UsedBy, find_attr,
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, UsedBy, find_attr,
};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
Expand Down Expand Up @@ -109,14 +109,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {

if let hir::Attribute::Parsed(p) = attr {
match p {
AttributeKind::Repr(reprs) => {
codegen_fn_attrs.alignment = reprs
.iter()
.filter_map(
|(r, _)| if let ReprAttr::ReprAlign(x) = r { Some(*x) } else { None },
)
.max();
}
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
AttributeKind::ExportName { name, .. } => {
codegen_fn_attrs.export_name = Some(*name);
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ pub(super) fn transmute_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// While optimizations will remove no-op transmutes, they might still be
// there in debug or things that aren't no-op in MIR because they change
// the Rust type but not the underlying layout/niche.
if from_scalar == to_scalar {
if from_scalar == to_scalar && from_backend_ty == to_backend_ty {
return imm;
}

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

imm = match (from_scalar.primitive(), to_scalar.primitive()) {
(Int(..) | Float(_), Int(..) | Float(_)) => {
if from_backend_ty == to_backend_ty {
imm
} else {
bx.bitcast(imm, to_backend_ty)
}
}
(Int(..) | Float(_), Int(..) | Float(_)) => bx.bitcast(imm, to_backend_ty),
(Pointer(..), Pointer(..)) => bx.pointercast(imm, to_backend_ty),
(Int(..), Pointer(..)) => bx.ptradd(bx.const_null(bx.type_ptr()), imm),
(Pointer(..), Int(..)) => {
Expand Down
30 changes: 20 additions & 10 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&infcx_
};

tcx.all_traits()
tcx.all_traits_including_private()
.filter(|trait_def_id| {
// Consider only traits with the associated type
tcx.associated_items(*trait_def_id)
Expand Down Expand Up @@ -2460,13 +2460,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// type a projection.
let in_trait = match opaque_ty.origin {
hir::OpaqueTyOrigin::FnReturn {
parent,
in_trait_or_impl: Some(hir::RpitContext::Trait),
..
}
| hir::OpaqueTyOrigin::AsyncFn {
parent,
in_trait_or_impl: Some(hir::RpitContext::Trait),
..
} => true,
} => Some(parent),
hir::OpaqueTyOrigin::FnReturn {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
..
Expand All @@ -2475,7 +2477,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
..
}
| hir::OpaqueTyOrigin::TyAlias { .. } => false,
| hir::OpaqueTyOrigin::TyAlias { .. } => None,
};

self.lower_opaque_ty(opaque_ty.def_id, in_trait)
Expand Down Expand Up @@ -2595,17 +2597,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

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

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

// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
// generate the def_id of an associated type for the trait and return as
// type a projection.
let def_id = if in_trait {
tcx.associated_type_for_impl_trait_in_trait(def_id).to_def_id()
// If this is an RPITIT and we are using the new RPITIT lowering scheme,
// do a linear search to map this to the synthetic associated type that
// it will be lowered to.
let def_id = if let Some(parent_def_id) = in_trait {
*tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id)
.iter()
.find(|rpitit| match tcx.opt_rpitit_info(**rpitit) {
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
opaque_def_id.expect_local() == def_id
}
_ => unreachable!(),
})
.unwrap()
} else {
def_id.to_def_id()
};
Expand All @@ -2628,7 +2638,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
});
debug!(?args);

if in_trait {
if in_trait.is_some() {
Ty::new_projection_from_args(tcx, def_id, args)
} else {
Ty::new_opaque(tcx, def_id, args)
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if unsatisfied_predicates.is_empty()
// ...or if we already suggested that name because of `rustc_confusable` annotation
&& Some(similar_candidate.name()) != confusable_suggested
// and if the we aren't in an expansion.
// and if we aren't in an expansion.
&& !span.from_expansion()
{
self.find_likely_intended_associated_item(
Expand Down Expand Up @@ -3481,9 +3481,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
err: &mut Diag<'_>,
item_name: Ident,
valid_out_of_scope_traits: Vec<DefId>,
mut valid_out_of_scope_traits: Vec<DefId>,
explain: bool,
) -> bool {
valid_out_of_scope_traits.retain(|id| self.tcx.is_user_visible_dep(id.krate));
if !valid_out_of_scope_traits.is_empty() {
let mut candidates = valid_out_of_scope_traits;
candidates.sort_by_key(|id| self.tcx.def_path_str(id));
Expand Down Expand Up @@ -4388,7 +4389,7 @@ pub(crate) struct TraitInfo {
/// Retrieves all traits in this crate and any dependent crates,
/// and wraps them into `TraitInfo` for custom sorting.
pub(crate) fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
tcx.all_traits().map(|def_id| TraitInfo { def_id }).collect()
tcx.all_traits_including_private().map(|def_id| TraitInfo { def_id }).collect()
}

fn print_disambiguation_help<'tcx>(
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,13 +1093,6 @@ rustc_queries! {
separate_provide_extern
}

/// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
/// associated item.
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
desc { |tcx| "creating the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
cache_on_disk_if { true }
}

/// Given an `impl_id`, return the trait it implements along with some header information.
/// Return `None` if this is an inherent impl.
query impl_trait_header(impl_id: DefId) -> Option<ty::ImplTraitHeader<'tcx>> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

/// All traits in the crate graph, including those not visible to the user.
pub fn all_traits(self) -> impl Iterator<Item = DefId> {
pub fn all_traits_including_private(self) -> impl Iterator<Item = DefId> {
iter::once(LOCAL_CRATE)
.chain(self.crates(()).iter().copied())
.flat_map(move |cnum| self.traits(cnum).iter().copied())
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ passes_abi_ne =
passes_abi_of =
fn_abi_of({$fn_name}) = {$fn_abi}

passes_align_attr_application =
`#[align(...)]` should be applied to a function item
.label = not a function item

passes_align_should_be_repr_align =
`#[align(...)]` is not supported on {$item} items
.suggestion = use `#[repr(align(...))]` instead
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Checks if the `#[align]` attributes on `item` are valid.
fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) {
match target {
Target::Fn | Target::Method(_) => {}
Target::Fn | Target::Method(_) | Target::ForeignFn => {}
Target::Struct | Target::Union | Target::Enum => {
self.dcx().emit_err(errors::AlignShouldBeReprAlign {
span: repr_span,
Expand All @@ -1897,10 +1897,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
});
}
_ => {
self.dcx().emit_err(errors::AttrApplication::StructEnumUnion {
hint_span: repr_span,
span,
});
self.dcx().emit_err(errors::AlignAttrApplication { hint_span: repr_span, span });
}
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,3 +1838,12 @@ pub(crate) struct AlignShouldBeReprAlign {
pub item: &'static str,
pub align_bytes: u64,
}

#[derive(Diagnostic)]
#[diag(passes_align_attr_application)]
pub(crate) struct AlignAttrApplication {
#[primary_span]
pub hint_span: Span,
#[label]
pub span: Span,
}
Loading
Loading