From e7d1542a52dd04b58058d5d170a7a9b09f528f8c Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Fri, 10 Nov 2017 10:30:30 -0500 Subject: [PATCH] don't emit a type error if autoderef ends in an inference variable, as long as we went through a raw pointer This avoids a break in backward compatibility in the following case: ``` let ptr = std::ptr::null(); let _ = &data as *const *const (); if data.null() {} ``` --- src/librustc_typeck/check/method/probe.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 19fb32f96dff..141f0eea1fbe 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -321,9 +321,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // a real method lookup, this is a hard error (it's an // ambiguity and we can't make progress). if !is_suggestion.0 { - let t = self.structurally_resolved_type(span, final_ty); - assert_eq!(t, self.tcx.types.err); - return None + // don't report a type error if we dereferenced a raw pointer, + // because that would break backwards compatibility in certain cases + if !reached_raw_pointer { + let t = self.structurally_resolved_type(span, final_ty); + assert_eq!(t, self.tcx.types.err); + return None + } } else { // If we're just looking for suggestions, // though, ambiguity is no big thing, we can