Skip to content

Commit eb55cdc

Browse files
committed
use ParseSess instead of Session in into_diagnostic
1 parent fedbe5d commit eb55cdc

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

compiler/rustc_macros/src/session_diagnostic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ fn span_err(span: impl proc_macro::MultiSpan, msg: &str) -> proc_macro::Diagnost
119119
/// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration
120120
/// using the `FnOnce` passed in `diag`) and return `Err(ErrorHandled)`.
121121
macro_rules! throw_span_err {
122-
($span:expr, $msg:expr) => {{ throw_span_err!($span, $msg, |diag| diag) }};
122+
($span:expr, $msg:expr) => {{
123+
throw_span_err!($span, $msg, |diag| diag)
124+
}};
123125
($span:expr, $msg:expr, $f:expr) => {{
124126
return Err(_throw_span_err($span, $msg, $f));
125127
}};
@@ -308,7 +310,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
308310
{
309311
fn into_diagnostic(
310312
self,
311-
#sess: &'__session_diagnostic_sess rustc_session::Session
313+
#sess: &'__session_diagnostic_sess rustc_session::parse::ParseSess
312314
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, #param_ty> {
313315
use rustc_errors::IntoDiagnosticArg;
314316
#implementation

compiler/rustc_session/src/parse.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
44
use crate::config::CheckCfg;
55
use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId};
6+
use crate::SessionDiagnostic;
67
use rustc_ast::node_id::NodeId;
78
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
89
use rustc_data_structures::sync::{Lock, Lrc};
910
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1011
use rustc_errors::{
1112
error_code, fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder,
12-
ErrorGuaranteed, MultiSpan,
13+
DiagnosticMessage, ErrorGuaranteed, MultiSpan,
1314
};
1415
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
1516
use rustc_span::edition::Edition;
@@ -287,4 +288,19 @@ impl ParseSess {
287288
pub fn proc_macro_quoted_spans(&self) -> Vec<Span> {
288289
self.proc_macro_quoted_spans.lock().clone()
289290
}
291+
292+
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
293+
err.into_diagnostic(self).emit()
294+
}
295+
296+
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) {
297+
warning.into_diagnostic(self).emit()
298+
}
299+
300+
pub fn struct_err(
301+
&self,
302+
msg: impl Into<DiagnosticMessage>,
303+
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
304+
self.span_diagnostic.struct_err(msg)
305+
}
290306
}

compiler/rustc_session/src/session.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub struct PerfStats {
212212
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
213213
/// Write out as a diagnostic out of `sess`.
214214
#[must_use]
215-
fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a, T>;
215+
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, T>;
216216
}
217217

218218
impl Session {
@@ -334,7 +334,7 @@ impl Session {
334334
&self,
335335
msg: impl Into<DiagnosticMessage>,
336336
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
337-
self.diagnostic().struct_err(msg)
337+
self.parse_sess.struct_err(msg)
338338
}
339339
pub fn struct_err_with_code(
340340
&self,
@@ -414,10 +414,10 @@ impl Session {
414414
self.diagnostic().err(msg)
415415
}
416416
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
417-
err.into_diagnostic(self).emit()
417+
self.parse_sess.emit_err(err)
418418
}
419419
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) {
420-
warning.into_diagnostic(self).emit()
420+
self.parse_sess.emit_warning(warning)
421421
}
422422
#[inline]
423423
pub fn err_count(&self) -> usize {
@@ -783,7 +783,11 @@ impl Session {
783783
Path::new(&rustlib_path),
784784
Path::new("bin"),
785785
]);
786-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
786+
if self_contained {
787+
vec![p.clone(), p.join("self-contained")]
788+
} else {
789+
vec![p]
790+
}
787791
}
788792

789793
pub fn init_incr_comp_session(

0 commit comments

Comments
 (0)