1
Fork 0

Rollup merge of #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 https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443.

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
This commit is contained in:
Jubilee 2024-10-29 03:11:39 -07:00 committed by GitHub
commit 5d0f52efa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 100 additions and 92 deletions

View file

@ -63,7 +63,7 @@ pub struct CachingSourceMapView<'sm> {
impl<'sm> CachingSourceMapView<'sm> {
pub fn new(source_map: &'sm SourceMap) -> CachingSourceMapView<'sm> {
let files = source_map.files();
let first_file = files[0].clone();
let first_file = Lrc::clone(&files[0]);
let entry = CacheEntry {
time_stamp: 0,
line_number: 0,
@ -92,7 +92,7 @@ impl<'sm> CachingSourceMapView<'sm> {
cache_entry.touch(self.time_stamp);
let col = RelativeBytePos(pos.to_u32() - cache_entry.line.start.to_u32());
return Some((cache_entry.file.clone(), cache_entry.line_number, col));
return Some((Lrc::clone(&cache_entry.file), cache_entry.line_number, col));
}
// No cache hit ...
@ -109,7 +109,7 @@ impl<'sm> CachingSourceMapView<'sm> {
cache_entry.update(new_file_and_idx, pos, self.time_stamp);
let col = RelativeBytePos(pos.to_u32() - cache_entry.line.start.to_u32());
Some((cache_entry.file.clone(), cache_entry.line_number, col))
Some((Lrc::clone(&cache_entry.file), cache_entry.line_number, col))
}
pub fn span_data_to_lines_and_cols(
@ -133,7 +133,7 @@ impl<'sm> CachingSourceMapView<'sm> {
}
(
lo.file.clone(),
Lrc::clone(&lo.file),
lo.line_number,
span_data.lo - lo.line.start,
hi.line_number,
@ -181,7 +181,7 @@ impl<'sm> CachingSourceMapView<'sm> {
lo.update(new_file_and_idx, span_data.lo, self.time_stamp);
if !lo.line.contains(&span_data.hi) {
let new_file_and_idx = Some((lo.file.clone(), lo.file_index));
let new_file_and_idx = Some((Lrc::clone(&lo.file), lo.file_index));
let next_oldest = self.oldest_cache_entry_index_avoid(oldest);
let hi = &mut self.line_cache[next_oldest];
hi.update(new_file_and_idx, span_data.hi, self.time_stamp);
@ -227,7 +227,7 @@ impl<'sm> CachingSourceMapView<'sm> {
assert_eq!(lo.file_index, hi.file_index);
Some((
lo.file.clone(),
Lrc::clone(&lo.file),
lo.line_number,
span_data.lo - lo.line.start,
hi.line_number,
@ -277,7 +277,7 @@ impl<'sm> CachingSourceMapView<'sm> {
let file = &self.source_map.files()[file_idx];
if file_contains(file, pos) {
return Some((file.clone(), file_idx));
return Some((Lrc::clone(file), file_idx));
}
}

View file

@ -286,8 +286,8 @@ impl SourceMap {
});
let file = Lrc::new(file);
files.source_files.push(file.clone());
files.stable_id_to_source_file.insert(file_id, file.clone());
files.source_files.push(Lrc::clone(&file));
files.stable_id_to_source_file.insert(file_id, Lrc::clone(&file));
Ok(file)
}
@ -386,7 +386,7 @@ impl SourceMap {
/// Return the SourceFile that contains the given `BytePos`
pub fn lookup_source_file(&self, pos: BytePos) -> Lrc<SourceFile> {
let idx = self.lookup_source_file_idx(pos);
(*self.files.borrow().source_files)[idx].clone()
Lrc::clone(&(*self.files.borrow().source_files)[idx])
}
/// Looks up source information about a `BytePos`.
@ -468,7 +468,7 @@ impl SourceMap {
if lo != hi {
return true;
}
let f = (*self.files.borrow().source_files)[lo].clone();
let f = Lrc::clone(&(*self.files.borrow().source_files)[lo]);
let lo = f.relative_position(sp.lo());
let hi = f.relative_position(sp.hi());
f.lookup_line(lo) != f.lookup_line(hi)
@ -994,7 +994,7 @@ impl SourceMap {
let filename = self.path_mapping().map_filename_prefix(filename).0;
for sf in self.files.borrow().source_files.iter() {
if filename == sf.name {
return Some(sf.clone());
return Some(Lrc::clone(&sf));
}
}
None
@ -1003,7 +1003,7 @@ impl SourceMap {
/// For a global `BytePos`, computes the local offset within the containing `SourceFile`.
pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos {
let idx = self.lookup_source_file_idx(bpos);
let sf = (*self.files.borrow().source_files)[idx].clone();
let sf = Lrc::clone(&(*self.files.borrow().source_files)[idx]);
let offset = bpos - sf.start_pos;
SourceFileAndBytePos { sf, pos: offset }
}