@@ -1743,7 +1743,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17431743 }
17441744 }
17451745
1746- if let Some ( ( expected, found, exp_p , found_p ) ) = expected_found {
1746+ if let Some ( ( expected, found, path ) ) = expected_found {
17471747 let ( expected_label, found_label, exp_found) = match exp_found {
17481748 Mismatch :: Variable ( ef) => (
17491749 ef. expected . prefix_string ( self . tcx ) ,
@@ -1869,40 +1869,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18691869 }
18701870 TypeError :: Sorts ( values) => {
18711871 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+ )
19041882 }
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 ( ) ,
19061897 } ;
19071898 if !( values. expected . is_simple_text ( self . tcx )
19081899 && values. found . is_simple_text ( self . tcx ) )
@@ -1933,9 +1924,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19331924 expected,
19341925 & found_label,
19351926 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 ) ,
19381929 ) ;
1930+ if let Some ( path) = path {
1931+ diag. note ( format ! (
1932+ "the full type name has been written to '{}'" ,
1933+ path. display( ) ,
1934+ ) ) ;
1935+ }
19391936 }
19401937 }
19411938 }
@@ -2101,7 +2098,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
21012098 if let & ( MatchExpressionArm ( box MatchExpressionArmCause { source, .. } )
21022099 | BlockTailExpression ( .., source) ) = code
21032100 && 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 )
21052102 {
21062103 suggestions. push ( TypeErrorAdditionalDiags :: TryCannotConvert {
21072104 found : found_ty. content ( ) ,
@@ -2219,8 +2216,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22192216 fn values_str (
22202217 & self ,
22212218 values : ValuePairs < ' tcx > ,
2222- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2223- {
2219+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
22242220 match values {
22252221 infer:: Regions ( exp_found) => self . expected_found_str ( exp_found) ,
22262222 infer:: Terms ( exp_found) => self . expected_found_str_term ( exp_found) ,
@@ -2233,7 +2229,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22332229 found : exp_found. found . print_trait_sugared ( ) ,
22342230 } ;
22352231 match self . expected_found_str ( pretty_exp_found) {
2236- Some ( ( expected, found, _, _ ) ) if expected == found => {
2232+ Some ( ( expected, found, _) ) if expected == found => {
22372233 self . expected_found_str ( exp_found)
22382234 }
22392235 ret => ret,
@@ -2245,16 +2241,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22452241 return None ;
22462242 }
22472243 let ( exp, fnd) = self . cmp_fn_sig ( & exp_found. expected , & exp_found. found ) ;
2248- Some ( ( exp, fnd, None , None ) )
2244+ Some ( ( exp, fnd, None ) )
22492245 }
22502246 }
22512247 }
22522248
22532249 fn expected_found_str_term (
22542250 & self ,
22552251 exp_found : ty:: error:: ExpectedFound < ty:: Term < ' tcx > > ,
2256- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2257- {
2252+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
22582253 let exp_found = self . resolve_vars_if_possible ( exp_found) ;
22592254 if exp_found. references_error ( ) {
22602255 return None ;
@@ -2269,25 +2264,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22692264 let len = self . tcx . sess ( ) . diagnostic_width ( ) + 40 ;
22702265 let exp_s = exp. content ( ) ;
22712266 let fnd_s = fnd. content ( ) ;
2272- let mut exp_p = None ;
2273- let mut fnd_p = None ;
2267+ let mut path = None ;
22742268 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 ) ;
22762270 exp = DiagnosticStyledString :: highlighted ( exp_s) ;
2277- exp_p = exp_path;
22782271 }
22792272 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 ) ;
22812274 fnd = DiagnosticStyledString :: highlighted ( fnd_s) ;
2282- fnd_p = fnd_path;
22832275 }
2284- ( exp, fnd, exp_p , fnd_p )
2276+ ( exp, fnd, path )
22852277 }
22862278 _ => (
22872279 DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
22882280 DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
22892281 None ,
2290- None ,
22912282 ) ,
22922283 } )
22932284 }
@@ -2296,8 +2287,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22962287 fn expected_found_str < T : fmt:: Display + TypeFoldable < TyCtxt < ' tcx > > > (
22972288 & self ,
22982289 exp_found : ty:: error:: ExpectedFound < T > ,
2299- ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > , Option < PathBuf > ) >
2300- {
2290+ ) -> Option < ( DiagnosticStyledString , DiagnosticStyledString , Option < PathBuf > ) > {
23012291 let exp_found = self . resolve_vars_if_possible ( exp_found) ;
23022292 if exp_found. references_error ( ) {
23032293 return None ;
@@ -2307,7 +2297,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23072297 DiagnosticStyledString :: highlighted ( exp_found. expected . to_string ( ) ) ,
23082298 DiagnosticStyledString :: highlighted ( exp_found. found . to_string ( ) ) ,
23092299 None ,
2310- None ,
23112300 ) )
23122301 }
23132302
@@ -2591,8 +2580,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
25912580
25922581 if let infer:: Subtype ( ref sup_trace) = sup_origin
25932582 && 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 )
25962585 && sub_expected == sup_expected
25972586 && sub_found == sup_found
25982587 {
0 commit comments