Skip to content
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

rustc: Fix crate lint for single-item paths #50665

Merged
merged 1 commit into from
May 17, 2018

Conversation

alexcrichton
Copy link
Member

This commit fixes recommending the crate prefix when migrating to 2018 for
paths that look like use foo; or use {bar, baz}

Closes #50660

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2018
@alexcrichton
Copy link
Member Author

@bors: p=1

(affects upcoming edition preview)

let def = binding.def();
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def);
if let Some(next_module) = binding.module() {
module = Some(next_module);
} else if def == Def::Err {
return PathResult::NonModule(err_path_resolution());
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
self.lint_if_path_starts_with_module(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do this above as well, yes? After resolve_ident_in_lexical_scope? I'm not sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed here @Manishearth and I figured that we couldn't find other ways to get resolve to trigger those use cases, so we'll fix them up later if they come up and otherwise we'll move forward w/ this.

@Manishearth
Copy link
Member

@bors r+ p=1

@bors
Copy link
Contributor

bors commented May 11, 2018

📌 Commit 43f6b96 has been approved by Manishearth

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this pull request May 11, 2018
…arnings, r=Manishearth

rustc: Fix `crate` lint for single-item paths

This commit fixes recommending the `crate` prefix when migrating to 2018 for
paths that look like `use foo;` or `use {bar, baz}`

Closes rust-lang#50660
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:58:07] 
[00:58:07] running 1400 tests
[00:58:12] ..................................................................................i.................
[00:58:20] ................................i..............................................................F....
[00:58:28] ....................................................................................................
[00:58:32] ....................................................................................................
[00:58:37] ....................................................................................................
[00:58:43] ....................................................................................................
---
[00:59:34] failures:
[00:59:34] 
[00:59:34] ---- [ui] ui/edition-lint-paths.rs stdout ----
[00:59:34]  
[00:59:34] error: ui test compiled successfully!
[00:59:34] status: exit code: 0
[00:59:34] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/edition-lint-paths.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--target=x86_64-unknown-linux-gnu" "--error-fedition-lint-paths.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3033:9
[00:59:34] 
[00:59:34] 
[00:59:34] failures:
[00:59:34]     [ui] ui/edition-lint-paths.rs
[00:59:34]     [ui] ui/edition-lint-paths.rs
[00:59:34] 
[00:59:34] test result: FAILED. 1392 passed; 1 failed; 7 ignored; 0 measured; 0 filtered out
[00:59:34] 
[00:59:34] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:492:22
[00:59:34] 
[00:59:34] 
[00:59:34] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:59:34] 
[00:59:34] 
[00:59:34] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:59:34] Build completed unsuccessfully in 0:03:03
[00:59:34] Build completed unsuccessfully in 0:03:03
[00:59:34] make: *** [check] Error 1
[00:59:34] Makefile:58: recipe for target 'check' failed
112616 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu
112612 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release
108620 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps
103728 ./obj/build/bootstrap/debug/incremental/bootstrap-1x7l2oj4p22hp
103728 ./obj/build/bootstrap/debug/incremental/bootstrap-1x7l2oj4p22hp
103724 ./obj/build/bootstrap/debug/incremental/bootstrap-1x7l2oj4p22hp/s-f0y16e0z56-4wftwn-1nozvcbv9keul
98508 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/incremental
93332 ./obj/build/x86_64-unknown-linux-gnu/stage1
93308 ./obj/build/x86_64-unknown-linux-gnu/stage1/lib
90832 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
90832 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
90828 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz/s-f0y136m9r0-au7odn-5nj5h7hrw8mg
87816 ./obj/build/x86_64-unknown-linux-gnu/doc/core
81368 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps
80984 ./obj/build/x86_64-unknown-linux-gnu/doc/std
79044 ./obj/build/x86_64-unknown-linux-gnu/stage0-sysroot

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)

@alexcrichton alexcrichton force-pushed the fix-single-item-path-warnings branch from 43f6b96 to a7222c1 Compare May 11, 2018 19:56
@alexcrichton
Copy link
Member Author

@bors: r=Manishearth

@bors
Copy link
Contributor

bors commented May 11, 2018

📌 Commit a7222c1 has been approved by Manishearth

@alexcrichton
Copy link
Member Author

@bors: r-

I've found an issue with this that needs to be tweaked

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 11, 2018
@alexcrichton alexcrichton force-pushed the fix-single-item-path-warnings branch from a7222c1 to c9585dd Compare May 11, 2018 21:40
@alexcrichton
Copy link
Member Author

Ok the bug that I found was that the previous changes would lint for imports like use libc; and rewrite those to use crate::libc;. While that works in the 2015 edition it's not something we want to lint for. Once extern crate libc; is removed it breaks use crate::libc;.

I've done what I hope is a thorough review of librustc_resolve for where 2015/2018 diverge and have added a lint to the appropriate locations (hopefully). Now use libc; is not linted for and will continue to work in both the 2015 and 2018 editions.

re-r? @Manishearth

@@ -653,6 +654,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
return Some((directive.span,
"cannot glob-import all possible crates".to_string()));
}
GlobImport { .. } if self.session.features_untracked().extern_absolute_paths => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that was accidentally omitted from the lint entirely before, where use * is completely forbidden in 2018 and so this starts to lint about that in 2015.

Note that there's still a "bug" in the lint for "remove extern crate", I'll file a bug for that shortly

@alexcrichton
Copy link
Member Author

@bors: p=0

@alexcrichton
Copy link
Member Author

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned Manishearth May 14, 2018
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with either action taken

@@ -261,7 +261,7 @@ declare_lint! {
}

declare_lint! {
pub ABSOLUTE_PATH_STARTING_WITH_MODULE,
pub ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renaming would need to be backported or the old name put into the deprecated lint list

This commit fixes recommending the `crate` prefix when migrating to 2018 for
paths that look like `use foo;` or `use {bar, baz}`

Closes rust-lang#50660
@alexcrichton alexcrichton force-pushed the fix-single-item-path-warnings branch from ecb6964 to dff9ee1 Compare May 15, 2018 15:05
@alexcrichton
Copy link
Member Author

@bors: r=oli-ok

@bors
Copy link
Contributor

bors commented May 15, 2018

📌 Commit dff9ee1 has been approved by oli-ok

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 15, 2018
@alexcrichton
Copy link
Member Author

er,

@bors: r=oli-obk

@bors
Copy link
Contributor

bors commented May 15, 2018

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented May 15, 2018

📌 Commit dff9ee1 has been approved by oli-obk

@alexcrichton
Copy link
Member Author

@bors: p=1

relevant for the edition preview, so prioritizing

@bors
Copy link
Contributor

bors commented May 17, 2018

⌛ Testing commit dff9ee1 with merge ed9a29a...

bors added a commit that referenced this pull request May 17, 2018
…oli-obk

rustc: Fix `crate` lint for single-item paths

This commit fixes recommending the `crate` prefix when migrating to 2018 for
paths that look like `use foo;` or `use {bar, baz}`

Closes #50660
@bors
Copy link
Contributor

bors commented May 17, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: oli-obk
Pushing ed9a29a to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust-2018-preview Area: The 2018 edition preview S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2018 compatibility lint isn't firing for all imports that need to be rewritten
6 participants