about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSean Bowe <ewillbefull@gmail.com>2015-09-13 14:14:04 -0600
committerSean Bowe <ewillbefull@gmail.com>2015-09-13 14:14:04 -0600
commit522d4b0a354b60b1b69d15773197c4c3dba521a5 (patch)
treeef11c1e3431f5ceee32f0e156a3f525548e1717c /src
parentfd230ff12481ebeba720fb1ac1f610d93bb74920 (diff)
downloadrust-522d4b0a354b60b1b69d15773197c4c3dba521a5.tar.gz
rust-522d4b0a354b60b1b69d15773197c4c3dba521a5.zip
Fixed regression in associated item resolution with default type parameters that reference Self in traits.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/astconv.rs13
-rw-r--r--src/test/compile-fail/issue-28344.rs21
-rw-r--r--src/test/compile-fail/unspecified-self-in-trait-ref.rs28
3 files changed, 61 insertions, 1 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 6f2d8345142..b5b5113c487 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -413,9 +413,20 @@ fn create_substs_for_ast_path<'tcx>(
     let mut type_substs = if param_mode == PathParamMode::Optional &&
                              types_provided.is_empty() {
         let mut substs = region_substs.clone();
+
         ty_param_defs
             .iter()
-            .map(|p| this.ty_infer(Some(p.clone()), Some(&mut substs), Some(TypeSpace), span))
+            .map(|p| {
+                if let Some(ref default) = p.default {
+                    if self_ty.is_none() && default.has_self_ty() {
+                        // There is no suitable inference default for a type parameter
+                        // that references Self with no self-type provided.
+                        return this.ty_infer(None, Some(&mut substs), Some(TypeSpace), span);
+                    }
+                }
+
+                this.ty_infer(Some(p.clone()), Some(&mut substs), Some(TypeSpace), span)
+            })
             .collect()
     } else {
         types_provided
diff --git a/src/test/compile-fail/issue-28344.rs b/src/test/compile-fail/issue-28344.rs
new file mode 100644
index 00000000000..751a42826d2
--- /dev/null
+++ b/src/test/compile-fail/issue-28344.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 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.
+
+use std::ops::BitXor;
+
+fn main() {
+    let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
+    //~^ ERROR must be specified
+    //~| no associated item named
+
+    let g = BitXor::bitor;
+    //~^ ERROR must be specified
+    //~| no associated item named
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/unspecified-self-in-trait-ref.rs b/src/test/compile-fail/unspecified-self-in-trait-ref.rs
new file mode 100644
index 00000000000..5ec9cf430f1
--- /dev/null
+++ b/src/test/compile-fail/unspecified-self-in-trait-ref.rs
@@ -0,0 +1,28 @@
+// Copyright 2015 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 Foo<A=Self> {
+    fn foo();
+}
+
+pub trait Bar<X=usize, A=Self> {
+    fn foo();
+}
+
+fn main() {
+    let a = Foo::lol();
+    //~^ ERROR no associated item named
+    let b = Foo::<_>::lol();
+    //~^ ERROR no associated item named
+    let c = Bar::lol();
+    //~^ ERROR no associated item named
+    let d = Bar::<usize, _>::lol();
+    //~^ ERROR no associated item named
+}