@@ -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 ,
@@ -1629,13 +1628,6 @@ fn check_fn_or_method<'tcx>(
16291628 }
16301629}
16311630
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-
16391631#[ instrument( level = "debug" , skip( wfcx) ) ]
16401632fn check_method_receiver < ' tcx > (
16411633 wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1668,13 +1660,6 @@ fn check_method_receiver<'tcx>(
16681660 return Ok ( ( ) ) ;
16691661 }
16701662
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- } ;
16781663 let generics = tcx. generics_of ( method. def_id ) ;
16791664
16801665 // yet to do: determine whether self_ty is Sized. If not (most commonly
@@ -1687,46 +1672,19 @@ fn check_method_receiver<'tcx>(
16871672 // exist for this.
16881673 let raw_pointer = is_raw_pointer ( receiver_ty) ;
16891674
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+ ) ;
16921684 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 ( )
17301688 {
17311689 // Report error; would have worked with `arbitrary_self_types_pointers`.
17321690 feature_err (
@@ -1735,15 +1693,13 @@ fn check_method_receiver<'tcx>(
17351693 span,
17361694 format ! (
17371695 "`{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",
17391697 ) ,
17401698 )
17411699 . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
17421700 . 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]`.
17471703 match receiver_validity_err {
17481704 ReceiverValidityError :: DoesNotDeref => tcx
17491705 . dcx ( )
@@ -1752,8 +1708,8 @@ fn check_method_receiver<'tcx>(
17521708 tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
17531709 }
17541710 }
1755- }
1756- } ) ;
1711+ } ,
1712+ ) ;
17571713 }
17581714 Ok ( ( ) )
17591715}
@@ -1801,11 +1757,10 @@ fn receiver_is_valid<'tcx>(
18011757 span : Span ,
18021758 receiver_ty : Ty < ' tcx > ,
18031759 self_ty : Ty < ' tcx > ,
1804- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1760+ arbitrary_self_types_pointers_enabled : bool ,
18051761 method_generics : & ty:: Generics ,
18061762) -> Result < ( ) , ReceiverValidityError > {
18071763 let infcx = wfcx. infcx ;
1808- let tcx = wfcx. tcx ( ) ;
18091764 let cause =
18101765 ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
18111766
@@ -1820,17 +1775,11 @@ fn receiver_is_valid<'tcx>(
18201775
18211776 confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
18221777
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 ( ) ;
18311780
18321781 // 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 {
18341783 autoderef = autoderef. include_raw_pointers ( ) ;
18351784 }
18361785
@@ -1853,58 +1802,12 @@ fn receiver_is_valid<'tcx>(
18531802 wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
18541803 return Ok ( ( ) ) ;
18551804 }
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- }
18801805 }
18811806
18821807 debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
18831808 Err ( ReceiverValidityError :: DoesNotDeref )
18841809}
18851810
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-
19081811fn check_variances_for_type_defn < ' tcx > (
19091812 tcx : TyCtxt < ' tcx > ,
19101813 item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments