Skip to content

Commit 270922f

Browse files
committed
Auto merge of #122033 - matthiaskrgr:rollup-t8g7wp1, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #121065 (Add basic i18n guidance for `Display`) - #121301 (errors: share `SilentEmitter` between rustc and rustfmt) - #121744 (Stop using Bubble in coherence and instead emulate it with an intercrate check) - #121829 (Dummy tweaks (attempt 2)) - #121857 (Implement async closure signature deduction) - #121894 (const_eval_select: make it safe but be careful with what we expose on stable for now) - #121905 (Add a `description` field to target definitions) - #122022 (loongarch: add frecipe and relax target feature) - #122028 (Remove some dead code) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 96561a8 + d85480c commit 270922f

File tree

264 files changed

+556
-201
lines changed

Some content is hidden

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

264 files changed

+556
-201
lines changed

compiler/rustc_ast/src/mut_visit.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,10 @@ pub fn noop_visit_capture_by<T: MutVisitor>(capture_by: &mut CaptureBy, vis: &mu
16041604
}
16051605
}
16061606

1607-
/// Some value for the AST node that is valid but possibly meaningless.
1607+
/// Some value for the AST node that is valid but possibly meaningless. Similar
1608+
/// to `Default` but not intended for wide use. The value will never be used
1609+
/// meaningfully, it exists just to support unwinding in `visit_clobber` in the
1610+
/// case where its closure panics.
16081611
pub trait DummyAstNode {
16091612
fn dummy() -> Self;
16101613
}
@@ -1679,19 +1682,6 @@ impl DummyAstNode for Stmt {
16791682
}
16801683
}
16811684

1682-
impl DummyAstNode for Block {
1683-
fn dummy() -> Self {
1684-
Block {
1685-
stmts: Default::default(),
1686-
id: DUMMY_NODE_ID,
1687-
rules: BlockCheckMode::Default,
1688-
span: Default::default(),
1689-
tokens: Default::default(),
1690-
could_be_bare_literal: Default::default(),
1691-
}
1692-
}
1693-
}
1694-
16951685
impl DummyAstNode for Crate {
16961686
fn dummy() -> Self {
16971687
Crate {

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
852852
}
853853

854854
let instance = match intrinsic {
855-
None | Some(ty::IntrinsicDef { name: sym::drop_in_place, .. }) => instance,
855+
None => instance,
856856
Some(intrinsic) => {
857857
let mut llargs = Vec::with_capacity(1);
858858
let ret_dest = self.make_return_dest(

compiler/rustc_errors/src/emitter.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use rustc_span::source_map::SourceMap;
1111
use rustc_span::{FileLines, FileName, SourceFile, Span};
1212

13-
use crate::error::TranslateError;
1413
use crate::snippet::{
1514
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
1615
};
@@ -539,18 +538,9 @@ impl Emitter for HumanEmitter {
539538
/// Fatal diagnostics are forwarded to `fatal_dcx` to avoid silent
540539
/// failures of rustc, as witnessed e.g. in issue #89358.
541540
pub struct SilentEmitter {
541+
pub fallback_bundle: LazyFallbackBundle,
542542
pub fatal_dcx: DiagCtxt,
543-
pub fatal_note: String,
544-
}
545-
546-
pub fn silent_translate<'a>(message: &'a DiagMessage) -> Result<Cow<'_, str>, TranslateError<'_>> {
547-
match message {
548-
DiagMessage::Str(msg) | DiagMessage::Translated(msg) => Ok(Cow::Borrowed(msg)),
549-
DiagMessage::FluentIdentifier(identifier, _) => {
550-
// Any value works here.
551-
Ok(identifier.clone())
552-
}
553-
}
543+
pub fatal_note: Option<String>,
554544
}
555545

556546
impl Translate for SilentEmitter {
@@ -559,17 +549,9 @@ impl Translate for SilentEmitter {
559549
}
560550

561551
fn fallback_fluent_bundle(&self) -> &FluentBundle {
562-
panic!("silent emitter attempted to translate message")
563-
}
564-
565-
// Override `translate_message` for the silent emitter because eager translation of
566-
// subdiagnostics result in a call to this.
567-
fn translate_message<'a>(
568-
&'a self,
569-
message: &'a DiagMessage,
570-
_: &'a FluentArgs<'_>,
571-
) -> Result<Cow<'_, str>, TranslateError<'_>> {
572-
silent_translate(message)
552+
// Ideally this field wouldn't be necessary and the fallback bundle in `fatal_dcx` would be
553+
// used but the lock prevents this.
554+
&self.fallback_bundle
573555
}
574556
}
575557

@@ -580,7 +562,9 @@ impl Emitter for SilentEmitter {
580562

581563
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
582564
if diag.level == Level::Fatal {
583-
diag.sub(Level::Note, self.fatal_note.clone(), MultiSpan::new());
565+
if let Some(fatal_note) = &self.fatal_note {
566+
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
567+
}
584568
self.fatal_dcx.emit_diagnostic(diag);
585569
}
586570
}

compiler/rustc_errors/src/lib.rs

+72-23
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use emitter::{is_case_difference, DynEmitter, Emitter};
6363
use registry::Registry;
6464
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
6565
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
66-
use rustc_data_structures::sync::Lock;
66+
use rustc_data_structures::sync::{Lock, Lrc};
6767
use rustc_data_structures::AtomicRef;
6868
use rustc_lint_defs::LintExpectationId;
6969
use rustc_span::source_map::SourceMap;
@@ -606,29 +606,54 @@ impl DiagCtxt {
606606
}
607607

608608
pub fn new(emitter: Box<DynEmitter>) -> Self {
609-
Self {
610-
inner: Lock::new(DiagCtxtInner {
611-
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
612-
err_guars: Vec::new(),
613-
lint_err_guars: Vec::new(),
614-
delayed_bugs: Vec::new(),
615-
deduplicated_err_count: 0,
616-
deduplicated_warn_count: 0,
617-
emitter,
618-
must_produce_diag: false,
619-
has_printed: false,
620-
suppressed_expected_diag: false,
621-
taught_diagnostics: Default::default(),
622-
emitted_diagnostic_codes: Default::default(),
623-
emitted_diagnostics: Default::default(),
624-
stashed_diagnostics: Default::default(),
625-
future_breakage_diagnostics: Vec::new(),
626-
check_unstable_expect_diagnostics: false,
627-
unstable_expect_diagnostics: Vec::new(),
628-
fulfilled_expectations: Default::default(),
629-
ice_file: None,
630-
}),
609+
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
610+
}
611+
612+
pub fn make_silent(&mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String>) {
613+
self.wrap_emitter(|old_dcx| {
614+
Box::new(emitter::SilentEmitter {
615+
fallback_bundle,
616+
fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) },
617+
fatal_note,
618+
})
619+
});
620+
}
621+
622+
fn wrap_emitter<F>(&mut self, f: F)
623+
where
624+
F: FnOnce(DiagCtxtInner) -> Box<DynEmitter>,
625+
{
626+
// A empty type that implements `Emitter` so that a `DiagCtxtInner` can be constructed
627+
// to temporarily swap in place of the real one, which will be used in constructing
628+
// its replacement.
629+
struct FalseEmitter;
630+
631+
impl Emitter for FalseEmitter {
632+
fn emit_diagnostic(&mut self, _: DiagInner) {
633+
unimplemented!("false emitter must only used during `wrap_emitter`")
634+
}
635+
636+
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
637+
unimplemented!("false emitter must only used during `wrap_emitter`")
638+
}
631639
}
640+
641+
impl translation::Translate for FalseEmitter {
642+
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
643+
unimplemented!("false emitter must only used during `wrap_emitter`")
644+
}
645+
646+
fn fallback_fluent_bundle(&self) -> &FluentBundle {
647+
unimplemented!("false emitter must only used during `wrap_emitter`")
648+
}
649+
}
650+
651+
let mut inner = self.inner.borrow_mut();
652+
let mut prev_dcx = DiagCtxtInner::new(Box::new(FalseEmitter));
653+
std::mem::swap(&mut *inner, &mut prev_dcx);
654+
let new_emitter = f(prev_dcx);
655+
let mut new_dcx = DiagCtxtInner::new(new_emitter);
656+
std::mem::swap(&mut *inner, &mut new_dcx);
632657
}
633658

634659
/// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`.
@@ -1345,6 +1370,30 @@ impl DiagCtxt {
13451370
// `DiagCtxt::foo()` just borrows `inner` and forwards a call to
13461371
// `DiagCtxtInner::foo`.
13471372
impl DiagCtxtInner {
1373+
fn new(emitter: Box<DynEmitter>) -> Self {
1374+
Self {
1375+
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
1376+
err_guars: Vec::new(),
1377+
lint_err_guars: Vec::new(),
1378+
delayed_bugs: Vec::new(),
1379+
deduplicated_err_count: 0,
1380+
deduplicated_warn_count: 0,
1381+
emitter,
1382+
must_produce_diag: false,
1383+
has_printed: false,
1384+
suppressed_expected_diag: false,
1385+
taught_diagnostics: Default::default(),
1386+
emitted_diagnostic_codes: Default::default(),
1387+
emitted_diagnostics: Default::default(),
1388+
stashed_diagnostics: Default::default(),
1389+
future_breakage_diagnostics: Vec::new(),
1390+
check_unstable_expect_diagnostics: false,
1391+
unstable_expect_diagnostics: Vec::new(),
1392+
fulfilled_expectations: Default::default(),
1393+
ice_file: None,
1394+
}
1395+
}
1396+
13481397
/// Emit all stashed diagnostics.
13491398
fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
13501399
let mut guar = None;

compiler/rustc_expand/src/base.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::expand::{self, AstFragment, Invocation};
44
use crate::module::DirOwnership;
55

66
use rustc_ast::attr::MarkedAttrs;
7-
use rustc_ast::mut_visit::DummyAstNode;
87
use rustc_ast::ptr::P;
98
use rustc_ast::token::{self, Nonterminal};
109
use rustc_ast::tokenstream::TokenStream;
@@ -582,6 +581,17 @@ impl DummyResult {
582581
tokens: None,
583582
})
584583
}
584+
585+
/// A plain dummy crate.
586+
pub fn raw_crate() -> ast::Crate {
587+
ast::Crate {
588+
attrs: Default::default(),
589+
items: Default::default(),
590+
spans: Default::default(),
591+
id: ast::DUMMY_NODE_ID,
592+
is_placeholder: Default::default(),
593+
}
594+
}
585595
}
586596

587597
impl MacResult for DummyResult {
@@ -650,7 +660,7 @@ impl MacResult for DummyResult {
650660
}
651661

652662
fn make_crate(self: Box<DummyResult>) -> Option<ast::Crate> {
653-
Some(DummyAstNode::dummy())
663+
Some(DummyResult::raw_crate())
654664
}
655665
}
656666

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
132132
| sym::fsub_algebraic
133133
| sym::fmul_algebraic
134134
| sym::fdiv_algebraic
135-
| sym::frem_algebraic => hir::Unsafety::Normal,
135+
| sym::frem_algebraic
136+
| sym::const_eval_select => hir::Unsafety::Normal,
136137
_ => hir::Unsafety::Unsafe,
137138
};
138139

@@ -247,7 +248,6 @@ pub fn check_intrinsic_type(
247248
],
248249
Ty::new_unit(tcx),
249250
),
250-
sym::drop_in_place => (1, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_unit(tcx)),
251251
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
252252

253253
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),

0 commit comments

Comments
 (0)