Skip to content

Commit

Permalink
Fix use of no_std after rust-lang/RFC-1184
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jan 3, 2016
1 parent 0b71ed1 commit 9e4c0a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/no_std.rs
Expand Up @@ -4,7 +4,7 @@
// cfg-gating is a workaround for Cargo until https://github.com/rust-lang/cargo/issues/1570 lands.
// Do not include it if you copy any code.

#![cfg_attr(feature = "no_std", feature(lang_items, start, core, alloc, no_std))]
#![cfg_attr(feature = "no_std", feature(lang_items, start, alloc, no_std))]
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(not(feature = "no_std"))]
Expand All @@ -14,12 +14,11 @@ fn main() { }
#[macro_use]
extern crate mopa;

#[cfg(feature = "no_std")]
extern crate core;
#[cfg(feature = "no_std")]
extern crate alloc;

#[cfg(feature = "no_std")]
#[allow(dead_code)]
mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {
trait Panic { fn panic(&self) { } }

Expand All @@ -43,5 +42,6 @@ mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "eh_unwind_resume"] extern fn eh_unwind_resume() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
}
7 changes: 4 additions & 3 deletions examples/no_std_or_alloc.rs
Expand Up @@ -5,7 +5,7 @@
// Do not include it if you copy any code.


#![cfg_attr(feature = "no_std", feature(lang_items, start, core, libc, no_std))]
#![cfg_attr(feature = "no_std", feature(lang_items, start, libc, no_std))]
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(not(feature = "no_std"))]
Expand All @@ -15,17 +15,17 @@ fn main() { }
#[macro_use]
extern crate mopa;

#[cfg(feature = "no_std")]
extern crate core;
#[cfg(feature = "no_std")]
extern crate libc;

#[cfg(feature = "no_std")]
#[allow(dead_code)]
mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {
trait Panic { fn panic(&self) { } }

trait PanicAny: Panic + ::mopa::Any { }

#[allow(dead_code)]
mopafy!(PanicAny, core = core);

impl Panic for i32 { }
Expand All @@ -44,5 +44,6 @@ mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "eh_unwind_resume"] extern fn eh_unwind_resume() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
}
10 changes: 3 additions & 7 deletions src/lib.rs
Expand Up @@ -132,13 +132,9 @@
//! types across a variety of libraries. But the question of purpose and suitability is open, and I
//! don’t have a really good example of such a use case here at present. TODO.

#![cfg_attr(feature = "no_std", feature(core, no_std))]
#![cfg_attr(feature = "no_std", feature(no_std))]
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(feature = "no_std")]
#[macro_use]
extern crate core;

#[cfg(all(test, feature = "no_std"))]
extern crate std;

Expand Down Expand Up @@ -251,7 +247,7 @@ macro_rules! mopafy {
};

($trait_:ident, core = $core:ident) => {
mopafy!($trait_(), core = $core, alloc = std);
mopafy!($trait_(), core = $core);
};

($trait_:ident, core = $core:ident, alloc = $alloc:ident) => {
Expand All @@ -263,7 +259,7 @@ macro_rules! mopafy {
};

($trait_:ident <$($args: ident),+>, core = $core:ident) => {
mopafy!($trait_($($args),*), core = $core, alloc = $alloc);
mopafy!($trait_($($args),*), core = $core);
};

($trait_:ident <$($args: ident),+>, core = $core:ident, alloc = $alloc:ident) => {
Expand Down

0 comments on commit 9e4c0a0

Please sign in to comment.