about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBarosl Lee <vcs@barosl.com>2014-12-13 23:22:04 +0900
committerBarosl Lee <vcs@barosl.com>2014-12-20 04:54:43 +0900
commitd9f306757d3e7cdffaea26ddacaea55a837c3124 (patch)
tree17306ea086588ccbe287a40bf3f042a673dadd7f /src
parent95c2ed31aeb66b2662933200dbfd661a573b1f49 (diff)
downloadrust-d9f306757d3e7cdffaea26ddacaea55a837c3124.tar.gz
rust-d9f306757d3e7cdffaea26ddacaea55a837c3124.zip
Detect type inference failure when auto-dereferencing a pointer
check::autoderef() returns a ty_err when it fails to infer the type.
probe::probe() should respect this failure and fail together to prevent
further corruption.

Call stack: check::check_method_call() -> method::lookup() ->
            probe::probe() + confirm::confirm()

Fixes #19692.
Fixes #19583.
Fixes #19297.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/method/probe.rs13
-rw-r--r--src/test/compile-fail/issue-19692.rs18
2 files changed, 26 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs
index b5776f9aeb3..1217f811bc4 100644
--- a/src/librustc_typeck/check/method/probe.rs
+++ b/src/librustc_typeck/check/method/probe.rs
@@ -124,7 +124,10 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
     // it ride, although it's really not great, and in fact could I
     // think cause spurious errors. Really though this part should
     // take place in the `fcx.infcx().probe` below.
-    let steps = create_steps(fcx, span, self_ty);
+    let steps = match create_steps(fcx, span, self_ty) {
+        Some(steps) => steps,
+        None => return Err(NoMatch(Vec::new())),
+    };
 
     // Create a list of simplified self types, if we can.
     let mut simplified_steps = Vec::new();
@@ -160,7 +163,7 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
 fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                           span: Span,
                           self_ty: Ty<'tcx>)
-                          -> Vec<CandidateStep<'tcx>> {
+                          -> Option<Vec<CandidateStep<'tcx>>> {
     let mut steps = Vec::new();
 
     let (fully_dereferenced_ty, dereferences, _) =
@@ -179,11 +182,11 @@ fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                 adjustment: AutoUnsizeLength(dereferences, len),
             });
         }
-        _ => {
-        }
+        ty::ty_err => return None,
+        _ => (),
     }
 
-    return steps;
+    Some(steps)
 }
 
 impl<'a,'tcx> ProbeContext<'a,'tcx> {
diff --git a/src/test/compile-fail/issue-19692.rs b/src/test/compile-fail/issue-19692.rs
new file mode 100644
index 00000000000..4069ea6b997
--- /dev/null
+++ b/src/test/compile-fail/issue-19692.rs
@@ -0,0 +1,18 @@
+// 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.
+
+struct Homura;
+
+fn akemi(homura: Homura) {
+    let Some(ref madoka) = Some(homura.kaname()); //~ ERROR does not implement any method
+    madoka.clone(); //~ ERROR the type of this value must be known
+}
+
+fn main() { }