Rollup merge of #109358 - petrochenkov:nosess, r=cjgillot

rustc: Remove unused `Session` argument from some attribute functions

(One auxiliary test file containing one of these functions was unused, so I removed it instead of updating.)
This commit is contained in:
Matthias Krüger 2023-03-22 22:44:41 +01:00 committed by GitHub
commit 577d85f92f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 173 additions and 299 deletions

View file

@ -28,7 +28,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
} else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
} else if is_public && !is_proc_macro(attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
check_must_use_candidate(
cx,
sig.decl,
@ -51,7 +51,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
} else if is_public
&& !is_proc_macro(cx.sess(), attrs)
&& !is_proc_macro(attrs)
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
{
check_must_use_candidate(
@ -78,7 +78,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
} else if let hir::TraitFn::Provided(eid) = *eid {
let body = cx.tcx.hir().body(eid);
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) {
if attr.is_none() && is_public && !is_proc_macro(attrs) {
check_must_use_candidate(
cx,
sig.decl,

View file

@ -145,8 +145,8 @@ pub fn get_unique_attr<'a>(
/// Return true if the attributes contain any of `proc_macro`,
/// `proc_macro_derive` or `proc_macro_attribute`, false otherwise
pub fn is_proc_macro(sess: &Session, attrs: &[ast::Attribute]) -> bool {
attrs.iter().any(|attr| sess.is_proc_macro_attr(attr))
pub fn is_proc_macro(attrs: &[ast::Attribute]) -> bool {
attrs.iter().any(|attr| attr.is_proc_macro_attr())
}
/// Return true if the attributes contain `#[doc(hidden)]`

View file

@ -2,7 +2,7 @@
use rustc_ast::ast;
use rustc_ast::HasAttrs;
use rustc_span::{symbol::sym, Span, Symbol};
use rustc_span::{symbol::sym, Span};
use self::doc_comment::DocCommentFormatter;
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
@ -19,20 +19,6 @@ use crate::utils::{count_newlines, mk_sp};
mod doc_comment;
pub(crate) fn contains_name(attrs: &[ast::Attribute], name: Symbol) -> bool {
attrs.iter().any(|attr| attr.has_name(name))
}
pub(crate) fn first_attr_value_str_by_name(
attrs: &[ast::Attribute],
name: Symbol,
) -> Option<Symbol> {
attrs
.iter()
.find(|attr| attr.has_name(name))
.and_then(|attr| attr.value_str())
}
/// Returns attributes on the given statement.
pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
stmt.attrs()

View file

@ -2,13 +2,12 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
use std::path::{Path, PathBuf};
use rustc_ast::token::TokenKind;
use rustc_ast::{ast, ptr};
use rustc_ast::{ast, attr, ptr};
use rustc_errors::Diagnostic;
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
use rustc_span::{sym, Span};
use thin_vec::ThinVec;
use crate::attr::first_attr_value_str_by_name;
use crate::parse::session::ParseSess;
use crate::Input;
@ -93,7 +92,7 @@ pub(crate) enum ParserError {
impl<'a> Parser<'a> {
pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) -> Option<PathBuf> {
let path_sym = first_attr_value_str_by_name(attrs, sym::path)?;
let path_sym = attr::first_attr_value_str_by_name(attrs, sym::path)?;
let path_str = path_sym.as_str();
// On windows, the base path might have the form

View file

@ -8,7 +8,7 @@
use std::cmp::{Ord, Ordering};
use rustc_ast::ast;
use rustc_ast::{ast, attr};
use rustc_span::{symbol::sym, Span};
use crate::config::{Config, GroupImportsTactic};
@ -167,7 +167,7 @@ fn rewrite_reorderable_or_regroupable_items(
}
fn contains_macro_use_attr(item: &ast::Item) -> bool {
crate::attr::contains_name(&item.attrs, sym::macro_use)
attr::contains_name(&item.attrs, sym::macro_use)
}
/// Divides imports into three groups, corresponding to standard, external