rustc: Remove unused Session
argument from some attribute functions
This commit is contained in:
parent
9bdb4881c7
commit
67a2c5bec8
37 changed files with 173 additions and 299 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::{walk_list, EnumDef, VariantData};
|
||||
use rustc_ast::{attr, walk_list, EnumDef, VariantData};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt};
|
||||
use rustc_span::symbol::Ident;
|
||||
|
@ -106,7 +106,7 @@ fn extract_default_variant<'a>(
|
|||
let default_variants: SmallVec<[_; 1]> = enum_def
|
||||
.variants
|
||||
.iter()
|
||||
.filter(|variant| cx.sess.contains_name(&variant.attrs, kw::Default))
|
||||
.filter(|variant| attr::contains_name(&variant.attrs, kw::Default))
|
||||
.collect();
|
||||
|
||||
let variant = match default_variants.as_slice() {
|
||||
|
@ -116,7 +116,7 @@ fn extract_default_variant<'a>(
|
|||
.variants
|
||||
.iter()
|
||||
.filter(|variant| matches!(variant.data, VariantData::Unit(..)))
|
||||
.filter(|variant| !cx.sess.contains_name(&variant.attrs, sym::non_exhaustive));
|
||||
.filter(|variant| !attr::contains_name(&variant.attrs, sym::non_exhaustive));
|
||||
|
||||
let mut diag = cx.struct_span_err(trait_span, "no default declared");
|
||||
diag.help("make a unit variant default by placing `#[default]` above it");
|
||||
|
@ -146,7 +146,7 @@ fn extract_default_variant<'a>(
|
|||
if v.span == variant.span {
|
||||
None
|
||||
} else {
|
||||
Some((cx.sess.find_by_name(&v.attrs, kw::Default)?.span, String::new()))
|
||||
Some((attr::find_by_name(&v.attrs, kw::Default)?.span, String::new()))
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
@ -174,7 +174,7 @@ fn extract_default_variant<'a>(
|
|||
return Err(());
|
||||
}
|
||||
|
||||
if let Some(non_exhaustive_attr) = cx.sess.find_by_name(&variant.attrs, sym::non_exhaustive) {
|
||||
if let Some(non_exhaustive_attr) = attr::find_by_name(&variant.attrs, sym::non_exhaustive) {
|
||||
cx.struct_span_err(variant.ident.span, "default variant must be exhaustive")
|
||||
.span_label(non_exhaustive_attr.span, "declared `#[non_exhaustive]` here")
|
||||
.help("consider a manual implementation of `Default`")
|
||||
|
@ -191,7 +191,7 @@ fn validate_default_attribute(
|
|||
default_variant: &rustc_ast::Variant,
|
||||
) -> Result<(), ()> {
|
||||
let attrs: SmallVec<[_; 1]> =
|
||||
cx.sess.filter_by_name(&default_variant.attrs, kw::Default).collect();
|
||||
attr::filter_by_name(&default_variant.attrs, kw::Default).collect();
|
||||
|
||||
let attr = match attrs.as_slice() {
|
||||
[attr] => attr,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{self, Visitor};
|
||||
use rustc_ast::{self as ast, NodeId};
|
||||
use rustc_ast::{self as ast, attr, NodeId};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_expand::base::{parse_macro_name_and_helper_attrs, ExtCtxt, ResolverExpand};
|
||||
use rustc_expand::expand::{AstFragment, ExpansionConfig};
|
||||
|
@ -34,7 +34,6 @@ enum ProcMacro {
|
|||
}
|
||||
|
||||
struct CollectProcMacros<'a> {
|
||||
sess: &'a Session,
|
||||
macros: Vec<ProcMacro>,
|
||||
in_root: bool,
|
||||
handler: &'a rustc_errors::Handler,
|
||||
|
@ -56,7 +55,6 @@ pub fn inject(
|
|||
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
|
||||
|
||||
let mut collect = CollectProcMacros {
|
||||
sess,
|
||||
macros: Vec::new(),
|
||||
in_root: true,
|
||||
handler,
|
||||
|
@ -160,7 +158,7 @@ impl<'a> CollectProcMacros<'a> {
|
|||
impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
||||
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||
if let ast::ItemKind::MacroDef(..) = item.kind {
|
||||
if self.is_proc_macro_crate && self.sess.contains_name(&item.attrs, sym::macro_export) {
|
||||
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
|
||||
let msg =
|
||||
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
|
||||
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
|
||||
|
@ -176,7 +174,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
|||
let mut found_attr: Option<&'a ast::Attribute> = None;
|
||||
|
||||
for attr in &item.attrs {
|
||||
if self.sess.is_proc_macro_attr(&attr) {
|
||||
if attr.is_proc_macro_attr() {
|
||||
if let Some(prev_attr) = found_attr {
|
||||
let prev_item = prev_attr.get_normal_item();
|
||||
let item = attr.get_normal_item();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_ast as ast;
|
||||
use rustc_ast::{self as ast, attr};
|
||||
use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
||||
use rustc_expand::expand::ExpansionConfig;
|
||||
use rustc_session::Session;
|
||||
|
@ -16,10 +16,10 @@ pub fn inject(
|
|||
let edition = sess.parse_sess.edition;
|
||||
|
||||
// the first name in this list is the crate name of the crate with the prelude
|
||||
let names: &[Symbol] = if sess.contains_name(&krate.attrs, sym::no_core) {
|
||||
let names: &[Symbol] = if attr::contains_name(&krate.attrs, sym::no_core) {
|
||||
return krate;
|
||||
} else if sess.contains_name(&krate.attrs, sym::no_std) {
|
||||
if sess.contains_name(&krate.attrs, sym::compiler_builtins) {
|
||||
} else if attr::contains_name(&krate.attrs, sym::no_std) {
|
||||
if attr::contains_name(&krate.attrs, sym::compiler_builtins) {
|
||||
&[sym::core]
|
||||
} else {
|
||||
&[sym::core, sym::compiler_builtins]
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/// The expansion from a test function to the appropriate test struct for libtest
|
||||
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
|
||||
use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, attr};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_expand::base::*;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{FileNameDisplayPreference, Span};
|
||||
use std::iter;
|
||||
|
@ -291,14 +290,11 @@ pub fn expand_test_or_bench(
|
|||
),
|
||||
),
|
||||
// ignore: true | false
|
||||
field(
|
||||
"ignore",
|
||||
cx.expr_bool(sp, should_ignore(&cx.sess, &item)),
|
||||
),
|
||||
field("ignore", cx.expr_bool(sp, should_ignore(&item)),),
|
||||
// ignore_message: Some("...") | None
|
||||
field(
|
||||
"ignore_message",
|
||||
if let Some(msg) = should_ignore_message(cx, &item) {
|
||||
if let Some(msg) = should_ignore_message(&item) {
|
||||
cx.expr_some(sp, cx.expr_str(sp, msg))
|
||||
} else {
|
||||
cx.expr_none(sp)
|
||||
|
@ -425,12 +421,12 @@ enum ShouldPanic {
|
|||
Yes(Option<Symbol>),
|
||||
}
|
||||
|
||||
fn should_ignore(sess: &Session, i: &ast::Item) -> bool {
|
||||
sess.contains_name(&i.attrs, sym::ignore)
|
||||
fn should_ignore(i: &ast::Item) -> bool {
|
||||
attr::contains_name(&i.attrs, sym::ignore)
|
||||
}
|
||||
|
||||
fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
|
||||
match cx.sess.find_by_name(&i.attrs, sym::ignore) {
|
||||
fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
|
||||
match attr::find_by_name(&i.attrs, sym::ignore) {
|
||||
Some(attr) => {
|
||||
match attr.meta_item_list() {
|
||||
// Handle #[ignore(bar = "foo")]
|
||||
|
@ -444,7 +440,7 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
|
|||
}
|
||||
|
||||
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
|
||||
match cx.sess.find_by_name(&i.attrs, sym::should_panic) {
|
||||
match attr::find_by_name(&i.attrs, sym::should_panic) {
|
||||
Some(attr) => {
|
||||
let sd = &cx.sess.parse_sess.span_diagnostic;
|
||||
|
||||
|
@ -510,7 +506,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
|
|||
}
|
||||
|
||||
fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
|
||||
let has_should_panic_attr = cx.sess.contains_name(&i.attrs, sym::should_panic);
|
||||
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
|
||||
let sd = &cx.sess.parse_sess.span_diagnostic;
|
||||
match &i.kind {
|
||||
ast::ItemKind::Fn(box ast::Fn { sig, generics, .. }) => {
|
||||
|
|
|
@ -47,11 +47,11 @@ pub fn inject(sess: &Session, resolver: &mut dyn ResolverExpand, krate: &mut ast
|
|||
// unconditional, so that the attribute is still marked as used in
|
||||
// non-test builds.
|
||||
let reexport_test_harness_main =
|
||||
sess.first_attr_value_str_by_name(&krate.attrs, sym::reexport_test_harness_main);
|
||||
attr::first_attr_value_str_by_name(&krate.attrs, sym::reexport_test_harness_main);
|
||||
|
||||
// Do this here so that the test_runner crate attribute gets marked as used
|
||||
// even in non-test builds
|
||||
let test_runner = get_test_runner(sess, span_diagnostic, &krate);
|
||||
let test_runner = get_test_runner(span_diagnostic, &krate);
|
||||
|
||||
if sess.opts.test {
|
||||
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
|
||||
|
@ -123,7 +123,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
|||
|
||||
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
let mut item = i.into_inner();
|
||||
if let Some(name) = get_test_name(&self.cx.ext_cx.sess, &item) {
|
||||
if let Some(name) = get_test_name(&item) {
|
||||
debug!("this is a test item");
|
||||
|
||||
let test = Test { span: item.span, ident: item.ident, name };
|
||||
|
@ -145,12 +145,12 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
|||
|
||||
// Beware, this is duplicated in librustc_passes/entry.rs (with
|
||||
// `rustc_hir::Item`), so make sure to keep them in sync.
|
||||
fn entry_point_type(sess: &Session, item: &ast::Item, depth: usize) -> EntryPointType {
|
||||
fn entry_point_type(item: &ast::Item, depth: usize) -> EntryPointType {
|
||||
match item.kind {
|
||||
ast::ItemKind::Fn(..) => {
|
||||
if sess.contains_name(&item.attrs, sym::start) {
|
||||
if attr::contains_name(&item.attrs, sym::start) {
|
||||
EntryPointType::Start
|
||||
} else if sess.contains_name(&item.attrs, sym::rustc_main) {
|
||||
} else if attr::contains_name(&item.attrs, sym::rustc_main) {
|
||||
EntryPointType::RustcMainAttr
|
||||
} else if item.ident.name == sym::main {
|
||||
if depth == 0 {
|
||||
|
@ -184,7 +184,7 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
|||
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
|
||||
// clash with the one we're going to add, but mark it as
|
||||
// #[allow(dead_code)] to avoid printing warnings.
|
||||
let item = match entry_point_type(self.sess, &item, self.depth) {
|
||||
let item = match entry_point_type(&item, self.depth) {
|
||||
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
|
||||
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
|
||||
let allow_dead_code = attr::mk_attr_nested_word(
|
||||
|
@ -373,16 +373,12 @@ fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
|
|||
)
|
||||
}
|
||||
|
||||
fn get_test_name(sess: &Session, i: &ast::Item) -> Option<Symbol> {
|
||||
sess.first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
|
||||
fn get_test_name(i: &ast::Item) -> Option<Symbol> {
|
||||
attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
|
||||
}
|
||||
|
||||
fn get_test_runner(
|
||||
sess: &Session,
|
||||
sd: &rustc_errors::Handler,
|
||||
krate: &ast::Crate,
|
||||
) -> Option<ast::Path> {
|
||||
let test_attr = sess.find_by_name(&krate.attrs, sym::test_runner)?;
|
||||
fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast::Path> {
|
||||
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
|
||||
let meta_list = test_attr.meta_item_list()?;
|
||||
let span = test_attr.span;
|
||||
match &*meta_list {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_ast::{AttrStyle, Attribute, MetaItem};
|
||||
use rustc_ast::{attr, AttrStyle, Attribute, MetaItem};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
|
||||
|
@ -36,7 +36,7 @@ pub fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name:
|
|||
_ => None,
|
||||
};
|
||||
if let Some(attrs) = attrs {
|
||||
if let Some(attr) = ecx.sess.find_by_name(attrs, name) {
|
||||
if let Some(attr) = attr::find_by_name(attrs, name) {
|
||||
ecx.parse_sess().buffer_lint(
|
||||
DUPLICATE_MACRO_ATTRIBUTES,
|
||||
attr.span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue