@@ -32,7 +32,7 @@ use ty::adjustment;
3232use ty:: { TyVid , IntVid , FloatVid } ;
3333use ty:: { self , Ty , TyCtxt } ;
3434use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
35- use ty:: fold:: TypeFoldable ;
35+ use ty:: fold:: { TypeFoldable , TypeFolder , TypeVisitor } ;
3636use ty:: relate:: { Relate , RelateResult , TypeRelation } ;
3737use traits:: { self , PredicateObligations , ProjectionMode } ;
3838use rustc_data_structures:: unify:: { self , UnificationTable } ;
@@ -219,6 +219,15 @@ pub enum TypeOrigin {
219219
220220 // `where a == b`
221221 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 ) ,
222231}
223232
224233impl TypeOrigin {
@@ -238,6 +247,9 @@ impl TypeOrigin {
238247 & TypeOrigin :: IfExpressionWithNoElse ( _) => "if may be missing an else clause" ,
239248 & TypeOrigin :: RangeExpression ( _) => "start and end of range have incompatible types" ,
240249 & 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" ,
241253 }
242254 }
243255}
@@ -1791,6 +1803,9 @@ impl TypeOrigin {
17911803 TypeOrigin :: IfExpressionWithNoElse ( span) => span,
17921804 TypeOrigin :: RangeExpression ( span) => span,
17931805 TypeOrigin :: EquatePredicate ( span) => span,
1806+ TypeOrigin :: MainFunctionType ( span) => span,
1807+ TypeOrigin :: StartFunctionType ( span) => span,
1808+ TypeOrigin :: IntrinsicType ( span) => span,
17941809 }
17951810 }
17961811}
@@ -1841,3 +1856,50 @@ impl RegionVariableOrigin {
18411856 }
18421857 }
18431858}
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