Skip to content

Commit 698a22e

Browse files
David Tolnayfacebook-github-bot
David Tolnay
authored andcommitted
Relocate non-local impl definitions
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
1 parent b97b4da commit 698a22e

File tree

7 files changed

+467
-473
lines changed

7 files changed

+467
-473
lines changed

app/buck2_analysis/src/analysis/calculation.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,33 @@ pub(crate) fn init_rule_analysis_calculation() {
7676
RULE_ANALYSIS_CALCULATION.init(&RuleAnalysisCalculationInstance);
7777
}
7878

79+
#[async_trait]
80+
impl Key for AnalysisKey {
81+
type Value = buck2_error::Result<MaybeCompatible<AnalysisResult>>;
82+
async fn compute(
83+
&self,
84+
ctx: &mut DiceComputations,
85+
_cancellation: &CancellationContext,
86+
) -> Self::Value {
87+
Ok(get_analysis_result(ctx, &self.0)
88+
.await
89+
.with_context(|| format!("Error running analysis for `{}`", &self.0))?)
90+
}
91+
92+
fn equality(_: &Self::Value, _: &Self::Value) -> bool {
93+
// analysis result is not comparable
94+
// TODO consider if we want analysis result to be eq
95+
false
96+
}
97+
}
98+
7999
#[async_trait]
80100
impl RuleAnalsysisCalculationImpl for RuleAnalysisCalculationInstance {
81101
async fn get_analysis_result(
82102
&self,
83103
ctx: &mut DiceComputations<'_>,
84104
target: &ConfiguredTargetLabel,
85105
) -> anyhow::Result<MaybeCompatible<AnalysisResult>> {
86-
#[async_trait]
87-
impl Key for AnalysisKey {
88-
type Value = buck2_error::Result<MaybeCompatible<AnalysisResult>>;
89-
async fn compute(
90-
&self,
91-
ctx: &mut DiceComputations,
92-
_cancellation: &CancellationContext,
93-
) -> Self::Value {
94-
Ok(get_analysis_result(ctx, &self.0)
95-
.await
96-
.with_context(|| format!("Error running analysis for `{}`", &self.0))?)
97-
}
98-
99-
fn equality(_: &Self::Value, _: &Self::Value) -> bool {
100-
// analysis result is not comparable
101-
// TODO consider if we want analysis result to be eq
102-
false
103-
}
104-
}
105-
106106
ctx.compute(&AnalysisKey(target.dupe()))
107107
.await?
108108
.map_err(anyhow::Error::from)

app/buck2_anon_target/src/anon_targets.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ pub enum AnonTargetsError {
125125
#[derive(Hash, Eq, PartialEq, Clone, Dupe, Debug, Display, Trace, Allocative)]
126126
pub(crate) struct AnonTargetKey(pub(crate) Arc<AnonTarget>);
127127

128+
#[async_trait]
129+
impl Key for AnonTargetKey {
130+
type Value = buck2_error::Result<AnalysisResult>;
131+
132+
async fn compute(
133+
&self,
134+
ctx: &mut DiceComputations,
135+
_cancellation: &CancellationContext,
136+
) -> Self::Value {
137+
Ok(self.run_analysis(ctx).await?)
138+
}
139+
140+
fn equality(_: &Self::Value, _: &Self::Value) -> bool {
141+
false
142+
}
143+
}
144+
128145
impl AnonTargetKey {
129146
fn downcast(key: Arc<dyn BaseDeferredKeyDyn>) -> anyhow::Result<Self> {
130147
Ok(AnonTargetKey(
@@ -256,23 +273,6 @@ impl AnonTargetKey {
256273
&self,
257274
dice: &mut DiceComputations<'_>,
258275
) -> anyhow::Result<AnalysisResult> {
259-
#[async_trait]
260-
impl Key for AnonTargetKey {
261-
type Value = buck2_error::Result<AnalysisResult>;
262-
263-
async fn compute(
264-
&self,
265-
ctx: &mut DiceComputations,
266-
_cancellation: &CancellationContext,
267-
) -> Self::Value {
268-
Ok(self.run_analysis(ctx).await?)
269-
}
270-
271-
fn equality(_: &Self::Value, _: &Self::Value) -> bool {
272-
false
273-
}
274-
}
275-
276276
Ok(dice.compute(self).await??)
277277
}
278278

0 commit comments

Comments
 (0)