@@ -209,6 +209,8 @@ use syntax::ptr::P;
209209
210210use self :: ty:: { LifetimeBounds , Path , Ptr , PtrTy , Self_ , Ty } ;
211211
212+ use deriving;
213+
212214pub mod ty;
213215
214216pub struct TraitDef < ' a > {
@@ -381,22 +383,6 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec<P<ast
381383 visitor. types
382384}
383385
384- /// Replacement for expr_unreachable which generates intrinsics::unreachable()
385- /// instead of unreachable!()
386- fn expr_unreachable_intrinsic ( cx : & ExtCtxt , sp : Span ) -> P < Expr > {
387- let path = cx. std_path ( & [ "intrinsics" , "unreachable" ] ) ;
388- let call = cx. expr_call_global (
389- sp, path, vec ! [ ] ) ;
390- let unreachable = cx. expr_block ( P ( ast:: Block {
391- stmts : vec ! [ ] ,
392- expr : Some ( call) ,
393- id : ast:: DUMMY_NODE_ID ,
394- rules : ast:: BlockCheckMode :: Unsafe ( ast:: CompilerGenerated ) ,
395- span : sp } ) ) ;
396-
397- unreachable
398- }
399-
400386impl < ' a > TraitDef < ' a > {
401387 pub fn expand ( & self ,
402388 cx : & mut ExtCtxt ,
@@ -1279,15 +1265,11 @@ impl<'a> MethodDef<'a> {
12791265
12801266 let mut first_ident = None ;
12811267 for ( & ident, self_arg) in vi_idents. iter ( ) . zip ( & self_args) {
1282- let path = cx. std_path ( & [ "intrinsics" , "discriminant_value" ] ) ;
1283- let call = cx. expr_call_global (
1284- sp, path, vec ! [ cx. expr_addr_of( sp, self_arg. clone( ) ) ] ) ;
1285- let variant_value = cx. expr_block ( P ( ast:: Block {
1286- stmts : vec ! [ ] ,
1287- expr : Some ( call) ,
1288- id : ast:: DUMMY_NODE_ID ,
1289- rules : ast:: BlockCheckMode :: Unsafe ( ast:: CompilerGenerated ) ,
1290- span : sp } ) ) ;
1268+ let self_addr = cx. expr_addr_of ( sp, self_arg. clone ( ) ) ;
1269+ let variant_value = deriving:: call_intrinsic ( cx,
1270+ sp,
1271+ "discriminant_value" ,
1272+ vec ! [ self_addr] ) ;
12911273
12921274 let target_ty = cx. ty_ident ( sp, cx. ident_of ( target_type_name) ) ;
12931275 let variant_disr = cx. expr_cast ( sp, variant_value, target_ty) ;
@@ -1315,7 +1297,9 @@ impl<'a> MethodDef<'a> {
13151297 //Since we know that all the arguments will match if we reach the match expression we
13161298 //add the unreachable intrinsics as the result of the catch all which should help llvm
13171299 //in optimizing it
1318- match_arms. push ( cx. arm ( sp, vec ! [ cx. pat_wild( sp) ] , expr_unreachable_intrinsic ( cx, sp) ) ) ;
1300+ match_arms. push ( cx. arm ( sp,
1301+ vec ! [ cx. pat_wild( sp) ] ,
1302+ deriving:: call_intrinsic ( cx, sp, "unreachable" , vec ! [ ] ) ) ) ;
13191303
13201304 // Final wrinkle: the self_args are expressions that deref
13211305 // down to desired l-values, but we cannot actually deref
@@ -1391,7 +1375,7 @@ impl<'a> MethodDef<'a> {
13911375 // derive Debug on such a type could here generate code
13921376 // that needs the feature gate enabled.)
13931377
1394- expr_unreachable_intrinsic ( cx, sp)
1378+ deriving :: call_intrinsic ( cx, sp, "unreachable" , vec ! [ ] )
13951379 }
13961380 else {
13971381
0 commit comments