@@ -36,7 +36,6 @@ use rustc::traits::query::type_op;
36
36
use rustc:: traits:: query:: { Fallible , NoSolution } ;
37
37
use rustc:: ty:: fold:: TypeFoldable ;
38
38
use rustc:: ty:: { self , CanonicalTy , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind } ;
39
- use rustc_errors:: Diagnostic ;
40
39
use std:: fmt;
41
40
use std:: rc:: Rc ;
42
41
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -103,8 +102,7 @@ mod relate_tys;
103
102
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
104
103
/// constraints for the regions in the types of variables
105
104
/// - `flow_inits` -- results of a maybe-init dataflow analysis
106
- /// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
107
- /// - `errors_buffer` -- errors are sent here for future reporting
105
+ /// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysiss
108
106
pub ( crate ) fn type_check < ' gcx , ' tcx > (
109
107
infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
110
108
param_env : ty:: ParamEnv < ' gcx > ,
@@ -117,7 +115,6 @@ pub(crate) fn type_check<'gcx, 'tcx>(
117
115
flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' _ , ' gcx , ' tcx > > ,
118
116
move_data : & MoveData < ' tcx > ,
119
117
elements : & Rc < RegionValueElements > ,
120
- errors_buffer : & mut Vec < Diagnostic > ,
121
118
) -> MirTypeckResults < ' tcx > {
122
119
let implicit_region_bound = infcx. tcx . mk_region ( ty:: ReVar ( universal_regions. fr_fn_body ) ) ;
123
120
let mut constraints = MirTypeckRegionConstraints {
@@ -157,7 +154,6 @@ pub(crate) fn type_check<'gcx, 'tcx>(
157
154
& region_bound_pairs,
158
155
Some ( implicit_region_bound) ,
159
156
Some ( & mut borrowck_context) ,
160
- Some ( errors_buffer) ,
161
157
|cx| {
162
158
cx. equate_inputs_and_outputs (
163
159
mir,
@@ -185,7 +181,6 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>(
185
181
region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
186
182
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
187
183
borrowck_context : Option < & ' a mut BorrowCheckContext < ' a , ' tcx > > ,
188
- errors_buffer : Option < & mut Vec < Diagnostic > > ,
189
184
mut extra : impl FnMut ( & mut TypeChecker < ' a , ' gcx , ' tcx > ) -> R ,
190
185
) -> R where {
191
186
let mut checker = TypeChecker :: new (
@@ -205,7 +200,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>(
205
200
206
201
if !errors_reported {
207
202
// if verifier failed, don't do further checks to avoid ICEs
208
- checker. typeck_mir ( mir, errors_buffer ) ;
203
+ checker. typeck_mir ( mir) ;
209
204
}
210
205
211
206
extra ( & mut checker)
@@ -989,7 +984,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
989
984
mir : & Mir < ' tcx > ,
990
985
term : & Terminator < ' tcx > ,
991
986
term_location : Location ,
992
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
993
987
) {
994
988
debug ! ( "check_terminator: {:?}" , term) ;
995
989
let tcx = self . tcx ( ) ;
@@ -1069,7 +1063,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1069
1063
& sig,
1070
1064
) ;
1071
1065
let sig = self . normalize ( sig, term_location) ;
1072
- self . check_call_dest ( mir, term, & sig, destination, term_location, errors_buffer ) ;
1066
+ self . check_call_dest ( mir, term, & sig, destination, term_location) ;
1073
1067
1074
1068
self . prove_predicates (
1075
1069
sig. inputs ( ) . iter ( ) . map ( |ty| ty:: Predicate :: WellFormed ( ty) ) ,
@@ -1143,7 +1137,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1143
1137
sig : & ty:: FnSig < ' tcx > ,
1144
1138
destination : & Option < ( Place < ' tcx > , BasicBlock ) > ,
1145
1139
term_location : Location ,
1146
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
1147
1140
) {
1148
1141
let tcx = self . tcx ( ) ;
1149
1142
match * destination {
@@ -1177,7 +1170,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1177
1170
// this check is done at `check_local`.
1178
1171
if self . tcx ( ) . features ( ) . unsized_locals {
1179
1172
let span = term. source_info . span ;
1180
- self . ensure_place_sized ( dest_ty, span, errors_buffer ) ;
1173
+ self . ensure_place_sized ( dest_ty, span) ;
1181
1174
}
1182
1175
}
1183
1176
None => {
@@ -1330,7 +1323,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1330
1323
mir : & Mir < ' tcx > ,
1331
1324
local : Local ,
1332
1325
local_decl : & LocalDecl < ' tcx > ,
1333
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ,
1334
1326
) {
1335
1327
match mir. local_kind ( local) {
1336
1328
LocalKind :: ReturnPointer | LocalKind :: Arg => {
@@ -1346,18 +1338,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1346
1338
}
1347
1339
1348
1340
// When `#![feature(unsized_locals)]` is enabled, only function calls
1349
- // are checked in `check_call_dest`.
1341
+ // and nullary ops are checked in `check_call_dest`.
1350
1342
if !self . tcx ( ) . features ( ) . unsized_locals {
1351
1343
let span = local_decl. source_info . span ;
1352
1344
let ty = local_decl. ty ;
1353
- self . ensure_place_sized ( ty, span, errors_buffer ) ;
1345
+ self . ensure_place_sized ( ty, span) ;
1354
1346
}
1355
1347
}
1356
1348
1357
- fn ensure_place_sized ( & mut self ,
1358
- ty : Ty < ' tcx > ,
1359
- span : Span ,
1360
- errors_buffer : & mut Option < & mut Vec < Diagnostic > > ) {
1349
+ fn ensure_place_sized ( & mut self , ty : Ty < ' tcx > , span : Span ) {
1361
1350
let tcx = self . tcx ( ) ;
1362
1351
1363
1352
// Erase the regions from `ty` to get a global type. The
@@ -1379,15 +1368,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1379
1368
cannot be statically determined",
1380
1369
ty
1381
1370
) ;
1382
- if let Some ( ref mut errors_buffer) = * errors_buffer {
1383
- diag. buffer ( errors_buffer) ;
1384
- } else {
1385
- // we're allowed to use emit() here because the
1386
- // NLL migration will be turned on (and thus
1387
- // errors will need to be buffered) *only if*
1388
- // errors_buffer is Some.
1389
- diag. emit ( ) ;
1390
- }
1371
+
1372
+ // While this is located in `nll::typeck` this error is not
1373
+ // an NLL error, it's a required check to prevent creation
1374
+ // of unsized rvalues in certain cases:
1375
+ // * operand of a box expression
1376
+ // * callee in a call expression
1377
+ diag. emit ( ) ;
1391
1378
}
1392
1379
}
1393
1380
}
@@ -1462,6 +1449,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1462
1449
} ,
1463
1450
1464
1451
Rvalue :: NullaryOp ( _, ty) => {
1452
+ // Even with unsized locals cannot box an unsized value.
1453
+ if self . tcx ( ) . features ( ) . unsized_locals {
1454
+ let span = mir. source_info ( location) . span ;
1455
+ self . ensure_place_sized ( ty, span) ;
1456
+ }
1457
+
1465
1458
let trait_ref = ty:: TraitRef {
1466
1459
def_id : tcx. lang_items ( ) . sized_trait ( ) . unwrap ( ) ,
1467
1460
substs : tcx. mk_substs_trait ( ty, & [ ] ) ,
@@ -1895,12 +1888,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1895
1888
} )
1896
1889
}
1897
1890
1898
- fn typeck_mir ( & mut self , mir : & Mir < ' tcx > , mut errors_buffer : Option < & mut Vec < Diagnostic > > ) {
1891
+ fn typeck_mir ( & mut self , mir : & Mir < ' tcx > ) {
1899
1892
self . last_span = mir. span ;
1900
1893
debug ! ( "run_on_mir: {:?}" , mir. span) ;
1901
1894
1902
1895
for ( local, local_decl) in mir. local_decls . iter_enumerated ( ) {
1903
- self . check_local ( mir, local, local_decl, & mut errors_buffer ) ;
1896
+ self . check_local ( mir, local, local_decl) ;
1904
1897
}
1905
1898
1906
1899
for ( block, block_data) in mir. basic_blocks ( ) . iter_enumerated ( ) {
@@ -1916,7 +1909,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1916
1909
location. statement_index += 1 ;
1917
1910
}
1918
1911
1919
- self . check_terminator ( mir, block_data. terminator ( ) , location, & mut errors_buffer ) ;
1912
+ self . check_terminator ( mir, block_data. terminator ( ) , location) ;
1920
1913
self . check_iscleanup ( mir, block_data) ;
1921
1914
}
1922
1915
}
@@ -1973,7 +1966,6 @@ impl MirPass for TypeckMir {
1973
1966
& [ ] ,
1974
1967
None ,
1975
1968
None ,
1976
- None ,
1977
1969
|_| ( ) ,
1978
1970
) ;
1979
1971
0 commit comments