Skip to content

Commit 4d117f7

Browse files
committed
Auto merge of #157464 - jhpratt:rollup-Y0Egh2K, r=jhpratt
Rollup of 7 pull requests Successful merges: - #150453 (Dont bail in error predicate unless self ty is error in new solver) - #155338 (Staticlib hide internal symbols) - #156892 (Suppress E0621 perpetual borrow suggestion) - #157135 (fix armv7a-none-eabihf tier doc) - #157360 (Document error conditions for `Command::{spawn, output, status}`) - #157418 (NVPTX: Add @kulst to the target maintainers) - #157443 (Make distinction between crate-level attributes that are warned vs errored)
2 parents 3179a47 + 2951ef0 commit 4d117f7

38 files changed

Lines changed: 837 additions & 113 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ impl SingleAttributeParser for CrateNameParser {
1313
const PATH: &[Symbol] = &[sym::crate_name];
1414
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
1515
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
16+
const ALLOWED_TARGETS: AllowedTargets =
17+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
1718
const STABILITY: AttributeStability = AttributeStability::Stable;
1819

1920
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -31,7 +32,8 @@ impl CombineAttributeParser for CrateTypeParser {
3132
const PATH: &[Symbol] = &[sym::crate_type];
3233
type Item = CrateType;
3334
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::CrateType(items);
34-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
35+
const ALLOWED_TARGETS: AllowedTargets =
36+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
3537
const TEMPLATE: AttributeTemplate =
3638
template!(NameValueStr: "crate type", "https://doc.rust-lang.org/reference/linkage.html");
3739
const STABILITY: AttributeStability = AttributeStability::Stable;
@@ -74,7 +76,8 @@ impl SingleAttributeParser for RecursionLimitParser {
7476
const PATH: &[Symbol] = &[sym::recursion_limit];
7577
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
7678
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
77-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
79+
const ALLOWED_TARGETS: AllowedTargets =
80+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
7881
const STABILITY: AttributeStability = AttributeStability::Stable;
7982

8083
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -105,7 +108,8 @@ impl SingleAttributeParser for TypeLengthLimitParser {
105108
const PATH: &[Symbol] = &[sym::type_length_limit];
106109
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
107110
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
108-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
111+
const ALLOWED_TARGETS: AllowedTargets =
112+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
109113
const STABILITY: AttributeStability = AttributeStability::Stable;
110114

111115
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -147,7 +151,8 @@ pub(crate) struct NoStdParser;
147151
impl NoArgsAttributeParser for NoStdParser {
148152
const PATH: &[Symbol] = &[sym::no_std];
149153
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
150-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
154+
const ALLOWED_TARGETS: AllowedTargets =
155+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
151156
const STABILITY: AttributeStability = AttributeStability::Stable;
152157
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
153158
}
@@ -157,7 +162,8 @@ pub(crate) struct NoMainParser;
157162
impl NoArgsAttributeParser for NoMainParser {
158163
const PATH: &[Symbol] = &[sym::no_main];
159164
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
160-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
165+
const ALLOWED_TARGETS: AllowedTargets =
166+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
161167
const STABILITY: AttributeStability = AttributeStability::Stable;
162168
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoMain;
163169
}
@@ -176,7 +182,8 @@ pub(crate) struct WindowsSubsystemParser;
176182
impl SingleAttributeParser for WindowsSubsystemParser {
177183
const PATH: &[Symbol] = &[sym::windows_subsystem];
178184
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
179-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
185+
const ALLOWED_TARGETS: AllowedTargets =
186+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
180187
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
181188
const STABILITY: AttributeStability = AttributeStability::Stable;
182189

@@ -231,7 +238,8 @@ pub(crate) struct NoBuiltinsParser;
231238
impl NoArgsAttributeParser for NoBuiltinsParser {
232239
const PATH: &[Symbol] = &[sym::no_builtins];
233240
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
234-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
241+
const ALLOWED_TARGETS: AllowedTargets =
242+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
235243
const STABILITY: AttributeStability = AttributeStability::Stable;
236244
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
237245
}
@@ -269,7 +277,8 @@ impl CombineAttributeParser for FeatureParser {
269277
const PATH: &[Symbol] = &[sym::feature];
270278
type Item = Ident;
271279
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Feature;
272-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
280+
const ALLOWED_TARGETS: AllowedTargets =
281+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
273282
const TEMPLATE: AttributeTemplate = template!(List: &["feature1, feature2, ..."]);
274283
const STABILITY: AttributeStability = AttributeStability::Stable;
275284

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub(crate) struct InvalidAttrStyle {
148148
pub crate_root_path: String,
149149
#[help("the crate root is at `{$crate_root_path}`")]
150150
pub show_crate_root_help: bool,
151+
#[primary_span]
152+
pub span: Span,
151153
}
152154

153155
#[derive(Diagnostic)]

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ impl<'sess> AttributeParser<'sess> {
114114
// For crate-level attributes we emit a specific set of lints to warn
115115
// people about accidentally not using them on the crate.
116116
if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets {
117-
Self::check_crate_level(cx);
117+
Self::check_crate_level(cx, false);
118+
return;
119+
}
120+
if let &AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]) = allowed_targets {
121+
Self::check_crate_level(cx, true);
118122
return;
119123
}
120124

@@ -181,7 +185,7 @@ impl<'sess> AttributeParser<'sess> {
181185
}
182186
}
183187

184-
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) {
188+
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>, warn: bool) {
185189
if cx.target == Target::Crate {
186190
return;
187191
}
@@ -205,19 +209,20 @@ impl<'sess> AttributeParser<'sess> {
205209
})
206210
.unwrap_or_default();
207211

208-
let target = cx.target;
209-
cx.emit_lint(
210-
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
211-
crate::errors::InvalidAttrStyle {
212-
name,
213-
is_used_as_inner,
214-
target_span: (!is_used_as_inner).then_some(target_span),
215-
target: target.name(),
216-
crate_root_path,
217-
show_crate_root_help,
218-
},
219-
attr_span,
220-
);
212+
let diag = crate::errors::InvalidAttrStyle {
213+
name,
214+
is_used_as_inner,
215+
target_span: (!is_used_as_inner).then_some(target_span),
216+
target: cx.target.name(),
217+
crate_root_path,
218+
show_crate_root_help,
219+
span: attr_span,
220+
};
221+
if warn {
222+
cx.emit_lint(rustc_session::lint::builtin::UNUSED_ATTRIBUTES, diag, attr_span);
223+
} else {
224+
cx.emit_err(diag);
225+
}
221226
}
222227

223228
// FIXME: Fix "Cannot determine resolution" error and remove built-in macros

0 commit comments

Comments
 (0)