@@ -1735,7 +1735,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1735
1735
}
1736
1736
}
1737
1737
1738
- if let Some ( ( expected, found, exp_p , found_p ) ) = expected_found {
1738
+ if let Some ( ( expected, found, path ) ) = expected_found {
1739
1739
let ( expected_label, found_label, exp_found) = match exp_found {
1740
1740
Mismatch :: Variable ( ef) => (
1741
1741
ef. expected . prefix_string ( self . tcx ) ,
@@ -1861,40 +1861,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1861
1861
}
1862
1862
TypeError :: Sorts ( values) => {
1863
1863
let extra = expected == found;
1864
- let sort_string = |ty : Ty < ' tcx > , path : Option < PathBuf > | {
1865
- let mut s = match ( extra, ty. kind ( ) ) {
1866
- ( true , ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) ) => {
1867
- let sm = self . tcx . sess . source_map ( ) ;
1868
- let pos = sm. lookup_char_pos ( self . tcx . def_span ( * def_id) . lo ( ) ) ;
1869
- format ! (
1870
- " (opaque type at <{}:{}:{}>)" ,
1871
- sm. filename_for_diagnostics( & pos. file. name) ,
1872
- pos. line,
1873
- pos. col. to_usize( ) + 1 ,
1874
- )
1875
- }
1876
- ( true , ty:: Alias ( ty:: Projection , proj) )
1877
- if self . tcx . is_impl_trait_in_trait ( proj. def_id ) =>
1878
- {
1879
- let sm = self . tcx . sess . source_map ( ) ;
1880
- let pos = sm. lookup_char_pos ( self . tcx . def_span ( proj. def_id ) . lo ( ) ) ;
1881
- format ! (
1882
- " (trait associated opaque type at <{}:{}:{}>)" ,
1883
- sm. filename_for_diagnostics( & pos. file. name) ,
1884
- pos. line,
1885
- pos. col. to_usize( ) + 1 ,
1886
- )
1887
- }
1888
- ( true , _) => format ! ( " ({})" , ty. sort_string( self . tcx) ) ,
1889
- ( false , _) => "" . to_string ( ) ,
1890
- } ;
1891
- if let Some ( path) = path {
1892
- s. push_str ( & format ! (
1893
- "\n the full type name has been written to '{}'" ,
1894
- path. display( ) ,
1895
- ) ) ;
1864
+ let sort_string = |ty : Ty < ' tcx > | match ( extra, ty. kind ( ) ) {
1865
+ ( true , ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) ) => {
1866
+ let sm = self . tcx . sess . source_map ( ) ;
1867
+ let pos = sm. lookup_char_pos ( self . tcx . def_span ( * def_id) . lo ( ) ) ;
1868
+ format ! (
1869
+ " (opaque type at <{}:{}:{}>)" ,
1870
+ sm. filename_for_diagnostics( & pos. file. name) ,
1871
+ pos. line,
1872
+ pos. col. to_usize( ) + 1 ,
1873
+ )
1896
1874
}
1897
- s
1875
+ ( true , ty:: Alias ( ty:: Projection , proj) )
1876
+ if self . tcx . is_impl_trait_in_trait ( proj. def_id ) =>
1877
+ {
1878
+ let sm = self . tcx . sess . source_map ( ) ;
1879
+ let pos = sm. lookup_char_pos ( self . tcx . def_span ( proj. def_id ) . lo ( ) ) ;
1880
+ format ! (
1881
+ " (trait associated opaque type at <{}:{}:{}>)" ,
1882
+ sm. filename_for_diagnostics( & pos. file. name) ,
1883
+ pos. line,
1884
+ pos. col. to_usize( ) + 1 ,
1885
+ )
1886
+ }
1887
+ ( true , _) => format ! ( " ({})" , ty. sort_string( self . tcx) ) ,
1888
+ ( false , _) => "" . to_string ( ) ,
1898
1889
} ;
1899
1890
if !( values. expected . is_simple_text ( self . tcx )
1900
1891
&& values. found . is_simple_text ( self . tcx ) )
@@ -1925,9 +1916,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1925
1916
expected,
1926
1917
& found_label,
1927
1918
found,
1928
- & sort_string ( values. expected , exp_p ) ,
1929
- & sort_string ( values. found , found_p ) ,
1919
+ & sort_string ( values. expected ) ,
1920
+ & sort_string ( values. found ) ,
1930
1921
) ;
1922
+ if let Some ( path) = path {
1923
+ diag. note ( format ! (
1924
+ "the full type name has been written to '{}'" ,
1925
+ path. display( ) ,
1926
+ ) ) ;
1927
+ }
1931
1928
}
1932
1929
}
1933
1930
}
@@ -2093,7 +2090,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2093
2090
if let & ( MatchExpressionArm ( box MatchExpressionArmCause { source, .. } )
2094
2091
| BlockTailExpression ( .., source) ) = code
2095
2092
&& let hir:: MatchSource :: TryDesugar ( _) = source
2096
- && let Some ( ( expected_ty, found_ty, _, _ ) ) = self . values_str ( trace. values )
2093
+ && let Some ( ( expected_ty, found_ty, _) ) = self . values_str ( trace. values )
2097
2094
{
2098
2095
suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
2099
2096
found : found_ty. content ( ) ,
@@ -2211,8 +2208,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2211
2208
fn values_str (
2212
2209
& self ,
2213
2210
values : ValuePairs < ' tcx > ,
2214
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2215
- {
2211
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2216
2212
match values {
2217
2213
infer:: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
2218
2214
infer:: Terms ( exp_found) => self . expected_found_str_term ( exp_found) ,
@@ -2225,7 +2221,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2225
2221
found : exp_found. found . print_only_trait_path ( ) ,
2226
2222
} ;
2227
2223
match self . expected_found_str ( pretty_exp_found) {
2228
- Some ( ( expected, found, _, _ ) ) if expected == found => {
2224
+ Some ( ( expected, found, _) ) if expected == found => {
2229
2225
self . expected_found_str ( exp_found)
2230
2226
}
2231
2227
ret => ret,
@@ -2237,7 +2233,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2237
2233
found : exp_found. found . print_only_trait_path ( ) ,
2238
2234
} ;
2239
2235
match self . expected_found_str ( pretty_exp_found) {
2240
- Some ( ( expected, found, _, _ ) ) if expected == found => {
2236
+ Some ( ( expected, found, _) ) if expected == found => {
2241
2237
self . expected_found_str ( exp_found)
2242
2238
}
2243
2239
ret => ret,
@@ -2249,16 +2245,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2249
2245
return None ;
2250
2246
}
2251
2247
let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , & exp_found. found ) ;
2252
- Some ( ( exp, fnd, None , None ) )
2248
+ Some ( ( exp, fnd, None ) )
2253
2249
}
2254
2250
}
2255
2251
}
2256
2252
2257
2253
fn expected_found_str_term (
2258
2254
& self ,
2259
2255
exp_found : ty:: error:: ExpectedFound < ty:: Term < ' tcx > > ,
2260
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2261
- {
2256
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2262
2257
let exp_found = self . resolve_vars_if_possible ( exp_found) ;
2263
2258
if exp_found. references_error ( ) {
2264
2259
return None ;
@@ -2273,25 +2268,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2273
2268
let len = self . tcx . sess ( ) . diagnostic_width ( ) + 40 ;
2274
2269
let exp_s = exp. content ( ) ;
2275
2270
let fnd_s = fnd. content ( ) ;
2276
- let mut exp_p = None ;
2277
- let mut fnd_p = None ;
2271
+ let mut path = None ;
2278
2272
if exp_s. len ( ) > len {
2279
- let ( exp_s, exp_path ) = self . tcx . short_ty_string ( expected) ;
2273
+ let exp_s = self . tcx . short_ty_string ( expected, & mut path ) ;
2280
2274
exp = DiagnosticStyledString :: highlighted ( exp_s) ;
2281
- exp_p = exp_path;
2282
2275
}
2283
2276
if fnd_s. len ( ) > len {
2284
- let ( fnd_s, fnd_path ) = self . tcx . short_ty_string ( found) ;
2277
+ let fnd_s = self . tcx . short_ty_string ( found, & mut path ) ;
2285
2278
fnd = DiagnosticStyledString :: highlighted ( fnd_s) ;
2286
- fnd_p = fnd_path;
2287
2279
}
2288
- ( exp, fnd, exp_p , fnd_p )
2280
+ ( exp, fnd, path )
2289
2281
}
2290
2282
_ => (
2291
2283
DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
2292
2284
DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
2293
2285
None ,
2294
- None ,
2295
2286
) ,
2296
2287
} )
2297
2288
}
@@ -2300,8 +2291,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2300
2291
fn expected_found_str < T : fmt:: Display + TypeFoldable < TyCtxt < ' tcx > > > (
2301
2292
& self ,
2302
2293
exp_found : ty:: error:: ExpectedFound < T > ,
2303
- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2304
- {
2294
+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
2305
2295
let exp_found = self . resolve_vars_if_possible ( exp_found) ;
2306
2296
if exp_found. references_error ( ) {
2307
2297
return None ;
@@ -2311,7 +2301,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2311
2301
DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
2312
2302
DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
2313
2303
None ,
2314
- None ,
2315
2304
) )
2316
2305
}
2317
2306
@@ -2595,8 +2584,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2595
2584
2596
2585
if let infer:: Subtype ( ref sup_trace) = sup_origin
2597
2586
&& let infer:: Subtype ( ref sub_trace) = sub_origin
2598
- && let Some ( ( sup_expected, sup_found, _, _ ) ) = self . values_str ( sup_trace. values )
2599
- && let Some ( ( sub_expected, sub_found, _, _ ) ) = self . values_str ( sub_trace. values )
2587
+ && let Some ( ( sup_expected, sup_found, _) ) = self . values_str ( sup_trace. values )
2588
+ && let Some ( ( sub_expected, sub_found, _) ) = self . values_str ( sub_trace. values )
2600
2589
&& sub_expected == sup_expected
2601
2590
&& sub_found == sup_found
2602
2591
{
0 commit comments