-
Notifications
You must be signed in to change notification settings - Fork 192
Remove bounds and type checks from IngredientCache
#937
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,7 +177,8 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync { | |
| } | ||
|
|
||
| impl dyn Ingredient { | ||
| /// Equivalent to the `downcast` methods on `any`. | ||
| /// Equivalent to the `downcast` method on `Any`. | ||
| /// | ||
| /// Because we do not have dyn-upcasting support, we need this workaround. | ||
| pub fn assert_type<T: Any>(&self) -> &T { | ||
| assert_eq!( | ||
|
|
@@ -192,7 +193,27 @@ impl dyn Ingredient { | |
| unsafe { transmute_data_ptr(self) } | ||
| } | ||
|
|
||
| /// Equivalent to the `downcast` methods on `any`. | ||
| /// Equivalent to the `downcast` methods on `Any`. | ||
| /// | ||
| /// Because we do not have dyn-upcasting support, we need this workaround. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could consider bumping the MSRV.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bumping msrv seems reasonable; rust-analyzer shouldn't have an issue with that (we're generally current-1).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upcasting was stabilized in 1.86, which is quite recent. FWIW this is an old comment, so I'm not sure it makes sense to do in this PR (but I'm not opposed to it).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agree, I think it's better to do in a separate PR. I only wanted to point out that bumping the MSRV is a possiblity |
||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The contained value must be of type `T`. | ||
| pub unsafe fn assert_type_unchecked<T: Any>(&self) -> &T { | ||
| debug_assert_eq!( | ||
| self.type_id(), | ||
| TypeId::of::<T>(), | ||
| "ingredient `{self:?}` is not of type `{}`", | ||
| std::any::type_name::<T>() | ||
| ); | ||
|
|
||
| // SAFETY: Guaranteed by caller. | ||
| unsafe { transmute_data_ptr(self) } | ||
| } | ||
|
|
||
| /// Equivalent to the `downcast` method on `Any`. | ||
| /// | ||
| /// Because we do not have dyn-upcasting support, we need this workaround. | ||
| pub fn assert_type_mut<T: Any>(&mut self) -> &mut T { | ||
| assert_eq!( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's technically possible that a salsa user implements their own
Ingredient. Could a maliciousIngredientimplementation invalidate the SAFETY assumption?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this just accesses the ingredient created by this jar.