Skip to content

Commit 8507a57

Browse files
authored
Rollup merge of rust-lang#131375 - klensy:clone_on_ref_ptr, r=cjgillot
compiler: apply clippy::clone_on_ref_ptr for CI Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see rust-lang#131225 (comment). Some Arc's can be misplaced with Lrc's, sorry. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2 parents 3f1be1e + 746b675 commit 8507a57

File tree

34 files changed

+101
-93
lines changed

34 files changed

+101
-93
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,6 +3301,7 @@ version = "0.0.0"
33013301
dependencies = [
33023302
"itertools",
33033303
"rustc_ast",
3304+
"rustc_data_structures",
33043305
"rustc_lexer",
33053306
"rustc_span",
33063307
"thin-vec",

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl Clone for TokenKind {
368368
// a copy. This is faster than the `derive(Clone)` version which has a
369369
// separate path for every variant.
370370
match self {
371-
Interpolated(nt) => Interpolated(nt.clone()),
371+
Interpolated(nt) => Interpolated(Lrc::clone(nt)),
372372
_ => unsafe { std::ptr::read(self) },
373373
}
374374
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::assert_matches::assert_matches;
33
use rustc_ast::ptr::P as AstP;
44
use rustc_ast::*;
55
use rustc_data_structures::stack::ensure_sufficient_stack;
6+
use rustc_data_structures::sync::Lrc;
67
use rustc_hir as hir;
78
use rustc_hir::HirId;
89
use rustc_hir::def::{DefKind, Res};
@@ -143,7 +144,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
143144
ExprKind::IncludedBytes(bytes) => {
144145
let lit = self.arena.alloc(respan(
145146
self.lower_span(e.span),
146-
LitKind::ByteStr(bytes.clone(), StrStyle::Cooked),
147+
LitKind::ByteStr(Lrc::clone(bytes), StrStyle::Cooked),
147148
));
148149
hir::ExprKind::Lit(lit)
149150
}
@@ -521,15 +522,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
521522
this.mark_span_with_reason(
522523
DesugaringKind::TryBlock,
523524
expr.span,
524-
Some(this.allow_try_trait.clone()),
525+
Some(Lrc::clone(&this.allow_try_trait)),
525526
),
526527
expr,
527528
)
528529
} else {
529530
let try_span = this.mark_span_with_reason(
530531
DesugaringKind::TryBlock,
531532
this.tcx.sess.source_map().end_point(body.span),
532-
Some(this.allow_try_trait.clone()),
533+
Some(Lrc::clone(&this.allow_try_trait)),
533534
);
534535

535536
(try_span, this.expr_unit(try_span))
@@ -638,7 +639,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
638639
let unstable_span = self.mark_span_with_reason(
639640
DesugaringKind::Async,
640641
self.lower_span(span),
641-
Some(self.allow_gen_future.clone()),
642+
Some(Lrc::clone(&self.allow_gen_future)),
642643
);
643644
let resume_ty =
644645
self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span, None);
@@ -724,7 +725,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
724725
let unstable_span = self.mark_span_with_reason(
725726
DesugaringKind::Async,
726727
span,
727-
Some(self.allow_gen_future.clone()),
728+
Some(Lrc::clone(&self.allow_gen_future)),
728729
);
729730
self.lower_attrs(inner_hir_id, &[Attribute {
730731
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
@@ -800,13 +801,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
800801

801802
let features = match await_kind {
802803
FutureKind::Future => None,
803-
FutureKind::AsyncIterator => Some(self.allow_for_await.clone()),
804+
FutureKind::AsyncIterator => Some(Lrc::clone(&self.allow_for_await)),
804805
};
805806
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, features);
806807
let gen_future_span = self.mark_span_with_reason(
807808
DesugaringKind::Await,
808809
full_span,
809-
Some(self.allow_gen_future.clone()),
810+
Some(Lrc::clone(&self.allow_gen_future)),
810811
);
811812
let expr_hir_id = expr.hir_id;
812813

@@ -1812,13 +1813,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
18121813
let unstable_span = self.mark_span_with_reason(
18131814
DesugaringKind::QuestionMark,
18141815
span,
1815-
Some(self.allow_try_trait.clone()),
1816+
Some(Lrc::clone(&self.allow_try_trait)),
18161817
);
18171818
let try_span = self.tcx.sess.source_map().end_point(span);
18181819
let try_span = self.mark_span_with_reason(
18191820
DesugaringKind::QuestionMark,
18201821
try_span,
1821-
Some(self.allow_try_trait.clone()),
1822+
Some(Lrc::clone(&self.allow_try_trait)),
18221823
);
18231824

18241825
// `Try::branch(<expr>)`
@@ -1912,7 +1913,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19121913
let unstable_span = self.mark_span_with_reason(
19131914
DesugaringKind::YeetExpr,
19141915
span,
1915-
Some(self.allow_try_trait.clone()),
1916+
Some(Lrc::clone(&self.allow_try_trait)),
19161917
);
19171918

19181919
let from_yeet_expr = self.wrap_in_try_constructor(

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18651865
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
18661866
CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
18671867
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1868-
(return_impl_trait_id, Some(self.allow_async_iterator.clone()))
1868+
(return_impl_trait_id, Some(Lrc::clone(&self.allow_async_iterator)))
18691869
}
18701870
};
18711871

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7373
let bound_modifier_allowed_features = if let Res::Def(DefKind::Trait, async_def_id) = res
7474
&& self.tcx.async_fn_trait_kind_from_def_id(async_def_id).is_some()
7575
{
76-
Some(self.allow_async_fn_traits.clone())
76+
Some(Lrc::clone(&self.allow_async_fn_traits))
7777
} else {
7878
None
7979
};

compiler/rustc_ast_pretty/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
# tidy-alphabetical-start
88
itertools = "0.12"
99
rustc_ast = { path = "../rustc_ast" }
10+
rustc_data_structures = { path = "../rustc_data_structures" }
1011
rustc_lexer = { path = "../rustc_lexer" }
1112
rustc_span = { path = "../rustc_span" }
1213
thin-vec = "0.2.12"

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_ast::{
2121
GenericBound, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass,
2222
InlineAsmTemplatePiece, PatKind, RangeEnd, RangeSyntax, Safety, SelfKind, Term, attr,
2323
};
24+
use rustc_data_structures::sync::Lrc;
2425
use rustc_span::edition::Edition;
2526
use rustc_span::source_map::{SourceMap, Spanned};
2627
use rustc_span::symbol::{Ident, IdentPrinter, Symbol, kw, sym};
@@ -105,7 +106,7 @@ fn split_block_comment_into_lines(text: &str, col: CharPos) -> Vec<String> {
105106
fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment> {
106107
let sm = SourceMap::new(sm.path_mapping().clone());
107108
let source_file = sm.new_source_file(path, src);
108-
let text = (*source_file.src.as_ref().unwrap()).clone();
109+
let text = Lrc::clone(&(*source_file.src.as_ref().unwrap()));
109110

110111
let text: &str = text.as_str();
111112
let start_bpos = source_file.start_pos;

compiler/rustc_borrowck/src/nll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ pub(crate) fn compute_regions<'a, 'tcx>(
107107
param_env,
108108
body,
109109
promoted,
110-
universal_regions.clone(),
110+
Rc::clone(&universal_regions),
111111
location_table,
112112
borrow_set,
113113
&mut all_facts,
114114
flow_inits,
115115
move_data,
116-
elements.clone(),
116+
Rc::clone(&elements),
117117
upvars,
118118
);
119119

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
733733
}
734734

735735
// Now take member constraints into account.
736-
let member_constraints = self.member_constraints.clone();
736+
let member_constraints = Rc::clone(&self.member_constraints);
737737
for m_c_i in member_constraints.indices(scc_a) {
738738
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
739739
}
@@ -1679,7 +1679,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16791679
infcx: &InferCtxt<'tcx>,
16801680
errors_buffer: &mut RegionErrors<'tcx>,
16811681
) {
1682-
let member_constraints = self.member_constraints.clone();
1682+
let member_constraints = Rc::clone(&self.member_constraints);
16831683
for m_c_i in member_constraints.all_indices() {
16841684
debug!(?m_c_i);
16851685
let m_c = &member_constraints[m_c_i];

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(crate) fn type_check<'a, 'tcx>(
134134
let mut constraints = MirTypeckRegionConstraints {
135135
placeholder_indices: PlaceholderIndices::default(),
136136
placeholder_index_to_region: IndexVec::default(),
137-
liveness_constraints: LivenessValues::with_specific_points(elements.clone()),
137+
liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&elements)),
138138
outlives_constraints: OutlivesConstraintSet::default(),
139139
member_constraints: MemberConstraintSet::default(),
140140
type_tests: Vec::default(),
@@ -150,7 +150,7 @@ pub(crate) fn type_check<'a, 'tcx>(
150150
infcx,
151151
param_env,
152152
implicit_region_bound,
153-
universal_regions.clone(),
153+
Rc::clone(&universal_regions),
154154
&mut constraints,
155155
);
156156

0 commit comments

Comments
 (0)