Skip to content

Commit f2b97a8

Browse files
committed
Remove useless borrows and derefs
1 parent 9c0bc30 commit f2b97a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+145
-146
lines changed

compiler/rustc_abi/src/layout.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub trait LayoutCalculator {
354354
if !always_sized { StructKind::MaybeUnsized } else { StructKind::AlwaysSized }
355355
};
356356

357-
let mut st = self.univariant(dl, &variants[v], &repr, kind)?;
357+
let mut st = self.univariant(dl, &variants[v], repr, kind)?;
358358
st.variants = Variants::Single { index: v };
359359

360360
if is_unsafe_cell {
@@ -457,7 +457,7 @@ pub trait LayoutCalculator {
457457
let mut variant_layouts = variants
458458
.iter_enumerated()
459459
.map(|(j, v)| {
460-
let mut st = self.univariant(dl, v, &repr, StructKind::AlwaysSized)?;
460+
let mut st = self.univariant(dl, v, repr, StructKind::AlwaysSized)?;
461461
st.variants = Variants::Single { index: j };
462462

463463
align = align.max(st.align);
@@ -647,8 +647,8 @@ pub trait LayoutCalculator {
647647
.map(|(i, field_layouts)| {
648648
let mut st = self.univariant(
649649
dl,
650-
&field_layouts,
651-
&repr,
650+
field_layouts,
651+
repr,
652652
StructKind::Prefixed(min_ity.size(), prefix_align),
653653
)?;
654654
st.variants = Variants::Single { index: i };
@@ -755,7 +755,7 @@ pub trait LayoutCalculator {
755755
// Try to use a ScalarPair for all tagged enums.
756756
let mut common_prim = None;
757757
let mut common_prim_initialized_in_all_variants = true;
758-
for (field_layouts, layout_variant) in iter::zip(&*variants, &layout_variants) {
758+
for (field_layouts, layout_variant) in iter::zip(variants, &layout_variants) {
759759
let FieldsShape::Arbitrary { ref offsets, .. } = layout_variant.fields else {
760760
panic!();
761761
};

compiler/rustc_ast/src/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ impl Expr {
11791179
pub fn peel_parens(&self) -> &Expr {
11801180
let mut expr = self;
11811181
while let ExprKind::Paren(inner) = &expr.kind {
1182-
expr = &inner;
1182+
expr = inner;
11831183
}
11841184
expr
11851185
}
@@ -2027,7 +2027,7 @@ impl Ty {
20272027
pub fn peel_refs(&self) -> &Self {
20282028
let mut final_ty = self;
20292029
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
2030-
final_ty = &ty;
2030+
final_ty = ty;
20312031
}
20322032
final_ty
20332033
}

compiler/rustc_ast/src/mut_visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,7 @@ pub fn visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
740740
return; // Avoid visiting the span for the second time.
741741
}
742742
token::Interpolated(nt) => {
743-
let mut nt = Lrc::make_mut(nt);
744-
visit_nonterminal(&mut nt, vis);
743+
visit_nonterminal(Lrc::make_mut(nt), vis);
745744
}
746745
_ => {}
747746
}

compiler/rustc_ast/src/tokenstream.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl TokenTree {
6464
match (self, other) {
6565
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
6666
(TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
67-
delim == delim2 && tts.eq_unspanned(&tts2)
67+
delim == delim2 && tts.eq_unspanned(tts2)
6868
}
6969
_ => false,
7070
}
@@ -402,7 +402,7 @@ impl TokenStream {
402402
let mut t1 = self.trees();
403403
let mut t2 = other.trees();
404404
for (t1, t2) in iter::zip(&mut t1, &mut t2) {
405-
if !t1.eq_unspanned(&t2) {
405+
if !t1.eq_unspanned(t2) {
406406
return false;
407407
}
408408
}
@@ -475,7 +475,7 @@ impl TokenStream {
475475
token::Interpolated(nt) => TokenTree::Delimited(
476476
DelimSpan::from_single(token.span),
477477
Delimiter::Invisible,
478-
TokenStream::from_nonterminal_ast(&nt).flattened(),
478+
TokenStream::from_nonterminal_ast(nt).flattened(),
479479
),
480480
_ => TokenTree::Token(token.clone(), spacing),
481481
}
@@ -511,7 +511,7 @@ impl TokenStream {
511511
fn try_glue_to_last(vec: &mut Vec<TokenTree>, tt: &TokenTree) -> bool {
512512
if let Some(TokenTree::Token(last_tok, Spacing::Joint)) = vec.last()
513513
&& let TokenTree::Token(tok, spacing) = tt
514-
&& let Some(glued_tok) = last_tok.glue(&tok)
514+
&& let Some(glued_tok) = last_tok.glue(tok)
515515
{
516516
// ...then overwrite the last token tree in `vec` with the
517517
// glued token, and skip the first token tree from `stream`.

compiler/rustc_ast/src/util/comments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
110110
} else {
111111
&mut lines
112112
};
113-
if let Some(horizontal) = get_horizontal_trim(&lines, kind) {
113+
if let Some(horizontal) = get_horizontal_trim(lines, kind) {
114114
changes = true;
115115
// remove a "[ \t]*\*" block from each line, if possible
116116
for line in lines.iter_mut() {
@@ -147,7 +147,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
147147

148148
fn trim_whitespace_prefix(s: &str, col: CharPos) -> &str {
149149
let len = s.len();
150-
match all_whitespace(&s, col) {
150+
match all_whitespace(s, col) {
151151
Some(col) => {
152152
if col < len {
153153
&s[col..]

compiler/rustc_ast/src/util/literal.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ impl LitKind {
5252
// new symbol because the string in the LitKind is different to the
5353
// string in the token.
5454
let s = symbol.as_str();
55-
let symbol = if s.contains(&['\\', '\r']) {
55+
let symbol = if s.contains(['\\', '\r']) {
5656
let mut buf = String::with_capacity(s.len());
5757
let mut error = Ok(());
5858
// Force-inlining here is aggressive but the closure is
5959
// called on every char in the string, so it can be
6060
// hot in programs with many long strings.
6161
unescape_literal(
62-
&s,
62+
s,
6363
Mode::Str,
6464
&mut #[inline(always)]
6565
|_, unescaped_char| match unescaped_char {
@@ -85,7 +85,7 @@ impl LitKind {
8585
if s.contains('\r') {
8686
let mut buf = String::with_capacity(s.len());
8787
let mut error = Ok(());
88-
unescape_literal(&s, Mode::RawStr, &mut |_, unescaped_char| {
88+
unescape_literal(s, Mode::RawStr, &mut |_, unescaped_char| {
8989
match unescaped_char {
9090
Ok(c) => buf.push(c),
9191
Err(err) => {
@@ -106,7 +106,7 @@ impl LitKind {
106106
let s = symbol.as_str();
107107
let mut buf = Vec::with_capacity(s.len());
108108
let mut error = Ok(());
109-
unescape_literal(&s, Mode::ByteStr, &mut |_, c| match c {
109+
unescape_literal(s, Mode::ByteStr, &mut |_, c| match c {
110110
Ok(c) => buf.push(byte_from_char(c)),
111111
Err(err) => {
112112
if err.is_fatal() {
@@ -122,7 +122,7 @@ impl LitKind {
122122
let bytes = if s.contains('\r') {
123123
let mut buf = Vec::with_capacity(s.len());
124124
let mut error = Ok(());
125-
unescape_literal(&s, Mode::RawByteStr, &mut |_, c| match c {
125+
unescape_literal(s, Mode::RawByteStr, &mut |_, c| match c {
126126
Ok(c) => buf.push(byte_from_char(c)),
127127
Err(err) => {
128128
if err.is_fatal() {

compiler/rustc_ast/src/util/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
384384
| ast::ExprKind::AssignOp(_, lhs, rhs)
385385
| ast::ExprKind::Binary(_, lhs, rhs) => {
386386
// X { y: 1 } + X { y: 2 }
387-
contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
387+
contains_exterior_struct_lit(lhs) || contains_exterior_struct_lit(rhs)
388388
}
389389
ast::ExprKind::Await(x)
390390
| ast::ExprKind::Unary(_, x)
@@ -393,12 +393,12 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
393393
| ast::ExprKind::Field(x, _)
394394
| ast::ExprKind::Index(x, _) => {
395395
// &X { y: 1 }, X { y: 1 }.y
396-
contains_exterior_struct_lit(&x)
396+
contains_exterior_struct_lit(x)
397397
}
398398

399399
ast::ExprKind::MethodCall(box ast::MethodCall { receiver, .. }) => {
400400
// X { y: 1 }.bar(...)
401-
contains_exterior_struct_lit(&receiver)
401+
contains_exterior_struct_lit(receiver)
402402
}
403403

404404
_ => false,

compiler/rustc_ast/src/util/unicode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn contains_text_flow_control_chars(s: &str) -> bool {
1717
// U+2069 - E2 81 A9
1818
let mut bytes = s.as_bytes();
1919
loop {
20-
match core::slice::memchr::memchr(0xE2, &bytes) {
20+
match core::slice::memchr::memchr(0xE2, bytes) {
2121
Some(idx) => {
2222
// bytes are valid UTF-8 -> E2 must be followed by two bytes
2323
let ch = &bytes[idx..idx + 3];

compiler/rustc_ast_pretty/src/pprust/state.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
519519
ast::MetaItemKind::List(items) => {
520520
self.print_path(&item.path, false, 0);
521521
self.popen();
522-
self.commasep(Consistent, &items, |s, i| s.print_meta_list_item(i));
522+
self.commasep(Consistent, items, |s, i| s.print_meta_list_item(i));
523523
self.pclose();
524524
}
525525
}
@@ -536,7 +536,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
536536
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) {
537537
match tt {
538538
TokenTree::Token(token, _) => {
539-
let token_str = self.token_to_string_ext(&token, convert_dollar_crate);
539+
let token_str = self.token_to_string_ext(token, convert_dollar_crate);
540540
self.word(token_str);
541541
if let token::DocComment(..) = token.kind {
542542
self.hardbreak()
@@ -998,7 +998,7 @@ impl<'a> State<'a> {
998998
ast::AssocConstraintKind::Bound { bounds } => {
999999
if !bounds.is_empty() {
10001000
self.word_nbsp(":");
1001-
self.print_type_bounds(&bounds);
1001+
self.print_type_bounds(bounds);
10021002
}
10031003
}
10041004
}
@@ -1035,7 +1035,7 @@ impl<'a> State<'a> {
10351035
}
10361036
ast::TyKind::Tup(elts) => {
10371037
self.popen();
1038-
self.commasep(Inconsistent, &elts, |s, ty| s.print_type(ty));
1038+
self.commasep(Inconsistent, elts, |s, ty| s.print_type(ty));
10391039
if elts.len() == 1 {
10401040
self.word(",");
10411041
}
@@ -1254,7 +1254,7 @@ impl<'a> State<'a> {
12541254

12551255
self.popen();
12561256
self.commasep(Consistent, &args, |s, arg| match arg {
1257-
AsmArg::Template(template) => s.print_string(&template, ast::StrStyle::Cooked),
1257+
AsmArg::Template(template) => s.print_string(template, ast::StrStyle::Cooked),
12581258
AsmArg::Operand(op) => {
12591259
let print_reg_or_class = |s: &mut Self, r: &InlineAsmRegOrRegClass| match r {
12601260
InlineAsmRegOrRegClass::Reg(r) => s.print_symbol(*r, ast::StrStyle::Cooked),
@@ -1424,11 +1424,11 @@ impl<'a> State<'a> {
14241424
self.print_path(path, true, 0);
14251425
}
14261426
self.popen();
1427-
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
1427+
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
14281428
self.pclose();
14291429
}
14301430
PatKind::Or(pats) => {
1431-
self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(p));
1431+
self.strsep("|", true, Inconsistent, pats, |s, p| s.print_pat(p));
14321432
}
14331433
PatKind::Path(None, path) => {
14341434
self.print_path(path, true, 0);
@@ -1450,7 +1450,7 @@ impl<'a> State<'a> {
14501450
}
14511451
self.commasep_cmnt(
14521452
Consistent,
1453-
&fields,
1453+
fields,
14541454
|s, f| {
14551455
s.cbox(INDENT_UNIT);
14561456
if !f.is_shorthand {
@@ -1475,7 +1475,7 @@ impl<'a> State<'a> {
14751475
}
14761476
PatKind::Tuple(elts) => {
14771477
self.popen();
1478-
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
1478+
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
14791479
if elts.len() == 1 {
14801480
self.word(",");
14811481
}
@@ -1498,7 +1498,7 @@ impl<'a> State<'a> {
14981498
self.print_pat(inner);
14991499
}
15001500
}
1501-
PatKind::Lit(e) => self.print_expr(&**e),
1501+
PatKind::Lit(e) => self.print_expr(e),
15021502
PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
15031503
if let Some(e) = begin {
15041504
self.print_expr(e);
@@ -1514,7 +1514,7 @@ impl<'a> State<'a> {
15141514
}
15151515
PatKind::Slice(elts) => {
15161516
self.word("[");
1517-
self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p));
1517+
self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
15181518
self.word("]");
15191519
}
15201520
PatKind::Rest => self.word(".."),
@@ -1600,7 +1600,7 @@ impl<'a> State<'a> {
16001600

16011601
self.word("<");
16021602

1603-
self.commasep(Inconsistent, &generic_params, |s, param| {
1603+
self.commasep(Inconsistent, generic_params, |s, param| {
16041604
s.print_outer_attributes_inline(&param.attrs);
16051605

16061606
match &param.kind {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ impl<'a> State<'a> {
305305
self.print_expr_tup(exprs);
306306
}
307307
ast::ExprKind::Call(func, args) => {
308-
self.print_expr_call(func, &args);
308+
self.print_expr_call(func, args);
309309
}
310310
ast::ExprKind::MethodCall(box ast::MethodCall { seg, receiver, args, .. }) => {
311-
self.print_expr_method_call(seg, &receiver, &args);
311+
self.print_expr_method_call(seg, receiver, args);
312312
}
313313
ast::ExprKind::Binary(op, lhs, rhs) => {
314314
self.print_expr_binary(*op, lhs, rhs);
@@ -605,7 +605,7 @@ impl<'a> State<'a> {
605605
match binder {
606606
ast::ClosureBinder::NotPresent => {}
607607
ast::ClosureBinder::For { generic_params, .. } => {
608-
self.print_formal_generic_params(&generic_params)
608+
self.print_formal_generic_params(generic_params)
609609
}
610610
}
611611
}

compiler/rustc_data_structures/src/intern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, T: PartialOrd> PartialOrd for Interned<'a, T> {
7272
if ptr::eq(self.0, other.0) {
7373
Some(Ordering::Equal)
7474
} else {
75-
let res = self.0.partial_cmp(&other.0);
75+
let res = self.0.partial_cmp(other.0);
7676
debug_assert_ne!(res, Some(Ordering::Equal));
7777
res
7878
}
@@ -86,7 +86,7 @@ impl<'a, T: Ord> Ord for Interned<'a, T> {
8686
if ptr::eq(self.0, other.0) {
8787
Ordering::Equal
8888
} else {
89-
let res = self.0.cmp(&other.0);
89+
let res = self.0.cmp(other.0);
9090
debug_assert_ne!(res, Ordering::Equal);
9191
res
9292
}

compiler/rustc_data_structures/src/memmap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Deref for Mmap {
3636

3737
#[inline]
3838
fn deref(&self) -> &[u8] {
39-
&*self.0
39+
&self.0
4040
}
4141
}
4242

@@ -96,13 +96,13 @@ impl Deref for MmapMut {
9696

9797
#[inline]
9898
fn deref(&self) -> &[u8] {
99-
&*self.0
99+
&self.0
100100
}
101101
}
102102

103103
impl DerefMut for MmapMut {
104104
#[inline]
105105
fn deref_mut(&mut self) -> &mut [u8] {
106-
&mut *self.0
106+
&mut self.0
107107
}
108108
}

compiler/rustc_data_structures/src/profiling.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl SelfProfilerRef {
192192
F: for<'a> FnOnce(&'a SelfProfiler) -> TimingGuard<'a>,
193193
{
194194
let profiler = profiler_ref.profiler.as_ref().unwrap();
195-
f(&**profiler)
195+
f(profiler)
196196
}
197197

198198
if self.event_filter_mask.contains(event_filter) {
@@ -466,7 +466,7 @@ impl SelfProfilerRef {
466466

467467
pub fn with_profiler(&self, f: impl FnOnce(&SelfProfiler)) {
468468
if let Some(profiler) = &self.profiler {
469-
f(&profiler)
469+
f(profiler)
470470
}
471471
}
472472

@@ -733,7 +733,7 @@ impl Drop for VerboseTimingGuard<'_> {
733733
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
734734
let end_rss = get_resident_set_size();
735735
let dur = start_time.elapsed();
736-
print_time_passes_entry(&message, dur, start_rss, end_rss);
736+
print_time_passes_entry(message, dur, start_rss, end_rss);
737737
}
738738
}
739739
}

0 commit comments

Comments
 (0)