@@ -1791,6 +1791,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1791
1791
let body_hir_id = obligation. cause . body_id ;
1792
1792
let item_id = self . tcx . hir ( ) . get_parent_node ( body_hir_id) ;
1793
1793
1794
+ let mut is_future = false ;
1795
+ if let ty:: Opaque ( def_id, substs) = trait_ref. self_ty ( ) . kind {
1796
+ let preds = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , substs) ;
1797
+ for p in preds. predicates {
1798
+ if let Some ( trait_ref) = p. to_opt_poly_trait_ref ( ) {
1799
+ if Some ( trait_ref. def_id ( ) ) == self . tcx . lang_items ( ) . future_trait ( ) {
1800
+ is_future = true ;
1801
+ break ;
1802
+ }
1803
+ }
1804
+ }
1805
+ }
1806
+
1794
1807
if let Some ( body_id) = self . tcx . hir ( ) . maybe_body_owned_by ( item_id) {
1795
1808
let body = self . tcx . hir ( ) . body ( body_id) ;
1796
1809
if let Some ( hir:: GeneratorKind :: Async ( _) ) = body. generator_kind {
@@ -1802,6 +1815,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1802
1815
. next ( )
1803
1816
. unwrap ( )
1804
1817
. def_id ;
1818
+ debug ! ( "trait_ref_self_ty: {:?}" , trait_ref. self_ty( ) ) ;
1805
1819
// `<T as Future>::Output`
1806
1820
let projection_ty = ty:: ProjectionTy {
1807
1821
// `T`
@@ -1813,7 +1827,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1813
1827
item_def_id,
1814
1828
} ;
1815
1829
1816
- //let cause = ObligationCause::misc(span, body_hir_id);
1817
1830
let mut selcx = SelectionContext :: new ( self ) ;
1818
1831
1819
1832
let mut obligations = vec ! [ ] ;
@@ -1826,15 +1839,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1826
1839
& mut obligations,
1827
1840
) ;
1828
1841
1829
- debug ! ( "suggest_await_befor_try: normalized_projection_type {:?}" , normalized_ty) ;
1842
+ debug ! (
1843
+ "suggest_await_befor_try: normalized_projection_type {:?}" ,
1844
+ self . resolve_vars_if_possible( & normalized_ty)
1845
+ ) ;
1830
1846
let try_obligation = self . mk_obligation_for_def_id (
1831
1847
trait_ref. def_id ( ) ,
1832
1848
normalized_ty,
1833
1849
obligation. cause . clone ( ) ,
1834
1850
obligation. param_env ,
1835
1851
) ;
1836
1852
debug ! ( "suggest_await_befor_try: try_trait_obligation {:?}" , try_obligation) ;
1837
- if self . predicate_may_hold ( & try_obligation) {
1853
+ if self . predicate_may_hold ( & try_obligation) && is_future {
1838
1854
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
1839
1855
if snippet. ends_with ( '?' ) {
1840
1856
err. span_suggestion (
0 commit comments