Skip to content

Commit 1a1876c

Browse files
committed
Auto merge of #121804 - GuillaumeGomez:rollup-jh0v3ex, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #119748 (Increase visibility of `join_path` and `split_paths`) - #120820 (Enable CMPXCHG16B, SSE3, SAHF/LAHF and 128-bit Atomics (in nightly) in Windows x64) - #121000 (pattern_analysis: rework how we hide empty private fields) - #121376 (Skip unnecessary comparison with half-open range patterns) - #121596 (Use volatile access instead of `#[used]` for `on_tls_callback`) - #121669 (Count stashed errors again) - #121783 (Emitter cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 384d26f + 0e9f02d commit 1a1876c

File tree

66 files changed

+767
-715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+767
-715
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
373373

374374
impl<B: WriteBackendMethods> CodegenContext<B> {
375375
pub fn create_dcx(&self) -> DiagCtxt {
376-
DiagCtxt::with_emitter(Box::new(self.diag_emitter.clone()))
376+
DiagCtxt::new(Box::new(self.diag_emitter.clone()))
377377
}
378378

379379
pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {

compiler/rustc_driver_impl/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
2121
use rustc_data_structures::profiling::{
2222
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
2323
};
24+
use rustc_errors::emitter::stderr_destination;
2425
use rustc_errors::registry::Registry;
2526
use rustc_errors::{
2627
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
@@ -1384,11 +1385,11 @@ fn report_ice(
13841385
) {
13851386
let fallback_bundle =
13861387
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
1387-
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::stderr(
1388-
rustc_errors::ColorConfig::Auto,
1388+
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::new(
1389+
stderr_destination(rustc_errors::ColorConfig::Auto),
13891390
fallback_bundle,
13901391
));
1391-
let dcx = rustc_errors::DiagCtxt::with_emitter(emitter);
1392+
let dcx = rustc_errors::DiagCtxt::new(emitter);
13921393

13931394
// a .span_bug or .bug call has already printed what
13941395
// it wants to print.

compiler/rustc_errors/src/diagnostic.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1308,11 +1308,9 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
13081308
drop(self);
13091309
}
13101310

1311-
/// Stashes diagnostic for possible later improvement in a different,
1312-
/// later stage of the compiler. The diagnostic can be accessed with
1313-
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
1314-
pub fn stash(mut self, span: Span, key: StashKey) {
1315-
self.dcx.stash_diagnostic(span, key, self.take_diag());
1311+
/// See `DiagCtxt::stash_diagnostic` for details.
1312+
pub fn stash(mut self, span: Span, key: StashKey) -> Option<ErrorGuaranteed> {
1313+
self.dcx.stash_diagnostic(span, key, self.take_diag())
13161314
}
13171315

13181316
/// Delay emission of this diagnostic as a bug.

compiler/rustc_errors/src/emitter.rs

+16-45
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ use crate::{
2121
FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight,
2222
SuggestionStyle, TerminalUrl,
2323
};
24-
use rustc_lint_defs::pluralize;
25-
2624
use derive_setters::Setters;
2725
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
2826
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
2927
use rustc_error_messages::{FluentArgs, SpanLabel};
28+
use rustc_lint_defs::pluralize;
3029
use rustc_span::hygiene::{ExpnKind, MacroKind};
3130
use std::borrow::Cow;
3231
use std::cmp::{max, min, Reverse};
@@ -35,7 +34,7 @@ use std::io::prelude::*;
3534
use std::io::{self, IsTerminal};
3635
use std::iter;
3736
use std::path::Path;
38-
use termcolor::{Ansi, Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
37+
use termcolor::{Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
3938
use termcolor::{Color, WriteColor};
4039

4140
/// Default column width, used in tests and when terminal dimensions cannot be determined.
@@ -58,18 +57,6 @@ impl HumanReadableErrorType {
5857
HumanReadableErrorType::AnnotateSnippet(cc) => (false, cc),
5958
}
6059
}
61-
pub fn new_emitter(
62-
self,
63-
mut dst: Box<dyn WriteColor + Send>,
64-
fallback_bundle: LazyFallbackBundle,
65-
) -> HumanEmitter {
66-
let (short, color_config) = self.unzip();
67-
let color = color_config.suggests_using_colors();
68-
if !dst.supports_color() && color {
69-
dst = Box::new(Ansi::new(dst));
70-
}
71-
HumanEmitter::new(dst, fallback_bundle).short_message(short)
72-
}
7360
}
7461

7562
#[derive(Clone, Copy, Debug)]
@@ -130,8 +117,8 @@ impl Margin {
130117
fn was_cut_right(&self, line_len: usize) -> bool {
131118
let right =
132119
if self.computed_right == self.span_right || self.computed_right == self.label_right {
133-
// Account for the "..." padding given above. Otherwise we end up with code lines that
134-
// do fit but end in "..." as if they were trimmed.
120+
// Account for the "..." padding given above. Otherwise we end up with code lines
121+
// that do fit but end in "..." as if they were trimmed.
135122
self.computed_right - 6
136123
} else {
137124
self.computed_right
@@ -628,12 +615,6 @@ impl ColorConfig {
628615
ColorConfig::Auto => ColorChoice::Never,
629616
}
630617
}
631-
fn suggests_using_colors(self) -> bool {
632-
match self {
633-
ColorConfig::Always | ColorConfig::Auto => true,
634-
ColorConfig::Never => false,
635-
}
636-
}
637618
}
638619

639620
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
@@ -657,19 +638,14 @@ pub struct HumanEmitter {
657638
}
658639

659640
#[derive(Debug)]
660-
pub struct FileWithAnnotatedLines {
661-
pub file: Lrc<SourceFile>,
662-
pub lines: Vec<Line>,
641+
pub(crate) struct FileWithAnnotatedLines {
642+
pub(crate) file: Lrc<SourceFile>,
643+
pub(crate) lines: Vec<Line>,
663644
multiline_depth: usize,
664645
}
665646

666647
impl HumanEmitter {
667-
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
668-
let dst = from_stderr(color_config);
669-
Self::create(dst, fallback_bundle)
670-
}
671-
672-
fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
648+
pub fn new(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
673649
HumanEmitter {
674650
dst: IntoDynSyncSend(dst),
675651
sm: None,
@@ -686,13 +662,6 @@ impl HumanEmitter {
686662
}
687663
}
688664

689-
pub fn new(
690-
dst: Box<dyn WriteColor + Send>,
691-
fallback_bundle: LazyFallbackBundle,
692-
) -> HumanEmitter {
693-
Self::create(dst, fallback_bundle)
694-
}
695-
696665
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
697666
if self.ui_testing {
698667
Cow::Borrowed(ANONYMIZED_LINE_NUM)
@@ -724,8 +693,9 @@ impl HumanEmitter {
724693
.skip(left)
725694
.take_while(|ch| {
726695
// Make sure that the trimming on the right will fall within the terminal width.
727-
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
728-
// For now, just accept that sometimes the code line will be longer than desired.
696+
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char`
697+
// is. For now, just accept that sometimes the code line will be longer than
698+
// desired.
729699
let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
730700
if taken + next > right - left {
731701
return false;
@@ -2228,8 +2198,8 @@ impl HumanEmitter {
22282198
buffer.puts(*row_num - 1, max_line_num_len + 3, &line, Style::NoStyle);
22292199
*row_num += 1;
22302200
}
2231-
// If the last line is exactly equal to the line we need to add, we can skip both of them.
2232-
// This allows us to avoid output like the following:
2201+
// If the last line is exactly equal to the line we need to add, we can skip both of
2202+
// them. This allows us to avoid output like the following:
22332203
// 2 - &
22342204
// 2 + if true { true } else { false }
22352205
// 3 - if true { true } else { false }
@@ -2586,6 +2556,7 @@ fn num_overlap(
25862556
let extra = if inclusive { 1 } else { 0 };
25872557
(b_start..b_end + extra).contains(&a_start) || (a_start..a_end + extra).contains(&b_start)
25882558
}
2559+
25892560
fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
25902561
num_overlap(
25912562
a1.start_col.display,
@@ -2632,7 +2603,7 @@ fn emit_to_destination(
26322603
Ok(())
26332604
}
26342605

2635-
pub type Destination = Box<(dyn WriteColor + Send)>;
2606+
pub type Destination = Box<dyn WriteColor + Send>;
26362607

26372608
struct Buffy {
26382609
buffer_writer: BufferWriter,
@@ -2674,7 +2645,7 @@ impl WriteColor for Buffy {
26742645
}
26752646
}
26762647

2677-
fn from_stderr(color: ColorConfig) -> Destination {
2648+
pub fn stderr_destination(color: ColorConfig) -> Destination {
26782649
let choice = color.to_color_choice();
26792650
// On Windows we'll be performing global synchronization on the entire
26802651
// system for emitting rustc errors, so there's no need to buffer

compiler/rustc_errors/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ impl<'args> TranslateError<'args> {
2323
pub fn message(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
2424
Self::One { id, args, kind: TranslateErrorKind::MessageMissing }
2525
}
26+
2627
pub fn primary(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
2728
Self::One { id, args, kind: TranslateErrorKind::PrimaryBundleMissing }
2829
}
30+
2931
pub fn attribute(
3032
id: &'args Cow<'args, str>,
3133
args: &'args FluentArgs<'args>,
3234
attr: &'args str,
3335
) -> Self {
3436
Self::One { id, args, kind: TranslateErrorKind::AttributeMissing { attr } }
3537
}
38+
3639
pub fn value(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
3740
Self::One { id, args, kind: TranslateErrorKind::ValueMissing }
3841
}

0 commit comments

Comments
 (0)