@@ -30,7 +30,6 @@ use rustc_trait_selection::traits::misc::{
3030 ConstParamTyImplementationError , type_allowed_to_implement_const_param_ty,
3131} ;
3232use rustc_trait_selection:: traits:: outlives_bounds:: InferCtxtExt as _;
33- use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
3433use rustc_trait_selection:: traits:: {
3534 self , FulfillmentError , Obligation , ObligationCause , ObligationCauseCode , ObligationCtxt ,
3635 WellFormedLoc ,
@@ -1642,13 +1641,6 @@ fn check_fn_or_method<'tcx>(
16421641 }
16431642}
16441643
1645- /// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1646- #[ derive( Clone , Copy , PartialEq ) ]
1647- enum ArbitrarySelfTypesLevel {
1648- Basic , // just arbitrary_self_types
1649- WithPointers , // both arbitrary_self_types and arbitrary_self_types_pointers
1650- }
1651-
16521644#[ instrument( level = "debug" , skip( wfcx) ) ]
16531645fn check_method_receiver < ' tcx > (
16541646 wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1681,55 +1673,21 @@ fn check_method_receiver<'tcx>(
16811673 return Ok ( ( ) ) ;
16821674 }
16831675
1684- let arbitrary_self_types_level = if tcx. features ( ) . arbitrary_self_types_pointers ( ) {
1685- Some ( ArbitrarySelfTypesLevel :: WithPointers )
1686- } else if tcx. features ( ) . arbitrary_self_types ( ) {
1687- Some ( ArbitrarySelfTypesLevel :: Basic )
1688- } else {
1689- None
1690- } ;
16911676 let generics = tcx. generics_of ( method. def_id ) ;
16921677
1693- let receiver_validity =
1694- receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
1678+ let arbitrary_self_types_pointers_enabled = tcx. features ( ) . arbitrary_self_types_pointers ( ) ;
1679+ let receiver_validity = receiver_is_valid (
1680+ wfcx,
1681+ span,
1682+ receiver_ty,
1683+ self_ty,
1684+ arbitrary_self_types_pointers_enabled,
1685+ generics,
1686+ ) ;
16951687 if let Err ( receiver_validity_err) = receiver_validity {
1696- return Err ( match arbitrary_self_types_level {
1697- // Wherever possible, emit a message advising folks that the features
1698- // `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1699- // have helped.
1700- None if receiver_is_valid (
1701- wfcx,
1702- span,
1703- receiver_ty,
1704- self_ty,
1705- Some ( ArbitrarySelfTypesLevel :: Basic ) ,
1706- generics,
1707- )
1708- . is_ok ( ) =>
1709- {
1710- // Report error; would have worked with `arbitrary_self_types`.
1711- feature_err (
1712- & tcx. sess ,
1713- sym:: arbitrary_self_types,
1714- span,
1715- format ! (
1716- "`{receiver_ty}` cannot be used as the type of `self` without \
1717- the `arbitrary_self_types` feature",
1718- ) ,
1719- )
1720- . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1721- . emit ( )
1722- }
1723- None | Some ( ArbitrarySelfTypesLevel :: Basic )
1724- if receiver_is_valid (
1725- wfcx,
1726- span,
1727- receiver_ty,
1728- self_ty,
1729- Some ( ArbitrarySelfTypesLevel :: WithPointers ) ,
1730- generics,
1731- )
1732- . is_ok ( ) =>
1688+ return Err (
1689+ if !arbitrary_self_types_pointers_enabled
1690+ && receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true , generics) . is_ok ( )
17331691 {
17341692 // Report error; would have worked with `arbitrary_self_types_pointers`.
17351693 feature_err (
@@ -1738,17 +1696,15 @@ fn check_method_receiver<'tcx>(
17381696 span,
17391697 format ! (
17401698 "`{receiver_ty}` cannot be used as the type of `self` without \
1741- the `arbitrary_self_types_pointers` feature",
1699+ the `arbitrary_self_types_pointers` feature",
17421700 ) ,
17431701 )
17441702 . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
17451703 . emit ( )
1746- }
1747- _ =>
1748- // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1749- {
1704+ } else {
1705+ // Report error; would not have worked with `arbitrary_self_types_pointers`.
17501706 match receiver_validity_err {
1751- ReceiverValidityError :: DoesNotDeref if arbitrary_self_types_level . is_some ( ) => {
1707+ ReceiverValidityError :: DoesNotDeref => {
17521708 let hint = match receiver_ty
17531709 . builtin_deref ( false )
17541710 . unwrap_or ( receiver_ty)
@@ -1762,18 +1718,12 @@ fn check_method_receiver<'tcx>(
17621718
17631719 tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTy { span, receiver_ty, hint } )
17641720 }
1765- ReceiverValidityError :: DoesNotDeref => {
1766- tcx. dcx ( ) . emit_err ( errors:: InvalidReceiverTyNoArbitrarySelfTypes {
1767- span,
1768- receiver_ty,
1769- } )
1770- }
17711721 ReceiverValidityError :: MethodGenericParamUsed => {
17721722 tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
17731723 }
17741724 }
1775- }
1776- } ) ;
1725+ } ,
1726+ ) ;
17771727 }
17781728 Ok ( ( ) )
17791729}
@@ -1817,11 +1767,10 @@ fn receiver_is_valid<'tcx>(
18171767 span : Span ,
18181768 receiver_ty : Ty < ' tcx > ,
18191769 self_ty : Ty < ' tcx > ,
1820- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1770+ arbitrary_self_types_pointers_enabled : bool ,
18211771 method_generics : & ty:: Generics ,
18221772) -> Result < ( ) , ReceiverValidityError > {
18231773 let infcx = wfcx. infcx ;
1824- let tcx = wfcx. tcx ( ) ;
18251774 let cause =
18261775 ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
18271776
@@ -1836,17 +1785,11 @@ fn receiver_is_valid<'tcx>(
18361785
18371786 confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
18381787
1839- let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
1840-
1841- // The `arbitrary_self_types` feature allows custom smart pointer
1842- // types to be method receivers, as identified by following the Receiver<Target=T>
1843- // chain.
1844- if arbitrary_self_types_enabled. is_some ( ) {
1845- autoderef = autoderef. use_receiver_trait ( ) ;
1846- }
1788+ let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty)
1789+ . use_receiver_trait ( ) ;
18471790
18481791 // The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1849- if arbitrary_self_types_enabled == Some ( ArbitrarySelfTypesLevel :: WithPointers ) {
1792+ if arbitrary_self_types_pointers_enabled {
18501793 autoderef = autoderef. include_raw_pointers ( ) ;
18511794 }
18521795
@@ -1869,58 +1812,12 @@ fn receiver_is_valid<'tcx>(
18691812 wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
18701813 return Ok ( ( ) ) ;
18711814 }
1872-
1873- // Without `feature(arbitrary_self_types)`, we require that each step in the
1874- // deref chain implement `LegacyReceiver`.
1875- if arbitrary_self_types_enabled. is_none ( ) {
1876- let legacy_receiver_trait_def_id =
1877- tcx. require_lang_item ( LangItem :: LegacyReceiver , Some ( span) ) ;
1878- if !legacy_receiver_is_implemented (
1879- wfcx,
1880- legacy_receiver_trait_def_id,
1881- cause. clone ( ) ,
1882- potential_self_ty,
1883- ) {
1884- // We cannot proceed.
1885- break ;
1886- }
1887-
1888- // Register the bound, in case it has any region side-effects.
1889- wfcx. register_bound (
1890- cause. clone ( ) ,
1891- wfcx. param_env ,
1892- potential_self_ty,
1893- legacy_receiver_trait_def_id,
1894- ) ;
1895- }
18961815 }
18971816
18981817 debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
18991818 Err ( ReceiverValidityError :: DoesNotDeref )
19001819}
19011820
1902- fn legacy_receiver_is_implemented < ' tcx > (
1903- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1904- legacy_receiver_trait_def_id : DefId ,
1905- cause : ObligationCause < ' tcx > ,
1906- receiver_ty : Ty < ' tcx > ,
1907- ) -> bool {
1908- let tcx = wfcx. tcx ( ) ;
1909- let trait_ref = ty:: TraitRef :: new ( tcx, legacy_receiver_trait_def_id, [ receiver_ty] ) ;
1910-
1911- let obligation = Obligation :: new ( tcx, cause, wfcx. param_env , trait_ref) ;
1912-
1913- if wfcx. infcx . predicate_must_hold_modulo_regions ( & obligation) {
1914- true
1915- } else {
1916- debug ! (
1917- "receiver_is_implemented: type `{:?}` does not implement `LegacyReceiver` trait" ,
1918- receiver_ty
1919- ) ;
1920- false
1921- }
1922- }
1923-
19241821fn check_variances_for_type_defn < ' tcx > (
19251822 tcx : TyCtxt < ' tcx > ,
19261823 item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments