Skip to content

Commit 2f0bc93

Browse files
committed
Auto merge of rust-lang#128297 - matthiaskrgr:rollup-tzqftgw, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#127853 (`#[naked]`: report incompatible attributes) - rust-lang#128228 (Stabilize `const_waker`) - rust-lang#128276 (Add a README to rustbook to explain its purpose) - rust-lang#128279 (Stabilize `is_sorted`) - rust-lang#128282 (bitwise and bytewise methods on `NonZero`) - rust-lang#128285 (rustc book: document how the RUST_TARGET_PATH variable is used) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3148b35 + 0b4d21b commit 2f0bc93

File tree

46 files changed

+923
-255
lines changed

Some content is hidden

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

46 files changed

+923
-255
lines changed

compiler/rustc_builtin_macros/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ builtin_macros_multiple_defaults = multiple declared defaults
220220
.note = only one variant can be default
221221
.suggestion = make `{$ident}` default
222222
223+
builtin_macros_naked_functions_testing_attribute =
224+
cannot use `#[naked]` with testing attributes
225+
.label = function marked with testing attribute here
226+
.naked_attribute = `#[naked]` is incompatible with testing attributes
227+
223228
builtin_macros_no_default_variant = no default declared
224229
.help = make a unit variant default by placing `#[default]` above it
225230
.suggestion = make `{$ident}` default

compiler/rustc_builtin_macros/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,13 @@ pub(crate) struct ExpectedItem<'a> {
923923
pub span: Span,
924924
pub token: &'a str,
925925
}
926+
927+
#[derive(Diagnostic)]
928+
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)]
929+
pub struct NakedFunctionTestingAttribute {
930+
#[primary_span]
931+
#[label(builtin_macros_naked_attribute)]
932+
pub naked_span: Span,
933+
#[label]
934+
pub testing_span: Span,
935+
}

compiler/rustc_builtin_macros/src/test.rs

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ pub(crate) fn expand_test_or_bench(
133133
};
134134
};
135135

136+
if let Some(attr) = attr::find_by_name(&item.attrs, sym::naked) {
137+
cx.dcx().emit_err(errors::NakedFunctionTestingAttribute {
138+
testing_span: attr_sp,
139+
naked_span: attr.span,
140+
});
141+
return vec![Annotatable::Item(item)];
142+
}
143+
136144
// check_*_signature will report any errors in the type so compilation
137145
// will fail. We shouldn't try to expand in this case because the errors
138146
// would be spurious.

compiler/rustc_codegen_cranelift/example/std_example.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
coroutines,
44
stmt_expr_attributes,
55
coroutine_trait,
6-
is_sorted,
76
repr_simd,
87
tuple_trait,
98
unboxed_closures

compiler/rustc_codegen_gcc/example/std_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(internal_features)]
2-
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted, stmt_expr_attributes)]
2+
#![feature(core_intrinsics, coroutines, coroutine_trait, stmt_expr_attributes)]
33

44
#[cfg(feature="master")]
55
#[cfg(target_arch="x86_64")]
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
`#[track_caller]` and `#[naked]` cannot both be applied to the same function.
1+
Functions marked with the `#[naked]` attribute are restricted in what other
2+
attributes they may be marked with.
3+
4+
Notable attributes that are incompatible with `#[naked]` are:
5+
6+
* `#[inline]`
7+
* `#[track_caller]`
8+
* `#[test]`, `#[ignore]`, `#[should_panic]`
29

310
Erroneous code example:
411

512
```compile_fail,E0736
13+
#[inline]
614
#[naked]
7-
#[track_caller]
815
fn foo() {}
916
```
1017

11-
This is primarily due to ABI incompatibilities between the two attributes.
12-
See [RFC 2091] for details on this and other limitations.
13-
14-
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
18+
These incompatibilities are due to the fact that naked functions deliberately
19+
impose strict restrictions regarding the code that the compiler is
20+
allowed to produce for this function.

compiler/rustc_error_codes/src/error_codes/E0739.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
`#[track_caller]` can not be applied on struct.
1+
`#[track_caller]` must be applied to a function
22

33
Erroneous code example:
44

compiler/rustc_hir_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ This API is completely unstable and subject to change.
6464
#![doc(rust_logo)]
6565
#![feature(control_flow_enum)]
6666
#![feature(if_let_guard)]
67-
#![feature(is_sorted)]
6867
#![feature(iter_intersperse)]
6968
#![feature(let_chains)]
7069
#![feature(never_type)]

compiler/rustc_lint_defs/src/builtin.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,18 @@ declare_lint! {
19841984
///
19851985
/// ```rust
19861986
/// trait MyIterator : Iterator {
1987-
/// // is_sorted is an unstable method that already exists on the Iterator trait
1988-
/// fn is_sorted(self) -> bool where Self: Sized {true}
1987+
/// // is_partitioned is an unstable method that already exists on the Iterator trait
1988+
/// fn is_partitioned<P>(self, predicate: P) -> bool
1989+
/// where
1990+
/// Self: Sized,
1991+
/// P: FnMut(Self::Item) -> bool,
1992+
/// {true}
19891993
/// }
19901994
///
19911995
/// impl<T: ?Sized> MyIterator for T where T: Iterator { }
19921996
///
19931997
/// let x = vec![1, 2, 3];
1994-
/// let _ = x.iter().is_sorted();
1998+
/// let _ = x.iter().is_partitioned(|_| true);
19951999
/// ```
19962000
///
19972001
/// {{produces}}
@@ -2007,7 +2011,7 @@ declare_lint! {
20072011
/// is an early-warning to let you know that there may be a collision in
20082012
/// the future. This can be avoided by adding type annotations to
20092013
/// disambiguate which trait method you intend to call, such as
2010-
/// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
2014+
/// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
20112015
///
20122016
/// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
20132017
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(decl_macro)]
77
#![feature(if_let_guard)]
88
#![feature(impl_trait_in_assoc_type)]
9-
#![feature(is_sorted)]
109
#![feature(let_chains)]
1110
#![feature(map_try_insert)]
1211
#![feature(never_type)]

compiler/rustc_monomorphize/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tidy-alphabetical-start
22
#![feature(array_windows)]
3-
#![feature(is_sorted)]
43
// tidy-alphabetical-end
54

65
use rustc_hir::lang_items::LangItem;

compiler/rustc_passes/messages.ftl

+5-6
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ passes_break_non_loop =
6969
.suggestion = use `break` on its own without a value inside this `{$kind}` loop
7070
.break_expr_suggestion = alternatively, you might have meant to use the available loop label
7171
72-
passes_cannot_inline_naked_function =
73-
naked functions cannot be inlined
74-
7572
passes_cannot_stabilize_deprecated =
7673
an API can't be stabilized after it is deprecated
7774
.label = invalid version
@@ -485,16 +482,18 @@ passes_naked_functions_asm_block =
485482
passes_naked_functions_asm_options =
486483
asm options unsupported in naked functions: {$unsupported_options}
487484
485+
passes_naked_functions_incompatible_attribute =
486+
attribute incompatible with `#[naked]`
487+
.label = the `{$attr}` attribute is incompatible with `#[naked]`
488+
.naked_attribute = function marked with `#[naked]` here
489+
488490
passes_naked_functions_must_use_noreturn =
489491
asm in naked functions must use `noreturn` option
490492
.suggestion = consider specifying that the asm block is responsible for returning from the function
491493
492494
passes_naked_functions_operands =
493495
only `const` and `sym` operands are supported in naked functions
494496
495-
passes_naked_tracked_caller =
496-
cannot use `#[track_caller]` with `#[naked]`
497-
498497
passes_no_link =
499498
attribute should be applied to an `extern crate` item
500499
.label = not an `extern crate` item

compiler/rustc_passes/src/check_attr.rs

+64-9
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
155155
[sym::rustc_std_internal_symbol] => {
156156
self.check_rustc_std_internal_symbol(attr, span, target)
157157
}
158-
[sym::naked] => self.check_naked(hir_id, attr, span, target),
158+
[sym::naked] => self.check_naked(hir_id, attr, span, target, attrs),
159159
[sym::rustc_never_returns_null_ptr] => {
160160
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
161161
}
@@ -410,12 +410,71 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
410410
}
411411

412412
/// Checks if `#[naked]` is applied to a function definition.
413-
fn check_naked(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
413+
fn check_naked(
414+
&self,
415+
hir_id: HirId,
416+
attr: &Attribute,
417+
span: Span,
418+
target: Target,
419+
attrs: &[Attribute],
420+
) -> bool {
421+
// many attributes don't make sense in combination with #[naked].
422+
// Notable attributes that are incompatible with `#[naked]` are:
423+
//
424+
// * `#[inline]`
425+
// * `#[track_caller]`
426+
// * `#[test]`, `#[ignore]`, `#[should_panic]`
427+
//
428+
// NOTE: when making changes to this list, check that `error_codes/E0736.md` remains accurate
429+
const ALLOW_LIST: &[rustc_span::Symbol] = &[
430+
// conditional compilation
431+
sym::cfg,
432+
sym::cfg_attr,
433+
// testing (allowed here so better errors can be generated in `rustc_builtin_macros::test`)
434+
sym::test,
435+
sym::ignore,
436+
sym::should_panic,
437+
sym::bench,
438+
// diagnostics
439+
sym::allow,
440+
sym::warn,
441+
sym::deny,
442+
sym::forbid,
443+
sym::deprecated,
444+
sym::must_use,
445+
// abi, linking and FFI
446+
sym::export_name,
447+
sym::link_section,
448+
sym::linkage,
449+
sym::no_mangle,
450+
sym::naked,
451+
sym::instruction_set,
452+
// code generation
453+
sym::cold,
454+
sym::target_feature,
455+
// documentation
456+
sym::doc,
457+
];
458+
414459
match target {
415460
Target::Fn
416-
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
461+
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {
462+
for other_attr in attrs {
463+
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
464+
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
465+
span: other_attr.span,
466+
naked_span: attr.span,
467+
attr: other_attr.name_or_empty(),
468+
});
469+
470+
return false;
471+
}
472+
}
473+
474+
true
475+
}
417476
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
418-
// `#[allow_internal_unstable]` attribute with just a lint, because we previously
477+
// `#[naked]` attribute with just a lint, because we previously
419478
// erroneously allowed it and some crates used it accidentally, to be compatible
420479
// with crates depending on them, we can't throw an error here.
421480
Target::Field | Target::Arm | Target::MacroDef => {
@@ -488,7 +547,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
488547
}
489548
}
490549

491-
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
550+
/// Checks if a `#[track_caller]` is applied to a function. Returns `true` if valid.
492551
fn check_track_caller(
493552
&self,
494553
hir_id: HirId,
@@ -498,10 +557,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
498557
target: Target,
499558
) -> bool {
500559
match target {
501-
_ if attrs.iter().any(|attr| attr.has_name(sym::naked)) => {
502-
self.dcx().emit_err(errors::NakedTrackedCaller { attr_span });
503-
false
504-
}
505560
Target::Fn => {
506561
// `#[track_caller]` is not valid on weak lang items because they are called via
507562
// `extern` declarations and `#[track_caller]` would alter their ABI.

compiler/rustc_passes/src/errors.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ pub struct AttrShouldBeAppliedToFn {
7979
pub on_crate: bool,
8080
}
8181

82-
#[derive(Diagnostic)]
83-
#[diag(passes_naked_tracked_caller, code = E0736)]
84-
pub struct NakedTrackedCaller {
85-
#[primary_span]
86-
pub attr_span: Span,
87-
}
88-
8982
#[derive(Diagnostic)]
9083
#[diag(passes_should_be_applied_to_fn, code = E0739)]
9184
pub struct TrackedCallerWrongLocation {
@@ -1124,13 +1117,6 @@ pub struct UnlabeledCfInWhileCondition<'a> {
11241117
pub cf_type: &'a str,
11251118
}
11261119

1127-
#[derive(Diagnostic)]
1128-
#[diag(passes_cannot_inline_naked_function)]
1129-
pub struct CannotInlineNakedFunction {
1130-
#[primary_span]
1131-
pub span: Span,
1132-
}
1133-
11341120
#[derive(LintDiagnostic)]
11351121
#[diag(passes_undefined_naked_function_abi)]
11361122
pub struct UndefinedNakedFunctionAbi;
@@ -1196,6 +1182,17 @@ pub struct NakedFunctionsMustUseNoreturn {
11961182
pub last_span: Span,
11971183
}
11981184

1185+
#[derive(Diagnostic)]
1186+
#[diag(passes_naked_functions_incompatible_attribute, code = E0736)]
1187+
pub struct NakedFunctionIncompatibleAttribute {
1188+
#[primary_span]
1189+
#[label]
1190+
pub span: Span,
1191+
#[label(passes_naked_attribute)]
1192+
pub naked_span: Span,
1193+
pub attr: Symbol,
1194+
}
1195+
11991196
#[derive(Diagnostic)]
12001197
#[diag(passes_attr_only_in_functions)]
12011198
pub struct AttrOnlyInFunctions {

compiler/rustc_passes/src/naked_functions.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use rustc_span::Span;
1414
use rustc_target::spec::abi::Abi;
1515

1616
use crate::errors::{
17-
CannotInlineNakedFunction, NakedFunctionsAsmBlock, NakedFunctionsAsmOptions,
18-
NakedFunctionsMustUseNoreturn, NakedFunctionsOperands, NoPatterns, ParamsNotAllowed,
19-
UndefinedNakedFunctionAbi,
17+
NakedFunctionsAsmBlock, NakedFunctionsAsmOptions, NakedFunctionsMustUseNoreturn,
18+
NakedFunctionsOperands, NoPatterns, ParamsNotAllowed, UndefinedNakedFunctionAbi,
2019
};
2120

2221
pub(crate) fn provide(providers: &mut Providers) {
@@ -53,15 +52,6 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
5352
check_no_patterns(tcx, body.params);
5453
check_no_parameters_use(tcx, body);
5554
check_asm(tcx, def_id, body);
56-
check_inline(tcx, def_id);
57-
}
58-
}
59-
60-
/// Check that the function isn't inlined.
61-
fn check_inline(tcx: TyCtxt<'_>, def_id: LocalDefId) {
62-
let attrs = tcx.get_attrs(def_id, sym::inline);
63-
for attr in attrs {
64-
tcx.dcx().emit_err(CannotInlineNakedFunction { span: attr.span });
6555
}
6656
}
6757

library/alloc/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
// tidy-alphabetical-start
9393
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
9494
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
95-
#![cfg_attr(test, feature(is_sorted))]
9695
#![cfg_attr(test, feature(new_uninit))]
9796
#![feature(alloc_layout_extra)]
9897
#![feature(allocator_api)]
@@ -117,7 +116,6 @@
117116
#![feature(const_pin)]
118117
#![feature(const_refs_to_cell)]
119118
#![feature(const_size_of_val)]
120-
#![feature(const_waker)]
121119
#![feature(core_intrinsics)]
122120
#![feature(deprecated_suggestion)]
123121
#![feature(deref_pure_trait)]

0 commit comments

Comments
 (0)