-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Keep rename-imported main alive in dead-code analysis under --test
#157646
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
tests/ui/lint/dead-code/imported_main_dead_code_under_test.rs
|
mu001999 marked this conversation as resolved.
|
This file contains hidden or 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,13 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: --test | ||
|
|
||
| // Regression test for https://github.com/rust-lang/rust/issues/157608: a function used | ||
| // as `main` via a rename import was wrongly reported as dead code under `--test`. | ||
|
|
||
| #![deny(dead_code)] | ||
|
|
||
| fn different_main() { | ||
| println!("Hello from different_main"); | ||
| } | ||
|
|
||
| use different_main as main; |
This file contains hidden or 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,10 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: --test | ||
|
|
||
| #![deny(dead_code)] | ||
|
|
||
| mod m { | ||
| pub fn main() {} | ||
| } | ||
|
|
||
| use m::*; |
This file contains hidden or 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,10 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: --test | ||
|
|
||
| #![deny(dead_code)] | ||
|
|
||
| mod m { | ||
| pub fn main() {} | ||
| } | ||
|
|
||
| use m::main; |
11 changes: 11 additions & 0 deletions
11
tests/ui/lint/dead-code/imported_main_renamed_from_mod_under_test.rs
This file contains hidden or 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,11 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: --test | ||
|
|
||
|
|
||
| #![deny(dead_code)] | ||
|
|
||
| mod m { | ||
| pub fn other() {} | ||
| } | ||
|
|
||
| use m::other as main; |
This file contains hidden or 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,22 @@ | ||
| //@ compile-flags: --test | ||
|
|
||
| // A `fn main` demoted by an explicit `#[rustc_main]` on another function is dead code and | ||
| // must be flagged under `--test` just like in a normal build. | ||
|
|
||
| #![allow(unused_variables)] | ||
| #![deny(dead_code)] | ||
| #![feature(rustc_attrs)] | ||
|
|
||
| fn dead_fn() {} //~ ERROR: function `dead_fn` is never used | ||
|
|
||
| fn used_fn() {} | ||
|
|
||
| #[rustc_main] | ||
| fn actual_main() { | ||
| used_fn(); | ||
| } | ||
|
|
||
| // this is not main | ||
| fn main() { //~ ERROR: function `main` is never used | ||
| dead_fn(); | ||
| } |
20 changes: 20 additions & 0 deletions
20
tests/ui/lint/dead-code/lint-dead-code-2-under-test.stderr
This file contains hidden or 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,20 @@ | ||
| error: function `dead_fn` is never used | ||
| --> $DIR/lint-dead-code-2-under-test.rs:10:4 | ||
| | | ||
| LL | fn dead_fn() {} | ||
| | ^^^^^^^ | ||
| | | ||
| note: the lint level is defined here | ||
| --> $DIR/lint-dead-code-2-under-test.rs:7:9 | ||
| | | ||
| LL | #![deny(dead_code)] | ||
| | ^^^^^^^^^ | ||
|
|
||
| error: function `main` is never used | ||
| --> $DIR/lint-dead-code-2-under-test.rs:20:4 | ||
| | | ||
| LL | fn main() { | ||
| | ^^^^ | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
9 changes: 9 additions & 0 deletions
9
tests/ui/lint/dead-code/submodule_main_not_entry_under_test.rs
This file contains hidden or 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,9 @@ | ||
| //@ compile-flags: --test | ||
|
|
||
| #![deny(dead_code)] | ||
|
|
||
| fn main() {} | ||
|
|
||
| mod m { | ||
| pub fn main() {} //~ ERROR: function `main` is never used | ||
| } |
14 changes: 14 additions & 0 deletions
14
tests/ui/lint/dead-code/submodule_main_not_entry_under_test.stderr
This file contains hidden or 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,14 @@ | ||
| error: function `main` is never used | ||
| --> $DIR/submodule_main_not_entry_under_test.rs:8:12 | ||
| | | ||
| LL | pub fn main() {} | ||
| | ^^^^ | ||
| | | ||
| note: the lint level is defined here | ||
| --> $DIR/submodule_main_not_entry_under_test.rs:3:9 | ||
| | | ||
| LL | #![deny(dead_code)] | ||
| | ^^^^^^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.