Skip to content

Commit 6a05cd8

Browse files
committed
A more general implementation of IntoDiagnosticArg for Binder (Also removes DiagArg, as it's no longer necessary)
1 parent fd18d9a commit 6a05cd8

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

compiler/rustc_infer/src/errors/mod.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1146,14 +1146,6 @@ pub struct OpaqueCapturesLifetime<'tcx> {
11461146
pub opaque_ty: Ty<'tcx>,
11471147
}
11481148

1149-
pub struct DiagArg<T>(pub T);
1150-
1151-
impl<T: ToString> IntoDiagnosticArg for DiagArg<T> {
1152-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
1153-
self.0.to_string().into_diagnostic_arg()
1154-
}
1155-
}
1156-
11571149
#[derive(Subdiagnostic)]
11581150
pub enum FunctionPointerSuggestion<'a> {
11591151
#[suggestion(
@@ -1221,7 +1213,7 @@ pub enum FunctionPointerSuggestion<'a> {
12211213
fn_name: String,
12221214
#[skip_arg]
12231215
found_sig: Binder<'a, FnSig<'a>>,
1224-
expected_sig: DiagArg<Binder<'a, FnSig<'a>>>,
1216+
expected_sig: Binder<'a, FnSig<'a>>,
12251217
},
12261218
#[suggestion(
12271219
infer_fps_cast_both,
@@ -1236,7 +1228,7 @@ pub enum FunctionPointerSuggestion<'a> {
12361228
fn_name: String,
12371229
#[skip_arg]
12381230
found_sig: Binder<'a, FnSig<'a>>,
1239-
expected_sig: DiagArg<Binder<'a, FnSig<'a>>>,
1231+
expected_sig: Binder<'a, FnSig<'a>>,
12401232
},
12411233
}
12421234

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::{sym, BytePos, Span};
1313
use rustc_target::abi::FieldIdx;
1414

1515
use crate::errors::{
16-
ConsiderAddingAwait, DiagArg, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
16+
ConsiderAddingAwait, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
1717
FunctionPointerSuggestion, SuggestAccessingField, SuggestAsRefWhereAppropriate,
1818
SuggestBoxingForReturnImplTrait, SuggestRemoveSemiOrReturnBinding, SuggestTuplePatternMany,
1919
SuggestTuplePatternOne, TypeErrorAdditionalDiags,
@@ -379,14 +379,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
379379
span,
380380
fn_name,
381381
found_sig: *found_sig,
382-
expected_sig: DiagArg(*expected_sig),
382+
expected_sig: *expected_sig,
383383
}
384384
} else {
385385
FunctionPointerSuggestion::CastBoth {
386386
span,
387387
fn_name,
388388
found_sig: *found_sig,
389-
expected_sig: DiagArg(*expected_sig),
389+
expected_sig: *expected_sig,
390390
}
391391
};
392392

compiler/rustc_middle/src/ty/sty.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use hir::def::DefKind;
1515
use polonius_engine::Atom;
1616
use rustc_data_structures::captures::Captures;
1717
use rustc_data_structures::intern::Interned;
18+
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
1819
use rustc_hir as hir;
1920
use rustc_hir::def_id::DefId;
2021
use rustc_hir::LangItem;
@@ -26,7 +27,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
2627
use rustc_target::spec::abi::{self, Abi};
2728
use std::borrow::Cow;
2829
use std::cmp::Ordering;
29-
use std::fmt;
30+
use std::fmt::{self, Display};
3031
use std::marker::PhantomData;
3132
use std::ops::{ControlFlow, Deref, Range};
3233
use ty::util::IntTypeExt;
@@ -877,12 +878,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
877878
}
878879
}
879880

880-
impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {
881-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
882-
self.to_string().into_diagnostic_arg()
883-
}
884-
}
885-
886881
/// An existential reference to a trait, where `Self` is erased.
887882
/// For example, the trait object `Trait<'a, 'b, X, Y>` is:
888883
/// ```ignore (illustrative)
@@ -939,12 +934,6 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
939934
}
940935
}
941936

942-
impl rustc_errors::IntoDiagnosticArg for PolyExistentialTraitRef<'_> {
943-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
944-
self.to_string().into_diagnostic_arg()
945-
}
946-
}
947-
948937
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
949938
#[derive(HashStable)]
950939
pub enum BoundVariableKind {
@@ -1159,6 +1148,15 @@ impl<'tcx, T: IntoIterator> Binder<'tcx, T> {
11591148
}
11601149
}
11611150

1151+
impl<'tcx, T> IntoDiagnosticArg for Binder<'tcx, T>
1152+
where
1153+
Binder<'tcx, T>: Display,
1154+
{
1155+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
1156+
self.to_string().into_diagnostic_arg()
1157+
}
1158+
}
1159+
11621160
struct SkipBindersAt<'tcx> {
11631161
tcx: TyCtxt<'tcx>,
11641162
index: ty::DebruijnIndex,

0 commit comments

Comments
 (0)