Skip to content

Commit 5c3bb1f

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Unimpl AllocValue for Option
Summary: This impl has two drawbacks: - there's no `UnpackValue` for `Option` (because `Option` in parameter indicates optional parameter) - we may accidentally allocate `None` where we don't mean to, for example, when data is stored as `None` meaning "does not mean to go into starlark". One of such cases is D63708443, another time I accidentally almost did it in `dynamic_actions` refactoring (that diff is not published yet) Reviewed By: JakobDegen Differential Revision: D63717899 fbshipit-source-id: 19ae37c367be2ac0b1424cdc6dbfa734c3d1d1af
1 parent e09c119 commit 5c3bb1f

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

starlark/src/stdlib/call_stack.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ fn stack_frame_methods(builder: &mut MethodsBuilder) {
8989

9090
/// Returns a path of the module from which the entry was called, or [`None`] for native Rust functions.
9191
#[starlark(attribute)]
92-
fn module_path(this: &StackFrame) -> anyhow::Result<Option<String>> {
92+
fn module_path(this: &StackFrame) -> anyhow::Result<NoneOr<String>> {
9393
match this.location {
94-
Some(ref location) => Ok(Some(location.file.filename().to_owned())),
95-
None => Ok(None),
94+
Some(ref location) => Ok(NoneOr::Other(location.file.filename().to_owned())),
95+
None => Ok(NoneOr::None),
9696
}
9797
}
9898
}

starlark/src/values/alloc_value.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,6 @@ impl<'v> AllocValue<'v> for Value<'v> {
9696
}
9797
}
9898

99-
impl<'v, T> AllocValue<'v> for Option<T>
100-
where
101-
T: AllocValue<'v>,
102-
{
103-
fn alloc_value(self, heap: &'v Heap) -> Value<'v> {
104-
match self {
105-
Some(v) => v.alloc_value(heap),
106-
None => Value::new_none(),
107-
}
108-
}
109-
}
110-
11199
impl<'v, A: AllocValue<'v>, B: AllocValue<'v>> AllocValue<'v> for Either<A, B> {
112100
#[inline]
113101
fn alloc_value(self, heap: &'v Heap) -> Value<'v> {

0 commit comments

Comments
 (0)