Skip to content

Commit cacd19d

Browse files
committed
Auto merge of #128608 - tgross35:rollup-kibt0o5, r=tgross35
Rollup of 6 pull requests Successful merges: - #127095 (Migrate `reproducible-build-2` and `stable-symbol-names` `run-make` tests to rmake) - #127921 (Stabilize unsafe extern blocks (RFC 3484)) - #128466 (Update the stdarch submodule) - #128530 (Implement `UncheckedIterator` directly for `RepeatN`) - #128581 (Assert that all attributes are actually checked via `CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes) - #128603 (Update run-make/used to use `any_symbol_contains`) Failed merges: - #128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake) r? `@ghost` `@rustbot` modify labels: rollup
2 parents edc4dc3 + 74cc27f commit cacd19d

File tree

60 files changed

+365
-288
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

+365
-288
lines changed

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+12-30
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,6 @@ impl<'a> AstValidator<'a> {
453453
item_span: span,
454454
block: Some(self.current_extern_span().shrink_to_lo()),
455455
});
456-
} else if !self.features.unsafe_extern_blocks {
457-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
458-
item_span: span,
459-
block: None,
460-
});
461456
}
462457
}
463458
}
@@ -1054,32 +1049,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10541049
errors::VisibilityNotPermittedNote::IndividualForeignItems,
10551050
);
10561051

1057-
if this.features.unsafe_extern_blocks {
1058-
if &Safety::Default == safety {
1059-
if item.span.at_least_rust_2024() {
1060-
this.dcx()
1061-
.emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1062-
} else {
1063-
this.lint_buffer.buffer_lint(
1064-
MISSING_UNSAFE_ON_EXTERN,
1065-
item.id,
1066-
item.span,
1067-
BuiltinLintDiag::MissingUnsafeOnExtern {
1068-
suggestion: item.span.shrink_to_lo(),
1069-
},
1070-
);
1071-
}
1052+
if &Safety::Default == safety {
1053+
if item.span.at_least_rust_2024() {
1054+
this.dcx().emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1055+
} else {
1056+
this.lint_buffer.buffer_lint(
1057+
MISSING_UNSAFE_ON_EXTERN,
1058+
item.id,
1059+
item.span,
1060+
BuiltinLintDiag::MissingUnsafeOnExtern {
1061+
suggestion: item.span.shrink_to_lo(),
1062+
},
1063+
);
10721064
}
1073-
} else if let &Safety::Unsafe(span) = safety {
1074-
let mut diag = this
1075-
.dcx()
1076-
.create_err(errors::UnsafeItem { span, kind: "extern block" });
1077-
rustc_session::parse::add_feature_diagnostics(
1078-
&mut diag,
1079-
self.session,
1080-
sym::unsafe_extern_blocks,
1081-
);
1082-
diag.emit();
10831065
}
10841066

10851067
if abi.is_none() {

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

-4
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
560560
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
561561
gate_all!(global_registration, "global registration is experimental");
562562
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
563-
gate_all!(
564-
unsafe_extern_blocks,
565-
"`unsafe extern {}` blocks and `safe` keyword are experimental"
566-
);
567563
gate_all!(return_type_notation, "return type notation is experimental");
568564

569565
if !visitor.features.never_patterns {

Diff for: compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ declare_features! (
390390
(accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208)),
391391
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
392392
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668)),
393+
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
394+
(accepted, unsafe_extern_blocks, "CURRENT_RUSTC_VERSION", Some(123743)),
393395
/// Allows importing and reexporting macros with `use`,
394396
/// enables macro modularization in general.
395397
(accepted, use_extern_macros, "1.30.0", Some(35896)),

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -703,21 +703,21 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
703703
EncodeCrossCrate::No, allocator_internals, experimental!(needs_allocator),
704704
),
705705
gated!(
706-
panic_runtime, Normal, template!(Word), WarnFollowing,
706+
panic_runtime, CrateLevel, template!(Word), WarnFollowing,
707707
EncodeCrossCrate::No, experimental!(panic_runtime)
708708
),
709709
gated!(
710-
needs_panic_runtime, Normal, template!(Word), WarnFollowing,
710+
needs_panic_runtime, CrateLevel, template!(Word), WarnFollowing,
711711
EncodeCrossCrate::No, experimental!(needs_panic_runtime)
712712
),
713713
gated!(
714-
compiler_builtins, Normal, template!(Word), WarnFollowing,
714+
compiler_builtins, CrateLevel, template!(Word), WarnFollowing,
715715
EncodeCrossCrate::No,
716716
"the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
717717
which contains compiler-rt intrinsics and will never be stable",
718718
),
719719
gated!(
720-
profiler_runtime, Normal, template!(Word), WarnFollowing,
720+
profiler_runtime, CrateLevel, template!(Word), WarnFollowing,
721721
EncodeCrossCrate::No,
722722
"the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
723723
which contains the profiler runtime and will never be stable",

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,6 @@ declare_features! (
631631
(incomplete, unnamed_fields, "1.74.0", Some(49804)),
632632
/// Allows unsafe attributes.
633633
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
634-
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
635-
(unstable, unsafe_extern_blocks, "1.80.0", Some(123743)),
636634
/// Allows const generic parameters to be defined with types that
637635
/// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
638636
(incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),

Diff for: compiler/rustc_lint_defs/src/builtin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,6 @@ declare_lint! {
49344934
/// ### Example
49354935
///
49364936
/// ```rust
4937-
/// #![feature(unsafe_extern_blocks)]
49384937
/// #![warn(missing_unsafe_on_extern)]
49394938
/// #![allow(dead_code)]
49404939
///

Diff for: compiler/rustc_parse/src/parser/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1250,9 +1250,6 @@ impl<'a> Parser<'a> {
12501250
if self.eat_keyword_case(kw::Unsafe, case) {
12511251
Safety::Unsafe(self.prev_token.uninterpolated_span())
12521252
} else if self.eat_keyword_case(kw::Safe, case) {
1253-
self.psess
1254-
.gated_spans
1255-
.gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span());
12561253
Safety::Safe(self.prev_token.uninterpolated_span())
12571254
} else {
12581255
Safety::Default

Diff for: compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ passes_continue_labeled_block =
100100
.label = labeled blocks cannot be `continue`'d
101101
.block_label = labeled block the `continue` points to
102102
103+
passes_coroutine_on_non_closure =
104+
attribute should be applied to closures
105+
.label = not a closure
106+
103107
passes_coverage_not_fn_or_closure =
104108
attribute should be applied to a function definition or closure
105109
.label = not a function or closure

Diff for: compiler/rustc_passes/src/check_attr.rs

+64-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ use rustc_hir::{
2020
TraitItem, CRATE_HIR_ID, CRATE_OWNER_ID,
2121
};
2222
use rustc_macros::LintDiagnostic;
23-
use rustc_middle::bug;
2423
use rustc_middle::hir::nested_filter;
2524
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
2625
use rustc_middle::query::Providers;
2726
use rustc_middle::traits::ObligationCause;
2827
use rustc_middle::ty::error::{ExpectedFound, TypeError};
2928
use rustc_middle::ty::{self, TyCtxt};
29+
use rustc_middle::{bug, span_bug};
3030
use rustc_session::lint::builtin::{
3131
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
3232
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
@@ -239,7 +239,59 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
239239
self.check_generic_attr(hir_id, attr, target, Target::Fn);
240240
self.check_proc_macro(hir_id, target, ProcMacroKind::Derive)
241241
}
242-
_ => {}
242+
[sym::coroutine] => {
243+
self.check_coroutine(attr, target);
244+
}
245+
[
246+
// ok
247+
sym::allow
248+
| sym::expect
249+
| sym::warn
250+
| sym::deny
251+
| sym::forbid
252+
| sym::cfg
253+
// need to be fixed
254+
| sym::cfi_encoding // FIXME(cfi_encoding)
255+
| sym::may_dangle // FIXME(dropck_eyepatch)
256+
| sym::pointee // FIXME(derive_smart_pointer)
257+
| sym::linkage // FIXME(linkage)
258+
| sym::no_sanitize // FIXME(no_sanitize)
259+
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
260+
| sym::used // handled elsewhere to restrict to static items
261+
| sym::repr // handled elsewhere to restrict to type decls items
262+
| sym::instruction_set // broken on stable!!!
263+
| sym::windows_subsystem // broken on stable!!!
264+
| sym::patchable_function_entry // FIXME(patchable_function_entry)
265+
| sym::deprecated_safe // FIXME(deprecated_safe)
266+
// internal
267+
| sym::prelude_import
268+
| sym::panic_handler
269+
| sym::allow_internal_unsafe
270+
| sym::fundamental
271+
| sym::lang
272+
| sym::needs_allocator
273+
| sym::default_lib_allocator
274+
| sym::start
275+
| sym::custom_mir,
276+
] => {}
277+
[name, ..] => {
278+
match BUILTIN_ATTRIBUTE_MAP.get(name) {
279+
// checked below
280+
Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
281+
Some(_) => {
282+
// FIXME: differentiate between unstable and internal attributes just like we do with features instead
283+
// of just accepting `rustc_` attributes by name. That should allow trimming the above list, too.
284+
if !name.as_str().starts_with("rustc_") {
285+
span_bug!(
286+
attr.span,
287+
"builtin attribute {name:?} not handled by `CheckAttrVisitor`"
288+
)
289+
}
290+
}
291+
None => (),
292+
}
293+
}
294+
[] => unreachable!(),
243295
}
244296

245297
let builtin = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
@@ -376,6 +428,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
376428

377429
/// Checks that `#[optimize(..)]` is applied to a function/closure/method,
378430
/// or to an impl block or module.
431+
// FIXME(#128488): this should probably be elevated to an error?
379432
fn check_optimize(&self, hir_id: HirId, attr: &Attribute, target: Target) {
380433
match target {
381434
Target::Fn
@@ -2279,6 +2332,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22792332
self.abort.set(true);
22802333
}
22812334
}
2335+
2336+
fn check_coroutine(&self, attr: &Attribute, target: Target) {
2337+
match target {
2338+
Target::Closure => return,
2339+
_ => {
2340+
self.dcx().emit_err(errors::CoroutineOnNonClosure { span: attr.span });
2341+
}
2342+
}
2343+
}
22822344
}
22832345

22842346
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

Diff for: compiler/rustc_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,13 @@ pub struct Confusables {
636636
pub attr_span: Span,
637637
}
638638

639+
#[derive(Diagnostic)]
640+
#[diag(passes_coroutine_on_non_closure)]
641+
pub struct CoroutineOnNonClosure {
642+
#[primary_span]
643+
pub span: Span,
644+
}
645+
639646
#[derive(Diagnostic)]
640647
#[diag(passes_empty_confusables)]
641648
pub(crate) struct EmptyConfusables {

Diff for: library/core/src/iter/sources/repeat_n.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,12 @@ impl<A: Clone> Iterator for RepeatN<A> {
114114

115115
#[inline]
116116
fn next(&mut self) -> Option<A> {
117-
if self.count == 0 {
118-
return None;
119-
}
120-
121-
self.count -= 1;
122-
Some(if self.count == 0 {
123-
// SAFETY: the check above ensured that the count used to be non-zero,
124-
// so element hasn't been dropped yet, and we just lowered the count to
125-
// zero so it won't be dropped later, and thus it's okay to take it here.
126-
unsafe { ManuallyDrop::take(&mut self.element) }
117+
if self.count > 0 {
118+
// SAFETY: Just checked it's not empty
119+
unsafe { Some(self.next_unchecked()) }
127120
} else {
128-
A::clone(&self.element)
129-
})
121+
None
122+
}
130123
}
131124

132125
#[inline]
@@ -194,4 +187,18 @@ impl<A: Clone> FusedIterator for RepeatN<A> {}
194187
#[unstable(feature = "trusted_len", issue = "37572")]
195188
unsafe impl<A: Clone> TrustedLen for RepeatN<A> {}
196189
#[unstable(feature = "trusted_len_next_unchecked", issue = "37572")]
197-
impl<A: Clone> UncheckedIterator for RepeatN<A> {}
190+
impl<A: Clone> UncheckedIterator for RepeatN<A> {
191+
#[inline]
192+
unsafe fn next_unchecked(&mut self) -> Self::Item {
193+
// SAFETY: The caller promised the iterator isn't empty
194+
self.count = unsafe { self.count.unchecked_sub(1) };
195+
if self.count == 0 {
196+
// SAFETY: the check above ensured that the count used to be non-zero,
197+
// so element hasn't been dropped yet, and we just lowered the count to
198+
// zero so it won't be dropped later, and thus it's okay to take it here.
199+
unsafe { ManuallyDrop::take(&mut self.element) }
200+
} else {
201+
A::clone(&self.element)
202+
}
203+
}
204+
}

Diff for: library/stdarch

Submodule stdarch updated 93 files

Diff for: src/tools/run-make-support/src/external_deps/llvm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ impl LlvmReadobj {
151151
self
152152
}
153153

154-
/// Pass `--symbols` to display the symbol.
154+
/// Pass `--symbols` to display the symbol table, including both local
155+
/// and global symbols.
155156
pub fn symbols(&mut self) -> &mut Self {
156157
self.cmd.arg("--symbols");
157158
self

Diff for: src/tools/run-make-support/src/fs.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
99
if link.as_ref().exists() {
1010
std::fs::remove_dir(link.as_ref()).unwrap();
1111
}
12-
std::os::windows::fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
13-
"failed to create symlink {:?} for {:?}",
14-
link.as_ref().display(),
15-
original.as_ref().display(),
16-
));
12+
if original.as_ref().is_file() {
13+
std::os::windows::fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
14+
"failed to create symlink {:?} for {:?}",
15+
link.as_ref().display(),
16+
original.as_ref().display(),
17+
));
18+
} else {
19+
std::os::windows::fs::symlink_dir(original.as_ref(), link.as_ref()).expect(&format!(
20+
"failed to create symlink {:?} for {:?}",
21+
link.as_ref().display(),
22+
original.as_ref().display(),
23+
));
24+
}
1725
}
1826

1927
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
@@ -41,6 +49,8 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
4149
let ty = entry.file_type()?;
4250
if ty.is_dir() {
4351
copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
52+
} else if ty.is_symlink() {
53+
copy_symlink(entry.path(), dst.join(entry.file_name()))?;
4454
} else {
4555
std::fs::copy(entry.path(), dst.join(entry.file_name()))?;
4656
}
@@ -59,6 +69,12 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
5969
}
6070
}
6171

72+
fn copy_symlink<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
73+
let target_path = std::fs::read_link(from).unwrap();
74+
create_symlink(target_path, to);
75+
Ok(())
76+
}
77+
6278
/// Helper for reading entries in a given directory.
6379
pub fn read_dir_entries<P: AsRef<Path>, F: FnMut(&Path)>(dir: P, mut callback: F) {
6480
for entry in read_dir(dir) {

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ run-make/raw-dylib-alt-calling-convention/Makefile
2929
run-make/raw-dylib-c/Makefile
3030
run-make/redundant-libs/Makefile
3131
run-make/remap-path-prefix-dwarf/Makefile
32-
run-make/reproducible-build-2/Makefile
3332
run-make/reproducible-build/Makefile
3433
run-make/rlib-format-packed-bundled-libs/Makefile
3534
run-make/simd-ffi/Makefile
3635
run-make/split-debuginfo/Makefile
37-
run-make/stable-symbol-names/Makefile
3836
run-make/staticlib-dylib-linkage/Makefile
3937
run-make/symbol-mangling-hashed/Makefile
4038
run-make/sysroot-crates-are-unstable/Makefile

Diff for: tests/codegen/iter-repeat-n-trivial-drop.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//@ compile-flags: -O
1+
//@ compile-flags: -C opt-level=3
22
//@ only-x86_64
33

44
#![crate_type = "lib"]
55
#![feature(iter_repeat_n)]
6+
#![feature(array_repeat)]
67

78
#[derive(Clone)]
89
pub struct NotCopy(u16);
@@ -54,3 +55,15 @@ pub fn vec_extend_via_iter_repeat_n() -> Vec<u8> {
5455
v.extend(std::iter::repeat_n(42_u8, n));
5556
v
5657
}
58+
59+
// Array repeat uses `RepeatN::next_unchecked` internally,
60+
// so also check that the distinction disappears there.
61+
62+
#[no_mangle]
63+
// CHECK-LABEL: @array_repeat_not_copy
64+
pub unsafe fn array_repeat_not_copy(item: NotCopy) -> [NotCopy; 8] {
65+
// CHECK: insertelement {{.+}} i16 %item
66+
// CHECK: shufflevector <8 x i16> {{.+}} zeroinitializer
67+
// CHECK: store <8 x i16>
68+
std::array::repeat(item)
69+
}

0 commit comments

Comments
 (0)