Skip to content

Commit

Permalink
Convert Option<&Lrc<T>> return types to Option<&T>.
Browse files Browse the repository at this point in the history
It's simpler and more concise.
  • Loading branch information
nnethercote committed Oct 7, 2024
1 parent 55a22d2 commit 731469f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_ast::attr;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::Emitter;
use rustc_errors::translation::Translate;
use rustc_errors::{
Expand Down Expand Up @@ -1889,7 +1888,7 @@ impl SharedEmitter {
}

impl Translate for SharedEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
fn fluent_bundle(&self) -> Option<&FluentBundle> {
None
}

Expand Down Expand Up @@ -1924,7 +1923,7 @@ impl Emitter for SharedEmitter {
);
}

fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct AnnotateSnippetEmitter {
}

impl Translate for AnnotateSnippetEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
self.fluent_bundle.as_ref()
fn fluent_bundle(&self) -> Option<&FluentBundle> {
self.fluent_bundle.as_deref()
}

fn fallback_fluent_bundle(&self) -> &FluentBundle {
Expand Down Expand Up @@ -69,8 +69,8 @@ impl Emitter for AnnotateSnippetEmitter {
);
}

fn source_map(&self) -> Option<&Lrc<SourceMap>> {
self.source_map.as_ref()
fn source_map(&self) -> Option<&SourceMap> {
self.source_map.as_deref()
}

fn should_show_explain(&self) -> bool {
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub trait Emitter: Translate {
false
}

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

/// Formats the substitutions of the primary_span
///
Expand Down Expand Up @@ -481,8 +481,8 @@ pub trait Emitter: Translate {
}

impl Translate for HumanEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
self.fluent_bundle.as_ref()
fn fluent_bundle(&self) -> Option<&FluentBundle> {
self.fluent_bundle.as_deref()
}

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

impl Emitter for HumanEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
self.sm.as_ref()
fn source_map(&self) -> Option<&SourceMap> {
self.sm.as_deref()
}

fn emit_diagnostic(&mut self, mut diag: DiagInner) {
Expand Down Expand Up @@ -540,7 +540,7 @@ pub struct SilentEmitter {
}

impl Translate for SilentEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
fn fluent_bundle(&self) -> Option<&FluentBundle> {
None
}

Expand All @@ -552,7 +552,7 @@ impl Translate for SilentEmitter {
}

impl Emitter for SilentEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ enum EmitTyped<'a> {
}

impl Translate for JsonEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
self.fluent_bundle.as_ref()
fn fluent_bundle(&self) -> Option<&FluentBundle> {
self.fluent_bundle.as_deref()
}

fn fallback_fluent_bundle(&self) -> &FluentBundle {
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Emitter for JsonEmitter {
}
}

fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
Some(&self.sm)
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use registry::Registry;
use rustc_data_structures::AtomicRef;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
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::{
DiagMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel,
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
Expand Down Expand Up @@ -685,13 +685,13 @@ impl DiagCtxt {
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`")
}
}

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`")
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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::{DiagMessage, langid};

Expand All @@ -12,7 +12,7 @@ struct Dummy {
}

impl Translate for Dummy {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
fn fluent_bundle(&self) -> Option<&FluentBundle> {
None
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_errors/src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::borrow::Cow;
use std::env;
use std::error::Report;

use rustc_data_structures::sync::Lrc;
pub use rustc_error_messages::FluentArgs;
use tracing::{debug, trace};

Expand Down Expand Up @@ -33,7 +32,7 @@ pub trait Translate {
/// 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`
/// 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.
/// Used when the user has not requested a specific language or when a localized diagnostic is
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/lint/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct BufferEmitter {
}

impl Translate for BufferEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
None
}

Expand All @@ -169,7 +169,7 @@ impl Emitter for BufferEmitter {
}
}

fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}
}
8 changes: 4 additions & 4 deletions src/tools/rustfmt/src/parse/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl 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()
}

Expand All @@ -56,7 +56,7 @@ impl Translate for SilentOnIgnoredFilesEmitter {
}

impl Emitter for SilentOnIgnoredFilesEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}

Expand Down Expand Up @@ -344,7 +344,7 @@ mod tests {
}

impl Translate for TestEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> {
None
}

Expand All @@ -354,7 +354,7 @@ mod tests {
}

impl Emitter for TestEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
fn source_map(&self) -> Option<&SourceMap> {
None
}

Expand Down

0 comments on commit 731469f

Please sign in to comment.