From 8848c38758d5afd16d4046ae89caeaeb340bb7e7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 12 Jan 2017 16:04:33 -0500 Subject: [PATCH 1/3] only consider value items when searching for methods, not types --- src/librustc_typeck/check/method/probe.rs | 11 +++++++++-- src/test/compile-fail/issue-38919.rs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-38919.rs diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index f331c561f0c..aa8f3bef92e 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1261,10 +1261,17 @@ fn collapse_candidates_to_trait_pick(&self, probes: &[&Candidate<'tcx>]) -> Opti /////////////////////////////////////////////////////////////////////////// // MISCELLANY fn has_applicable_self(&self, item: &ty::AssociatedItem) -> bool { - // "fast track" -- check for usage of sugar + // "Fast track" -- check for usage of sugar when in method call + // mode. + // + // In Path mode (i.e., resolving a value like `T::next`), consider any + // associated value (i.e., methods, constants) but not types. match self.mode { Mode::MethodCall => item.method_has_self_argument, - Mode::Path => true + Mode::Path => match item.kind { + ty::AssociatedKind::Type => false, + ty::AssociatedKind::Method | ty::AssociatedKind::Const => true + }, } // FIXME -- check for types that deref to `Self`, // like `Rc` and so on. diff --git a/src/test/compile-fail/issue-38919.rs b/src/test/compile-fail/issue-38919.rs new file mode 100644 index 00000000000..d907740ed01 --- /dev/null +++ b/src/test/compile-fail/issue-38919.rs @@ -0,0 +1,15 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo() { + T::Item; //~ ERROR no associated item named `Item` found for type `T` +} + +fn main() { } From 2bade8133c942b4598f41ea92f860da4bdaea67f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 17 Jan 2017 17:55:49 -0500 Subject: [PATCH 2/3] more complete error message --- src/test/compile-fail/issue-38919.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-38919.rs b/src/test/compile-fail/issue-38919.rs index d907740ed01..e6cee4afd59 100644 --- a/src/test/compile-fail/issue-38919.rs +++ b/src/test/compile-fail/issue-38919.rs @@ -9,7 +9,7 @@ // except according to those terms. fn foo() { - T::Item; //~ ERROR no associated item named `Item` found for type `T` + T::Item; //~ ERROR no associated item named `Item` found for type `T` in the current scope } fn main() { } From d82d4b66f24e21dd124e1b4765939b230cec3685 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 17 Jan 2017 17:56:03 -0500 Subject: [PATCH 3/3] tolerate `None` return from `get_line` --- src/libsyntax/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index a1c273baeea..adab76309fe 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -296,7 +296,7 @@ fn line_from_filemap(fm: &syntax_pos::FileMap, h_end: usize) -> DiagnosticSpanLine { DiagnosticSpanLine { - text: fm.get_line(index).unwrap().to_owned(), + text: fm.get_line(index).unwrap_or("").to_owned(), highlight_start: h_start, highlight_end: h_end, }