@@ -36,7 +36,32 @@ use util::liveness::LivenessResults;
36
36
use rustc_data_structures:: fx:: FxHashSet ;
37
37
use rustc_data_structures:: indexed_vec:: Idx ;
38
38
39
+ macro_rules! span_mirbug {
40
+ ( $context: expr, $elem: expr, $( $message: tt) * ) => ( {
41
+ $crate:: borrow_check:: nll:: type_check:: mirbug(
42
+ $context. tcx( ) ,
43
+ $context. last_span,
44
+ & format!(
45
+ "broken MIR in {:?} ({:?}): {}" ,
46
+ $context. body_id,
47
+ $elem,
48
+ format_args!( $( $message) * ) ,
49
+ ) ,
50
+ )
51
+ } )
52
+ }
53
+
54
+ macro_rules! span_mirbug_and_err {
55
+ ( $context: expr, $elem: expr, $( $message: tt) * ) => ( {
56
+ {
57
+ span_mirbug!( $context, $elem, $( $message) * ) ;
58
+ $context. error( )
59
+ }
60
+ } )
61
+ }
62
+
39
63
mod liveness;
64
+ mod input_output;
40
65
41
66
/// Type checks the given `mir` in the context of the inference
42
67
/// context `infcx`. Returns any region constraints that have yet to
@@ -88,18 +113,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
88
113
& mut |cx| {
89
114
liveness:: generate ( cx, mir, liveness, flow_inits, move_data) ;
90
115
91
- // Equate the input and output tys given by the user with
92
- // the ones found in the MIR.
93
- let & UniversalRegions {
94
- unnormalized_output_ty,
95
- unnormalized_input_tys,
96
- ..
97
- } = universal_regions;
98
- cx. equate_input_or_output ( unnormalized_output_ty, mir. local_decls [ RETURN_PLACE ] . ty ) ;
99
- let arg_locals = ( 1 ..) . map ( Local :: new) ;
100
- for ( & input_ty, local) in unnormalized_input_tys. iter ( ) . zip ( arg_locals) {
101
- cx. equate_input_or_output ( input_ty, mir. local_decls [ local] . ty ) ;
102
- }
116
+ cx. equate_inputs_and_outputs ( mir, universal_regions) ;
103
117
} ,
104
118
)
105
119
}
@@ -136,33 +150,13 @@ fn type_check_internal<'gcx, 'tcx>(
136
150
checker. constraints
137
151
}
138
152
139
-
140
153
fn mirbug ( tcx : TyCtxt , span : Span , msg : & str ) {
141
154
// We sometimes see MIR failures (notably predicate failures) due to
142
155
// the fact that we check rvalue sized predicates here. So use `delay_span_bug`
143
156
// to avoid reporting bugs in those cases.
144
157
tcx. sess . diagnostic ( ) . delay_span_bug ( span, msg) ;
145
158
}
146
159
147
- macro_rules! span_mirbug {
148
- ( $context: expr, $elem: expr, $( $message: tt) * ) => ( {
149
- mirbug( $context. tcx( ) , $context. last_span,
150
- & format!( "broken MIR in {:?} ({:?}): {}" ,
151
- $context. body_id,
152
- $elem,
153
- format_args!( $( $message) * ) ) )
154
- } )
155
- }
156
-
157
- macro_rules! span_mirbug_and_err {
158
- ( $context: expr, $elem: expr, $( $message: tt) * ) => ( {
159
- {
160
- span_mirbug!( $context, $elem, $( $message) * ) ;
161
- $context. error( )
162
- }
163
- } )
164
- }
165
-
166
160
enum FieldAccessError {
167
161
OutOfRange { field_count : usize } ,
168
162
}
@@ -714,25 +708,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
714
708
} )
715
709
}
716
710
717
- fn equate_input_or_output ( & mut self , unnormalized_a : Ty < ' tcx > , b : Ty < ' tcx > ) {
718
- let start_position = Location {
719
- block : START_BLOCK ,
720
- statement_index : 0 ,
721
- } ;
722
- let a = self . normalize ( & unnormalized_a, start_position) ;
723
- if let Err ( terr) = self . eq_types ( a, b, start_position. at_self ( ) ) {
724
- span_mirbug ! (
725
- self ,
726
- start_position,
727
- "bad input or output {:?} normalized to {:?} should equal {:?} but got error {:?}" ,
728
- unnormalized_a,
729
- a,
730
- b,
731
- terr
732
- ) ;
733
- }
734
- }
735
-
736
711
fn tcx ( & self ) -> TyCtxt < ' a , ' gcx , ' tcx > {
737
712
self . infcx . tcx
738
713
}
0 commit comments