Skip to content

Fix the ICE 6539 #6582

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

Merged
merged 1 commit into from
Jan 17, 2021
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
4 changes: 3 additions & 1 deletion clippy_lints/src/zero_sized_map_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_target::abi::LayoutOf as _;
use rustc_typeck::hir_ty_to_ty;

use crate::utils::{is_type_diagnostic_item, match_type, paths, span_lint_and_help};
use crate::utils::{is_normalizable, is_type_diagnostic_item, match_type, paths, span_lint_and_help};

declare_clippy_lint! {
/// **What it does:** Checks for maps with zero-sized value types anywhere in the code.
Expand Down Expand Up @@ -50,6 +50,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP);
if let Adt(_, ref substs) = ty.kind();
let ty = substs.type_at(1);
// Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
if is_normalizable(cx, cx.param_env, ty);
if let Ok(layout) = cx.layout_of(ty);
if layout.is_zst();
then {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/crashes/ice-6539.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// The test for the ICE 6539: https://github.com/rust-lang/rust-clippy/issues/6539.
// The cause is that `zero_sized_map_values` used `layout_of` with types from type aliases,
// which is essentially the same as the ICE 4968.
// Note that only type aliases with associated types caused the crash this time,
// not others such as trait impls.

use std::collections::{BTreeMap, HashMap};

pub trait Trait {
type Assoc;
}

type TypeAlias<T> = HashMap<(), <T as Trait>::Assoc>;
type TypeAlias2<T> = BTreeMap<(), <T as Trait>::Assoc>;

fn main() {}