Skip to content

librustc: Check built-in trait bounds on implementations when direct #15957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2014
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
2 changes: 1 addition & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//! }
Expand Down
11 changes: 10 additions & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/kindck-impl-type-params-2.rs
Original file line number Diff line number Diff line change
@@ -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
}