Skip to content

Commit 034dcc6

Browse files
authored
Unrolled build for #143400
Rollup merge of #143400 - GrigorenkoPV:attributes/lints, r=jdonszelmann Port `#[rustc_pass_by_value]` to the new attribute system Part of #131229 r? `@oli-obk`
2 parents 556d20a + ef4dece commit 034dcc6

File tree

7 files changed

+32
-13
lines changed

7 files changed

+32
-13
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ pub enum AttributeKind {
287287
/// Represents `#[optimize(size|speed)]`
288288
Optimize(OptimizeAttr, Span),
289289

290+
/// Represents `#[rustc_pass_by_value]` (used by the `rustc_pass_by_value` lint).
291+
PassByValue(Span),
292+
290293
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
291294
PubTransparent(Span),
292295

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,43 @@ impl AttributeKind {
1212
use EncodeCrossCrate::*;
1313

1414
match self {
15+
// tidy-alphabetical-start
1516
Align { .. } => No,
1617
AllowConstFnUnstable(..) => No,
1718
AllowInternalUnstable(..) => Yes,
1819
AsPtr(..) => Yes,
1920
BodyStability { .. } => No,
21+
Cold(..) => No,
2022
Confusables { .. } => Yes,
23+
ConstContinue(..) => No,
2124
ConstStability { .. } => Yes,
2225
ConstStabilityIndirect => No,
2326
Deprecation { .. } => Yes,
2427
DocComment { .. } => Yes,
2528
ExportName { .. } => Yes,
2629
Inline(..) => No,
27-
LinkSection { .. } => No,
28-
MacroTransparency(..) => Yes,
29-
Repr(..) => No,
30-
Stability { .. } => Yes,
31-
Cold(..) => No,
32-
ConstContinue(..) => No,
3330
LinkName { .. } => Yes,
31+
LinkSection { .. } => No,
3432
LoopMatch(..) => No,
33+
MacroTransparency(..) => Yes,
3534
MayDangle(..) => No,
3635
MustUse { .. } => Yes,
3736
Naked(..) => No,
3837
NoImplicitPrelude(..) => No,
3938
NoMangle(..) => No,
4039
Optimize(..) => No,
40+
PassByValue(..) => Yes,
4141
PubTransparent(..) => Yes,
42+
Repr(..) => No,
4243
RustcLayoutScalarValidRangeEnd(..) => Yes,
4344
RustcLayoutScalarValidRangeStart(..) => Yes,
4445
RustcObjectLifetimeDefault => No,
4546
SkipDuringMethodDispatch { .. } => No,
47+
Stability { .. } => Yes,
4648
TargetFeature(..) => No,
4749
TrackCaller(..) => Yes,
4850
Used { .. } => No,
51+
// tidy-alphabetical-end
4952
}
5053
}
5154
}

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for PubTransparentParser {
1717
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1818
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PubTransparent;
1919
}
20+
21+
pub(crate) struct PassByValueParser;
22+
impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
23+
const PATH: &[Symbol] = &[sym::rustc_pass_by_value];
24+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
25+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
26+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2525
use crate::attributes::link_attrs::{LinkNameParser, LinkSectionParser};
26-
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
26+
use crate::attributes::lint_helpers::{AsPtrParser, PassByValueParser, PubTransparentParser};
2727
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2828
use crate::attributes::must_use::MustUseParser;
2929
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
@@ -144,6 +144,7 @@ attribute_parsers!(
144144
Single<WithoutArgs<MayDangleParser>>,
145145
Single<WithoutArgs<NoImplicitPreludeParser>>,
146146
Single<WithoutArgs<NoMangleParser>>,
147+
Single<WithoutArgs<PassByValueParser>>,
147148
Single<WithoutArgs<PubTransparentParser>>,
148149
Single<WithoutArgs<TrackCallerParser>>,
149150
// tidy-alphabetical-end

compiler/rustc_lint/src/pass_by_value.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use rustc_attr_data_structures::{AttributeKind, find_attr};
12
use rustc_hir::def::Res;
23
use rustc_hir::{self as hir, AmbigArg, GenericArg, PathSegment, QPath, TyKind};
34
use rustc_middle::ty;
45
use rustc_session::{declare_lint_pass, declare_tool_lint};
5-
use rustc_span::sym;
66

77
use crate::lints::PassByValueDiag;
88
use crate::{LateContext, LateLintPass, LintContext};
@@ -45,14 +45,16 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
4545
fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<String> {
4646
if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
4747
match path.res {
48-
Res::Def(_, def_id) if cx.tcx.has_attr(def_id, sym::rustc_pass_by_value) => {
48+
Res::Def(_, def_id)
49+
if find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::PassByValue(_)) =>
50+
{
4951
let name = cx.tcx.item_ident(def_id);
5052
let path_segment = path.segments.last().unwrap();
5153
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
5254
}
5355
Res::SelfTyAlias { alias_to: did, is_trait_impl: false, .. } => {
5456
if let ty::Adt(adt, args) = cx.tcx.type_of(did).instantiate_identity().kind() {
55-
if cx.tcx.has_attr(adt.did(), sym::rustc_pass_by_value) {
57+
if find_attr!(cx.tcx.get_all_attrs(adt.did()), AttributeKind::PassByValue(_)) {
5658
return Some(cx.tcx.def_path_str_with_args(adt.did(), args));
5759
}
5860
}

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ fn emit_malformed_attribute(
293293
| sym::rustc_force_inline
294294
| sym::rustc_confusables
295295
| sym::rustc_skip_during_method_dispatch
296+
| sym::rustc_pass_by_value
296297
| sym::repr
297298
| sym::align
298299
| sym::deprecated

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
221221
Attribute::Parsed(AttributeKind::Used { span: attr_span, .. }) => {
222222
self.check_used(*attr_span, target, span);
223223
}
224+
&Attribute::Parsed(AttributeKind::PassByValue(attr_span)) => {
225+
self.check_pass_by_value(attr_span, span, target)
226+
}
224227
Attribute::Unparsed(attr_item) => {
225228
style = Some(attr_item.style);
226229
match attr.path().as_slice() {
@@ -283,7 +286,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283286
| [sym::const_trait, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
284287
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
285288
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
286-
[sym::rustc_pass_by_value, ..] => self.check_pass_by_value(attr, span, target),
287289
[sym::rustc_allow_incoherent_impl, ..] => {
288290
self.check_allow_incoherent_impl(attr, span, target)
289291
}
@@ -1465,11 +1467,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14651467
}
14661468

14671469
/// Warns against some misuses of `#[pass_by_value]`
1468-
fn check_pass_by_value(&self, attr: &Attribute, span: Span, target: Target) {
1470+
fn check_pass_by_value(&self, attr_span: Span, span: Span, target: Target) {
14691471
match target {
14701472
Target::Struct | Target::Enum | Target::TyAlias => {}
14711473
_ => {
1472-
self.dcx().emit_err(errors::PassByValue { attr_span: attr.span(), span });
1474+
self.dcx().emit_err(errors::PassByValue { attr_span, span });
14731475
}
14741476
}
14751477
}

0 commit comments

Comments
 (0)