Skip to content

Commit 01bba2c

Browse files
committed
Eliminate the SessionGlobals from librustc_ast.
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This means they are accessed via the `Session`, rather than via TLS. A few `Attr` methods and `librustc_ast` functions are now methods of `Session`. All of this required passing a `Session` to lots of functions that didn't already have one. Some of these functions also had arguments removed, because those arguments could be accessed directly via the `Session` argument. `contains_feature_attr()` was dead, and is removed. Some functions were moved from `librustc_ast` elsewhere because they now need to access `Session`, which isn't available in that crate. - `entry_point_type()` --> `librustc_builtin_macros` - `global_allocator_spans()` --> `librustc_metadata` - `is_proc_macro_attr()` --> `Session`
1 parent a7fa264 commit 01bba2c

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

clippy_lints/src/functions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
239239
return;
240240
}
241241
if cx.access_levels.is_exported(item.hir_id)
242-
&& !is_proc_macro(&item.attrs)
242+
&& !is_proc_macro(cx.sess(), &item.attrs)
243243
&& attr_by_name(&item.attrs, "no_mangle").is_none()
244244
{
245245
check_must_use_candidate(
@@ -262,7 +262,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
262262
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
263263
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
264264
} else if cx.access_levels.is_exported(item.hir_id)
265-
&& !is_proc_macro(&item.attrs)
265+
&& !is_proc_macro(cx.sess(), &item.attrs)
266266
&& trait_ref_of_method(cx, item.hir_id).is_none()
267267
{
268268
check_must_use_candidate(
@@ -294,7 +294,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
294294
let body = cx.tcx.hir().body(eid);
295295
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
296296

297-
if attr.is_none() && cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(&item.attrs) {
297+
if attr.is_none() && cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(cx.sess(), &item.attrs) {
298298
check_must_use_candidate(
299299
cx,
300300
&sig.decl,

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants
102102
"this seems like a manual implementation of the non-exhaustive pattern",
103103
|diag| {
104104
if_chain! {
105-
if !attr::contains_name(&item.attrs, sym!(non_exhaustive));
105+
if !item.attrs.iter().any(|attr| attr.has_name(sym!(non_exhaustive)));
106106
let header_span = cx.sess.source_map().span_until_char(item.span, '{');
107107
if let Some(snippet) = snippet_opt(cx, header_span);
108108
then {
@@ -154,7 +154,7 @@ fn check_manual_non_exhaustive_struct(cx: &EarlyContext<'_>, item: &Item, data:
154154
"this seems like a manual implementation of the non-exhaustive pattern",
155155
|diag| {
156156
if_chain! {
157-
if !attr::contains_name(&item.attrs, sym!(non_exhaustive));
157+
if !item.attrs.iter().any(|attr| attr.has_name(sym!(non_exhaustive)));
158158
let header_span = find_header_span(cx, item, data);
159159
if let Some(snippet) = snippet_opt(cx, header_span);
160160
then {

clippy_lints/src/non_expressive_names.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::utils::{span_lint, span_lint_and_then};
22
use rustc_ast::ast::{
33
Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, MacCall, Pat, PatKind,
44
};
5-
use rustc_ast::attr;
65
use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor};
76
use rustc_lint::{EarlyContext, EarlyLintPass};
87
use rustc_middle::lint::in_external_macro;
@@ -385,7 +384,7 @@ impl EarlyLintPass for NonExpressiveNames {
385384
}
386385

387386
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {
388-
if !attr::contains_name(attrs, sym!(test)) {
387+
if !attrs.iter().any(|attr| attr.has_name(sym!(test))) {
389388
let mut visitor = SimilarNamesLocalVisitor {
390389
names: Vec::new(),
391390
cx,

clippy_lints/src/utils/attrs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_ast::ast;
2-
use rustc_ast::expand::is_proc_macro_attr;
32
use rustc_errors::Applicability;
43
use rustc_session::Session;
54
use std::str::FromStr;
@@ -126,6 +125,6 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
126125

127126
/// Return true if the attributes contain any of `proc_macro`,
128127
/// `proc_macro_derive` or `proc_macro_attribute`, false otherwise
129-
pub fn is_proc_macro(attrs: &[ast::Attribute]) -> bool {
130-
attrs.iter().any(is_proc_macro_attr)
128+
pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool {
129+
attrs.iter().any(|attr| sess.is_proc_macro_attr(attr))
131130
}

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
932932
/// Checks for the `#[automatically_derived]` attribute all `#[derive]`d
933933
/// implementations have.
934934
pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool {
935-
attr::contains_name(attrs, sym!(automatically_derived))
935+
attrs.iter().any(|attr| attr.has_name(sym!(automatically_derived)))
936936
}
937937

938938
/// Remove blocks around an expression.

0 commit comments

Comments
 (0)