Skip to content

Commit 1adcfb8

Browse files
Add librustc_trans error codes
1 parent 7badafa commit 1adcfb8

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

src/librustc_borrowck/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ let mut x = &mut i; // ok!
289289
let mut i = 0;
290290
let a = &i; // ok!
291291
let b = &i; // still ok!
292-
let c = &i; // super still ok!
292+
let c = &i; // still ok!
293293
```
294294
"##,
295295

src/librustc_trans/diagnostics.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(non_snake_case)]
12+
13+
register_long_diagnostics! {
14+
15+
}
16+
17+
register_diagnostics! {
18+
E0510, // invalid use of `return_address` intrinsic: function does not use out pointer
19+
E0511, // invalid monomorphization of `{}` intrinsic
20+
E0512, // transmute called on types with potentially different sizes...
21+
}

src/librustc_trans/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub mod back {
8080
pub mod msvc;
8181
}
8282

83+
pub mod diagnostics;
84+
8385
pub mod trans;
8486
pub mod save;
8587

src/librustc_trans/trans/intrinsic.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ use syntax::ast;
4444
use syntax::ptr::P;
4545
use syntax::parse::token;
4646

47+
use rustc::session::Session;
48+
use syntax::codemap::Span;
49+
4750
use std::cmp::Ordering;
4851

4952
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
99102
Some(ccx.get_intrinsic(&name))
100103
}
101104

105+
pub fn span_transmute_size_error(a: &Session, b: Span, msg: &str) {
106+
span_err!(a, b, E0512, "{}", msg);
107+
}
108+
102109
/// Performs late verification that intrinsics are used correctly. At present,
103110
/// the only intrinsic that needs such verification is `transmute`.
104111
pub fn check_intrinsics(ccx: &CrateContext) {
@@ -127,8 +134,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
127134
last_failing_id = Some(transmute_restriction.id);
128135

129136
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,
132138
&format!("transmute called on types with potentially different sizes: \
133139
{} (could be {} bit{}) to {} (could be {} bit{})",
134140
transmute_restriction.original_from,
@@ -138,8 +144,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
138144
to_type_size as usize,
139145
if to_type_size == 1 {""} else {"s"}));
140146
} else {
141-
ccx.sess().span_err(
142-
transmute_restriction.span,
147+
span_transmute_size_error(ccx.sess(), transmute_restriction.span,
143148
&format!("transmute called on types with different sizes: \
144149
{} ({} bit{}) to {} ({} bit{})",
145150
transmute_restriction.original_from,
@@ -798,9 +803,9 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
798803

799804
(_, "return_address") => {
800805
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");
804809
C_null(Type::i8p(ccx))
805810
} else {
806811
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>,
14391444
return rust_try
14401445
}
14411446

1447+
fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) {
1448+
span_err!(a, b, E0511, "{}", c);
1449+
}
1450+
14421451
fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14431452
(bcx: Block<'blk, 'tcx>,
14441453
name: &str,
@@ -1457,10 +1466,11 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14571466
emit_error!($msg, )
14581467
};
14591468
($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)*));
14641474
}
14651475
}
14661476
macro_rules! require {

0 commit comments

Comments
 (0)