Skip to content

Commit 2a16bb0

Browse files
committed
handle ConstEquate in rustdoc
1 parent 1454bbd commit 2a16bb0

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/librustc_trait_selection/traits/auto_trait.rs

+32
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,38 @@ impl AutoTraitFinder<'tcx> {
802802
_ => {}
803803
};
804804
}
805+
ty::PredicateAtom::ConstEquate(c1, c2) => {
806+
let evaluate = |c: &'tcx ty::Const<'tcx>| {
807+
if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val {
808+
match select.infcx().const_eval_resolve(
809+
obligation.param_env,
810+
def,
811+
substs,
812+
promoted,
813+
Some(obligation.cause.span),
814+
) {
815+
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty)),
816+
Err(err) => Err(err),
817+
}
818+
} else {
819+
Ok(c)
820+
}
821+
};
822+
823+
match (evaluate(c1), evaluate(c2)) {
824+
(Ok(c1), Ok(c2)) => {
825+
match select
826+
.infcx()
827+
.at(&obligation.cause, obligation.param_env)
828+
.eq(c1, c2)
829+
{
830+
Ok(_) => (),
831+
Err(_) => return false,
832+
}
833+
}
834+
_ => return false,
835+
}
836+
}
805837
_ => panic!("Unexpected predicate {:?} {:?}", ty, predicate),
806838
};
807839
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name = "foo"]
2+
#![feature(lazy_normalization_consts)]
3+
#![allow(incomplete_features)]
4+
5+
// Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate,
6+
// which previously caused an ICE.
7+
8+
pub struct Hasher<T> {
9+
cv_stack: T,
10+
}
11+
12+
unsafe impl<T: Default> Send for Hasher<T> {}
13+
14+
// @has foo/struct.Foo.html
15+
// @has - '//code' 'impl Send for Foo'
16+
pub struct Foo {
17+
hasher: Hasher<[u8; 3]>,
18+
}

0 commit comments

Comments
 (0)