Skip to content

Commit 4fd2335

Browse files
committed
expand: Remove some unnecessary self mutability
1 parent dc7e771 commit 4fd2335

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

compiler/rustc_expand/src/config.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ macro_rules! configure {
238238
}
239239

240240
impl<'a> StripUnconfigured<'a> {
241-
pub fn configure<T: AstLike>(&mut self, mut node: T) -> Option<T> {
241+
pub fn configure<T: AstLike>(&self, mut node: T) -> Option<T> {
242242
self.process_cfg_attrs(&mut node);
243243
if self.in_cfg(node.attrs()) {
244244
self.try_configure_tokens(&mut node);
@@ -248,7 +248,7 @@ impl<'a> StripUnconfigured<'a> {
248248
}
249249
}
250250

251-
fn try_configure_tokens<T: AstLike>(&mut self, node: &mut T) {
251+
fn try_configure_tokens<T: AstLike>(&self, node: &mut T) {
252252
if self.config_tokens {
253253
if let Some(Some(tokens)) = node.tokens_mut() {
254254
let attr_annotated_tokens = tokens.create_token_stream();
@@ -257,10 +257,7 @@ impl<'a> StripUnconfigured<'a> {
257257
}
258258
}
259259

260-
fn configure_krate_attrs(
261-
&mut self,
262-
mut attrs: Vec<ast::Attribute>,
263-
) -> Option<Vec<ast::Attribute>> {
260+
fn configure_krate_attrs(&self, mut attrs: Vec<ast::Attribute>) -> Option<Vec<ast::Attribute>> {
264261
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
265262
if self.in_cfg(&attrs) { Some(attrs) } else { None }
266263
}
@@ -269,7 +266,7 @@ impl<'a> StripUnconfigured<'a> {
269266
/// This is only used during the invocation of `derive` proc-macros,
270267
/// which require that we cfg-expand their entire input.
271268
/// Normal cfg-expansion operates on parsed AST nodes via the `configure` method
272-
fn configure_tokens(&mut self, stream: &AttrAnnotatedTokenStream) -> AttrAnnotatedTokenStream {
269+
fn configure_tokens(&self, stream: &AttrAnnotatedTokenStream) -> AttrAnnotatedTokenStream {
273270
fn can_skip(stream: &AttrAnnotatedTokenStream) -> bool {
274271
stream.0.iter().all(|(tree, _spacing)| match tree {
275272
AttrAnnotatedTokenTree::Attributes(_) => false,
@@ -325,7 +322,7 @@ impl<'a> StripUnconfigured<'a> {
325322
/// Gives compiler warnings if any `cfg_attr` does not contain any
326323
/// attributes and is in the original source code. Gives compiler errors if
327324
/// the syntax of any `cfg_attr` is incorrect.
328-
fn process_cfg_attrs<T: AstLike>(&mut self, node: &mut T) {
325+
fn process_cfg_attrs<T: AstLike>(&self, node: &mut T) {
329326
node.visit_attrs(|attrs| {
330327
attrs.flat_map_in_place(|attr| self.process_cfg_attr(attr));
331328
});
@@ -338,7 +335,7 @@ impl<'a> StripUnconfigured<'a> {
338335
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
339336
/// is in the original source file. Gives a compiler error if the syntax of
340337
/// the attribute is incorrect.
341-
fn process_cfg_attr(&mut self, attr: Attribute) -> Vec<Attribute> {
338+
fn process_cfg_attr(&self, attr: Attribute) -> Vec<Attribute> {
342339
if !attr.has_name(sym::cfg_attr) {
343340
return vec![attr];
344341
}
@@ -461,7 +458,7 @@ impl<'a> StripUnconfigured<'a> {
461458
}
462459
}
463460

464-
pub fn configure_expr(&mut self, expr: &mut P<ast::Expr>) {
461+
pub fn configure_expr(&self, expr: &mut P<ast::Expr>) {
465462
for attr in expr.attrs.iter() {
466463
self.maybe_emit_expr_attr_err(attr);
467464
}

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10071007
/// its position and derives following it. We have to collect the derives in order to resolve
10081008
/// legacy derive helpers (helpers written before derives that introduce them).
10091009
fn take_first_attr(
1010-
&mut self,
1010+
&self,
10111011
item: &mut impl AstLike,
10121012
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
10131013
let mut attr = None;
@@ -1040,7 +1040,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10401040
}
10411041

10421042
fn take_stmt_bang(
1043-
&mut self,
1043+
&self,
10441044
stmt: ast::Stmt,
10451045
) -> Result<(bool, MacCall, Vec<ast::Attribute>), ast::Stmt> {
10461046
match stmt.kind {
@@ -1071,7 +1071,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10711071
}
10721072
}
10731073

1074-
fn configure<T: AstLike>(&mut self, node: T) -> Option<T> {
1074+
fn configure<T: AstLike>(&self, node: T) -> Option<T> {
10751075
self.cfg.configure(node)
10761076
}
10771077

0 commit comments

Comments
 (0)