about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-26 12:16:43 -0800
committerbors <bors@rust-lang.org>2014-02-26 12:16:43 -0800
commitb4d923852e959e1bb79ebfa12e5951caee1a95b2 (patch)
treee0262c13fcb16efe63030629b8bbcb3fe7ae5d77 /src
parent5737d1f70459d03b219c8dadb8ac71c26e7e49d8 (diff)
parent9083cb24b2739e04ea1e0a90a14740939f8cfeed (diff)
downloadrust-b4d923852e959e1bb79ebfa12e5951caee1a95b2.tar.gz
rust-b4d923852e959e1bb79ebfa12e5951caee1a95b2.zip
auto merge of #12572 : lifthrasiir/rust/owned-ptr-static-bound, r=alexcrichton
This is inspired by the [question](http://www.reddit.com/r/rust/comments/1yy57k/unsolved_question_from_irc/) (re-)posted to /r/rust. The error message in this question correctly states that one should add `'static` to the trait bounds, but does not state which trait bounds. This PR makes that explicit by appending two words.

This also renames `check_durable` to `check_static` and removes the outdated comment as a cleanup.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/kind.rs12
-rw-r--r--src/test/compile-fail/owned-ptr-static-bound.rs30
2 files changed, 36 insertions, 6 deletions
diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs
index f4c9911c243..672a3e44ccb 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 00000000000..508633d2941
--- /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 <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() {}
+