Skip to content

Commit 527b357

Browse files
committed
Use a dedicated type instead of a reference for the diagnostic context
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
1 parent d565d3d commit 527b357

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/back/lto.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
2828
use rustc_codegen_ssa::traits::*;
2929
use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind};
3030
use rustc_data_structures::memmap::Mmap;
31-
use rustc_errors::{DiagCtxt, FatalError};
31+
use rustc_errors::{DiagCtxtHandle, FatalError};
3232
use rustc_hir::def_id::LOCAL_CRATE;
3333
use rustc_middle::dep_graph::WorkProduct;
3434
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
@@ -59,7 +59,7 @@ struct LtoData {
5959

6060
fn prepare_lto(
6161
cgcx: &CodegenContext<GccCodegenBackend>,
62-
dcx: &DiagCtxt,
62+
dcx: DiagCtxtHandle<'_>,
6363
) -> Result<LtoData, FatalError> {
6464
let export_threshold = match cgcx.lto {
6565
// We're just doing LTO for our one crate
@@ -179,12 +179,13 @@ pub(crate) fn run_fat(
179179
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
180180
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
181181
let dcx = cgcx.create_dcx();
182-
let lto_data = prepare_lto(cgcx, &dcx)?;
182+
let dcx = dcx.handle();
183+
let lto_data = prepare_lto(cgcx, dcx)?;
183184
/*let symbols_below_threshold =
184185
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
185186
fat_lto(
186187
cgcx,
187-
&dcx,
188+
dcx,
188189
modules,
189190
cached_modules,
190191
lto_data.upstream_modules,
@@ -195,7 +196,7 @@ pub(crate) fn run_fat(
195196

196197
fn fat_lto(
197198
cgcx: &CodegenContext<GccCodegenBackend>,
198-
_dcx: &DiagCtxt,
199+
_dcx: DiagCtxtHandle<'_>,
199200
modules: Vec<FatLtoInput<GccCodegenBackend>>,
200201
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
201202
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,

src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gccjit::OutputKind;
44
use rustc_codegen_ssa::back::link::ensure_removed;
55
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
66
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
7-
use rustc_errors::DiagCtxt;
7+
use rustc_errors::DiagCtxtHandle;
88
use rustc_fs_util::link_or_copy;
99
use rustc_session::config::OutputType;
1010
use rustc_span::fatal_error::FatalError;
@@ -15,7 +15,7 @@ use crate::{GccCodegenBackend, GccContext};
1515

1616
pub(crate) unsafe fn codegen(
1717
cgcx: &CodegenContext<GccCodegenBackend>,
18-
dcx: &DiagCtxt,
18+
dcx: DiagCtxtHandle<'_>,
1919
module: ModuleCodegen<GccContext>,
2020
config: &ModuleConfig,
2121
) -> Result<CompiledModule, FatalError> {
@@ -166,7 +166,7 @@ pub(crate) unsafe fn codegen(
166166

167167
pub(crate) fn link(
168168
_cgcx: &CodegenContext<GccCodegenBackend>,
169-
_dcx: &DiagCtxt,
169+
_dcx: DiagCtxtHandle<'_>,
170170
mut _modules: Vec<ModuleCodegen<GccContext>>,
171171
) -> Result<ModuleCodegen<GccContext>, FatalError> {
172172
unimplemented!();

src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
1+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level};
22
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_span::Span;
44

@@ -90,7 +90,7 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
9090
pub(crate) struct MissingFeatures;
9191

9292
impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
93-
fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
93+
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
9494
let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable);
9595
if let Some(span) = self.span {
9696
diag.span(span);

src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616
#![allow(internal_features)]
1717
#![doc(rust_logo)]
1818
#![feature(rustdoc_internals)]
19-
#![feature(
20-
rustc_private,
21-
decl_macro,
22-
never_type,
23-
trusted_len,
24-
hash_raw_entry
25-
)]
19+
#![feature(rustc_private, decl_macro, never_type, trusted_len, hash_raw_entry)]
2620
#![allow(broken_intra_doc_links)]
2721
#![recursion_limit = "256"]
2822
#![warn(rust_2018_idioms)]
@@ -104,7 +98,7 @@ use rustc_codegen_ssa::traits::{
10498
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
10599
use rustc_data_structures::fx::FxIndexMap;
106100
use rustc_data_structures::sync::IntoDynSyncSend;
107-
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
101+
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
108102
use rustc_metadata::EncodedMetadata;
109103
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
110104
use rustc_middle::ty::TyCtxt;
@@ -386,7 +380,7 @@ impl WriteBackendMethods for GccCodegenBackend {
386380

387381
unsafe fn optimize(
388382
_cgcx: &CodegenContext<Self>,
389-
_dcx: &DiagCtxt,
383+
_dcx: DiagCtxtHandle<'_>,
390384
module: &ModuleCodegen<Self::Module>,
391385
config: &ModuleConfig,
392386
) -> Result<(), FatalError> {
@@ -411,14 +405,17 @@ impl WriteBackendMethods for GccCodegenBackend {
411405

412406
unsafe fn codegen(
413407
cgcx: &CodegenContext<Self>,
414-
dcx: &DiagCtxt,
408+
dcx: DiagCtxtHandle<'_>,
415409
module: ModuleCodegen<Self::Module>,
416410
config: &ModuleConfig,
417411
) -> Result<CompiledModule, FatalError> {
418412
back::write::codegen(cgcx, dcx, module, config)
419413
}
420414

421-
fn prepare_thin(_module: ModuleCodegen<Self::Module>, _emit_summary: bool) -> (String, Self::ThinBuffer) {
415+
fn prepare_thin(
416+
_module: ModuleCodegen<Self::Module>,
417+
_emit_summary: bool,
418+
) -> (String, Self::ThinBuffer) {
422419
unimplemented!();
423420
}
424421

@@ -428,7 +425,7 @@ impl WriteBackendMethods for GccCodegenBackend {
428425

429426
fn run_link(
430427
cgcx: &CodegenContext<Self>,
431-
dcx: &DiagCtxt,
428+
dcx: DiagCtxtHandle<'_>,
432429
modules: Vec<ModuleCodegen<Self::Module>>,
433430
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
434431
back::write::link(cgcx, dcx, modules)

0 commit comments

Comments
 (0)