diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-19 15:26:24 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-23 13:23:10 +1100 |
| commit | 757d6f6ef8567ec846a62f16e3691b7555f2545f (patch) | |
| tree | da16dce1d2e7d8f47288f65900ceebfc0aebbfbd /compiler/rustc_errors | |
| parent | 6257f3bf1f8679296eeb69b3578573d3fed78b31 (diff) | |
| download | rust-757d6f6ef8567ec846a62f16e3691b7555f2545f.tar.gz rust-757d6f6ef8567ec846a62f16e3691b7555f2545f.zip | |
Give `DiagnosticBuilder` a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_builder.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 18 |
2 files changed, 8 insertions, 14 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 828560ec452..e8cad62f393 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -43,7 +43,7 @@ where /// extending `DiagCtxtFlags`. #[must_use] #[derive(Clone)] -pub struct DiagnosticBuilder<'a, G: EmissionGuarantee> { +pub struct DiagnosticBuilder<'a, G: EmissionGuarantee = ErrorGuaranteed> { inner: DiagnosticBuilderInner<'a>, _marker: PhantomData<G>, } @@ -128,7 +128,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } } -impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> { +impl<'a> DiagnosticBuilder<'a> { /// Discard the guarantee `.emit()` would return, in favor of having the /// type `DiagnosticBuilder<'a, ()>`. This may be necessary whenever there /// is a common codepath handling both errors and warnings. diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index dafb67932a0..c48fe1ca8c2 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -91,7 +91,7 @@ mod styled_buffer; mod tests; pub mod translation; -pub type PErr<'a> = DiagnosticBuilder<'a, ErrorGuaranteed>; +pub type PErr<'a> = DiagnosticBuilder<'a>; pub type PResult<'a, T> = Result<T, PErr<'a>>; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } @@ -788,7 +788,7 @@ impl DiagCtxt { &self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + ) -> DiagnosticBuilder<'_> { let mut result = self.struct_err(msg); result.set_span(span); result @@ -802,7 +802,7 @@ impl DiagCtxt { span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>, code: DiagnosticId, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + ) -> DiagnosticBuilder<'_> { let mut result = self.struct_span_err(span, msg); result.code(code); result @@ -812,10 +812,7 @@ impl DiagCtxt { // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_err( - &self, - msg: impl Into<DiagnosticMessage>, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> { DiagnosticBuilder::new(self, Level::Error { lint: false }, msg) } @@ -826,7 +823,7 @@ impl DiagCtxt { &self, msg: impl Into<DiagnosticMessage>, code: DiagnosticId, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + ) -> DiagnosticBuilder<'_> { let mut result = self.struct_err(msg); result.code(code); result @@ -1221,10 +1218,7 @@ impl DiagCtxt { } #[track_caller] - pub fn create_err<'a>( - &'a self, - err: impl IntoDiagnostic<'a>, - ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> { err.into_diagnostic(self, Level::Error { lint: false }) } |
