rust-lang / rust-lang/rust

Docs say `const` items are always `'static`, but they aren't.

Open Beginner friendly
#159,162 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Location (URL)

https://doc.rust-lang.org/std/keyword.const.html

Summary

The documentation says:

The only lifetime allowed in a constant is 'static, which is the lifetime that encompasses all others in a Rust program.

However, the following program has a non-'static const (associated) item, contradicting the docs. It compiles without errors.

struct Thing<'a>(&'a i32);
impl<'a> Thing<'a> {
    const DATA: &'a i64 = &1;
}

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.

Research direction

Open the const keyword documentation at the reported URL and locate the statement about lifetimes in constants. Check it against the associated-const example in the issue, then revise the wording so the documentation matches the demonstrated behavior and verify the example still compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.