Skip to content

Commit e46bfa2

Browse files
committed
Auto merge of #52204 - zackmdavis:and_the_crate_of_the_missing_module, r=oli-obk
correct import suggestions for edition 2018 For #52202.
2 parents 77117e3 + 96b151b commit e46bfa2

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Diff for: src/librustc_resolve/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -4125,7 +4125,18 @@ impl<'a> Resolver<'a> {
41254125
if ident.name == lookup_name && ns == namespace {
41264126
if filter_fn(name_binding.def()) {
41274127
// create the path
4128-
let mut segms = path_segments.clone();
4128+
let mut segms = if self.session.rust_2018() && !in_module_is_extern {
4129+
// crate-local absolute paths start with `crate::` in edition 2018
4130+
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
4131+
let mut full_segms = vec![
4132+
ast::PathSegment::from_ident(keywords::Crate.ident())
4133+
];
4134+
full_segms.extend(path_segments.clone());
4135+
full_segms
4136+
} else {
4137+
path_segments.clone()
4138+
};
4139+
41294140
segms.push(ast::PathSegment::from_ident(ident));
41304141
let path = Path {
41314142
span: name_binding.span,

Diff for: src/test/ui/rust-2018/issue-52202-use-suggestions.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 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+
// compile-flags: --edition 2018
12+
13+
// The local `use` suggestion should start with `crate::` (but the
14+
// standard-library suggestions should not, obviously).
15+
16+
mod plumbing {
17+
pub struct Drain;
18+
}
19+
20+
fn main() {
21+
let _d = Drain {};
22+
//~^ ERROR cannot find struct, variant or union type `Drain` in this scope
23+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0422]: cannot find struct, variant or union type `Drain` in this scope
2+
--> $DIR/issue-52202-use-suggestions.rs:21:14
3+
|
4+
LL | let _d = Drain {};
5+
| ^^^^^ not found in this scope
6+
help: possible candidates are found in other modules, you can import them into scope
7+
|
8+
LL | use crate::plumbing::Drain;
9+
|
10+
LL | use std::collections::binary_heap::Drain;
11+
|
12+
LL | use std::collections::hash_map::Drain;
13+
|
14+
LL | use std::collections::hash_set::Drain;
15+
|
16+
and 3 other candidates
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0422`.

0 commit comments

Comments
 (0)