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

couple more clippy fixes (let_and_return, if_same_then_else) #70254

Merged
merged 2 commits into from
Mar 22, 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
3 changes: 1 addition & 2 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ mod hack {
unsafe {
let len = b.len();
let b = Box::into_raw(b);
let xs = Vec::from_raw_parts(b as *mut T, len, len);
xs
Vec::from_raw_parts(b as *mut T, len, len)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,7 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
};

let map = tcx.arena.alloc(IndexedHir { crate_hash, map });

map
tcx.arena.alloc(IndexedHir { crate_hash, map })
}

/// Identical to the `PpAnn` implementation for `hir::Crate`,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_ssa/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ fn get_rpaths(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
rpaths.extend_from_slice(&fallback_rpaths);

// Remove duplicates
let rpaths = minimize_rpaths(&rpaths);

rpaths
minimize_rpaths(&rpaths)
}

fn get_rpaths_relative_to_output(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules).unwrap_or_else(|e| e.raise())
};

let result = lto_modules
lto_modules
.into_iter()
.map(|module| {
let cost = module.cost();
Expand All @@ -303,9 +303,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
0,
)
}))
.collect();

result
.collect()
}

pub struct CompiledModules {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
// avoid allocations in those cases. We also don't use `indices` to
// determine if a kind has been seen before until the limit of 8 has
// been exceeded, to also avoid allocations for `indices`.
let var = if !var_values.spilled() {
if !var_values.spilled() {
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
// direct linear search of `var_values`.
if let Some(idx) = var_values.iter().position(|&k| k == kind) {
Expand Down Expand Up @@ -589,9 +589,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
assert_eq!(variables.len(), var_values.len());
BoundVar::new(variables.len() - 1)
})
};

var
}
}

/// Shorthand helper that creates a canonical region variable for
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_metadata/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ mod dl {
let result = f();

let last_error = libc::dlerror() as *const _;
let ret = if ptr::null() == last_error {
if ptr::null() == last_error {
Ok(result)
} else {
let s = CStr::from_ptr(last_error).to_bytes();
Err(str::from_utf8(s).unwrap().to_owned())
};

ret
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
..
} = self.builder;
*rev_lookup.projections.entry((base, elem.lift())).or_insert_with(move || {
let path = MoveDataBuilder::new_move_path(
MoveDataBuilder::new_move_path(
move_paths,
path_map,
init_path_map,
Some(base),
mk_place(*tcx),
);
path
)
})
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
where
F: FnOnce(&mut Self) -> InterpResult<'tcx, T>,
{
let r = match f(self) {
match f(self) {
Ok(val) => Some(val),
Err(error) => {
// Some errors shouldn't come up because creating them causes
Expand All @@ -414,8 +414,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
);
None
}
};
r
}
}

fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
Expand Down
12 changes: 4 additions & 8 deletions src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,12 @@ impl<'a> StringReader<'a> {
rustc_lexer::TokenKind::LineComment => {
let string = self.str_from(start);
// comments with only more "/"s are not doc comments
let tok = if comments::is_line_doc_comment(string) {
if comments::is_line_doc_comment(string) {
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
token::DocComment(Symbol::intern(string))
} else {
token::Comment
};

tok
}
}
rustc_lexer::TokenKind::BlockComment { terminated } => {
let string = self.str_from(start);
Expand All @@ -204,14 +202,12 @@ impl<'a> StringReader<'a> {
self.fatal_span_(start, last_bpos, msg).raise();
}

let tok = if is_doc_comment {
if is_doc_comment {
self.forbid_bare_cr(start, string, "bare CR not allowed in block doc-comment");
token::DocComment(Symbol::intern(string))
} else {
token::Comment
};

tok
}
}
rustc_lexer::TokenKind::Whitespace => token::Whitespace,
rustc_lexer::TokenKind::Ident | rustc_lexer::TokenKind::RawIdent => {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_parse/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,7 @@ impl<'a> Parser<'a> {

/// Parses the RHS of a local variable declaration (e.g., '= 14;').
fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> {
if self.eat(&token::Eq) {
Ok(Some(self.parse_expr()?))
} else if skip_eq {
Ok(Some(self.parse_expr()?))
} else {
Ok(None)
}
if self.eat(&token::Eq) || skip_eq { Ok(Some(self.parse_expr()?)) } else { Ok(None) }
}

/// Parses a block. No inner attributes are allowed.
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ crate struct ImportSuggestion {
/// `source_map` functions and this function to something more robust.
fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
let impl_span = sm.span_until_char(impl_span, '<');
let impl_span = sm.span_until_whitespace(impl_span);
impl_span
sm.span_until_whitespace(impl_span)
}

impl<'a> Resolver<'a> {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,16 +1871,15 @@ impl<'a> Resolver<'a> {
// No adjustments
}
}
let result = self.resolve_ident_in_module_unadjusted_ext(
self.resolve_ident_in_module_unadjusted_ext(
module,
ident,
ns,
adjusted_parent_scope,
false,
record_used,
path_span,
);
result
)
}

fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,16 +1069,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
});

let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| {
let t = match flds {
Some(ref fs) if i < fs.len() => {
let ety = fs[i].expect_ty();
self.check_expr_coercable_to_type(&e, ety);
ety
}
_ => self.check_expr_with_expectation(&e, NoExpectation),
};
t
let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| match flds {
Some(ref fs) if i < fs.len() => {
let ety = fs[i].expect_ty();
self.check_expr_coercable_to_type(&e, ety);
ety
}
_ => self.check_expr_with_expectation(&e, NoExpectation),
});
let tuple = self.tcx.mk_tup(elt_ts_iter);
if tuple.references_error() {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3654,14 +3654,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Otherwise, fall back to the immutable version.
let (imm_tr, imm_op) = self.resolve_place_op(op, false);
let method = match (method, imm_tr) {
match (method, imm_tr) {
(None, Some(trait_did)) => {
self.lookup_method_in_trait(span, imm_op, trait_did, base_ty, Some(arg_tys))
}
(method, _) => method,
};

method
}
}

fn check_method_argument_types(
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
}

pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<String> {
let value = cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
let ty = cx.tcx.type_of(def_id);
match (val, &ty.kind) {
(_, &ty::Ref(..)) => None,
Expand All @@ -518,9 +518,7 @@ pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<Strin
}
_ => None,
}
});

value
})
}

fn format_integer_with_underscore_sep(num: &str) -> String {
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,12 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
}

fn get_index_type(clean_type: &clean::Type) -> RenderType {
let t = RenderType {
RenderType {
ty: clean_type.def_id(),
idx: None,
name: get_index_type_name(clean_type, true).map(|s| s.to_ascii_lowercase()),
generics: get_generics(clean_type),
};
t
}
}

fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option<String> {
Expand Down