Fix ICE with trivial_bounds feature

This commit is contained in:
Shotaro Yamada
2020-03-10 13:17:15 +09:00
parent 187bbf0e7b
commit a3d9355bef
5 changed files with 56 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ use rustc::ty::{
self,
layout::{self, IntegerExt},
subst::GenericArg,
Binder, Ty, TyCtxt,
Binder, Ty, TyCtxt, TypeFoldable,
};
use rustc_ast::ast::{self, Attribute, LitKind};
use rustc_attr as attr;
@@ -1377,6 +1377,27 @@ pub fn is_trait_impl_item(cx: &LateContext<'_, '_>, hir_id: HirId) -> bool {
}
}
/// Check if it's even possible to satisfy the `where` clause for the item.
///
/// `trivial_bounds` feature allows functions with unsatisfiable bounds, for example:
///
/// ```rust
/// fn foo() i32: Iterator {
/// for _ in 2i32 {}
/// }
/// ```
pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool {
use rustc_infer::traits;
let predicates = cx
.tcx
.predicates_of(did)
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None })
.collect();
!traits::normalize_and_test_predicates(cx.tcx, traits::elaborate_predicates(cx.tcx, predicates).collect())
}
#[cfg(test)]
mod test {
use super::{trim_multiline, without_block_comments};