From 343a359109a48f4ece657831bf0331e22d108800 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 30 Jan 2023 19:04:55 +0000 Subject: [PATCH] Use ObligationCtxt::new_in_snapshot in satisfied_from_param_env --- .../src/traits/const_evaluatable.rs | 2 +- ...m-with-associated-const-in-where-clause.rs | 17 ++++++++ ...gle-satisfied-ConstEvaluatable-in-probe.rs | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc/document-item-with-associated-const-in-where-clause.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index f779d9dd8d9..786473457ae 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -219,7 +219,7 @@ fn satisfied_from_param_env<'tcx>( } if let Some(Ok(c)) = single_match { - let ocx = ObligationCtxt::new(infcx); + let ocx = ObligationCtxt::new_in_snapshot(infcx); assert!(ocx.eq(&ObligationCause::dummy(), param_env, c.ty(), ct.ty()).is_ok()); assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok()); assert!(ocx.select_all_or_error().is_empty()); diff --git a/tests/rustdoc/document-item-with-associated-const-in-where-clause.rs b/tests/rustdoc/document-item-with-associated-const-in-where-clause.rs new file mode 100644 index 00000000000..c9408ef3360 --- /dev/null +++ b/tests/rustdoc/document-item-with-associated-const-in-where-clause.rs @@ -0,0 +1,17 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait Enumerable { + const N: usize; +} + +#[derive(Clone)] +pub struct SymmetricGroup +where + S: Enumerable, + [(); S::N]: Sized, +{ + _phantom: std::marker::PhantomData, +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs b/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs new file mode 100644 index 00000000000..0ba0c5a72ef --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs @@ -0,0 +1,39 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +use std::marker::PhantomData; + +pub trait Bytes { + const BYTES: usize; +} + +#[derive(Clone, Debug)] +pub struct Conster +where + OT: Bytes, + [(); OT::BYTES]: Sized, +{ + _offset_type: PhantomData OT>, +} + +impl Conster +where + OT: Bytes, + [(); OT::BYTES]: Sized, +{ + pub fn new() -> Self { + Conster { _offset_type: PhantomData } + } +} + +pub fn make_conster() -> Conster +where + COT: Bytes, + [(); COT::BYTES]: Sized, +{ + Conster::new() +} + +fn main() {}