Pointer shared by all enum variants loses `noalias`, `align` and `dereferenceable` attributes
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 14/100
Línea de trabajo
This is compiler-internals work: two places must agree, the enum layout in rustc_abi (where the shared field offset and pointee type are derived) and the call-ABI attribute computation in rustc_codegen_llvm, which today only special-cases a null niche like Option<&mut i32>. Start by reproducing the two -Copt-level=3 -Cno-prepopulate-passes IR dumps in the issue and diffing both_mut against option_mut, then read how the reference attributes (noalias, dereferenceable, align, readonly) are attached for a plain reference. Done means each row of the issue's table emits the listed attributes, checked by a codegen test under tests/codegen.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When every variant of an enum stores a reference at the same offset, rustc emits that pointer to LLVM as an opaque ptr, without the attributes it would get on its own or inside Option.
#![crate_type = "lib"]
pub enum BothMut<'a> {
A(&'a mut i32),
B(&'a mut i32),
}
#[no_mangle]
pub fn both_mut(x: BothMut<'_>) {}
#[no_mangle]
pub fn option_mut(x: Option<&mut i32>) {}
With rustc 1.102.0-nightly (9c5648833 2026-11-10) and -Copt-level=3 -Cno-prepopulate-passes on aarch64-apple-darwin:
define void @both_mut(i64 noundef range(i64 0, 2) %x.0, ptr noundef %x.1)
define void @option_mut(ptr noalias nofree noundef align 4 dereferenceable_or_null(4) %x)
The second field of BothMut is a &mut i32 whichever variant is active, so it could be marked noalias nofree noundef align 4 dereferenceable_or_null(4), just like Option<&mut i32>. The same goes for shared references, which could also get readonly. Loads of the pointer miss !align metadata too:
#[derive(Clone, Copy)]
pub enum BothShared<'a> {
A(&'a i32),
B(&'a i32),
}
#[no_mangle]
pub fn load_both_shared<'a>(x: &BothShared<'a>) -> BothShared<'a> {
*x
}
%_0.1 = load ptr, ptr %0, align 8, !noundef !5
where !align !{i64 4} could be added.
Expected behaviour
If every inhabited variant has a pointer at the offset, the enum should get what all of them agree on:
- the smaller pointee size and alignment;
- the shared pointer kind, e.g. two
&mut Tstay&mut T,Box<T>and&mut Tmeet atBox<T>, while&Tand&mut Thave nothing in common beyond size and alignment; - nothing if any inhabited variant has a non-pointer, or nothing, at that offset.
Uninhabited variants can be ignored, and a null niche variant (as today) is compatible with any pointer.
| Type | Today | Could be |
|---|---|---|
enum { A(&mut i32), B(&mut i32) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&i32), B(&i32) } |
noundef |
noalias nofree noundef readonly align 4 captures(address, read_provenance) dereferenceable_or_null(4) |
enum { A(&mut u32), B(&mut [u64; 4]) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B(&i32) } |
noundef |
noundef align 4 dereferenceable_or_null(4) |
enum { A(Box<i32>), B(&mut i32) } |
noundef |
noalias noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B(*mut i32) } |
noundef |
noundef |
enum { A(&i32), B(usize) } |
noundef |
noundef |
enum { A(&mut i32), B(u64, Infallible) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
enum { A(&mut i32), B, C(Infallible) } |
noundef |
noalias nofree noundef align 4 dereferenceable_or_null(4) |
The last one is passed as a single pointer, like Option<&mut i32>, but misses out because it has three variants.
- Lenguaje dominante
- Rust
- Estrellas
- 123k
- Forks
- 16.6k
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 532
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rust
-
strictly_dominates missing a `=`AbiertoC-bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
rust-lang/rust#166722 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
A-run-make C-bug T-bootstrap
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`Abiertorelnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)Posiblemente ocupada @mastel2 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
storytold/craft-anything#2538 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
compiler-explorer/compiler-explorer#9738 ·
Los mantenedores suelen responder en 2 días
-
area: runtime enhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
hffgzktbcc-blip/ounce-core#663 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
zellij-org/zellij#6026 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
tamatebako/tebako#1155 ·
Los mantenedores suelen responder en 1 día