-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #50260 - Manishearth:no-extern-crate, r=nikomatsakis
idiom lints for removing `extern crate` Based off of #49789 This contains two lints: - One that suggests replacing pub extern crates with pub use, and removing non-pub extern crates entirely - One that suggests rewriting `use modulename::...::cratename::foo` as `cratename::foo` The latter is a bit tricky to emit suggestions for; for one this involves splicing spans (never a good idea), and it also won't be able to correctly handle `use module::{cratename, foo}` and use-trees. I'm not sure how to proceed here. Currently it doesn't suggest anything at all. Perhaps we can go the other way and suggest removal of all extern crates _except_ those used through modules (stash node ids somewhere) and suggest replacing those with `<visibility> use`? r? @nikomatsakis fixes #48719
- Loading branch information
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2015 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. | ||
|
||
#![deny(unnecessary_extern_crate)] | ||
#![feature(alloc, test, libc)] | ||
|
||
extern crate alloc; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP remove | ||
extern crate alloc as x; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `use` | ||
|
||
#[macro_use] | ||
extern crate test; | ||
pub extern crate test as y; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `pub use` | ||
pub extern crate libc; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `pub use` | ||
|
||
|
||
mod foo { | ||
extern crate alloc; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `use` | ||
extern crate alloc as x; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `use` | ||
pub extern crate test; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `pub use` | ||
pub extern crate test as y; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `pub use` | ||
mod bar { | ||
extern crate alloc; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `use` | ||
extern crate alloc as x; | ||
//~^ ERROR `extern crate` is unnecessary in the new edition | ||
//~| HELP use `use` | ||
} | ||
} | ||
|
||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:14:1 | ||
| | ||
LL | extern crate alloc; | ||
| ^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| | ||
note: lint level defined here | ||
--> $DIR/unnecessary-extern-crate.rs:11:9 | ||
| | ||
LL | #![deny(unnecessary_extern_crate)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:17:1 | ||
| | ||
LL | extern crate alloc as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:23:1 | ||
| | ||
LL | pub extern crate test as y; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:26:1 | ||
| | ||
LL | pub extern crate libc; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use libc` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:32:5 | ||
| | ||
LL | extern crate alloc; | ||
| ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:35:5 | ||
| | ||
LL | extern crate alloc as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:38:5 | ||
| | ||
LL | pub extern crate test; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:41:5 | ||
| | ||
LL | pub extern crate test as y; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:45:9 | ||
| | ||
LL | extern crate alloc; | ||
| ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` | ||
|
||
error: `extern crate` is unnecessary in the new edition | ||
--> $DIR/unnecessary-extern-crate.rs:48:9 | ||
| | ||
LL | extern crate alloc as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` | ||
|
||
error: aborting due to 10 previous errors | ||
|