Skip to content

Commit

Permalink
rustc: Remove unused Session argument from some attribute functions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Mar 22, 2023
1 parent 4e658cc commit 809dd77
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
16 changes: 1 addition & 15 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 809dd77

Please sign in to comment.