@@ -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 ,
@@ -1628,13 +1627,6 @@ fn check_fn_or_method<'tcx>(
16281627 }
16291628}
16301629
1631- /// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
1632- #[ derive( Clone , Copy , PartialEq ) ]
1633- enum ArbitrarySelfTypesLevel {
1634- Basic , // just arbitrary_self_types
1635- WithPointers , // both arbitrary_self_types and arbitrary_self_types_pointers
1636- }
1637-
16381630#[ instrument( level = "debug" , skip( wfcx) ) ]
16391631fn check_method_receiver < ' tcx > (
16401632 wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
@@ -1667,13 +1659,6 @@ fn check_method_receiver<'tcx>(
16671659 return Ok ( ( ) ) ;
16681660 }
16691661
1670- let arbitrary_self_types_level = if tcx. features ( ) . arbitrary_self_types_pointers ( ) {
1671- Some ( ArbitrarySelfTypesLevel :: WithPointers )
1672- } else if tcx. features ( ) . arbitrary_self_types ( ) {
1673- Some ( ArbitrarySelfTypesLevel :: Basic )
1674- } else {
1675- None
1676- } ;
16771662 let generics = tcx. generics_of ( method. def_id ) ;
16781663
16791664 // yet to do: determine whether self_ty is Sized. If not (most commonly
@@ -1686,46 +1671,19 @@ fn check_method_receiver<'tcx>(
16861671 // exist for this.
16871672 let raw_pointer = is_raw_pointer ( receiver_ty) ;
16881673
1689- let receiver_validity =
1690- receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
1674+ let arbitrary_self_types_pointers_enabled = tcx. features ( ) . arbitrary_self_types_pointers ( ) ;
1675+ let receiver_validity = receiver_is_valid (
1676+ wfcx,
1677+ span,
1678+ receiver_ty,
1679+ self_ty,
1680+ arbitrary_self_types_pointers_enabled,
1681+ generics,
1682+ ) ;
16911683 if let Err ( receiver_validity_err) = receiver_validity {
1692- return Err ( match arbitrary_self_types_level {
1693- // Wherever possible, emit a message advising folks that the features
1694- // `arbitrary_self_types` or `arbitrary_self_types_pointers` might
1695- // have helped.
1696- None if receiver_is_valid (
1697- wfcx,
1698- span,
1699- receiver_ty,
1700- self_ty,
1701- Some ( ArbitrarySelfTypesLevel :: Basic ) ,
1702- generics,
1703- )
1704- . is_ok ( ) =>
1705- {
1706- // Report error; would have worked with `arbitrary_self_types`.
1707- feature_err (
1708- & tcx. sess ,
1709- sym:: arbitrary_self_types,
1710- span,
1711- format ! (
1712- "`{receiver_ty}` cannot be used as the type of `self` without \
1713- the `arbitrary_self_types` feature",
1714- ) ,
1715- )
1716- . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
1717- . emit ( )
1718- }
1719- None | Some ( ArbitrarySelfTypesLevel :: Basic )
1720- if receiver_is_valid (
1721- wfcx,
1722- span,
1723- receiver_ty,
1724- self_ty,
1725- Some ( ArbitrarySelfTypesLevel :: WithPointers ) ,
1726- generics,
1727- )
1728- . is_ok ( ) =>
1684+ return Err (
1685+ if !arbitrary_self_types_pointers_enabled
1686+ && receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true , generics) . is_ok ( )
17291687 {
17301688 // Report error; would have worked with `arbitrary_self_types_pointers`.
17311689 feature_err (
@@ -1734,15 +1692,13 @@ fn check_method_receiver<'tcx>(
17341692 span,
17351693 format ! (
17361694 "`{receiver_ty}` cannot be used as the type of `self` without \
1737- the `arbitrary_self_types_pointers` feature",
1695+ the `arbitrary_self_types_pointers` feature",
17381696 ) ,
17391697 )
17401698 . with_help ( fluent:: hir_analysis_invalid_receiver_ty_help)
17411699 . emit ( )
1742- }
1743- _ =>
1744- // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
1745- {
1700+ } else {
1701+ // Report error; would not have worked with `arbitrary_self_types[_pointers]`.
17461702 match receiver_validity_err {
17471703 ReceiverValidityError :: DoesNotDeref => tcx
17481704 . dcx ( )
@@ -1751,8 +1707,8 @@ fn check_method_receiver<'tcx>(
17511707 tcx. dcx ( ) . emit_err ( errors:: InvalidGenericReceiverTy { span, receiver_ty } )
17521708 }
17531709 }
1754- }
1755- } ) ;
1710+ } ,
1711+ ) ;
17561712 }
17571713 Ok ( ( ) )
17581714}
@@ -1800,11 +1756,10 @@ fn receiver_is_valid<'tcx>(
18001756 span : Span ,
18011757 receiver_ty : Ty < ' tcx > ,
18021758 self_ty : Ty < ' tcx > ,
1803- arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1759+ arbitrary_self_types_pointers_enabled : bool ,
18041760 method_generics : & ty:: Generics ,
18051761) -> Result < ( ) , ReceiverValidityError > {
18061762 let infcx = wfcx. infcx ;
1807- let tcx = wfcx. tcx ( ) ;
18081763 let cause =
18091764 ObligationCause :: new ( span, wfcx. body_def_id , traits:: ObligationCauseCode :: MethodReceiver ) ;
18101765
@@ -1819,17 +1774,11 @@ fn receiver_is_valid<'tcx>(
18191774
18201775 confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics) ?;
18211776
1822- let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
1823-
1824- // The `arbitrary_self_types` feature allows custom smart pointer
1825- // types to be method receivers, as identified by following the Receiver<Target=T>
1826- // chain.
1827- if arbitrary_self_types_enabled. is_some ( ) {
1828- autoderef = autoderef. use_receiver_trait ( ) ;
1829- }
1777+ let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty)
1778+ . use_receiver_trait ( ) ;
18301779
18311780 // The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1832- if arbitrary_self_types_enabled == Some ( ArbitrarySelfTypesLevel :: WithPointers ) {
1781+ if arbitrary_self_types_pointers_enabled {
18331782 autoderef = autoderef. include_raw_pointers ( ) ;
18341783 }
18351784
@@ -1852,58 +1801,12 @@ fn receiver_is_valid<'tcx>(
18521801 wfcx. register_obligations ( autoderef. into_obligations ( ) ) ;
18531802 return Ok ( ( ) ) ;
18541803 }
1855-
1856- // Without `feature(arbitrary_self_types)`, we require that each step in the
1857- // deref chain implement `LegacyReceiver`.
1858- if arbitrary_self_types_enabled. is_none ( ) {
1859- let legacy_receiver_trait_def_id =
1860- tcx. require_lang_item ( LangItem :: LegacyReceiver , Some ( span) ) ;
1861- if !legacy_receiver_is_implemented (
1862- wfcx,
1863- legacy_receiver_trait_def_id,
1864- cause. clone ( ) ,
1865- potential_self_ty,
1866- ) {
1867- // We cannot proceed.
1868- break ;
1869- }
1870-
1871- // Register the bound, in case it has any region side-effects.
1872- wfcx. register_bound (
1873- cause. clone ( ) ,
1874- wfcx. param_env ,
1875- potential_self_ty,
1876- legacy_receiver_trait_def_id,
1877- ) ;
1878- }
18791804 }
18801805
18811806 debug ! ( "receiver_is_valid: type `{:?}` does not deref to `{:?}`" , receiver_ty, self_ty) ;
18821807 Err ( ReceiverValidityError :: DoesNotDeref )
18831808}
18841809
1885- fn legacy_receiver_is_implemented < ' tcx > (
1886- wfcx : & WfCheckingCtxt < ' _ , ' tcx > ,
1887- legacy_receiver_trait_def_id : DefId ,
1888- cause : ObligationCause < ' tcx > ,
1889- receiver_ty : Ty < ' tcx > ,
1890- ) -> bool {
1891- let tcx = wfcx. tcx ( ) ;
1892- let trait_ref = ty:: TraitRef :: new ( tcx, legacy_receiver_trait_def_id, [ receiver_ty] ) ;
1893-
1894- let obligation = Obligation :: new ( tcx, cause, wfcx. param_env , trait_ref) ;
1895-
1896- if wfcx. infcx . predicate_must_hold_modulo_regions ( & obligation) {
1897- true
1898- } else {
1899- debug ! (
1900- "receiver_is_implemented: type `{:?}` does not implement `LegacyReceiver` trait" ,
1901- receiver_ty
1902- ) ;
1903- false
1904- }
1905- }
1906-
19071810fn check_variances_for_type_defn < ' tcx > (
19081811 tcx : TyCtxt < ' tcx > ,
19091812 item : & ' tcx hir:: Item < ' tcx > ,
0 commit comments