Skip to content

Commit

Permalink
fix: subtypings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu-Lala committed Jul 9, 2024
1 parent 30cd73d commit 3706a6b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install cargo-spellcheck
uses: taiki-e/install-action@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.rust_min }}
- uses: taiki-e/install-action@v2
with:
tool: cargo-spellcheck
- run: cargo spellcheck --code 1
9 changes: 5 additions & 4 deletions src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ impl<'a> Request<'a> {
unsafe { &mut *(opt as &mut dyn Erased as *mut dyn Erased as *mut Self) }
}

pub(crate) fn new_action<'t, 'p, P: Property<'p>>(
val: &'t mut Tagged<'p, Action<P>>,
) -> &'t mut Self {
unsafe { &mut *(val as &mut dyn Erased as *mut dyn Erased as *mut Self) }
pub(crate) fn new_action<'p, P: Property<'p>>(
val: &'a mut Tagged<'p, Action<P>>,
) -> &'a mut Request<'p> {
unsafe { &mut *(val as &mut dyn Erased as *mut dyn Erased as *mut Request) }
}
}

impl<'a> Request<'a> {
fn is_satisfy<P: Property<'a>>(&self) -> bool {
self.0.is::<tags::RefMut<Satisfy<P>>>()
Expand Down
2 changes: 1 addition & 1 deletion src/channel_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ mod tests {
.unwrap();

let mut tagged_option = Tagged::<'_, NoValidation>(None);

let validate = Validate::new::<NoValidation>(&mut tagged_option);
session
.get_cb_data("this-cb", validate, &mut |cb| {
Expand All @@ -74,6 +73,7 @@ mod tests {
})
.unwrap();

let mut tagged_option = Tagged::<'_, NoValidation>(None);
let validate = Validate::new::<NoValidation>(&mut tagged_option);
let e = session
.get_cb_data("blahblubb", validate, &mut |_cb| {
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'a> Demand<'a> {
}
}

pub fn build_context<'a>(provider: &'a dyn Provider) -> &'a Context<'a> {
pub fn build_context<'a, 'b>(provider: &'a (dyn Provider<'b> + 'a)) -> &'a Context<'b> {
unsafe { &*(provider as *const dyn Provider as *const Context) }
}

Expand Down
14 changes: 7 additions & 7 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ mod provider {
}
}

impl<'a> MechanismData<'a> {
impl<'a, 'b> MechanismData<'a, 'b> {
fn new(
callback: &'a dyn SessionCallback,
chanbind_cb: &'a dyn ChannelBindingCallback,
validator: &'a mut Validate<'a>,
validator: &'a mut Validate<'b>,
mechanism_desc: Mechanism,
side: Side,
) -> Self {
Expand Down Expand Up @@ -302,14 +302,14 @@ mod provider {
#[cfg(any(feature = "provider", feature = "testutils", test))]
pub use provider::Session;

pub struct MechanismData<'a> {
pub struct MechanismData<'a, 'b> {
callback: &'a dyn SessionCallback,
chanbind_cb: &'a dyn ChannelBindingCallback,
validator: &'a mut Validate<'a>,
validator: &'a mut Validate<'b>,
session_data: SessionData,
}

impl MechanismData<'_> {
impl MechanismData<'_, '_> {
pub fn validate(&mut self, provider: &dyn Provider) -> Result<(), ValidationError> {
let context = build_context(provider);
self.callback
Expand All @@ -336,7 +336,7 @@ impl MechanismData<'_> {
where
T: Property<'a>,
{
let mut tagged = Tagged::<'a, Action<T>>(Some(value));
let mut tagged = Tagged::<'_, Action<T>>(Some(value));
self.callback(provider, Request::new_action::<T>(&mut tagged))?;
if tagged.is_some() {
Err(SessionError::CallbackError(CallbackError::NoCallback(
Expand Down Expand Up @@ -408,7 +408,7 @@ impl MechanismData<'_> {
}
}

impl fmt::Debug for MechanismData<'_> {
impl fmt::Debug for MechanismData<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MechanismData").finish()
}
Expand Down
4 changes: 2 additions & 2 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl Validation for NoValidation {
/// mechanism.
pub struct Validate<'a>(dyn Erased<'a> + 'a);
#[cfg(any(test, feature = "provider", feature = "testutils"))]
impl Validate<'_> {
pub(crate) fn new<'opt, V: Validation>(opt: &'opt mut Tagged<'_, V>) -> &'opt mut Self {
impl<'a> Validate<'a> {
pub(crate) fn new<'opt, V: Validation>(opt: &'opt mut Tagged<'a, V>) -> &'opt mut Self {
unsafe { &mut *(opt as &mut dyn Erased as *mut dyn Erased as *mut Self) }
}
}
Expand Down

0 comments on commit 3706a6b

Please sign in to comment.