use emitter::{is_case_difference, Emitter, EmitterWriter};
use registry::Registry;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
-use rustc_data_structures::stable_hasher::StableHasher;
-use rustc_data_structures::sync::{self, Lock, Lrc};
+use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
+use rustc_data_structures::sync::{self, IntoDynSyncSend, Lock, Lrc};
use rustc_data_structures::AtomicRef;
pub use rustc_error_messages::{
fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle,
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
};
+use rustc_fluent_macro::fluent_messages;
pub use rustc_lint_defs::{pluralize, Applicability};
-use rustc_macros::fluent_messages;
use rustc_span::source_map::SourceMap;
pub use rustc_span::ErrorGuaranteed;
use rustc_span::{Loc, Span};
});
buf.push_str(&part.snippet);
let cur_hi = sm.lookup_char_pos(part.span.hi());
- if cur_hi.line == cur_lo.line && !part.snippet.is_empty() {
- // Account for the difference between the width of the current code and the
- // snippet being suggested, so that the *later* suggestions are correctly
- // aligned on the screen.
- acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
- }
+ // Account for the difference between the width of the current code and the
+ // snippet being suggested, so that the *later* suggestions are correctly
+ // aligned on the screen. Note that cur_hi and cur_lo can be on different
+ // lines, so cur_hi.col can be smaller than cur_lo.col
+ acc += len - (cur_hi.col.0 as isize - cur_lo.col.0 as isize);
prev_hi = cur_hi;
prev_line = sf.get_line(prev_hi.line - 1);
for line in part.snippet.split('\n').skip(1) {
err_count: usize,
warn_count: usize,
deduplicated_err_count: usize,
- emitter: Box<dyn Emitter + sync::Send>,
+ emitter: IntoDynSyncSend<Box<dyn Emitter + sync::Send>>,
delayed_span_bugs: Vec<DelayedDiagnostic>,
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
/// This flag indicates that an expected diagnostic was emitted and suppressed.
/// This set contains a hash of every diagnostic that has been emitted by
/// this handler. These hashes is used to avoid emitting the same error
/// twice.
- emitted_diagnostics: FxHashSet<u128>,
+ emitted_diagnostics: FxHashSet<Hash128>,
/// Stashed diagnostics emitted in one stage of the compiler that may be
/// stolen by other stages (e.g. to improve them and add more information).
/// FRU syntax
MaybeFruTypo,
CallAssocMethod,
+ TraitMissingMethod,
+ OpaqueHiddenTypeMismatch,
}
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {
warn_count: 0,
deduplicated_err_count: 0,
deduplicated_warn_count: 0,
- emitter,
+ emitter: IntoDynSyncSend(emitter),
delayed_span_bugs: Vec::new(),
delayed_good_path_bugs: Vec::new(),
suppressed_expected_diag: false,
}
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
- self.inner.borrow().has_errors().then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .has_errors_or_lint_errors()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors_or_lint_errors().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn has_errors_or_delayed_span_bugs(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .has_errors_or_delayed_span_bugs()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().has_errors_or_delayed_span_bugs().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
- self.inner
- .borrow()
- .is_compilation_going_to_fail()
- .then(ErrorGuaranteed::unchecked_claim_error_was_emitted)
+ self.inner.borrow().is_compilation_going_to_fail().then(|| {
+ #[allow(deprecated)]
+ ErrorGuaranteed::unchecked_claim_error_was_emitted()
+ })
}
pub fn print_error_count(&self, registry: &Registry) {
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
if !self.flags.report_delayed_bugs {
+ #[allow(deprecated)]
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
}
}
self.bump_err_count();
}
- guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
+ #[allow(deprecated)]
+ {
+ guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
+ }
} else {
self.bump_warn_count();
}
}
fn treat_err_as_bug(&self) -> bool {
- self.flags.treat_err_as_bug.map_or(false, |c| {
+ self.flags.treat_err_as_bug.is_some_and(|c| {
self.err_count() + self.lint_err_count + self.delayed_bug_count() >= c.get()
})
}
DiagnosticMessage::Str(warnings),
)),
(_, 0) => {
- let _ = self.fatal(&errors);
+ let _ = self.fatal(errors);
}
(_, _) => {
- let _ = self.fatal(&format!("{}; {}", &errors, &warnings));
+ let _ = self.fatal(format!("{}; {}", &errors, &warnings));
}
}
error_codes.sort();
if error_codes.len() > 1 {
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
- self.failure(&format!(
+ self.failure(format!(
"Some errors have detailed explanations: {}{}",
error_codes[..limit].join(", "),
if error_codes.len() > 9 { "..." } else { "." }
));
- self.failure(&format!(
+ self.failure(format!(
"For more information about an error, try \
`rustc --explain {}`.",
&error_codes[0]
));
} else {
- self.failure(&format!(
+ self.failure(format!(
"For more information about this error, try \
`rustc --explain {}`.",
&error_codes[0]
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
// incrementing `err_count` by one, so we need to +1 the comparing.
// FIXME: Would be nice to increment err_count in a more coherent way.
- if self.flags.treat_err_as_bug.map_or(false, |c| {
+ if self.flags.treat_err_as_bug.is_some_and(|c| {
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
}) {
// FIXME: don't abort here if report_delayed_bugs is off
if bug.level != Level::DelayedBug {
// NOTE(eddyb) not panicking here because we're already producing
// an ICE, and the more information the merrier.
- bug.note(&format!(
+ bug.note(format!(
"`flushed_delayed` got diagnostic with level {:?}, \
instead of the expected `DelayedBug`",
bug.level,
}
fn decorate(mut self) -> Diagnostic {
- self.inner.note(&format!("delayed at {}", self.note));
+ self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
self.inner
}
}
if incl_angl_brckt { format!("<{}>", anon_lts) } else { format!("{}, ", anon_lts) };
diag.span_suggestion_verbose(
insertion_span.shrink_to_hi(),
- &format!("indicate the anonymous lifetime{}", pluralize!(n)),
+ format!("indicate the anonymous lifetime{}", pluralize!(n)),
suggestion,
Applicability::MachineApplicable,
);