Skip to content

can't get the span of an arbitrary parsed attribute #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zjp-CN opened this issue Apr 11, 2025 · 0 comments · Fixed by #7
Closed

can't get the span of an arbitrary parsed attribute #5

zjp-CN opened this issue Apr 11, 2025 · 0 comments · Fixed by #7

Comments

@zjp-CN
Copy link
Member

zjp-CN commented Apr 11, 2025

thread 'standard_proof' panicked at tests/snapshots.rs:11:5:
Failed to test standard_proof.rs:
The application panicked (crashed).
Message:  can't get the span of an arbitrary parsed attribute: Parsed(Stability { stability: Stability { level: Unstable { reason: None, issue
: Some(81513), is_soft: false, implied_by: None }, feature: "ptr_metadata" }, span: /home/zjp/.rustup/toolchains/nightly-2025-04-01-x86_64-unk
nown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/metadata.rs:110:1: 110:55 (#0) })
Location: /home/zjp/.rustup/toolchains/nightly-2025-04-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/compiler/rustc_hir/src/hir.rs:1204

Seems that it's problematic to query span of some attributes?

#[unstable(feature = "ptr_metadata", issue = "81513")] // 💥fails to get this attr
#[inline]
pub const fn from_raw_parts<T: ?Sized>(
    data_pointer: *const impl Thin,
    metadata: <T as Pointee>::Metadata,
) -> *const T {
    aggregate_raw_ptr(data_pointer, metadata)
}

panic location: https://github.com/rust-lang/rust/blob/71b68da1bd9fa6afb9f964a731e9c843ab0862bd/compiler/rustc_hir/src/hir.rs#L1204

    fn span(&self) -> Span {
        match &self {
            Attribute::Unparsed(u) => u.span,
            // FIXME: should not be needed anymore when all attrs are parsed
            Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
            Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
            a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
        }
    }

So the problem is some internal attrs don't contain span, and attr.span() is infallible.

The solution is to extract some kinds of attrs, but most attrs on fns are not useful, except contracts.
The contracts come from two flavours: builtin-Rust, or custom tools

  • builtin-Rust contracts seems not a kind of attr, it may be converted to some generated code into the function, thus skip this case
  • #[kanitool::contract] is important, because once the contract content changes, proofs related to this contracts need to rerun
zjp-CN added a commit that referenced this issue Apr 11, 2025
@zjp-CN zjp-CN closed this as completed in #7 Apr 11, 2025
zjp-CN added a commit that referenced this issue Apr 16, 2025
cc #31 (comment)

$ cargo r -- --json=false tests/proofs/gen_by_macros.rs
...
(stable_mir span to internal span) [tests/proofs/gen_by_macros.rs:4:9: 4:26 (#4)]
fn $name() $block
[src/functions/mod.rs:114:5] span.from_expansion() = true
[src/functions/mod.rs:114:5] ancestor_span.from_expansion() = false
(find_oldest_ancestor_in_same_ctxt) [tests/proofs/gen_by_macros.rs:10:5: 10:57 (#0)]
gen! { proof1, { assert_eq!(kani::any::<u8>(), 0) }}

(stable_mir span to internal span) [/home/zjp/rust/distributed-verification/kani/library/kani_core/src/arbitrary.rs:38:21: 41:22 (#32)]
fn any() -> Self {
                        // This size_of call does not use generic_const_exprs feature. It's inside a macro, and Self isn't generic.
                        unsafe { crate::kani::any_raw_internal::<Self>() }
                    }
[src/functions/mod.rs:114:5] span.from_expansion() = true
[src/functions/mod.rs:114:5] ancestor_span.from_expansion() = true
(find_oldest_ancestor_in_same_ctxt) [/home/zjp/rust/distributed-verification/kani/library/kani_core/src/arbitrary.rs:66:9: 66:31 (#5)]
trivial_arbitrary!(u8)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant