Skip to content

core::panic!() cannot be used everywhere std::panic!() can. #80846

Closed
@m-ou-se

Description

@m-ou-se

This compiles:

fn main() {
    let x = &5;
    x = &std::panic!()
}

This does not:

fn main() {
    let x = &5;
    x = &core::panic!()
}
error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
3 |     x = &core::panic!()
  |         ^^^^^^^^^^^^^^^ expected integer, found `!`
  |
  = note: expected reference `&{integer}`
             found reference `&!`

The cause seems to be that std::panic!() expands to { some_function(..) } while core::panic!() expands to some_function(..), without { .. }. Adding { .. } in the core::panic!() macro_rules 'fixes' it.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-libs-apiRelevant to the library API 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