Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jul 15, 2024
1 parent 257f49e commit 4051f88
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
20 changes: 13 additions & 7 deletions crates/turbo-tasks/src/native_function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::type_name, fmt::Debug, hash::Hash, pin::Pin};
use std::{fmt::Debug, hash::Hash, pin::Pin};

use anyhow::{Context, Result};
use futures::Future;
Expand Down Expand Up @@ -38,11 +38,14 @@ impl ArgMeta {
value
.downcast_ref::<T>()
.with_context(|| {
format!(
#[cfg(debug_assertions)]
return format!(
"Invalid argument type, expected {} got {}",
type_name::<T>(),
std::any::type_name::<T>(),
value.magic_type_name()
)
);
#[cfg(not(debug_assertions))]
return "Invalid argument type";
})
.unwrap()
.is_resolved()
Expand All @@ -52,11 +55,14 @@ impl ArgMeta {
let value = value
.downcast_ref::<T>()
.with_context(|| {
format!(
#[cfg(debug_assertions)]
return format!(
"Invalid argument type, expected {} got {}",
type_name::<T>(),
std::any::type_name::<T>(),
value.magic_type_name()
)
);
#[cfg(not(debug_assertions))]
return "Invalid argument type";
})
.unwrap();
let resolved = value.resolve().await?;
Expand Down
26 changes: 20 additions & 6 deletions crates/turbo-tasks/src/task/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ macro_rules! task_inputs_impl {
}
}

fn get_args<T: MagicAny>(arg: &dyn MagicAny) -> Result<&T> {
let value = arg.downcast_ref::<T>();
#[cfg(debug_assertions)]
return anyhow::Context::with_context(value, || {
format!(
"Invalid argument type, expected {} got {}",
std::any::type_name::<T>(),
(*arg).magic_type_name()
)
});
#[cfg(not(debug_assertions))]
return anyhow::Context::context(value, "Invalid argument type");
}

macro_rules! task_fn_impl {
( $async_fn_trait:ident $arg_len:literal $( $arg:ident )* ) => {
impl<F, Output, $($arg,)*> TaskFnInputFunction<FunctionMode, ($($arg,)*)> for F
Expand All @@ -179,7 +193,7 @@ macro_rules! task_fn_impl {
let task_fn = self.clone();

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::with_context(arg.downcast_ref::<($($arg,)*)>(), || format!("Invalid argument type, expected {} got {}", stringify!(($($arg,)*)), (*arg).magic_type_name()))?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand All @@ -202,7 +216,7 @@ macro_rules! task_fn_impl {
let task_fn = self.clone();

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::context(arg.downcast_ref::<($($arg,)*)>(), "Invalid argument type")?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand All @@ -226,7 +240,7 @@ macro_rules! task_fn_impl {
let recv = Vc::<Recv>::from(this);

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::context(arg.downcast_ref::<($($arg,)*)>(), "Invalid argument type")?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand All @@ -252,7 +266,7 @@ macro_rules! task_fn_impl {
let recv = Vc::<Recv>::from(this);

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::context(arg.downcast_ref::<($($arg,)*)>(), "Invalid argument type")?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand Down Expand Up @@ -290,7 +304,7 @@ macro_rules! task_fn_impl {
let recv = Vc::<Recv>::from(this);

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::context(arg.downcast_ref::<($($arg,)*)>(), "Invalid argument type")?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand All @@ -315,7 +329,7 @@ macro_rules! task_fn_impl {
let recv = Vc::<Recv>::from(this);

#[allow(unused_parens)]
let ($($arg,)*) = anyhow::Context::context(arg.downcast_ref::<($($arg,)*)>(), "Invalid argument type")?;
let ($($arg,)*) = get_args::<($($arg,)*)>(arg)?;
$(
let $arg = $arg.clone();
)*
Expand Down

0 comments on commit 4051f88

Please sign in to comment.