Skip to content

Commit

Permalink
codemod(turbopack): Remove unused async function modifier keywords (#…
Browse files Browse the repository at this point in the history
…70474)

I left a bunch of these behind in #70412 . This cleans them up.

The only remaining work after this is removing unused `Result<...>`s
from return types.

ast-grep config:

```yaml
language: rust
id: remove_unused_async_keyword

rule:
  pattern: async
  inside:
    kind: function_modifiers
    inside:
      kind: function_item
      follows:
        pattern:
          context: |
            #[turbo_tasks::function]
          selector: attribute_item
        stopBy:
          not:
            kind: attribute_item
      has:
        field: body
        not:
          has:
            any:
              - kind: await_expression
              - pattern:
                  context: foo!($$$ await $$$)
                  selector: token_tree
                inside:
                  kind: macro_invocation
                  stopBy: end
            stopBy:
              any:
                - kind: function_item
                - kind: async_block
                - kind: closure_expression

fix: ""

# these files have intentionally async functions
ignores:
  - "**/turbo-tasks-testing/**"
  - "**/turbo-tasks-memory/tests/**"
```

Applied with:

```
sg scan -U -r ../codemod_remove_unused_async_keyword.yml . && cargo fmt
```
  • Loading branch information
bgw authored Sep 26, 2024
1 parent 82682dd commit bb1617b
Show file tree
Hide file tree
Showing 98 changed files with 238 additions and 252 deletions.
36 changes: 17 additions & 19 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn client_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn client_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_client_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -164,7 +164,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn client_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn client_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_client_resolve_options_context(
self.project().project_path(),
Value::new(self.client_ty()),
Expand All @@ -180,13 +180,13 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn client_transition(self: Vc<Self>) -> Result<Vc<FullContextTransition>> {
fn client_transition(self: Vc<Self>) -> Result<Vc<FullContextTransition>> {
let module_context = self.client_module_context();
Ok(FullContextTransition::new(module_context))
}

#[turbo_tasks::function]
async fn rsc_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn rsc_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -198,7 +198,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_rsc_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn edge_rsc_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -210,7 +210,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn route_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn route_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -222,7 +222,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_route_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn edge_route_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -234,7 +234,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.rsc_ty()),
Expand All @@ -245,7 +245,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn edge_rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.rsc_ty()),
Expand All @@ -256,7 +256,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn route_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn route_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.route_ty()),
Expand All @@ -267,9 +267,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_route_resolve_options_context(
self: Vc<Self>,
) -> Result<Vc<ResolveOptionsContext>> {
fn edge_route_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.route_ty()),
Expand Down Expand Up @@ -446,7 +444,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -458,7 +456,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn edge_ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -470,7 +468,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.ssr_ty()),
Expand All @@ -481,7 +479,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.ssr_ty()),
Expand Down Expand Up @@ -532,7 +530,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
Ok(get_server_runtime_entries(
Value::new(self.rsc_ty()),
self.project().next_mode(),
Expand Down Expand Up @@ -560,7 +558,7 @@ impl AppProject {
}

#[turbo_tasks::function]
async fn client_runtime_entries(self: Vc<Self>) -> Result<Vc<EvaluatableAssets>> {
fn client_runtime_entries(self: Vc<Self>) -> Result<Vc<EvaluatableAssets>> {
Ok(get_client_runtime_entries(
self.project().project_path(),
Value::new(self.client_ty()),
Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/global_module_id_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl GlobalModuleIdStrategyBuilder {
// NOTE(LichuAcu) We can't move this function to `turbopack-core` because we need access to
// `Endpoint`, which is not available there.
#[turbo_tasks::function]
async fn preprocess_module_ids(
fn preprocess_module_ids(
endpoint: Vc<Box<dyn Endpoint>>,
) -> Result<Vc<PreprocessedChildrenIdents>> {
let root_modules = endpoint.root_modules();
Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl InstrumentationEndpoint {
}

#[turbo_tasks::function]
async fn core_modules(&self) -> Result<Vc<InstrumentationCoreModules>> {
fn core_modules(&self) -> Result<Vc<InstrumentationCoreModules>> {
let userland_module = self
.asset_context
.process(
Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl MiddlewareEndpoint {
}

#[turbo_tasks::function]
async fn userland_module(&self) -> Result<Vc<Box<dyn Module>>> {
fn userland_module(&self) -> Result<Vc<Box<dyn Module>>> {
Ok(self
.asset_context
.process(
Expand Down
32 changes: 15 additions & 17 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct PagesProject {
#[turbo_tasks::value_impl]
impl PagesProject {
#[turbo_tasks::function]
pub async fn new(project: Vc<Project>) -> Result<Vc<Self>> {
pub fn new(project: Vc<Project>) -> Result<Vc<Self>> {
Ok(PagesProject { project }.cell())
}

Expand Down Expand Up @@ -279,7 +279,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn client_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn client_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_client_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -293,7 +293,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn client_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn client_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_client_resolve_options_context(
self.project().project_path(),
Value::new(ClientContextType::Pages {
Expand Down Expand Up @@ -385,7 +385,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -399,7 +399,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn edge_ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn edge_ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -413,7 +413,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn api_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn api_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -427,7 +427,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn edge_api_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn edge_api_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -441,7 +441,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn ssr_data_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
fn ssr_data_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -455,9 +455,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn edge_ssr_data_module_options_context(
self: Vc<Self>,
) -> Result<Vc<ModuleOptionsContext>> {
fn edge_ssr_data_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Expand All @@ -471,7 +469,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context(
self.project().project_path(),
// NOTE(alexkirsz) This could be `PagesData` for the data endpoint, but it doesn't
Expand All @@ -487,7 +485,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_edge_resolve_options_context(
self.project().project_path(),
// NOTE(alexkirsz) This could be `PagesData` for the data endpoint, but it doesn't
Expand All @@ -503,7 +501,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn client_runtime_entries(self: Vc<Self>) -> Result<Vc<EvaluatableAssets>> {
fn client_runtime_entries(self: Vc<Self>) -> Result<Vc<EvaluatableAssets>> {
let client_runtime_entries = get_client_runtime_entries(
self.project().project_path(),
Value::new(ClientContextType::Pages {
Expand All @@ -517,7 +515,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
Ok(get_server_runtime_entries(
Value::new(ServerContextType::Pages {
pages_dir: self.pages_dir(),
Expand All @@ -527,7 +525,7 @@ impl PagesProject {
}

#[turbo_tasks::function]
async fn data_runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
fn data_runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
Ok(get_server_runtime_entries(
Value::new(ServerContextType::PagesData {
pages_dir: self.pages_dir(),
Expand Down Expand Up @@ -640,7 +638,7 @@ impl PageEndpoint {
}

#[turbo_tasks::function]
async fn source(&self) -> Result<Vc<Box<dyn Source>>> {
fn source(&self) -> Result<Vc<Box<dyn Source>>> {
Ok(Vc::upcast(FileSource::new(self.page.project_path())))
}

Expand Down
Loading

0 comments on commit bb1617b

Please sign in to comment.