Skip to content

Commit 9083cb2

Browse files
committed
rustc: Explicitly mention type params with missing 'static bounds
Also renames `check_durable` to `check_static` and removes the outdated comment.
1 parent 05a2d32 commit 9083cb2

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/librustc/middle/kind.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
315315
match e.node {
316316
ExprUnary(UnBox, interior) => {
317317
let interior_type = ty::expr_ty(cx.tcx, interior);
318-
let _ = check_durable(cx.tcx, interior_type, interior.span);
318+
let _ = check_static(cx.tcx, interior_type, interior.span);
319319
}
320320
ExprCast(source, _) => {
321321
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 {
474474
}
475475
}
476476

477-
// note: also used from middle::typeck::regionck!
478-
pub fn check_durable(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
477+
pub fn check_static(tcx: ty::ctxt, ty: ty::t, sp: Span) -> bool {
479478
if !ty::type_is_static(tcx, ty) {
480479
match ty::get(ty).sty {
481480
ty::ty_param(..) => {
482-
tcx.sess.span_err(sp, "value may contain references; \
483-
add `'static` bound");
481+
tcx.sess.span_err(sp,
482+
format!("value may contain references; \
483+
add `'static` bound to `{}`", ty_to_str(tcx, ty)));
484484
}
485485
_ => {
486486
tcx.sess.span_err(sp, "value may contain references");
@@ -578,7 +578,7 @@ pub fn check_cast_for_escaping_regions(
578578
if target_params.iter().any(|x| x == &source_param) {
579579
/* case (2) */
580580
} else {
581-
check_durable(cx.tcx, ty, source_span); /* case (3) */
581+
check_static(cx.tcx, ty, source_span); /* case (3) */
582582
}
583583
}
584584
_ => {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 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+
trait A<T> {}
12+
struct B<'a, T>(&'a A<T>);
13+
14+
trait X {}
15+
impl<'a, T> X for B<'a, T> {}
16+
17+
fn f<'a, T, U>(v: ~A<T>) -> ~X: {
18+
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `T`
19+
}
20+
21+
fn g<'a, T, U>(v: ~A<U>) -> ~X: {
22+
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `U`
23+
}
24+
25+
fn h<'a, T: 'static>(v: ~A<T>) -> ~X: {
26+
~B(v) as ~X: // ok
27+
}
28+
29+
fn main() {}
30+

0 commit comments

Comments
 (0)