Skip to content

Commit d9611da

Browse files
committed
auto merge of #15066 : pcwalton/rust/lang-and-intrinsic-feature-gate, r=alexcrichton
If you define lang items in your crate, add `#[feature(lang_items)]`. If you define intrinsics (`extern "rust-intrinsic"`), add `#[feature(intrinsics)]`. Closes #12858. [breaking-change] r? @brson
2 parents e8c12d3 + 5466d13 commit d9611da

24 files changed

+106
-17
lines changed

src/doc/guide-unsafe.md

+7
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ in the same format as a C:
451451

452452
```
453453
#![no_std]
454+
#![feature(lang_items)]
454455
455456
// Pull in the system libc library for what crt0.o likely requires
456457
extern crate libc;
@@ -477,6 +478,7 @@ compiler's name mangling too:
477478
```ignore
478479
#![no_std]
479480
#![no_main]
481+
#![feature(lang_items)]
480482
481483
extern crate libc;
482484
@@ -528,6 +530,7 @@ vectors provided from C, using idiomatic Rust practices.
528530
```
529531
#![no_std]
530532
#![feature(globs)]
533+
#![feature(lang_items)]
531534
532535
# extern crate libc;
533536
extern crate core;
@@ -619,6 +622,9 @@ perform efficient pointer arithmetic, one would import those functions
619622
via a declaration like
620623

621624
```
625+
# #![feature(intrinsics)]
626+
# fn main() {}
627+
622628
extern "rust-intrinsic" {
623629
fn transmute<T, U>(x: T) -> U;
624630
@@ -647,6 +653,7 @@ sugar for dynamic allocations via `malloc` and `free`:
647653

648654
```
649655
#![no_std]
656+
#![feature(lang_items)]
650657
651658
extern crate libc;
652659

src/liballoc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
html_root_url = "http://doc.rust-lang.org/")]
7070

7171
#![no_std]
72-
#![feature(phase, unsafe_destructor)]
72+
#![feature(lang_items, phase, unsafe_destructor)]
73+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
7374

7475
#[phase(plugin, link)]
7576
extern crate core;

src/libcore/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@
5555
html_playground_url = "http://play.rust-lang.org/")]
5656

5757
#![no_std]
58-
#![feature(globs, macro_rules, managed_boxes, phase, simd, unsafe_destructor)]
58+
#![feature(globs, intrinsics, lang_items, macro_rules, managed_boxes, phase)]
59+
#![feature(simd, unsafe_destructor)]
5960
#![deny(missing_doc)]
61+
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
6062

6163
#[cfg(test)] extern crate realcore = "core";
6264
#[cfg(test)] extern crate libc;

src/libnative/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

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

5961
// NB this crate explicitly does *not* allow glob imports, please seriously
6062
// consider whether they're needed before adding that feature here (the

src/librlibc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2727
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2828
html_root_url = "http://doc.rust-lang.org/")]
29+
#![feature(intrinsics)]
30+
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
2931

3032
#![no_std]
3133
#![experimental]

src/librustc/front/feature_gate.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
2121
use middle::lint;
2222

23+
use syntax::abi::RustIntrinsic;
24+
use syntax::ast::NodeId;
2325
use syntax::ast;
2426
use syntax::attr;
2527
use syntax::attr::AttrMetaMethods;
@@ -51,6 +53,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5153
("trace_macros", Active),
5254
("concat_idents", Active),
5355
("unsafe_destructor", Active),
56+
("intrinsics", Active),
57+
("lang_items", Active),
5458

5559
("simd", Active),
5660
("default_type_params", Active),
@@ -187,13 +191,18 @@ impl<'a> Visitor<()> for Context<'a> {
187191
}
188192
}
189193

190-
ast::ItemForeignMod(..) => {
194+
ast::ItemForeignMod(ref foreign_module) => {
191195
if attr::contains_name(i.attrs.as_slice(), "link_args") {
192196
self.gate_feature("link_args", i.span,
193197
"the `link_args` attribute is not portable \
194198
across platforms, it is recommended to \
195199
use `#[link(name = \"foo\")]` instead")
196200
}
201+
if foreign_module.abi == RustIntrinsic {
202+
self.gate_feature("intrinsics",
203+
i.span,
204+
"intrinsics are subject to change")
205+
}
197206
}
198207

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

285294
fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
286-
match i.node {
287-
ast::ForeignItemFn(..) | ast::ForeignItemStatic(..) => {
288-
if attr::contains_name(i.attrs.as_slice(), "linkage") {
289-
self.gate_feature("linkage", i.span,
290-
"the `linkage` attribute is experimental \
291-
and not portable across platforms")
292-
}
293-
}
295+
if attr::contains_name(i.attrs.as_slice(), "linkage") {
296+
self.gate_feature("linkage", i.span,
297+
"the `linkage` attribute is experimental \
298+
and not portable across platforms")
294299
}
295300
visit::walk_foreign_item(self, i, ())
296301
}
@@ -338,6 +343,32 @@ impl<'a> Visitor<()> for Context<'a> {
338343
}
339344
visit::walk_generics(self, generics, ());
340345
}
346+
347+
fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
348+
if attr::contains_name([*attr], "lang") {
349+
self.gate_feature("lang_items",
350+
attr.span,
351+
"language items are subject to change");
352+
}
353+
}
354+
355+
fn visit_fn(&mut self,
356+
fn_kind: &visit::FnKind,
357+
fn_decl: &ast::FnDecl,
358+
block: &ast::Block,
359+
span: Span,
360+
_: NodeId,
361+
(): ()) {
362+
match *fn_kind {
363+
visit::FkItemFn(_, _, _, ref abi) if *abi == RustIntrinsic => {
364+
self.gate_feature("intrinsics",
365+
span,
366+
"intrinsics are subject to change")
367+
}
368+
_ => {}
369+
}
370+
visit::walk_fn(self, fn_kind, fn_decl, block, span, ());
371+
}
341372
}
342373

343374
pub fn check_crate(sess: &Session, krate: &ast::Crate) {

src/librustrt/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
html_root_url = "http://doc.rust-lang.org/")]
1818

1919
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)]
20-
#![feature(linkage, unsafe_destructor)]
20+
#![feature(linkage, lang_items, unsafe_destructor)]
21+
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
2122
#![no_std]
2223
#![experimental]
2324

src/libstd/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@
104104
html_root_url = "http://doc.rust-lang.org/",
105105
html_playground_url = "http://play.rust-lang.org/")]
106106

107-
#![feature(macro_rules, globs, managed_boxes)]
108-
#![feature(linkage, default_type_params, phase, unsafe_destructor)]
107+
#![feature(macro_rules, globs, managed_boxes, linkage)]
108+
#![feature(default_type_params, phase, lang_items, unsafe_destructor)]
109109

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

113113
#![allow(deprecated)]
114+
#![allow(unknown_features)] // NOTE: remove after stage0 snapshot
114115
#![deny(missing_doc)]
115116

116117
// When testing libstd, bring in libuv as the I/O backend so tests can print

src/test/auxiliary/cci_intrinsic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(intrinsics)]
12+
1113
pub mod rusti {
1214
extern "rust-intrinsic" {
1315
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;

src/test/auxiliary/lang-item-public.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![no_std]
12+
#![feature(lang_items)]
1213

1314
#[lang="fail_"]
1415
fn fail(_: &'static str, _: &'static str, _: uint) -> ! { loop {} }

src/test/compile-fail/attr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(lang_items)]
12+
1113
fn main() {}
1214

1315
#![lang(foo)] //~ ERROR an inner attribute is not permitted in this context

src/test/compile-fail/bad-mid-path-type-params.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ignore-tidy-linelength
1212

1313
#![no_std]
14+
#![feature(lang_items)]
1415

1516
#[lang="sized"]
1617
pub trait Sized {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[lang="foo"] //~ ERROR language items are subject to change
12+
trait Foo {}
13+
14+
extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
15+
fn bar();
16+
}
17+
18+
extern "rust-intrinsic" fn baz() { //~ ERROR intrinsics are subject to change
19+
}
20+
21+
fn main() {
22+
}
23+

src/test/compile-fail/lint-dead-code-1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![allow(non_camel_case_types)]
1414
#![allow(visible_private_types)]
1515
#![deny(dead_code)]
16+
#![feature(lang_items)]
1617

1718
#![crate_type="lib"]
1819

src/test/compile-fail/privacy1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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

1414
#[lang="sized"]

src/test/run-pass/intrinsic-alignment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(intrinsics)]
1112

1213
mod rusti {
1314
extern "rust-intrinsic" {

src/test/run-pass/intrinsic-atomics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(intrinsics)]
12+
1113
mod rusti {
1214
extern "rust-intrinsic" {
1315
pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;

src/test/run-pass/intrinsic-move-val.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(intrinsics)]
12+
1113
use std::mem::transmute;
1214

1315
mod rusti {

src/test/run-pass/intrinsic-uninit.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(intrinsics)]
12+
1113
mod rusti {
1214
extern "rust-intrinsic" {
1315
pub fn uninit<T>() -> T;

src/test/run-pass/intrinsics-integer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(globs)]
11+
#![feature(globs, intrinsics)]
1212

1313
mod rusti {
1414
extern "rust-intrinsic" {

src/test/run-pass/intrinsics-math.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// option. This file may not be copied, modified, or distributed
1010
// except according to those terms.
1111

12-
#![feature(globs, macro_rules)]
12+
#![feature(globs, macro_rules, intrinsics)]
1313

1414
macro_rules! assert_approx_eq(
1515
($a:expr, $b:expr) => ({

src/test/run-pass/rec-align-u32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Issue #2303
1212

13+
#![feature(intrinsics)]
14+
1315
extern crate debug;
1416

1517
use std::mem;

src/test/run-pass/rec-align-u64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Issue #2303
1212

13+
#![feature(intrinsics)]
14+
1315
extern crate debug;
1416

1517
use std::mem;

src/test/run-pass/smallest-hello-world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Smallest "hello world" with a libc runtime
1414

1515
#![no_std]
16+
#![feature(intrinsics, lang_items)]
1617

1718
extern crate libc;
1819

0 commit comments

Comments
 (0)