@@ -195,51 +195,39 @@ pub enum deref_kind {
195
195
// Categorizes a derefable type. Note that we include vectors and strings as
196
196
// derefable (we model an index as the combination of a deref and then a
197
197
// pointer adjustment).
198
- pub fn opt_deref_kind ( t : Ty ) -> Option < deref_kind > {
198
+ pub fn deref_kind ( t : Ty ) -> McResult < deref_kind > {
199
199
match t. sty {
200
200
ty:: ty_uniq( _) |
201
201
ty:: ty_closure( box ty:: ClosureTy { store : ty:: UniqTraitStore , ..} ) => {
202
- Some ( deref_ptr ( Unique ) )
202
+ Ok ( deref_ptr ( Unique ) )
203
203
}
204
204
205
205
ty:: ty_rptr( r, mt) => {
206
206
let kind = ty:: BorrowKind :: from_mutbl ( mt. mutbl ) ;
207
- Some ( deref_ptr ( BorrowedPtr ( kind, * r) ) )
207
+ Ok ( deref_ptr ( BorrowedPtr ( kind, * r) ) )
208
208
}
209
209
210
210
ty:: ty_closure( box ty:: ClosureTy {
211
211
store : ty:: RegionTraitStore ( r, _) ,
212
212
..
213
213
} ) => {
214
- Some ( deref_ptr ( BorrowedPtr ( ty:: ImmBorrow , r) ) )
214
+ Ok ( deref_ptr ( BorrowedPtr ( ty:: ImmBorrow , r) ) )
215
215
}
216
216
217
217
ty:: ty_ptr( ref mt) => {
218
- Some ( deref_ptr ( UnsafePtr ( mt. mutbl ) ) )
218
+ Ok ( deref_ptr ( UnsafePtr ( mt. mutbl ) ) )
219
219
}
220
220
221
221
ty:: ty_enum( ..) |
222
222
ty:: ty_struct( ..) => { // newtype
223
- Some ( deref_interior ( InteriorField ( PositionalField ( 0 ) ) ) )
223
+ Ok ( deref_interior ( InteriorField ( PositionalField ( 0 ) ) ) )
224
224
}
225
225
226
226
ty:: ty_vec( _, _) | ty:: ty_str => {
227
- Some ( deref_interior ( InteriorElement ( element_kind ( t) ) ) )
227
+ Ok ( deref_interior ( InteriorElement ( element_kind ( t) ) ) )
228
228
}
229
229
230
- _ => None
231
- }
232
- }
233
-
234
- pub fn deref_kind < ' tcx > ( tcx : & ty:: ctxt < ' tcx > , t : Ty < ' tcx > ) -> deref_kind {
235
- debug ! ( "deref_kind {}" , ty_to_string( tcx, t) ) ;
236
- match opt_deref_kind ( t) {
237
- Some ( k) => k,
238
- None => {
239
- tcx. sess . bug (
240
- format ! ( "deref_kind() invoked on non-derefable type {}" ,
241
- ty_to_string( tcx, t) ) [ ] ) ;
242
- }
230
+ _ => Err ( ( ) ) ,
243
231
}
244
232
}
245
233
@@ -403,7 +391,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
403
391
404
392
fn pat_ty ( & self , pat : & ast:: Pat ) -> McResult < Ty < ' tcx > > {
405
393
let tcx = self . typer . tcx ( ) ;
406
- let base_ty = self . typer . node_ty ( pat. id ) ;
394
+ let base_ty = try! ( self . typer . node_ty ( pat. id ) ) ;
407
395
// FIXME (Issue #18207): This code detects whether we are
408
396
// looking at a `ref x`, and if so, figures out what the type
409
397
// *being borrowed* is. But ideally we would put in a more
@@ -413,15 +401,16 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
413
401
// a bind-by-ref means that the base_ty will be the type of the ident itself,
414
402
// but what we want here is the type of the underlying value being borrowed.
415
403
// So peel off one-level, turning the &T into T.
416
- ty:: deref ( base_ty, false ) . unwrap_or_else ( || {
417
- panic ! ( "encountered BindByRef with non &-type" ) ;
418
- } ) . ty
404
+ match ty:: deref ( base_ty, false ) {
405
+ Some ( t) => t. ty ,
406
+ None => { return Err ( ( ) ) ; }
407
+ }
419
408
}
420
409
_ => base_ty,
421
410
} ;
422
411
debug ! ( "pat_ty(pat={}) base_ty={} ret_ty={}" ,
423
412
pat. repr( tcx) , base_ty. repr( tcx) , ret_ty. repr( tcx) ) ;
424
- ret_ty
413
+ Ok ( ret_ty)
425
414
}
426
415
427
416
pub fn cat_expr ( & self , expr : & ast:: Expr ) -> McResult < cmt < ' tcx > > {
@@ -909,13 +898,13 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
909
898
}
910
899
None => base_cmt
911
900
} ;
912
- match ty:: deref ( base_cmt. ty , true ) {
901
+ let base_cmt_ty = base_cmt. ty ;
902
+ match ty:: deref ( base_cmt_ty, true ) {
913
903
Some ( mt) => self . cat_deref_common ( node, base_cmt, deref_cnt, mt. ty , implicit) ,
914
904
None => {
915
- self . tcx ( ) . sess . span_bug (
916
- node. span ( ) ,
917
- format ! ( "Explicit deref of non-derefable type: {}" ,
918
- base_cmt. ty. repr( self . tcx( ) ) ) [ ] ) ;
905
+ debug ! ( "Explicit deref of non-derefable type: {}" ,
906
+ base_cmt_ty. repr( self . tcx( ) ) ) ;
907
+ return Err ( ( ) ) ;
919
908
}
920
909
}
921
910
}
@@ -992,17 +981,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
992
981
match ty:: array_element_ty ( self . tcx ( ) , base_cmt. ty ) {
993
982
Some ( ty) => ty,
994
983
None => {
995
- self . tcx ( ) . sess . span_bug (
996
- elt. span ( ) ,
997
- format ! ( "Explicit index of non-index type `{}`" ,
998
- base_cmt. ty. repr( self . tcx( ) ) ) [ ] ) ;
984
+ return Err ( ( ) ) ;
999
985
}
1000
986
}
1001
987
}
1002
988
} ;
1003
989
1004
990
let m = base_cmt. mutbl . inherit ( ) ;
1005
- return interior ( elt, base_cmt. clone ( ) , base_cmt. ty , m, element_ty) ;
991
+ return Ok ( interior ( elt, base_cmt. clone ( ) , base_cmt. ty , m, element_ty) ) ;
1006
992
1007
993
fn interior < ' tcx , N : ast_node > ( elt : & N ,
1008
994
of_cmt : cmt < ' tcx > ,
0 commit comments