errors: implement IntoDiagnosticArg
for &T
Implement `IntoDiagnosticArg` for `&'a T` when `T` implements `IntoDiagnosticArg` and `Clone`. Makes it easier to write diagnostic structs that borrow something which implements `IntoDiagnosticArg`. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
59cc5e5d59
commit
f7b42102e6
3 changed files with 13 additions and 13 deletions
|
@ -187,6 +187,12 @@ impl Display for RegionName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl rustc_errors::IntoDiagnosticArg for RegionName {
|
||||||
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
||||||
|
self.to_string().into_diagnostic_arg()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
|
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
|
||||||
self.body.source.def_id().expect_local()
|
self.body.source.def_id().expect_local()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
|
use rustc_errors::MultiSpan;
|
||||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::{GenericArg, Ty};
|
use rustc_middle::ty::{GenericArg, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -128,18 +128,6 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for &RegionName {
|
|
||||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
|
||||||
format!("{}", self).into_diagnostic_arg()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for RegionName {
|
|
||||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
|
||||||
format!("{}", self).into_diagnostic_arg()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum RequireStaticErr {
|
pub(crate) enum RequireStaticErr {
|
||||||
#[note(borrowck_used_impl_require_static)]
|
#[note(borrowck_used_impl_require_static)]
|
||||||
|
|
|
@ -36,6 +36,12 @@ impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
self.clone().into_diagnostic_arg()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! into_diagnostic_arg_using_display {
|
macro_rules! into_diagnostic_arg_using_display {
|
||||||
($( $ty:ty ),+ $(,)?) => {
|
($( $ty:ty ),+ $(,)?) => {
|
||||||
$(
|
$(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue