Skip to content

Commit

Permalink
Clippy: Fix botstrap fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Feb 10, 2022
1 parent 78ae132 commit 04c9842
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/tools/clippy/clippy_lints/src/lib.rs
Expand Up @@ -5,7 +5,6 @@
#![feature(control_flow_enum)]
#![feature(drain_filter)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(once_cell)]
#![feature(rustc_private)]
Expand All @@ -19,7 +18,7 @@
// warn on rustc internal lints
#![warn(rustc::internal)]
// Disable this rustc lint for now, as it was also done in rustc
#![allow(rustc::potential_query_instability)]
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]

// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
Expand Down
Expand Up @@ -111,19 +111,21 @@ pub(super) fn check<'tcx>(
from_ty_orig, to_ty_orig
),
|diag| {
if let (Some(from_def), Some(to_def)) = (from_ty.ty_adt_def(), to_ty.ty_adt_def())
&& from_def == to_def
{
diag.note(&format!(
"two instances of the same generic type (`{}`) may have different layouts",
cx.tcx.item_name(from_def.did)
));
} else {
if from_ty_orig.peel_refs() != from_ty {
diag.note(&format!("the contained type `{}` has an undefined layout", from_ty));
}
if to_ty_orig.peel_refs() != to_ty {
diag.note(&format!("the contained type `{}` has an undefined layout", to_ty));
if_chain! {
if let (Some(from_def), Some(to_def)) = (from_ty.ty_adt_def(), to_ty.ty_adt_def());
if from_def == to_def;
then {
diag.note(&format!(
"two instances of the same generic type (`{}`) may have different layouts",
cx.tcx.item_name(from_def.did)
));
} else {
if from_ty_orig.peel_refs() != from_ty {
diag.note(&format!("the contained type `{}` has an undefined layout", from_ty));
}
if to_ty_orig.peel_refs() != to_ty {
diag.note(&format!("the contained type `{}` has an undefined layout", to_ty));
}
}
}
},
Expand Down Expand Up @@ -279,11 +281,13 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
}

fn is_zero_sized_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
if let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty)
&& let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty))
{
layout.layout.size.bytes() == 0
} else {
false
if_chain! {
if let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty);
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
then {
layout.layout.size.bytes() == 0
} else {
false
}
}
}

0 comments on commit 04c9842

Please sign in to comment.