@@ -44,6 +44,9 @@ use syntax::ast;
44
44
use syntax:: ptr:: P ;
45
45
use syntax:: parse:: token;
46
46
47
+ use rustc:: session:: Session ;
48
+ use syntax:: codemap:: Span ;
49
+
47
50
use std:: cmp:: Ordering ;
48
51
49
52
pub fn get_simple_intrinsic ( ccx : & CrateContext , item : & hir:: ForeignItem ) -> Option < ValueRef > {
@@ -99,6 +102,10 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Opti
99
102
Some ( ccx. get_intrinsic ( & name) )
100
103
}
101
104
105
+ pub fn span_transmute_size_error ( a : & Session , b : Span , msg : & str ) {
106
+ span_err ! ( a, b, E0512 , "{}" , msg) ;
107
+ }
108
+
102
109
/// Performs late verification that intrinsics are used correctly. At present,
103
110
/// the only intrinsic that needs such verification is `transmute`.
104
111
pub fn check_intrinsics ( ccx : & CrateContext ) {
@@ -127,8 +134,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
127
134
last_failing_id = Some ( transmute_restriction. id ) ;
128
135
129
136
if transmute_restriction. original_from != transmute_restriction. substituted_from {
130
- ccx. sess ( ) . span_err (
131
- transmute_restriction. span ,
137
+ span_transmute_size_error ( ccx. sess ( ) , transmute_restriction. span ,
132
138
& format ! ( "transmute called on types with potentially different sizes: \
133
139
{} (could be {} bit{}) to {} (could be {} bit{})",
134
140
transmute_restriction. original_from,
@@ -138,8 +144,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
138
144
to_type_size as usize ,
139
145
if to_type_size == 1 { "" } else { "s" } ) ) ;
140
146
} else {
141
- ccx. sess ( ) . span_err (
142
- transmute_restriction. span ,
147
+ span_transmute_size_error ( ccx. sess ( ) , transmute_restriction. span ,
143
148
& format ! ( "transmute called on types with different sizes: \
144
149
{} ({} bit{}) to {} ({} bit{})",
145
150
transmute_restriction. original_from,
@@ -798,9 +803,9 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
798
803
799
804
( _, "return_address" ) => {
800
805
if !fcx. caller_expects_out_pointer {
801
- tcx. sess . span_err ( call_info. span ,
802
- "invalid use of `return_address` intrinsic: function \
803
- does not use out pointer") ;
806
+ span_err ! ( tcx. sess, call_info. span, E0510 ,
807
+ "invalid use of `return_address` intrinsic: function \
808
+ does not use out pointer") ;
804
809
C_null ( Type :: i8p ( ccx) )
805
810
} else {
806
811
PointerCast ( bcx, llvm:: get_param ( fcx. llfn , 0 ) , Type :: i8p ( ccx) )
@@ -1439,6 +1444,10 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
1439
1444
return rust_try
1440
1445
}
1441
1446
1447
+ fn span_invalid_monomorphization_error ( a : & Session , b : Span , c : & str ) {
1448
+ span_err ! ( a, b, E0511 , "{}" , c) ;
1449
+ }
1450
+
1442
1451
fn generic_simd_intrinsic < ' blk , ' tcx , ' a >
1443
1452
( bcx : Block < ' blk , ' tcx > ,
1444
1453
name : & str ,
@@ -1457,10 +1466,11 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
1457
1466
emit_error!( $msg, )
1458
1467
} ;
1459
1468
( $msg: tt, $( $fmt: tt) * ) => {
1460
- bcx. sess( ) . span_err( call_info. span,
1461
- & format!( concat!( "invalid monomorphization of `{}` intrinsic: " ,
1462
- $msg) ,
1463
- name, $( $fmt) * ) ) ;
1469
+ span_invalid_monomorphization_error(
1470
+ bcx. sess( ) , call_info. span,
1471
+ & format!( concat!( "invalid monomorphization of `{}` intrinsic: " ,
1472
+ $msg) ,
1473
+ name, $( $fmt) * ) ) ;
1464
1474
}
1465
1475
}
1466
1476
macro_rules! require {
0 commit comments