-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
The rewrites suggested by question_mark
do not work correctly inside try
blocks (unstable with #![feature(try_blocks)]
), since ?
exits the try
block rather than the function.
I don't know what the policy is for unstable features, so just close this if it's irrelevant.
Lint Name
question_mark
Reproducer
With the following function,
fn foo1(a: Option<u32>) -> Option<u32> {
let b: Option<u32> = try {
if a.is_none() {
return None;
}
32
};
b.or(Some(128))
}
Clippy suggests rewriting it as
fn foo2(a: Option<u32>) -> Option<u32> {
let b: Option<u32> = try {
a?;
32
};
b.or(Some(128))
}
However, foo1(None)
gives None
, while foo2(None)
gives Some(128)
, which is not the same.
Version
rustc 1.61.0-nightly (9f4dc0b4d 2022-03-23)
binary: rustc
commit-hash: 9f4dc0b4db892271cd0dada6e072775b5b5d6b1e
commit-date: 2022-03-23
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
Additional Labels
@rustbot label +I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
question_mark
]: don't lint inside oftry
block #11001Auto merge of #11001 - y21:issue8628, r=Jarcho