diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 2ae998841d928..a5b313e2dd67e 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -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! ``` "##, diff --git a/src/librustc_trans/diagnostics.rs b/src/librustc_trans/diagnostics.rs new file mode 100644 index 0000000000000..dd7c3834e564a --- /dev/null +++ b/src/librustc_trans/diagnostics.rs @@ -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 or the MIT license +// , 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... +} diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index a7fb3af138453..049d8fbe390a4 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -80,6 +80,8 @@ pub mod back { pub mod msvc; } +pub mod diagnostics; + pub mod trans; pub mod save; diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index bcfd44d8835d7..b43a4b3fc889d 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -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 { @@ -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 {