@@ -50,6 +50,7 @@ use rustc_trait_selection::traits::{self, astconv_object_safety_violations, Obli
50
50
51
51
use smallvec:: { smallvec, SmallVec } ;
52
52
use std:: collections:: BTreeSet ;
53
+ use std:: fmt:: Display ;
53
54
use std:: slice;
54
55
55
56
#[ derive( Debug ) ]
@@ -1095,11 +1096,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1095
1096
// those that do.
1096
1097
self . one_bound_for_assoc_type (
1097
1098
|| traits:: supertraits ( tcx, trait_ref) ,
1098
- || trait_ref. print_only_trait_path ( ) . to_string ( ) ,
1099
+ trait_ref. print_only_trait_path ( ) ,
1099
1100
binding. item_name ,
1100
1101
path_span,
1101
- || match binding. kind {
1102
- ConvertedBindingKind :: Equality ( ty ) => Some ( ty . to_string ( ) ) ,
1102
+ match binding. kind {
1103
+ ConvertedBindingKind :: Equality ( term ) => Some ( term ) ,
1103
1104
_ => None ,
1104
1105
} ,
1105
1106
) ?
@@ -1789,10 +1790,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1789
1790
assoc_name,
1790
1791
)
1791
1792
} ,
1792
- || param_name. to_string ( ) ,
1793
+ param_name,
1793
1794
assoc_name,
1794
1795
span,
1795
- || None ,
1796
+ None ,
1796
1797
)
1797
1798
}
1798
1799
@@ -1802,10 +1803,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1802
1803
fn one_bound_for_assoc_type < I > (
1803
1804
& self ,
1804
1805
all_candidates : impl Fn ( ) -> I ,
1805
- ty_param_name : impl Fn ( ) -> String ,
1806
+ ty_param_name : impl Display ,
1806
1807
assoc_name : Ident ,
1807
1808
span : Span ,
1808
- is_equality : impl Fn ( ) -> Option < String > ,
1809
+ is_equality : Option < ty :: Term < ' tcx > > ,
1809
1810
) -> Result < ty:: PolyTraitRef < ' tcx > , ErrorGuaranteed >
1810
1811
where
1811
1812
I : Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
@@ -1821,7 +1822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1821
1822
( None , None ) => {
1822
1823
let reported = self . complain_about_assoc_type_not_found (
1823
1824
all_candidates,
1824
- & ty_param_name ( ) ,
1825
+ & ty_param_name. to_string ( ) ,
1825
1826
assoc_name,
1826
1827
span,
1827
1828
) ;
@@ -1833,7 +1834,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1833
1834
if let Some ( bound2) = next_cand {
1834
1835
debug ! ( ?bound2) ;
1835
1836
1836
- let is_equality = is_equality ( ) ;
1837
1837
let bounds = IntoIterator :: into_iter ( [ bound, bound2] ) . chain ( matching_candidates) ;
1838
1838
let mut err = if is_equality. is_some ( ) {
1839
1839
// More specific Error Index entry.
@@ -1843,7 +1843,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1843
1843
E0222 ,
1844
1844
"ambiguous associated type `{}` in bounds of `{}`" ,
1845
1845
assoc_name,
1846
- ty_param_name( )
1846
+ ty_param_name
1847
1847
)
1848
1848
} else {
1849
1849
struct_span_err ! (
@@ -1852,7 +1852,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1852
1852
E0221 ,
1853
1853
"ambiguous associated type `{}` in bounds of `{}`" ,
1854
1854
assoc_name,
1855
- ty_param_name( )
1855
+ ty_param_name
1856
1856
)
1857
1857
} ;
1858
1858
err. span_label ( span, format ! ( "ambiguous associated type `{}`" , assoc_name) ) ;
@@ -1886,18 +1886,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1886
1886
err. span_suggestion_verbose (
1887
1887
span. with_hi ( assoc_name. span . lo ( ) ) ,
1888
1888
"use fully qualified syntax to disambiguate" ,
1889
- format ! (
1890
- "<{} as {}>::" ,
1891
- ty_param_name( ) ,
1892
- bound. print_only_trait_path( ) ,
1893
- ) ,
1889
+ format ! ( "<{} as {}>::" , ty_param_name, bound. print_only_trait_path( ) ) ,
1894
1890
Applicability :: MaybeIncorrect ,
1895
1891
) ;
1896
1892
}
1897
1893
} else {
1898
1894
err. note ( & format ! (
1899
1895
"associated type `{}` could derive from `{}`" ,
1900
- ty_param_name( ) ,
1896
+ ty_param_name,
1901
1897
bound. print_only_trait_path( ) ,
1902
1898
) ) ;
1903
1899
}
@@ -1906,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1906
1902
err. help ( & format ! (
1907
1903
"consider introducing a new type parameter `T` and adding `where` constraints:\
1908
1904
\n where\n T: {},\n {}",
1909
- ty_param_name( ) ,
1905
+ ty_param_name,
1910
1906
where_bounds. join( ",\n " ) ,
1911
1907
) ) ;
1912
1908
}
@@ -2070,10 +2066,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2070
2066
2071
2067
self . one_bound_for_assoc_type (
2072
2068
|| traits:: supertraits ( tcx, ty:: Binder :: dummy ( trait_ref. subst_identity ( ) ) ) ,
2073
- || "Self" . to_string ( ) ,
2069
+ kw :: SelfUpper ,
2074
2070
assoc_ident,
2075
2071
span,
2076
- || None ,
2072
+ None ,
2077
2073
) ?
2078
2074
}
2079
2075
(
0 commit comments