@@ -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 ,
@@ -1672,13 +1671,6 @@ fn check_sized_if_body<'tcx>(
1672
1671
}
1673
1672
}
1674
1673
1675
- /// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1676
- #[ derive( Clone , Copy , PartialEq ) ]
1677
- enum ArbitrarySelfTypesLevel {
1678
- Basic , // just arbitrary_self_types
1679
- WithPointers , // both arbitrary_self_types and arbitrary_self_types_pointers
1680
- }
1681
-
1682
1674
#[ instrument( level = "debug" , skip( wfcx) ) ]
1683
1675
fn check_method_receiver < ' tcx > (
1684
1676
wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1711,55 +1703,21 @@ fn check_method_receiver<'tcx>(
1711
1703
return Ok ( ( ) ) ;
1712
1704
}
1713
1705
1714
- let arbitrary_self_types_level = if tcx. features ( ) . arbitrary_self_types_pointers ( ) {
1715
- Some ( ArbitrarySelfTypesLevel :: WithPointers )
1716
- } else if tcx. features ( ) . arbitrary_self_types ( ) {
1717
- Some ( ArbitrarySelfTypesLevel :: Basic )
1718
- } else {
1719
- None
1720
- } ;
1721
1706
let generics = tcx. generics_of ( method. def_id ) ;
1722
1707
1723
- let receiver_validity =
1724
- receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
1708
+ let arbitrary_self_types_pointers_enabled = tcx. features ( ) . arbitrary_self_types_pointers ( ) ;
1709
+ let receiver_validity = receiver_is_valid (
1710
+ wfcx,
1711
+ span,
1712
+ receiver_ty,
1713
+ self_ty,
1714
+ arbitrary_self_types_pointers_enabled,
1715
+ generics,
1716
+ ) ;
1725
1717
if let Err ( receiver_validity_err) = receiver_validity {
1726
- return Err ( match arbitrary_self_types_level {
1727
- // Wherever possible, emit a message advising folks that the features
1728
- // `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1729
- // have helped.
1730
- None if receiver_is_valid (
1731
- wfcx,
1732
- span,
1733
- receiver_ty,
1734
- self_ty,
1735
- Some ( ArbitrarySelfTypesLevel :: Basic ) ,
1736
- generics,
1737
- )
1738
- . is_ok ( ) =>
1739
- {
1740
- // Report error; would have worked with `arbitrary_self_types`.
1741
- feature_err (
1742
- & tcx. sess ,
1743
- sym:: arbitrary_self_types,
1744
- span,
1745
- format ! (
1746
- "`{receiver_ty}` cannot be used as the type of `self` without \
1747
- the `arbitrary_self_types` feature",
1748
- ) ,
1749
- )
1750
- . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1751
- . emit ( )
1752
- }
1753
- None | Some ( ArbitrarySelfTypesLevel :: Basic )
1754
- if receiver_is_valid (
1755
- wfcx,
1756
- span,
1757
- receiver_ty,
1758
- self_ty,
1759
- Some ( ArbitrarySelfTypesLevel :: WithPointers ) ,
1760
- generics,
1761
- )
1762
- . is_ok ( ) =>
1718
+ return Err (
1719
+ if !arbitrary_self_types_pointers_enabled
1720
+ && receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true , generics) . is_ok ( )
1763
1721
{
1764
1722
// Report error; would have worked with `arbitrary_self_types_pointers`.
1765
1723
feature_err (
@@ -1768,17 +1726,15 @@ fn check_method_receiver<'tcx>(
1768
1726
span,
1769
1727
format ! (
1770
1728
"`{receiver_ty}` cannot be used as the type of `self` without \
1771
- the `arbitrary_self_types_pointers` feature",
1729
+ the `arbitrary_self_types_pointers` feature",
1772
1730
) ,
1773
1731
)
1774
1732
. with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1775
1733
. emit ( )
1776
- }
1777
- _ =>
1778
- // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1779
- {
1734
+ } else {
1735
+ // Report error; would not have worked with `arbitrary_self_types_pointers`.
1780
1736
match receiver_validity_err {
1781
- ReceiverValidityError :: DoesNotDeref if arbitrary_self_types_level . is_some ( ) => {
1737
+ ReceiverValidityError :: DoesNotDeref => {
1782
1738
let hint = match receiver_ty
1783
1739
. builtin_deref ( false )
1784
1740
. unwrap_or ( receiver_ty)
@@ -1792,18 +1748,12 @@ fn check_method_receiver<'tcx>(
1792
1748
1793
1749
tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTy { span, receiver_ty, hint } )
1794
1750
}
1795
- ReceiverValidityError :: DoesNotDeref => {
1796
- tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTyNoArbitrarySelfTypes {
1797
- span,
1798
- receiver_ty,
1799
- } )
1800
- }
1801
1751
ReceiverValidityError :: MethodGenericParamUsed => {
1802
1752
tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
1803
1753
}
1804
1754
}
1805
- }
1806
- } ) ;
1755
+ } ,
1756
+ ) ;
1807
1757
}
1808
1758
Ok ( ( ) )
1809
1759
}
@@ -1847,11 +1797,10 @@ fn receiver_is_valid<'tcx>(
1847
1797
span : Span ,
1848
1798
receiver_ty : Ty < ' tcx > ,
1849
1799
self_ty : Ty < ' tcx > ,
1850
- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1800
+ arbitrary_self_types_pointers_enabled : bool ,
1851
1801
method_generics : & ty:: Generics ,
1852
1802
) -> Result < ( ) , ReceiverValidityError > {
1853
1803
let infcx = wfcx. infcx ;
1854
- let tcx = wfcx. tcx ( ) ;
1855
1804
let cause =
1856
1805
ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
1857
1806
@@ -1866,17 +1815,11 @@ fn receiver_is_valid<'tcx>(
1866
1815
1867
1816
confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
1868
1817
1869
- let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
1870
-
1871
- // The `arbitrary_self_types` feature allows custom smart pointer
1872
- // types to be method receivers, as identified by following the Receiver<Target=T>
1873
- // chain.
1874
- if arbitrary_self_types_enabled. is_some ( ) {
1875
- autoderef = autoderef. use_receiver_trait ( ) ;
1876
- }
1818
+ let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty)
1819
+ . use_receiver_trait ( ) ;
1877
1820
1878
1821
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1879
- if arbitrary_self_types_enabled == Some ( ArbitrarySelfTypesLevel :: WithPointers ) {
1822
+ if arbitrary_self_types_pointers_enabled {
1880
1823
autoderef = autoderef. include_raw_pointers ( ) ;
1881
1824
}
1882
1825
@@ -1899,58 +1842,12 @@ fn receiver_is_valid<'tcx>(
1899
1842
wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
1900
1843
return Ok ( ( ) ) ;
1901
1844
}
1902
-
1903
- // Without `feature(arbitrary_self_types)`, we require that each step in the
1904
- // deref chain implement `LegacyReceiver`.
1905
- if arbitrary_self_types_enabled. is_none ( ) {
1906
- let legacy_receiver_trait_def_id =
1907
- tcx. require_lang_item ( LangItem :: LegacyReceiver , Some ( span) ) ;
1908
- if !legacy_receiver_is_implemented (
1909
- wfcx,
1910
- legacy_receiver_trait_def_id,
1911
- cause. clone ( ) ,
1912
- potential_self_ty,
1913
- ) {
1914
- // We cannot proceed.
1915
- break ;
1916
- }
1917
-
1918
- // Register the bound, in case it has any region side-effects.
1919
- wfcx. register_bound (
1920
- cause. clone ( ) ,
1921
- wfcx. param_env ,
1922
- potential_self_ty,
1923
- legacy_receiver_trait_def_id,
1924
- ) ;
1925
- }
1926
1845
}
1927
1846
1928
1847
debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
1929
1848
Err ( ReceiverValidityError :: DoesNotDeref )
1930
1849
}
1931
1850
1932
- fn legacy_receiver_is_implemented < ' tcx > (
1933
- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1934
- legacy_receiver_trait_def_id : DefId ,
1935
- cause : ObligationCause < ' tcx > ,
1936
- receiver_ty : Ty < ' tcx > ,
1937
- ) -> bool {
1938
- let tcx = wfcx. tcx ( ) ;
1939
- let trait_ref = ty:: TraitRef :: new ( tcx, legacy_receiver_trait_def_id, [ receiver_ty] ) ;
1940
-
1941
- let obligation = Obligation :: new ( tcx, cause, wfcx. param_env , trait_ref) ;
1942
-
1943
- if wfcx. infcx . predicate_must_hold_modulo_regions ( & obligation) {
1944
- true
1945
- } else {
1946
- debug ! (
1947
- "receiver_is_implemented: type `{:?}` does not implement `LegacyReceiver` trait" ,
1948
- receiver_ty
1949
- ) ;
1950
- false
1951
- }
1952
- }
1953
-
1954
1851
fn check_variances_for_type_defn < ' tcx > (
1955
1852
tcx : TyCtxt < ' tcx > ,
1956
1853
item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments