Skip to content

Commit 3468054

Browse files
authored
Merge pull request #156 from lqd/unsafer-traits
Improvements to unsafe trait support
2 parents ddbb916 + 9a61bf6 commit 3468054

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

crates/formality-check/src/impls.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use formality_types::{
1919
impl super::Check<'_> {
2020
#[context("check_trait_impl({trait_impl:?})")]
2121
pub(super) fn check_trait_impl(&self, trait_impl: &TraitImpl) -> Fallible<()> {
22+
let TraitImpl { binder, safety: _ } = trait_impl;
23+
2224
let mut env = Env::default();
2325

2426
let TraitImplBoundData {
@@ -27,7 +29,7 @@ impl super::Check<'_> {
2729
trait_parameters,
2830
where_clauses,
2931
impl_items,
30-
} = env.instantiate_universally(&trait_impl.binder);
32+
} = env.instantiate_universally(&binder);
3133

3234
let trait_ref = trait_id.with(self_ty, trait_parameters);
3335

@@ -54,19 +56,21 @@ impl super::Check<'_> {
5456

5557
#[context("check_neg_trait_impl({trait_impl:?})")]
5658
pub(super) fn check_neg_trait_impl(&self, trait_impl: &NegTraitImpl) -> Fallible<()> {
59+
let NegTraitImpl { binder, safety } = trait_impl;
60+
5761
let mut env = Env::default();
5862

5963
let NegTraitImplBoundData {
6064
trait_id,
6165
self_ty,
6266
trait_parameters,
6367
where_clauses,
64-
} = env.instantiate_universally(&trait_impl.binder);
68+
} = env.instantiate_universally(binder);
6569

6670
let trait_ref = trait_id.with(self_ty, trait_parameters);
6771

6872
// Negative impls are always safe (rustc E0198) regardless of the trait's safety.
69-
if trait_impl.safety == Safety::Unsafe {
73+
if *safety == Safety::Unsafe {
7074
bail!("negative impls cannot be unsafe");
7175
}
7276

crates/formality-prove/src/decls.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
use formality_core::{set, Set, Upcast};
42
use formality_macros::term;
53
use formality_types::grammar::{
@@ -144,23 +142,13 @@ pub struct NegImplDeclBoundData {
144142

145143
/// Mark a trait or trait impl as `unsafe`.
146144
#[term]
147-
#[customize(debug)]
148145
#[derive(Default)]
149146
pub enum Safety {
150147
#[default]
151148
Safe,
152149
Unsafe,
153150
}
154151

155-
impl fmt::Debug for Safety {
156-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157-
match self {
158-
Safety::Safe => write!(f, "safe"),
159-
Safety::Unsafe => write!(f, "unsafe"),
160-
}
161-
}
162-
}
163-
164152
/// A "trait declaration" declares a trait that exists, its generics, and its where-clauses.
165153
/// It doesn't capture the trait items, which will be transformed into other sorts of rules.
166154
///

0 commit comments

Comments
 (0)