Skip to content

Commit 4734b4a

Browse files
nikomatsakisbrson
authored andcommitted
only consider value items when searching for methods, not types
1 parent fd490b8 commit 4734b4a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/librustc_typeck/check/method/probe.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,10 +1140,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11401140
///////////////////////////////////////////////////////////////////////////
11411141
// MISCELLANY
11421142
fn has_applicable_self(&self, item: &ty::AssociatedItem) -> bool {
1143-
// "fast track" -- check for usage of sugar
1143+
// "Fast track" -- check for usage of sugar when in method call
1144+
// mode.
1145+
//
1146+
// In Path mode (i.e., resolving a value like `T::next`), consider any
1147+
// associated value (i.e., methods, constants) but not types.
11441148
match self.mode {
11451149
Mode::MethodCall => item.method_has_self_argument,
1146-
Mode::Path => true
1150+
Mode::Path => match item.kind {
1151+
ty::AssociatedKind::Type => false,
1152+
ty::AssociatedKind::Method | ty::AssociatedKind::Const => true
1153+
},
11471154
}
11481155
// FIXME -- check for types that deref to `Self`,
11491156
// like `Rc<Self>` and so on.

src/test/compile-fail/issue-38919.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn foo<T: Iterator>() {
12+
T::Item; //~ ERROR no associated item named `Item` found for type `T`
13+
}
14+
15+
fn main() { }

0 commit comments

Comments
 (0)