Rollup merge of #70229 - matthiaskrgr:cl3ppy, r=Mark-Simulacrum
more clippy fixes * remove unused unit values (clippy::unused_unit) * make some let-if-bindings more idiomatic (clippy::useless_let_if_seq) * clarify when we pass () to functions (clippy::unit_arg) * don't redundantly repeat field names (clippy::redundant_field_names) * remove redundant returns (clippy::needless_return) * use let instead of match for matches with single bindings (clippy::match_single_binding) * don't convert results to options just for matching (clippy::if_let_some_result)
This commit is contained in:
commit
e58fec0c1c
|
@ -381,12 +381,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
// Field 5 would be the first element, so memory_index is i:
|
||||
// Note: if we didn't optimize, it's already right.
|
||||
|
||||
let memory_index;
|
||||
if optimize {
|
||||
memory_index = invert_mapping(&inverse_memory_index);
|
||||
} else {
|
||||
memory_index = inverse_memory_index;
|
||||
}
|
||||
let memory_index =
|
||||
if optimize { invert_mapping(&inverse_memory_index) } else { inverse_memory_index };
|
||||
|
||||
let size = min_size.align_to(align.abi);
|
||||
let mut abi = Abi::Aggregate { sized };
|
||||
|
@ -944,33 +940,33 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
let offset = st[i].fields.offset(field_index) + niche.offset;
|
||||
let size = st[i].size;
|
||||
|
||||
let mut abi = match st[i].abi {
|
||||
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
|
||||
Abi::ScalarPair(ref first, ref second) => {
|
||||
// We need to use scalar_unit to reset the
|
||||
// valid range to the maximal one for that
|
||||
// primitive, because only the niche is
|
||||
// guaranteed to be initialised, not the
|
||||
// other primitive.
|
||||
if offset.bytes() == 0 {
|
||||
Abi::ScalarPair(
|
||||
niche_scalar.clone(),
|
||||
scalar_unit(second.value),
|
||||
)
|
||||
} else {
|
||||
Abi::ScalarPair(
|
||||
scalar_unit(first.value),
|
||||
niche_scalar.clone(),
|
||||
)
|
||||
let abi = if st.iter().all(|v| v.abi.is_uninhabited()) {
|
||||
Abi::Uninhabited
|
||||
} else {
|
||||
match st[i].abi {
|
||||
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
|
||||
Abi::ScalarPair(ref first, ref second) => {
|
||||
// We need to use scalar_unit to reset the
|
||||
// valid range to the maximal one for that
|
||||
// primitive, because only the niche is
|
||||
// guaranteed to be initialised, not the
|
||||
// other primitive.
|
||||
if offset.bytes() == 0 {
|
||||
Abi::ScalarPair(
|
||||
niche_scalar.clone(),
|
||||
scalar_unit(second.value),
|
||||
)
|
||||
} else {
|
||||
Abi::ScalarPair(
|
||||
scalar_unit(first.value),
|
||||
niche_scalar.clone(),
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => Abi::Aggregate { sized: true },
|
||||
}
|
||||
_ => Abi::Aggregate { sized: true },
|
||||
};
|
||||
|
||||
if st.iter().all(|v| v.abi.is_uninhabited()) {
|
||||
abi = Abi::Uninhabited;
|
||||
}
|
||||
|
||||
let largest_niche =
|
||||
Niche::from_scalar(dl, offset, niche_scalar.clone());
|
||||
|
||||
|
|
|
@ -746,7 +746,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// side-effects -- e.g., in order to report errors for erroneous programs.
|
||||
///
|
||||
/// Note: The optimization is only available during incr. comp.
|
||||
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) -> () {
|
||||
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) {
|
||||
if Q::EVAL_ALWAYS {
|
||||
let _ = self.get_query::<Q>(DUMMY_SP, key);
|
||||
return;
|
||||
|
|
|
@ -1056,8 +1056,9 @@ impl<'a> MethodDef<'a> {
|
|||
self_: field,
|
||||
other: other_fields
|
||||
.iter_mut()
|
||||
.map(|l| match l.next().unwrap() {
|
||||
(.., ex, _) => ex,
|
||||
.map(|l| {
|
||||
let (.., ex, _) = l.next().unwrap();
|
||||
ex
|
||||
})
|
||||
.collect(),
|
||||
attrs,
|
||||
|
|
|
@ -23,7 +23,7 @@ pub type NormalizedTy<'tcx> = Normalized<'tcx, Ty<'tcx>>;
|
|||
|
||||
impl<'tcx, T> Normalized<'tcx, T> {
|
||||
pub fn with<U>(self, value: U) -> Normalized<'tcx, U> {
|
||||
Normalized { value: value, obligations: self.obligations }
|
||||
Normalized { value, obligations: self.obligations }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ struct PredicateSet<'tcx> {
|
|||
|
||||
impl PredicateSet<'tcx> {
|
||||
fn new(tcx: TyCtxt<'tcx>) -> Self {
|
||||
Self { tcx: tcx, set: Default::default() }
|
||||
Self { tcx, set: Default::default() }
|
||||
}
|
||||
|
||||
fn insert(&mut self, pred: &ty::Predicate<'tcx>) -> bool {
|
||||
|
|
|
@ -490,17 +490,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
{
|
||||
if pat_snippet.starts_with('&') {
|
||||
let pat_snippet = pat_snippet[1..].trim_start();
|
||||
let suggestion;
|
||||
let to_remove;
|
||||
if pat_snippet.starts_with("mut")
|
||||
let (suggestion, to_remove) = if pat_snippet.starts_with("mut")
|
||||
&& pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace)
|
||||
{
|
||||
suggestion = pat_snippet["mut".len()..].trim_start();
|
||||
to_remove = "&mut";
|
||||
(pat_snippet["mut".len()..].trim_start(), "&mut")
|
||||
} else {
|
||||
suggestion = pat_snippet;
|
||||
to_remove = "&";
|
||||
}
|
||||
(pat_snippet, "&")
|
||||
};
|
||||
suggestions.push((pat_span, to_remove, suggestion.to_owned()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,9 +335,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn tag_static_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {
|
||||
()
|
||||
}
|
||||
fn tag_static_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {}
|
||||
|
||||
fn box_alloc(
|
||||
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||
|
|
|
@ -581,7 +581,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
/// If `target` is `None`, that indicates the function cannot return, so we raise UB.
|
||||
pub fn return_to_block(&mut self, target: Option<mir::BasicBlock>) -> InterpResult<'tcx> {
|
||||
if let Some(target) = target {
|
||||
Ok(self.go_to_block(target))
|
||||
self.go_to_block(target);
|
||||
Ok(())
|
||||
} else {
|
||||
throw_ub!(Unreachable)
|
||||
}
|
||||
|
|
|
@ -192,7 +192,8 @@ impl PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
|
|||
|
||||
impl Write for AbsolutePathPrinter<'_> {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
Ok(self.path.push_str(s))
|
||||
self.path.push_str(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -370,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
self.stack.pop();
|
||||
Err(err)
|
||||
}
|
||||
Ok(v) => Ok(v),
|
||||
Ok(()) => Ok(()),
|
||||
}
|
||||
}
|
||||
// cannot use the shim here, because that will only result in infinite recursion
|
||||
|
|
|
@ -232,9 +232,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn tag_static_base_pointer(_memory_extra: &(), _id: AllocId) -> Self::PointerTag {
|
||||
()
|
||||
}
|
||||
fn tag_static_base_pointer(_memory_extra: &(), _id: AllocId) -> Self::PointerTag {}
|
||||
|
||||
fn box_alloc(
|
||||
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||
|
|
|
@ -73,10 +73,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// they are never assigned.
|
||||
ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } => (),
|
||||
ExprKind::Block { body: hir::Block { expr: None, targeted_by_break: false, .. } }
|
||||
if expr_ty.is_never() =>
|
||||
{
|
||||
()
|
||||
}
|
||||
if expr_ty.is_never() => {}
|
||||
_ => {
|
||||
this.cfg
|
||||
.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });
|
||||
|
|
|
@ -637,11 +637,12 @@ where
|
|||
);
|
||||
assert_eq!(block, builder.return_block());
|
||||
|
||||
let mut spread_arg = None;
|
||||
if abi == Abi::RustCall {
|
||||
let spread_arg = if abi == Abi::RustCall {
|
||||
// RustCall pseudo-ABI untuples the last argument.
|
||||
spread_arg = Some(Local::new(arguments.len()));
|
||||
}
|
||||
Some(Local::new(arguments.len()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
debug!("fn_id {:?} has attrs {:?}", fn_def_id, tcx.get_attrs(fn_def_id));
|
||||
|
||||
let mut body = builder.finish();
|
||||
|
|
|
@ -750,14 +750,16 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
// If this is a tuple or unit struct, define a name
|
||||
// in the value namespace as well.
|
||||
if let Some(ctor_node_id) = vdata.ctor_id() {
|
||||
let mut ctor_vis = vis;
|
||||
// If the structure is marked as non_exhaustive then lower the visibility
|
||||
// to within the crate.
|
||||
if vis == ty::Visibility::Public
|
||||
let mut ctor_vis = if vis == ty::Visibility::Public
|
||||
&& attr::contains_name(&item.attrs, sym::non_exhaustive)
|
||||
{
|
||||
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
|
||||
}
|
||||
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
|
||||
} else {
|
||||
vis
|
||||
};
|
||||
|
||||
for field in vdata.fields() {
|
||||
// NOTE: The field may be an expansion placeholder, but expansion sets
|
||||
// correct visibilities for unnamed field placeholders specifically, so the
|
||||
|
@ -1166,7 +1168,7 @@ macro_rules! method {
|
|||
visit::$walk(self, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
||||
|
|
|
@ -370,11 +370,11 @@ impl SourceMap {
|
|||
pub fn doctest_offset_line(&self, file: &FileName, orig: usize) -> usize {
|
||||
match file {
|
||||
FileName::DocTest(_, offset) => {
|
||||
return if *offset >= 0 {
|
||||
orig + *offset as usize
|
||||
} else {
|
||||
if *offset < 0 {
|
||||
orig - (-(*offset)) as usize
|
||||
};
|
||||
} else {
|
||||
orig + *offset as usize
|
||||
}
|
||||
}
|
||||
_ => orig,
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn macos_link_env_remove() -> Vec<String> {
|
|||
let mut env_remove = Vec::with_capacity(2);
|
||||
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
||||
// may occur when we're linking a custom build script while targeting iOS for example.
|
||||
if let Some(sdkroot) = env::var("SDKROOT").ok() {
|
||||
if let Ok(sdkroot) = env::var("SDKROOT") {
|
||||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") {
|
||||
env_remove.push("SDKROOT".to_string())
|
||||
}
|
||||
|
|
|
@ -43,40 +43,26 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
|
|||
// to allow the SDK path to be set. (For clang, xcrun sets
|
||||
// SDKROOT; for rustc, the user or build system can set it, or we
|
||||
// can fall back to checking for xcrun on PATH.)
|
||||
if let Some(sdkroot) = env::var("SDKROOT").ok() {
|
||||
if let Ok(sdkroot) = env::var("SDKROOT") {
|
||||
let p = Path::new(&sdkroot);
|
||||
match sdk_name {
|
||||
// Ignore `SDKROOT` if it's clearly set for the wrong platform.
|
||||
"appletvos"
|
||||
if sdkroot.contains("TVSimulator.platform")
|
||||
|| sdkroot.contains("MacOSX.platform") =>
|
||||
{
|
||||
()
|
||||
}
|
||||
|| sdkroot.contains("MacOSX.platform") => {}
|
||||
"appletvsimulator"
|
||||
if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") =>
|
||||
{
|
||||
()
|
||||
}
|
||||
if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") => {}
|
||||
"iphoneos"
|
||||
if sdkroot.contains("iPhoneSimulator.platform")
|
||||
|| sdkroot.contains("MacOSX.platform") =>
|
||||
{
|
||||
()
|
||||
}
|
||||
|| sdkroot.contains("MacOSX.platform") => {}
|
||||
"iphonesimulator"
|
||||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("MacOSX.platform") =>
|
||||
{
|
||||
()
|
||||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("MacOSX.platform") => {
|
||||
}
|
||||
"macosx10.15"
|
||||
if sdkroot.contains("iPhoneOS.platform")
|
||||
|| sdkroot.contains("iPhoneSimulator.platform") =>
|
||||
{
|
||||
()
|
||||
}
|
||||
|| sdkroot.contains("iPhoneSimulator.platform") => {}
|
||||
// Ignore `SDKROOT` if it's not a valid path.
|
||||
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => (),
|
||||
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
|
||||
_ => return Ok(sdkroot),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2792,7 +2792,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
trait_def_id, trait_obligations
|
||||
);
|
||||
|
||||
VtableTraitAliasData { alias_def_id, substs: substs, nested: trait_obligations }
|
||||
VtableTraitAliasData { alias_def_id, substs, nested: trait_obligations }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -80,11 +80,11 @@ impl AscribeUserTypeCx<'me, 'tcx> {
|
|||
where
|
||||
T: ToTrace<'tcx>,
|
||||
{
|
||||
Ok(self
|
||||
.infcx
|
||||
self.infcx
|
||||
.at(&ObligationCause::dummy(), self.param_env)
|
||||
.relate(a, variance, b)?
|
||||
.into_value_registering_obligations(self.infcx, self.fulfill_cx))
|
||||
.into_value_registering_obligations(self.infcx, self.fulfill_cx);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prove_predicate(&mut self, predicate: Predicate<'tcx>) {
|
||||
|
@ -165,10 +165,11 @@ fn type_op_eq<'tcx>(
|
|||
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
|
||||
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
|
||||
let (param_env, Eq { a, b }) = key.into_parts();
|
||||
Ok(infcx
|
||||
infcx
|
||||
.at(&ObligationCause::dummy(), param_env)
|
||||
.eq(a, b)?
|
||||
.into_value_registering_obligations(infcx, fulfill_cx))
|
||||
.into_value_registering_obligations(infcx, fulfill_cx);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -221,10 +222,11 @@ fn type_op_subtype<'tcx>(
|
|||
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
|
||||
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
|
||||
let (param_env, Subtype { sub, sup }) = key.into_parts();
|
||||
Ok(infcx
|
||||
infcx
|
||||
.at(&ObligationCause::dummy(), param_env)
|
||||
.sup(sup, sub)?
|
||||
.into_value_registering_obligations(infcx, fulfill_cx))
|
||||
.into_value_registering_obligations(infcx, fulfill_cx);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -368,11 +368,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let fn_sig = tcx.fn_sig(def_id);
|
||||
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, &fn_sig).0;
|
||||
let fn_sig = fn_sig.subst(self.tcx, substs);
|
||||
let fn_sig = match self.normalize_associated_types_in_as_infer_ok(span, &fn_sig) {
|
||||
InferOk { value, obligations: o } => {
|
||||
obligations.extend(o);
|
||||
value
|
||||
}
|
||||
|
||||
let InferOk { value, obligations: o } =
|
||||
self.normalize_associated_types_in_as_infer_ok(span, &fn_sig);
|
||||
let fn_sig = {
|
||||
obligations.extend(o);
|
||||
value
|
||||
};
|
||||
|
||||
// Register obligations for the parameters. This will include the
|
||||
|
@ -384,12 +385,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// Note that as the method comes from a trait, it should not have
|
||||
// any late-bound regions appearing in its bounds.
|
||||
let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, substs);
|
||||
let bounds = match self.normalize_associated_types_in_as_infer_ok(span, &bounds) {
|
||||
InferOk { value, obligations: o } => {
|
||||
obligations.extend(o);
|
||||
value
|
||||
}
|
||||
|
||||
let InferOk { value, obligations: o } =
|
||||
self.normalize_associated_types_in_as_infer_ok(span, &bounds);
|
||||
let bounds = {
|
||||
obligations.extend(o);
|
||||
value
|
||||
};
|
||||
|
||||
assert!(!bounds.has_escaping_bound_vars());
|
||||
|
||||
let cause = traits::ObligationCause::misc(span, self.body_id);
|
||||
|
|
|
@ -178,10 +178,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: DefId) {
|
|||
use ty::TyKind::*;
|
||||
match (&source.kind, &target.kind) {
|
||||
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))
|
||||
if infcx.at(&cause, param_env).eq(r_a, r_b).is_ok() && mutbl_a == *mutbl_b =>
|
||||
{
|
||||
()
|
||||
}
|
||||
if infcx.at(&cause, param_env).eq(r_a, r_b).is_ok() && mutbl_a == *mutbl_b => {}
|
||||
(&RawPtr(tm_a), &RawPtr(tm_b)) if tm_a.mutbl == tm_b.mutbl => (),
|
||||
(&Adt(def_a, substs_a), &Adt(def_b, substs_b))
|
||||
if def_a.is_struct() && def_b.is_struct() =>
|
||||
|
|
|
@ -234,9 +234,7 @@ pub fn load_css_paths(v: &[u8]) -> CssPath {
|
|||
}
|
||||
|
||||
pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>) {
|
||||
if against.name != other.name {
|
||||
return;
|
||||
} else {
|
||||
if against.name == other.name {
|
||||
for child in &against.children {
|
||||
let mut found = false;
|
||||
let mut found_working = false;
|
||||
|
|
Loading…
Reference in New Issue