@@ -1743,7 +1743,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1743
1743
}
1744
1744
}
1745
1745
1746
- if let Some ( ( expected, found, exp_p , found_p ) ) = expected_found {
1746
+ if let Some ( ( expected, found, path ) ) = expected_found {
1747
1747
let ( expected_label, found_label, exp_found) = match exp_found {
1748
1748
Mismatch :: Variable ( ef) => (
1749
1749
ef. expected . prefix_string ( self . tcx ) ,
@@ -1869,40 +1869,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1869
1869
}
1870
1870
TypeError :: Sorts ( values) => {
1871
1871
let extra = expected == found;
1872
- let sort_string = |ty : Ty < ' tcx > , path : Option < PathBuf > | {
1873
- let mut s = match ( extra, ty. kind ( ) ) {
1874
- ( true , ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) ) => {
1875
- let sm = self . tcx . sess . source_map ( ) ;
1876
- let pos = sm. lookup_char_pos ( self . tcx . def_span ( * def_id) . lo ( ) ) ;
1877
- format ! (
1878
- " (opaque type at <{}:{}:{}>)" ,
1879
- sm. filename_for_diagnostics( & pos. file. name) ,
1880
- pos. line,
1881
- pos. col. to_usize( ) + 1 ,
1882
- )
1883
- }
1884
- ( true , ty:: Alias ( ty:: Projection , proj) )
1885
- if self . tcx . is_impl_trait_in_trait ( proj. def_id ) =>
1886
- {
1887
- let sm = self . tcx . sess . source_map ( ) ;
1888
- let pos = sm. lookup_char_pos ( self . tcx . def_span ( proj. def_id ) . lo ( ) ) ;
1889
- format ! (
1890
- " (trait associated opaque type at <{}:{}:{}>)" ,
1891
- sm. filename_for_diagnostics( & pos. file. name) ,
1892
- pos. line,
1893
- pos. col. to_usize( ) + 1 ,
1894
- )
1895
- }
1896
- ( true , _) => format ! ( " ({})" , ty. sort_string( self . tcx) ) ,
1897
- ( false , _) => "" . to_string ( ) ,
1898
- } ;
1899
- if let Some ( path) = path {
1900
- s. push_str ( & format ! (
1901
- "\n the full type name has been written to '{}'" ,
1902
- path. display( ) ,
1903
- ) ) ;
1872
+ let sort_string = |ty : Ty < ' tcx > | match ( extra, ty. kind ( ) ) {
1873
+ ( true , ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) ) => {
1874
+ let sm = self . tcx . sess . source_map ( ) ;
1875
+ let pos = sm. lookup_char_pos ( self . tcx . def_span ( * def_id) . lo ( ) ) ;
1876
+ format ! (
1877
+ " (opaque type at <{}:{}:{}>)" ,
1878
+ sm. filename_for_diagnostics( & pos. file. name) ,
1879
+ pos. line,
1880
+ pos. col. to_usize( ) + 1 ,
1881
+ )
1904
1882
}
1905
- s
1883
+ ( true , ty:: Alias ( ty:: Projection , proj) )
1884
+ if self . tcx . is_impl_trait_in_trait ( proj. def_id ) =>
1885
+ {
1886
+ let sm = self . tcx . sess . source_map ( ) ;
1887
+ let pos = sm. lookup_char_pos ( self . tcx . def_span ( proj. def_id ) . lo ( ) ) ;
1888
+ format ! (
1889
+ " (trait associated opaque type at <{}:{}:{}>)" ,
1890
+ sm. filename_for_diagnostics( & pos. file. name) ,
1891
+ pos. line,
1892
+ pos. col. to_usize( ) + 1 ,
1893
+ )
1894
+ }
1895
+ ( true , _) => format ! ( " ({})" , ty. sort_string( self . tcx) ) ,
1896
+ ( false , _) => "" . to_string ( ) ,
1906
1897
} ;
1907
1898
if !( values. expected . is_simple_text ( self . tcx )
1908
1899
&& values. found . is_simple_text ( self . tcx ) )
@@ -1933,9 +1924,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1933
1924
expected,
1934
1925
& found_label,
1935
1926
found,
1936
- & sort_string ( values. expected , exp_p ) ,
1937
- & sort_string ( values. found , found_p ) ,
1927
+ & sort_string ( values. expected ) ,
1928
+ & sort_string ( values. found ) ,
1938
1929
) ;
1930
+ if let Some ( path) = path {
1931
+ diag. note ( format ! (
1932
+ "the full type name has been written to '{}'" ,
1933
+ path. display( ) ,
1934
+ ) ) ;
1935
+ }
1939
1936
}
1940
1937
}
1941
1938
}
@@ -2101,7 +2098,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2101
2098
if let & ( MatchExpressionArm ( box MatchExpressionArmCause { source, .. } )
2102
2099
| BlockTailExpression ( .., source) ) = code
2103
2100
&& let hir:: MatchSource :: TryDesugar ( _) = source
2104
- && let Some ( ( expected_ty, found_ty, _, _ ) ) = self . values_str ( trace. values )
2101
+ && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values )
2105
2102
{
2106
2103
suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
2107
2104
found : found_ty. content ( ) ,
@@ -2219,8 +2216,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2219
2216
fn values_str (
2220
2217
& self ,
2221
2218
values : ValuePairs < ' tcx > ,
2222
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2223
- {
2219
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2224
2220
match values {
2225
2221
infer:: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
2226
2222
infer:: Terms ( exp_found) => self . expected_found_str_term ( exp_found) ,
@@ -2233,7 +2229,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2233
2229
found : exp_found. found . print_trait_sugared ( ) ,
2234
2230
} ;
2235
2231
match self . expected_found_str ( pretty_exp_found) {
2236
- Some ( ( expected, found, _, _ ) ) if expected == found => {
2232
+ Some ( ( expected, found, _) ) if expected == found => {
2237
2233
self . expected_found_str ( exp_found)
2238
2234
}
2239
2235
ret => ret,
@@ -2245,16 +2241,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2245
2241
return None ;
2246
2242
}
2247
2243
let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , & exp_found. found ) ;
2248
- Some ( ( exp, fnd, None , None ) )
2244
+ Some ( ( exp, fnd, None ) )
2249
2245
}
2250
2246
}
2251
2247
}
2252
2248
2253
2249
fn expected_found_str_term (
2254
2250
& self ,
2255
2251
exp_found : ty:: error:: ExpectedFound < ty:: Term < ' tcx > > ,
2256
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2257
- {
2252
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2258
2253
let exp_found = self . resolve_vars_if_possible ( exp_found) ;
2259
2254
if exp_found. references_error ( ) {
2260
2255
return None ;
@@ -2269,25 +2264,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2269
2264
let len = self . tcx . sess ( ) . diagnostic_width ( ) + 40 ;
2270
2265
let exp_s = exp. content ( ) ;
2271
2266
let fnd_s = fnd. content ( ) ;
2272
- let mut exp_p = None ;
2273
- let mut fnd_p = None ;
2267
+ let mut path = None ;
2274
2268
if exp_s. len ( ) > len {
2275
- let ( exp_s, exp_path ) = self . tcx . short_ty_string ( expected) ;
2269
+ let exp_s = self . tcx . short_ty_string ( expected, & mut path ) ;
2276
2270
exp = DiagnosticStyledString :: highlighted ( exp_s) ;
2277
- exp_p = exp_path;
2278
2271
}
2279
2272
if fnd_s. len ( ) > len {
2280
- let ( fnd_s, fnd_path ) = self . tcx . short_ty_string ( found) ;
2273
+ let fnd_s = self . tcx . short_ty_string ( found, & mut path ) ;
2281
2274
fnd = DiagnosticStyledString :: highlighted ( fnd_s) ;
2282
- fnd_p = fnd_path;
2283
2275
}
2284
- ( exp, fnd, exp_p , fnd_p )
2276
+ ( exp, fnd, path )
2285
2277
}
2286
2278
_ => (
2287
2279
DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
2288
2280
DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
2289
2281
None ,
2290
- None ,
2291
2282
) ,
2292
2283
} )
2293
2284
}
@@ -2296,8 +2287,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2296
2287
fn expected_found_str < T : fmt:: Display + TypeFoldable < TyCtxt < ' tcx > > > (
2297
2288
& self ,
2298
2289
exp_found : ty:: error:: ExpectedFound < T > ,
2299
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2300
- {
2290
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2301
2291
let exp_found = self . resolve_vars_if_possible ( exp_found) ;
2302
2292
if exp_found. references_error ( ) {
2303
2293
return None ;
@@ -2307,7 +2297,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2307
2297
DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
2308
2298
DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
2309
2299
None ,
2310
- None ,
2311
2300
) )
2312
2301
}
2313
2302
@@ -2591,8 +2580,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2591
2580
2592
2581
if let infer:: Subtype ( ref sup_trace) = sup_origin
2593
2582
&& let infer:: Subtype ( ref sub_trace) = sub_origin
2594
- && let Some ( ( sup_expected, sup_found, _, _ ) ) = self . values_str ( sup_trace. values )
2595
- && let Some ( ( sub_expected, sub_found, _, _ ) ) = self . values_str ( sub_trace. values )
2583
+ && let Some ( ( sup_expected, sup_found, _) ) = self . values_str ( sup_trace. values )
2584
+ && let Some ( ( sub_expected, sub_found, _) ) = self . values_str ( sub_trace. values )
2596
2585
&& sub_expected == sup_expected
2597
2586
&& sub_found == sup_found
2598
2587
{
0 commit comments