diff options
Diffstat (limited to 'compiler/rustc_session')
| -rw-r--r-- | compiler/rustc_session/src/errors.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 74 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 20 |
3 files changed, 24 insertions, 93 deletions
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 9f7d918d98b..0f86773b73f 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -364,13 +364,14 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: } let token::Lit { kind, symbol, suffix, .. } = lit; + let dcx = &sess.dcx; match err { // `LexerError` is an error, but it was already reported // by lexer, so here we don't report it the second time. LitError::LexerError => {} LitError::InvalidSuffix => { if let Some(suffix) = suffix { - sess.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix }); + dcx.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix }); } } LitError::InvalidIntSuffix => { @@ -378,11 +379,11 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: let suf = suf.as_str(); if looks_like_width_suffix(&['i', 'u'], suf) { // If it looks like a width, try to be helpful. - sess.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() }); + dcx.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() }); } else if let Some(fixed) = fix_base_capitalisation(symbol.as_str(), suf) { - sess.emit_err(InvalidNumLiteralBasePrefix { span, fixed }); + dcx.emit_err(InvalidNumLiteralBasePrefix { span, fixed }); } else { - sess.emit_err(InvalidNumLiteralSuffix { span, suffix: suf.to_string() }); + dcx.emit_err(InvalidNumLiteralSuffix { span, suffix: suf.to_string() }); } } LitError::InvalidFloatSuffix => { @@ -390,16 +391,16 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: let suf = suf.as_str(); if looks_like_width_suffix(&['f'], suf) { // If it looks like a width, try to be helpful. - sess.emit_err(InvalidFloatLiteralWidth { span, width: suf[1..].to_string() }); + dcx.emit_err(InvalidFloatLiteralWidth { span, width: suf[1..].to_string() }); } else { - sess.emit_err(InvalidFloatLiteralSuffix { span, suffix: suf.to_string() }); + dcx.emit_err(InvalidFloatLiteralSuffix { span, suffix: suf.to_string() }); } } LitError::NonDecimalFloat(base) => { match base { - 16 => sess.emit_err(HexadecimalFloatLiteralNotSupported { span }), - 8 => sess.emit_err(OctalFloatLiteralNotSupported { span }), - 2 => sess.emit_err(BinaryFloatLiteralNotSupported { span }), + 16 => dcx.emit_err(HexadecimalFloatLiteralNotSupported { span }), + 8 => dcx.emit_err(OctalFloatLiteralNotSupported { span }), + 2 => dcx.emit_err(BinaryFloatLiteralNotSupported { span }), _ => unreachable!(), }; } @@ -411,13 +412,13 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: 16 => format!("{max:#x}"), _ => format!("{max}"), }; - sess.emit_err(IntLiteralTooLarge { span, limit }); + dcx.emit_err(IntLiteralTooLarge { span, limit }); } LitError::NulInCStr(range) => { let lo = BytePos(span.lo().0 + range.start as u32 + 2); let hi = BytePos(span.lo().0 + range.end as u32 + 2); let span = span.with_lo(lo).with_hi(hi); - sess.emit_err(NulInCStr { span }); + dcx.emit_err(NulInCStr { span }); } } } diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 52a637b74e7..439fa18b7fa 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -14,7 +14,7 @@ use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, DiagCtxt}; use rustc_errors::{ fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, - ErrorGuaranteed, FatalAbort, IntoDiagnostic, Level, MultiSpan, StashKey, + MultiSpan, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -108,7 +108,7 @@ pub fn feature_err_issue( } } - let mut err = sess.create_err(FeatureGateError { span, explain: explain.into() }); + let mut err = sess.dcx.create_err(FeatureGateError { span, explain: explain.into() }); add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); err } @@ -316,74 +316,4 @@ impl ParseSess { // AppendOnlyVec, so we resort to this scheme. self.proc_macro_quoted_spans.iter_enumerated() } - - #[track_caller] - pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> { - err.into_diagnostic(&self.dcx, Level::Error { lint: false }) - } - - #[track_caller] - pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { - self.create_err(err).emit() - } - - #[track_caller] - pub fn create_warning<'a>( - &'a self, - warning: impl IntoDiagnostic<'a, ()>, - ) -> DiagnosticBuilder<'a, ()> { - warning.into_diagnostic(&self.dcx, Level::Warning(None)) - } - - #[track_caller] - pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { - self.create_warning(warning).emit() - } - - #[track_caller] - pub fn create_note<'a>( - &'a self, - note: impl IntoDiagnostic<'a, ()>, - ) -> DiagnosticBuilder<'a, ()> { - note.into_diagnostic(&self.dcx, Level::Note) - } - - #[track_caller] - pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) { - self.create_note(note).emit() - } - - #[track_caller] - pub fn create_fatal<'a>( - &'a self, - fatal: impl IntoDiagnostic<'a, FatalAbort>, - ) -> DiagnosticBuilder<'a, FatalAbort> { - fatal.into_diagnostic(&self.dcx, Level::Fatal) - } - - #[track_caller] - pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, FatalAbort>) -> ! { - self.create_fatal(fatal).emit() - } - - #[rustc_lint_diagnostics] - #[track_caller] - pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> { - self.dcx.struct_err(msg) - } - - #[rustc_lint_diagnostics] - #[track_caller] - pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> { - self.dcx.struct_warn(msg) - } - - #[rustc_lint_diagnostics] - #[track_caller] - pub fn struct_fatal( - &self, - msg: impl Into<DiagnosticMessage>, - ) -> DiagnosticBuilder<'_, FatalAbort> { - self.dcx.struct_fatal(msg) - } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 272e231d3ed..45e6f445600 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -371,7 +371,7 @@ impl Session { #[rustc_lint_diagnostics] #[track_caller] pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> { - self.parse_sess.struct_err(msg) + self.dcx().struct_err(msg) } #[track_caller] #[rustc_lint_diagnostics] @@ -461,7 +461,7 @@ impl Session { } #[track_caller] pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> { - self.parse_sess.create_err(err) + self.dcx().create_err(err) } #[track_caller] pub fn create_feature_err<'a>( @@ -469,7 +469,7 @@ impl Session { err: impl IntoDiagnostic<'a>, feature: Symbol, ) -> DiagnosticBuilder<'a> { - let mut err = self.parse_sess.create_err(err); + let mut err = self.dcx().create_err(err); if err.code.is_none() { err.code(error_code!(E0658)); } @@ -478,40 +478,40 @@ impl Session { } #[track_caller] pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { - self.parse_sess.emit_err(err) + self.dcx().emit_err(err) } #[track_caller] pub fn create_warning<'a>( &'a self, err: impl IntoDiagnostic<'a, ()>, ) -> DiagnosticBuilder<'a, ()> { - self.parse_sess.create_warning(err) + self.dcx().create_warning(err) } #[track_caller] pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { - self.parse_sess.emit_warning(warning) + self.dcx().emit_warning(warning) } #[track_caller] pub fn create_note<'a>( &'a self, note: impl IntoDiagnostic<'a, ()>, ) -> DiagnosticBuilder<'a, ()> { - self.parse_sess.create_note(note) + self.dcx().create_note(note) } #[track_caller] pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) { - self.parse_sess.emit_note(note) + self.dcx().emit_note(note) } #[track_caller] pub fn create_fatal<'a>( &'a self, fatal: impl IntoDiagnostic<'a, FatalAbort>, ) -> DiagnosticBuilder<'a, FatalAbort> { - self.parse_sess.create_fatal(fatal) + self.dcx().create_fatal(fatal) } #[track_caller] pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, FatalAbort>) -> ! { - self.parse_sess.emit_fatal(fatal) + self.dcx().emit_fatal(fatal) } #[inline] pub fn err_count(&self) -> usize { |
