File tree Expand file tree Collapse file tree 8 files changed +66
-10
lines changed
rustc_next_trait_solver/src/solve
tests/ui/field_projections Expand file tree Collapse file tree 8 files changed +66
-10
lines changed Original file line number Diff line number Diff line change @@ -807,6 +807,8 @@ bidirectional_lang_item_map! {
807807 CoroutineReturn ,
808808 CoroutineYield ,
809809 DynMetadata ,
810+ FieldBase ,
811+ FieldType ,
810812 FutureOutput ,
811813 Metadata ,
812814// tidy-alphabetical-end
Original file line number Diff line number Diff line change @@ -351,6 +351,11 @@ where
351351 ecx : & mut EvalCtxt < ' _ , D > ,
352352 goal : Goal < I , Self > ,
353353 ) -> Vec < Candidate < I > > ;
354+
355+ fn consider_builtin_field_candidate (
356+ ecx : & mut EvalCtxt < ' _ , D > ,
357+ goal : Goal < I , Self > ,
358+ ) -> Result < Candidate < I > , NoSolution > ;
354359}
355360
356361/// Allows callers of `assemble_and_evaluate_candidates` to choose whether to limit
@@ -609,6 +614,7 @@ where
609614 Some ( SolverTraitLangItem :: BikeshedGuaranteedNoDrop ) => {
610615 G :: consider_builtin_bikeshed_guaranteed_no_drop_candidate ( self , goal)
611616 }
617+ Some ( SolverTraitLangItem :: Field ) => G :: consider_builtin_field_candidate ( self , goal) ,
612618 _ => Err ( NoSolution ) ,
613619 }
614620 } ;
Original file line number Diff line number Diff line change @@ -382,6 +382,13 @@ where
382382 ) -> Vec < Candidate < I > > {
383383 unreachable ! ( "Unsize is not const" )
384384 }
385+
386+ fn consider_builtin_field_candidate (
387+ _ecx : & mut EvalCtxt < ' _ , D > ,
388+ _goal : Goal < I , Self > ,
389+ ) -> Result < Candidate < I > , NoSolution > {
390+ unreachable ! ( "Field is not const" )
391+ }
385392}
386393
387394impl < D , I > EvalCtxt < ' _ , D >
Original file line number Diff line number Diff line change @@ -949,6 +949,26 @@ where
949949 ) -> Result < Candidate < I > , NoSolution > {
950950 unreachable ! ( "`BikeshedGuaranteedNoDrop` does not have an associated type: {:?}" , goal)
951951 }
952+ fn consider_builtin_field_candidate (
953+ ecx : & mut EvalCtxt < ' _ , D > ,
954+ goal : Goal < <D as SolverDelegate >:: Interner , Self > ,
955+ ) -> Result < Candidate < I > , NoSolution > {
956+ let cx = ecx. cx ( ) ;
957+ let ty:: Field ( container, field_path) = goal. predicate . self_ty ( ) . kind ( ) else {
958+ panic ! ( "only `field_of!()` can implement `Field`" )
959+ } ;
960+ let ty = if cx. is_lang_item ( goal. predicate . def_id ( ) , SolverLangItem :: FieldBase ) {
961+ container
962+ } else if cx. is_lang_item ( goal. predicate . def_id ( ) , SolverLangItem :: FieldType ) {
963+ field_path. field_ty ( cx, container)
964+ } else {
965+ panic ! ( "unexpected associated type {:?} in `Field`" , goal. predicate)
966+ } ;
967+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
968+ ecx. instantiate_normalizes_to_term ( goal, ty. into ( ) ) ;
969+ ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
970+ } )
971+ }
952972}
953973
954974impl < D , I > EvalCtxt < ' _ , D >
Original file line number Diff line number Diff line change @@ -842,6 +842,22 @@ where
842842 }
843843 } )
844844 }
845+
846+ fn consider_builtin_field_candidate (
847+ ecx : & mut EvalCtxt < ' _ , D > ,
848+ goal : Goal < I , Self > ,
849+ ) -> Result < Candidate < I > , NoSolution > {
850+ if goal. predicate . polarity != ty:: PredicatePolarity :: Positive {
851+ return Err ( NoSolution ) ;
852+ }
853+
854+ match goal. predicate . self_ty ( ) . kind ( ) {
855+ ty:: Field ( ..) => ecx
856+ . probe_builtin_trait_candidate ( BuiltinImplSource :: Misc )
857+ . enter ( |ecx| ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes ) ) ,
858+ _ => Err ( NoSolution ) ,
859+ }
860+ }
845861}
846862
847863/// Small helper function to change the `def_id` of a trait predicate - this is not normally
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ pub enum SolverLangItem {
99 CoroutineReturn ,
1010 CoroutineYield ,
1111 DynMetadata ,
12+ FieldBase ,
13+ FieldType ,
1214 FutureOutput ,
1315 Metadata ,
1416 // tidy-alphabetical-end
Original file line number Diff line number Diff line change 1- error[E0322]: explicit impls for the `UnalignedField` trait are not permitted
2- --> $DIR/deny-manual-impl.rs:11:1
3- |
4- LL | unsafe impl UnalignedField for MyStruct {
5- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `UnalignedField` not allowed
6-
71error[E0322]: explicit impls for the `Field` trait are not permitted
8- --> $DIR/deny-manual-impl.rs:18 :1
2+ --> $DIR/deny-manual-impl.rs:11 :1
93 |
10- LL | unsafe impl Field for field_of!( MyStruct, 0) {}
11- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Field` not allowed
4+ LL | unsafe impl Field for MyStruct {
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Field` not allowed
126
13- error: aborting due to 2 previous errors
7+ error: aborting due to 1 previous error
148
159For more information about this error, try `rustc --explain E0322`.
Original file line number Diff line number Diff line change 1+ error[E0322]: explicit impls for the `Field` trait are not permitted
2+ --> $DIR/deny-manual-impl.rs:11:1
3+ |
4+ LL | unsafe impl Field for MyStruct {
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Field` not allowed
6+
7+ error: aborting due to 1 previous error
8+
9+ For more information about this error, try `rustc --explain E0322`.
You can’t perform that action at this time.
0 commit comments