@@ -381,6 +381,22 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec<P<ast
381
381
visitor. types
382
382
}
383
383
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
+
384
400
impl < ' a > TraitDef < ' a > {
385
401
pub fn expand ( & self ,
386
402
cx : & mut ExtCtxt ,
@@ -1297,16 +1313,7 @@ impl<'a> MethodDef<'a> {
1297
1313
//Since we know that all the arguments will match if we reach the match expression we
1298
1314
//add the unreachable intrinsics as the result of the catch all which should help llvm
1299
1315
//in optimizing it
1300
- let path = cx. std_path ( & [ "intrinsics" , "unreachable" ] ) ;
1301
- let call = cx. expr_call_global (
1302
- sp, path, vec ! [ ] ) ;
1303
- let unreachable = cx. expr_block ( P ( ast:: Block {
1304
- stmts : vec ! [ ] ,
1305
- expr : Some ( call) ,
1306
- id : ast:: DUMMY_NODE_ID ,
1307
- rules : ast:: BlockCheckMode :: Unsafe ( ast:: CompilerGenerated ) ,
1308
- span : sp } ) ) ;
1309
- match_arms. push ( cx. arm ( sp, vec ! [ cx. pat_wild( sp) ] , unreachable) ) ;
1316
+ match_arms. push ( cx. arm ( sp, vec ! [ cx. pat_wild( sp) ] , expr_unreachable_intrinsic ( cx, sp) ) ) ;
1310
1317
1311
1318
// Final wrinkle: the self_args are expressions that deref
1312
1319
// down to desired l-values, but we cannot actually deref
@@ -1382,7 +1389,7 @@ impl<'a> MethodDef<'a> {
1382
1389
// derive Debug on such a type could here generate code
1383
1390
// that needs the feature gate enabled.)
1384
1391
1385
- cx . expr_unreachable ( sp)
1392
+ expr_unreachable_intrinsic ( cx , sp)
1386
1393
}
1387
1394
else {
1388
1395
0 commit comments