expand: Remove some unnecessary self
mutability
This commit is contained in:
parent
dc7e771155
commit
4fd23350cd
@ -238,7 +238,7 @@ macro_rules! configure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StripUnconfigured<'a> {
|
impl<'a> StripUnconfigured<'a> {
|
||||||
pub fn configure<T: AstLike>(&mut self, mut node: T) -> Option<T> {
|
pub fn configure<T: AstLike>(&self, mut node: T) -> Option<T> {
|
||||||
self.process_cfg_attrs(&mut node);
|
self.process_cfg_attrs(&mut node);
|
||||||
if self.in_cfg(node.attrs()) {
|
if self.in_cfg(node.attrs()) {
|
||||||
self.try_configure_tokens(&mut node);
|
self.try_configure_tokens(&mut node);
|
||||||
@ -248,7 +248,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_configure_tokens<T: AstLike>(&mut self, node: &mut T) {
|
fn try_configure_tokens<T: AstLike>(&self, node: &mut T) {
|
||||||
if self.config_tokens {
|
if self.config_tokens {
|
||||||
if let Some(Some(tokens)) = node.tokens_mut() {
|
if let Some(Some(tokens)) = node.tokens_mut() {
|
||||||
let attr_annotated_tokens = tokens.create_token_stream();
|
let attr_annotated_tokens = tokens.create_token_stream();
|
||||||
@ -257,10 +257,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_krate_attrs(
|
fn configure_krate_attrs(&self, mut attrs: Vec<ast::Attribute>) -> Option<Vec<ast::Attribute>> {
|
||||||
&mut self,
|
|
||||||
mut attrs: Vec<ast::Attribute>,
|
|
||||||
) -> Option<Vec<ast::Attribute>> {
|
|
||||||
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
|
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
|
||||||
if self.in_cfg(&attrs) { Some(attrs) } else { None }
|
if self.in_cfg(&attrs) { Some(attrs) } else { None }
|
||||||
}
|
}
|
||||||
@ -269,7 +266,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
/// This is only used during the invocation of `derive` proc-macros,
|
/// This is only used during the invocation of `derive` proc-macros,
|
||||||
/// which require that we cfg-expand their entire input.
|
/// which require that we cfg-expand their entire input.
|
||||||
/// Normal cfg-expansion operates on parsed AST nodes via the `configure` method
|
/// Normal cfg-expansion operates on parsed AST nodes via the `configure` method
|
||||||
fn configure_tokens(&mut self, stream: &AttrAnnotatedTokenStream) -> AttrAnnotatedTokenStream {
|
fn configure_tokens(&self, stream: &AttrAnnotatedTokenStream) -> AttrAnnotatedTokenStream {
|
||||||
fn can_skip(stream: &AttrAnnotatedTokenStream) -> bool {
|
fn can_skip(stream: &AttrAnnotatedTokenStream) -> bool {
|
||||||
stream.0.iter().all(|(tree, _spacing)| match tree {
|
stream.0.iter().all(|(tree, _spacing)| match tree {
|
||||||
AttrAnnotatedTokenTree::Attributes(_) => false,
|
AttrAnnotatedTokenTree::Attributes(_) => false,
|
||||||
@ -325,7 +322,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
/// Gives compiler warnings if any `cfg_attr` does not contain any
|
/// Gives compiler warnings if any `cfg_attr` does not contain any
|
||||||
/// attributes and is in the original source code. Gives compiler errors if
|
/// attributes and is in the original source code. Gives compiler errors if
|
||||||
/// the syntax of any `cfg_attr` is incorrect.
|
/// the syntax of any `cfg_attr` is incorrect.
|
||||||
fn process_cfg_attrs<T: AstLike>(&mut self, node: &mut T) {
|
fn process_cfg_attrs<T: AstLike>(&self, node: &mut T) {
|
||||||
node.visit_attrs(|attrs| {
|
node.visit_attrs(|attrs| {
|
||||||
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
|
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
|
||||||
});
|
});
|
||||||
@ -338,7 +335,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
|
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
|
||||||
/// is in the original source file. Gives a compiler error if the syntax of
|
/// is in the original source file. Gives a compiler error if the syntax of
|
||||||
/// the attribute is incorrect.
|
/// the attribute is incorrect.
|
||||||
fn process_cfg_attr(&mut self, attr: Attribute) -> Vec<Attribute> {
|
fn process_cfg_attr(&self, attr: Attribute) -> Vec<Attribute> {
|
||||||
if !attr.has_name(sym::cfg_attr) {
|
if !attr.has_name(sym::cfg_attr) {
|
||||||
return vec![attr];
|
return vec![attr];
|
||||||
}
|
}
|
||||||
@ -461,7 +458,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure_expr(&mut self, expr: &mut P<ast::Expr>) {
|
pub fn configure_expr(&self, expr: &mut P<ast::Expr>) {
|
||||||
for attr in expr.attrs.iter() {
|
for attr in expr.attrs.iter() {
|
||||||
self.maybe_emit_expr_attr_err(attr);
|
self.maybe_emit_expr_attr_err(attr);
|
||||||
}
|
}
|
||||||
|
@ -1007,7 +1007,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||||||
/// its position and derives following it. We have to collect the derives in order to resolve
|
/// its position and derives following it. We have to collect the derives in order to resolve
|
||||||
/// legacy derive helpers (helpers written before derives that introduce them).
|
/// legacy derive helpers (helpers written before derives that introduce them).
|
||||||
fn take_first_attr(
|
fn take_first_attr(
|
||||||
&mut self,
|
&self,
|
||||||
item: &mut impl AstLike,
|
item: &mut impl AstLike,
|
||||||
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
|
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
|
||||||
let mut attr = None;
|
let mut attr = None;
|
||||||
@ -1040,7 +1040,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn take_stmt_bang(
|
fn take_stmt_bang(
|
||||||
&mut self,
|
&self,
|
||||||
stmt: ast::Stmt,
|
stmt: ast::Stmt,
|
||||||
) -> Result<(bool, MacCall, Vec<ast::Attribute>), ast::Stmt> {
|
) -> Result<(bool, MacCall, Vec<ast::Attribute>), ast::Stmt> {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
@ -1071,7 +1071,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure<T: AstLike>(&mut self, node: T) -> Option<T> {
|
fn configure<T: AstLike>(&self, node: T) -> Option<T> {
|
||||||
self.cfg.configure(node)
|
self.cfg.configure(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user