Skip to content

Commit 07fef41

Browse files
committed
Auto merge of rust-lang#126771 - workingjubilee:rollup-wjof1kc, r=workingjubilee
Rollup of 9 pull requests Successful merges: - rust-lang#124101 (Add PidFd::{kill, wait, try_wait}) - rust-lang#126125 (Improve conflict marker recovery) - rust-lang#126481 (Add `powerpc-unknown-openbsd` maintaince status) - rust-lang#126613 (Print the tested value in int_log tests) - rust-lang#126617 (Expand `avx512_target_feature` to include VEX variants) - rust-lang#126707 (Pass target to inaccessible-temp-dir rmake test) - rust-lang#126712 (Migrate `relocation-model`, `error-writing-dependencies` and `crate-name-priority` `run-make` tests to rmake) - rust-lang#126757 (Properly gate `safe` keyword in pre-expansion) - rust-lang#126758 (Do not allow safe/unsafe on static and fn items) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a9c8887 + ff05860 commit 07fef41

Some content is hidden

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

49 files changed

+732
-314
lines changed

compiler/rustc_ast_passes/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetim
3030
3131
ast_passes_bad_c_variadic = only foreign or `unsafe extern "C"` functions may be C-variadic
3232
33+
ast_passes_bare_fn_invalid_safety = function pointers cannot be declared with `safe` safety qualifier
34+
.suggestion = remove safe from this item
35+
3336
ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block
3437
.cannot_have = cannot have a body
3538
.invalid = the invalid body
@@ -167,6 +170,9 @@ ast_passes_invalid_unnamed_field_ty =
167170
unnamed fields can only have struct or union types
168171
.label = not a struct or union
169172
173+
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
174+
.suggestion = remove safe from this item
175+
170176
ast_passes_item_underscore = `{$kind}` items in this context need a name
171177
.label = `_` is not a valid name for this `{$kind}` item
172178

compiler/rustc_ast_passes/src/ast_validation.rs

+38-16
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,29 @@ impl<'a> AstValidator<'a> {
456456
}
457457
}
458458

459-
fn check_foreign_item_safety(&self, item_span: Span, safety: Safety) {
460-
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
461-
&& (self.extern_mod_safety == Some(Safety::Default)
462-
|| !self.features.unsafe_extern_blocks)
463-
{
464-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
465-
item_span,
466-
block: self.current_extern_span(),
467-
});
459+
fn check_item_safety(&self, span: Span, safety: Safety) {
460+
match self.extern_mod_safety {
461+
Some(extern_safety) => {
462+
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
463+
&& (extern_safety == Safety::Default || !self.features.unsafe_extern_blocks)
464+
{
465+
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
466+
item_span: span,
467+
block: self.current_extern_span(),
468+
});
469+
}
470+
}
471+
None => {
472+
if matches!(safety, Safety::Safe(_)) {
473+
self.dcx().emit_err(errors::InvalidSafetyOnItem { span });
474+
}
475+
}
476+
}
477+
}
478+
479+
fn check_bare_fn_safety(&self, span: Span, safety: Safety) {
480+
if matches!(safety, Safety::Safe(_)) {
481+
self.dcx().emit_err(errors::InvalidSafetyOnBareFn { span });
468482
}
469483
}
470484

@@ -746,6 +760,7 @@ impl<'a> AstValidator<'a> {
746760
fn visit_ty_common(&mut self, ty: &'a Ty) {
747761
match &ty.kind {
748762
TyKind::BareFn(bfty) => {
763+
self.check_bare_fn_safety(bfty.decl_span, bfty.safety);
749764
self.check_fn_decl(&bfty.decl, SelfSemantic::No);
750765
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
751766
self.dcx().emit_err(errors::PatternFnPointer { span });
@@ -1174,11 +1189,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11741189
});
11751190
}
11761191
}
1177-
ItemKind::Static(box StaticItem { expr: None, .. }) => {
1178-
self.dcx().emit_err(errors::StaticWithoutBody {
1179-
span: item.span,
1180-
replace_span: self.ending_semi_or_hi(item.span),
1181-
});
1192+
ItemKind::Static(box StaticItem { expr, safety, .. }) => {
1193+
self.check_item_safety(item.span, *safety);
1194+
1195+
if expr.is_none() {
1196+
self.dcx().emit_err(errors::StaticWithoutBody {
1197+
span: item.span,
1198+
replace_span: self.ending_semi_or_hi(item.span),
1199+
});
1200+
}
11821201
}
11831202
ItemKind::TyAlias(
11841203
ty_alias @ box TyAlias { defaultness, bounds, where_clauses, ty, .. },
@@ -1212,7 +1231,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12121231
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
12131232
match &fi.kind {
12141233
ForeignItemKind::Fn(box Fn { defaultness, sig, body, .. }) => {
1215-
self.check_foreign_item_safety(fi.span, sig.header.safety);
12161234
self.check_defaultness(fi.span, *defaultness);
12171235
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
12181236
self.check_foreign_fn_headerless(sig.header);
@@ -1233,7 +1251,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12331251
self.check_foreign_item_ascii_only(fi.ident);
12341252
}
12351253
ForeignItemKind::Static(box StaticForeignItem { expr, safety, .. }) => {
1236-
self.check_foreign_item_safety(fi.span, *safety);
1254+
self.check_item_safety(fi.span, *safety);
12371255
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|b| b.span));
12381256
self.check_foreign_item_ascii_only(fi.ident);
12391257
}
@@ -1453,6 +1471,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14531471
};
14541472
self.check_fn_decl(fk.decl(), self_semantic);
14551473

1474+
if let Some(&FnHeader { safety, .. }) = fk.header() {
1475+
self.check_item_safety(span, safety);
1476+
}
1477+
14561478
self.check_c_variadic_type(fk);
14571479

14581480
// Functions cannot both be `const async` or `const gen`

compiler/rustc_ast_passes/src/errors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ pub struct InvalidSafetyOnExtern {
225225
pub block: Span,
226226
}
227227

228+
#[derive(Diagnostic)]
229+
#[diag(ast_passes_item_invalid_safety)]
230+
pub struct InvalidSafetyOnItem {
231+
#[primary_span]
232+
pub span: Span,
233+
}
234+
235+
#[derive(Diagnostic)]
236+
#[diag(ast_passes_bare_fn_invalid_safety)]
237+
pub struct InvalidSafetyOnBareFn {
238+
#[primary_span]
239+
pub span: Span,
240+
}
241+
228242
#[derive(Diagnostic)]
229243
#[diag(ast_passes_bound_in_context)]
230244
pub struct BoundInContext<'a> {

compiler/rustc_ast_passes/src/feature_gate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
562562
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
563563
gate_all!(global_registration, "global registration is experimental");
564564
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
565+
gate_all!(
566+
unsafe_extern_blocks,
567+
"`unsafe extern {}` blocks and `safe` keyword are experimental"
568+
);
565569

566570
if !visitor.features.never_patterns {
567571
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_parse/src/parser/diagnostics.rs

+42-16
Original file line numberDiff line numberDiff line change
@@ -2965,9 +2965,10 @@ impl<'a> Parser<'a> {
29652965

29662966
/// This checks if this is a conflict marker, depending of the parameter passed.
29672967
///
2968-
/// * `>>>>>`
2969-
/// * `=====`
2970-
/// * `<<<<<`
2968+
/// * `<<<<<<<`
2969+
/// * `|||||||`
2970+
/// * `=======`
2971+
/// * `>>>>>>>`
29712972
///
29722973
pub(super) fn is_vcs_conflict_marker(
29732974
&mut self,
@@ -2997,14 +2998,18 @@ impl<'a> Parser<'a> {
29972998
}
29982999

29993000
pub(crate) fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()> {
3001+
// <<<<<<<
30003002
let Some(start) = self.conflict_marker(&TokenKind::BinOp(token::Shl), &TokenKind::Lt)
30013003
else {
30023004
return Ok(());
30033005
};
30043006
let mut spans = Vec::with_capacity(3);
30053007
spans.push(start);
3008+
// |||||||
30063009
let mut middlediff3 = None;
3010+
// =======
30073011
let mut middle = None;
3012+
// >>>>>>>
30083013
let mut end = None;
30093014
loop {
30103015
if self.token.kind == TokenKind::Eof {
@@ -3025,29 +3030,50 @@ impl<'a> Parser<'a> {
30253030
}
30263031
self.bump();
30273032
}
3033+
30283034
let mut err = self.dcx().struct_span_err(spans, "encountered diff marker");
3029-
err.span_label(start, "after this is the code before the merge");
3030-
if let Some(middle) = middlediff3 {
3031-
err.span_label(middle, "");
3032-
}
3035+
match middlediff3 {
3036+
// We're using diff3
3037+
Some(middlediff3) => {
3038+
err.span_label(
3039+
start,
3040+
"between this marker and `|||||||` is the code that we're merging into",
3041+
);
3042+
err.span_label(middlediff3, "between this marker and `=======` is the base code (what the two refs diverged from)");
3043+
}
3044+
None => {
3045+
err.span_label(
3046+
start,
3047+
"between this marker and `=======` is the code that we're merging into",
3048+
);
3049+
}
3050+
};
3051+
30333052
if let Some(middle) = middle {
3034-
err.span_label(middle, "");
3053+
err.span_label(middle, "between this marker and `>>>>>>>` is the incoming code");
30353054
}
30363055
if let Some(end) = end {
3037-
err.span_label(end, "above this are the incoming code changes");
3056+
err.span_label(end, "this marker concludes the conflict region");
30383057
}
3039-
err.help(
3040-
"if you're having merge conflicts after pulling new code, the top section is the code \
3041-
you already had and the bottom section is the remote code",
3058+
err.note(
3059+
"conflict markers indicate that a merge was started but could not be completed due \
3060+
to merge conflicts\n\
3061+
to resolve a conflict, keep only the code you want and then delete the lines \
3062+
containing conflict markers",
30423063
);
30433064
err.help(
3044-
"if you're in the middle of a rebase, the top section is the code being rebased onto \
3045-
and the bottom section is the code coming from the current commit being rebased",
3065+
"if you're having merge conflicts after pulling new code:\n\
3066+
the top section is the code you already had and the bottom section is the remote code\n\
3067+
if you're in the middle of a rebase:\n\
3068+
the top section is the code being rebased onto and the bottom section is the code \
3069+
coming from the current commit being rebased",
30463070
);
3071+
30473072
err.note(
3048-
"for an explanation on these markers from the `git` documentation, visit \
3049-
<https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
3073+
"for an explanation on these markers from the `git` documentation:\n\
3074+
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>",
30503075
);
3076+
30513077
Err(err)
30523078
}
30533079

compiler/rustc_parse/src/parser/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,9 @@ impl<'a> Parser<'a> {
12141214
if self.eat_keyword_case(kw::Unsafe, case) {
12151215
Safety::Unsafe(self.prev_token.uninterpolated_span())
12161216
} else if self.eat_keyword_case(kw::Safe, case) {
1217+
self.psess
1218+
.gated_spans
1219+
.gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span());
12171220
Safety::Safe(self.prev_token.uninterpolated_span())
12181221
} else {
12191222
Safety::Default

compiler/rustc_target/src/target_features.rs

+5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability)] = &[
208208
("avx512vnni", Unstable(sym::avx512_target_feature)),
209209
("avx512vp2intersect", Unstable(sym::avx512_target_feature)),
210210
("avx512vpopcntdq", Unstable(sym::avx512_target_feature)),
211+
("avxifma", Unstable(sym::avx512_target_feature)),
212+
("avxneconvert", Unstable(sym::avx512_target_feature)),
213+
("avxvnni", Unstable(sym::avx512_target_feature)),
214+
("avxvnniint16", Unstable(sym::avx512_target_feature)),
215+
("avxvnniint8", Unstable(sym::avx512_target_feature)),
211216
("bmi1", Stable),
212217
("bmi2", Stable),
213218
("cmpxchg16b", Stable),

library/core/tests/num/int_log.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ fn checked_ilog() {
2424

2525
#[cfg(not(miri))] // Miri is too slow
2626
for i in i16::MIN..=0 {
27-
assert_eq!(i.checked_ilog(4), None);
27+
assert_eq!(i.checked_ilog(4), None, "checking {i}");
2828
}
2929
#[cfg(not(miri))] // Miri is too slow
3030
for i in 1..=i16::MAX {
31-
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32));
31+
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32), "checking {i}");
3232
}
3333
#[cfg(not(miri))] // Miri is too slow
3434
for i in 1..=u16::MAX {
35-
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32));
35+
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32), "checking {i}");
3636
}
3737
}
3838

@@ -49,30 +49,30 @@ fn checked_ilog2() {
4949
assert_eq!(0i16.checked_ilog2(), None);
5050

5151
for i in 1..=u8::MAX {
52-
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32));
52+
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
5353
}
5454
#[cfg(not(miri))] // Miri is too slow
5555
for i in 1..=u16::MAX {
5656
// Guard against Android's imprecise f32::ilog2 implementation.
5757
if i != 8192 && i != 32768 {
58-
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32));
58+
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
5959
}
6060
}
6161
for i in i8::MIN..=0 {
62-
assert_eq!(i.checked_ilog2(), None);
62+
assert_eq!(i.checked_ilog2(), None, "checking {i}");
6363
}
6464
for i in 1..=i8::MAX {
65-
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32));
65+
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
6666
}
6767
#[cfg(not(miri))] // Miri is too slow
6868
for i in i16::MIN..=0 {
69-
assert_eq!(i.checked_ilog2(), None);
69+
assert_eq!(i.checked_ilog2(), None, "checking {i}");
7070
}
7171
#[cfg(not(miri))] // Miri is too slow
7272
for i in 1..=i16::MAX {
7373
// Guard against Android's imprecise f32::ilog2 implementation.
7474
if i != 8192 {
75-
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32));
75+
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
7676
}
7777
}
7878
}
@@ -95,19 +95,19 @@ fn checked_ilog10() {
9595

9696
#[cfg(not(miri))] // Miri is too slow
9797
for i in i16::MIN..=0 {
98-
assert_eq!(i.checked_ilog10(), None);
98+
assert_eq!(i.checked_ilog10(), None, "checking {i}");
9999
}
100100
#[cfg(not(miri))] // Miri is too slow
101101
for i in 1..=i16::MAX {
102-
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32));
102+
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
103103
}
104104
#[cfg(not(miri))] // Miri is too slow
105105
for i in 1..=u16::MAX {
106-
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32));
106+
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
107107
}
108108
#[cfg(not(miri))] // Miri is too slow
109109
for i in 1..=100_000u32 {
110-
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32));
110+
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
111111
}
112112
}
113113

0 commit comments

Comments
 (0)