diff options
| author | Christian Poveda <git@pvdrz.com> | 2022-04-25 22:53:09 +0200 |
|---|---|---|
| committer | Christian Poveda <git@pvdrz.com> | 2022-04-25 22:54:16 +0200 |
| commit | eb55cdce4bc1c03e1ce805af633dac611a948d43 (patch) | |
| tree | 698491ccbb08c4fa847876d37fe742369a8ca9c7 | |
| parent | fedbe5dabc815bd710217221bfebad1ff9f37a43 (diff) | |
| download | rust-eb55cdce4bc1c03e1ce805af633dac611a948d43.tar.gz rust-eb55cdce4bc1c03e1ce805af633dac611a948d43.zip | |
use `ParseSess` instead of `Session` in `into_diagnostic`
| -rw-r--r-- | compiler/rustc_macros/src/session_diagnostic.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 14 |
3 files changed, 30 insertions, 8 deletions
diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs index ff7506979fc..5661451f520 100644 --- a/compiler/rustc_macros/src/session_diagnostic.rs +++ b/compiler/rustc_macros/src/session_diagnostic.rs @@ -119,7 +119,9 @@ fn span_err(span: impl proc_macro::MultiSpan, msg: &str) -> proc_macro::Diagnost /// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration /// using the `FnOnce` passed in `diag`) and return `Err(ErrorHandled)`. macro_rules! throw_span_err { - ($span:expr, $msg:expr) => {{ throw_span_err!($span, $msg, |diag| diag) }}; + ($span:expr, $msg:expr) => {{ + throw_span_err!($span, $msg, |diag| diag) + }}; ($span:expr, $msg:expr, $f:expr) => {{ return Err(_throw_span_err($span, $msg, $f)); }}; @@ -308,7 +310,7 @@ impl<'a> SessionDiagnosticDerive<'a> { { fn into_diagnostic( self, - #sess: &'__session_diagnostic_sess rustc_session::Session + #sess: &'__session_diagnostic_sess rustc_session::parse::ParseSess ) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, #param_ty> { use rustc_errors::IntoDiagnosticArg; #implementation diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 6a36ae63c68..dd7682ebace 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -3,13 +3,14 @@ use crate::config::CheckCfg; use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId}; +use crate::SessionDiagnostic; use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{ error_code, fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, - ErrorGuaranteed, MultiSpan, + DiagnosticMessage, ErrorGuaranteed, MultiSpan, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -287,4 +288,19 @@ impl ParseSess { pub fn proc_macro_quoted_spans(&self) -> Vec<Span> { self.proc_macro_quoted_spans.lock().clone() } + + pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { + err.into_diagnostic(self).emit() + } + + pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { + warning.into_diagnostic(self).emit() + } + + pub fn struct_err( + &self, + msg: impl Into<DiagnosticMessage>, + ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + self.span_diagnostic.struct_err(msg) + } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b4548129689..2bc0c5f1228 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -212,7 +212,7 @@ pub struct PerfStats { pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `sess`. #[must_use] - fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a, T>; + fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, T>; } impl Session { @@ -334,7 +334,7 @@ impl Session { &self, msg: impl Into<DiagnosticMessage>, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - self.diagnostic().struct_err(msg) + self.parse_sess.struct_err(msg) } pub fn struct_err_with_code( &self, @@ -414,10 +414,10 @@ impl Session { self.diagnostic().err(msg) } pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { - err.into_diagnostic(self).emit() + self.parse_sess.emit_err(err) } pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { - warning.into_diagnostic(self).emit() + self.parse_sess.emit_warning(warning) } #[inline] pub fn err_count(&self) -> usize { @@ -783,7 +783,11 @@ impl Session { Path::new(&rustlib_path), Path::new("bin"), ]); - if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] } + if self_contained { + vec![p.clone(), p.join("self-contained")] + } else { + vec![p] + } } pub fn init_incr_comp_session( |
