Skip to content

Commit

Permalink
Relocate non-local impl definitions
Browse files Browse the repository at this point in the history
Summary:
Rust 1.79 produces a new warning.

```lang=text
warning: non-local `impl` definition, they should be avoided as they go against expectation
   --> app/buck2_common/src/dice/file_ops/delegate.rs:170:5
    |
170 | /     impl Key for FileOpsKey {
171 | |         type Value = buck2_error::Result<FileOpsValue>;
172 | |         async fn compute(
173 | |             &self,
...   |
212 | |         }
213 | |     }
    | |_____^
    |
    = help: move this `impl` block outside the of the current async fn `<unnameable>` and up 2 bodies
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <rust-lang/rust#120363>
    = note: `#[warn(non_local_definitions)]` on by default
```

Reviewed By: JakobDegen

Differential Revision: D59641307

fbshipit-source-id: 8993440bebd455ef9a81caadbb24d8b70ace05d0
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Jul 11, 2024
1 parent b97b4da commit 698a22e
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 473 deletions.
40 changes: 20 additions & 20 deletions app/buck2_analysis/src/analysis/calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,33 @@ pub(crate) fn init_rule_analysis_calculation() {
RULE_ANALYSIS_CALCULATION.init(&RuleAnalysisCalculationInstance);
}

#[async_trait]
impl Key for AnalysisKey {
type Value = buck2_error::Result<MaybeCompatible<AnalysisResult>>;
async fn compute(
&self,
ctx: &mut DiceComputations,
_cancellation: &CancellationContext,
) -> Self::Value {
Ok(get_analysis_result(ctx, &self.0)
.await
.with_context(|| format!("Error running analysis for `{}`", &self.0))?)
}

fn equality(_: &Self::Value, _: &Self::Value) -> bool {
// analysis result is not comparable
// TODO consider if we want analysis result to be eq
false
}
}

#[async_trait]
impl RuleAnalsysisCalculationImpl for RuleAnalysisCalculationInstance {
async fn get_analysis_result(
&self,
ctx: &mut DiceComputations<'_>,
target: &ConfiguredTargetLabel,
) -> anyhow::Result<MaybeCompatible<AnalysisResult>> {
#[async_trait]
impl Key for AnalysisKey {
type Value = buck2_error::Result<MaybeCompatible<AnalysisResult>>;
async fn compute(
&self,
ctx: &mut DiceComputations,
_cancellation: &CancellationContext,
) -> Self::Value {
Ok(get_analysis_result(ctx, &self.0)
.await
.with_context(|| format!("Error running analysis for `{}`", &self.0))?)
}

fn equality(_: &Self::Value, _: &Self::Value) -> bool {
// analysis result is not comparable
// TODO consider if we want analysis result to be eq
false
}
}

ctx.compute(&AnalysisKey(target.dupe()))
.await?
.map_err(anyhow::Error::from)
Expand Down
34 changes: 17 additions & 17 deletions app/buck2_anon_target/src/anon_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ pub enum AnonTargetsError {
#[derive(Hash, Eq, PartialEq, Clone, Dupe, Debug, Display, Trace, Allocative)]
pub(crate) struct AnonTargetKey(pub(crate) Arc<AnonTarget>);

#[async_trait]
impl Key for AnonTargetKey {
type Value = buck2_error::Result<AnalysisResult>;

async fn compute(
&self,
ctx: &mut DiceComputations,
_cancellation: &CancellationContext,
) -> Self::Value {
Ok(self.run_analysis(ctx).await?)
}

fn equality(_: &Self::Value, _: &Self::Value) -> bool {
false
}
}

impl AnonTargetKey {
fn downcast(key: Arc<dyn BaseDeferredKeyDyn>) -> anyhow::Result<Self> {
Ok(AnonTargetKey(
Expand Down Expand Up @@ -256,23 +273,6 @@ impl AnonTargetKey {
&self,
dice: &mut DiceComputations<'_>,
) -> anyhow::Result<AnalysisResult> {
#[async_trait]
impl Key for AnonTargetKey {
type Value = buck2_error::Result<AnalysisResult>;

async fn compute(
&self,
ctx: &mut DiceComputations,
_cancellation: &CancellationContext,
) -> Self::Value {
Ok(self.run_analysis(ctx).await?)
}

fn equality(_: &Self::Value, _: &Self::Value) -> bool {
false
}
}

Ok(dice.compute(self).await??)
}

Expand Down
Loading

0 comments on commit 698a22e

Please sign in to comment.