@@ -48,6 +48,7 @@ use intern::Interned;
48
48
use la_arena:: { Arena , ArenaMap } ;
49
49
use once_cell:: unsync:: OnceCell ;
50
50
use rustc_hash:: FxHashSet ;
51
+ use rustc_pattern_analysis:: Captures ;
51
52
use smallvec:: SmallVec ;
52
53
use stdx:: { impl_from, never} ;
53
54
use syntax:: ast;
@@ -1595,14 +1596,20 @@ pub(crate) fn generic_predicates_for_param_query(
1595
1596
. collect ( ) ;
1596
1597
1597
1598
let subst = generics. bound_vars_subst ( db, DebruijnIndex :: INNERMOST ) ;
1598
- let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1599
- if let Some ( implicitly_sized_predicates) =
1600
- implicitly_sized_clauses ( db, param_id. parent , & explicitly_unsized_tys, & subst, & resolver)
1601
- {
1602
- predicates. extend (
1603
- implicitly_sized_predicates
1604
- . map ( |p| make_binders ( db, & generics, crate :: wrap_empty_binders ( p) ) ) ,
1605
- ) ;
1599
+ if !subst. is_empty ( Interner ) {
1600
+ let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1601
+ if let Some ( implicitly_sized_predicates) = implicitly_sized_clauses (
1602
+ db,
1603
+ param_id. parent ,
1604
+ & explicitly_unsized_tys,
1605
+ & subst,
1606
+ & resolver,
1607
+ ) {
1608
+ predicates. extend (
1609
+ implicitly_sized_predicates
1610
+ . map ( |p| make_binders ( db, & generics, crate :: wrap_empty_binders ( p) ) ) ,
1611
+ ) ;
1612
+ } ;
1606
1613
}
1607
1614
predicates. into ( )
1608
1615
}
@@ -1665,14 +1672,17 @@ pub(crate) fn trait_environment_query(
1665
1672
}
1666
1673
1667
1674
let subst = generics ( db. upcast ( ) , def) . placeholder_subst ( db) ;
1668
- let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1669
- if let Some ( implicitly_sized_clauses) =
1670
- implicitly_sized_clauses ( db, def, & explicitly_unsized_tys, & subst, & resolver)
1671
- {
1672
- clauses. extend (
1673
- implicitly_sized_clauses
1674
- . map ( |pred| pred. cast :: < ProgramClause > ( Interner ) . into_from_env_clause ( Interner ) ) ,
1675
- ) ;
1675
+ if !subst. is_empty ( Interner ) {
1676
+ let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1677
+ if let Some ( implicitly_sized_clauses) =
1678
+ implicitly_sized_clauses ( db, def, & explicitly_unsized_tys, & subst, & resolver)
1679
+ {
1680
+ clauses. extend (
1681
+ implicitly_sized_clauses. map ( |pred| {
1682
+ pred. cast :: < ProgramClause > ( Interner ) . into_from_env_clause ( Interner )
1683
+ } ) ,
1684
+ ) ;
1685
+ } ;
1676
1686
}
1677
1687
1678
1688
let env = chalk_ir:: Environment :: new ( Interner ) . add_clauses ( Interner , clauses) ;
@@ -1714,27 +1724,29 @@ pub(crate) fn generic_predicates_query(
1714
1724
. collect :: < Vec < _ > > ( ) ;
1715
1725
1716
1726
let subst = generics. bound_vars_subst ( db, DebruijnIndex :: INNERMOST ) ;
1717
- let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1718
- if let Some ( implicitly_sized_predicates) =
1719
- implicitly_sized_clauses ( db, def, & explicitly_unsized_tys, & subst, & resolver)
1720
- {
1721
- predicates. extend (
1722
- implicitly_sized_predicates
1723
- . map ( |p| make_binders ( db, & generics, crate :: wrap_empty_binders ( p) ) ) ,
1724
- ) ;
1727
+ if !subst. is_empty ( Interner ) {
1728
+ let explicitly_unsized_tys = ctx. unsized_types . into_inner ( ) ;
1729
+ if let Some ( implicitly_sized_predicates) =
1730
+ implicitly_sized_clauses ( db, def, & explicitly_unsized_tys, & subst, & resolver)
1731
+ {
1732
+ predicates. extend (
1733
+ implicitly_sized_predicates
1734
+ . map ( |p| make_binders ( db, & generics, crate :: wrap_empty_binders ( p) ) ) ,
1735
+ ) ;
1736
+ } ;
1725
1737
}
1726
1738
GenericPredicates ( predicates. is_empty ( ) . not ( ) . then ( || predicates. into ( ) ) )
1727
1739
}
1728
1740
1729
1741
/// Generate implicit `: Sized` predicates for all generics that has no `?Sized` bound.
1730
1742
/// Exception is Self of a trait def.
1731
- fn implicitly_sized_clauses < ' a > (
1743
+ fn implicitly_sized_clauses < ' a , ' subst : ' a > (
1732
1744
db : & dyn HirDatabase ,
1733
1745
def : GenericDefId ,
1734
1746
explicitly_unsized_tys : & ' a FxHashSet < Ty > ,
1735
- substitution : & ' a Substitution ,
1747
+ substitution : & ' subst Substitution ,
1736
1748
resolver : & Resolver ,
1737
- ) -> Option < impl Iterator < Item = WhereClause > + ' a > {
1749
+ ) -> Option < impl Iterator < Item = WhereClause > + Captures < ' a > + Captures < ' subst > > {
1738
1750
let is_trait_def = matches ! ( def, GenericDefId :: TraitId ( ..) ) ;
1739
1751
let generic_args = & substitution. as_slice ( Interner ) [ is_trait_def as usize ..] ;
1740
1752
let sized_trait = db
@@ -1761,12 +1773,13 @@ pub(crate) fn generic_defaults_query(
1761
1773
def : GenericDefId ,
1762
1774
) -> Arc < [ Binders < crate :: GenericArg > ] > {
1763
1775
let resolver = def. resolver ( db. upcast ( ) ) ;
1764
- let ctx = TyLoweringContext :: new ( db, & resolver, def. into ( ) )
1765
- . with_type_param_mode ( ParamLoweringMode :: Variable ) ;
1766
1776
let generic_params = generics ( db. upcast ( ) , def) ;
1767
1777
let parent_start_idx = generic_params. len_self ( ) ;
1768
1778
1769
- let defaults = Arc :: from_iter ( generic_params. iter ( ) . enumerate ( ) . map ( |( idx, ( id, p) ) | {
1779
+ let ctx = TyLoweringContext :: new ( db, & resolver, def. into ( ) )
1780
+ . with_impl_trait_mode ( ImplTraitLoweringMode :: Disallowed )
1781
+ . with_type_param_mode ( ParamLoweringMode :: Variable ) ;
1782
+ Arc :: from_iter ( generic_params. iter ( ) . enumerate ( ) . map ( |( idx, ( id, p) ) | {
1770
1783
match p {
1771
1784
GenericParamDataRef :: TypeParamData ( p) => {
1772
1785
let mut ty =
@@ -1797,9 +1810,7 @@ pub(crate) fn generic_defaults_query(
1797
1810
make_binders ( db, & generic_params, error_lifetime ( ) . cast ( Interner ) )
1798
1811
}
1799
1812
}
1800
- } ) ) ;
1801
-
1802
- defaults
1813
+ } ) )
1803
1814
}
1804
1815
1805
1816
pub ( crate ) fn generic_defaults_recover (
@@ -1810,16 +1821,14 @@ pub(crate) fn generic_defaults_recover(
1810
1821
let generic_params = generics ( db. upcast ( ) , * def) ;
1811
1822
// FIXME: this code is not covered in tests.
1812
1823
// we still need one default per parameter
1813
- let defaults = Arc :: from_iter ( generic_params. iter_id ( ) . map ( |id| {
1824
+ Arc :: from_iter ( generic_params. iter_id ( ) . map ( |id| {
1814
1825
let val = match id {
1815
1826
GenericParamId :: TypeParamId ( _) => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
1816
1827
GenericParamId :: ConstParamId ( id) => unknown_const_as_generic ( db. const_param_ty ( id) ) ,
1817
1828
GenericParamId :: LifetimeParamId ( _) => error_lifetime ( ) . cast ( Interner ) ,
1818
1829
} ;
1819
1830
crate :: make_binders ( db, & generic_params, val)
1820
- } ) ) ;
1821
-
1822
- defaults
1831
+ } ) )
1823
1832
}
1824
1833
1825
1834
fn fn_sig_for_fn ( db : & dyn HirDatabase , def : FunctionId ) -> PolyFnSig {
0 commit comments