Skip to content

Commit a1e655d

Browse files
committed
encode_cross_crate for hir attributes
1 parent 8a65ee0 commit a1e655d

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,7 @@ dependencies = [
37243724
name = "rustc_feature"
37253725
version = "0.0.0"
37263726
dependencies = [
3727+
"rustc_attr_data_structures",
37273728
"rustc_data_structures",
37283729
"rustc_span",
37293730
"serde",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::AttributeKind;
2+
3+
#[derive(PartialEq)]
4+
pub enum EncodeCrossCrate {
5+
Yes,
6+
No,
7+
}
8+
9+
impl AttributeKind {
10+
pub fn encode_cross_crate(&self) -> EncodeCrossCrate {
11+
use AttributeKind::*;
12+
use EncodeCrossCrate::*;
13+
14+
match self {
15+
Align { .. } => No,
16+
AllowConstFnUnstable(..) => No,
17+
AllowInternalUnstable(..) => Yes,
18+
AsPtr(..) => Yes,
19+
BodyStability { .. } => No,
20+
Confusables { .. } => Yes,
21+
ConstStability { .. } => Yes,
22+
ConstStabilityIndirect => No,
23+
Deprecation { .. } => Yes,
24+
DocComment { .. } => Yes,
25+
Inline(..) => No,
26+
MacroTransparency(..) => Yes,
27+
Repr(..) => No,
28+
Stability { .. } => Yes,
29+
}
30+
}
31+
}

compiler/rustc_attr_data_structures/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// tidy-alphabetical-end
1010

1111
mod attributes;
12+
mod encode_cross_crate;
1213
mod stability;
1314
mod version;
1415

@@ -17,6 +18,7 @@ pub mod lints;
1718
use std::num::NonZero;
1819

1920
pub use attributes::*;
21+
pub use encode_cross_crate::EncodeCrossCrate;
2022
use rustc_abi::Align;
2123
use rustc_ast::token::CommentKind;
2224
use rustc_ast::{AttrStyle, IntTy, UintTy};

compiler/rustc_feature/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
89
rustc_data_structures = { path = "../rustc_data_structures" }
910
rustc_span = { path = "../rustc_span" }
10-
serde = { version = "1.0.125", features = [ "derive" ] }
11+
serde = { version = "1.0.125", features = ["derive"] }
1112
serde_json = "1.0.59"
1213
# tidy-alphabetical-end

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::LazyLock;
55
use AttributeDuplicates::*;
66
use AttributeGate::*;
77
use AttributeType::*;
8+
use rustc_attr_data_structures::EncodeCrossCrate;
89
use rustc_data_structures::fx::FxHashMap;
910
use rustc_span::edition::Edition;
1011
use rustc_span::{Symbol, sym};
@@ -368,12 +369,6 @@ macro_rules! experimental {
368369
};
369370
}
370371

371-
#[derive(PartialEq)]
372-
pub enum EncodeCrossCrate {
373-
Yes,
374-
No,
375-
}
376-
377372
pub struct BuiltinAttribute {
378373
pub name: Symbol,
379374
/// Whether this attribute is encode cross crate.

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{Read, Seek, Write};
55
use std::path::{Path, PathBuf};
66
use std::sync::Arc;
77

8-
use rustc_ast::attr::AttributeExt;
8+
use rustc_attr_data_structures::EncodeCrossCrate;
99
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1010
use rustc_data_structures::memmap::{Mmap, MmapMut};
1111
use rustc_data_structures::sync::{join, par_for_each_in};
@@ -824,9 +824,13 @@ struct AnalyzeAttrState<'a> {
824824
/// visibility: this is a piece of data that can be computed once per defid, and not once per
825825
/// attribute. Some attributes would only be usable downstream if they are public.
826826
#[inline]
827-
fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> bool {
827+
fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool {
828828
let mut should_encode = false;
829-
if let Some(name) = attr.name()
829+
if let hir::Attribute::Parsed(p) = attr
830+
&& p.encode_cross_crate() == EncodeCrossCrate::No
831+
{
832+
// Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.
833+
} else if let Some(name) = attr.name()
830834
&& !rustc_feature::encode_cross_crate(name)
831835
{
832836
// Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.

0 commit comments

Comments
 (0)