The reference does not allow in-bounds reads of "partially dangling" pointers, whereas Miri does.
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- documentation
Research direction
Start with the Rust Reference sections on dangling pointers, pointed-to bytes, allocations, and undefined behavior, then reproduce the supplied example in Miri. Compare the Reference wording with Miri's behavior and determine the documentation change needed to resolve whether partially dangling pointers may be read; done means the semantics and example are described consistently.
Written by the indexing model from the issue text.
Description
Miri accepts this code, which prints 42:
#[repr(C)]
struct X {
a: usize,
}
#[repr(C)]
struct Y {
a: usize,
b: usize,
}
fn main() {
unsafe {
let x = X { a: 42 };
let py = &raw const x as *const Y;
let Y { a, .. } = *py;
println!("{a}");
}
}
On the other hand, the reference defines a dangling pointer as follows:
A reference/pointer is “dangling” if not all of the bytes it points to are part of the same live allocation (so in particular they all have to be part of some allocation).
And mentions as undefined behavior:
Accessing (loading from or storing to) a place that is dangling
Clearly, py is dangling by this definition, and clearly, the line let Y { a, .. } = *py; loads from py. So according to the reference, this should be UB. The reference does not have any notion of a "partially dangling" pointer that it's okay to read part of. Who is right: the reference or miri?
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 609
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/reference
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
rust-lang/reference#2371 · 3 comments ·
Maintainers usually reply within 1 day
-
A-const-eval A-undefined-behavior
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/reference#2266 · 1 comment ·
Maintainers usually reply within 1 day
-
A-resolve
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
All issues in rust-lang/reference
Similar issues
-
Change output crossing a compactsize boundary leaves the fee slightly below the requested feerateOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bitcoindevkit/bdk_wallet#578 ·
Maintainers usually reply within 8 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
521xueweihan/HelloGitHub#3832 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
canonical/opentelemetry-collector-operator#409 ·
Maintainers usually reply within 1 day