mirror of https://github.com/rust-lang/rust.git
Merge pull request #2833 from phansch/cannot_relate_bound_region_without_ICE_cream
Fix cargo late bound region mismatch ICE
This commit is contained in:
commit
2a2e602f2a
|
@ -8,7 +8,7 @@ use rustc::hir::map::Node;
|
||||||
use rustc::lint::{LateContext, Level, Lint, LintContext};
|
use rustc::lint::{LateContext, Level, Lint, LintContext};
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}, subst::Kind};
|
use rustc::ty::{self, Binder, Ty, TyCtxt, layout::{self, IntegerExt}, subst::Kind};
|
||||||
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
|
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -869,10 +869,14 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if two types are the same.
|
/// Check if two types are the same.
|
||||||
|
///
|
||||||
|
/// This discards any lifetime annotations, too.
|
||||||
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for
|
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for
|
||||||
// <'b> Foo<'b>` but
|
// <'b> Foo<'b>` but
|
||||||
// not for type parameters.
|
// not for type parameters.
|
||||||
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||||
|
let a = cx.tcx.erase_late_bound_regions(&Binder::bind(a));
|
||||||
|
let b = cx.tcx.erase_late_bound_regions(&Binder::bind(b));
|
||||||
cx.tcx
|
cx.tcx
|
||||||
.infer_ctxt()
|
.infer_ctxt()
|
||||||
.enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok())
|
.enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok())
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
// See https://github.com/rust-lang-nursery/rust-clippy/issues/2774
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub struct Bar {
|
||||||
|
foo: Foo,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub struct Foo {}
|
||||||
|
|
||||||
|
#[allow(implicit_hasher)]
|
||||||
|
// This should not cause a 'cannot relate bound region' ICE
|
||||||
|
pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
|
||||||
|
let mut foos = HashSet::new();
|
||||||
|
foos.extend(
|
||||||
|
bars.iter().map(|b| &b.foo)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(implicit_hasher)]
|
||||||
|
// Also this should not cause a 'cannot relate bound region' ICE
|
||||||
|
pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) {
|
||||||
|
let mut foos = HashSet::new();
|
||||||
|
foos.extend(
|
||||||
|
bars.iter().map(|b| &b.foo)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue