File tree Expand file tree Collapse file tree 5 files changed +80
-0
lines changed
rustc_trait_selection/src/solve Expand file tree Collapse file tree 5 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -1046,6 +1046,13 @@ impl<'tcx> InferCtxt<'tcx> {
1046
1046
}
1047
1047
}
1048
1048
1049
+ pub fn shallow_resolve_term ( & self , term : ty:: Term < ' tcx > ) -> ty:: Term < ' tcx > {
1050
+ match term. kind ( ) {
1051
+ ty:: TermKind :: Ty ( ty) => self . shallow_resolve ( ty) . into ( ) ,
1052
+ ty:: TermKind :: Const ( ct) => self . shallow_resolve_const ( ct) . into ( ) ,
1053
+ }
1054
+ }
1055
+
1049
1056
pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
1050
1057
self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
1051
1058
}
Original file line number Diff line number Diff line change @@ -144,6 +144,19 @@ impl<'tcx> Const<'tcx> {
144
144
let reported = tcx. dcx ( ) . span_delayed_bug ( span, msg) ;
145
145
Const :: new_error ( tcx, reported)
146
146
}
147
+
148
+ pub fn is_trivially_wf ( self ) -> bool {
149
+ match self . kind ( ) {
150
+ ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Placeholder ( _) | ty:: ConstKind :: Bound ( ..) => {
151
+ true
152
+ }
153
+ ty:: ConstKind :: Infer ( _)
154
+ | ty:: ConstKind :: Unevaluated ( ..)
155
+ | ty:: ConstKind :: Value ( _)
156
+ | ty:: ConstKind :: Error ( _)
157
+ | ty:: ConstKind :: Expr ( _) => false ,
158
+ }
159
+ }
147
160
}
148
161
149
162
impl < ' tcx > rustc_type_ir:: inherent:: Const < TyCtxt < ' tcx > > for Const < ' tcx > {
Original file line number Diff line number Diff line change @@ -651,6 +651,13 @@ impl<'tcx> Term<'tcx> {
651
651
}
652
652
}
653
653
654
+ pub fn is_trivially_wf ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
655
+ match self . kind ( ) {
656
+ TermKind :: Ty ( ty) => ty. is_trivially_wf ( tcx) ,
657
+ TermKind :: Const ( ct) => ct. is_trivially_wf ( ) ,
658
+ }
659
+ }
660
+
654
661
/// Iterator that walks `self` and any types reachable from
655
662
/// `self`, in depth-first order. Note that just walks the types
656
663
/// that appear in `self`, it does not descend into the fields of
Original file line number Diff line number Diff line change @@ -1888,6 +1888,50 @@ impl<'tcx> Ty<'tcx> {
1888
1888
}
1889
1889
}
1890
1890
1891
+ pub fn is_trivially_wf ( self , tcx : TyCtxt < ' tcx > ) -> bool {
1892
+ match * self . kind ( ) {
1893
+ ty:: Bool
1894
+ | ty:: Char
1895
+ | ty:: Int ( _)
1896
+ | ty:: Uint ( _)
1897
+ | ty:: Float ( _)
1898
+ | ty:: Str
1899
+ | ty:: Never
1900
+ | ty:: Param ( _)
1901
+ | ty:: Placeholder ( _)
1902
+ | ty:: Bound ( ..) => true ,
1903
+
1904
+ ty:: Slice ( ty) => ty. is_trivially_wf ( tcx) && ty. is_trivially_sized ( tcx) ,
1905
+ ty:: RawPtr ( ty, _) => ty. is_trivially_wf ( tcx) ,
1906
+
1907
+ ty:: FnPtr ( sig_tys, _) => {
1908
+ sig_tys. skip_binder ( ) . inputs_and_output . iter ( ) . all ( |ty| ty. is_trivially_wf ( tcx) )
1909
+ }
1910
+ ty:: Ref ( _, ty, _) => ty. is_global ( ) && ty. is_trivially_wf ( tcx) ,
1911
+
1912
+ ty:: Infer ( infer) => match infer {
1913
+ ty:: TyVar ( _) => false ,
1914
+ ty:: IntVar ( _) | ty:: FloatVar ( _) => true ,
1915
+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => true ,
1916
+ } ,
1917
+
1918
+ ty:: Adt ( _, _)
1919
+ | ty:: Tuple ( _)
1920
+ | ty:: Array ( ..)
1921
+ | ty:: Foreign ( _)
1922
+ | ty:: Pat ( _, _)
1923
+ | ty:: FnDef ( ..)
1924
+ | ty:: UnsafeBinder ( ..)
1925
+ | ty:: Dynamic ( ..)
1926
+ | ty:: Closure ( ..)
1927
+ | ty:: CoroutineClosure ( ..)
1928
+ | ty:: Coroutine ( ..)
1929
+ | ty:: CoroutineWitness ( ..)
1930
+ | ty:: Alias ( ..)
1931
+ | ty:: Error ( _) => false ,
1932
+ }
1933
+ }
1934
+
1891
1935
/// If `self` is a primitive, return its [`Symbol`].
1892
1936
pub fn primitive_symbol ( self ) -> Option < Symbol > {
1893
1937
match self . kind ( ) {
Original file line number Diff line number Diff line change @@ -136,6 +136,15 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
136
136
None
137
137
}
138
138
}
139
+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: WellFormed ( arg) ) => {
140
+ if arg. is_trivially_wf ( self . tcx ) {
141
+ Some ( Certainty :: Yes )
142
+ } else if self . shallow_resolve_term ( arg) . is_infer ( ) {
143
+ Some ( Certainty :: AMBIGUOUS )
144
+ } else {
145
+ None
146
+ }
147
+ }
139
148
_ => None ,
140
149
}
141
150
}
You can’t perform that action at this time.
0 commit comments