@@ -29,7 +29,6 @@ use rustc_trait_selection::regions::{InferCtxtRegionExt, OutlivesEnvironmentBuil
29
29
use rustc_trait_selection:: traits:: misc:: {
30
30
ConstParamTyImplementationError , type_allowed_to_implement_const_param_ty,
31
31
} ;
32
- use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
33
32
use rustc_trait_selection:: traits:: {
34
33
self , FulfillmentError , Obligation , ObligationCause , ObligationCauseCode , ObligationCtxt ,
35
34
WellFormedLoc ,
@@ -1698,13 +1697,6 @@ fn check_sized_if_body<'tcx>(
1698
1697
}
1699
1698
}
1700
1699
1701
- /// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1702
- #[ derive( Clone , Copy , PartialEq ) ]
1703
- enum ArbitrarySelfTypesLevel {
1704
- Basic , // just arbitrary_self_types
1705
- WithPointers , // both arbitrary_self_types and arbitrary_self_types_pointers
1706
- }
1707
-
1708
1700
#[ instrument( level = "debug" , skip( wfcx) ) ]
1709
1701
fn check_method_receiver < ' tcx > (
1710
1702
wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1737,55 +1729,21 @@ fn check_method_receiver<'tcx>(
1737
1729
return Ok ( ( ) ) ;
1738
1730
}
1739
1731
1740
- let arbitrary_self_types_level = if tcx. features ( ) . arbitrary_self_types_pointers ( ) {
1741
- Some ( ArbitrarySelfTypesLevel :: WithPointers )
1742
- } else if tcx. features ( ) . arbitrary_self_types ( ) {
1743
- Some ( ArbitrarySelfTypesLevel :: Basic )
1744
- } else {
1745
- None
1746
- } ;
1747
1732
let generics = tcx. generics_of ( method. def_id ) ;
1748
1733
1749
- let receiver_validity =
1750
- receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
1734
+ let arbitrary_self_types_pointers_enabled = tcx. features ( ) . arbitrary_self_types_pointers ( ) ;
1735
+ let receiver_validity = receiver_is_valid (
1736
+ wfcx,
1737
+ span,
1738
+ receiver_ty,
1739
+ self_ty,
1740
+ arbitrary_self_types_pointers_enabled,
1741
+ generics,
1742
+ ) ;
1751
1743
if let Err ( receiver_validity_err) = receiver_validity {
1752
- return Err ( match arbitrary_self_types_level {
1753
- // Wherever possible, emit a message advising folks that the features
1754
- // `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1755
- // have helped.
1756
- None if receiver_is_valid (
1757
- wfcx,
1758
- span,
1759
- receiver_ty,
1760
- self_ty,
1761
- Some ( ArbitrarySelfTypesLevel :: Basic ) ,
1762
- generics,
1763
- )
1764
- . is_ok ( ) =>
1765
- {
1766
- // Report error; would have worked with `arbitrary_self_types`.
1767
- feature_err (
1768
- & tcx. sess ,
1769
- sym:: arbitrary_self_types,
1770
- span,
1771
- format ! (
1772
- "`{receiver_ty}` cannot be used as the type of `self` without \
1773
- the `arbitrary_self_types` feature",
1774
- ) ,
1775
- )
1776
- . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1777
- . emit ( )
1778
- }
1779
- None | Some ( ArbitrarySelfTypesLevel :: Basic )
1780
- if receiver_is_valid (
1781
- wfcx,
1782
- span,
1783
- receiver_ty,
1784
- self_ty,
1785
- Some ( ArbitrarySelfTypesLevel :: WithPointers ) ,
1786
- generics,
1787
- )
1788
- . is_ok ( ) =>
1744
+ return Err (
1745
+ if !arbitrary_self_types_pointers_enabled
1746
+ && receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true , generics) . is_ok ( )
1789
1747
{
1790
1748
// Report error; would have worked with `arbitrary_self_types_pointers`.
1791
1749
feature_err (
@@ -1794,17 +1752,15 @@ fn check_method_receiver<'tcx>(
1794
1752
span,
1795
1753
format ! (
1796
1754
"`{receiver_ty}` cannot be used as the type of `self` without \
1797
- the `arbitrary_self_types_pointers` feature",
1755
+ the `arbitrary_self_types_pointers` feature",
1798
1756
) ,
1799
1757
)
1800
1758
. with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1801
1759
. emit ( )
1802
- }
1803
- _ =>
1804
- // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1805
- {
1760
+ } else {
1761
+ // Report error; would not have worked with `arbitrary_self_types_pointers`.
1806
1762
match receiver_validity_err {
1807
- ReceiverValidityError :: DoesNotDeref if arbitrary_self_types_level . is_some ( ) => {
1763
+ ReceiverValidityError :: DoesNotDeref => {
1808
1764
let hint = match receiver_ty
1809
1765
. builtin_deref ( false )
1810
1766
. unwrap_or ( receiver_ty)
@@ -1818,18 +1774,12 @@ fn check_method_receiver<'tcx>(
1818
1774
1819
1775
tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTy { span, receiver_ty, hint } )
1820
1776
}
1821
- ReceiverValidityError :: DoesNotDeref => {
1822
- tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTyNoArbitrarySelfTypes {
1823
- span,
1824
- receiver_ty,
1825
- } )
1826
- }
1827
1777
ReceiverValidityError :: MethodGenericParamUsed => {
1828
1778
tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
1829
1779
}
1830
1780
}
1831
- }
1832
- } ) ;
1781
+ } ,
1782
+ ) ;
1833
1783
}
1834
1784
Ok ( ( ) )
1835
1785
}
@@ -1873,11 +1823,10 @@ fn receiver_is_valid<'tcx>(
1873
1823
span : Span ,
1874
1824
receiver_ty : Ty < ' tcx > ,
1875
1825
self_ty : Ty < ' tcx > ,
1876
- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1826
+ arbitrary_self_types_pointers_enabled : bool ,
1877
1827
method_generics : & ty:: Generics ,
1878
1828
) -> Result < ( ) , ReceiverValidityError > {
1879
1829
let infcx = wfcx. infcx ;
1880
- let tcx = wfcx. tcx ( ) ;
1881
1830
let cause =
1882
1831
ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
1883
1832
@@ -1892,17 +1841,11 @@ fn receiver_is_valid<'tcx>(
1892
1841
1893
1842
confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
1894
1843
1895
- let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
1896
-
1897
- // The `arbitrary_self_types` feature allows custom smart pointer
1898
- // types to be method receivers, as identified by following the Receiver<Target=T>
1899
- // chain.
1900
- if arbitrary_self_types_enabled. is_some ( ) {
1901
- autoderef = autoderef. use_receiver_trait ( ) ;
1902
- }
1844
+ let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty)
1845
+ . use_receiver_trait ( ) ;
1903
1846
1904
1847
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1905
- if arbitrary_self_types_enabled == Some ( ArbitrarySelfTypesLevel :: WithPointers ) {
1848
+ if arbitrary_self_types_pointers_enabled {
1906
1849
autoderef = autoderef. include_raw_pointers ( ) ;
1907
1850
}
1908
1851
@@ -1925,58 +1868,12 @@ fn receiver_is_valid<'tcx>(
1925
1868
wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
1926
1869
return Ok ( ( ) ) ;
1927
1870
}
1928
-
1929
- // Without `feature(arbitrary_self_types)`, we require that each step in the
1930
- // deref chain implement `LegacyReceiver`.
1931
- if arbitrary_self_types_enabled. is_none ( ) {
1932
- let legacy_receiver_trait_def_id =
1933
- tcx. require_lang_item ( LangItem :: LegacyReceiver , Some ( span) ) ;
1934
- if !legacy_receiver_is_implemented (
1935
- wfcx,
1936
- legacy_receiver_trait_def_id,
1937
- cause. clone ( ) ,
1938
- potential_self_ty,
1939
- ) {
1940
- // We cannot proceed.
1941
- break ;
1942
- }
1943
-
1944
- // Register the bound, in case it has any region side-effects.
1945
- wfcx. register_bound (
1946
- cause. clone ( ) ,
1947
- wfcx. param_env ,
1948
- potential_self_ty,
1949
- legacy_receiver_trait_def_id,
1950
- ) ;
1951
- }
1952
1871
}
1953
1872
1954
1873
debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
1955
1874
Err ( ReceiverValidityError :: DoesNotDeref )
1956
1875
}
1957
1876
1958
- fn legacy_receiver_is_implemented < ' tcx > (
1959
- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1960
- legacy_receiver_trait_def_id : DefId ,
1961
- cause : ObligationCause < ' tcx > ,
1962
- receiver_ty : Ty < ' tcx > ,
1963
- ) -> bool {
1964
- let tcx = wfcx. tcx ( ) ;
1965
- let trait_ref = ty:: TraitRef :: new ( tcx, legacy_receiver_trait_def_id, [ receiver_ty] ) ;
1966
-
1967
- let obligation = Obligation :: new ( tcx, cause, wfcx. param_env , trait_ref) ;
1968
-
1969
- if wfcx. infcx . predicate_must_hold_modulo_regions ( & obligation) {
1970
- true
1971
- } else {
1972
- debug ! (
1973
- "receiver_is_implemented: type `{:?}` does not implement `LegacyReceiver` trait" ,
1974
- receiver_ty
1975
- ) ;
1976
- false
1977
- }
1978
- }
1979
-
1980
1877
fn check_variances_for_type_defn < ' tcx > (
1981
1878
tcx : TyCtxt < ' tcx > ,
1982
1879
item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments