From 0547847fa2b8a2bc5fd975cddd89e711b42ddf17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 12 Nov 2023 17:10:49 +0000 Subject: [PATCH 1/3] simplify `Safety` pretty-printing No need to customize the Debug impl any more --- crates/formality-prove/src/decls.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/crates/formality-prove/src/decls.rs b/crates/formality-prove/src/decls.rs index 6f725c01..95b8767d 100644 --- a/crates/formality-prove/src/decls.rs +++ b/crates/formality-prove/src/decls.rs @@ -1,5 +1,3 @@ -use std::fmt; - use formality_core::{set, Set, Upcast}; use formality_macros::term; use formality_types::grammar::{ @@ -144,7 +142,6 @@ pub struct NegImplDeclBoundData { /// Mark a trait or trait impl as `unsafe`. #[term] -#[customize(debug)] #[derive(Default)] pub enum Safety { #[default] @@ -152,15 +149,6 @@ pub enum Safety { Unsafe, } -impl fmt::Debug for Safety { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Safety::Safe => write!(f, "safe"), - Safety::Unsafe => write!(f, "unsafe"), - } - } -} - /// A "trait declaration" declares a trait that exists, its generics, and its where-clauses. /// It doesn't capture the trait items, which will be transformed into other sorts of rules. /// From 765661e751974334059b5fc370a0d7b391f0e569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 12 Nov 2023 17:14:18 +0000 Subject: [PATCH 2/3] re-introduce struct pattern in `check_trait_impl` --- crates/formality-check/src/impls.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/formality-check/src/impls.rs b/crates/formality-check/src/impls.rs index b7b9b491..be7e43d9 100644 --- a/crates/formality-check/src/impls.rs +++ b/crates/formality-check/src/impls.rs @@ -19,6 +19,8 @@ use formality_types::{ impl super::Check<'_> { #[context("check_trait_impl({trait_impl:?})")] pub(super) fn check_trait_impl(&self, trait_impl: &TraitImpl) -> Fallible<()> { + let TraitImpl { binder, safety: _ } = trait_impl; + let mut env = Env::default(); let TraitImplBoundData { @@ -27,7 +29,7 @@ impl super::Check<'_> { trait_parameters, where_clauses, impl_items, - } = env.instantiate_universally(&trait_impl.binder); + } = env.instantiate_universally(&binder); let trait_ref = trait_id.with(self_ty, trait_parameters); From 9a61bf6e3ea544e5923b81cda19f900f7cb4e5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sun, 12 Nov 2023 17:18:40 +0000 Subject: [PATCH 3/3] introduce struct pattern in `check_neg_trait_impl` --- crates/formality-check/src/impls.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/formality-check/src/impls.rs b/crates/formality-check/src/impls.rs index be7e43d9..079989d9 100644 --- a/crates/formality-check/src/impls.rs +++ b/crates/formality-check/src/impls.rs @@ -56,6 +56,8 @@ impl super::Check<'_> { #[context("check_neg_trait_impl({trait_impl:?})")] pub(super) fn check_neg_trait_impl(&self, trait_impl: &NegTraitImpl) -> Fallible<()> { + let NegTraitImpl { binder, safety } = trait_impl; + let mut env = Env::default(); let NegTraitImplBoundData { @@ -63,12 +65,12 @@ impl super::Check<'_> { self_ty, trait_parameters, where_clauses, - } = env.instantiate_universally(&trait_impl.binder); + } = env.instantiate_universally(binder); let trait_ref = trait_id.with(self_ty, trait_parameters); // Negative impls are always safe (rustc E0198) regardless of the trait's safety. - if trait_impl.safety == Safety::Unsafe { + if *safety == Safety::Unsafe { bail!("negative impls cannot be unsafe"); }