Rollup merge of #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`
This commit is contained in:
commit
df61a0b1b2
16 changed files with 45 additions and 39 deletions
|
@ -11,7 +11,6 @@ use rustc_ast::attr;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_data_structures::memmap::Mmap;
|
use rustc_data_structures::memmap::Mmap;
|
||||||
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
|
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
|
||||||
use rustc_data_structures::sync::Lrc;
|
|
||||||
use rustc_errors::emitter::Emitter;
|
use rustc_errors::emitter::Emitter;
|
||||||
use rustc_errors::translation::Translate;
|
use rustc_errors::translation::Translate;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
|
@ -1889,7 +1888,7 @@ impl SharedEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for SharedEmitter {
|
impl Translate for SharedEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1924,7 +1923,7 @@ impl Emitter for SharedEmitter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ pub struct AnnotateSnippetEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for AnnotateSnippetEmitter {
|
impl Translate for AnnotateSnippetEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
self.fluent_bundle.as_ref()
|
self.fluent_bundle.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
|
@ -69,8 +69,8 @@ impl Emitter for AnnotateSnippetEmitter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
self.source_map.as_ref()
|
self.source_map.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_show_explain(&self) -> bool {
|
fn should_show_explain(&self) -> bool {
|
||||||
|
|
|
@ -205,7 +205,7 @@ pub trait Emitter: Translate {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>>;
|
fn source_map(&self) -> Option<&SourceMap>;
|
||||||
|
|
||||||
/// Formats the substitutions of the primary_span
|
/// Formats the substitutions of the primary_span
|
||||||
///
|
///
|
||||||
|
@ -481,8 +481,8 @@ pub trait Emitter: Translate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for HumanEmitter {
|
impl Translate for HumanEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
self.fluent_bundle.as_ref()
|
self.fluent_bundle.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
|
@ -491,8 +491,8 @@ impl Translate for HumanEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for HumanEmitter {
|
impl Emitter for HumanEmitter {
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
self.sm.as_ref()
|
self.sm.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
||||||
|
@ -540,7 +540,7 @@ pub struct SilentEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for SilentEmitter {
|
impl Translate for SilentEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +552,7 @@ impl Translate for SilentEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SilentEmitter {
|
impl Emitter for SilentEmitter {
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,8 +111,8 @@ enum EmitTyped<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for JsonEmitter {
|
impl Translate for JsonEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
self.fluent_bundle.as_ref()
|
self.fluent_bundle.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
fn fallback_fluent_bundle(&self) -> &FluentBundle {
|
||||||
|
@ -172,7 +172,7 @@ impl Emitter for JsonEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
Some(&self.sm)
|
Some(&self.sm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ use registry::Registry;
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::Lock;
|
||||||
pub use rustc_error_messages::{
|
pub use rustc_error_messages::{
|
||||||
DiagMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel,
|
DiagMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel,
|
||||||
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
|
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
|
||||||
|
@ -685,13 +685,13 @@ impl DiagCtxt {
|
||||||
unimplemented!("false emitter must only used during `wrap_emitter`")
|
unimplemented!("false emitter must only used during `wrap_emitter`")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
unimplemented!("false emitter must only used during `wrap_emitter`")
|
unimplemented!("false emitter must only used during `wrap_emitter`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl translation::Translate for FalseEmitter {
|
impl translation::Translate for FalseEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
unimplemented!("false emitter must only used during `wrap_emitter`")
|
unimplemented!("false emitter must only used during `wrap_emitter`")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
|
use rustc_data_structures::sync::IntoDynSyncSend;
|
||||||
use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError};
|
use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError};
|
||||||
use rustc_error_messages::{DiagMessage, langid};
|
use rustc_error_messages::{DiagMessage, langid};
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ struct Dummy {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for Dummy {
|
impl Translate for Dummy {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&FluentBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Report;
|
use std::error::Report;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
|
||||||
pub use rustc_error_messages::FluentArgs;
|
pub use rustc_error_messages::FluentArgs;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ pub trait Translate {
|
||||||
/// Return `FluentBundle` with localized diagnostics for the locale requested by the user. If no
|
/// Return `FluentBundle` with localized diagnostics for the locale requested by the user. If no
|
||||||
/// language was requested by the user then this will be `None` and `fallback_fluent_bundle`
|
/// language was requested by the user then this will be `None` and `fallback_fluent_bundle`
|
||||||
/// should be used.
|
/// should be used.
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>>;
|
fn fluent_bundle(&self) -> Option<&FluentBundle>;
|
||||||
|
|
||||||
/// Return `FluentBundle` with localized diagnostics for the default locale of the compiler.
|
/// Return `FluentBundle` with localized diagnostics for the default locale of the compiler.
|
||||||
/// Used when the user has not requested a specific language or when a localized diagnostic is
|
/// Used when the user has not requested a specific language or when a localized diagnostic is
|
||||||
|
|
|
@ -749,7 +749,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
in_regions: &Lrc<Vec<ty::Region<'tcx>>>,
|
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
|
||||||
) {
|
) {
|
||||||
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
|
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
|
||||||
key,
|
key,
|
||||||
|
|
|
@ -358,7 +358,15 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
// not currently sound until we have existential regions.
|
// not currently sound until we have existential regions.
|
||||||
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
op: |r| self.member_constraint(opaque_type_key, span, concrete_ty, r, &choice_regions),
|
op: |r| {
|
||||||
|
self.member_constraint(
|
||||||
|
opaque_type_key,
|
||||||
|
span,
|
||||||
|
concrete_ty,
|
||||||
|
r,
|
||||||
|
choice_regions.clone(),
|
||||||
|
)
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -522,7 +522,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
member_region: ty::Region<'tcx>,
|
member_region: ty::Region<'tcx>,
|
||||||
choice_regions: &Lrc<Vec<ty::Region<'tcx>>>,
|
choice_regions: Lrc<Vec<ty::Region<'tcx>>>,
|
||||||
) {
|
) {
|
||||||
debug!("member_constraint({:?} in {:#?})", member_region, choice_regions);
|
debug!("member_constraint({:?} in {:#?})", member_region, choice_regions);
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||||
definition_span,
|
definition_span,
|
||||||
hidden_ty,
|
hidden_ty,
|
||||||
member_region,
|
member_region,
|
||||||
choice_regions: choice_regions.clone(),
|
choice_regions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::any::Any;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_data_structures::sync::{Lrc, join};
|
use rustc_data_structures::sync::join;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||||
use rustc_hir::{HirId, intravisit as hir_visit};
|
use rustc_hir::{HirId, intravisit as hir_visit};
|
||||||
|
@ -36,8 +36,7 @@ use crate::{LateContext, LateLintPass, LintStore};
|
||||||
///
|
///
|
||||||
/// This function exists because [`Session::lint_store`] is type-erased.
|
/// This function exists because [`Session::lint_store`] is type-erased.
|
||||||
pub fn unerased_lint_store(sess: &Session) -> &LintStore {
|
pub fn unerased_lint_store(sess: &Session) -> &LintStore {
|
||||||
let store: &Lrc<_> = sess.lint_store.as_ref().unwrap();
|
let store: &dyn Any = sess.lint_store.as_deref().unwrap();
|
||||||
let store: &dyn Any = &**store;
|
|
||||||
store.downcast_ref().unwrap()
|
store.downcast_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1380,7 +1380,7 @@ pub enum ExternalSourceKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternalSource {
|
impl ExternalSource {
|
||||||
pub fn get_source(&self) -> Option<&Lrc<String>> {
|
pub fn get_source(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
ExternalSource::Foreign { kind: ExternalSourceKind::Present(ref src), .. } => Some(src),
|
ExternalSource::Foreign { kind: ExternalSourceKind::Present(ref src), .. } => Some(src),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -257,7 +257,7 @@ fn t10() {
|
||||||
);
|
);
|
||||||
imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
|
imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
imported_src_file.external_src.borrow().get_source().unwrap().as_ref(),
|
imported_src_file.external_src.borrow().get_source().unwrap(),
|
||||||
normalized,
|
normalized,
|
||||||
"imported source file should be normalized"
|
"imported source file should be normalized"
|
||||||
);
|
);
|
||||||
|
|
|
@ -145,7 +145,7 @@ struct BufferEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for BufferEmitter {
|
impl Translate for BufferEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ impl Emitter for BufferEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,7 @@ impl SourceFileRange {
|
||||||
self.sf
|
self.sf
|
||||||
.src
|
.src
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
.map(|src| src.as_str())
|
||||||
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
|
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
|
||||||
.and_then(|x| x.get(self.range.clone()))
|
.and_then(|x| x.get(self.range.clone()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl SilentOnIgnoredFilesEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for SilentOnIgnoredFilesEmitter {
|
impl Translate for SilentOnIgnoredFilesEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
|
||||||
self.emitter.fluent_bundle()
|
self.emitter.fluent_bundle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ impl Translate for SilentOnIgnoredFilesEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SilentOnIgnoredFilesEmitter {
|
impl Emitter for SilentOnIgnoredFilesEmitter {
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Translate for TestEmitter {
|
impl Translate for TestEmitter {
|
||||||
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
|
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for TestEmitter {
|
impl Emitter for TestEmitter {
|
||||||
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
|
fn source_map(&self) -> Option<&SourceMap> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue