Skip to content

Commit ecd3dba

Browse files
committed
Auto merge of #111380 - Dylan-DPC:rollup-xiptbhn, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #110304 (Add GNU Property Note) - #110504 (Tweak borrow suggestion span) - #110583 (tweak "make mut" spans when assigning to locals) - #110694 (Implement builtin # syntax and use it for offset_of!(...)) - #111120 (Suggest let for possible binding with ty) - #111252 (Min specialization improvements) - #111361 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7e7483d + 9d913eb commit ecd3dba

File tree

134 files changed

+1739
-919
lines changed

Some content is hidden

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

134 files changed

+1739
-919
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
603603
gate_all!(yeet_expr, "`do yeet` expression is experimental");
604604
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
605605
gate_all!(const_closures, "const closures are experimental");
606+
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
606607

607608
if !visitor.features.negative_bounds {
608609
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ impl<'a> State<'a> {
556556
self.pclose();
557557
}
558558
ast::ExprKind::OffsetOf(container, fields) => {
559-
// FIXME: This should have its own syntax, distinct from a macro invocation.
560-
self.word("offset_of!");
559+
self.word("builtin # offset_of");
561560
self.popen();
562561
self.rbox(0, Inconsistent);
563562
self.print_type(container);

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+264-245
Large diffs are not rendered by default.

compiler/rustc_builtin_macros/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ builtin_macros_format_pos_mismatch = {$n} positional {$n ->
150150
*[more] arguments
151151
} in format string, but {$desc}
152152
153-
builtin_macros_offset_of_expected_field = expected field
154-
155-
builtin_macros_offset_of_expected_two_args = expected 2 arguments
156-
157153
builtin_macros_test_case_non_item = `#[test_case]` attribute is only allowed on items
158154
159155
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests

compiler/rustc_builtin_macros/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ mod format;
4444
mod format_foreign;
4545
mod global_allocator;
4646
mod log_syntax;
47-
mod offset_of;
4847
mod source_util;
4948
mod test;
5049
mod trace_macros;
@@ -92,7 +91,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
9291
line: source_util::expand_line,
9392
log_syntax: log_syntax::expand_log_syntax,
9493
module_path: source_util::expand_mod,
95-
offset_of: offset_of::expand_offset_of,
9694
option_env: env::expand_option_env,
9795
core_panic: edition_panic::expand_panic,
9896
std_panic: edition_panic::expand_panic,

compiler/rustc_builtin_macros/src/offset_of.rs

-99
This file was deleted.

compiler/rustc_codegen_ssa/src/back/metadata.rs

+50
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use object::{
1212

1313
use snap::write::FrameEncoder;
1414

15+
use object::elf::NT_GNU_PROPERTY_TYPE_0;
1516
use rustc_data_structures::memmap::Mmap;
1617
use rustc_data_structures::owned_slice::try_slice_owned;
1718
use rustc_data_structures::sync::MetadataRef;
@@ -93,6 +94,54 @@ pub(super) fn search_for_section<'a>(
9394
.map_err(|e| format!("failed to read {} section in '{}': {}", section, path.display(), e))
9495
}
9596

97+
fn add_gnu_property_note(
98+
file: &mut write::Object<'static>,
99+
architecture: Architecture,
100+
binary_format: BinaryFormat,
101+
endianness: Endianness,
102+
) {
103+
// check bti protection
104+
if binary_format != BinaryFormat::Elf
105+
|| !matches!(architecture, Architecture::X86_64 | Architecture::Aarch64)
106+
{
107+
return;
108+
}
109+
110+
let section = file.add_section(
111+
file.segment_name(StandardSegment::Data).to_vec(),
112+
b".note.gnu.property".to_vec(),
113+
SectionKind::Note,
114+
);
115+
let mut data: Vec<u8> = Vec::new();
116+
let n_namsz: u32 = 4; // Size of the n_name field
117+
let n_descsz: u32 = 16; // Size of the n_desc field
118+
let n_type: u32 = NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
119+
let header_values = [n_namsz, n_descsz, n_type];
120+
header_values.iter().for_each(|v| {
121+
data.extend_from_slice(&match endianness {
122+
Endianness::Little => v.to_le_bytes(),
123+
Endianness::Big => v.to_be_bytes(),
124+
})
125+
});
126+
data.extend_from_slice(b"GNU\0"); // Owner of the program property note
127+
let pr_type: u32 = match architecture {
128+
Architecture::X86_64 => 0xc0000002,
129+
Architecture::Aarch64 => 0xc0000000,
130+
_ => unreachable!(),
131+
};
132+
let pr_datasz: u32 = 4; //size of the pr_data field
133+
let pr_data: u32 = 3; //program property descriptor
134+
let pr_padding: u32 = 0;
135+
let property_values = [pr_type, pr_datasz, pr_data, pr_padding];
136+
property_values.iter().for_each(|v| {
137+
data.extend_from_slice(&match endianness {
138+
Endianness::Little => v.to_le_bytes(),
139+
Endianness::Big => v.to_be_bytes(),
140+
})
141+
});
142+
file.append_section_data(section, &data, 8);
143+
}
144+
96145
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
97146
let endianness = match sess.target.options.endian {
98147
Endian::Little => Endianness::Little,
@@ -205,6 +254,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
205254
_ => elf::ELFOSABI_NONE,
206255
};
207256
let abi_version = 0;
257+
add_gnu_property_note(&mut file, architecture, binary_format, endianness);
208258
file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
209259
Some(file)
210260
}

compiler/rustc_data_structures/src/owned_slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ impl Borrow<[u8]> for OwnedSlice {
109109
}
110110

111111
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Send`
112+
#[cfg(parallel_compiler)]
112113
unsafe impl Send for OwnedSlice {}
113114

114115
// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Sync`
116+
#[cfg(parallel_compiler)]
115117
unsafe impl Sync for OwnedSlice {}
116118

117119
#[cfg(test)]

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ declare_features! (
313313
(active, async_closure, "1.37.0", Some(62290), None),
314314
/// Allows async functions to be declared, implemented, and used in traits.
315315
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
316+
/// Allows builtin # foo() syntax
317+
(active, builtin_syntax, "CURRENT_RUSTC_VERSION", Some(110680), None),
316318
/// Allows `c"foo"` literals.
317319
(active, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
318320
/// Treat `extern "C"` function as nounwind.

compiler/rustc_hir_analysis/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ hir_analysis_specialization_trait = implementing `rustc_specialization_trait` tr
279279
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
280280
.label = `for<...>` is here
281281
282+
hir_analysis_empty_specialization = specialization impl does not specialize any associated items
283+
.note = impl is a specialization of this impl
284+
282285
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
283286
284287
hir_analysis_static_specialize = cannot specialize on `'static` lifetime

compiler/rustc_hir_analysis/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,15 @@ pub(crate) struct ClosureImplicitHrtb {
814814
pub for_sp: Span,
815815
}
816816

817+
#[derive(Diagnostic)]
818+
#[diag(hir_analysis_empty_specialization)]
819+
pub(crate) struct EmptySpecialization {
820+
#[primary_span]
821+
pub span: Span,
822+
#[note]
823+
pub base_impl_span: Span,
824+
}
825+
817826
#[derive(Diagnostic)]
818827
#[diag(hir_analysis_const_specialize)]
819828
pub(crate) struct ConstSpecialize {

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
8080
use rustc_span::Span;
8181
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
8282
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
83-
use rustc_trait_selection::traits::{self, translate_substs, wf, ObligationCtxt};
83+
use rustc_trait_selection::traits::{self, translate_substs_with_cause, wf, ObligationCtxt};
8484

8585
pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) {
8686
if let Some(node) = parent_specialization_node(tcx, impl_def_id) {
@@ -100,12 +100,19 @@ fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Opti
100100
// Implementing a normal trait isn't a specialization.
101101
return None;
102102
}
103+
if trait_def.is_marker {
104+
// Overlapping marker implementations are not really specializations.
105+
return None;
106+
}
103107
Some(impl2_node)
104108
}
105109

106110
/// Check that `impl1` is a sound specialization
107111
#[instrument(level = "debug", skip(tcx))]
108112
fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node) {
113+
let span = tcx.def_span(impl1_def_id);
114+
check_has_items(tcx, impl1_def_id, impl2_node, span);
115+
109116
if let Some((impl1_substs, impl2_substs)) = get_impl_substs(tcx, impl1_def_id, impl2_node) {
110117
let impl2_def_id = impl2_node.def_id();
111118
debug!(?impl2_def_id, ?impl2_substs);
@@ -116,14 +123,20 @@ fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node
116123
unconstrained_parent_impl_substs(tcx, impl2_def_id, impl2_substs)
117124
};
118125

119-
let span = tcx.def_span(impl1_def_id);
120126
check_constness(tcx, impl1_def_id, impl2_node, span);
121127
check_static_lifetimes(tcx, &parent_substs, span);
122128
check_duplicate_params(tcx, impl1_substs, &parent_substs, span);
123129
check_predicates(tcx, impl1_def_id, impl1_substs, impl2_node, impl2_substs, span);
124130
}
125131
}
126132

133+
fn check_has_items(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node, span: Span) {
134+
if let Node::Impl(impl2_id) = impl2_node && tcx.associated_item_def_ids(impl1_def_id).is_empty() {
135+
let base_impl_span = tcx.def_span(impl2_id);
136+
tcx.sess.emit_err(errors::EmptySpecialization { span, base_impl_span });
137+
}
138+
}
139+
127140
/// Check that the specializing impl `impl1` is at least as const as the base
128141
/// impl `impl2`
129142
fn check_constness(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node, span: Span) {
@@ -167,8 +180,21 @@ fn get_impl_substs(
167180
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
168181

169182
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id);
170-
let impl2_substs =
171-
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
183+
let impl1_span = tcx.def_span(impl1_def_id);
184+
let impl2_substs = translate_substs_with_cause(
185+
infcx,
186+
param_env,
187+
impl1_def_id.to_def_id(),
188+
impl1_substs,
189+
impl2_node,
190+
|_, span| {
191+
traits::ObligationCause::new(
192+
impl1_span,
193+
impl1_def_id,
194+
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span),
195+
)
196+
},
197+
);
172198

173199
let errors = ocx.select_all_or_error();
174200
if !errors.is_empty() {

0 commit comments

Comments
 (0)