New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggest `crate::...` for "local" paths in 2018 #54391

Merged
merged 4 commits into from Oct 4, 2018

Conversation

Projects
None yet
8 participants
@davidtwco
Member

davidtwco commented Sep 20, 2018

Fixes #54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing crate::, super::, self:: or a missing
external crate name before an import.

r? @nikomatsakis

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis Sep 21, 2018

Contributor

The code looks pretty good to me. I think there are some policy questions, e.g. the way that it prefers self or super to crate, that are not entirely clear to me. But probably not a big deal in practice.

Contributor

nikomatsakis commented Sep 21, 2018

The code looks pretty good to me. I think there are some policy questions, e.g. the way that it prefers self or super to crate, that are not entirely clear to me. But probably not a big deal in practice.

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis Sep 21, 2018

Contributor

Or, I guess that the current heuristic is:

  • self::foo
  • crate::foo
  • super::bar
  • extern_crate::bar

It feels like it might be reasonable to show more than one, too, though it'd be silly to do so if they are the same thing underneath.

Contributor

nikomatsakis commented Sep 21, 2018

Or, I guess that the current heuristic is:

  • self::foo
  • crate::foo
  • super::bar
  • extern_crate::bar

It feels like it might be reasonable to show more than one, too, though it'd be silly to do so if they are the same thing underneath.

@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Sep 21, 2018

Member

The code looks pretty good to me. I think there are some policy questions, e.g. the way that it prefers self or super to crate, that are not entirely clear to me. But probably not a big deal in practice.

Yeah, I've ordered these entirely arbitrarily - we can adjust that. I also experimented with having it attempt to correct misspellings but I couldn't quite tweak it so it wasn't over- or under-correcting. I would get it so if I had tsd::path it would suggest std::path but it would also suggest that for things that were completely wrong; and on the other end of the scale, if I had a long path that had one or two characters swapped, it wouldn't suggest anything.

Member

davidtwco commented Sep 21, 2018

The code looks pretty good to me. I think there are some policy questions, e.g. the way that it prefers self or super to crate, that are not entirely clear to me. But probably not a big deal in practice.

Yeah, I've ordered these entirely arbitrarily - we can adjust that. I also experimented with having it attempt to correct misspellings but I couldn't quite tweak it so it wasn't over- or under-correcting. I would get it so if I had tsd::path it would suggest std::path but it would also suggest that for things that were completely wrong; and on the other end of the scale, if I had a long path that had one or two characters swapped, it wouldn't suggest anything.

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis Sep 21, 2018

Contributor

I'm feeling a bit confused now because I know there is also this lookup_import_candidates_from_module function, and I'm trying to figure out how/if these ought to relate to one another. =)

Contributor

nikomatsakis commented Sep 21, 2018

I'm feeling a bit confused now because I know there is also this lookup_import_candidates_from_module function, and I'm trying to figure out how/if these ought to relate to one another. =)

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis Sep 21, 2018

Contributor

Maybe that code is only invoked if the bar part of foo::bar fails, not the foo part?

Contributor

nikomatsakis commented Sep 21, 2018

Maybe that code is only invoked if the bar part of foo::bar fails, not the foo part?

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb
Member

eddyb commented Sep 21, 2018

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned nikomatsakis Sep 21, 2018

@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Sep 21, 2018

Member

@nikomatsakis If it is at all helpful, these are the rough notes I threw together when initially working out what was happening and where these errors were coming from:

Searching for the error message, we find it in resolve_path_with_scope:

let msg = if module_def == self.graph_root.def() {
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
let mut candidates =
self.lookup_import_candidates(name, TypeNS, is_mod);
candidates.sort_by_cached_key(|c| {
(c.path.segments.len(), c.path.to_string())
});
if let Some(candidate) = candidates.get(0) {
format!("Did you mean `{}`?", candidate.path)
} else {
format!("Maybe a missing `extern crate {};`?", ident)
}
} else if i == 0 {
format!("Use of undeclared type or module `{}`", ident)
} else {
format!("Could not find `{}` in `{}`", ident, path[i - 1])
};

This returns a PathResult::Failed(..) with a span, message and boolean indicating if this is the last error. resolve_path_with_parent_scope is called by resolve_path.

resolved_path is called by resolve_import where the PathResult is matched, returning true:

match result {
PathResult::Module(module) => module,
PathResult::Indeterminate => return false,
_ => return true,
}

resolve_import is called by resolved_imports where the true is matched against to add the import that failed to the determined_imports list:

match self.resolve_import(&import) {
true => self.determined_imports.push(import),
false => self.indeterminate_imports.push(import),
}

Later, finalize_imports is called, this iterates over the determined_imports which calls finalize_import:

for i in 0 .. self.determined_imports.len() {
let import = self.determined_imports[i];
let error = self.finalize_import(import);

finalize_import eventually returns a span and a message, this is where we can see the original self:: suggestion being made:

let (mut self_path, mut self_result) = (module_path.clone(), None);
let is_special = |ident: Ident| ident.is_path_segment_keyword() &&
ident.name != keywords::CrateRoot.name();
if !self_path.is_empty() && !is_special(self_path[0]) &&
!(self_path.len() > 1 && is_special(self_path[1])) {
self_path[0].name = keywords::SelfValue.name();
self_result = Some(self.resolve_path(None, &self_path, None, false,
span, CrateLint::No));
}
return if let Some(PathResult::Module(..)) = self_result {
Some((span, format!("Did you mean `{}`?", names_to_string(&self_path[..]))))
} else {
Some((span, msg))
};

This then goes back to finalize_imports which calls adds the span and message to a vector:

error_vec.push((span, path, err));

That vector then is passed to throw_unresolved_import_error:

self.throw_unresolved_import_error(error_vec.clone(), None);

throw_unresolved_import_error throws the actual error that we see:

fn throw_unresolved_import_error(&self, error_vec: Vec<(Span, String, String)>,

Member

davidtwco commented Sep 21, 2018

@nikomatsakis If it is at all helpful, these are the rough notes I threw together when initially working out what was happening and where these errors were coming from:

Searching for the error message, we find it in resolve_path_with_scope:

let msg = if module_def == self.graph_root.def() {
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
let mut candidates =
self.lookup_import_candidates(name, TypeNS, is_mod);
candidates.sort_by_cached_key(|c| {
(c.path.segments.len(), c.path.to_string())
});
if let Some(candidate) = candidates.get(0) {
format!("Did you mean `{}`?", candidate.path)
} else {
format!("Maybe a missing `extern crate {};`?", ident)
}
} else if i == 0 {
format!("Use of undeclared type or module `{}`", ident)
} else {
format!("Could not find `{}` in `{}`", ident, path[i - 1])
};

This returns a PathResult::Failed(..) with a span, message and boolean indicating if this is the last error. resolve_path_with_parent_scope is called by resolve_path.

resolved_path is called by resolve_import where the PathResult is matched, returning true:

match result {
PathResult::Module(module) => module,
PathResult::Indeterminate => return false,
_ => return true,
}

resolve_import is called by resolved_imports where the true is matched against to add the import that failed to the determined_imports list:

match self.resolve_import(&import) {
true => self.determined_imports.push(import),
false => self.indeterminate_imports.push(import),
}

Later, finalize_imports is called, this iterates over the determined_imports which calls finalize_import:

for i in 0 .. self.determined_imports.len() {
let import = self.determined_imports[i];
let error = self.finalize_import(import);

finalize_import eventually returns a span and a message, this is where we can see the original self:: suggestion being made:

let (mut self_path, mut self_result) = (module_path.clone(), None);
let is_special = |ident: Ident| ident.is_path_segment_keyword() &&
ident.name != keywords::CrateRoot.name();
if !self_path.is_empty() && !is_special(self_path[0]) &&
!(self_path.len() > 1 && is_special(self_path[1])) {
self_path[0].name = keywords::SelfValue.name();
self_result = Some(self.resolve_path(None, &self_path, None, false,
span, CrateLint::No));
}
return if let Some(PathResult::Module(..)) = self_result {
Some((span, format!("Did you mean `{}`?", names_to_string(&self_path[..]))))
} else {
Some((span, msg))
};

This then goes back to finalize_imports which calls adds the span and message to a vector:

error_vec.push((span, path, err));

That vector then is passed to throw_unresolved_import_error:

self.throw_unresolved_import_error(error_vec.clone(), None);

throw_unresolved_import_error throws the actual error that we see:

fn throw_unresolved_import_error(&self, error_vec: Vec<(Span, String, String)>,

@davidtwco davidtwco changed the title from WIP: suggest `crate::...` for "local" paths in 2018 to suggest `crate::...` for "local" paths in 2018 Sep 27, 2018

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Sep 28, 2018

Member

I think this PR might need to check the edition? Or somehow involve the compat lints.
That said,
r? @petrochenkov

Member

eddyb commented Sep 28, 2018

I think this PR might need to check the edition? Or somehow involve the compat lints.
That said,
r? @petrochenkov

@rust-highfive rust-highfive assigned petrochenkov and unassigned eddyb Sep 28, 2018

@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Sep 28, 2018

Member

@eddyb I've added a test demonstrating the 2015 behaviour for the same test case.

Member

davidtwco commented Sep 28, 2018

@eddyb I've added a test demonstrating the 2015 behaviour for the same test case.

@petrochenkov

This comment has been minimized.

Show comment
Hide comment
@petrochenkov

petrochenkov Oct 2, 2018

Contributor

@bors r+

Contributor

petrochenkov commented Oct 2, 2018

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 2, 2018

Contributor

📌 Commit 1525e97 has been approved by petrochenkov

Contributor

bors commented Oct 2, 2018

📌 Commit 1525e97 has been approved by petrochenkov

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Oct 2, 2018

Rollup merge of rust-lang#54391 - davidtwco:issue-54230, r=petrochenkov
suggest `crate::...` for "local" paths in 2018

Fixes rust-lang#54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.

r? @nikomatsakis

bors added a commit that referenced this pull request Oct 2, 2018

Auto merge of #54763 - pietroalbini:rollup, r=pietroalbini
Rollup of 10 pull requests

Successful merges:

 - #54269 (#53840: Consolidate pattern check errors)
 - #54391 (suggest `crate::...` for "local" paths in 2018)
 - #54603 (Add `crate::` to trait suggestions in Rust 2018.)
 - #54648 (Update Cargo's submodule)
 - #54680 (make run-pass tests with empty main just compile-pass tests)
 - #54687 (Use impl_header_lifetime_elision in libcore)
 - #54699 (Re-export `getopts` so custom drivers can reference it.)
 - #54702 (do not promote comparing function pointers)
 - #54728 (Renumber `proc_macro` tracking issues)
 - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)

Failed merges:

r? @ghost
@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

⌛️ Testing commit 1525e97 with merge cf2e02e...

Contributor

bors commented Oct 3, 2018

⌛️ Testing commit 1525e97 with merge cf2e02e...

bors added a commit that referenced this pull request Oct 3, 2018

Auto merge of #54391 - davidtwco:issue-54230, r=petrochenkov
suggest `crate::...` for "local" paths in 2018

Fixes #54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.

r? @nikomatsakis
@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

💔 Test failed - status-travis

Contributor

bors commented Oct 3, 2018

💔 Test failed - status-travis

@rust-highfive

This comment was marked as outdated.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 3, 2018

Collaborator

The job mingw-check of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:06:46]     Checking rustc_allocator v0.0.0 (/checkout/src/librustc_allocator)
[00:06:46]     Checking rustc_traits v0.0.0 (/checkout/src/librustc_traits)
[00:06:50]     Checking rustc_plugin v0.0.0 (/checkout/src/librustc_plugin)
[00:06:50]     Checking rustc_resolve v0.0.0 (/checkout/src/librustc_resolve)
[00:06:52] error[E0609]: no field `extern_prelude` on type `&mut resolve_imports::ImportResolver<'a, 'b, 'c>`
[00:06:52]    --> librustc_resolve/error_reporting.rs:135:41
[00:06:52]     |
[00:06:52] 135 |         let external_crate_names = self.extern_prelude.clone();
[00:06:52] 
[00:06:52] error: aborting due to previous error
[00:06:52] 
[00:06:52] For more information about this error, try `rustc --explain E0609`.
[00:06:52] For more information about this error, try `rustc --explain E0609`.
[00:06:52] error: Could not compile `rustc_resolve`.
[00:06:52] warning: build failed, waiting for other jobs to finish...
[00:07:20] error: build failed
[00:07:20] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:07:20] expected success, got: exit code: 101
[00:07:20] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:07:20] travis_fold:end:stage0-rustc

[00:07:20] travis_time:end:stage0-rustc:start=1538541735174863493,finish=1538541896027504234,duration=160852640741

---
travis_time:end:26a4ef48:start=1538541896747656856,finish=1538541896756495733,duration=8838877
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0178d06b
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1bf7e0cc
travis_time:start:1bf7e0cc
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:08c0b5d8
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Collaborator

rust-highfive commented Oct 3, 2018

The job mingw-check of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:06:46]     Checking rustc_allocator v0.0.0 (/checkout/src/librustc_allocator)
[00:06:46]     Checking rustc_traits v0.0.0 (/checkout/src/librustc_traits)
[00:06:50]     Checking rustc_plugin v0.0.0 (/checkout/src/librustc_plugin)
[00:06:50]     Checking rustc_resolve v0.0.0 (/checkout/src/librustc_resolve)
[00:06:52] error[E0609]: no field `extern_prelude` on type `&mut resolve_imports::ImportResolver<'a, 'b, 'c>`
[00:06:52]    --> librustc_resolve/error_reporting.rs:135:41
[00:06:52]     |
[00:06:52] 135 |         let external_crate_names = self.extern_prelude.clone();
[00:06:52] 
[00:06:52] error: aborting due to previous error
[00:06:52] 
[00:06:52] For more information about this error, try `rustc --explain E0609`.
[00:06:52] For more information about this error, try `rustc --explain E0609`.
[00:06:52] error: Could not compile `rustc_resolve`.
[00:06:52] warning: build failed, waiting for other jobs to finish...
[00:07:20] error: build failed
[00:07:20] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:07:20] expected success, got: exit code: 101
[00:07:20] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
[00:07:20] travis_fold:end:stage0-rustc

[00:07:20] travis_time:end:stage0-rustc:start=1538541735174863493,finish=1538541896027504234,duration=160852640741

---
travis_time:end:26a4ef48:start=1538541896747656856,finish=1538541896756495733,duration=8838877
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0178d06b
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1bf7e0cc
travis_time:start:1bf7e0cc
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:08c0b5d8
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@davidtwco

This comment was marked as outdated.

Show comment
Hide comment
@davidtwco

davidtwco Oct 3, 2018

Member

@bors r=petrochenkov

Member

davidtwco commented Oct 3, 2018

@bors r=petrochenkov

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

📌 Commit c6645b5 has been approved by petrochenkov

Contributor

bors commented Oct 3, 2018

📌 Commit c6645b5 has been approved by petrochenkov

@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

⌛️ Testing commit c6645b5 with merge bab80bb...

Contributor

bors commented Oct 3, 2018

⌛️ Testing commit c6645b5 with merge bab80bb...

bors added a commit that referenced this pull request Oct 3, 2018

Auto merge of #54391 - davidtwco:issue-54230, r=petrochenkov
suggest `crate::...` for "local" paths in 2018

Fixes #54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.

r? @nikomatsakis
@bors

This comment was marked as outdated.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

💔 Test failed - status-appveyor

Contributor

bors commented Oct 3, 2018

💔 Test failed - status-appveyor

@rust-highfive

This comment was marked as outdated.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 3, 2018

Collaborator

The job i686-apple of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:28]       Memory: 8 GB
[00:03:28]       Boot ROM Version: VMW71.00V.0.B64.1704110547
[00:03:28]       Apple ROM Info: [MS_VM_CERT/SHA1/27d66596a61c48dd3dc7216fd715126e33f59ae7]Welcome to the Virtual Machine
[00:03:28]       SMC Version (system): 2.8f0
[00:03:28]       Serial Number (system): VMomKGnSy3aJ
[00:03:28] 
[00:03:28] hw.ncpu: 4
[00:03:28] hw.byteorder: 1234
[00:03:28] hw.memsize: 8589934592
---
[01:01:27] diff of stderr:
[01:01:27] 
[01:01:27] 2   --> $DIR/issue-54006.rs:16:5
[01:01:27] 3    |
[01:01:27] 4 LL | use alloc::vec;
[01:01:27] -    |     ^^^^^ Did you mean `std::alloc`?
[01:01:27] +    |     ^^^^^ Did you mean `core::alloc`?
[01:01:27] 7 error: cannot determine resolution for the macro `vec`
[01:01:27] 8   --> $DIR/issue-54006.rs:20:18
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] The actual stderr differed from the expected stderr.
[01:01:27] Actual stderr saved to /Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/issue-54006.stderr
[01:01:27] To update references, rerun the tests and pass the `--bless` flag
[01:01:27] To only update this specific test, also pass `--test-args rust-2018/issue-54006.rs`
[01:01:27] error: 1 errors occurred comparing output.
[01:01:27] status: exit code: 1
[01:01:27] status: exit code: 1
[01:01:27] command: "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/bin/rustc" "/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs" "--target=i686-apple-darwin" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/native/rust-test-helpers" "--edition=2018" "-L" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/auxiliary" "-A" "unused"
[01:01:27] ------------------------------------------
[01:01:27] 
[01:01:27] ------------------------------------------
[01:01:27] stderr:
[01:01:27] stderr:
[01:01:27] ------------------------------------------
[01:01:27] {"message":"unresolved import `alloc`","code":{"code":"E0432","explanation":"\nAn import was unresolved.\n\nErroneous code example:\n\n```compile_fail,E0432\nuse something::Foo; // error: unresolved import `something::Foo`.\n```\n\nPaths in `use` statements are relative to the crate root. To import items\nrelative to the current and parent modules, use the `self::` and `super::`\nprefixes, respectively. Also verify that you didn't misspell the import\nname and that the import exists in the module from where you tried to\nimport it. Example:\n\n```\nuse self::something::Foo; // ok!\n\nmod something {\n    pub struct Foo;\n}\n# fn main() {}\n```\n\nOr, if you tried to use a module from an external crate, you may have missed\nthe `extern crate` declaration (which is usually placed in the crate root):\n\n```\nextern crate core; // Required to use the `core` crate\n\nuse core::any;\n# fn main() {}\n```\n"},"level":"error","spans":[{"file_name":"/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs","byte_start":523,"byte_end":528,"line_start":16,"line_end":16,"column_start":5,"column_end":10,"is_primary":true,"text":[{"text":"use alloc::vec;","highlight_start":5,"highlight_end":10}],"label":"Did you mean `core::alloc`?","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0432]: unresolved import `alloc`\n  --> /Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs:16:5\n   |\nLL | use alloc::vec;\n   |     ^^^^^ Did you mean `core::alloc`?\n\n"}
[01:01:27] {"message":"cannot determine resolution for the macro `vec`","code":null,"level":"error","spans":[{"file_name":"/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs","byte_start":605,"byte_end":608,"line_start":20,"line_end":20,"column_start":18,"column_end":21,"is_primary":true,"text":[{"text":"    let mut xs = vec![];","highlight_start":18,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"import resolution is stuck, try simplifying macro imports","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error: cannot determine resolution for the macro `vec`\n  --> /Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs:20:18\n   |\nLL |     let mut xs = vec![];\n   |                  ^^^\n   |\n   = note: import resolution is stuck, try simplifying macro imports\n\n"}
[01:01:27] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[01:01:27] {"message":"For more information about this error, try `rustc --explain E0432`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0432`.\n"}
[01:01:27] ------------------------------------------
[01:01:27] 
[01:01:27] thread '[ui] ui/rust-2018/issue-54006.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3267:9
[01:01:27] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:01:27] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:01:27] 
[01:01:27] 
[01:01:27] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:499:22
[01:01:27] make: *** [check] Error 1
[01:01:27]     [ui] ui/rust-2018/issue-54006.rs
[01:01:27] 
[01:01:27] test result: FAILED. 4518 passed; 1 failed; 26 ignored; 0 measured; 0 filtered out
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] command did not execute successfully: "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage0-tools-bin/compiletest" "--compile-lib-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/lib" "--run-lib-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib" "--rustc-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/bin/rustc" "--src-base" "/Users/travis/build/rust-lang/rust/src/test/ui" "--build-base" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui" "--stage-id" "stage2-i686-apple-darwin" "--mode" "ui" "--target" "i686-apple-darwin" "--host" "i686-apple-darwin" "--llvm-filecheck" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/llvm/build/bin/FileCheck" "--nodejs" "/Users/travis/.nvm/versions/node/v6.12.3/bin/node" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/native/rust-test-helpers" "--docck-python" "/usr/local/opt/python/bin/python2.7" "--lldb-python" "/usr/bin/python" "--lldb-version" "lldb-902.0.73.1" "--lldb-python-dir" "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python" "--llvm-version" "8.0.0svn\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:01:27] 
[01:01:27] 
[01:01:27] failed to run: /Users/travis/build/rust-lang/rust/build/bootstrap/debug/bootstrap test
[01:01:27] Build completed unsuccessfully in 0:06:28
---
travis_fold:start:after_failure.2
travis_time:start:0cc47d5b
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
total 0
drwx------+ 15 travis  staff  510 Jan 25  2018 ..
drwx------   2 travis  staff   68 Dec  6  2017 .
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:134f1195
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
travis_time:end:134f1195:start=1538563405324143000,finish=1538563405345197000,duration=21054000
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1b2a678f
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:03ae871c
travis_time:start:03ae871c
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0835dcc2
$ dmesg | grep -i kill
$ dmesg | grep -i kill
Unable to obtain kernel buffer: Operation not permitted
usage: sudo dmesg
travis_fold:end:after_failure.6

Done. Your build exited with 1.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Collaborator

rust-highfive commented Oct 3, 2018

The job i686-apple of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:28]       Memory: 8 GB
[00:03:28]       Boot ROM Version: VMW71.00V.0.B64.1704110547
[00:03:28]       Apple ROM Info: [MS_VM_CERT/SHA1/27d66596a61c48dd3dc7216fd715126e33f59ae7]Welcome to the Virtual Machine
[00:03:28]       SMC Version (system): 2.8f0
[00:03:28]       Serial Number (system): VMomKGnSy3aJ
[00:03:28] 
[00:03:28] hw.ncpu: 4
[00:03:28] hw.byteorder: 1234
[00:03:28] hw.memsize: 8589934592
---
[01:01:27] diff of stderr:
[01:01:27] 
[01:01:27] 2   --> $DIR/issue-54006.rs:16:5
[01:01:27] 3    |
[01:01:27] 4 LL | use alloc::vec;
[01:01:27] -    |     ^^^^^ Did you mean `std::alloc`?
[01:01:27] +    |     ^^^^^ Did you mean `core::alloc`?
[01:01:27] 7 error: cannot determine resolution for the macro `vec`
[01:01:27] 8   --> $DIR/issue-54006.rs:20:18
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] The actual stderr differed from the expected stderr.
[01:01:27] Actual stderr saved to /Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/issue-54006.stderr
[01:01:27] To update references, rerun the tests and pass the `--bless` flag
[01:01:27] To only update this specific test, also pass `--test-args rust-2018/issue-54006.rs`
[01:01:27] error: 1 errors occurred comparing output.
[01:01:27] status: exit code: 1
[01:01:27] status: exit code: 1
[01:01:27] command: "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/bin/rustc" "/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs" "--target=i686-apple-darwin" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/native/rust-test-helpers" "--edition=2018" "-L" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui/rust-2018/issue-54006/auxiliary" "-A" "unused"
[01:01:27] ------------------------------------------
[01:01:27] 
[01:01:27] ------------------------------------------
[01:01:27] stderr:
[01:01:27] stderr:
[01:01:27] ------------------------------------------
[01:01:27] {"message":"unresolved import `alloc`","code":{"code":"E0432","explanation":"\nAn import was unresolved.\n\nErroneous code example:\n\n```compile_fail,E0432\nuse something::Foo; // error: unresolved import `something::Foo`.\n```\n\nPaths in `use` statements are relative to the crate root. To import items\nrelative to the current and parent modules, use the `self::` and `super::`\nprefixes, respectively. Also verify that you didn't misspell the import\nname and that the import exists in the module from where you tried to\nimport it. Example:\n\n```\nuse self::something::Foo; // ok!\n\nmod something {\n    pub struct Foo;\n}\n# fn main() {}\n```\n\nOr, if you tried to use a module from an external crate, you may have missed\nthe `extern crate` declaration (which is usually placed in the crate root):\n\n```\nextern crate core; // Required to use the `core` crate\n\nuse core::any;\n# fn main() {}\n```\n"},"level":"error","spans":[{"file_name":"/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs","byte_start":523,"byte_end":528,"line_start":16,"line_end":16,"column_start":5,"column_end":10,"is_primary":true,"text":[{"text":"use alloc::vec;","highlight_start":5,"highlight_end":10}],"label":"Did you mean `core::alloc`?","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0432]: unresolved import `alloc`\n  --> /Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs:16:5\n   |\nLL | use alloc::vec;\n   |     ^^^^^ Did you mean `core::alloc`?\n\n"}
[01:01:27] {"message":"cannot determine resolution for the macro `vec`","code":null,"level":"error","spans":[{"file_name":"/Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs","byte_start":605,"byte_end":608,"line_start":20,"line_end":20,"column_start":18,"column_end":21,"is_primary":true,"text":[{"text":"    let mut xs = vec![];","highlight_start":18,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"import resolution is stuck, try simplifying macro imports","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error: cannot determine resolution for the macro `vec`\n  --> /Users/travis/build/rust-lang/rust/src/test/ui/rust-2018/issue-54006.rs:20:18\n   |\nLL |     let mut xs = vec![];\n   |                  ^^^\n   |\n   = note: import resolution is stuck, try simplifying macro imports\n\n"}
[01:01:27] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[01:01:27] {"message":"For more information about this error, try `rustc --explain E0432`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0432`.\n"}
[01:01:27] ------------------------------------------
[01:01:27] 
[01:01:27] thread '[ui] ui/rust-2018/issue-54006.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3267:9
[01:01:27] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:01:27] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:01:27] 
[01:01:27] 
[01:01:27] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:499:22
[01:01:27] make: *** [check] Error 1
[01:01:27]     [ui] ui/rust-2018/issue-54006.rs
[01:01:27] 
[01:01:27] test result: FAILED. 4518 passed; 1 failed; 26 ignored; 0 measured; 0 filtered out
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] 
[01:01:27] command did not execute successfully: "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage0-tools-bin/compiletest" "--compile-lib-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/lib" "--run-lib-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib" "--rustc-path" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/stage2/bin/rustc" "--src-base" "/Users/travis/build/rust-lang/rust/src/test/ui" "--build-base" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/test/ui" "--stage-id" "stage2-i686-apple-darwin" "--mode" "ui" "--target" "i686-apple-darwin" "--host" "i686-apple-darwin" "--llvm-filecheck" "/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/llvm/build/bin/FileCheck" "--nodejs" "/Users/travis/.nvm/versions/node/v6.12.3/bin/node" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/Users/travis/build/rust-lang/rust/build/i686-apple-darwin/native/rust-test-helpers" "--docck-python" "/usr/local/opt/python/bin/python2.7" "--lldb-python" "/usr/bin/python" "--lldb-version" "lldb-902.0.73.1" "--lldb-python-dir" "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python" "--llvm-version" "8.0.0svn\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:01:27] 
[01:01:27] 
[01:01:27] failed to run: /Users/travis/build/rust-lang/rust/build/bootstrap/debug/bootstrap test
[01:01:27] Build completed unsuccessfully in 0:06:28
---
travis_fold:start:after_failure.2
travis_time:start:0cc47d5b
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
total 0
drwx------+ 15 travis  staff  510 Jan 25  2018 ..
drwx------   2 travis  staff   68 Dec  6  2017 .
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:134f1195
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
travis_time:end:134f1195:start=1538563405324143000,finish=1538563405345197000,duration=21054000
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1b2a678f
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:03ae871c
travis_time:start:03ae871c
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0835dcc2
$ dmesg | grep -i kill
$ dmesg | grep -i kill
Unable to obtain kernel buffer: Operation not permitted
usage: sudo dmesg
travis_fold:end:after_failure.6

Done. Your build exited with 1.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

davidtwco added some commits Sep 20, 2018

Add suggestions for unresolved imports.
This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.
Removed hardcoded crate.
Previously, `meta` crate was hardcoded as attempting to resolve a path
with it would ICE. Now, we attempt to load each extern crate first so
that resolving a path involving that crate doesn't error.
Update tests to demonstrate 2015 behaviour.
Adds a test to demonstrate behaviour of suggestions in the
2015 edition.
Deterministic external crate suggestion.
This commit ensures that the external crate suggestion is deterministic
by using a `BTreeMap` rather than a `FxHashMap`. This is particularly
useful as `std` and `core` will often contain the same items and
therefore the suggestion would previously suggest either for any given
error - in this case, the suggestion will always prefer `std` now.
@davidtwco

This comment has been minimized.

Show comment
Hide comment
@davidtwco

davidtwco Oct 3, 2018

Member

@bors r=petrochenkov

Member

davidtwco commented Oct 3, 2018

@bors r=petrochenkov

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

📌 Commit 5872d3e has been approved by petrochenkov

Contributor

bors commented Oct 3, 2018

📌 Commit 5872d3e has been approved by petrochenkov

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 3, 2018

Contributor

⌛️ Testing commit 5872d3e with merge 4bf883b...

Contributor

bors commented Oct 3, 2018

⌛️ Testing commit 5872d3e with merge 4bf883b...

bors added a commit that referenced this pull request Oct 3, 2018

Auto merge of #54391 - davidtwco:issue-54230, r=petrochenkov
suggest `crate::...` for "local" paths in 2018

Fixes #54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.

r? @nikomatsakis
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 4, 2018

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 4bf883b to master...

Contributor

bors commented Oct 4, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 4bf883b to master...

@bors bors merged commit 5872d3e into rust-lang:master Oct 4, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@davidtwco davidtwco deleted the davidtwco:issue-54230 branch Oct 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment