diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-07-29 17:01:14 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-03 17:23:01 -0700 |
| commit | 5cccf3cd256420d9f32c265e83036dea1d5f94d8 (patch) | |
| tree | 22904c7bb3df0872afa227638aa5e1e4ccb99fbc /src/libsyntax/ext/deriving | |
| parent | ceded6adb3a4e172eabef09e1c78717a99c16b14 (diff) | |
| download | rust-5cccf3cd256420d9f32c265e83036dea1d5f94d8.tar.gz rust-5cccf3cd256420d9f32c265e83036dea1d5f94d8.zip | |
syntax: Implement #![no_core]
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184
Diffstat (limited to 'src/libsyntax/ext/deriving')
| -rw-r--r-- | src/libsyntax/ext/deriving/bounds.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/clone.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/ord.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/partial_ord.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/decodable.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/default.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/encodable.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/hash.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 12 |
10 files changed, 26 insertions, 60 deletions
diff --git a/src/libsyntax/ext/deriving/bounds.rs b/src/libsyntax/ext/deriving/bounds.rs index 689a4e96aec..71b6184390a 100644 --- a/src/libsyntax/ext/deriving/bounds.rs +++ b/src/libsyntax/ext/deriving/bounds.rs @@ -29,11 +29,10 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt, item: &Annotatable, push: &mut FnMut(Annotatable)) { - let path = Path::new(vec![ - if cx.use_std { "std" } else { "core" }, - "marker", - "Copy", - ]); + let mut v = cx.crate_root.map(|s| vec![s]).unwrap_or(Vec::new()); + v.push("marker"); + v.push("Copy"); + let path = Path::new(v); let trait_def = TraitDef { span: span, diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index a9c05339894..9261c0162c7 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -57,12 +57,7 @@ fn cs_clone( substr: &Substructure) -> P<Expr> { let ctor_path; let all_fields; - let fn_path = vec![ - cx.ident_of_std("core"), - cx.ident_of("clone"), - cx.ident_of("Clone"), - cx.ident_of("clone"), - ]; + let fn_path = cx.std_path(&["clone", "Clone", "clone"]); let subcall = |field: &FieldInfo| { let args = vec![cx.expr_addr_of(field.span, field.self_.clone())]; diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index d605e0286f5..815448ac610 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -65,17 +65,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { let test_id = cx.ident_of("__test"); let equals_path = cx.path_global(span, - vec!(cx.ident_of_std("core"), - cx.ident_of("cmp"), - cx.ident_of("Ordering"), - cx.ident_of("Equal"))); + cx.std_path(&["cmp", "Ordering", "Equal"])); - let cmp_path = vec![ - cx.ident_of_std("core"), - cx.ident_of("cmp"), - cx.ident_of("Ord"), - cx.ident_of("cmp"), - ]; + let cmp_path = cx.std_path(&["cmp", "Ord", "cmp"]); /* Builds: diff --git a/src/libsyntax/ext/deriving/cmp/partial_ord.rs b/src/libsyntax/ext/deriving/cmp/partial_ord.rs index 4eb95343a49..a11e9f473a4 100644 --- a/src/libsyntax/ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax/ext/deriving/cmp/partial_ord.rs @@ -108,19 +108,11 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { let test_id = cx.ident_of("__test"); let ordering = cx.path_global(span, - vec!(cx.ident_of_std("core"), - cx.ident_of("cmp"), - cx.ident_of("Ordering"), - cx.ident_of("Equal"))); + cx.std_path(&["cmp", "Ordering", "Equal"])); let ordering = cx.expr_path(ordering); let equals_expr = cx.expr_some(span, ordering); - let partial_cmp_path = vec![ - cx.ident_of_std("core"), - cx.ident_of("cmp"), - cx.ident_of("PartialOrd"), - cx.ident_of("partial_cmp"), - ]; + let partial_cmp_path = cx.std_path(&["cmp", "PartialOrd", "partial_cmp"]); /* Builds: diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 085d9d60937..99fac991e7f 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -46,10 +46,11 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, push: &mut FnMut(Annotatable), krate: &'static str) { - if !cx.use_std { + if cx.crate_root != Some("std") { // FIXME(#21880): lift this requirement. - cx.span_err(span, "this trait cannot be derived with #![no_std]"); - return; + cx.span_err(span, "this trait cannot be derived with #![no_std] \ + or #![no_core]"); + return } let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index ab22b710700..3f4e9da0ed5 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -51,12 +51,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, } fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { - let default_ident = vec!( - cx.ident_of_std("core"), - cx.ident_of("default"), - cx.ident_of("Default"), - cx.ident_of("default") - ); + let default_ident = cx.std_path(&["default", "Default", "default"]); let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new()); return match *substr.fields { diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index ae4d337b9f6..3c77effe5f5 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -122,9 +122,10 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, push: &mut FnMut(Annotatable), krate: &'static str) { - if !cx.use_std { + if cx.crate_root != Some("std") { // FIXME(#21880): lift this requirement. - cx.span_err(span, "this trait cannot be derived with #![no_std]"); + cx.span_err(span, "this trait cannot be derived with #![no_std] \ + or #![no_core]"); return; } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 8f9e0279b29..1f4860b7ec1 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1252,9 +1252,7 @@ impl<'a> MethodDef<'a> { let mut first_ident = None; for (&ident, self_arg) in vi_idents.iter().zip(&self_args) { - let path = vec![cx.ident_of_std("core"), - cx.ident_of("intrinsics"), - cx.ident_of("discriminant_value")]; + let path = cx.std_path(&["intrinsics", "discriminant_value"]); let call = cx.expr_call_global( sp, path, vec![cx.expr_addr_of(sp, self_arg.clone())]); let variant_value = cx.expr_block(P(ast::Block { @@ -1289,9 +1287,7 @@ impl<'a> MethodDef<'a> { //Since we know that all the arguments will match if we reach the match expression we //add the unreachable intrinsics as the result of the catch all which should help llvm //in optimizing it - let path = vec![cx.ident_of_std("core"), - cx.ident_of("intrinsics"), - cx.ident_of("unreachable")]; + let path = cx.std_path(&["intrinsics", "unreachable"]); let call = cx.expr_call_global( sp, path, vec![]); let unreachable = cx.expr_block(P(ast::Block { diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index cdb378a34d4..97c50ed1eea 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -63,12 +63,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) }; let call_hash = |span, thing_expr| { let hash_path = { - let strs = vec![ - cx.ident_of_std("core"), - cx.ident_of("hash"), - cx.ident_of("Hash"), - cx.ident_of("hash"), - ]; + let strs = cx.std_path(&["hash", "Hash", "hash"]); cx.expr_path(cx.path_global(span, strs)) }; diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 344515b875f..36deaf488e1 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -40,13 +40,13 @@ macro_rules! path_local { } macro_rules! pathvec_std { - ($cx:expr, $first:ident :: $($rest:ident)::+) => ( - if $cx.use_std { - pathvec!(std :: $($rest)::+) - } else { - pathvec!($first :: $($rest)::+) + ($cx:expr, $first:ident :: $($rest:ident)::+) => ({ + let mut v = pathvec!($($rest)::+); + if let Some(s) = $cx.crate_root { + v.insert(0, s); } - ) + v + }) } macro_rules! path_std { |
