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

"crate-ify" paths that begin with a renamed crate #51010

Merged

Conversation

nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented May 23, 2018

This does two things:

  • crate-ify paths that begin with a renamed crate (i.e., add crate::) to the front

Fixes #50996

I also added tests for a few other scenarios.

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2018
@nikomatsakis nikomatsakis force-pushed the issue-50996-renamed-extern-crate branch from f7890fa to 3c79a07 Compare May 23, 2018 21:45
@nikomatsakis
Copy link
Contributor Author

Maybe I should split out the unused_extern_crates stuff into a different PR. Have to run now but might do that later. Will also file follow-up issues.

@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.
    100% |████████████████████████████████| 4.2MB 298kB/s 
Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/a0/70/2c27740f08e477499ce19eefe05dbcae6f19fdc49e9e82ce4768be0643b9/pyasn1-0.4.3-py2.py3-none-any.whl (72kB)
    14% |████▌                           | 10kB 42.9MB/s eta 0:00:01
    28% |█████████                       | 20kB 43.1MB/s eta 0:00:01
    42% |█████████████▌                  | 30kB 50.4MB/s eta 0:00:01
    56% |██████████████████              | 40kB 54.5MB/s eta 0:00:01
---
[00:47:39] ....................................................................................................
[00:47:44] ....................................................................................................
[00:47:50] ...........................................................................i........................
[00:47:55] ....................................................i...............................................
[00:48:00] ........................................................................ii..................F.......
[00:48:06] ......F.............................................................................................
[00:48:12] ...................................................................................i................
[00:48:15] .iiiiiiiii...................................................
[00:48:15] 
[00:48:15] ---- [ui] ui/rfc-2166-underscore-imports/basic.rs stdout ----
[00:48:15] diff of stderr:
[00:48:15] 
[00:48:15] 
[00:48:15] 20   --> $DIR/basic.rs:33:5
[00:48:15] 21    |
[00:48:15] 22 LL |     extern crate core as _; //~ WARN unused extern crate
[00:48:15] +    |     ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
[00:48:15] 24    |
[00:48:15] 25 note: lint level defined here
[00:48:15] 26   --> $DIR/basic.rs:14:25
[00:48:15] 26   --> $DIR/basic.rs:14:25
[00:48:15] 
[00:48:15] 
[00:48:15] The actual stderr differed from the expected stderr.
[00:48:15] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2166-underscore-imports/basic/basic.stderr
[00:48:15] To update references, rerun the tests and pass the `--bless` flag
[00:48:15] To only update this specific test, also pass `--test-args rfc-2166-underscore-imports/basic.rs`
[00:48:15] error: 1 errors occurred comparing output.
[00:48:15] status: exit code: 0
[00:48:15] status: exit code: 0
[00:48:15] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2166-underscore-imports/basic/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2166-underscore-imports/basic/auxiliary" "-A" "unused"
[00:48:15] ------------------------------------------
[00:48:15] 
[00:48:15] ------------------------------------------
[00:48:15] stderr:
[00:48:15] stderr:
[00:48:15] ------------------------------------------
[00:48:15] {"message":"unused import: `m::Tr1 as _`","code":{"code":"unused_imports","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":782,"byte_end":793,"line_start":31,"line_end":31,"column_start":9,"column_end":20,"is_primary":true,"text":[{"text":"    use m::Tr1 as _; //~ WARN unused import","highlight_start":9,"highlight_end":20}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":524,"byte_end":538,"line_start":14,"line_end":14,"column_start":9,"column_end":23,"is_primary":true,"text":[{"text":"#![warn(unused_imports, unused_extern_crates)]","highlight_start":9,"highlight_end":23}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null}],"rendered":"warning: unused import: `m::Tr1 as _`\n  --> /checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs:31:9\n   |\nLL |     use m::Tr1 as _; //~ WARN unused import\n   |         ^^^^^^^^^^^\n   |\nnote: lint level defined here\n  --> /checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs:14:9\n   |\nLL | #![warn(unused_imports, unused_extern_crates)]\n   |         ^^^^^^^^^^^^^^\n\n"}
[00:48:15] {"message":"unused import: `S as _`","code":{"code":"unused_imports","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":826,"byte_end":832,"line_start":32,"line_end":32,"column_start":9,"column_end":15,"is_primary":true,"text":[{"text":"    use S as _; //~ WARN unused import","highlight_start":9,"highlight_end":15}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: unused import: `S as _`\n  --> /checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs:32:9\n   |\nLL |     use S as _; //~ WARN unused import\n   |         ^^^^^^\n\n"}
[00:48:15] {"message":"unused extern crate","code":{"code":"unused_extern_crates","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":861,"byte_end":884,"line_start":33,"line_end":33,"column_start":5,"column_end":28,"is_primary":true,"text":[{"text":"    extern crate core as _; //~ WARN unused extern crate","highlight_start":5,"highlight_end":28}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":540,"byte_end":560,"line_start":14,"line_end":14,"column_start":25,"column_end":45,"is_primary":true,"text":[{"text":"#![warn(unused_imports, unused_extern_crates)]","highlight_start":25,"highlight_end":45}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove it","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs","byte_start":861,"byte_end":884,"line_start":33,"line_end":33,"column_start":5,"column_end":28,"is_primary":true,"text":[{"text":"    extern crate core as _; //~ WARN unused extern crate","highlight_start":5,"highlight_end":28}],"label":null,"suggested_replacement":"","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"warning: unused extern crate\n  --> /checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs:33:5\n   |\nLL |     extern crate core as _; //~ WARN unused extern crate\n   |     ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it\n   |\nnote: lint level defined here\n  --> /checkout/src/test/ui/rfc-2166-underscore-imports/basic.rs:14:25\n   |\nLL | #![warn(unused_imports, unused_extern_crates)]\n   |                         ^^^^^^^^^^^^^^^^^^^^\n\n"}
[00:48:15] ------------------------------------------
[00:48:15] 
[00:48:15] thread '[ui] ui/rfc-2166-underscore-imports/basic.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3044:9
[00:48:15] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:48:15] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:48:15] 
[00:48:15] ---- [ui] ui/rust-2018/extern-crate-idiomatic-in-2018.rs stdout ----
[00:48:15] diff of fixed:
[00:48:15] 
[00:48:15] 26 extern crate edition_lint_paths as bar;
[00:48:15] 27 
[00:48:15] 28 fn main() {
[00:48:15] +     // This is not considered to *use* the `extern crate` in Rust 2018:
[00:48:15] 29     use edition_lint_paths::foo;
[00:48:15] 30     foo();
[00:48:15] + 
[00:48:15] +     // But this should be a use of the (renamed) crate:
[00:48:15] 31     crate::bar::foo();
[00:48:15] 32 }
[00:48:15] 
[00:48:15] 
[00:48:15] The actual fixed differed from the expected fixed.
[00:48:15] The actual fixed differed from the expected fixed.
[00:48:15] Actual fixed saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rust-2018/extern-crate-idiomatic-in-2018/extern-crate-idiomatic-in-2018.fixed
[00:48:15] To update references, rerun the tests and pass the `--bless` flag
[00:48:15] To only update this specific test, also pass `--test-args rust-2018/extern-crate-idiomatic-in-2018.rs`
[00:48:15] error: 1 errors occurred comparing output.
[00:48:15] status: exit code: 101
[00:48:15] status: exit code: 101
[00:48:15] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rust-2018/extern-crate-idiomatic-in-2018/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition" "2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rust-2018/extern-crate-idiomatic-in-2018/auxiliary" "-A" "unused"
[00:48:15] ------------------------------------------
[00:48:15] 
[00:48:15] ------------------------------------------
[00:48:15] stderr:
[00:48:15] stderr:
[00:48:15] ------------------------------------------
[00:48:15] {"message":"unused extern crate","code":{"code":"unused_extern_crates","explanation":null},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs","byte_start":771,"byte_end":803,"line_start":23,"line_end":23,"column_start":1,"column_end":33,"is_primary":true,"text":[{"text":"extern crate edition_lint_paths;","highlight_start":1,"highlight_end":33}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs","byte_start":726,"byte_end":746,"line_start":20,"line_end":20,"column_start":9,"column_end":29,"is_primary":true,"text":[{"text":"#![deny(unused_extern_crates)]","highlight_start":9,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove it","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs","byte_start":771,"byte_end":803,"line_start":23,"line_end":23,"column_start":1,"column_end":33,"is_primary":true,"text":[{"text":"extern crate edition_lint_paths;","highlight_start":1,"highlight_end":33}],"label":null,"suggested_replacement":"","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unused extern crate\n  --> /checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs:23:1\n   |\nLL | extern crate edition_lint_paths;\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it\n   |\nnote: lint level defined here\n  --> /checkout/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs:20:9\n   |\nLL | #![deny(unused_extern_crates)]\n   |         ^^^^^^^^^^^^^^^^^^^^\n\n"}
[00:48:15] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:48:15] ------------------------------------------
[00:48:15] 
[00:48:15] 
[00:48:15] thread '[ui] ui/rust-2018/extern-crate-idiomatic-in-2018.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3044:9
[00:48:15] 
[00:48:15] failures:
[00:48:15]     [ui] ui/rfc-2166-underscore-imports/basic.rs
[00:48:15]     [ui] ui/rfc-2166-underscore-imports/basic.rs
[00:48:15]     [ui] ui/rust-2018/extern-crate-idiomatic-in-2018.rs
[00:48:15] test result: FAILED. 1443 passed; 2 failed; 16 ignored; 0 measured; 0 filtered out
[00:48:15] 
[00:48:15] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.

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
Copy link
Member

r=me with Travis fixed

@nikomatsakis nikomatsakis force-pushed the issue-50996-renamed-extern-crate branch 3 times, most recently from 3ee1606 to 2249d65 Compare May 24, 2018 00:10
@nikomatsakis
Copy link
Contributor Author

@bors r=acrichto p=1

Giving high priority because edition lints.

@bors
Copy link
Contributor

bors commented May 24, 2018

📌 Commit 2249d65 has been approved by acrichto

@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 24, 2018
@bors
Copy link
Contributor

bors commented May 24, 2018

⌛ Testing commit 2249d65 with merge 242195d...

bors added a commit that referenced this pull request May 24, 2018
… r=acrichto

"crate-ify" paths that begin with a renamed crate

This does two things:

- crate-ify paths that begin with a renamed crate (i.e., add `crate::`) to the front

Fixes #50996

I also added tests for a few other scenarios.

r? @alexcrichton
@bors
Copy link
Contributor

bors commented May 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: acrichto
Pushing 242195d to master...

@bors bors merged commit 2249d65 into rust-lang:master May 24, 2018
bors added a commit that referenced this pull request Jun 2, 2018
…diom, r=alexcrichton

merge unused-extern-crate and unnecessary-extern-crate lints

Extend the `unused_extern_crates` lint to offer a suggestion to remove the extern crate and remove the `unnecessary_extern_crate` lint.

Still a few minor issues to fix:
- [x] this *does* now leave a blank line... (defer to #51176)
  - idea: extend the span to be replaced by 1 character if the next character is a `\n`
- [x] what about macros? do we need to watch out for that? (defer to #48704)
- [x] also it doesn't work for `extern crate foo; fn main() { foo::bar(); }`
  - this is subtle: the `foo` might be shadowing a glob import too, can't always remove
  - defer to #51177
- [x] we also don't do the `pub use` rewrite thang (#51013)

Spun off from #51010

Fixes #50672

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants