55//! candidates. See the [rustc dev guide] for more details.
66//!
77//! [rustc dev guide]:https://rustc-dev-guide.rust-lang.org/traits/resolution.html#candidate-assembly
8+ use hir:: LangItem ;
89use rustc_hir as hir;
910use rustc_hir:: def_id:: DefId ;
1011use rustc_infer:: traits:: TraitEngine ;
@@ -307,7 +308,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
307308 } else if lang_items. drop_trait ( ) == Some ( def_id)
308309 && obligation. predicate . is_const_if_const ( )
309310 {
310- self . assemble_const_drop_candidates ( obligation, & mut candidates) ;
311+ // holds to make it easier to transition
312+ // FIXME(fee1-dead): add a note for selection error of `~const Drop`
313+ // when beta is bumped
314+ // FIXME: remove this when beta is bumped
315+ #[ cfg( bootstrap) ]
316+ { }
317+
318+ candidates. vec . push ( SelectionCandidate :: ConstDestructCandidate ( None ) )
319+ } else if lang_items. destruct_trait ( ) == Some ( def_id) {
320+ self . assemble_const_destruct_candidates ( obligation, & mut candidates) ;
311321 } else {
312322 if lang_items. clone_trait ( ) == Some ( def_id) {
313323 // Same builtin conditions as `Copy`, i.e., every type which has builtin support
@@ -906,15 +916,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
906916 }
907917 }
908918
909- fn assemble_const_drop_candidates (
919+ fn assemble_const_destruct_candidates (
910920 & mut self ,
911921 obligation : & TraitObligation < ' tcx > ,
912922 candidates : & mut SelectionCandidateSet < ' tcx > ,
913923 ) {
914- // If the predicate is `~const Drop ` in a non-const environment, we don't actually need
924+ // If the predicate is `~const Destruct ` in a non-const environment, we don't actually need
915925 // to check anything. We'll short-circuit checking any obligations in confirmation, too.
916- if obligation. param_env . constness ( ) == hir :: Constness :: NotConst {
917- candidates. vec . push ( ConstDropCandidate ( None ) ) ;
926+ if ! obligation. is_const ( ) {
927+ candidates. vec . push ( ConstDestructCandidate ( None ) ) ;
918928 return ;
919929 }
920930
@@ -927,7 +937,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
927937 | ty:: Param ( _)
928938 | ty:: Placeholder ( _)
929939 | ty:: Projection ( _) => {
930- // We don't know if these are `~const Drop `, at least
940+ // We don't know if these are `~const Destruct `, at least
931941 // not structurally... so don't push a candidate.
932942 }
933943
@@ -951,26 +961,26 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
951961 | ty:: Generator ( ..)
952962 | ty:: Tuple ( _)
953963 | ty:: GeneratorWitness ( _) => {
954- // These are built-in, and cannot have a custom `impl const Drop `.
955- candidates. vec . push ( ConstDropCandidate ( None ) ) ;
964+ // These are built-in, and cannot have a custom `impl const Destruct `.
965+ candidates. vec . push ( ConstDestructCandidate ( None ) ) ;
956966 }
957967
958968 ty:: Adt ( ..) => {
959969 // Find a custom `impl Drop` impl, if it exists
960970 let relevant_impl = self . tcx ( ) . find_map_relevant_impl (
961- obligation . predicate . def_id ( ) ,
971+ self . tcx ( ) . require_lang_item ( LangItem :: Drop , None ) ,
962972 obligation. predicate . skip_binder ( ) . trait_ref . self_ty ( ) ,
963973 Some ,
964974 ) ;
965975
966976 if let Some ( impl_def_id) = relevant_impl {
967977 // Check that `impl Drop` is actually const, if there is a custom impl
968978 if self . tcx ( ) . impl_constness ( impl_def_id) == hir:: Constness :: Const {
969- candidates. vec . push ( ConstDropCandidate ( Some ( impl_def_id) ) ) ;
979+ candidates. vec . push ( ConstDestructCandidate ( Some ( impl_def_id) ) ) ;
970980 }
971981 } else {
972982 // Otherwise check the ADT like a built-in type (structurally)
973- candidates. vec . push ( ConstDropCandidate ( None ) ) ;
983+ candidates. vec . push ( ConstDestructCandidate ( None ) ) ;
974984 }
975985 }
976986
0 commit comments