From f746e1916999810a1e643077fcb677b077e31bc4 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Mon, 14 Aug 2023 19:10:33 +0200 Subject: [PATCH] allow trait alias DefIds in `implements_trait_with_env_from_iter` --- clippy_utils/src/lib.rs | 1 + clippy_utils/src/ty.rs | 7 ++++++- tests/ui/crashes/ice-11337.rs | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/ui/crashes/ice-11337.rs diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 171b7faf219..64b24c56121 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -5,6 +5,7 @@ #![feature(lint_reasons)] #![feature(never_type)] #![feature(rustc_private)] +#![feature(assert_matches)] #![recursion_limit = "512"] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)] diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a05f682aa8c..f0b4ede35fb 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -27,6 +27,7 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Obligation, ObligationCause}; +use std::assert_matches::debug_assert_matches; use std::iter; use crate::{match_def_path, path_res, paths}; @@ -259,7 +260,11 @@ pub fn implements_trait_with_env_from_iter<'tcx>( })), ); - debug_assert_eq!(tcx.def_kind(trait_id), DefKind::Trait); + debug_assert_matches!( + tcx.def_kind(trait_id), + DefKind::Trait | DefKind::TraitAlias, + "`DefId` must belong to a trait or trait alias" + ); #[cfg(debug_assertions)] assert_generic_args_match(tcx, trait_id, trait_ref.args); diff --git a/tests/ui/crashes/ice-11337.rs b/tests/ui/crashes/ice-11337.rs new file mode 100644 index 00000000000..0bed4035f6b --- /dev/null +++ b/tests/ui/crashes/ice-11337.rs @@ -0,0 +1,9 @@ +#![feature(trait_alias)] + +trait Confusing = Fn(i32) where F: Fn(u32); + +fn alias, F>(_: T, _: F) {} + +fn main() { + alias(|_| {}, |_| {}); +}