diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index f4c9911c24387..672a3e44ccba2 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -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); @@ -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"); @@ -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) */ } } _ => {} diff --git a/src/test/compile-fail/owned-ptr-static-bound.rs b/src/test/compile-fail/owned-ptr-static-bound.rs new file mode 100644 index 0000000000000..508633d294146 --- /dev/null +++ b/src/test/compile-fail/owned-ptr-static-bound.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait A {} +struct B<'a, T>(&'a A); + +trait X {} +impl<'a, T> X for B<'a, T> {} + +fn f<'a, T, U>(v: ~A) -> ~X: { + ~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `T` +} + +fn g<'a, T, U>(v: ~A) -> ~X: { + ~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `U` +} + +fn h<'a, T: 'static>(v: ~A) -> ~X: { + ~B(v) as ~X: // ok +} + +fn main() {} +