Skip to content

Commit c5c52a2

Browse files
committed
fix clippy::clone_on_ref_ptr for compiler
1 parent fa88b78 commit c5c52a2

File tree

35 files changed

+104
-96
lines changed

35 files changed

+104
-96
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3319,6 +3319,7 @@ version = "0.0.0"
33193319
dependencies = [
33203320
"itertools",
33213321
"rustc_ast",
3322+
"rustc_data_structures",
33223323
"rustc_lexer",
33233324
"rustc_span",
33243325
"thin-vec",

compiler/rustc_ast/src/token.rs

+1-1
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

+11-10
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 = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
644645
let input_ty = hir::Ty {
@@ -723,7 +724,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
723724
let unstable_span = self.mark_span_with_reason(
724725
DesugaringKind::Async,
725726
span,
726-
Some(self.allow_gen_future.clone()),
727+
Some(Lrc::clone(&self.allow_gen_future)),
727728
);
728729
self.lower_attrs(inner_hir_id, &[Attribute {
729730
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
@@ -799,13 +800,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
799800

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

@@ -1811,13 +1812,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
18111812
let unstable_span = self.mark_span_with_reason(
18121813
DesugaringKind::QuestionMark,
18131814
span,
1814-
Some(self.allow_try_trait.clone()),
1815+
Some(Lrc::clone(&self.allow_try_trait)),
18151816
);
18161817
let try_span = self.tcx.sess.source_map().end_point(span);
18171818
let try_span = self.mark_span_with_reason(
18181819
DesugaringKind::QuestionMark,
18191820
try_span,
1820-
Some(self.allow_try_trait.clone()),
1821+
Some(Lrc::clone(&self.allow_try_trait)),
18211822
);
18221823

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

19171918
let from_yeet_expr = self.wrap_in_try_constructor(

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19151915
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
19161916
CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
19171917
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1918-
(return_impl_trait_id, Some(self.allow_async_iterator.clone()))
1918+
(return_impl_trait_id, Some(Lrc::clone(&self.allow_async_iterator)))
19191919
}
19201920
};
19211921

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7070
let bound_modifier_allowed_features = if let Res::Def(DefKind::Trait, async_def_id) = res
7171
&& self.tcx.async_fn_trait_kind_from_def_id(async_def_id).is_some()
7272
{
73-
Some(self.allow_async_fn_traits.clone())
73+
Some(Lrc::clone(&self.allow_async_fn_traits))
7474
} else {
7575
None
7676
};

compiler/rustc_ast_pretty/Cargo.toml

+1
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

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

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

compiler/rustc_borrowck/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn do_mir_borrowck<'tcx>(
288288
access_place_error_reported: Default::default(),
289289
reservation_error_reported: Default::default(),
290290
uninitialized_error_reported: Default::default(),
291-
regioncx: regioncx.clone(),
291+
regioncx: Rc::clone(&regioncx),
292292
used_mut: Default::default(),
293293
used_mut_upvars: SmallVec::new(),
294294
borrow_set: Rc::clone(&borrow_set),
@@ -800,7 +800,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
800800
TerminatorKind::Yield { value: _, resume: _, resume_arg: _, drop: _ } => {
801801
if self.movable_coroutine {
802802
// Look for any active borrows to locals
803-
let borrow_set = self.borrow_set.clone();
803+
let borrow_set = Rc::clone(&self.borrow_set);
804804
for i in state.borrows.iter() {
805805
let borrow = &borrow_set[i];
806806
self.check_for_local_borrow(borrow, span);
@@ -816,7 +816,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
816816
// Often, the storage will already have been killed by an explicit
817817
// StorageDead, but we don't always emit those (notably on unwind paths),
818818
// so this "extra check" serves as a kind of backup.
819-
let borrow_set = self.borrow_set.clone();
819+
let borrow_set = Rc::clone(&self.borrow_set);
820820
for i in state.borrows.iter() {
821821
let borrow = &borrow_set[i];
822822
self.check_for_invalidation_at_exit(loc, borrow, span);
@@ -1580,7 +1580,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15801580
// Two-phase borrow support: For each activation that is newly
15811581
// generated at this statement, check if it interferes with
15821582
// another borrow.
1583-
let borrow_set = self.borrow_set.clone();
1583+
let borrow_set = Rc::clone(&self.borrow_set);
15841584
for &borrow_index in borrow_set.activations_at_location(location) {
15851585
let borrow = &borrow_set[borrow_index];
15861586

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
731731
}
732732

733733
// Now take member constraints into account.
734-
let member_constraints = self.member_constraints.clone();
734+
let member_constraints = Rc::clone(&self.member_constraints);
735735
for m_c_i in member_constraints.indices(scc_a) {
736736
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
737737
}
@@ -1677,7 +1677,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16771677
infcx: &InferCtxt<'tcx>,
16781678
errors_buffer: &mut RegionErrors<'tcx>,
16791679
) {
1680-
let member_constraints = self.member_constraints.clone();
1680+
let member_constraints = Rc::clone(&self.member_constraints);
16811681
for m_c_i in member_constraints.all_indices() {
16821682
debug!(?m_c_i);
16831683
let m_c = &member_constraints[m_c_i];

compiler/rustc_borrowck/src/region_infer/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ impl<N: Idx> RegionValues<N> {
281281
) -> Self {
282282
let num_placeholders = placeholder_indices.len();
283283
Self {
284-
elements: elements.clone(),
284+
elements: Rc::clone(elements),
285285
points: SparseIntervalMatrix::new(elements.num_points()),
286-
placeholder_indices: placeholder_indices.clone(),
286+
placeholder_indices: Rc::clone(placeholder_indices),
287287
free_regions: SparseBitMatrix::new(num_universal_regions),
288288
placeholders: SparseBitMatrix::new(num_placeholders),
289289
}

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) fn create<'tcx>(
6262
param_env,
6363
implicit_region_bound,
6464
constraints,
65-
universal_regions: universal_regions.clone(),
65+
universal_regions: Rc::clone(universal_regions),
6666
region_bound_pairs: Default::default(),
6767
outlives: Default::default(),
6868
inverse_outlives: Default::default(),

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
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(),

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ fn thin_lto(
569569

570570
info!(" - {}: re-compiled", module_name);
571571
opt_jobs.push(LtoModuleCodegen::Thin(ThinModule {
572-
shared: shared.clone(),
572+
shared: Arc::clone(&shared),
573573
idx: module_index,
574574
}));
575575
}

compiler/rustc_codegen_ssa/src/back/write.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_ast::attr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1212
use rustc_data_structures::memmap::Mmap;
1313
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
14+
use rustc_data_structures::sync::Lrc;
1415
use rustc_errors::emitter::Emitter;
1516
use rustc_errors::translation::Translate;
1617
use rustc_errors::{
@@ -514,7 +515,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
514515
future: Some(coordinator_thread),
515516
phantom: PhantomData,
516517
},
517-
output_filenames: tcx.output_filenames(()).clone(),
518+
output_filenames: Lrc::clone(tcx.output_filenames(())),
518519
}
519520
}
520521

@@ -1203,7 +1204,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
12031204
coordinator_send,
12041205
expanded_args: tcx.sess.expanded_args.clone(),
12051206
diag_emitter: shared_emitter.clone(),
1206-
output_filenames: tcx.output_filenames(()).clone(),
1207+
output_filenames: Lrc::clone(tcx.output_filenames(())),
12071208
regular_module_config: regular_config,
12081209
metadata_module_config: metadata_config,
12091210
allocator_module_config: allocator_config,

compiler/rustc_codegen_ssa/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_n
77
use rustc_attr as attr;
88
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
99
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
10-
use rustc_data_structures::sync::par_map;
10+
use rustc_data_structures::sync::{Lrc, par_map};
1111
use rustc_data_structures::unord::UnordMap;
1212
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1313
use rustc_hir::lang_items::LangItem;
@@ -922,7 +922,7 @@ impl CrateInfo {
922922
crate_name: UnordMap::with_capacity(n_crates),
923923
used_crates,
924924
used_crate_source: UnordMap::with_capacity(n_crates),
925-
dependency_formats: tcx.dependency_formats(()).clone(),
925+
dependency_formats: Lrc::clone(tcx.dependency_formats(())),
926926
windows_subsystem,
927927
natvis_debugger_visualizers: Default::default(),
928928
};
@@ -935,7 +935,7 @@ impl CrateInfo {
935935
info.crate_name.insert(cnum, tcx.crate_name(cnum));
936936

937937
let used_crate_source = tcx.used_crate_source(cnum);
938-
info.used_crate_source.insert(cnum, used_crate_source.clone());
938+
info.used_crate_source.insert(cnum, Lrc::clone(used_crate_source));
939939
if tcx.is_profiler_runtime(cnum) {
940940
info.profiler_runtime = Some(cnum);
941941
}

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ pub fn install_ice_hook(
13961396
}
13971397

13981398
let using_internal_features = Arc::new(std::sync::atomic::AtomicBool::default());
1399-
let using_internal_features_hook = using_internal_features.clone();
1399+
let using_internal_features_hook = Arc::clone(&using_internal_features);
14001400
panic::update_hook(Box::new(
14011401
move |default_hook: &(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static),
14021402
info: &PanicHookInfo<'_>| {

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl AnnotateSnippetEmitter {
173173
source_map.ensure_source_file_source_present(&file);
174174
(
175175
format!("{}", source_map.filename_for_diagnostics(&file.name)),
176-
source_string(file.clone(), &line),
176+
source_string(Lrc::clone(&file), &line),
177177
line.line_index,
178178
line.annotations,
179179
)

compiler/rustc_errors/src/emitter.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ impl HumanEmitter {
15551555
// Get the left-side margin to remove it
15561556
let mut whitespace_margin = usize::MAX;
15571557
for line_idx in 0..annotated_file.lines.len() {
1558-
let file = annotated_file.file.clone();
1558+
let file = Lrc::clone(&annotated_file.file);
15591559
let line = &annotated_file.lines[line_idx];
15601560
if let Some(source_string) =
15611561
line.line_index.checked_sub(1).and_then(|l| file.get_line(l))
@@ -1646,7 +1646,7 @@ impl HumanEmitter {
16461646

16471647
let depths = self.render_source_line(
16481648
&mut buffer,
1649-
annotated_file.file.clone(),
1649+
Lrc::clone(&annotated_file.file),
16501650
&annotated_file.lines[line_idx],
16511651
width_offset,
16521652
code_offset,
@@ -2529,7 +2529,12 @@ impl FileWithAnnotatedLines {
25292529
// | | |
25302530
// | |______foo
25312531
// | baz
2532-
add_annotation_to_file(&mut output, file.clone(), ann.line_start, ann.as_start());
2532+
add_annotation_to_file(
2533+
&mut output,
2534+
Lrc::clone(&file),
2535+
ann.line_start,
2536+
ann.as_start(),
2537+
);
25332538
// 4 is the minimum vertical length of a multiline span when presented: two lines
25342539
// of code and two lines of underline. This is not true for the special case where
25352540
// the beginning doesn't have an underline, but the current logic seems to be
@@ -2545,11 +2550,11 @@ impl FileWithAnnotatedLines {
25452550
.unwrap_or(ann.line_start);
25462551
for line in ann.line_start + 1..until {
25472552
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
2548-
add_annotation_to_file(&mut output, file.clone(), line, ann.as_line());
2553+
add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
25492554
}
25502555
let line_end = ann.line_end - 1;
25512556
if middle < line_end {
2552-
add_annotation_to_file(&mut output, file.clone(), line_end, ann.as_line());
2557+
add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
25532558
}
25542559
} else {
25552560
end_ann.annotation_type = AnnotationType::Singleline;

compiler/rustc_errors/src/json.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ impl Diagnostic {
367367
ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)),
368368
ColorConfig::Never => {}
369369
}
370-
HumanEmitter::new(dst, je.fallback_bundle.clone())
370+
HumanEmitter::new(dst, Lrc::clone(&je.fallback_bundle))
371371
.short_message(short)
372-
.sm(Some(je.sm.clone()))
372+
.sm(Some(Lrc::clone(&je.sm)))
373373
.fluent_bundle(je.fluent_bundle.clone())
374374
.diagnostic_width(je.diagnostic_width)
375375
.macro_backtrace(je.macro_backtrace)

compiler/rustc_expand/src/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl TtParser {
622622
// possible next positions into `next_mps`. After some post-processing, the contents of
623623
// `next_mps` replenish `cur_mps` and we start over again.
624624
self.cur_mps.clear();
625-
self.cur_mps.push(MatcherPos { idx: 0, matches: self.empty_matches.clone() });
625+
self.cur_mps.push(MatcherPos { idx: 0, matches: Rc::clone(&self.empty_matches) });
626626

627627
loop {
628628
self.next_mps.clear();

0 commit comments

Comments
 (0)