-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Lint uncallable function #54127
Closed
Closed
Lint uncallable function #54127
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e04872
Lint functions taking unhabited parameters with unreachable_code
varkor df3035a
Fix tests making use of uninhabited arguments
varkor 7d86754
Add test case for methods in traits that take uninhabited types
varkor 2c8f042
Add tests for privately/publicly uninhabited types in function signat…
varkor adac7a1
Allow unreachable_code for uncallable functions in WASM
varkor 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
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
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
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
// run-pass | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
// pretty-expanded FIXME #23616 | ||
#![allow(unreachable_code)] | ||
|
||
enum Foo { } | ||
enum Foo {} | ||
|
||
impl Drop for Foo { | ||
fn drop(&mut self) { } | ||
} | ||
|
||
fn foo(x: Foo) { } | ||
fn foo() { | ||
let _x: Foo = unimplemented!(); | ||
} | ||
|
||
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
// run-pass | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
// pretty-expanded FIXME #23616 | ||
#![allow(non_camel_case_types)] | ||
|
||
enum what { } | ||
enum Void {} | ||
|
||
fn what_to_string(x: what) -> String | ||
{ | ||
match x { | ||
} | ||
fn void() -> Void { | ||
unimplemented!() | ||
} | ||
|
||
pub fn main() | ||
{ | ||
fn void_to_string() -> String { | ||
match void() {} | ||
} | ||
|
||
pub 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,18 @@ | ||
warning: functions with parameters of uninhabited types are uncallable | ||
--> $DIR/issue-46855.rs:15:1 | ||
| | ||
LL | fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 } | ||
| ^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| this parameter has an uninhabited type | ||
| | ||
= note: #[warn(unreachable_code)] on by default | ||
|
||
warning: functions with parameters of uninhabited types are uncallable | ||
--> $DIR/issue-46855.rs:17:1 | ||
| | ||
LL | fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x } | ||
| ^^^^^^^--------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| this parameter has an uninhabited type | ||
|
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
// run-pass | ||
enum Void {} | ||
|
||
#[allow(unreachable_code)] | ||
fn foo(_: Result<(Void, u32), (Void, String)>) {} | ||
|
||
fn main() { | ||
let _: fn(_) = foo; | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
src/test/ui/uninhabited/uninhabited-function-parameter-warning.rs
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,41 @@ | ||
#![deny(unreachable_code)] | ||
|
||
enum Void {} | ||
|
||
mod hide { | ||
pub struct PrivatelyUninhabited(::Void); | ||
|
||
pub struct PubliclyUninhabited(pub ::Void); | ||
} | ||
|
||
// Check that functions with (publicly) uninhabited parameters trigger a lint. | ||
|
||
fn foo(a: (), b: Void) { //~ ERROR functions with parameters of uninhabited types are uncallable | ||
a | ||
} | ||
|
||
fn bar(a: (), b: hide::PrivatelyUninhabited) { // ok | ||
a | ||
} | ||
|
||
fn baz(a: (), b: hide::PubliclyUninhabited) { | ||
//~^ ERROR functions with parameters of uninhabited types are uncallable | ||
a | ||
} | ||
|
||
// Check that trait methods with uninhabited parameters do not trigger a lint | ||
// (at least for now). | ||
|
||
trait Foo { | ||
fn foo(a: Self); | ||
|
||
fn bar(b: Void); | ||
} | ||
|
||
impl Foo for Void { | ||
fn foo(a: Void) {} // ok | ||
|
||
fn bar(b: Void) {} // ok | ||
} | ||
|
||
fn main() {} |
31 changes: 31 additions & 0 deletions
31
src/test/ui/uninhabited/uninhabited-function-parameter-warning.stderr
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,31 @@ | ||
error: functions with parameters of uninhabited types are uncallable | ||
--> $DIR/uninhabited-function-parameter-warning.rs:13:1 | ||
| | ||
LL | fn foo(a: (), b: Void) { //~ ERROR functions with parameters of uninhabited types are uncallable | ||
| ^ - this parameter has an uninhabited type | ||
| _| | ||
| | | ||
LL | | a | ||
LL | | } | ||
| |_^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/uninhabited-function-parameter-warning.rs:1:9 | ||
| | ||
LL | #![deny(unreachable_code)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: functions with parameters of uninhabited types are uncallable | ||
--> $DIR/uninhabited-function-parameter-warning.rs:21:1 | ||
| | ||
LL | fn baz(a: (), b: hide::PubliclyUninhabited) { | ||
| ^ - this parameter has an uninhabited type | ||
| _| | ||
| | | ||
LL | | //~^ ERROR functions with parameters of uninhabited types are uncallable | ||
LL | | a | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In its previous form, it was taking an uninhabited type as an argument, so the new lint was kicking in. Since #3037 was about matching on uninhabited types, it felt clearer to rewrite it like this rather than ignore the lint (since eventually we could be more aggressive about functions taking uninhabited types).