Auto merge of #79817 - LingMan:if_map, r=lcnr
Replace simple `if let` constructs with Option::map Replaces a few constructs of the form ``` if let Some(x) = var { Some(...) } else { None } ``` with calls to `Option::map`. `@rustbot` modify labels +C-cleanup +T-compiler
This commit is contained in:
commit
5e6e1e33a1
|
@ -361,11 +361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
|
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
|
||||||
if let Some(stripped) = s.strip_prefix(old) {
|
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
|
||||||
Some(new.to_string() + stripped)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is used to determine potential "simple" improvements or users' errors and
|
/// This function is used to determine potential "simple" improvements or users' errors and
|
||||||
|
@ -587,47 +583,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
hir::Mutability::Mut => {
|
hir::Mutability::Mut => {
|
||||||
let new_prefix = "&mut ".to_owned() + derefs;
|
let new_prefix = "&mut ".to_owned() + derefs;
|
||||||
match mutbl_a {
|
match mutbl_a {
|
||||||
hir::Mutability::Mut => {
|
hir::Mutability::Mut => self
|
||||||
if let Some(s) =
|
.replace_prefix(&src, "&mut ", &new_prefix)
|
||||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
.map(|s| (s, Applicability::MachineApplicable)),
|
||||||
{
|
hir::Mutability::Not => self
|
||||||
Some((s, Applicability::MachineApplicable))
|
.replace_prefix(&src, "&", &new_prefix)
|
||||||
} else {
|
.map(|s| (s, Applicability::Unspecified)),
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hir::Mutability::Not => {
|
|
||||||
if let Some(s) =
|
|
||||||
self.replace_prefix(&src, "&", &new_prefix)
|
|
||||||
{
|
|
||||||
Some((s, Applicability::Unspecified))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::Mutability::Not => {
|
hir::Mutability::Not => {
|
||||||
let new_prefix = "&".to_owned() + derefs;
|
let new_prefix = "&".to_owned() + derefs;
|
||||||
match mutbl_a {
|
match mutbl_a {
|
||||||
hir::Mutability::Mut => {
|
hir::Mutability::Mut => self
|
||||||
if let Some(s) =
|
.replace_prefix(&src, "&mut ", &new_prefix)
|
||||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
.map(|s| (s, Applicability::MachineApplicable)),
|
||||||
{
|
hir::Mutability::Not => self
|
||||||
Some((s, Applicability::MachineApplicable))
|
.replace_prefix(&src, "&", &new_prefix)
|
||||||
} else {
|
.map(|s| (s, Applicability::MachineApplicable)),
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hir::Mutability::Not => {
|
|
||||||
if let Some(s) =
|
|
||||||
self.replace_prefix(&src, "&", &new_prefix)
|
|
||||||
{
|
|
||||||
Some((s, Applicability::MachineApplicable))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
|
|
Loading…
Reference in a new issue