@@ -32,7 +32,7 @@ use ty::adjustment;
32
32
use ty:: { TyVid , IntVid , FloatVid } ;
33
33
use ty:: { self , Ty , TyCtxt } ;
34
34
use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
35
- use ty:: fold:: TypeFoldable ;
35
+ use ty:: fold:: { TypeFoldable , TypeFolder , TypeVisitor } ;
36
36
use ty:: relate:: { Relate , RelateResult , TypeRelation } ;
37
37
use traits:: { self , PredicateObligations , ProjectionMode } ;
38
38
use rustc_data_structures:: unify:: { self , UnificationTable } ;
@@ -219,6 +219,15 @@ pub enum TypeOrigin {
219
219
220
220
// `where a == b`
221
221
EquatePredicate ( Span ) ,
222
+
223
+ // `main` has wrong type
224
+ MainFunctionType ( Span ) ,
225
+
226
+ // `start` has wrong type
227
+ StartFunctionType ( Span ) ,
228
+
229
+ // intrinsic has wrong type
230
+ IntrinsicType ( Span ) ,
222
231
}
223
232
224
233
impl TypeOrigin {
@@ -238,6 +247,9 @@ impl TypeOrigin {
238
247
& TypeOrigin :: IfExpressionWithNoElse ( _) => "if may be missing an else clause" ,
239
248
& TypeOrigin :: RangeExpression ( _) => "start and end of range have incompatible types" ,
240
249
& TypeOrigin :: EquatePredicate ( _) => "equality predicate not satisfied" ,
250
+ & TypeOrigin :: MainFunctionType ( _) => "main function has wrong type" ,
251
+ & TypeOrigin :: StartFunctionType ( _) => "start function has wrong type" ,
252
+ & TypeOrigin :: IntrinsicType ( _) => "intrinsic has wrong type" ,
241
253
}
242
254
}
243
255
}
@@ -1791,6 +1803,9 @@ impl TypeOrigin {
1791
1803
TypeOrigin :: IfExpressionWithNoElse ( span) => span,
1792
1804
TypeOrigin :: RangeExpression ( span) => span,
1793
1805
TypeOrigin :: EquatePredicate ( span) => span,
1806
+ TypeOrigin :: MainFunctionType ( span) => span,
1807
+ TypeOrigin :: StartFunctionType ( span) => span,
1808
+ TypeOrigin :: IntrinsicType ( span) => span,
1794
1809
}
1795
1810
}
1796
1811
}
@@ -1841,3 +1856,50 @@ impl RegionVariableOrigin {
1841
1856
}
1842
1857
}
1843
1858
}
1859
+
1860
+ impl < ' tcx > TypeFoldable < ' tcx > for TypeOrigin {
1861
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , _folder : & mut F ) -> Self {
1862
+ self . clone ( )
1863
+ }
1864
+
1865
+ fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _visitor : & mut V ) -> bool {
1866
+ false
1867
+ }
1868
+ }
1869
+
1870
+ impl < ' tcx > TypeFoldable < ' tcx > for ValuePairs < ' tcx > {
1871
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
1872
+ match * self {
1873
+ ValuePairs :: Types ( ref ef) => {
1874
+ ValuePairs :: Types ( ef. fold_with ( folder) )
1875
+ }
1876
+ ValuePairs :: TraitRefs ( ref ef) => {
1877
+ ValuePairs :: TraitRefs ( ef. fold_with ( folder) )
1878
+ }
1879
+ ValuePairs :: PolyTraitRefs ( ref ef) => {
1880
+ ValuePairs :: PolyTraitRefs ( ef. fold_with ( folder) )
1881
+ }
1882
+ }
1883
+ }
1884
+
1885
+ fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
1886
+ match * self {
1887
+ ValuePairs :: Types ( ref ef) => ef. visit_with ( visitor) ,
1888
+ ValuePairs :: TraitRefs ( ref ef) => ef. visit_with ( visitor) ,
1889
+ ValuePairs :: PolyTraitRefs ( ref ef) => ef. visit_with ( visitor) ,
1890
+ }
1891
+ }
1892
+ }
1893
+
1894
+ impl < ' tcx > TypeFoldable < ' tcx > for TypeTrace < ' tcx > {
1895
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
1896
+ TypeTrace {
1897
+ origin : self . origin . fold_with ( folder) ,
1898
+ values : self . values . fold_with ( folder)
1899
+ }
1900
+ }
1901
+
1902
+ fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
1903
+ self . origin . visit_with ( visitor) || self . values . visit_with ( visitor)
1904
+ }
1905
+ }
0 commit comments