about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-25 09:31:10 +0000
committerbors <bors@rust-lang.org>2014-07-25 09:31:10 +0000
commit470dbef29a3df65b6b7a7c7c46a28696eda1d031 (patch)
tree47ba4e4f65e25493914abdd249c9695a16fdc122
parente5984640e63d2e9f613d857ad2d48ff57b310655 (diff)
parentf1520ea0cfa2a96731475cea221cd9ab70cf5588 (diff)
downloadrust-470dbef29a3df65b6b7a7c7c46a28696eda1d031.tar.gz
rust-470dbef29a3df65b6b7a7c7c46a28696eda1d031.zip
auto merge of #15957 : pcwalton/rust/builtin-bound-impl-checking, r=huonw,pnkfelix
method calls are involved.

This breaks code like:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = box 3i; // note no `Copy` bound
        take_param(&x);
    }

Change this code to not contain a type error. For example:

    impl<T:Copy> Foo for T { ... }

    fn take_param<T:Foo>(foo: &T) { ... }

    fn main() {
        let x = 3i; // satisfies `Copy` bound
        take_param(&x);
    }

Closes #15860.

[breaking-change]

r? @alexcrichton
-rw-r--r--src/libcore/any.rs2
-rw-r--r--src/librustc/middle/kind.rs11
-rw-r--r--src/test/compile-fail/kindck-impl-type-params-2.rs23
3 files changed, 34 insertions, 2 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index e0ac20d2fbf..297da495799 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -55,7 +55,7 @@
 //! }
 //!
 //! // This function wants to log its parameter out prior to doing work with it.
-//! fn do_work<T: Show>(value: &T) {
+//! fn do_work<T: Show+'static>(value: &T) {
 //!     log(value);
 //!     // ...do some other work
 //! }
diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs
index 517bdcbff96..e2e3081eb2d 100644
--- a/src/librustc/middle/kind.rs
+++ b/src/librustc/middle/kind.rs
@@ -324,7 +324,8 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
 
 fn check_bounds_on_type_parameters(cx: &mut Context, e: &Expr) {
     let method_map = cx.tcx.method_map.borrow();
-    let method = method_map.find(&typeck::MethodCall::expr(e.id));
+    let method_call = typeck::MethodCall::expr(e.id);
+    let method = method_map.find(&method_call);
 
     // Find the values that were provided (if any)
     let item_substs = cx.tcx.item_substs.borrow();
@@ -393,6 +394,14 @@ fn check_bounds_on_type_parameters(cx: &mut Context, e: &Expr) {
                type_param_def.space, type_param_def.index, ty.repr(cx.tcx));
         check_typaram_bounds(cx, e.span, ty, type_param_def)
     }
+
+    // Check the vtable.
+    let vtable_map = cx.tcx.vtable_map.borrow();
+    let vtable_res = match vtable_map.find(&method_call) {
+        None => return,
+        Some(vtable_res) => vtable_res,
+    };
+    check_type_parameter_bounds_in_vtable_result(cx, e.span, vtable_res);
 }
 
 fn check_type_parameter_bounds_in_vtable_result(
diff --git a/src/test/compile-fail/kindck-impl-type-params-2.rs b/src/test/compile-fail/kindck-impl-type-params-2.rs
new file mode 100644
index 00000000000..a034e252d31
--- /dev/null
+++ b/src/test/compile-fail/kindck-impl-type-params-2.rs
@@ -0,0 +1,23 @@
+// 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 Foo {
+}
+
+impl<T:Copy> Foo for T {
+}
+
+fn take_param<T:Foo>(foo: &T) { }
+
+fn main() {
+    let x = box 3i;
+    take_param(&x);
+    //~^ ERROR instantiating a type parameter with an incompatible type
+}