Skip to content

Commit df61a0b

Browse files
authored
Rollup merge of rust-lang#131344 - nnethercote:ref-Lrc, r=compiler-errors
Avoid `&Lrc<T>` in various places Seeing `&Lrc<T>` is a bit suspicious, and `&T` or `Lrc<T>` is often better. r? `@oli-obk`
2 parents 3a5a816 + 4547c0a commit df61a0b

File tree

16 files changed

+45
-39
lines changed

16 files changed

+45
-39
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ 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;
1514
use rustc_errors::emitter::Emitter;
1615
use rustc_errors::translation::Translate;
1716
use rustc_errors::{
@@ -1889,7 +1888,7 @@ impl SharedEmitter {
18891888
}
18901889

18911890
impl Translate for SharedEmitter {
1892-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
1891+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
18931892
None
18941893
}
18951894

@@ -1924,7 +1923,7 @@ impl Emitter for SharedEmitter {
19241923
);
19251924
}
19261925

1927-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
1926+
fn source_map(&self) -> Option<&SourceMap> {
19281927
None
19291928
}
19301929
}

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub struct AnnotateSnippetEmitter {
3434
}
3535

3636
impl Translate for AnnotateSnippetEmitter {
37-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
38-
self.fluent_bundle.as_ref()
37+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
38+
self.fluent_bundle.as_deref()
3939
}
4040

4141
fn fallback_fluent_bundle(&self) -> &FluentBundle {
@@ -69,8 +69,8 @@ impl Emitter for AnnotateSnippetEmitter {
6969
);
7070
}
7171

72-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
73-
self.source_map.as_ref()
72+
fn source_map(&self) -> Option<&SourceMap> {
73+
self.source_map.as_deref()
7474
}
7575

7676
fn should_show_explain(&self) -> bool {

compiler/rustc_errors/src/emitter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub trait Emitter: Translate {
205205
false
206206
}
207207

208-
fn source_map(&self) -> Option<&Lrc<SourceMap>>;
208+
fn source_map(&self) -> Option<&SourceMap>;
209209

210210
/// Formats the substitutions of the primary_span
211211
///
@@ -481,8 +481,8 @@ pub trait Emitter: Translate {
481481
}
482482

483483
impl Translate for HumanEmitter {
484-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
485-
self.fluent_bundle.as_ref()
484+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
485+
self.fluent_bundle.as_deref()
486486
}
487487

488488
fn fallback_fluent_bundle(&self) -> &FluentBundle {
@@ -491,8 +491,8 @@ impl Translate for HumanEmitter {
491491
}
492492

493493
impl Emitter for HumanEmitter {
494-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
495-
self.sm.as_ref()
494+
fn source_map(&self) -> Option<&SourceMap> {
495+
self.sm.as_deref()
496496
}
497497

498498
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
@@ -540,7 +540,7 @@ pub struct SilentEmitter {
540540
}
541541

542542
impl Translate for SilentEmitter {
543-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
543+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
544544
None
545545
}
546546

@@ -552,7 +552,7 @@ impl Translate for SilentEmitter {
552552
}
553553

554554
impl Emitter for SilentEmitter {
555-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
555+
fn source_map(&self) -> Option<&SourceMap> {
556556
None
557557
}
558558

compiler/rustc_errors/src/json.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ enum EmitTyped<'a> {
111111
}
112112

113113
impl Translate for JsonEmitter {
114-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
115-
self.fluent_bundle.as_ref()
114+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
115+
self.fluent_bundle.as_deref()
116116
}
117117

118118
fn fallback_fluent_bundle(&self) -> &FluentBundle {
@@ -172,7 +172,7 @@ impl Emitter for JsonEmitter {
172172
}
173173
}
174174

175-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
175+
fn source_map(&self) -> Option<&SourceMap> {
176176
Some(&self.sm)
177177
}
178178

compiler/rustc_errors/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use registry::Registry;
5959
use rustc_data_structures::AtomicRef;
6060
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
6161
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
62-
use rustc_data_structures::sync::{Lock, Lrc};
62+
use rustc_data_structures::sync::Lock;
6363
pub use rustc_error_messages::{
6464
DiagMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel,
6565
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
@@ -685,13 +685,13 @@ impl DiagCtxt {
685685
unimplemented!("false emitter must only used during `wrap_emitter`")
686686
}
687687

688-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
688+
fn source_map(&self) -> Option<&SourceMap> {
689689
unimplemented!("false emitter must only used during `wrap_emitter`")
690690
}
691691
}
692692

693693
impl translation::Translate for FalseEmitter {
694-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
694+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
695695
unimplemented!("false emitter must only used during `wrap_emitter`")
696696
}
697697

compiler/rustc_errors/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
1+
use rustc_data_structures::sync::IntoDynSyncSend;
22
use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError};
33
use rustc_error_messages::{DiagMessage, langid};
44

@@ -12,7 +12,7 @@ struct Dummy {
1212
}
1313

1414
impl Translate for Dummy {
15-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
15+
fn fluent_bundle(&self) -> Option<&FluentBundle> {
1616
None
1717
}
1818

compiler/rustc_errors/src/translation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::Cow;
22
use std::env;
33
use std::error::Report;
44

5-
use rustc_data_structures::sync::Lrc;
65
pub use rustc_error_messages::FluentArgs;
76
use tracing::{debug, trace};
87

@@ -33,7 +32,7 @@ pub trait Translate {
3332
/// Return `FluentBundle` with localized diagnostics for the locale requested by the user. If no
3433
/// language was requested by the user then this will be `None` and `fallback_fluent_bundle`
3534
/// should be used.
36-
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>>;
35+
fn fluent_bundle(&self) -> Option<&FluentBundle>;
3736

3837
/// Return `FluentBundle` with localized diagnostics for the default locale of the compiler.
3938
/// Used when the user has not requested a specific language or when a localized diagnostic is

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<'tcx> InferCtxt<'tcx> {
749749
definition_span: Span,
750750
hidden_ty: Ty<'tcx>,
751751
region: ty::Region<'tcx>,
752-
in_regions: &Lrc<Vec<ty::Region<'tcx>>>,
752+
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
753753
) {
754754
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
755755
key,

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,15 @@ impl<'tcx> InferCtxt<'tcx> {
358358
// not currently sound until we have existential regions.
359359
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
360360
tcx: self.tcx,
361-
op: |r| self.member_constraint(opaque_type_key, span, concrete_ty, r, &choice_regions),
361+
op: |r| {
362+
self.member_constraint(
363+
opaque_type_key,
364+
span,
365+
concrete_ty,
366+
r,
367+
choice_regions.clone(),
368+
)
369+
},
362370
});
363371
}
364372
}

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
522522
definition_span: Span,
523523
hidden_ty: Ty<'tcx>,
524524
member_region: ty::Region<'tcx>,
525-
choice_regions: &Lrc<Vec<ty::Region<'tcx>>>,
525+
choice_regions: Lrc<Vec<ty::Region<'tcx>>>,
526526
) {
527527
debug!("member_constraint({:?} in {:#?})", member_region, choice_regions);
528528

@@ -535,7 +535,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
535535
definition_span,
536536
hidden_ty,
537537
member_region,
538-
choice_regions: choice_regions.clone(),
538+
choice_regions,
539539
});
540540
}
541541

compiler/rustc_lint/src/late.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::any::Any;
1818
use std::cell::Cell;
1919

2020
use rustc_data_structures::stack::ensure_sufficient_stack;
21-
use rustc_data_structures::sync::{Lrc, join};
21+
use rustc_data_structures::sync::join;
2222
use rustc_hir as hir;
2323
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
2424
use rustc_hir::{HirId, intravisit as hir_visit};
@@ -36,8 +36,7 @@ use crate::{LateContext, LateLintPass, LintStore};
3636
///
3737
/// This function exists because [`Session::lint_store`] is type-erased.
3838
pub fn unerased_lint_store(sess: &Session) -> &LintStore {
39-
let store: &Lrc<_> = sess.lint_store.as_ref().unwrap();
40-
let store: &dyn Any = &**store;
39+
let store: &dyn Any = sess.lint_store.as_deref().unwrap();
4140
store.downcast_ref().unwrap()
4241
}
4342

compiler/rustc_span/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ pub enum ExternalSourceKind {
13801380
}
13811381

13821382
impl ExternalSource {
1383-
pub fn get_source(&self) -> Option<&Lrc<String>> {
1383+
pub fn get_source(&self) -> Option<&str> {
13841384
match self {
13851385
ExternalSource::Foreign { kind: ExternalSourceKind::Present(ref src), .. } => Some(src),
13861386
_ => None,

compiler/rustc_span/src/source_map/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ fn t10() {
257257
);
258258
imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
259259
assert_eq!(
260-
imported_src_file.external_src.borrow().get_source().unwrap().as_ref(),
260+
imported_src_file.external_src.borrow().get_source().unwrap(),
261261
normalized,
262262
"imported source file should be normalized"
263263
);

src/librustdoc/passes/lint/check_code_block_syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct BufferEmitter {
145145
}
146146

147147
impl Translate for BufferEmitter {
148-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
148+
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
149149
None
150150
}
151151

@@ -169,7 +169,7 @@ impl Emitter for BufferEmitter {
169169
}
170170
}
171171

172-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
172+
fn source_map(&self) -> Option<&SourceMap> {
173173
None
174174
}
175175
}

src/tools/clippy/clippy_utils/src/source.rs

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl SourceFileRange {
287287
self.sf
288288
.src
289289
.as_ref()
290+
.map(|src| src.as_str())
290291
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
291292
.and_then(|x| x.get(self.range.clone()))
292293
}

src/tools/rustfmt/src/parse/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl SilentOnIgnoredFilesEmitter {
4646
}
4747

4848
impl Translate for SilentOnIgnoredFilesEmitter {
49-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
49+
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
5050
self.emitter.fluent_bundle()
5151
}
5252

@@ -56,7 +56,7 @@ impl Translate for SilentOnIgnoredFilesEmitter {
5656
}
5757

5858
impl Emitter for SilentOnIgnoredFilesEmitter {
59-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
59+
fn source_map(&self) -> Option<&SourceMap> {
6060
None
6161
}
6262

@@ -344,7 +344,7 @@ mod tests {
344344
}
345345

346346
impl Translate for TestEmitter {
347-
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
347+
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
348348
None
349349
}
350350

@@ -354,7 +354,7 @@ mod tests {
354354
}
355355

356356
impl Emitter for TestEmitter {
357-
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
357+
fn source_map(&self) -> Option<&SourceMap> {
358358
None
359359
}
360360

0 commit comments

Comments
 (0)