only consider value items when searching for methods, not types

This commit is contained in:
Niko Matsakis 2017-01-12 16:04:33 -05:00
parent ac5046cf67
commit 8848c38758
2 changed files with 24 additions and 2 deletions

View File

@ -1261,10 +1261,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
///////////////////////////////////////////////////////////////////////////
// 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<Self>` and so on.

View File

@ -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 <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.
fn foo<T: Iterator>() {
T::Item; //~ ERROR no associated item named `Item` found for type `T`
}
fn main() { }