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