Skip to content

librustc: Feature gate lang items and intrinsics. #15066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ in the same format as a C:

```
#![no_std]
#![feature(lang_items)]

// Pull in the system libc library for what crt0.o likely requires
extern crate libc;
Expand All @@ -477,6 +478,7 @@ compiler's name mangling too:
```ignore
#![no_std]
#![no_main]
#![feature(lang_items)]

extern crate libc;

Expand Down Expand Up @@ -528,6 +530,7 @@ vectors provided from C, using idiomatic Rust practices.
```
#![no_std]
#![feature(globs)]
#![feature(lang_items)]

# extern crate libc;
extern crate core;
Expand Down Expand Up @@ -619,6 +622,9 @@ perform efficient pointer arithmetic, one would import those functions
via a declaration like

```
# #![feature(intrinsics)]
# fn main() {}

extern "rust-intrinsic" {
fn transmute<T, U>(x: T) -> U;

Expand Down Expand Up @@ -647,6 +653,7 @@ sugar for dynamic allocations via `malloc` and `free`:

```
#![no_std]
#![feature(lang_items)]

extern crate libc;

Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
html_root_url = "http://doc.rust-lang.org/")]

#![no_std]
#![feature(phase, unsafe_destructor)]
#![feature(lang_items, phase, unsafe_destructor)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap

#[phase(plugin, link)]
extern crate core;
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
html_playground_url = "http://play.rust-lang.org/")]

#![no_std]
#![feature(globs, macro_rules, managed_boxes, phase, simd, unsafe_destructor)]
#![feature(globs, intrinsics, lang_items, macro_rules, managed_boxes, phase)]
#![feature(simd, unsafe_destructor)]
#![deny(missing_doc)]
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot

#[cfg(test)] extern crate realcore = "core";
#[cfg(test)] extern crate libc;
Expand Down
2 changes: 2 additions & 0 deletions src/libnative/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

#![deny(unused_result, unused_must_use)]
#![allow(non_camel_case_types, deprecated)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#![feature(default_type_params, lang_items)]

// NB this crate explicitly does *not* allow glob imports, please seriously
// consider whether they're needed before adding that feature here (the
Expand Down
2 changes: 2 additions & 0 deletions src/librlibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![feature(intrinsics)]
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot

#![no_std]
#![experimental]
Expand Down
49 changes: 40 additions & 9 deletions src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

use middle::lint;

use syntax::abi::RustIntrinsic;
use syntax::ast::NodeId;
use syntax::ast;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
Expand Down Expand Up @@ -51,6 +53,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("trace_macros", Active),
("concat_idents", Active),
("unsafe_destructor", Active),
("intrinsics", Active),
("lang_items", Active),

("simd", Active),
("default_type_params", Active),
Expand Down Expand Up @@ -187,13 +191,18 @@ impl<'a> Visitor<()> for Context<'a> {
}
}

ast::ItemForeignMod(..) => {
ast::ItemForeignMod(ref foreign_module) => {
if attr::contains_name(i.attrs.as_slice(), "link_args") {
self.gate_feature("link_args", i.span,
"the `link_args` attribute is not portable \
across platforms, it is recommended to \
use `#[link(name = \"foo\")]` instead")
}
if foreign_module.abi == RustIntrinsic {
self.gate_feature("intrinsics",
i.span,
"intrinsics are subject to change")
}
}

ast::ItemFn(..) => {
Expand Down Expand Up @@ -283,14 +292,10 @@ impl<'a> Visitor<()> for Context<'a> {
}

fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
match i.node {
ast::ForeignItemFn(..) | ast::ForeignItemStatic(..) => {
if attr::contains_name(i.attrs.as_slice(), "linkage") {
self.gate_feature("linkage", i.span,
"the `linkage` attribute is experimental \
and not portable across platforms")
}
}
if attr::contains_name(i.attrs.as_slice(), "linkage") {
self.gate_feature("linkage", i.span,
"the `linkage` attribute is experimental \
and not portable across platforms")
}
visit::walk_foreign_item(self, i, ())
}
Expand Down Expand Up @@ -338,6 +343,32 @@ impl<'a> Visitor<()> for Context<'a> {
}
visit::walk_generics(self, generics, ());
}

fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
if attr::contains_name([*attr], "lang") {
self.gate_feature("lang_items",
attr.span,
"language items are subject to change");
}
}

fn visit_fn(&mut self,
fn_kind: &visit::FnKind,
fn_decl: &ast::FnDecl,
block: &ast::Block,
span: Span,
_: NodeId,
(): ()) {
match *fn_kind {
visit::FkItemFn(_, _, _, ref abi) if *abi == RustIntrinsic => {
self.gate_feature("intrinsics",
span,
"intrinsics are subject to change")
}
_ => {}
}
visit::walk_fn(self, fn_kind, fn_decl, block, span, ());
}
}

pub fn check_crate(sess: &Session, krate: &ast::Crate) {
Expand Down
3 changes: 2 additions & 1 deletion src/librustrt/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
html_root_url = "http://doc.rust-lang.org/")]

#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)]
#![feature(linkage, unsafe_destructor)]
#![feature(linkage, lang_items, unsafe_destructor)]
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
#![no_std]
#![experimental]

Expand Down
5 changes: 3 additions & 2 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]

#![feature(macro_rules, globs, managed_boxes)]
#![feature(linkage, default_type_params, phase, unsafe_destructor)]
#![feature(macro_rules, globs, managed_boxes, linkage)]
#![feature(default_type_params, phase, lang_items, unsafe_destructor)]

// Don't link to std. We are std.
#![no_std]

#![allow(deprecated)]
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
#![deny(missing_doc)]

// When testing libstd, bring in libuv as the I/O backend so tests can print
Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/cci_intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]

pub mod rusti {
extern "rust-intrinsic" {
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
Expand Down
1 change: 1 addition & 0 deletions src/test/auxiliary/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![no_std]
#![feature(lang_items)]

#[lang="fail_"]
fn fail(_: &'static str, _: &'static str, _: uint) -> ! { loop {} }
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(lang_items)]

fn main() {}

#![lang(foo)] //~ ERROR an inner attribute is not permitted in this context
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/bad-mid-path-type-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ignore-tidy-linelength

#![no_std]
#![feature(lang_items)]

#[lang="sized"]
pub trait Sized {}
Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/feature-gate-intrinsics-and-lang-items.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2014 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[lang="foo"] //~ ERROR language items are subject to change
trait Foo {}

extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
fn bar();
}

extern "rust-intrinsic" fn baz() { //~ ERROR intrinsics are subject to change
}

fn main() {
}

1 change: 1 addition & 0 deletions src/test/compile-fail/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![allow(non_camel_case_types)]
#![allow(visible_private_types)]
#![deny(dead_code)]
#![feature(lang_items)]

#![crate_type="lib"]

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/privacy1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(globs)]
#![feature(globs, lang_items)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)

#[lang="sized"]
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/intrinsic-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]

mod rusti {
extern "rust-intrinsic" {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/intrinsic-atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]

mod rusti {
extern "rust-intrinsic" {
pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/intrinsic-move-val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]

use std::mem::transmute;

mod rusti {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/intrinsic-uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]

mod rusti {
extern "rust-intrinsic" {
pub fn uninit<T>() -> T;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/intrinsics-integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(globs)]
#![feature(globs, intrinsics)]

mod rusti {
extern "rust-intrinsic" {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/intrinsics-math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(globs, macro_rules)]
#![feature(globs, macro_rules, intrinsics)]

macro_rules! assert_approx_eq(
($a:expr, $b:expr) => ({
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/rec-align-u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Issue #2303

#![feature(intrinsics)]

extern crate debug;

use std::mem;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/rec-align-u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Issue #2303

#![feature(intrinsics)]

extern crate debug;

use std::mem;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/smallest-hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Smallest "hello world" with a libc runtime

#![no_std]
#![feature(intrinsics, lang_items)]

extern crate libc;

Expand Down