Skip to content
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

fix more clippy findings #69802

Merged
merged 12 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
let haystack = self.haystack.as_bytes();
loop {
// get the haystack up to but not including the last character searched
let bytes = if let Some(slice) = haystack.get(self.finger..self.finger_back) {
slice
} else {
return None;
};
let bytes = haystack.get(self.finger..self.finger_back)?;
// the last byte of the utf8 encoded needle
// SAFETY: we have an invariant that `utf8_size < 5`
let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
Expand Down Expand Up @@ -575,11 +571,12 @@ macro_rules! pattern_methods {

#[inline]
fn is_suffix_of(self, haystack: &'a str) -> bool
where $t: ReverseSearcher<'a>
where
$t: ReverseSearcher<'a>,
{
($pmap)(self).is_suffix_of(haystack)
}
}
};
}

macro_rules! searcher_methods {
Expand Down Expand Up @@ -614,7 +611,7 @@ macro_rules! searcher_methods {
fn next_reject_back(&mut self) -> Option<(usize, usize)> {
self.0.next_reject_back()
}
}
};
}

/////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'hir> Map<'hir> {
}

pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
let node = if let Some(node) = self.find(hir_id) { node } else { return None };
let node = self.find(hir_id)?;

Some(match node {
Node::Item(item) => match item.kind {
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,7 @@ impl<'tcx> TyCtxt<'tcx> {
adt_did: DefId,
validate: &mut dyn FnMut(Self, DefId) -> Result<(), ErrorReported>,
) -> Option<ty::Destructor> {
let drop_trait = if let Some(def_id) = self.lang_items().drop_trait() {
def_id
} else {
return None;
};

let drop_trait = self.lang_items().drop_trait()?;
self.ensure().coherent_trait(drop_trait);

let mut dtor_did = None;
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,7 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
return None;
}

let matches = if let Some(matches) = handle_options(&args) {
matches
} else {
return None;
};

let matches = handle_options(&args)?;
let mut result = Vec::new();
let mut excluded_cargo_defaults = false;
for flag in ICE_REPORT_COMPILER_FLAGS {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
return AutoTraitResult::ExplicitImpl;
}

return tcx.infer_ctxt().enter(|mut infcx| {
return tcx.infer_ctxt().enter(|infcx| {
let mut fresh_preds = FxHashSet::default();

// Due to the way projections are handled by SelectionContext, we need to run
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {

let (full_env, full_user_env) = self
.evaluate_predicates(
&mut infcx,
&infcx,
trait_did,
ty,
new_env,
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_infer/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,7 @@ pub(super) fn specialization_graph_provider(
fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
use std::fmt::Write;

let trait_ref = if let Some(tr) = tcx.impl_trait_ref(impl_def_id) {
tr
} else {
return None;
};

let trait_ref = tcx.impl_trait_ref(impl_def_id)?;
let mut w = "impl".to_owned();

let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ fn create_generator_drop_shim<'tcx>(
// unrelated code from the resume part of the function
simplify::remove_dead_blocks(&mut body);

dump_mir(tcx, None, "generator_drop", &0, source, &mut body, |_, _| Ok(()));
dump_mir(tcx, None, "generator_drop", &0, source, &body, |_, _| Ok(()));

body
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn dump_matched_mir_node<'tcx>(
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
writeln!(file, "// source = {:?}", source)?;
writeln!(file, "// pass_name = {}", pass_name)?;
writeln!(file, "")?;
writeln!(file)?;
write_mir_fn(tcx, source, body, &mut file, result)?;
Ok(())
});
Expand All @@ -316,7 +316,7 @@ pub fn write_mir_fn<'tcx>(
write_basic_block(tcx, block, body, &mut |_, _| Ok(()), w)?;
print(w, " ", &result.outs)?;
if block.index() + 1 != body.basic_blocks().len() {
writeln!(w, "")?;
writeln!(w)?;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn dump_matched_mir_node<'tcx, F>(
if let Some(ref layout) = body.generator_layout {
writeln!(file, "// generator_layout = {:?}", layout)?;
}
writeln!(file, "")?;
writeln!(file)?;
extra_data(PassWhere::BeforeCFG, &mut file)?;
write_user_type_annotations(body, &mut file)?;
write_mir_fn(tcx, source, body, &mut extra_data, &mut file)?;
Expand Down Expand Up @@ -242,13 +242,13 @@ pub fn write_mir_pretty<'tcx>(
first = false;
} else {
// Put empty lines between all items
writeln!(w, "")?;
writeln!(w)?;
}

write_mir_fn(tcx, MirSource::item(def_id), body, &mut |_, _| Ok(()), w)?;

for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
writeln!(w, "")?;
writeln!(w)?;
let src = MirSource { instance: ty::InstanceDef::Item(def_id), promoted: Some(i) };
write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?;
}
Expand All @@ -271,7 +271,7 @@ where
extra_data(PassWhere::BeforeBlock(block), w)?;
write_basic_block(tcx, block, body, extra_data, w)?;
if block.index() + 1 != body.basic_blocks().len() {
writeln!(w, "")?;
writeln!(w)?;
}
}

Expand Down Expand Up @@ -529,7 +529,7 @@ pub fn write_mir_intro<'tcx>(
write_scope_tree(tcx, body, &scope_tree, w, OUTERMOST_SOURCE_SCOPE, 1)?;

// Add an empty line before the first block is printed.
writeln!(w, "")?;
writeln!(w)?;

Ok(())
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
}
};

match (
lifetime_names.len(),
lifetime_names.iter().next(),
snippet.as_ref().map(|s| s.as_str()),
) {
match (lifetime_names.len(), lifetime_names.iter().next(), snippet.as_deref()) {
(1, Some(name), Some("&")) => {
suggest_existing(err, format!("&{} ", name));
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2778,12 +2778,8 @@ impl<'a> Resolver<'a> {
} else {
let crate_id = if !speculative {
self.crate_loader.process_path_extern(ident.name, ident.span)
} else if let Some(crate_id) =
self.crate_loader.maybe_process_path_extern(ident.name, ident.span)
{
crate_id
} else {
return None;
self.crate_loader.maybe_process_path_extern(ident.name, ident.span)?
};
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
Some(
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_span/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,11 +1167,7 @@ impl SourceFile {
}

let begin = {
let line = if let Some(line) = self.lines.get(line_number) {
line
} else {
return None;
};
let line = self.lines.get(line_number)?;
let begin: BytePos = *line - self.start_pos;
begin.to_usize()
};
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ pub fn try_inline(
attrs: Option<Attrs<'_>>,
visited: &mut FxHashSet<DefId>,
) -> Option<Vec<clean::Item>> {
let did = if let Some(did) = res.opt_def_id() {
did
} else {
return None;
};
let did = res.opt_def_id()?;
if did.is_local() {
return None;
}
Expand Down Expand Up @@ -581,7 +577,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
name: ref _name,
},
ref bounds,
} => !(*s == "Self" && did == trait_did) && !bounds.is_empty(),
} => !(bounds.is_empty() || *s == "Self" && did == trait_did),
_ => true,
});
g
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,7 @@ pub fn plain_summary_line(md: &str) -> String {
type Item = String;

fn next(&mut self) -> Option<String> {
let next_event = self.inner.next();
if next_event.is_none() {
return None;
}
let next_event = next_event.unwrap();
let next_event = self.inner.next()?;
let (ret, is_in) = match next_event {
Event::Start(Tag::Paragraph) => (None, 1),
Event::Start(Tag::Heading(_)) => (None, 1),
Expand All @@ -870,7 +866,7 @@ pub fn plain_summary_line(md: &str) -> String {
}
let mut s = String::with_capacity(md.len() * 3 / 2);
let p = ParserWrapper { inner: Parser::new(md), is_in: 0, is_first: true };
p.into_iter().filter(|t| !t.is_empty()).for_each(|i| s.push_str(&i));
p.filter(|t| !t.is_empty()).for_each(|i| s.push_str(&i));
s
}

Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ impl Context {
}

if self.shared.sort_modules_alphabetically {
for (_, items) in &mut map {
for items in map.values_mut() {
items.sort();
}
}
Expand Down Expand Up @@ -3401,10 +3401,8 @@ fn render_assoc_items(
let deref_impl =
traits.iter().find(|t| t.inner_impl().trait_.def_id() == c.deref_trait_did);
if let Some(impl_) = deref_impl {
let has_deref_mut = traits
.iter()
.find(|t| t.inner_impl().trait_.def_id() == c.deref_mut_trait_did)
.is_some();
let has_deref_mut =
traits.iter().any(|t| t.inner_impl().trait_.def_id() == c.deref_mut_trait_did);
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut);
}

Expand Down Expand Up @@ -3816,7 +3814,7 @@ fn render_impl(
) {
for trait_item in &t.items {
let n = trait_item.name.clone();
if i.items.iter().find(|m| m.name == n).is_some() {
if i.items.iter().any(|m| m.name == n) {
continue;
}
let did = i.trait_.as_ref().unwrap().def_id().unwrap();
Expand Down
Loading