Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ jobs:
# discoverable Python in $env:PATH. Only install if we're actually running Windows tests
# that use LLDB
if: ${{ startsWith(matrix.os, 'windows') && matrix.required_python_version}}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.required_python_version }}

Expand Down
22 changes: 0 additions & 22 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_span::{Ident, Span, Symbol, sym};
use smallvec::{SmallVec, smallvec};
use thin_vec::{ThinVec, thin_vec};

use crate::GeneratedAttr;
use crate::ast::{
AttrArgs, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DUMMY_NODE_ID, DelimArgs,
Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NormalAttr, Path,
Expand Down Expand Up @@ -248,21 +247,6 @@ impl AttributeExt for Attribute {
}
}

fn is_automatically_derived_attr(&self) -> bool {
self.has_name(sym::automatically_derived)
}

fn is_doc_hidden(&self) -> bool {
match &self.kind {
AttrKind::Normal(_) => {
self.has_name(sym::doc)
&& self.meta_item_list().is_some_and(|l| list_contains_name(&l, sym::hidden))
}
AttrKind::Generated(GeneratedAttr::DocHidden) => true,
_ => false,
}
}

fn is_doc_keyword_or_attribute(&self) -> bool {
match &self.kind {
AttrKind::Normal(_) => {
Expand Down Expand Up @@ -1000,9 +984,6 @@ pub trait AttributeExt: Debug + 'static {
/// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`.
fn is_proc_macro_attr(&self) -> bool;

/// Returns true if this attribute is `#[automatically_deived]`.
fn is_automatically_derived_attr(&self) -> bool;

/// Returns the documentation and its kind if this is a doc comment or a sugared doc comment.
/// * `///doc` returns `Some(("doc", CommentKind::Line))`.
/// * `/** doc */` returns `Some(("doc", CommentKind::Block))`.
Expand All @@ -1019,9 +1000,6 @@ pub trait AttributeExt: Debug + 'static {
/// doc).
fn doc_resolution_scope(&self) -> Option<AttrStyle>;

/// Returns `true` if this attribute contains `doc(hidden)`.
fn is_doc_hidden(&self) -> bool;

/// Returns `true` is this attribute contains `doc(keyword)` or `doc(attribute)`.
fn is_doc_keyword_or_attribute(&self) -> bool;

Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_attr_ir/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ impl AttributeExt for Attribute {
}
}

fn is_automatically_derived_attr(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::AutomaticallyDerived))
}

#[inline]
fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind, Span)> {
match &self {
Expand Down Expand Up @@ -261,10 +257,6 @@ impl AttributeExt for Attribute {
)
}

fn is_doc_hidden(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.hidden.is_some())
}

fn is_doc_keyword_or_attribute(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.attribute.is_some() || d.keyword.is_some())
}
Expand Down
87 changes: 31 additions & 56 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::fmt::Debug;

use rustc_ast as ast;
use rustc_ast::CRATE_NODE_ID;
use rustc_ast::attr::AttributeExt;
use rustc_attr_ir::lint::{LintCheck, LintCheckKind};
use rustc_attr_ir::target::Target;
use rustc_attr_ir::{Attribute, AttributeKind, find_attr};
use rustc_attr_ir::{Attribute, DocAttribute, find_attr};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::unord::UnordSet;
Expand All @@ -32,7 +31,6 @@ use rustc_middle::ty::{RegisteredTools, TyCtxt};
use rustc_session::Session;
use rustc_span::def_id::CRATE_MOD_ID;
use rustc_span::{AttrId, DUMMY_SP, Ident, Span, Symbol, sym};
use thin_vec::ThinVec;
use tracing::{debug, instrument};

use crate::builtin::MISSING_DOCS;
Expand Down Expand Up @@ -293,7 +291,7 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
impl<'tcx> LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
fn add_id(&mut self, hir_id: HirId) {
self.provider.cur = hir_id;
self.add(self.provider.attrs.get(hir_id.local_id), hir_id == hir::CRATE_HIR_ID);
self.add_hir(self.provider.attrs.get(hir_id.local_id), hir_id == hir::CRATE_HIR_ID);
}
}

Expand Down Expand Up @@ -413,7 +411,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
crate_attrs: &[ast::Attribute],
) -> Self {
let mut builder = Self::new(sess, features, lint_added_lints, store, registered_lint_tools);
builder.add(crate_attrs, true);
builder.add_ast(crate_attrs, true);
builder
}

Expand Down Expand Up @@ -445,7 +443,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
self.provider.cur =
self.provider.sets.list.push(LintSet { specs: FxIndexMap::default(), parent: prev });

self.add(attrs, is_crate_node);
self.add_ast(attrs, is_crate_node);

if self.provider.current_specs().is_empty() {
self.provider.sets.list.pop();
Expand Down Expand Up @@ -655,31 +653,22 @@ where
};
}

fn parse_lint_attributes(
&mut self,
attrs: &[impl AttributeExt + 'static],
) -> ThinVec<LintCheck> {
fn try_cast_slice<T: 'static, U: 'static>(slice: &[T]) -> Option<&[U]> {
use std::any::TypeId;
if TypeId::of::<T>() == TypeId::of::<U>() {
// SAFETY: T == U, so it is sound to cast `&[T]` to `&[U]`
unsafe {
Some(core::slice::from_raw_parts(slice.as_ptr().cast::<U>(), slice.len()))
}
} else {
None
}
fn add_ast(&mut self, attrs: &[rustc_ast::Attribute], is_crate_node: bool) {
if attrs.is_empty() {
return;
}

if let Some(attrs) = try_cast_slice::<_, rustc_attr_ir::Attribute>(attrs) {
return find_attr!(attrs, LintCheck(lints) => lints.clone()).unwrap_or_default();
for attr in attrs {
// `SINGLE_USE_LIFETIMES` is an AST lint so we only insert this here
if attr.has_name(sym::automatically_derived) {
self.provider.insert(
LintId::of(SINGLE_USE_LIFETIMES),
LevelSpec::new(Level::Allow, None, LintLevelSource::Default),
);
}
}

let parsed = AttributeParser::parse_limited_all(
self.sess,
try_cast_slice(attrs).unwrap_or_else(|| {
unreachable!("unknown `&[implAttributeExt]` {}", std::any::type_name_of_val(attrs))
}),
attrs,
Some(&|attr| {
// This is ...complicated. Sometimes we need to parse lint check
// attributes pre-expansion, but of course things are allowed to
Expand Down Expand Up @@ -713,41 +702,27 @@ where
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
Some(self.registered_lint_tools),
);
parsed
.into_iter()
.find_map(|p| {
if let Attribute::Parsed(AttributeKind::LintCheck(lints)) = p {
Some(lints)
} else {
None
}
})
.unwrap_or_default()
self.add_hir_inner(&parsed, is_crate_node)
}

fn add(&mut self, attrs: &[impl AttributeExt + 'static], is_crate_node: bool) {
fn add_hir(&mut self, attrs: &[Attribute], is_crate_node: bool) {
if attrs.is_empty() {
return;
}
for attr in attrs {
if attr.is_automatically_derived_attr() {
self.provider.insert(
LintId::of(SINGLE_USE_LIFETIMES),
LevelSpec::new(Level::Allow, None, LintLevelSource::Default),
);
continue;
}

// `#[doc(hidden)]` disables missing_docs check.
if attr.is_doc_hidden() {
self.provider.insert(
LintId::of(MISSING_DOCS),
LevelSpec::new(Level::Allow, None, LintLevelSource::Default),
);
continue;
}
// `MISSING_DOCS` is a HIR lint so we only insert this here
if find_attr!(attrs, Doc(DocAttribute { hidden: Some(_), .. })) {
self.provider.insert(
LintId::of(MISSING_DOCS),
LevelSpec::new(Level::Allow, None, LintLevelSource::Default),
);
}
let lint_checks = self.parse_lint_attributes(attrs);
self.add_hir_inner(attrs, is_crate_node)
}

fn add_hir_inner(&mut self, attrs: &[Attribute], is_crate_node: bool) {
let Some(lint_checks) = find_attr!(attrs, LintCheck(lints) => lints.clone()) else {
return;
};

let sess = self.sess;

Expand Down
Loading
Loading