Skip to content
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
12 changes: 6 additions & 6 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
match e.node {
ExprUnary(UnBox, interior) => {
let interior_type = ty::expr_ty(cx.tcx, interior);
let _ = check_durable(cx.tcx, interior_type, interior.span);
let _ = check_static(cx.tcx, interior_type, interior.span);
}
ExprCast(source, _) => {
let source_ty = ty::expr_ty(cx.tcx, source);
Expand Down Expand Up @@ -474,13 +474,13 @@ pub fn check_send(cx: &Context, ty: ty::t, sp: Span) -> bool {
}
}

// note: also used from middle::typeck::regionck!
pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
pub fn check_static(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
if !ty::type_is_static(tcx, ty) {
match ty::get(ty).sty {
ty::ty_param(..) => {
tcx.sess.span_err(sp, "value may contain references; \
add `'static` bound");
tcx.sess.span_err(sp,
format!("value may contain references; \
add `'static` bound to `{}`", ty_to_str(tcx, ty)));
}
_ => {
tcx.sess.span_err(sp, "value may contain references");
Expand Down Expand Up @@ -578,7 +578,7 @@ pub fn check_cast_for_escaping_regions(
if target_params.iter().any(|x| x == &source_param) {
/* case (2) */
} else {
check_durable(cx.tcx, ty, source_span); /* case (3) */
check_static(cx.tcx, ty, source_span); /* case (3) */
}
}
_ => {}
Expand Down
30 changes: 30 additions & 0 deletions src/test/compile-fail/owned-ptr-static-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

trait A<T> {}
struct B<'a, T>(&'a A<T>);

trait X {}
impl<'a, T> X for B<'a, T> {}

fn f<'a, T, U>(v: ~A<T>) -> ~X: {
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `T`
}

fn g<'a, T, U>(v: ~A<U>) -> ~X: {
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `U`
}

fn h<'a, T: 'static>(v: ~A<T>) -> ~X: {
~B(v) as ~X: // ok
}

fn main() {}