Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/librustc_trait_selection/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,38 @@ impl AutoTraitFinder<'tcx> {
_ => {}
};
}
ty::PredicateAtom::ConstEquate(c1, c2) => {
let evaluate = |c: &'tcx ty::Const<'tcx>| {
if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val {
match select.infcx().const_eval_resolve(
obligation.param_env,
def,
substs,
promoted,
Some(obligation.cause.span),
) {
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty)),
Err(err) => Err(err),
}
} else {
Ok(c)
}
};

match (evaluate(c1), evaluate(c2)) {
(Ok(c1), Ok(c2)) => {
match select
.infcx()
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{
Ok(_) => (),
Err(_) => return false,
}
}
_ => return false,
}
}
_ => panic!("Unexpected predicate {:?} {:?}", ty, predicate),
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc/lazy_normalization_consts/const-equate-pred.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![crate_name = "foo"]
#![feature(lazy_normalization_consts)]
#![allow(incomplete_features)]

// Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate,
// which previously caused an ICE.

pub struct Hasher<T> {
cv_stack: T,
}

unsafe impl<T: Default> Send for Hasher<T> {}

// @has foo/struct.Foo.html
// @has - '//code' 'impl Send for Foo'
pub struct Foo {
hasher: Hasher<[u8; 3]>,
}