@@ -1738,6 +1738,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1738
1738
// label pointing out the cause for the type coercion will be wrong
1739
1739
// as prior return coercions would not be relevant (#57664).
1740
1740
let fn_decl = if let ( Some ( expr) , Some ( blk_id) ) = ( expression, blk_id) {
1741
+ self . explain_self_literal ( fcx, & mut err, expr) ;
1741
1742
let pointing_at_return_type =
1742
1743
fcx. suggest_mismatched_types_on_tail ( & mut err, expr, expected, found, blk_id) ;
1743
1744
if let ( Some ( cond_expr) , true , false ) = (
@@ -1810,6 +1811,43 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1810
1811
err
1811
1812
}
1812
1813
1814
+ fn explain_self_literal (
1815
+ & self ,
1816
+ fcx : & FnCtxt < ' _ , ' tcx > ,
1817
+ err : & mut Diagnostic ,
1818
+ expr : & ' tcx hir:: Expr < ' tcx > ,
1819
+ ) {
1820
+ match expr. peel_drop_temps ( ) . kind {
1821
+ hir:: ExprKind :: Struct (
1822
+ hir:: QPath :: Resolved (
1823
+ None ,
1824
+ hir:: Path { res : hir:: def:: Res :: SelfTyAlias { alias_to, .. } , .. } ,
1825
+ ) ,
1826
+ ..,
1827
+ )
1828
+ | hir:: ExprKind :: Call (
1829
+ hir:: Expr {
1830
+ kind :
1831
+ hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
1832
+ None ,
1833
+ hir:: Path { res : hir:: def:: Res :: SelfTyAlias { alias_to, .. } , .. } ,
1834
+ ) ) ,
1835
+ ..
1836
+ } ,
1837
+ ..,
1838
+ ) => {
1839
+ if let Some ( hir:: Node :: Item ( hir:: Item {
1840
+ kind : hir:: ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ,
1841
+ ..
1842
+ } ) ) = fcx. tcx . hir ( ) . get_if_local ( * alias_to)
1843
+ {
1844
+ err. span_label ( self_ty. span , "this is the type of the `Self` literal" ) ;
1845
+ }
1846
+ }
1847
+ _ => { }
1848
+ }
1849
+ }
1850
+
1813
1851
/// Checks whether the return type is unsized via an obligation, which makes
1814
1852
/// sure we consider `dyn Trait: Sized` where clauses, which are trivially
1815
1853
/// false but technically valid for typeck.
0 commit comments