-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #8896 - Alexendoo:fn_sig_ice, r=llogiq
Only return `DefId`s to `Fn`-like definitions in `clippy_utils::fn_def_id` Fixes #8850 in `returns.rs` `tcx.fn_sig` is called on the result of `fn_def_id`, which panics if the def is a `const`/`static`/etc rather than a functions definition https://github.com/rust-lang/rust-clippy/blob/bc4d39e5fea64970dded1e6d2132d41435c0ef24/clippy_lints/src/returns.rs#L294-L303 changelog: Fix ICE due to callable `static`/`const`s
- Loading branch information
Showing
3 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
fn fn_pointer_static() -> usize { | ||
static FN: fn() -> usize = || 1; | ||
let res = FN() + 1; | ||
res | ||
} | ||
|
||
fn fn_pointer_const() -> usize { | ||
const FN: fn() -> usize = || 1; | ||
let res = FN() + 1; | ||
res | ||
} | ||
|
||
fn deref_to_dyn_fn() -> usize { | ||
struct Derefs; | ||
impl std::ops::Deref for Derefs { | ||
type Target = dyn Fn() -> usize; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&|| 2 | ||
} | ||
} | ||
static FN: Derefs = Derefs; | ||
let res = FN() + 1; | ||
res | ||
} | ||
|
||
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,45 @@ | ||
error: returning the result of a `let` binding from a block | ||
--> $DIR/ice-8850.rs:4:5 | ||
| | ||
LL | let res = FN() + 1; | ||
| ------------------- unnecessary `let` binding | ||
LL | res | ||
| ^^^ | ||
| | ||
= note: `-D clippy::let-and-return` implied by `-D warnings` | ||
help: return the expression directly | ||
| | ||
LL ~ | ||
LL ~ FN() + 1 | ||
| | ||
|
||
error: returning the result of a `let` binding from a block | ||
--> $DIR/ice-8850.rs:10:5 | ||
| | ||
LL | let res = FN() + 1; | ||
| ------------------- unnecessary `let` binding | ||
LL | res | ||
| ^^^ | ||
| | ||
help: return the expression directly | ||
| | ||
LL ~ | ||
LL ~ FN() + 1 | ||
| | ||
|
||
error: returning the result of a `let` binding from a block | ||
--> $DIR/ice-8850.rs:24:5 | ||
| | ||
LL | let res = FN() + 1; | ||
| ------------------- unnecessary `let` binding | ||
LL | res | ||
| ^^^ | ||
| | ||
help: return the expression directly | ||
| | ||
LL ~ | ||
LL ~ FN() + 1 | ||
| | ||
|
||
error: aborting due to 3 previous errors | ||
|