Skip to content

Commit 8d820c0

Browse files
authored
Rollup merge of rust-lang#123188 - klensy:clippy-me2, r=Nilstrieb
compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints This fixes few instances of `unused_peekable` and `needless_pass_by_ref_mut`. While i expected to fix more warnings, `needless_pass_by_ref_mut` produced too much for one PR, so i stopped here. Better reviewed commit by commit, as fixes splitted by chunks.
2 parents a18da00 + 8245718 commit 8d820c0

File tree

40 files changed

+111
-120
lines changed

40 files changed

+111
-120
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15521552
/// When encountering an equality constraint in a `where` clause, emit an error. If the code seems
15531553
/// like it's setting an associated type, provide an appropriate suggestion.
15541554
fn deny_equality_constraints(
1555-
this: &mut AstValidator<'_>,
1555+
this: &AstValidator<'_>,
15561556
predicate: &WhereEqPredicate,
15571557
generics: &Generics,
15581558
) {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
337337
}
338338

339339
fn suggest_ref_or_clone(
340-
&mut self,
340+
&self,
341341
mpi: MovePathIndex,
342342
move_span: Span,
343343
err: &mut Diag<'tcx>,
@@ -1125,7 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11251125
}
11261126

11271127
pub(crate) fn report_use_while_mutably_borrowed(
1128-
&mut self,
1128+
&self,
11291129
location: Location,
11301130
(place, _span): (Place<'tcx>, Span),
11311131
borrow: &BorrowData<'tcx>,
@@ -1174,7 +1174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11741174
}
11751175

11761176
pub(crate) fn report_conflicting_borrow(
1177-
&mut self,
1177+
&self,
11781178
location: Location,
11791179
(place, span): (Place<'tcx>, Span),
11801180
gen_borrow_kind: BorrowKind,
@@ -2463,7 +2463,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24632463
}
24642464

24652465
fn report_local_value_does_not_live_long_enough(
2466-
&mut self,
2466+
&self,
24672467
location: Location,
24682468
name: &str,
24692469
borrow: &BorrowData<'tcx>,
@@ -2642,7 +2642,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26422642
}
26432643

26442644
fn report_thread_local_value_does_not_live_long_enough(
2645-
&mut self,
2645+
&self,
26462646
drop_span: Span,
26472647
borrow_span: Span,
26482648
) -> Diag<'tcx> {
@@ -2663,7 +2663,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26632663

26642664
#[instrument(level = "debug", skip(self))]
26652665
fn report_temporary_value_does_not_live_long_enough(
2666-
&mut self,
2666+
&self,
26672667
location: Location,
26682668
borrow: &BorrowData<'tcx>,
26692669
drop_span: Span,
@@ -2921,7 +2921,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29212921

29222922
#[instrument(level = "debug", skip(self))]
29232923
fn report_escaping_closure_capture(
2924-
&mut self,
2924+
&self,
29252925
use_span: UseSpans<'tcx>,
29262926
var_span: Span,
29272927
fr_name: &RegionName,
@@ -3031,7 +3031,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30313031
}
30323032

30333033
fn report_escaping_data(
3034-
&mut self,
3034+
&self,
30353035
borrow_span: Span,
30363036
name: &Option<String>,
30373037
upvar_span: Span,
@@ -3065,7 +3065,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30653065
}
30663066

30673067
fn get_moved_indexes(
3068-
&mut self,
3068+
&self,
30693069
location: Location,
30703070
mpi: MovePathIndex,
30713071
) -> (Vec<MoveSite>, Vec<Location>) {
@@ -3854,7 +3854,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
38543854
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
38553855
/// Annotate the provided diagnostic with information about borrow from the fn signature that
38563856
/// helps explain.
3857-
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
3857+
pub(crate) fn emit(&self, cx: &MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
38583858
match self {
38593859
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
38603860
diag.span_label(

compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
8787
body: &Body<'tcx>,
8888
location_table: &LocationTable,
8989
move_data: &MoveData<'tcx>,
90+
//FIXME: this is not mutated, but expected to be modified as
91+
// out param, bug?
9092
dropped_at: &mut Vec<(Local, Location)>,
9193
) {
9294
debug!("populate_access_facts()");

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
200200
for local in boring_locals {
201201
let local_ty = self.cx.body.local_decls[local].ty;
202202
let drop_data = self.cx.drop_data.entry(local_ty).or_insert_with({
203-
let typeck = &mut self.cx.typeck;
203+
let typeck = &self.cx.typeck;
204204
move || LivenessContext::compute_drop_data(typeck, local_ty)
205205
});
206206

@@ -542,7 +542,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
542542
);
543543

544544
let drop_data = self.drop_data.entry(dropped_ty).or_insert_with({
545-
let typeck = &mut self.typeck;
545+
let typeck = &self.typeck;
546546
move || Self::compute_drop_data(typeck, dropped_ty)
547547
});
548548

@@ -597,10 +597,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
597597
});
598598
}
599599

600-
fn compute_drop_data(
601-
typeck: &mut TypeChecker<'_, 'tcx>,
602-
dropped_ty: Ty<'tcx>,
603-
) -> DropData<'tcx> {
600+
fn compute_drop_data(typeck: &TypeChecker<'_, 'tcx>, dropped_ty: Ty<'tcx>) -> DropData<'tcx> {
604601
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
605602

606603
match typeck

compiler/rustc_builtin_macros/src/asm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct AsmArgs {
2929
}
3030

3131
fn parse_args<'a>(
32-
ecx: &mut ExtCtxt<'a>,
32+
ecx: &ExtCtxt<'a>,
3333
sp: Span,
3434
tts: TokenStream,
3535
is_global_asm: bool,
@@ -303,7 +303,7 @@ pub fn parse_asm_args<'a>(
303303
///
304304
/// This function must be called immediately after the option token is parsed.
305305
/// Otherwise, the suggestion will be incorrect.
306-
fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
306+
fn err_duplicate_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
307307
// Tool-only output
308308
let full_span = if p.token.kind == token::Comma { span.to(p.token.span) } else { span };
309309
p.psess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
@@ -315,7 +315,7 @@ fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
315315
/// This function must be called immediately after the option token is parsed.
316316
/// Otherwise, the error will not point to the correct spot.
317317
fn try_set_option<'a>(
318-
p: &mut Parser<'a>,
318+
p: &Parser<'a>,
319319
args: &mut AsmArgs,
320320
symbol: Symbol,
321321
option: ast::InlineAsmOptions,

compiler/rustc_builtin_macros/src/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn expr_if_not(
111111
cx.expr_if(span, cx.expr(span, ExprKind::Unary(UnOp::Not, cond)), then, els)
112112
}
113113

114-
fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {
114+
fn parse_assert<'a>(cx: &ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {
115115
let mut parser = cx.new_parser_from_tts(stream);
116116

117117
if parser.token == token::Eof {

compiler/rustc_builtin_macros/src/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_cfg(
3535
})
3636
}
3737

38-
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
38+
fn parse_cfg<'a>(cx: &ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
3939
let mut p = cx.new_parser_from_tts(tts);
4040

4141
if p.token == token::Eof {

compiler/rustc_builtin_macros/src/cfg_accessible.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Span;
1010

1111
pub(crate) struct Expander;
1212

13-
fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
13+
fn validate_input<'a>(ecx: &ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
1414
use errors::CfgAccessibleInvalid::*;
1515
match mi.meta_item_list() {
1616
None => {}

compiler/rustc_builtin_macros/src/concat_bytes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::errors;
88

99
/// Emits errors for literal expressions that are invalid inside and outside of an array.
1010
fn invalid_type_err(
11-
cx: &mut ExtCtxt<'_>,
11+
cx: &ExtCtxt<'_>,
1212
token_lit: token::Lit,
1313
span: Span,
1414
is_nested: bool,
@@ -65,7 +65,7 @@ fn invalid_type_err(
6565
/// Otherwise, returns `None`, and either pushes the `expr`'s span to `missing_literals` or
6666
/// updates `guar` accordingly.
6767
fn handle_array_element(
68-
cx: &mut ExtCtxt<'_>,
68+
cx: &ExtCtxt<'_>,
6969
guar: &mut Option<ErrorGuaranteed>,
7070
missing_literals: &mut Vec<rustc_span::Span>,
7171
expr: &P<rustc_ast::Expr>,

compiler/rustc_builtin_macros/src/deriving/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::Span;
77

88
pub fn expand_deriving_copy(
9-
cx: &mut ExtCtxt<'_>,
9+
cx: &ExtCtxt<'_>,
1010
span: Span,
1111
mitem: &MetaItem,
1212
item: &Annotatable,
@@ -29,7 +29,7 @@ pub fn expand_deriving_copy(
2929
}
3030

3131
pub fn expand_deriving_const_param_ty(
32-
cx: &mut ExtCtxt<'_>,
32+
cx: &ExtCtxt<'_>,
3333
span: Span,
3434
mitem: &MetaItem,
3535
item: &Annotatable,

compiler/rustc_builtin_macros/src/deriving/clone.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::Span;
99
use thin_vec::{thin_vec, ThinVec};
1010

1111
pub fn expand_deriving_clone(
12-
cx: &mut ExtCtxt<'_>,
12+
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,
1515
item: &Annotatable,
@@ -94,7 +94,7 @@ pub fn expand_deriving_clone(
9494

9595
fn cs_clone_simple(
9696
name: &str,
97-
cx: &mut ExtCtxt<'_>,
97+
cx: &ExtCtxt<'_>,
9898
trait_span: Span,
9999
substr: &Substructure<'_>,
100100
is_union: bool,
@@ -157,14 +157,14 @@ fn cs_clone_simple(
157157

158158
fn cs_clone(
159159
name: &str,
160-
cx: &mut ExtCtxt<'_>,
160+
cx: &ExtCtxt<'_>,
161161
trait_span: Span,
162162
substr: &Substructure<'_>,
163163
) -> BlockOrExpr {
164164
let ctor_path;
165165
let all_fields;
166166
let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]);
167-
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo| {
167+
let subcall = |cx: &ExtCtxt<'_>, field: &FieldInfo| {
168168
let args = thin_vec![field.self_expr.clone()];
169169
cx.expr_call_global(field.span, fn_path.clone(), args)
170170
};

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Span;
1010
use thin_vec::{thin_vec, ThinVec};
1111

1212
pub fn expand_deriving_eq(
13-
cx: &mut ExtCtxt<'_>,
13+
cx: &ExtCtxt<'_>,
1414
span: Span,
1515
mitem: &MetaItem,
1616
item: &Annotatable,
@@ -49,7 +49,7 @@ pub fn expand_deriving_eq(
4949
}
5050

5151
fn cs_total_eq_assert(
52-
cx: &mut ExtCtxt<'_>,
52+
cx: &ExtCtxt<'_>,
5353
trait_span: Span,
5454
substr: &Substructure<'_>,
5555
) -> BlockOrExpr {

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88
use thin_vec::thin_vec;
99

1010
pub fn expand_deriving_ord(
11-
cx: &mut ExtCtxt<'_>,
11+
cx: &ExtCtxt<'_>,
1212
span: Span,
1313
mitem: &MetaItem,
1414
item: &Annotatable,
@@ -39,7 +39,7 @@ pub fn expand_deriving_ord(
3939
trait_def.expand(cx, mitem, item, push)
4040
}
4141

42-
pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
42+
pub fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
4343
let test_id = Ident::new(sym::cmp, span);
4444
let equal_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
4545
let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use rustc_span::Span;
99
use thin_vec::thin_vec;
1010

1111
pub fn expand_deriving_partial_eq(
12-
cx: &mut ExtCtxt<'_>,
12+
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,
1515
item: &Annotatable,
1616
push: &mut dyn FnMut(Annotatable),
1717
is_const: bool,
1818
) {
19-
fn cs_eq(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
19+
fn cs_eq(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
2020
let base = true;
2121
let expr = cs_fold(
2222
true, // use foldl

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88
use thin_vec::thin_vec;
99

1010
pub fn expand_deriving_partial_ord(
11-
cx: &mut ExtCtxt<'_>,
11+
cx: &ExtCtxt<'_>,
1212
span: Span,
1313
mitem: &MetaItem,
1414
item: &Annotatable,
@@ -69,7 +69,7 @@ pub fn expand_deriving_partial_ord(
6969
}
7070

7171
fn cs_partial_cmp(
72-
cx: &mut ExtCtxt<'_>,
72+
cx: &ExtCtxt<'_>,
7373
span: Span,
7474
substr: &Substructure<'_>,
7575
tag_then_data: bool,

compiler/rustc_builtin_macros/src/deriving/debug.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::Span;
99
use thin_vec::{thin_vec, ThinVec};
1010

1111
pub fn expand_deriving_debug(
12-
cx: &mut ExtCtxt<'_>,
12+
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,
1515
item: &Annotatable,
@@ -45,7 +45,7 @@ pub fn expand_deriving_debug(
4545
trait_def.expand(cx, mitem, item, push)
4646
}
4747

48-
fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
48+
fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
4949
// We want to make sure we have the ctxt set so that we can use unstable methods
5050
let span = cx.with_def_site_ctxt(span);
5151

@@ -209,7 +209,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
209209
/// }
210210
/// ```
211211
fn show_fieldless_enum(
212-
cx: &mut ExtCtxt<'_>,
212+
cx: &ExtCtxt<'_>,
213213
span: Span,
214214
def: &EnumDef,
215215
substr: &Substructure<'_>,

compiler/rustc_builtin_macros/src/deriving/decodable.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_span::Span;
1111
use thin_vec::{thin_vec, ThinVec};
1212

1313
pub fn expand_deriving_rustc_decodable(
14-
cx: &mut ExtCtxt<'_>,
14+
cx: &ExtCtxt<'_>,
1515
span: Span,
1616
mitem: &MetaItem,
1717
item: &Annotatable,
@@ -63,7 +63,7 @@ pub fn expand_deriving_rustc_decodable(
6363
}
6464

6565
fn decodable_substructure(
66-
cx: &mut ExtCtxt<'_>,
66+
cx: &ExtCtxt<'_>,
6767
trait_span: Span,
6868
substr: &Substructure<'_>,
6969
krate: Symbol,
@@ -186,14 +186,14 @@ fn decodable_substructure(
186186
/// - `outer_pat_path` is the path to this enum variant/struct
187187
/// - `getarg` should retrieve the `usize`-th field with name `@str`.
188188
fn decode_static_fields<F>(
189-
cx: &mut ExtCtxt<'_>,
189+
cx: &ExtCtxt<'_>,
190190
trait_span: Span,
191191
outer_pat_path: ast::Path,
192192
fields: &StaticFields,
193193
mut getarg: F,
194194
) -> P<Expr>
195195
where
196-
F: FnMut(&mut ExtCtxt<'_>, Span, Symbol, usize) -> P<Expr>,
196+
F: FnMut(&ExtCtxt<'_>, Span, Symbol, usize) -> P<Expr>,
197197
{
198198
match fields {
199199
Unnamed(fields, is_tuple) => {

0 commit comments

Comments
 (0)