Skip to content

Commit db92e8a

Browse files
committed
Auto merge of #120876 - matthiaskrgr:rollup-ava53mi, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #117614 (static mut: allow mutable reference to arbitrary types, not just slices and arrays) - #120588 (wasm: Store rlib metadata in wasm object files) - #120719 (Remove support for `associated_type_bound` nested in `dyn` types) - #120823 (Clarify that atomic and regular integers can differ in alignment) - #120859 (Loosen an assertion to account for stashed errors.) - #120865 (Turn the "no saved object file in work product" ICE into a translatable fatal error) - #120866 (Remove unnecessary `#![feature(min_specialization)]`) - #120870 (Allow restricted trait impls under `#[allow_internal_unstable(min_specialization)]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 232919c + 6966cad commit db92e8a

File tree

61 files changed

+308
-549
lines changed

Some content is hidden

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

61 files changed

+308
-549
lines changed

Cargo.lock

+11
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,7 @@ dependencies = [
26082608
"rustc-std-workspace-alloc",
26092609
"rustc-std-workspace-core",
26102610
"ruzstd",
2611+
"wasmparser",
26112612
]
26122613

26132614
[[package]]
@@ -6036,6 +6037,16 @@ version = "0.2.87"
60366037
source = "registry+https://github.com/rust-lang/crates.io-index"
60376038
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
60386039

6040+
[[package]]
6041+
name = "wasmparser"
6042+
version = "0.118.1"
6043+
source = "registry+https://github.com/rust-lang/crates.io-index"
6044+
checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9"
6045+
dependencies = [
6046+
"indexmap",
6047+
"semver",
6048+
]
6049+
60396050
[[package]]
60406051
name = "web-sys"
60416052
version = "0.3.61"

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(if_let_guard)]
1717
#![feature(let_chains)]
18-
#![feature(min_specialization)]
18+
#![cfg_attr(bootstrap, feature(min_specialization))]
1919
#![feature(negative_impls)]
2020
#![feature(stmt_expr_attributes)]
2121

compiler/rustc_ast_lowering/messages.ftl

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ ast_lowering_arbitrary_expression_in_pattern =
88
99
ast_lowering_argument = argument
1010
11+
ast_lowering_assoc_ty_binding_in_dyn =
12+
associated type bounds are not allowed in `dyn` types
13+
.suggestion = use `impl Trait` to introduce a type instead
14+
1115
ast_lowering_assoc_ty_parentheses =
1216
parenthesized generic arguments cannot be used in associated type constraints
1317
@@ -100,9 +104,6 @@ ast_lowering_match_arm_with_no_body =
100104
`match` arm with no body
101105
.suggestion = add a body after the pattern
102106
103-
ast_lowering_misplaced_assoc_ty_binding =
104-
associated type bounds are only allowed in where clauses and function signatures, not in {$position}
105-
106107
ast_lowering_misplaced_double_dot =
107108
`..` patterns are not allowed here
108109
.note = only allowed in tuple, tuple struct, and slice patterns

compiler/rustc_ast_lowering/src/errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ pub struct MisplacedImplTrait<'a> {
9494
}
9595

9696
#[derive(Diagnostic)]
97-
#[diag(ast_lowering_misplaced_assoc_ty_binding)]
98-
pub struct MisplacedAssocTyBinding<'a> {
97+
#[diag(ast_lowering_assoc_ty_binding_in_dyn)]
98+
pub struct MisplacedAssocTyBinding {
9999
#[primary_span]
100100
pub span: Span,
101-
pub position: DiagnosticArgFromDisplay<'a>,
101+
#[suggestion(code = " = impl", applicability = "maybe-incorrect", style = "verbose")]
102+
pub suggestion: Option<Span>,
102103
}
103104

104105
#[derive(Diagnostic, Clone, Copy)]

compiler/rustc_ast_lowering/src/lib.rs

+30-86
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ trait ResolverAstLoweringExt {
197197
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
198198
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
199199
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
200-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId);
201200
}
202201

203202
impl ResolverAstLoweringExt for ResolverAstLowering {
@@ -256,11 +255,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
256255
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
257256
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
258257
}
259-
260-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId) {
261-
let lifetimes = self.extra_lifetime_params_map.remove(&from).unwrap_or_default();
262-
self.extra_lifetime_params_map.insert(to, lifetimes);
263-
}
264258
}
265259

266260
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1084,88 +1078,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10841078
hir::TypeBindingKind::Equality { term }
10851079
}
10861080
AssocConstraintKind::Bound { bounds } => {
1087-
enum DesugarKind {
1088-
ImplTrait,
1089-
Error(ImplTraitPosition),
1090-
Bound,
1091-
}
1092-
1093-
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1094-
let desugar_kind = match itctx {
1095-
// in an argument, RPIT, or TAIT, if we are within a dyn type:
1096-
//
1097-
// fn foo(x: dyn Iterator<Item: Debug>)
1098-
//
1099-
// then desugar to:
1100-
//
1101-
// fn foo(x: dyn Iterator<Item = impl Debug>)
1102-
//
1103-
// This is because dyn traits must have all of their associated types specified.
1104-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1105-
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1106-
| ImplTraitContext::Universal
1107-
if self.is_in_dyn_type =>
1108-
{
1109-
DesugarKind::ImplTrait
1110-
}
1111-
1112-
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
1113-
DesugarKind::Error(position)
1114-
}
1115-
1116-
// We are in the parameter position, but not within a dyn type:
1117-
//
1118-
// fn foo(x: impl Iterator<Item: Debug>)
1119-
//
1120-
// so we leave it as is and this gets expanded in astconv to a bound like
1121-
// `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1122-
// `impl Iterator`.
1123-
_ => DesugarKind::Bound,
1124-
};
1125-
1126-
match desugar_kind {
1127-
DesugarKind::ImplTrait => {
1128-
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
1129-
// constructing the HIR for `impl bounds...` and then lowering that.
1130-
1131-
let impl_trait_node_id = self.next_node_id();
1132-
// Shift `impl Trait` lifetime captures from the associated type bound's
1133-
// node id to the opaque node id, so that the opaque can actually use
1134-
// these lifetime bounds.
1135-
self.resolver
1136-
.remap_extra_lifetime_params(constraint.id, impl_trait_node_id);
1137-
1138-
self.with_dyn_type_scope(false, |this| {
1139-
let node_id = this.next_node_id();
1140-
let ty = this.lower_ty(
1141-
&Ty {
1142-
id: node_id,
1143-
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1144-
span: this.lower_span(constraint.span),
1145-
tokens: None,
1146-
},
1147-
itctx,
1148-
);
1081+
// Disallow ATB in dyn types
1082+
if self.is_in_dyn_type {
1083+
let suggestion = match itctx {
1084+
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1085+
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1086+
| ImplTraitContext::Universal => {
1087+
let bound_end_span = constraint
1088+
.gen_args
1089+
.as_ref()
1090+
.map_or(constraint.ident.span, |args| args.span());
1091+
if bound_end_span.eq_ctxt(constraint.span) {
1092+
Some(self.tcx.sess.source_map().next_point(bound_end_span))
1093+
} else {
1094+
None
1095+
}
1096+
}
1097+
_ => None,
1098+
};
11491099

1150-
hir::TypeBindingKind::Equality { term: ty.into() }
1151-
})
1152-
}
1153-
DesugarKind::Bound => {
1154-
// Desugar `AssocTy: Bounds` into a type binding where the
1155-
// later desugars into a trait predicate.
1156-
let bounds = self.lower_param_bounds(bounds, itctx);
1100+
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1101+
span: constraint.span,
1102+
suggestion,
1103+
});
1104+
let err_ty =
1105+
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1106+
hir::TypeBindingKind::Equality { term: err_ty.into() }
1107+
} else {
1108+
// Desugar `AssocTy: Bounds` into a type binding where the
1109+
// later desugars into a trait predicate.
1110+
let bounds = self.lower_param_bounds(bounds, itctx);
11571111

1158-
hir::TypeBindingKind::Constraint { bounds }
1159-
}
1160-
DesugarKind::Error(position) => {
1161-
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1162-
span: constraint.span,
1163-
position: DiagnosticArgFromDisplay(&position),
1164-
});
1165-
let err_ty =
1166-
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1167-
hir::TypeBindingKind::Equality { term: err_ty.into() }
1168-
}
1112+
hir::TypeBindingKind::Constraint { bounds }
11691113
}
11701114
}
11711115
};

compiler/rustc_codegen_llvm/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(hash_raw_entry)]
1414
#![feature(iter_intersperse)]
1515
#![feature(let_chains)]
16-
#![feature(min_specialization)]
1716
#![feature(impl_trait_in_assoc_type)]
1817

1918
#[macro_use]

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ libc = "0.2.50"
4848
[dependencies.object]
4949
version = "0.32.1"
5050
default-features = false
51-
features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write"]
51+
features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"]
5252

5353
[target.'cfg(windows)'.dependencies.windows]
5454
version = "0.48.0"

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ codegen_ssa_no_module_named =
190190
191191
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
192192
193+
codegen_ssa_no_saved_object_file = cached cgu {$cgu_name} should have an object file, but doesn't
194+
193195
codegen_ssa_processing_dymutil_failed = processing debug info with `dsymutil` failed: {$status}
194196
.note = {$output}
195197

compiler/rustc_codegen_ssa/src/back/metadata.rs

+68-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
1515
use rustc_metadata::creader::MetadataLoader;
1616
use rustc_metadata::fs::METADATA_FILENAME;
1717
use rustc_metadata::EncodedMetadata;
18+
use rustc_serialize::leb128;
1819
use rustc_session::Session;
1920
use rustc_span::sym;
2021
use rustc_target::abi::Endian;
@@ -420,10 +421,9 @@ pub enum MetadataPosition {
420421
/// it's not in an allowlist of otherwise well known dwarf section names to
421422
/// go into the final artifact.
422423
///
423-
/// * WebAssembly - we actually don't have any container format for this
424-
/// target. WebAssembly doesn't support the `dylib` crate type anyway so
425-
/// there's no need for us to support this at this time. Consequently the
426-
/// metadata bytes are simply stored as-is into an rlib.
424+
/// * WebAssembly - this uses wasm files themselves as the object file format
425+
/// so an empty file with no linking metadata but a single custom section is
426+
/// created holding our metadata.
427427
///
428428
/// * COFF - Windows-like targets create an object with a section that has
429429
/// the `IMAGE_SCN_LNK_REMOVE` flag set which ensures that if the linker
@@ -438,22 +438,13 @@ pub fn create_wrapper_file(
438438
data: &[u8],
439439
) -> (Vec<u8>, MetadataPosition) {
440440
let Some(mut file) = create_object_file(sess) else {
441-
// This is used to handle all "other" targets. This includes targets
442-
// in two categories:
443-
//
444-
// * Some targets don't have support in the `object` crate just yet
445-
// to write an object file. These targets are likely to get filled
446-
// out over time.
447-
//
448-
// * Targets like WebAssembly don't support dylibs, so the purpose
449-
// of putting metadata in object files, to support linking rlibs
450-
// into dylibs, is moot.
451-
//
452-
// In both of these cases it means that linking into dylibs will
453-
// not be supported by rustc. This doesn't matter for targets like
454-
// WebAssembly and for targets not supported by the `object` crate
455-
// yet it means that work will need to be done in the `object` crate
456-
// to add a case above.
441+
if sess.target.is_like_wasm {
442+
return (create_metadata_file_for_wasm(data, &section_name), MetadataPosition::First);
443+
}
444+
445+
// Targets using this branch don't have support implemented here yet or
446+
// they're not yet implemented in the `object` crate and will likely
447+
// fill out this module over time.
457448
return (data.to_vec(), MetadataPosition::Last);
458449
};
459450
let section = if file.format() == BinaryFormat::Xcoff {
@@ -532,6 +523,9 @@ pub fn create_compressed_metadata_file(
532523
packed_metadata.extend(metadata.raw_data());
533524

534525
let Some(mut file) = create_object_file(sess) else {
526+
if sess.target.is_like_wasm {
527+
return create_metadata_file_for_wasm(&packed_metadata, b".rustc");
528+
}
535529
return packed_metadata.to_vec();
536530
};
537531
if file.format() == BinaryFormat::Xcoff {
@@ -624,3 +618,57 @@ pub fn create_compressed_metadata_file_for_xcoff(
624618
file.append_section_data(section, data, 1);
625619
file.write().unwrap()
626620
}
621+
622+
/// Creates a simple WebAssembly object file, which is itself a wasm module,
623+
/// that contains a custom section of the name `section_name` with contents
624+
/// `data`.
625+
///
626+
/// NB: the `object` crate does not yet have support for writing the the wasm
627+
/// object file format. The format is simple enough that for now an extra crate
628+
/// from crates.io (such as `wasm-encoder`). The file format is:
629+
///
630+
/// * 4-byte header "\0asm"
631+
/// * 4-byte version number - 1u32 in little-endian format
632+
/// * concatenated sections, which for this object is always "custom sections"
633+
///
634+
/// Custom sections are then defined by:
635+
/// * 1-byte section identifier - 0 for a custom section
636+
/// * leb-encoded section length (size of the contents beneath this bullet)
637+
/// * leb-encoded custom section name length
638+
/// * custom section name
639+
/// * section contents
640+
///
641+
/// One custom section, `linking`, is added here in accordance with
642+
/// <https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md>
643+
/// which is required to inform LLD that this is an object file but it should
644+
/// otherwise basically ignore it if it otherwise looks at it. The linking
645+
/// section currently is defined by a single version byte (2) and then further
646+
/// sections, but we have no more sections, so it's just the byte "2".
647+
///
648+
/// The next custom section is the one we're interested in.
649+
pub fn create_metadata_file_for_wasm(data: &[u8], section_name: &[u8]) -> Vec<u8> {
650+
let mut bytes = b"\0asm\x01\0\0\0".to_vec();
651+
652+
let mut append_custom_section = |section_name: &[u8], data: &[u8]| {
653+
let mut section_name_len = [0; leb128::max_leb128_len::<usize>()];
654+
let off = leb128::write_usize_leb128(&mut section_name_len, section_name.len());
655+
let section_name_len = &section_name_len[..off];
656+
657+
let mut section_len = [0; leb128::max_leb128_len::<usize>()];
658+
let off = leb128::write_usize_leb128(
659+
&mut section_len,
660+
data.len() + section_name_len.len() + section_name.len(),
661+
);
662+
let section_len = &section_len[..off];
663+
664+
bytes.push(0u8);
665+
bytes.extend_from_slice(section_len);
666+
bytes.extend_from_slice(section_name_len);
667+
bytes.extend_from_slice(section_name);
668+
bytes.extend_from_slice(data);
669+
};
670+
671+
append_custom_section(b"linking", &[2]);
672+
append_custom_section(section_name, data);
673+
bytes
674+
}

compiler/rustc_codegen_ssa/src/back/write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
913913

914914
let object = load_from_incr_comp_dir(
915915
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
916-
module.source.saved_files.get("o").expect("no saved object file in work product"),
916+
module.source.saved_files.get("o").unwrap_or_else(|| {
917+
cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name })
918+
}),
917919
);
918920
let dwarf_object =
919921
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {

compiler/rustc_codegen_ssa/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ pub struct NoNatvisDirectory {
121121
pub error: Error,
122122
}
123123

124+
#[derive(Diagnostic)]
125+
#[diag(codegen_ssa_no_saved_object_file)]
126+
pub struct NoSavedObjectFile<'a> {
127+
pub cgu_name: &'a str,
128+
}
129+
124130
#[derive(Diagnostic)]
125131
#[diag(codegen_ssa_copy_path_buf)]
126132
pub struct CopyPathBuf {

0 commit comments

Comments
 (0)