Closed
Description
The following file, when compiled without optimizations, correctly generates an overflow check in add_one
:
#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]
#![crate_type="lib"]
#[lang="sized"]
trait Sized {}
#[lang="add"]
trait Add<RHS=Self> {
type Output;
fn add(self, rhs: RHS) -> Self::Output;
}
impl Add for i32 {
type Output = i32;
#[inline]
#[rustc_inherit_overflow_checks]
fn add(self, other: i32) -> i32 { self + other }
}
#[cold] #[inline(never)] // this is the slow path, always
#[lang = "panic"]
pub fn panic(_expr_file_line: &(&'static str, &'static str, u32)) -> ! {
loop {}
}
#[lang="copy"]
trait Copy {}
pub fn add_one(x: i32) -> i32 {
x + 1
}
However, compiling with optimizations plus -C debug-assertions=on
or -Z force-overflow-checks=on
generates code without the overflow check.
However, if I move add_one
to a separate no_core crate like this, the issue disappears and the overflow check is generated:
#![feature(no_core)]
#![no_core]
#![crate_type="lib"]
extern crate minimal;
pub fn add_one(x: i32) -> i32 {
x + 1
}
Metadata
Metadata
Assignees
Labels
No labels