Skip to content

Commit

Permalink
rustc_apfloat: make the crate #![no_std] explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 28, 2019
1 parent bbd48e6 commit 0006216
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
16 changes: 8 additions & 8 deletions src/librustc_apfloat/ieee.rs
@@ -1,13 +1,13 @@
use crate::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
use crate::{Float, FloatConvert, ParseError, Round, Status, StatusAnd};

use core::cmp::{self, Ordering};
use core::convert::TryFrom;
use core::fmt::{self, Write};
use core::marker::PhantomData;
use core::mem;
use core::ops::Neg;
use smallvec::{SmallVec, smallvec};
use std::cmp::{self, Ordering};
use std::convert::TryFrom;
use std::fmt::{self, Write};
use std::marker::PhantomData;
use std::mem;
use std::ops::Neg;

#[must_use]
pub struct IeeeFloat<S> {
Expand Down Expand Up @@ -2287,8 +2287,8 @@ impl Loss {
/// Implementation details of IeeeFloat significands, such as big integer arithmetic.
/// As a rule of thumb, no functions in this module should dynamically allocate.
mod sig {
use std::cmp::Ordering;
use std::mem;
use core::cmp::Ordering;
use core::mem;
use super::{ExpInt, Limb, LIMB_BITS, limbs_for_bits, Loss};

pub(super) fn is_all_zeros(limbs: &[Limb]) -> bool {
Expand Down
36 changes: 20 additions & 16 deletions src/librustc_apfloat/lib.rs
Expand Up @@ -31,15 +31,19 @@
//! This API is completely unstable and subject to change.

#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![no_std]
#![forbid(unsafe_code)]

#![feature(nll)]

use std::cmp::Ordering;
use std::fmt;
use std::ops::{Neg, Add, Sub, Mul, Div, Rem};
use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
use std::str::FromStr;
#[macro_use]
extern crate alloc;

use core::cmp::Ordering;
use core::fmt;
use core::ops::{Neg, Add, Sub, Mul, Div, Rem};
use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
use core::str::FromStr;

bitflags::bitflags! {
/// IEEE-754R 7: Default exception handling.
Expand Down Expand Up @@ -587,7 +591,7 @@ macro_rules! float_common_impls {
}
}

impl<$t> ::std::str::FromStr for $ty<$t> where Self: Float {
impl<$t> ::core::str::FromStr for $ty<$t> where Self: Float {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, ParseError> {
Self::from_str_r(s, Round::NearestTiesToEven).map(|x| x.value)
Expand All @@ -596,66 +600,66 @@ macro_rules! float_common_impls {

// Rounding ties to the nearest even, by default.

impl<$t> ::std::ops::Add for $ty<$t> where Self: Float {
impl<$t> ::core::ops::Add for $ty<$t> where Self: Float {
type Output = StatusAnd<Self>;
fn add(self, rhs: Self) -> StatusAnd<Self> {
self.add_r(rhs, Round::NearestTiesToEven)
}
}

impl<$t> ::std::ops::Sub for $ty<$t> where Self: Float {
impl<$t> ::core::ops::Sub for $ty<$t> where Self: Float {
type Output = StatusAnd<Self>;
fn sub(self, rhs: Self) -> StatusAnd<Self> {
self.sub_r(rhs, Round::NearestTiesToEven)
}
}

impl<$t> ::std::ops::Mul for $ty<$t> where Self: Float {
impl<$t> ::core::ops::Mul for $ty<$t> where Self: Float {
type Output = StatusAnd<Self>;
fn mul(self, rhs: Self) -> StatusAnd<Self> {
self.mul_r(rhs, Round::NearestTiesToEven)
}
}

impl<$t> ::std::ops::Div for $ty<$t> where Self: Float {
impl<$t> ::core::ops::Div for $ty<$t> where Self: Float {
type Output = StatusAnd<Self>;
fn div(self, rhs: Self) -> StatusAnd<Self> {
self.div_r(rhs, Round::NearestTiesToEven)
}
}

impl<$t> ::std::ops::Rem for $ty<$t> where Self: Float {
impl<$t> ::core::ops::Rem for $ty<$t> where Self: Float {
type Output = StatusAnd<Self>;
fn rem(self, rhs: Self) -> StatusAnd<Self> {
self.c_fmod(rhs)
}
}

impl<$t> ::std::ops::AddAssign for $ty<$t> where Self: Float {
impl<$t> ::core::ops::AddAssign for $ty<$t> where Self: Float {
fn add_assign(&mut self, rhs: Self) {
*self = (*self + rhs).value;
}
}

impl<$t> ::std::ops::SubAssign for $ty<$t> where Self: Float {
impl<$t> ::core::ops::SubAssign for $ty<$t> where Self: Float {
fn sub_assign(&mut self, rhs: Self) {
*self = (*self - rhs).value;
}
}

impl<$t> ::std::ops::MulAssign for $ty<$t> where Self: Float {
impl<$t> ::core::ops::MulAssign for $ty<$t> where Self: Float {
fn mul_assign(&mut self, rhs: Self) {
*self = (*self * rhs).value;
}
}

impl<$t> ::std::ops::DivAssign for $ty<$t> where Self: Float {
impl<$t> ::core::ops::DivAssign for $ty<$t> where Self: Float {
fn div_assign(&mut self, rhs: Self) {
*self = (*self / rhs).value;
}
}

impl<$t> ::std::ops::RemAssign for $ty<$t> where Self: Float {
impl<$t> ::core::ops::RemAssign for $ty<$t> where Self: Float {
fn rem_assign(&mut self, rhs: Self) {
*self = (*self % rhs).value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_apfloat/ppc.rs
@@ -1,9 +1,9 @@
use crate::{Category, ExpInt, Float, FloatConvert, Round, ParseError, Status, StatusAnd};
use crate::ieee;

use std::cmp::Ordering;
use std::fmt;
use std::ops::Neg;
use core::cmp::Ordering;
use core::fmt;
use core::ops::Neg;

#[must_use]
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
Expand Down

0 comments on commit 0006216

Please sign in to comment.