Skip to content

handle ConstEquate in rustdoc #74891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2020
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]>,
}