diff options
| author | bors <bors@rust-lang.org> | 2018-07-10 09:05:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-10 09:05:46 +0000 |
| commit | e46bfa2879e92d3b8f1e204e3b786932c68047fe (patch) | |
| tree | 2cc445e85dda1d7f82aa322f05b8494291efd5cc /src | |
| parent | 77117e383676176116851d7d3ec04b5e0cf0c456 (diff) | |
| parent | 96b151bd9c0a0388ede4c412dea486084abab0b1 (diff) | |
| download | rust-e46bfa2879e92d3b8f1e204e3b786932c68047fe.tar.gz rust-e46bfa2879e92d3b8f1e204e3b786932c68047fe.zip | |
Auto merge of #52204 - zackmdavis:and_the_crate_of_the_missing_module, r=oli-obk
correct import suggestions for edition 2018 For #52202.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_resolve/lib.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/rust-2018/issue-52202-use-suggestions.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/rust-2018/issue-52202-use-suggestions.stderr | 20 |
3 files changed, 55 insertions, 1 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b8dfd21e540..ee2a1c3bdeb 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4125,7 +4125,18 @@ impl<'a> Resolver<'a> { if ident.name == lookup_name && ns == namespace { if filter_fn(name_binding.def()) { // create the path - let mut segms = path_segments.clone(); + let mut segms = if self.session.rust_2018() && !in_module_is_extern { + // crate-local absolute paths start with `crate::` in edition 2018 + // FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660) + let mut full_segms = vec![ + ast::PathSegment::from_ident(keywords::Crate.ident()) + ]; + full_segms.extend(path_segments.clone()); + full_segms + } else { + path_segments.clone() + }; + segms.push(ast::PathSegment::from_ident(ident)); let path = Path { span: name_binding.span, diff --git a/src/test/ui/rust-2018/issue-52202-use-suggestions.rs b/src/test/ui/rust-2018/issue-52202-use-suggestions.rs new file mode 100644 index 00000000000..5acd19c2471 --- /dev/null +++ b/src/test/ui/rust-2018/issue-52202-use-suggestions.rs @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +// compile-flags: --edition 2018 + +// The local `use` suggestion should start with `crate::` (but the +// standard-library suggestions should not, obviously). + +mod plumbing { + pub struct Drain; +} + +fn main() { + let _d = Drain {}; + //~^ ERROR cannot find struct, variant or union type `Drain` in this scope +} diff --git a/src/test/ui/rust-2018/issue-52202-use-suggestions.stderr b/src/test/ui/rust-2018/issue-52202-use-suggestions.stderr new file mode 100644 index 00000000000..95158dbd853 --- /dev/null +++ b/src/test/ui/rust-2018/issue-52202-use-suggestions.stderr @@ -0,0 +1,20 @@ +error[E0422]: cannot find struct, variant or union type `Drain` in this scope + --> $DIR/issue-52202-use-suggestions.rs:21:14 + | +LL | let _d = Drain {}; + | ^^^^^ not found in this scope +help: possible candidates are found in other modules, you can import them into scope + | +LL | use crate::plumbing::Drain; + | +LL | use std::collections::binary_heap::Drain; + | +LL | use std::collections::hash_map::Drain; + | +LL | use std::collections::hash_set::Drain; + | +and 3 other candidates + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0422`. |
