about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-08-12 14:39:27 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-08-12 14:42:27 -0700
commitdb2d9caeda41bbda7490166c63af3a0481c210a5 (patch)
treeca71049c8c9c87230d031b9bbc5cc9dc861cd7e2
parent59434a1b8c83b3c243556038578736ebde02a3e8 (diff)
downloadrust-db2d9caeda41bbda7490166c63af3a0481c210a5.tar.gz
rust-db2d9caeda41bbda7490166c63af3a0481c210a5.zip
rustc: Give a hint when a static method call has fewer than expected type parameters
In this case, it's likely to be that the user forgot the `self` type, so
say so.

Closes #4096
-rw-r--r--src/librustc/middle/typeck/check/mod.rs9
-rw-r--r--src/test/compile-fail/issue-4096.rs22
2 files changed, 31 insertions, 0 deletions
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index e7ef30c4576..b7fe565f5cf 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -3208,10 +3208,19 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
                   ty_param_count, ty_substs_len));
         fcx.infcx().next_ty_vars(ty_param_count)
     } else if ty_substs_len < ty_param_count {
+        let is_static_method = match fcx.ccx.tcx.def_map.find(&node_id) {
+            Some(&ast::def_static_method(*)) => true,
+            _ => false
+        };
         fcx.ccx.tcx.sess.span_err
             (span,
              fmt!("not enough type parameters provided: expected %u, found %u",
                   ty_param_count, ty_substs_len));
+        if is_static_method {
+            fcx.ccx.tcx.sess.span_note
+                (span, "Static methods have an extra implicit type parameter -- \
+                 did you omit the type parameter for the `Self` type?");
+        }
         fcx.infcx().next_ty_vars(ty_param_count)
     } else {
         pth.types.map(|aty| fcx.to_ty(aty))
diff --git a/src/test/compile-fail/issue-4096.rs b/src/test/compile-fail/issue-4096.rs
new file mode 100644
index 00000000000..3f1172b6de8
--- /dev/null
+++ b/src/test/compile-fail/issue-4096.rs
@@ -0,0 +1,22 @@
+// Copyright 2013 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.
+
+pub trait Nummy {
+    fn from_inty<T>() -> Self;
+}
+
+impl Nummy for float {
+    fn from_inty<T>() -> float { 0.0 }
+}
+
+fn main() {
+    let _1:float = Nummy::from_inty::<int>();  //~ ERROR not enough type
+    //~^ NOTE Static methods have an extra implicit type parameter
+}