5
5
//! candidates. See the [rustc dev guide] for more details.
6
6
//!
7
7
//! [rustc dev guide]:https://rustc-dev-guide.rust-lang.org/traits/resolution.html#candidate-assembly
8
+ use hir:: LangItem ;
8
9
use rustc_hir as hir;
9
10
use rustc_hir:: def_id:: DefId ;
10
11
use rustc_infer:: traits:: TraitEngine ;
@@ -307,7 +308,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
307
308
} else if lang_items. drop_trait ( ) == Some ( def_id)
308
309
&& obligation. predicate . is_const_if_const ( )
309
310
{
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) ;
311
321
} else {
312
322
if lang_items. clone_trait ( ) == Some ( def_id) {
313
323
// Same builtin conditions as `Copy`, i.e., every type which has builtin support
@@ -906,15 +916,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
906
916
}
907
917
}
908
918
909
- fn assemble_const_drop_candidates (
919
+ fn assemble_const_destruct_candidates (
910
920
& mut self ,
911
921
obligation : & TraitObligation < ' tcx > ,
912
922
candidates : & mut SelectionCandidateSet < ' tcx > ,
913
923
) {
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
915
925
// 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 ) ) ;
918
928
return ;
919
929
}
920
930
@@ -927,7 +937,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
927
937
| ty:: Param ( _)
928
938
| ty:: Placeholder ( _)
929
939
| 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
931
941
// not structurally... so don't push a candidate.
932
942
}
933
943
@@ -951,26 +961,26 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
951
961
| ty:: Generator ( ..)
952
962
| ty:: Tuple ( _)
953
963
| 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 ) ) ;
956
966
}
957
967
958
968
ty:: Adt ( ..) => {
959
969
// Find a custom `impl Drop` impl, if it exists
960
970
let relevant_impl = self . tcx ( ) . find_map_relevant_impl (
961
- obligation . predicate . def_id ( ) ,
971
+ self . tcx ( ) . require_lang_item ( LangItem :: Drop , None ) ,
962
972
obligation. predicate . skip_binder ( ) . trait_ref . self_ty ( ) ,
963
973
Some ,
964
974
) ;
965
975
966
976
if let Some ( impl_def_id) = relevant_impl {
967
977
// Check that `impl Drop` is actually const, if there is a custom impl
968
978
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) ) ) ;
970
980
}
971
981
} else {
972
982
// Otherwise check the ADT like a built-in type (structurally)
973
- candidates. vec . push ( ConstDropCandidate ( None ) ) ;
983
+ candidates. vec . push ( ConstDestructCandidate ( None ) ) ;
974
984
}
975
985
}
976
986
0 commit comments