Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5264bc9

Browse files
committed
Auto merge of #143305 - jhpratt:rollup-t7e7uhj, r=jhpratt
Rollup of 12 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) - #142568 (Use the .drectve section for exporting symbols from dlls on Windows) - #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 085c247 + 9a07698 commit 5264bc9

File tree

60 files changed

+762
-192
lines changed

Some content is hidden

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

60 files changed

+762
-192
lines changed

‎compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,9 +1957,11 @@ fn add_linked_symbol_object(
19571957
cmd: &mut dyn Linker,
19581958
sess: &Session,
19591959
tmpdir: &Path,
1960-
symbols: &[(String, SymbolExportKind)],
1960+
crate_type: CrateType,
1961+
linked_symbols: &[(String, SymbolExportKind)],
1962+
exported_symbols: &[(String, SymbolExportKind)],
19611963
) {
1962-
if symbols.is_empty() {
1964+
if linked_symbols.is_empty() && exported_symbols.is_empty() {
19631965
return;
19641966
}
19651967

@@ -1996,7 +1998,7 @@ fn add_linked_symbol_object(
19961998
None
19971999
};
19982000

1999-
for (sym, kind) in symbols.iter() {
2001+
for (sym, kind) in linked_symbols.iter() {
20002002
let symbol = file.add_symbol(object::write::Symbol {
20012003
name: sym.clone().into(),
20022004
value: 0,
@@ -2054,6 +2056,41 @@ fn add_linked_symbol_object(
20542056
}
20552057
}
20562058

2059+
if sess.target.is_like_msvc {
2060+
// Symbol visibility takes care of this for executables typically
2061+
let should_filter_symbols = if crate_type == CrateType::Executable {
2062+
sess.opts.unstable_opts.export_executable_symbols
2063+
} else {
2064+
true
2065+
};
2066+
if should_filter_symbols {
2067+
// Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
2068+
// export symbols from a dynamic library. When building a dynamic library,
2069+
// however, we're going to want some symbols exported, so this adds a
2070+
// `.drectve` section which lists all the symbols using /EXPORT arguments.
2071+
//
2072+
// The linker will read these arguments from the `.drectve` section and
2073+
// export all the symbols from the dynamic library. Note that this is not
2074+
// as simple as just exporting all the symbols in the current crate (as
2075+
// specified by `codegen.reachable`) but rather we also need to possibly
2076+
// export the symbols of upstream crates. Upstream rlibs may be linked
2077+
// statically to this dynamic library, in which case they may continue to
2078+
// transitively be used and hence need their symbols exported.
2079+
let drectve = exported_symbols
2080+
.into_iter()
2081+
.map(|(sym, kind)| match kind {
2082+
SymbolExportKind::Text | SymbolExportKind::Tls => format!(" /EXPORT:\"{sym}\""),
2083+
SymbolExportKind::Data => format!(" /EXPORT:\"{sym}\",DATA"),
2084+
})
2085+
.collect::<Vec<_>>()
2086+
.join("");
2087+
2088+
let section =
2089+
file.add_section(vec![], b".drectve".to_vec(), object::SectionKind::Linker);
2090+
file.append_section_data(section, drectve.as_bytes(), 1);
2091+
}
2092+
}
2093+
20572094
let path = tmpdir.join("symbols.o");
20582095
let result = std::fs::write(&path, file.write().unwrap());
20592096
if let Err(error) = result {
@@ -2228,7 +2265,9 @@ fn linker_with_args(
22282265
cmd,
22292266
sess,
22302267
tmpdir,
2268+
crate_type,
22312269
&codegen_results.crate_info.linked_symbols[&crate_type],
2270+
&codegen_results.crate_info.exported_symbols[&crate_type],
22322271
);
22332272

22342273
// Sanitizer libraries.

‎compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,53 +1097,13 @@ impl<'a> Linker for MsvcLinker<'a> {
10971097
}
10981098
}
10991099

1100-
// Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
1101-
// export symbols from a dynamic library. When building a dynamic library,
1102-
// however, we're going to want some symbols exported, so this function
1103-
// generates a DEF file which lists all the symbols.
1104-
//
1105-
// The linker will read this `*.def` file and export all the symbols from
1106-
// the dynamic library. Note that this is not as simple as just exporting
1107-
// all the symbols in the current crate (as specified by `codegen.reachable`)
1108-
// but rather we also need to possibly export the symbols of upstream
1109-
// crates. Upstream rlibs may be linked statically to this dynamic library,
1110-
// in which case they may continue to transitively be used and hence need
1111-
// their symbols exported.
11121100
fn export_symbols(
11131101
&mut self,
1114-
tmpdir: &Path,
1115-
crate_type: CrateType,
1116-
symbols: &[(String, SymbolExportKind)],
1102+
_tmpdir: &Path,
1103+
_crate_type: CrateType,
1104+
_symbols: &[(String, SymbolExportKind)],
11171105
) {
1118-
// Symbol visibility takes care of this typically
1119-
if crate_type == CrateType::Executable {
1120-
let should_export_executable_symbols =
1121-
self.sess.opts.unstable_opts.export_executable_symbols;
1122-
if !should_export_executable_symbols {
1123-
return;
1124-
}
1125-
}
1126-
1127-
let path = tmpdir.join("lib.def");
1128-
let res: io::Result<()> = try {
1129-
let mut f = File::create_buffered(&path)?;
1130-
1131-
// Start off with the standard module name header and then go
1132-
// straight to exports.
1133-
writeln!(f, "LIBRARY")?;
1134-
writeln!(f, "EXPORTS")?;
1135-
for (symbol, kind) in symbols {
1136-
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
1137-
debug!(" _{symbol}");
1138-
writeln!(f, " {symbol}{kind_marker}")?;
1139-
}
1140-
};
1141-
if let Err(error) = res {
1142-
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
1143-
}
1144-
let mut arg = OsString::from("/DEF:");
1145-
arg.push(path);
1146-
self.link_arg(&arg);
1106+
// We already add /EXPORT arguments to the .drectve section of symbols.o.
11471107
}
11481108

11491109
fn subsystem(&mut self, subsystem: &str) {

‎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+
mutvalid_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
@@ -2288,7 +2288,7 @@ impl<'tcx> TyCtxt<'tcx> {
22882288
}
22892289

22902290
/// All traits in the crate graph, including those not visible to the user.
2291-
pub fn all_traits(self) -> impl Iterator<Item = DefId> {
2291+
pub fn all_traits_including_private(self) -> impl Iterator<Item = DefId> {
22922292
iter::once(LOCAL_CRATE)
22932293
.chain(self.crates(()).iter().copied())
22942294
.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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /