@@ -38,7 +38,6 @@ use rustc::traits::query::type_op;
38
38
use rustc:: traits:: query:: { Fallible , NoSolution } ;
39
39
use rustc:: ty:: fold:: TypeFoldable ;
40
40
use rustc:: ty:: { self , CanonicalTy , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind } ;
41
- use rustc_errors:: Diagnostic ;
42
41
use std:: fmt;
43
42
use std:: rc:: Rc ;
44
43
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -106,8 +105,7 @@ mod relate_tys;
106
105
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
107
106
/// constraints for the regions in the types of variables
108
107
/// - `flow_inits` -- results of a maybe-init dataflow analysis
109
- /// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
110
- /// - `errors_buffer` -- errors are sent here for future reporting
108
+ /// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysiss
111
109
pub ( crate ) fn type_check < ' gcx , ' tcx > (
112
110
infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
113
111
param_env : ty:: ParamEnv < ' gcx > ,
@@ -120,7 +118,6 @@ pub(crate) fn type_check<'gcx, 'tcx>(
120
118
flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' _ , ' gcx , ' tcx > > ,
121
119
move_data : & MoveData < ' tcx > ,
122
120
elements : & Rc < RegionValueElements > ,
123
- errors_buffer : & mut Vec < Diagnostic > ,
124
121
) -> MirTypeckResults < ' tcx > {
125
122
let implicit_region_bound = infcx. tcx . mk_region ( ty:: ReVar ( universal_regions. fr_fn_body ) ) ;
126
123
let mut constraints = MirTypeckRegionConstraints {
@@ -161,7 +158,6 @@ pub(crate) fn type_check<'gcx, 'tcx>(
161
158
& region_bound_pairs,
162
159
Some ( implicit_region_bound) ,
163
160
Some ( & mut borrowck_context) ,
164
- Some ( errors_buffer) ,
165
161
|cx| {
166
162
cx. equate_inputs_and_outputs (
167
163
mir,
@@ -191,7 +187,6 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>(
191
187
region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
192
188
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
193
189
borrowck_context : Option < & ' a mut BorrowCheckContext < ' a , ' tcx > > ,
194
- errors_buffer : Option < & mut Vec < Diagnostic > > ,
195
190
mut extra : impl FnMut ( & mut TypeChecker < ' a , ' gcx , ' tcx > ) -> R ,
196
191
) -> R where {
197
192
let mut checker = TypeChecker :: new (
@@ -211,7 +206,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>(
211
206
212
207
if !errors_reported {
213
208
// if verifier failed, don't do further checks to avoid ICEs
214
- checker. typeck_mir ( mir, errors_buffer ) ;
209
+ checker. typeck_mir ( mir) ;
215
210
}
216
211
217
212
extra ( & mut checker)
@@ -964,7 +959,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
964
959
mir : & Mir < ' tcx > ,
965
960
term : & Terminator < ' tcx > ,
966
961
term_location : Location ,
967
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
968
962
) {
969
963
debug ! ( "check_terminator: {:?}" , term) ;
970
964
let tcx = self . tcx ( ) ;
@@ -1044,7 +1038,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1044
1038
& sig,
1045
1039
) ;
1046
1040
let sig = self . normalize ( sig, term_location) ;
1047
- self . check_call_dest ( mir, term, & sig, destination, term_location, errors_buffer ) ;
1041
+ self . check_call_dest ( mir, term, & sig, destination, term_location) ;
1048
1042
1049
1043
self . prove_predicates (
1050
1044
sig. inputs ( ) . iter ( ) . map ( |ty| ty:: Predicate :: WellFormed ( ty) ) ,
@@ -1118,7 +1112,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1118
1112
sig : & ty:: FnSig < ' tcx > ,
1119
1113
destination : & Option < ( Place < ' tcx > , BasicBlock ) > ,
1120
1114
term_location : Location ,
1121
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
1122
1115
) {
1123
1116
let tcx = self . tcx ( ) ;
1124
1117
match * destination {
@@ -1152,7 +1145,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1152
1145
// this check is done at `check_local`.
1153
1146
if self . tcx ( ) . features ( ) . unsized_locals {
1154
1147
let span = term. source_info . span ;
1155
- self . ensure_place_sized ( dest_ty, span, errors_buffer ) ;
1148
+ self . ensure_place_sized ( dest_ty, span) ;
1156
1149
}
1157
1150
}
1158
1151
None => {
@@ -1305,7 +1298,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1305
1298
mir : & Mir < ' tcx > ,
1306
1299
local : Local ,
1307
1300
local_decl : & LocalDecl < ' tcx > ,
1308
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
1309
1301
) {
1310
1302
match mir. local_kind ( local) {
1311
1303
LocalKind :: ReturnPointer | LocalKind :: Arg => {
@@ -1321,18 +1313,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1321
1313
}
1322
1314
1323
1315
// When `#![feature(unsized_locals)]` is enabled, only function calls
1324
- // are checked in `check_call_dest`.
1316
+ // and nullary ops are checked in `check_call_dest`.
1325
1317
if !self . tcx ( ) . features ( ) . unsized_locals {
1326
1318
let span = local_decl. source_info . span ;
1327
1319
let ty = local_decl. ty ;
1328
- self . ensure_place_sized ( ty, span, errors_buffer ) ;
1320
+ self . ensure_place_sized ( ty, span) ;
1329
1321
}
1330
1322
}
1331
1323
1332
- fn ensure_place_sized ( & mut self ,
1333
- ty : Ty < ' tcx > ,
1334
- span : Span ,
1335
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ) {
1324
+ fn ensure_place_sized ( & mut self , ty : Ty < ' tcx > , span : Span ) {
1336
1325
let tcx = self . tcx ( ) ;
1337
1326
1338
1327
// Erase the regions from `ty` to get a global type. The
@@ -1354,15 +1343,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1354
1343
cannot be statically determined",
1355
1344
ty
1356
1345
) ;
1357
- if let Some ( ref mut errors_buffer) = * errors_buffer {
1358
- diag. buffer ( errors_buffer) ;
1359
- } else {
1360
- // we're allowed to use emit() here because the
1361
- // NLL migration will be turned on (and thus
1362
- // errors will need to be buffered) *only if*
1363
- // errors_buffer is Some.
1364
- diag. emit ( ) ;
1365
- }
1346
+
1347
+ // While this is located in `nll::typeck` this error is not
1348
+ // an NLL error, it's a required check to prevent creation
1349
+ // of unsized rvalues in certain cases:
1350
+ // * operand of a box expression
1351
+ // * callee in a call expression
1352
+ diag. emit ( ) ;
1366
1353
}
1367
1354
}
1368
1355
}
@@ -1437,6 +1424,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1437
1424
} ,
1438
1425
1439
1426
Rvalue :: NullaryOp ( _, ty) => {
1427
+ // Even with unsized locals cannot box an unsized value.
1428
+ if self . tcx ( ) . features ( ) . unsized_locals {
1429
+ let span = mir. source_info ( location) . span ;
1430
+ self . ensure_place_sized ( ty, span) ;
1431
+ }
1432
+
1440
1433
let trait_ref = ty:: TraitRef {
1441
1434
def_id : tcx. lang_items ( ) . sized_trait ( ) . unwrap ( ) ,
1442
1435
substs : tcx. mk_substs_trait ( ty, & [ ] ) ,
@@ -1840,12 +1833,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1840
1833
} )
1841
1834
}
1842
1835
1843
- fn typeck_mir ( & mut self , mir : & Mir < ' tcx > , mut errors_buffer : Option < & mut Vec < Diagnostic > > ) {
1836
+ fn typeck_mir ( & mut self , mir : & Mir < ' tcx > ) {
1844
1837
self . last_span = mir. span ;
1845
1838
debug ! ( "run_on_mir: {:?}" , mir. span) ;
1846
1839
1847
1840
for ( local, local_decl) in mir. local_decls . iter_enumerated ( ) {
1848
- self . check_local ( mir, local, local_decl, & mut errors_buffer ) ;
1841
+ self . check_local ( mir, local, local_decl) ;
1849
1842
}
1850
1843
1851
1844
for ( block, block_data) in mir. basic_blocks ( ) . iter_enumerated ( ) {
@@ -1861,7 +1854,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1861
1854
location. statement_index += 1 ;
1862
1855
}
1863
1856
1864
- self . check_terminator ( mir, block_data. terminator ( ) , location, & mut errors_buffer ) ;
1857
+ self . check_terminator ( mir, block_data. terminator ( ) , location) ;
1865
1858
self . check_iscleanup ( mir, block_data) ;
1866
1859
}
1867
1860
}
@@ -1918,7 +1911,6 @@ impl MirPass for TypeckMir {
1918
1911
& [ ] ,
1919
1912
None ,
1920
1913
None ,
1921
- None ,
1922
1914
|_| ( ) ,
1923
1915
) ;
1924
1916
0 commit comments