Port #[rustc_pub_transparent] to the new attribute system
This commit is contained in:
@@ -240,6 +240,9 @@ pub enum AttributeKind {
|
|||||||
/// Represents `#[optimize(size|speed)]`
|
/// Represents `#[optimize(size|speed)]`
|
||||||
Optimize(OptimizeAttr, Span),
|
Optimize(OptimizeAttr, Span),
|
||||||
|
|
||||||
|
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
|
||||||
|
PubTransparent(Span),
|
||||||
|
|
||||||
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
|
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
|
||||||
Repr(ThinVec<(ReprAttr, Span)>),
|
Repr(ThinVec<(ReprAttr, Span)>),
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,16 @@ impl<S: Stage> SingleAttributeParser<S> for AsPtrParser {
|
|||||||
Some(AttributeKind::AsPtr(cx.attr_span))
|
Some(AttributeKind::AsPtr(cx.attr_span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct PubTransparentParser;
|
||||||
|
impl<S: Stage> SingleAttributeParser<S> for PubTransparentParser {
|
||||||
|
const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
|
||||||
|
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
|
||||||
|
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
|
||||||
|
const TEMPLATE: AttributeTemplate = template!(Word);
|
||||||
|
|
||||||
|
fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
|
||||||
|
// FIXME: check that there's no args (this is currently checked elsewhere)
|
||||||
|
Some(AttributeKind::PubTransparent(cx.attr_span))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
|
|||||||
use crate::attributes::confusables::ConfusablesParser;
|
use crate::attributes::confusables::ConfusablesParser;
|
||||||
use crate::attributes::deprecation::DeprecationParser;
|
use crate::attributes::deprecation::DeprecationParser;
|
||||||
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
|
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
|
||||||
use crate::attributes::lint_helpers::AsPtrParser;
|
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
|
||||||
use crate::attributes::repr::{AlignParser, ReprParser};
|
use crate::attributes::repr::{AlignParser, ReprParser};
|
||||||
use crate::attributes::semantics::MayDangleParser;
|
use crate::attributes::semantics::MayDangleParser;
|
||||||
use crate::attributes::stability::{
|
use crate::attributes::stability::{
|
||||||
@@ -113,6 +113,7 @@ attribute_parsers!(
|
|||||||
Single<InlineParser>,
|
Single<InlineParser>,
|
||||||
Single<MayDangleParser>,
|
Single<MayDangleParser>,
|
||||||
Single<OptimizeParser>,
|
Single<OptimizeParser>,
|
||||||
|
Single<PubTransparentParser>,
|
||||||
Single<RustcForceInlineParser>,
|
Single<RustcForceInlineParser>,
|
||||||
Single<TransparencyParser>,
|
Single<TransparencyParser>,
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
|
|||||||
@@ -710,7 +710,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
|||||||
),
|
),
|
||||||
rustc_attr!(
|
rustc_attr!(
|
||||||
rustc_pub_transparent, Normal, template!(Word),
|
rustc_pub_transparent, Normal, template!(Word),
|
||||||
WarnFollowing, EncodeCrossCrate::Yes,
|
ErrorFollowing, EncodeCrossCrate::Yes,
|
||||||
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
|
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::cell::LazyCell;
|
|||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use rustc_abi::FieldIdx;
|
use rustc_abi::FieldIdx;
|
||||||
|
use rustc_attr_data_structures::AttributeKind;
|
||||||
use rustc_attr_data_structures::ReprAttr::ReprPacked;
|
use rustc_attr_data_structures::ReprAttr::ReprPacked;
|
||||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||||
use rustc_errors::codes::*;
|
use rustc_errors::codes::*;
|
||||||
@@ -1384,7 +1385,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
|
|||||||
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
|
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
|
||||||
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
|
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
|
||||||
ty::Adt(def, args) => {
|
ty::Adt(def, args) => {
|
||||||
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
|
if !def.did().is_local()
|
||||||
|
&& !attrs::find_attr!(
|
||||||
|
tcx.get_all_attrs(def.did()),
|
||||||
|
AttributeKind::PubTransparent(_)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let non_exhaustive = def.is_variant_list_non_exhaustive()
|
let non_exhaustive = def.is_variant_list_non_exhaustive()
|
||||||
|| def
|
|| def
|
||||||
|
|||||||
@@ -149,6 +149,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
|
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&Attribute::Parsed(AttributeKind::PubTransparent(attr_span)) => {
|
||||||
|
self.check_rustc_pub_transparent(attr_span, span, attrs)
|
||||||
|
}
|
||||||
Attribute::Parsed(AttributeKind::Cold(attr_span)) => {
|
Attribute::Parsed(AttributeKind::Cold(attr_span)) => {
|
||||||
self.check_cold(hir_id, *attr_span, span, target)
|
self.check_cold(hir_id, *attr_span, span, target)
|
||||||
}
|
}
|
||||||
@@ -288,7 +292,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
self.check_type_const(hir_id,attr, target);
|
self.check_type_const(hir_id,attr, target);
|
||||||
}
|
}
|
||||||
[sym::linkage, ..] => self.check_linkage(attr, span, target),
|
[sym::linkage, ..] => self.check_linkage(attr, span, target),
|
||||||
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent(attr.span(), span, attrs),
|
|
||||||
[
|
[
|
||||||
// ok
|
// ok
|
||||||
sym::allow
|
sym::allow
|
||||||
|
|||||||
Reference in New Issue
Block a user