Merge from rustc
This commit is contained in:
commit
9510f7eb2c
16
src/attr.rs
16
src/attr.rs
@ -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 @@
|
||||
|
||||
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()
|
||||
|
@ -2,13 +2,12 @@
|
||||
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user