Skip to content

Commit 0efbb25

Browse files
committed
auto merge of #8477 : catamorphism/rust/issue-4096, r=msullivan
r? @msullivan ...e parameters In this case, it's likely to be that the user forgot the `self` type, so say so. Closes #4096
2 parents e86d414 + db2d9ca commit 0efbb25

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/librustc/middle/typeck/check/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3208,10 +3208,19 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
32083208
ty_param_count, ty_substs_len));
32093209
fcx.infcx().next_ty_vars(ty_param_count)
32103210
} else if ty_substs_len < ty_param_count {
3211+
let is_static_method = match fcx.ccx.tcx.def_map.find(&node_id) {
3212+
Some(&ast::def_static_method(*)) => true,
3213+
_ => false
3214+
};
32113215
fcx.ccx.tcx.sess.span_err
32123216
(span,
32133217
fmt!("not enough type parameters provided: expected %u, found %u",
32143218
ty_param_count, ty_substs_len));
3219+
if is_static_method {
3220+
fcx.ccx.tcx.sess.span_note
3221+
(span, "Static methods have an extra implicit type parameter -- \
3222+
did you omit the type parameter for the `Self` type?");
3223+
}
32153224
fcx.infcx().next_ty_vars(ty_param_count)
32163225
} else {
32173226
pth.types.map(|aty| fcx.to_ty(aty))

src/test/compile-fail/issue-4096.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 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+
pub trait Nummy {
12+
fn from_inty<T>() -> Self;
13+
}
14+
15+
impl Nummy for float {
16+
fn from_inty<T>() -> float { 0.0 }
17+
}
18+
19+
fn main() {
20+
let _1:float = Nummy::from_inty::<int>(); //~ ERROR not enough type
21+
//~^ NOTE Static methods have an extra implicit type parameter
22+
}

0 commit comments

Comments
 (0)