Skip to content

Touch up the managed boxes lint and feature gate #10932

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 2 commits into from
Dec 15, 2013
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
27 changes: 21 additions & 6 deletions src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl Context {
}
}

fn gate_box(&self, span: Span) {
self.gate_feature("managed_boxes", span,
"The managed box syntax is being replaced by the \
`std::gc::Gc` and `std::rc::Rc` types. Equivalent \
functionality to managed trait objects will be \
implemented but is currently missing.");
}

fn has_feature(&self, feature: &str) -> bool {
self.features.iter().any(|n| n.as_slice() == feature)
}
Expand Down Expand Up @@ -172,17 +180,24 @@ impl Visitor<()> for Context {
experimental and likely to be removed");

},
ast::ty_box(_) => {
self.gate_feature("managed_boxes", t.span,
"The managed box syntax is being replaced by the `std::gc::Gc` \
and `std::rc::Rc` types. Equivalent functionality to managed \
trait objects will be implemented but is currently missing.");
}
ast::ty_box(_) => { self.gate_box(t.span); }
_ => {}
}

visit::walk_ty(self, t, ());
}

fn visit_expr(&mut self, e: @ast::Expr, _: ()) {
match e.node {
ast::ExprUnary(_, ast::UnBox(..), _) |
ast::ExprVstore(_, ast::ExprVstoreBox) |
ast::ExprVstore(_, ast::ExprVstoreMutBox) => {
self.gate_box(e.span);
}
_ => {}
}
visit::walk_expr(self, e, ());
}
}

pub fn check_crate(sess: Session, crate: &ast::Crate) {
Expand Down
18 changes: 15 additions & 3 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,21 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
let mut n_uniq = 0;
ty::fold_ty(cx.tcx, ty, |t| {
match ty::get(t).sty {
ty::ty_box(_) => n_box += 1,
ty::ty_uniq(_) => n_uniq += 1,
_ => ()
ty::ty_box(_) | ty::ty_estr(ty::vstore_box) |
ty::ty_evec(_, ty::vstore_box) |
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
n_box += 1;
}
ty::ty_uniq(_) | ty::ty_estr(ty::vstore_uniq) |
ty::ty_evec(_, ty::vstore_uniq) |
ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => {
n_uniq += 1;
}
ty::ty_closure(ref c) if c.sigil == ast::OwnedSigil => {
n_uniq += 1;
}

_ => ()
};
t
});
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/auto-ref-slice-plus-ref.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(managed_boxes)];

fn main() {

// Testing that method lookup does not automatically borrow
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.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(managed_boxes)];

struct Point {
x: int,
y: int,
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-loan-rcvr.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(managed_boxes)];

struct point { x: int, y: int }

trait methods {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-mut-boxed-vec.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(managed_boxes)];

fn main() {
let v = @mut [ 1, 2, 3 ];
for _x in v.iter() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-3763.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(managed_boxes)];

mod my_mod {
pub struct MyStruct {
priv priv_field: int
Expand Down
16 changes: 15 additions & 1 deletion src/test/compile-fail/lint-heap-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ struct Foo {
struct Bar { x: ~int } //~ ERROR type uses owned

fn main() {
let _x : Bar = Bar {x : ~10};
let _x : Bar = Bar {x : ~10}; //~ ERROR type uses owned

@2; //~ ERROR type uses managed
@[1]; //~ ERROR type uses managed
//~^ ERROR type uses managed
fn f(_: @Clone) {} //~ ERROR type uses managed
@""; //~ ERROR type uses managed
//~^ ERROR type uses managed

~2; //~ ERROR type uses owned
~[1]; //~ ERROR type uses owned
//~^ ERROR type uses owned
fn g(_: ~Clone) {} //~ ERROR type uses owned
~""; //~ ERROR type uses owned
//~^ ERROR type uses owned
proc() {}; //~ ERROR type uses owned
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/moves-based-on-type-exprs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Tests that references to move-by-default values trigger moves when
// they occur as part of various kinds of expressions.

#[feature(managed_boxes)];

struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn touch<A>(_a: &A) {}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/non-exhaustive-match.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(managed_boxes)];

enum t { a, b, }

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/occurs-check.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(managed_boxes)];

fn main() {
let f; //~ ERROR cyclic type of infinite size
f = @f;
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/static-region-bound.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[feature(managed_boxes)];

fn f<T:'static>(_: T) {}

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/unique-unique-kind.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(managed_boxes)];

fn f<T:Send>(_i: T) {
}

Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/borrowed-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
// debugger:print *unique_val_interior_ref_2
// check:$10 = 26.5

#[feature(managed_boxes)];
#[allow(unused_variable)];

struct SomeStruct {
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// debugger:print d->val
// check:$4 = false

#[feature(managed_boxes)];
#[allow(unused_variable)];

fn main() {
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/boxed-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// debugger:print managed_dtor->val
// check:$4 = {x = 33, y = 333, z = 3333, w = 33333}

#[feature(managed_boxes)];
#[allow(unused_variable)];

struct StructWithSomePadding {
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/destructured-local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
// debugger:print *nn
// check:$43 = 56

#[feature(managed_boxes)];
#[allow(unused_variable)];

struct Struct {
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/generic-method-on-generic-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = {-16, 16.5}
// debugger:continue

#[feature(managed_boxes)];

struct Struct<T> {
x: T
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/debug-info/managed-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// check:$3 = {-9747455}

#[allow(unused_variable)];
#[feature(struct_variant)];
#[feature(struct_variant, managed_boxes)];

// The first element is to ensure proper alignment, irrespective of the machines word size. Since
// the size of the discriminant value is machine dependent, this has be taken into account when
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/method-on-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];
#[feature(struct_variant)];

enum Enum {
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/method-on-generic-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];

struct Struct<T> {
x: T
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/method-on-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];

struct Struct {
x: int
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/method-on-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];

struct Struct {
x: int
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/method-on-tuple-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];

struct TupleStruct(int, f64);

impl TupleStruct {
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/self-in-default-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = -16
// debugger:continue

#[feature(managed_boxes)];

struct Struct {
x: int
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/debug-info/self-in-generic-default-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
// check:$21 = {-16, 16.5}
// debugger:continue

#[feature(managed_boxes)];

struct Struct {
x: int
}
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/var-captured-in-nested-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
// check:$14 = 8
// debugger:continue

#[feature(managed_boxes)];
#[allow(unused_variable)];

struct Struct {
Expand Down
1 change: 1 addition & 0 deletions src/test/debug-info/var-captured-in-stack-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// debugger:print managed->val
// check:$6 = 7

#[feature(managed_boxes)];
#[allow(unused_variable)];

struct Struct {
Expand Down
2 changes: 2 additions & 0 deletions src/test/pretty/block-disambig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// previously ambiguous (e.g. 'if true { } *val;' gets parsed as a
// binop)

#[feature(managed_boxes)];

fn test1() { let val = @0; { } *val; }

fn test2() -> int { let val = @0; { } *val }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//
// for a detailed explanation of what is going on here.

#[feature(managed_boxes)];

fn main() {
let a = @mut [3i];
let b = @mut [a];
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-fail-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Test that write guards trigger when there is a write to a field
// of a frozen structure.

#[feature(managed_boxes)];

struct S {
x: int
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-fail-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Test that write guards trigger when there is a write to a directly
// frozen @mut box.

#[feature(managed_boxes)];

fn main() {
let x = @mut 3;
let _y: &mut int = x;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-one-mut-one-imm-slice-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Test that write guards trigger when there is a coercion to
// a slice on the receiver of a method.

#[feature(managed_boxes)];

trait MyMutSlice {
fn my_mut_slice(self) -> Self;
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-one-mut-one-imm-slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Test that write guards trigger when arguments are coerced to slices.

#[feature(managed_boxes)];

fn add(x:&mut [int], y:&[int])
{
x[0] = x[0] + y[0];
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-one-mut-one-imm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Test that write guards trigger when we are indexing into
// an @mut vector.

#[feature(managed_boxes)];

fn add(x:&mut int, y:&int)
{
*x = *x + *y;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/borrowck-wg-two-array-indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Test that arguments trigger when there are *two mutable* borrows
// of indices.

#[feature(managed_boxes)];

fn add(x:&mut int, y:&mut int)
{
*x = *x + *y;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/unwind-assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// error-pattern:fail

#[feature(managed_boxes)];

fn main() {
let _a = @0;
assert!(false);
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-fail/unwind-box-res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// error-pattern:fail

#[feature(managed_boxes)];

use std::cast;

fn failfn() {
Expand Down
Loading