Skip to content
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

librustc: Forbid & pointers (other than &'static) inside @ boxes. #7894

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 14 additions & 3 deletions src/libextra/fun_treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ enum TreeNode<K, V> {
}

/// Create a treemap
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
pub fn init<K: 'static, V: 'static>() -> Treemap<K, V> {
@Empty
}

/// Insert a value into the map
pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
pub fn insert<K:Eq + Ord + 'static,
V:'static>(
m: Treemap<K, V>,
k: K,
v: V)
-> Treemap<K, V> {
@match m {
@Empty => Node(@k, @v, @Empty, @Empty),
@Node(kk, vv, left, right) => cond!(
Expand All @@ -46,7 +53,11 @@ pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
}

/// Find a value based on the key
pub fn find<K:Eq + Ord,V:Clone>(m: Treemap<K, V>, k: K) -> Option<V> {
pub fn find<K:Eq + Ord + 'static,
V:Clone + 'static>(
m: Treemap<K, V>,
k: K)
-> Option<V> {
match *m {
Empty => None,
Node(kk, v, left, right) => cond!(
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum MutList<T> {
}

/// Create a list from a vector
pub fn from_vec<T:Clone>(v: &[T]) -> @List<T> {
pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons((*h).clone(), t))
}

Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn head<T:Clone>(ls: @List<T>) -> T {
}

/// Appends one list to another
pub fn append<T:Clone>(l: @List<T>, m: @List<T>) -> @List<T> {
pub fn append<T:Clone + 'static>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l {
Nil => return m,
Cons(ref x, xs) => {
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
}
}

impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T {
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
fn decode(d: &mut D) -> @T {
@Decodable::decode(d)
}
Expand All @@ -435,7 +435,7 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @mut T {
}
}

impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut T {
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @mut T {
fn decode(d: &mut D) -> @mut T {
@mut Decodable::decode(d)
}
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,9 @@ fn encode_info_for_items(ecx: &EncodeContext,

// Path and definition ID indexing

fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
-> ~[@~[entry<T>]] {
fn create_index<T:Clone + Hash + IterBytes + 'static>(
index: ~[entry<T>])
-> ~[@~[entry<T>]] {
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); };
for index.iter().advance |elt| {
Expand All @@ -1275,9 +1276,10 @@ fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
return buckets_frozen;
}

fn encode_index<T>(ebml_w: &mut writer::Encoder,
buckets: ~[@~[entry<T>]],
write_fn: &fn(@io::Writer, &T)) {
fn encode_index<T:'static>(
ebml_w: &mut writer::Encoder,
buckets: ~[@~[entry<T>]],
write_fn: &fn(@io::Writer, &T)) {
let writer = ebml_w.writer;
ebml_w.start_tag(tag_index);
let mut bucket_locs: ~[uint] = ~[];
Expand Down
35 changes: 18 additions & 17 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ use syntax::codemap::span;
use syntax::visit;
use util::ppaux::Repr;

#[deriving(Clone)]
struct CheckLoanCtxt<'self> {
bccx: @BorrowckCtxt,
dfcx_loans: &'self LoanDataFlow,
move_data: move_data::FlowedMoveData,
move_data: @move_data::FlowedMoveData,
all_loans: &'self [Loan],
reported: @mut HashSet<ast::node_id>,
}
Expand All @@ -46,10 +47,10 @@ pub fn check_loans(bccx: @BorrowckCtxt,
body: &ast::blk) {
debug!("check_loans(body id=%?)", body.id);

let clcx = @mut CheckLoanCtxt {
let clcx = CheckLoanCtxt {
bccx: bccx,
dfcx_loans: dfcx_loans,
move_data: move_data,
move_data: @move_data,
all_loans: all_loans,
reported: @mut HashSet::new(),
};
Expand Down Expand Up @@ -139,7 +140,7 @@ impl<'self> CheckLoanCtxt<'self> {
return result;
}

pub fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) {
pub fn check_for_conflicting_loans(&self, scope_id: ast::node_id) {
//! Checks to see whether any of the loans that are issued
//! by `scope_id` conflict with loans that have already been
//! issued when we enter `scope_id` (for example, we do not
Expand Down Expand Up @@ -596,7 +597,7 @@ impl<'self> CheckLoanCtxt<'self> {
MoveOk
}

pub fn check_call(&mut self,
pub fn check_call(&self,
_expr: @ast::expr,
_callee: Option<@ast::expr>,
_callee_id: ast::node_id,
Expand All @@ -617,8 +618,8 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
body: &ast::blk,
sp: span,
id: ast::node_id,
(this, visitor): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
(this, visitor): (CheckLoanCtxt<'a>,
visit::vt<CheckLoanCtxt<'a>>)) {
match *fk {
visit::fk_item_fn(*) |
visit::fk_method(*) => {
Expand All @@ -634,7 +635,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,

visit::visit_fn(fk, decl, body, sp, id, (this, visitor));

fn check_captured_variables(this: @mut CheckLoanCtxt,
fn check_captured_variables(this: CheckLoanCtxt,
closure_id: ast::node_id,
span: span) {
let cap_vars = this.bccx.capture_map.get(&closure_id);
Expand All @@ -652,7 +653,7 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
}
return;

fn check_by_move_capture(this: @mut CheckLoanCtxt,
fn check_by_move_capture(this: CheckLoanCtxt,
closure_id: ast::node_id,
cap_var: &moves::CaptureVar,
move_path: @LoanPath) {
Expand All @@ -676,14 +677,14 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
}

fn check_loans_in_local<'a>(local: @ast::local,
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
(this, vt): (CheckLoanCtxt<'a>,
visit::vt<CheckLoanCtxt<'a>>)) {
visit::visit_local(local, (this, vt));
}

fn check_loans_in_expr<'a>(expr: @ast::expr,
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>)) {
(this, vt): (CheckLoanCtxt<'a>,
visit::vt<CheckLoanCtxt<'a>>)) {
visit::visit_expr(expr, (this, vt));

debug!("check_loans_in_expr(expr=%s)",
Expand Down Expand Up @@ -736,17 +737,17 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
}

fn check_loans_in_pat<'a>(pat: @ast::pat,
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>))
(this, vt): (CheckLoanCtxt<'a>,
visit::vt<CheckLoanCtxt<'a>>))
{
this.check_for_conflicting_loans(pat.id);
this.check_move_out_from_id(pat.id, pat.span);
visit::visit_pat(pat, (this, vt));
}

fn check_loans_in_block<'a>(blk: &ast::blk,
(this, vt): (@mut CheckLoanCtxt<'a>,
visit::vt<@mut CheckLoanCtxt<'a>>))
(this, vt): (CheckLoanCtxt<'a>,
visit::vt<CheckLoanCtxt<'a>>))
{
visit::visit_block(blk, (this, vt));
this.check_for_conflicting_loans(blk.id);
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
}

match e.node {
expr_unary(_, box(_), interior) => {
let interior_type = ty::expr_ty(cx.tcx, interior);
let _ = check_durable(cx.tcx, interior_type, interior.span);
}
expr_cast(source, _) => {
check_cast_for_escaping_regions(cx, source, e);
match ty::get(ty::expr_ty(cx.tcx, e)).sty {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<T:Subst> Subst for ~[T] {
}
}

impl<T:Subst> Subst for @T {
impl<T:Subst + 'static> Subst for @T {
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> @T {
match self {
&@ref t => @t.subst(tcx, substs)
Expand Down
Loading