Skip to content

Commit 07ed567

Browse files
committed
---
yaml --- r: 60046 b: refs/heads/master c: 4023f54 h: refs/heads/master v: v3
1 parent 4a7ed4c commit 07ed567

File tree

10 files changed

+143
-65
lines changed

10 files changed

+143
-65
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 387d6c597aeb4d067998cb59f5526cee92994efa
2+
refs/heads/master: 4023f54deb814529fe5be572b33e9df561ed494a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589

trunk/src/libcore/cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ A dynamic, mutable location.
1919
Similar to a mutable option type, but friendlier.
2020
*/
2121

22+
#[mutable]
2223
pub struct Cell<T> {
2324
priv value: Option<T>
2425
}

trunk/src/libcore/stackwalk.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,20 @@ fn test_simple_deep() {
6464
if i == 0 { return }
6565

6666
for walk_stack |_frame| {
67-
breakpoint();
67+
// Would be nice to test something here...
6868
}
6969
run(i - 1);
7070
}
7171

7272
run(10);
7373
}
7474

75-
fn breakpoint() {
76-
unsafe {
77-
rustrt::rust_dbg_breakpoint()
78-
}
79-
}
80-
8175
fn frame_address(f: &fn(x: *u8)) {
8276
unsafe {
8377
rusti::frame_address(f)
8478
}
8579
}
8680

87-
pub mod rustrt {
88-
pub extern {
89-
pub unsafe fn rust_dbg_breakpoint();
90-
}
91-
}
92-
9381
pub mod rusti {
9482
#[abi = "rust-intrinsic"]
9583
pub extern "rust-intrinsic" {

trunk/src/librustc/middle/ty.rs

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ pub impl TypeContents {
17951795
}
17961796
17971797
fn nonowned(_cx: ctxt) -> TypeContents {
1798-
TC_MANAGED + TC_BORROWED_POINTER
1798+
TC_MANAGED + TC_BORROWED_POINTER + TC_NON_OWNED
17991799
}
18001800
18011801
fn contains_managed(&self) -> bool {
@@ -1849,40 +1849,43 @@ impl ToStr for TypeContents {
18491849
}
18501850
18511851
/// Constant for a type containing nothing of interest.
1852-
static TC_NONE: TypeContents = TypeContents{bits:0b0000_00000000};
1852+
static TC_NONE: TypeContents = TypeContents{bits: 0b0000_0000_0000};
18531853
18541854
/// Contains a borrowed value with a lifetime other than static
1855-
static TC_BORROWED_POINTER: TypeContents = TypeContents{bits:0b0000_00000001};
1855+
static TC_BORROWED_POINTER: TypeContents = TypeContents{bits: 0b0000_0000_0001};
18561856
18571857
/// Contains an owned pointer (~T) but not slice of some kind
1858-
static TC_OWNED_POINTER: TypeContents = TypeContents{bits:0b000000000010};
1858+
static TC_OWNED_POINTER: TypeContents = TypeContents{bits: 0b0000_0000_0010};
18591859
18601860
/// Contains an owned vector ~[] or owned string ~str
1861-
static TC_OWNED_VEC: TypeContents = TypeContents{bits:0b000000000100};
1861+
static TC_OWNED_VEC: TypeContents = TypeContents{bits: 0b0000_0000_0100};
18621862
18631863
/// Contains a ~fn() or a ~Trait, which is non-copyable.
1864-
static TC_OWNED_CLOSURE: TypeContents = TypeContents{bits:0b000000001000};
1864+
static TC_OWNED_CLOSURE: TypeContents = TypeContents{bits: 0b0000_0000_1000};
18651865
18661866
/// Type with a destructor
1867-
static TC_DTOR: TypeContents = TypeContents{bits:0b000000010000};
1867+
static TC_DTOR: TypeContents = TypeContents{bits: 0b0000_0001_0000};
18681868
18691869
/// Contains a managed value
1870-
static TC_MANAGED: TypeContents = TypeContents{bits:0b000000100000};
1870+
static TC_MANAGED: TypeContents = TypeContents{bits: 0b0000_0010_0000};
18711871
18721872
/// &mut with any region
1873-
static TC_BORROWED_MUT: TypeContents = TypeContents{bits:0b000001000000};
1873+
static TC_BORROWED_MUT: TypeContents = TypeContents{bits: 0b0000_0100_0000};
18741874
18751875
/// Mutable content, whether owned or by ref
1876-
static TC_MUTABLE: TypeContents = TypeContents{bits:0b000010000000};
1876+
static TC_MUTABLE: TypeContents = TypeContents{bits: 0b0000_1000_0000};
18771877
1878-
/// Mutable content, whether owned or by ref
1879-
static TC_ONCE_CLOSURE: TypeContents = TypeContents{bits:0b000100000000};
1878+
/// One-shot closure
1879+
static TC_ONCE_CLOSURE: TypeContents = TypeContents{bits: 0b0001_0000_0000};
18801880
18811881
/// An enum with no variants.
1882-
static TC_EMPTY_ENUM: TypeContents = TypeContents{bits:0b010000000000};
1882+
static TC_EMPTY_ENUM: TypeContents = TypeContents{bits: 0b0010_0000_0000};
1883+
1884+
/// Contains a type marked with `#[non_owned]`
1885+
static TC_NON_OWNED: TypeContents = TypeContents{bits: 0b0100_0000_0000};
18831886
18841887
/// All possible contents.
1885-
static TC_ALL: TypeContents = TypeContents{bits:0b011111111111};
1888+
static TC_ALL: TypeContents = TypeContents{bits: 0b0111_1111_1111};
18861889
18871890
pub fn type_is_copyable(cx: ctxt, t: ty::t) -> bool {
18881891
type_contents(cx, t).is_copy(cx)
@@ -2024,14 +2027,13 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20242027
20252028
ty_struct(did, ref substs) => {
20262029
let flds = struct_fields(cx, did, substs);
2027-
let flds_tc = flds.foldl(
2030+
let mut res = flds.foldl(
20282031
TC_NONE,
20292032
|tc, f| tc + tc_mt(cx, f.mt, cache));
20302033
if ty::has_dtor(cx, did) {
2031-
flds_tc + TC_DTOR
2032-
} else {
2033-
flds_tc
2034+
res += TC_DTOR;
20342035
}
2036+
apply_tc_attr(cx, did, res)
20352037
}
20362038
20372039
ty_tup(ref tys) => {
@@ -2040,7 +2042,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20402042
20412043
ty_enum(did, ref substs) => {
20422044
let variants = substd_enum_variants(cx, did, substs);
2043-
if variants.is_empty() {
2045+
let res = if variants.is_empty() {
20442046
// we somewhat arbitrary declare that empty enums
20452047
// are non-copyable
20462048
TC_EMPTY_ENUM
@@ -2050,7 +2052,8 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20502052
*tc,
20512053
|tc, arg_ty| *tc + tc_ty(cx, *arg_ty, cache))
20522054
})
2053-
}
2055+
};
2056+
apply_tc_attr(cx, did, res)
20542057
}
20552058
20562059
ty_param(p) => {
@@ -2110,6 +2113,16 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
21102113
mc + tc_ty(cx, mt.ty, cache)
21112114
}
21122115
2116+
fn apply_tc_attr(cx: ctxt, did: def_id, mut tc: TypeContents) -> TypeContents {
2117+
if has_attr(cx, did, "mutable") {
2118+
tc += TC_MUTABLE;
2119+
}
2120+
if has_attr(cx, did, "non_owned") {
2121+
tc += TC_NON_OWNED;
2122+
}
2123+
tc
2124+
}
2125+
21132126
fn borrowed_contents(region: ty::Region,
21142127
mutbl: ast::mutability) -> TypeContents
21152128
{
@@ -3874,28 +3887,32 @@ pub fn lookup_trait_def(cx: ctxt, did: ast::def_id) -> @ty::TraitDef {
38743887
}
38753888
}
38763889
3877-
// Determine whether an item is annotated with #[packed] or not
3878-
pub fn lookup_packed(tcx: ctxt,
3879-
did: def_id) -> bool {
3890+
/// Determine whether an item is annotated with an attribute
3891+
pub fn has_attr(tcx: ctxt, did: def_id, attr: &str) -> bool {
38803892
if is_local(did) {
38813893
match tcx.items.find(&did.node) {
38823894
Some(
38833895
&ast_map::node_item(@ast::item {
38843896
attrs: ref attrs,
38853897
_
3886-
}, _)) => attr::attrs_contains_name(*attrs, "packed"),
3898+
}, _)) => attr::attrs_contains_name(*attrs, attr),
38873899
_ => tcx.sess.bug(fmt!("lookup_packed: %? is not an item",
38883900
did))
38893901
}
38903902
} else {
38913903
let mut ret = false;
38923904
do csearch::get_item_attrs(tcx.cstore, did) |meta_items| {
3893-
ret = attr::contains_name(meta_items, "packed");
3905+
ret = attr::contains_name(meta_items, attr);
38943906
}
38953907
ret
38963908
}
38973909
}
38983910
3911+
/// Determine whether an item is annotated with `#[packed]` or not
3912+
pub fn lookup_packed(tcx: ctxt, did: def_id) -> bool {
3913+
has_attr(tcx, did, "packed")
3914+
}
3915+
38993916
// Look up a field ID, whether or not it's local
39003917
// Takes a list of type substs in case the struct is generic
39013918
pub fn lookup_field_type(tcx: ctxt,

trunk/src/librustc/middle/typeck/check/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,19 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13111311
// Extract the function signature from `in_fty`.
13121312
let fn_sty = structure_of(fcx, f.span, fn_ty);
13131313

1314+
// FIXME(#3678) For now, do not permit calls to C abi functions.
1315+
match fn_sty {
1316+
ty::ty_bare_fn(ty::BareFnTy {abis, _}) => {
1317+
if !abis.is_rust() {
1318+
fcx.tcx().sess.span_err(
1319+
call_expr.span,
1320+
fmt!("Calls to C ABI functions are not (yet) \
1321+
supported; be patient, dear user"));
1322+
}
1323+
}
1324+
_ => {}
1325+
}
1326+
13141327
let fn_sig = match fn_sty {
13151328
ty::ty_bare_fn(ty::BareFnTy {sig: sig, _}) |
13161329
ty::ty_closure(ty::ClosureTy {sig: sig, _}) => sig,
@@ -3594,7 +3607,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
35943607
};
35953608
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
35963609
purity: ast::unsafe_fn,
3597-
abis: AbiSet::Intrinsic(),
3610+
abis: AbiSet::Rust(),
35983611
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
35993612
inputs: inputs,
36003613
output: output}

trunk/src/librustc/middle/typeck/collect.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl AstConv for CrateCtxt {
134134
Some(&ast_map::node_item(item, _)) => {
135135
ty_of_item(self, item)
136136
}
137-
Some(&ast_map::node_foreign_item(foreign_item, abis, _, _)) => {
138-
ty_of_foreign_item(self, foreign_item, abis)
137+
Some(&ast_map::node_foreign_item(foreign_item, _, _, _)) => {
138+
ty_of_foreign_item(self, foreign_item)
139139
}
140140
ref x => {
141141
self.tcx.sess.bug(fmt!("unexpected sort of item \
@@ -932,20 +932,7 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: @ast::foreign_item) {
932932
// As above, this call populates the type table with the converted
933933
// type of the foreign item. We simply write it into the node type
934934
// table.
935-
936-
// For reasons I cannot fully articulate, I do so hate the AST
937-
// map, and I regard each time that I use it as a personal and
938-
// moral failing, but at the moment it seems like the only
939-
// convenient way to extract the ABI. - ndm
940-
let abis = match ccx.tcx.items.find(&i.id) {
941-
Some(&ast_map::node_foreign_item(_, abis, _, _)) => abis,
942-
ref x => {
943-
ccx.tcx.sess.bug(fmt!("unexpected sort of item \
944-
in get_item_ty(): %?", (*x)));
945-
}
946-
};
947-
948-
let tpt = ty_of_foreign_item(ccx, i, abis);
935+
let tpt = ty_of_foreign_item(ccx, i);
949936
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
950937
ccx.tcx.tcache.insert(local_def(i.id), tpt);
951938
}
@@ -1116,17 +1103,14 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
11161103
}
11171104
}
11181105
1119-
pub fn ty_of_foreign_item(ccx: &CrateCtxt,
1120-
it: @ast::foreign_item,
1121-
abis: AbiSet) -> ty::ty_param_bounds_and_ty
1122-
{
1106+
pub fn ty_of_foreign_item(ccx: &CrateCtxt, it: @ast::foreign_item)
1107+
-> ty::ty_param_bounds_and_ty {
11231108
match it.node {
11241109
ast::foreign_item_fn(ref fn_decl, _, ref generics) => {
11251110
ty_of_foreign_fn_decl(ccx,
11261111
fn_decl,
11271112
local_def(it.id),
1128-
generics,
1129-
abis)
1113+
generics)
11301114
}
11311115
ast::foreign_item_const(t) => {
11321116
ty::ty_param_bounds_and_ty {
@@ -1213,8 +1197,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
12131197
pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
12141198
decl: &ast::fn_decl,
12151199
def_id: ast::def_id,
1216-
ast_generics: &ast::Generics,
1217-
abis: AbiSet)
1200+
ast_generics: &ast::Generics)
12181201
-> ty::ty_param_bounds_and_ty {
12191202
let ty_generics = ty_generics(ccx, None, ast_generics, 0);
12201203
let region_param_names = RegionParamNames::from_generics(ast_generics);
@@ -1225,7 +1208,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
12251208
let t_fn = ty::mk_bare_fn(
12261209
ccx.tcx,
12271210
ty::BareFnTy {
1228-
abis: abis,
1211+
abis: AbiSet::Rust(),
12291212
purity: ast::unsafe_fn,
12301213
sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty,
12311214
inputs: input_tys,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 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+
#[mutable]
12+
enum Foo { A }
13+
14+
fn bar<T: Const>(_: T) {}
15+
16+
fn main() {
17+
let x = A;
18+
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Const`
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 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+
#[mutable]
12+
struct Foo { a: int }
13+
14+
fn bar<T: Const>(_: T) {}
15+
16+
fn main() {
17+
let x = Foo { a: 5 };
18+
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Const`
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 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+
#[non_owned]
12+
enum Foo { A }
13+
14+
fn bar<T: Owned>(_: T) {}
15+
16+
fn main() {
17+
let x = A;
18+
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned`
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 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+
#[non_owned]
12+
struct Foo { a: int }
13+
14+
fn bar<T: Owned>(_: T) {}
15+
16+
fn main() {
17+
let x = Foo { a: 5 };
18+
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned`
19+
}

0 commit comments

Comments
 (0)