Skip to content

Commit 67d45f4

Browse files
committed
Auto merge of #145074 - tgross35:rollup-0tillrm, r=tgross35
Rollup of 9 pull requests Successful merges: - #144705 (compiler-builtins: plumb LSE support for aarch64 on linux/gnu when optimized-compiler-builtins not enabled) - #144857 (Port `#[allow_internal_unsafe]` to the new attribute system) - #144900 (Stabilize `unsigned_signed_diff` feature) - #144903 (Rename `begin_panic_handler` to `panic_handler`) - #144974 (compiler-builtins subtree update) - #145007 (Fix build/doc/test of error index generator) - #145018 (Derive `Hash` for rustc_public types) - #145045 (doc(library): Fix Markdown in `Iterator::by_ref`) - #145046 (Fix doc comment of File::try_lock and File::try_lock_shared) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a980cd4 + 338a3e0 commit 67d45f4

File tree

197 files changed

+825
-716
lines changed

Some content is hidden

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

197 files changed

+825
-716
lines changed

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
113113
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
114114
}
115115
}
116+
117+
pub(crate) struct AllowInternalUnsafeParser;
118+
119+
impl<S: Stage> NoArgsAttributeParser<S> for AllowInternalUnsafeParser {
120+
const PATH: &[Symbol] = &[sym::allow_internal_unsafe];
121+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
122+
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::AllowInternalUnsafe(span);
123+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use crate::attributes::lint_helpers::{
3333
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3434
};
3535
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
36-
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
36+
use crate::attributes::macro_attrs::{
37+
AllowInternalUnsafeParser, MacroEscapeParser, MacroUseParser,
38+
};
3739
use crate::attributes::must_use::MustUseParser;
3840
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
3941
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -178,6 +180,7 @@ attribute_parsers!(
178180
Single<SkipDuringMethodDispatchParser>,
179181
Single<TransparencyParser>,
180182
Single<WithoutArgs<AllowIncoherentImplParser>>,
183+
Single<WithoutArgs<AllowInternalUnsafeParser>>,
181184
Single<WithoutArgs<AsPtrParser>>,
182185
Single<WithoutArgs<AutomaticallyDerivedParser>>,
183186
Single<WithoutArgs<CoherenceIsCoreParser>>,

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,7 @@ impl SyntaxExtension {
905905
find_attr!(attrs, AttributeKind::AllowInternalUnstable(i, _) => i)
906906
.map(|i| i.as_slice())
907907
.unwrap_or_default();
908-
// FIXME(jdonszelman): allow_internal_unsafe isn't yet new-style
909-
// let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe);
910-
let allow_internal_unsafe =
911-
ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some();
908+
let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe(_));
912909

913910
let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export)
914911
.and_then(|macro_export| macro_export.meta_item_list())

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ pub enum AttributeKind {
249249
/// Represents `#[rustc_allow_incoherent_impl]`.
250250
AllowIncoherentImpl(Span),
251251

252+
/// Represents `#[allow_internal_unsafe]`.
253+
AllowInternalUnsafe(Span),
254+
252255
/// Represents `#[allow_internal_unstable]`.
253256
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
254257

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ impl AttributeKind {
1616
Align { .. } => No,
1717
AllowConstFnUnstable(..) => No,
1818
AllowIncoherentImpl(..) => No,
19+
AllowInternalUnsafe(..) => Yes,
1920
AllowInternalUnstable(..) => Yes,
2021
AsPtr(..) => Yes,
2122
AutomaticallyDerived(..) => Yes,

compiler/rustc_lint/src/builtin.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
//! [`crate::late_lint_methods!`] invocation in `lib.rs`.
1515
1616
use std::fmt::Write;
17+
use std::slice;
1718

1819
use ast::token::TokenKind;
1920
use rustc_abi::BackendRepr;
2021
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2122
use rustc_ast::visit::{FnCtxt, FnKind};
2223
use rustc_ast::{self as ast, *};
2324
use rustc_ast_pretty::pprust::expr_to_string;
25+
use rustc_attr_parsing::AttributeParser;
2426
use rustc_errors::{Applicability, LintDiagnostic};
2527
use rustc_feature::GateIssue;
2628
use rustc_hir as hir;
@@ -249,7 +251,16 @@ impl UnsafeCode {
249251

250252
impl EarlyLintPass for UnsafeCode {
251253
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
252-
if attr.has_name(sym::allow_internal_unsafe) {
254+
if AttributeParser::parse_limited(
255+
cx.builder.sess(),
256+
slice::from_ref(attr),
257+
sym::allow_internal_unsafe,
258+
attr.span,
259+
DUMMY_NODE_ID,
260+
Some(cx.builder.features()),
261+
)
262+
.is_some()
263+
{
253264
self.report_unsafe(cx, attr.span, BuiltinUnsafe::AllowInternalUnsafe);
254265
}
255266
}

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ passes_allow_incoherent_impl =
2929
`rustc_allow_incoherent_impl` attribute should be applied to impl items
3030
.label = the only currently supported targets are inherent methods
3131
32-
passes_allow_internal_unstable =
32+
passes_macro_only_attribute =
3333
attribute should be applied to a macro
3434
.label = not a macro
3535

compiler/rustc_passes/src/check_attr.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
207207
Attribute::Parsed(AttributeKind::ConstContinue(attr_span)) => {
208208
self.check_const_continue(hir_id, *attr_span, target)
209209
}
210+
Attribute::Parsed(AttributeKind::AllowInternalUnsafe(attr_span)) => {
211+
self.check_allow_internal_unsafe(hir_id, *attr_span, span, target, attrs)
212+
}
210213
Attribute::Parsed(AttributeKind::AllowInternalUnstable(_, first_span)) => {
211214
self.check_allow_internal_unstable(hir_id, *first_span, span, target, attrs)
212215
}
@@ -413,7 +416,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
413416
// internal
414417
| sym::prelude_import
415418
| sym::panic_handler
416-
| sym::allow_internal_unsafe
417419
| sym::lang
418420
| sym::needs_allocator
419421
| sym::default_lib_allocator
@@ -2212,14 +2214,49 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22122214

22132215
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
22142216
/// (Allows proc_macro functions)
2215-
// FIXME(jdonszelmann): if possible, move to attr parsing
22162217
fn check_allow_internal_unstable(
22172218
&self,
22182219
hir_id: HirId,
22192220
attr_span: Span,
22202221
span: Span,
22212222
target: Target,
22222223
attrs: &[Attribute],
2224+
) {
2225+
self.check_macro_only_attr(
2226+
hir_id,
2227+
attr_span,
2228+
span,
2229+
target,
2230+
attrs,
2231+
"allow_internal_unstable",
2232+
)
2233+
}
2234+
2235+
/// Outputs an error for `#[allow_internal_unsafe]` which can only be applied to macros.
2236+
/// (Allows proc_macro functions)
2237+
fn check_allow_internal_unsafe(
2238+
&self,
2239+
hir_id: HirId,
2240+
attr_span: Span,
2241+
span: Span,
2242+
target: Target,
2243+
attrs: &[Attribute],
2244+
) {
2245+
self.check_macro_only_attr(hir_id, attr_span, span, target, attrs, "allow_internal_unsafe")
2246+
}
2247+
2248+
/// Outputs an error for attributes that can only be applied to macros, such as
2249+
/// `#[allow_internal_unsafe]` and `#[allow_internal_unstable]`.
2250+
/// (Allows proc_macro functions)
2251+
// FIXME(jdonszelmann): if possible, move to attr parsing
2252+
fn check_macro_only_attr(
2253+
&self,
2254+
hir_id: HirId,
2255+
attr_span: Span,
2256+
span: Span,
2257+
target: Target,
2258+
attrs: &[Attribute],
2259+
attr_name: &str,
22232260
) {
22242261
match target {
22252262
Target::Fn => {
@@ -2238,18 +2275,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22382275
// erroneously allowed it and some crates used it accidentally, to be compatible
22392276
// with crates depending on them, we can't throw an error here.
22402277
Target::Field | Target::Arm => {
2241-
self.inline_attr_str_error_without_macro_def(
2242-
hir_id,
2243-
attr_span,
2244-
"allow_internal_unstable",
2245-
);
2278+
self.inline_attr_str_error_without_macro_def(hir_id, attr_span, attr_name);
22462279
return;
22472280
}
22482281
// otherwise continue out of the match
22492282
_ => {}
22502283
}
22512284

2252-
self.tcx.dcx().emit_err(errors::AllowInternalUnstable { attr_span, span });
2285+
self.tcx.dcx().emit_err(errors::MacroOnlyAttribute { attr_span, span });
22532286
}
22542287

22552288
/// Checks if the items on the `#[debugger_visualizer]` attribute are valid.

compiler/rustc_passes/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ pub(crate) struct UsedStatic {
643643
}
644644

645645
#[derive(Diagnostic)]
646-
#[diag(passes_allow_internal_unstable)]
647-
pub(crate) struct AllowInternalUnstable {
646+
#[diag(passes_macro_only_attribute)]
647+
pub(crate) struct MacroOnlyAttribute {
648648
#[primary_span]
649649
pub attr_span: Span,
650650
#[label]

compiler/rustc_public/src/mir/body.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl AssertMessage {
349349
}
350350
}
351351

352-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
352+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
353353
pub enum BinOp {
354354
Add,
355355
AddUnchecked,
@@ -384,7 +384,7 @@ impl BinOp {
384384
}
385385
}
386386

387-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
387+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
388388
pub enum UnOp {
389389
Not,
390390
Neg,
@@ -490,7 +490,7 @@ pub enum StatementKind {
490490
Nop,
491491
}
492492

493-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
493+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
494494
pub enum Rvalue {
495495
/// Creates a pointer with the indicated mutability to the place.
496496
///
@@ -666,7 +666,7 @@ impl Rvalue {
666666
}
667667
}
668668

669-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
669+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
670670
pub enum AggregateKind {
671671
Array(Ty),
672672
Tuple,
@@ -677,14 +677,14 @@ pub enum AggregateKind {
677677
RawPtr(Ty, Mutability),
678678
}
679679

680-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
680+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
681681
pub enum Operand {
682682
Copy(Place),
683683
Move(Place),
684684
Constant(ConstOperand),
685685
}
686686

687-
#[derive(Clone, Eq, PartialEq, Serialize)]
687+
#[derive(Clone, Eq, PartialEq, Hash, Serialize)]
688688
pub struct Place {
689689
pub local: Local,
690690
/// projection out of a place (access a field, deref a pointer, etc)
@@ -697,7 +697,7 @@ impl From<Local> for Place {
697697
}
698698
}
699699

700-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
700+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
701701
pub struct ConstOperand {
702702
pub span: Span,
703703
pub user_ty: Option<UserTypeAnnotationIndex>,
@@ -770,7 +770,7 @@ pub enum VarDebugInfoContents {
770770
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
771771
// are of type ProjectionElem<(), ()>).
772772
// In rustc_public's IR we don't need this generality, so we just use ProjectionElem for Places.
773-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
773+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
774774
pub enum ProjectionElem {
775775
/// Dereference projections (e.g. `*_1`) project to the address referenced by the base place.
776776
Deref,
@@ -913,7 +913,7 @@ impl SwitchTargets {
913913
}
914914
}
915915

916-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
916+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
917917
pub enum BorrowKind {
918918
/// Data must be immutable and is aliasable.
919919
Shared,
@@ -940,7 +940,7 @@ impl BorrowKind {
940940
}
941941
}
942942

943-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
943+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
944944
pub enum RawPtrKind {
945945
Mut,
946946
Const,
@@ -958,14 +958,14 @@ impl RawPtrKind {
958958
}
959959
}
960960

961-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
961+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
962962
pub enum MutBorrowKind {
963963
Default,
964964
TwoPhaseBorrow,
965965
ClosureCapture,
966966
}
967967

968-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
968+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
969969
pub enum FakeBorrowKind {
970970
/// A shared (deep) borrow. Data must be immutable and is aliasable.
971971
Deep,
@@ -982,13 +982,13 @@ pub enum Mutability {
982982
Mut,
983983
}
984984

985-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
985+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
986986
pub enum Safety {
987987
Safe,
988988
Unsafe,
989989
}
990990

991-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
991+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
992992
pub enum PointerCoercion {
993993
/// Go from a fn-item type to a fn-pointer type.
994994
ReifyFnPointer,
@@ -1015,7 +1015,7 @@ pub enum PointerCoercion {
10151015
Unsize,
10161016
}
10171017

1018-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
1018+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
10191019
pub enum CastKind {
10201020
// FIXME(smir-rename): rename this to PointerExposeProvenance
10211021
PointerExposeAddress,
@@ -1030,7 +1030,7 @@ pub enum CastKind {
10301030
Transmute,
10311031
}
10321032

1033-
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1033+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
10341034
pub enum NullOp {
10351035
/// Returns the size of a value of that type.
10361036
SizeOf,

0 commit comments

Comments
 (0)