rust-lang / rust-lang/fls

[Change]: A pointer in a const does not need to be non-dangling

Open
#716 6 comments 0 reactions 1 assignee View on GitHub

@kirtchev-adacore is already working on this.

Since Aug 7, 2026.

Dominant language
reStructuredText
Stars
497
Forks
41
Avg merge
3h 52m
Merged PRs (30d)
4

Description

Change description

Currently the fls states that a pointer in a const shall be non-dangling. The compiler accepts a raw dangling pointers in constants.

Area

const evaluation

Category

Bug

FLS Paragraph ID

ls_l1FOH8zt0XRZ

Change description (extended)
fn main() {
    // accepted by the compiler
    const A: *const u8 = std::ptr::dangling();
    const B: *const u8 = std::ptr::null();
    // not accepted by the compiler    
    //const C: &u8 = unsafe { &(*std::ptr::dangling()) };
}

This creates a dangling pointer.
Maybe the text should be changed to say reference instead of pointer?

(i am sorry if i misunderstood the use of "shall". I looked at 1.3.5 and it seems to me that shall is used for rules that the programmer has to follow either to make the compiler accept the program or to avoid UB. But this is both accepted by the compiler and not UB.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.