Skip to content

Commit 2a2e602

Browse files
authored
Merge pull request #2833 from phansch/cannot_relate_bound_region_without_ICE_cream
Fix cargo late bound region mismatch ICE
2 parents 7563d81 + 17aff1d commit 2a2e602

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::hir::map::Node;
88
use rustc::lint::{LateContext, Level, Lint, LintContext};
99
use rustc::session::Session;
1010
use rustc::traits;
11-
use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}, subst::Kind};
11+
use rustc::ty::{self, Binder, Ty, TyCtxt, layout::{self, IntegerExt}, subst::Kind};
1212
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
1313
use std::borrow::Cow;
1414
use std::env;
@@ -869,10 +869,14 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'t
869869
}
870870

871871
/// Check if two types are the same.
872+
///
873+
/// This discards any lifetime annotations, too.
872874
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for
873875
// <'b> Foo<'b>` but
874876
// not for type parameters.
875877
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
878+
let a = cx.tcx.erase_late_bound_regions(&Binder::bind(a));
879+
let b = cx.tcx.erase_late_bound_regions(&Binder::bind(b));
876880
cx.tcx
877881
.infer_ctxt()
878882
.enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok())

tests/run-pass/ice-2774.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::collections::HashSet;
2+
3+
// See https://github.com/rust-lang-nursery/rust-clippy/issues/2774
4+
5+
#[derive(Eq, PartialEq, Debug, Hash)]
6+
pub struct Bar {
7+
foo: Foo,
8+
}
9+
10+
#[derive(Eq, PartialEq, Debug, Hash)]
11+
pub struct Foo {}
12+
13+
#[allow(implicit_hasher)]
14+
// This should not cause a 'cannot relate bound region' ICE
15+
pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
16+
let mut foos = HashSet::new();
17+
foos.extend(
18+
bars.iter().map(|b| &b.foo)
19+
);
20+
}
21+
22+
#[allow(implicit_hasher)]
23+
// Also this should not cause a 'cannot relate bound region' ICE
24+
pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) {
25+
let mut foos = HashSet::new();
26+
foos.extend(
27+
bars.iter().map(|b| &b.foo)
28+
);
29+
}
30+
31+
fn main() {}

0 commit comments

Comments
 (0)