Skip to content

Commit be1daa4

Browse files
committed
Auto merge of #39019 - nikomatsakis:issue-38919, r=eddyb
only consider value items when searching for methods, not types Fixes #38919 r? @eddyb
2 parents c07a6ae + d82d4b6 commit be1daa4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/librustc_typeck/check/method/probe.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
12611261
///////////////////////////////////////////////////////////////////////////
12621262
// MISCELLANY
12631263
fn has_applicable_self(&self, item: &ty::AssociatedItem) -> bool {
1264-
// "fast track" -- check for usage of sugar
1264+
// "Fast track" -- check for usage of sugar when in method call
1265+
// mode.
1266+
//
1267+
// In Path mode (i.e., resolving a value like `T::next`), consider any
1268+
// associated value (i.e., methods, constants) but not types.
12651269
match self.mode {
12661270
Mode::MethodCall => item.method_has_self_argument,
1267-
Mode::Path => true
1271+
Mode::Path => match item.kind {
1272+
ty::AssociatedKind::Type => false,
1273+
ty::AssociatedKind::Method | ty::AssociatedKind::Const => true
1274+
},
12681275
}
12691276
// FIXME -- check for types that deref to `Self`,
12701277
// like `Rc<Self>` and so on.

src/libsyntax/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl DiagnosticSpanLine {
296296
h_end: usize)
297297
-> DiagnosticSpanLine {
298298
DiagnosticSpanLine {
299-
text: fm.get_line(index).unwrap().to_owned(),
299+
text: fm.get_line(index).unwrap_or("").to_owned(),
300300
highlight_start: h_start,
301301
highlight_end: h_end,
302302
}

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

+15
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` in the current scope
13+
}
14+
15+
fn main() { }

0 commit comments

Comments
 (0)