Skip to content

Clarifying the behavior of #[rustc_nounwind] at trait methods #137765

Open
@dianqk

Description

@dianqk

Currently, #[rustc_nounwind] is only applied to functions that are explicitly annotated; it's neither required nor applied by default to all implementations. I have no objection to this, but I think we need to clarify what the expected behavior should be.

An alternative is:

If you apply #[rustc_nounwind] on a trait method, it should be fine to assume that all calls of this trait method don't unwind, right? If any of the implementations doesn't use #[rustc_nounwind], that should probably be reported as error. (from #137669 (comment) @bjorn3)

pub trait Trait {
    #[rustc_nounwind]
    fn m(&self, _: (i32, i32, i32));
}

impl Trait for () {
    fn m(&self, _: (i32, i32, i32)) {
        panic!();
    }
}

Based on the current behavior, there are some miscompile.
In the case of https://rust.godbolt.org/z/aTWsEMxWq, all invokes should be unwinding.

From #137669.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutA-lang-itemArea: Language itemsF-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions