Skip to content

Issue between non_local_definitions and soroban-sdk #132427

Closed
@Urgau

Description

@Urgau

After updating to rustc 1.84.0-nightly (759e07f06 2024-10-30), I am still seeing the warning when an impl is defined inside a const _: () = { ... } block is in code generated by a macro.

error: non-local `impl` definition, `impl` blocks should be written at the same level as their item
  --> /Users/leighmcculloch/Code/rs-soroban-sdk/soroban-sdk/src/auth.rs:11:1
   |
11 | #[contracttype(crate_path = "crate", export = false)]
   | ^----------------------------------------------------
   | |
   | `Arbitrary` is not local
   | move the `impl` block outside of this constant `_` and up 2 bodies
12 | pub enum Context {
   |          ------- `ArbitraryContext` is not local
   |
   = note: the derive macro `crate::testutils::arbitrary::arbitrary::Arbitrary` defines the non-local `impl`, and may need to be changed
   = note: the derive macro `crate::testutils::arbitrary::arbitrary::Arbitrary` may come from an old version of the `derive_arbitrary` crate, try updating your dependency with `cargo update -p derive_arbitrary`
   = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
   = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
   = note: `-D non-local-definitions` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(non_local_definitions)]`
   = note: this error originates in the derive macro `crate::testutils::arbitrary::arbitrary::Arbitrary` which comes from the expansion of the attribute macro `contracttype` (in Nightly builds, run with -Z macro-backtrace for more info)

The macro is generated by:
https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk-macros/src/arbitrary.rs#L320-L339

Originally posted by @leighmcculloch in #131643

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-non_local_definitionsLint: non_local_definitionsP-lowLow priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions