@@ -30,7 +30,6 @@ use rustc_trait_selection::traits::misc::{
30
30
ConstParamTyImplementationError , type_allowed_to_implement_const_param_ty,
31
31
} ;
32
32
use rustc_trait_selection:: traits:: outlives_bounds:: InferCtxtExt as _;
33
- use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
34
33
use rustc_trait_selection:: traits:: {
35
34
self , FulfillmentError , Obligation , ObligationCause , ObligationCauseCode , ObligationCtxt ,
36
35
WellFormedLoc ,
@@ -1628,13 +1627,6 @@ fn check_fn_or_method<'tcx>(
1628
1627
}
1629
1628
}
1630
1629
1631
- /// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1632
- #[ derive( Clone , Copy , PartialEq ) ]
1633
- enum ArbitrarySelfTypesLevel {
1634
- Basic , // just arbitrary_self_types
1635
- WithPointers , // both arbitrary_self_types and arbitrary_self_types_pointers
1636
- }
1637
-
1638
1630
#[ instrument( level = "debug" , skip( wfcx) ) ]
1639
1631
fn check_method_receiver < ' tcx > (
1640
1632
wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1667,13 +1659,6 @@ fn check_method_receiver<'tcx>(
1667
1659
return Ok ( ( ) ) ;
1668
1660
}
1669
1661
1670
- let arbitrary_self_types_level = if tcx. features ( ) . arbitrary_self_types_pointers ( ) {
1671
- Some ( ArbitrarySelfTypesLevel :: WithPointers )
1672
- } else if tcx. features ( ) . arbitrary_self_types ( ) {
1673
- Some ( ArbitrarySelfTypesLevel :: Basic )
1674
- } else {
1675
- None
1676
- } ;
1677
1662
let generics = tcx. generics_of ( method. def_id ) ;
1678
1663
1679
1664
// yet to do: determine whether self_ty is Sized. If not (most commonly
@@ -1686,46 +1671,19 @@ fn check_method_receiver<'tcx>(
1686
1671
// exist for this.
1687
1672
let raw_pointer = is_raw_pointer ( receiver_ty) ;
1688
1673
1689
- let receiver_validity =
1690
- receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
1674
+ let arbitrary_self_types_pointers_enabled = tcx. features ( ) . arbitrary_self_types_pointers ( ) ;
1675
+ let receiver_validity = receiver_is_valid (
1676
+ wfcx,
1677
+ span,
1678
+ receiver_ty,
1679
+ self_ty,
1680
+ arbitrary_self_types_pointers_enabled,
1681
+ generics,
1682
+ ) ;
1691
1683
if let Err ( receiver_validity_err) = receiver_validity {
1692
- return Err ( match arbitrary_self_types_level {
1693
- // Wherever possible, emit a message advising folks that the features
1694
- // `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1695
- // have helped.
1696
- None if receiver_is_valid (
1697
- wfcx,
1698
- span,
1699
- receiver_ty,
1700
- self_ty,
1701
- Some ( ArbitrarySelfTypesLevel :: Basic ) ,
1702
- generics,
1703
- )
1704
- . is_ok ( ) =>
1705
- {
1706
- // Report error; would have worked with `arbitrary_self_types`.
1707
- feature_err (
1708
- & tcx. sess ,
1709
- sym:: arbitrary_self_types,
1710
- span,
1711
- format ! (
1712
- "`{receiver_ty}` cannot be used as the type of `self` without \
1713
- the `arbitrary_self_types` feature",
1714
- ) ,
1715
- )
1716
- . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1717
- . emit ( )
1718
- }
1719
- None | Some ( ArbitrarySelfTypesLevel :: Basic )
1720
- if receiver_is_valid (
1721
- wfcx,
1722
- span,
1723
- receiver_ty,
1724
- self_ty,
1725
- Some ( ArbitrarySelfTypesLevel :: WithPointers ) ,
1726
- generics,
1727
- )
1728
- . is_ok ( ) =>
1684
+ return Err (
1685
+ if !arbitrary_self_types_pointers_enabled
1686
+ && receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true , generics) . is_ok ( )
1729
1687
{
1730
1688
// Report error; would have worked with `arbitrary_self_types_pointers`.
1731
1689
feature_err (
@@ -1734,15 +1692,13 @@ fn check_method_receiver<'tcx>(
1734
1692
span,
1735
1693
format ! (
1736
1694
"`{receiver_ty}` cannot be used as the type of `self` without \
1737
- the `arbitrary_self_types_pointers` feature",
1695
+ the `arbitrary_self_types_pointers` feature",
1738
1696
) ,
1739
1697
)
1740
1698
. with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1741
1699
. emit ( )
1742
- }
1743
- _ =>
1744
- // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1745
- {
1700
+ } else {
1701
+ // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1746
1702
match receiver_validity_err {
1747
1703
ReceiverValidityError :: DoesNotDeref => tcx
1748
1704
. dcx ( )
@@ -1751,8 +1707,8 @@ fn check_method_receiver<'tcx>(
1751
1707
tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
1752
1708
}
1753
1709
}
1754
- }
1755
- } ) ;
1710
+ } ,
1711
+ ) ;
1756
1712
}
1757
1713
Ok ( ( ) )
1758
1714
}
@@ -1800,11 +1756,10 @@ fn receiver_is_valid<'tcx>(
1800
1756
span : Span ,
1801
1757
receiver_ty : Ty < ' tcx > ,
1802
1758
self_ty : Ty < ' tcx > ,
1803
- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1759
+ arbitrary_self_types_pointers_enabled : bool ,
1804
1760
method_generics : & ty:: Generics ,
1805
1761
) -> Result < ( ) , ReceiverValidityError > {
1806
1762
let infcx = wfcx. infcx ;
1807
- let tcx = wfcx. tcx ( ) ;
1808
1763
let cause =
1809
1764
ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
1810
1765
@@ -1819,17 +1774,11 @@ fn receiver_is_valid<'tcx>(
1819
1774
1820
1775
confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
1821
1776
1822
- let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
1823
-
1824
- // The `arbitrary_self_types` feature allows custom smart pointer
1825
- // types to be method receivers, as identified by following the Receiver<Target=T>
1826
- // chain.
1827
- if arbitrary_self_types_enabled. is_some ( ) {
1828
- autoderef = autoderef. use_receiver_trait ( ) ;
1829
- }
1777
+ let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty)
1778
+ . use_receiver_trait ( ) ;
1830
1779
1831
1780
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1832
- if arbitrary_self_types_enabled == Some ( ArbitrarySelfTypesLevel :: WithPointers ) {
1781
+ if arbitrary_self_types_pointers_enabled {
1833
1782
autoderef = autoderef. include_raw_pointers ( ) ;
1834
1783
}
1835
1784
@@ -1852,58 +1801,12 @@ fn receiver_is_valid<'tcx>(
1852
1801
wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
1853
1802
return Ok ( ( ) ) ;
1854
1803
}
1855
-
1856
- // Without `feature(arbitrary_self_types)`, we require that each step in the
1857
- // deref chain implement `LegacyReceiver`.
1858
- if arbitrary_self_types_enabled. is_none ( ) {
1859
- let legacy_receiver_trait_def_id =
1860
- tcx. require_lang_item ( LangItem :: LegacyReceiver , Some ( span) ) ;
1861
- if !legacy_receiver_is_implemented (
1862
- wfcx,
1863
- legacy_receiver_trait_def_id,
1864
- cause. clone ( ) ,
1865
- potential_self_ty,
1866
- ) {
1867
- // We cannot proceed.
1868
- break ;
1869
- }
1870
-
1871
- // Register the bound, in case it has any region side-effects.
1872
- wfcx. register_bound (
1873
- cause. clone ( ) ,
1874
- wfcx. param_env ,
1875
- potential_self_ty,
1876
- legacy_receiver_trait_def_id,
1877
- ) ;
1878
- }
1879
1804
}
1880
1805
1881
1806
debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
1882
1807
Err ( ReceiverValidityError :: DoesNotDeref )
1883
1808
}
1884
1809
1885
- fn legacy_receiver_is_implemented < ' tcx > (
1886
- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1887
- legacy_receiver_trait_def_id : DefId ,
1888
- cause : ObligationCause < ' tcx > ,
1889
- receiver_ty : Ty < ' tcx > ,
1890
- ) -> bool {
1891
- let tcx = wfcx. tcx ( ) ;
1892
- let trait_ref = ty:: TraitRef :: new ( tcx, legacy_receiver_trait_def_id, [ receiver_ty] ) ;
1893
-
1894
- let obligation = Obligation :: new ( tcx, cause, wfcx. param_env , trait_ref) ;
1895
-
1896
- if wfcx. infcx . predicate_must_hold_modulo_regions ( & obligation) {
1897
- true
1898
- } else {
1899
- debug ! (
1900
- "receiver_is_implemented: type `{:?}` does not implement `LegacyReceiver` trait" ,
1901
- receiver_ty
1902
- ) ;
1903
- false
1904
- }
1905
- }
1906
-
1907
1810
fn check_variances_for_type_defn < ' tcx > (
1908
1811
tcx : TyCtxt < ' tcx > ,
1909
1812
item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments