Constructors don't receive `this` as the first argument
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
- 35/100
Línea de trabajo
Start by tracing constructor translation and the generated Rust representations for normal, copy, and move constructors; the issue gives no source files or tests to target. Read the related issues #582 and #248 for context, then locate the translation tests covering constructors. Done means constructors receive prebuilt storage through an explicit this argument, and copy/move translation avoids the extra construction and Clone behavior described here.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Normal constructors and copy/move constructors/assignments all receive this as an implicit first argument.
Our constructor translation instead receives no this and returns by value.
This has performance implications as described in #582 but most importantly it has wrong semantics:
- self referential constructors are broken (#248)
- copy/move constructors and assignments introduce calls that C++ does not have:
impl S {
pub fn copy_from(o: Ptr<S>) -> Self {
let __this: Counted = Self {
... // It constructs a fake __this that might have side effects
};
... body of copy ctor ...
__this
}
}
impl Clone for S {
fn clone(&self) -> Self {
// builds a fake argument for copy_from that might have side effects
let __src: Value<S> = Rc::new(RefCell::new(S { ... }));
S::copy_from(__src.as_pointer())
// drops the fake __src and the fields inside it
}
}
For 1, the solution is to build the storage before calling the constructor:
impl S {
pub fn new(this: Ptr<Self>) {
this.a = 1;
this.b = 2;
}
}
let s: Value<S> = Rc::new(RefCell::new(/* uninitialized storage of S */));
S::new(s.as_pointer());
For 2, the solution is to explicitly pass this to the copy ctor and stop using the Clone trait:
impl S for CopyConstructible {
pub fn copy_from(this: Ptr<S>, o: Ptr<S>) {
... body of copy ctor ...
}
}
- Lenguaje dominante
- Rust
- Estrellas
- 310
- Forks
- 18
- Merge medio
- 9 h 46 min
- PR fusionados (30 d)
- 82
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 Cpp2Rust/cpp2rust
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Cpp2Rust/cpp2rust#610 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 22/100
Los mantenedores suelen responder en 1 día
Todos los issues de Cpp2Rust/cpp2rust
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
kashsuks/Pinel#172 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
Los mantenedores suelen responder en 1 día
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixPosiblemente ocupada @naman-modi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
userFRM/egui-charts#4168 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día