Add librustc_trans error codes
This commit is contained in:
parent
7badafa593
commit
1adcfb8c13
@ -289,7 +289,7 @@ let mut x = &mut i; // ok!
|
||||
let mut i = 0;
|
||||
let a = &i; // ok!
|
||||
let b = &i; // still ok!
|
||||
let c = &i; // super still ok!
|
||||
let c = &i; // still ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
|
21
src/librustc_trans/diagnostics.rs
Normal file
21
src/librustc_trans/diagnostics.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
register_long_diagnostics! {
|
||||
|
||||
}
|
||||
|
||||
register_diagnostics! {
|
||||
E0510, // invalid use of `return_address` intrinsic: function does not use out pointer
|
||||
E0511, // invalid monomorphization of `{}` intrinsic
|
||||
E0512, // transmute called on types with potentially different sizes...
|
||||
}
|
@ -80,6 +80,8 @@ pub mod back {
|
||||
pub mod msvc;
|
||||
}
|
||||
|
||||
pub mod diagnostics;
|
||||
|
||||
pub mod trans;
|
||||
pub mod save;
|
||||
|
||||
|
@ -44,6 +44,9 @@ use syntax::ast;
|
||||
use syntax::ptr::P;
|
||||
use syntax::parse::token;
|
||||
|
||||
use rustc::session::Session;
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
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
|
||||
Some(ccx.get_intrinsic(&name))
|
||||
}
|
||||
|
||||
pub fn span_transmute_size_error(a: &Session, b: Span, msg: &str) {
|
||||
span_err!(a, b, E0512, "{}", msg);
|
||||
}
|
||||
|
||||
/// Performs late verification that intrinsics are used correctly. At present,
|
||||
/// the only intrinsic that needs such verification is `transmute`.
|
||||
pub fn check_intrinsics(ccx: &CrateContext) {
|
||||
@ -127,8 +134,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
|
||||
last_failing_id = Some(transmute_restriction.id);
|
||||
|
||||
if transmute_restriction.original_from != transmute_restriction.substituted_from {
|
||||
ccx.sess().span_err(
|
||||
transmute_restriction.span,
|
||||
span_transmute_size_error(ccx.sess(), transmute_restriction.span,
|
||||
&format!("transmute called on types with potentially different sizes: \
|
||||
{} (could be {} bit{}) to {} (could be {} bit{})",
|
||||
transmute_restriction.original_from,
|
||||
@ -138,8 +144,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
|
||||
to_type_size as usize,
|
||||
if to_type_size == 1 {""} else {"s"}));
|
||||
} else {
|
||||
ccx.sess().span_err(
|
||||
transmute_restriction.span,
|
||||
span_transmute_size_error(ccx.sess(), transmute_restriction.span,
|
||||
&format!("transmute called on types with different sizes: \
|
||||
{} ({} bit{}) to {} ({} bit{})",
|
||||
transmute_restriction.original_from,
|
||||
@ -798,9 +803,9 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
|
||||
(_, "return_address") => {
|
||||
if !fcx.caller_expects_out_pointer {
|
||||
tcx.sess.span_err(call_info.span,
|
||||
"invalid use of `return_address` intrinsic: function \
|
||||
does not use out pointer");
|
||||
span_err!(tcx.sess, call_info.span, E0510,
|
||||
"invalid use of `return_address` intrinsic: function \
|
||||
does not use out pointer");
|
||||
C_null(Type::i8p(ccx))
|
||||
} else {
|
||||
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>,
|
||||
return rust_try
|
||||
}
|
||||
|
||||
fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) {
|
||||
span_err!(a, b, E0511, "{}", c);
|
||||
}
|
||||
|
||||
fn generic_simd_intrinsic<'blk, 'tcx, 'a>
|
||||
(bcx: Block<'blk, 'tcx>,
|
||||
name: &str,
|
||||
@ -1457,10 +1466,11 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
|
||||
emit_error!($msg, )
|
||||
};
|
||||
($msg: tt, $($fmt: tt)*) => {
|
||||
bcx.sess().span_err(call_info.span,
|
||||
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
|
||||
$msg),
|
||||
name, $($fmt)*));
|
||||
span_invalid_monomorphization_error(
|
||||
bcx.sess(), call_info.span,
|
||||
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
|
||||
$msg),
|
||||
name, $($fmt)*));
|
||||
}
|
||||
}
|
||||
macro_rules! require {
|
||||
|
Loading…
x
Reference in New Issue
Block a user