Skip to content

Commit 8f681d8

Browse files
committed
When encountering &SmallImplCopy < &SmallImplCopy, suggest copying
When encountering a binary operation for two `T: Copy` where `T` is as small as a 64bit pointer, suggest dereferencing the expressions so the binary operation is inlined. Mitigate the effects of #105259, particularly when match ergonomics is involved.
1 parent fdbc432 commit 8f681d8

File tree

51 files changed

+372
-69
lines changed

Some content is hidden

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

51 files changed

+372
-69
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ impl PartialEq for Nonterminal {
894894
fn eq(&self, rhs: &Self) -> bool {
895895
match (self, rhs) {
896896
(NtIdent(ident_lhs, is_raw_lhs), NtIdent(ident_rhs, is_raw_rhs)) => {
897-
ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs
897+
ident_lhs == ident_rhs && *is_raw_lhs == *is_raw_rhs
898898
}
899899
(NtLifetime(ident_lhs), NtLifetime(ident_rhs)) => ident_lhs == ident_rhs,
900900
// FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl TokenTree {
6565
match (self, other) {
6666
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
6767
(TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
68-
delim == delim2 && tts.eq_unspanned(tts2)
68+
*delim == *delim2 && tts.eq_unspanned(tts2)
6969
}
7070
_ => false,
7171
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
617617
self.impl_trait_defs = current_impl_trait_defs;
618618
self.impl_trait_bounds = current_impl_trait_bounds;
619619

620-
debug_assert!(!self.children.iter().any(|(id, _)| id == &def_id));
620+
debug_assert!(!self.children.iter().any(|(id, _)| *id == def_id));
621621
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
622622
}
623623

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,9 @@ fn check_incompatible_features(sess: &Session) {
688688
.iter()
689689
.filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
690690
{
691-
if let Some((f1_name, f1_span)) = declared_features.clone().find(|(name, _)| name == f1) {
692-
if let Some((f2_name, f2_span)) = declared_features.clone().find(|(name, _)| name == f2)
691+
if let Some((f1_name, f1_span)) = declared_features.clone().find(|(name, _)| *name == *f1) {
692+
if let Some((f2_name, f2_span)) =
693+
declared_features.clone().find(|(name, _)| *name == *f2)
693694
{
694695
let spans = vec![f1_span, f2_span];
695696
sess.struct_span_err(

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
28252825
let mut arguments = Vec::new();
28262826
for (index, argument) in sig.inputs().skip_binder().iter().enumerate() {
28272827
if let ty::Ref(argument_region, _, _) = argument.kind() {
2828-
if argument_region == return_region {
2828+
if *argument_region == *return_region {
28292829
// Need to use the `rustc_middle::ty` types to compare against the
28302830
// `return_region`. Then use the `rustc_hir` type to get only
28312831
// the lifetime span.

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
694694
let cgus: Vec<_> = cgu_reuse
695695
.iter()
696696
.enumerate()
697-
.filter(|&(_, reuse)| reuse == &CguReuse::No)
697+
.filter(|&(_, reuse)| *reuse == CguReuse::No)
698698
.take(tcx.sess.threads())
699699
.collect();
700700

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
258258
(PassMode::Pair(a1, b1), PassMode::Pair(a2, b2)) => {
259259
arg_attr_compat(a1, a2) && arg_attr_compat(b1, b2)
260260
}
261-
(PassMode::Cast(c1, pad1), PassMode::Cast(c2, pad2)) => c1 == c2 && pad1 == pad2,
261+
(PassMode::Cast(c1, pad1), PassMode::Cast(c2, pad2)) => c1 == c2 && *pad1 == *pad2,
262262
(
263263
PassMode::Indirect { attrs: a1, extra_attrs: None, on_stack: s1 },
264264
PassMode::Indirect { attrs: a2, extra_attrs: None, on_stack: s2 },
265-
) => arg_attr_compat(a1, a2) && s1 == s2,
265+
) => arg_attr_compat(a1, a2) && *s1 == *s2,
266266
(
267267
PassMode::Indirect { attrs: a1, extra_attrs: Some(e1), on_stack: s1 },
268268
PassMode::Indirect { attrs: a2, extra_attrs: Some(e2), on_stack: s2 },
269-
) => arg_attr_compat(a1, a2) && arg_attr_compat(e1, e2) && s1 == s2,
269+
) => arg_attr_compat(a1, a2) && arg_attr_compat(e1, e2) && *s1 == *s2,
270270
_ => false,
271271
};
272272

compiler/rustc_errors/src/emitter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub trait Emitter: Translate {
351351
if let Some((macro_kind, name)) = has_macro_spans.first() {
352352
// Mark the actual macro this originates from
353353
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
354-
&& last_name != name
354+
&& *last_name != *name
355355
{
356356
let descr = macro_kind.descr();
357357
format!(
@@ -2753,7 +2753,7 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
27532753
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
27542754
// All the chars that differ in capitalization are confusable (above):
27552755
let confusable = iter::zip(found.chars(), suggested.chars())
2756-
.filter(|(f, s)| f != s)
2756+
.filter(|(f, s)| *f != *s)
27572757
.all(|(f, s)| (ascii_confusables.contains(&f) || ascii_confusables.contains(&s)));
27582758
confusable && found.to_lowercase() == suggested.to_lowercase()
27592759
// FIXME: We sometimes suggest the same thing we already have, which is a

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(super) fn transcribe<'a>(
123123
if let Frame::Sequence { idx, sep, .. } = stack.last_mut().unwrap() {
124124
let (repeat_idx, repeat_len) = repeats.last_mut().unwrap();
125125
*repeat_idx += 1;
126-
if repeat_idx < repeat_len {
126+
if *repeat_idx < *repeat_len {
127127
*idx = 0;
128128
if let Some(sep) = sep {
129129
result.push(TokenTree::Token(sep.clone(), Spacing::Alone));

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
579579
for (region_b, region_b_idx) in &regions {
580580
// Again, skip `'static` because it outlives everything. Also, we trivially
581581
// know that a region outlives itself.
582-
if ty::ReStatic == **region_b || region_a == region_b {
582+
if ty::ReStatic == **region_b || *region_a == *region_b {
583583
continue;
584584
}
585585
if region_known_to_outlive(

0 commit comments

Comments
 (0)