Skip to content

Commit e400ede

Browse files
authored
refactor: remove obsolete tranform let_x_uninitialized (#1613)
`let_x_uninitialized` is obsolete since the transpiler now initializes everything. This is also an old transform, using the deprecated `mem::uninitialized` instead of `MaybeUninit`, and not wrapping it in `unsafe` either. Furthermore, the `let_x_uninitialized.rs` test didn't compile since the variables were untyped.
2 parents ce3bbc8 + e36d590 commit e400ede

File tree

3 files changed

+2
-41
lines changed

3 files changed

+2
-41
lines changed

c2rust-refactor/src/transform/vars.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,12 @@ use crate::ast_manip::{MutVisit, MutVisitNodes, fold_blocks, visit_nodes};
1515
use crate::command::{CommandState, DriverCommand, Registry};
1616
use crate::driver::{Phase};
1717
use crate::match_or;
18-
use crate::matcher::{MatchCtxt, Subst, mut_visit_match_with, replace_stmts};
18+
use crate::matcher::{MatchCtxt, Subst, mut_visit_match_with};
1919
use crate::reflect::reflect_tcx_ty;
2020
use crate::transform::Transform;
2121
use crate::RefactorCtxt;
2222

2323

24-
/// # `let_x_uninitialized` Command
25-
///
26-
/// Obsolete - the translator now does this automatically.
27-
///
28-
/// Usage: `let_x_uninitialized`
29-
///
30-
/// For each local variable that is uninitialized (`let x;`), add
31-
/// `mem::uninitialized()` as an initializer expression.
32-
pub struct LetXUninitialized;
33-
34-
impl Transform for LetXUninitialized {
35-
fn transform(&self, krate: &mut Crate, st: &CommandState, cx: &RefactorCtxt) {
36-
replace_stmts(st, cx, krate,
37-
"let __pat;",
38-
"let __pat = ::std::mem::uninitialized();");
39-
replace_stmts(st, cx, krate,
40-
"let __pat: __ty;",
41-
"let __pat: __ty = ::std::mem::uninitialized();");
42-
}
43-
}
44-
45-
4624
/// # `sink_lets` Command
4725
///
4826
/// Usage: `sink_lets`
@@ -570,7 +548,6 @@ fn expand_local_ptr_tys(st: &CommandState, cx: &RefactorCtxt) {
570548
pub fn register_commands(reg: &mut Registry) {
571549
use super::mk;
572550

573-
reg.register("let_x_uninitialized", |_args| mk(LetXUninitialized));
574551
reg.register("sink_lets", |_args| mk(SinkLets));
575552
reg.register("fold_let_assign", |_args| mk(FoldLetAssign));
576553
reg.register("uninit_to_default", |_args| mk(UninitToDefault));

c2rust-refactor/tests/snapshots.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl<'a> RefactorTest<'a> {
8282
}
8383
}
8484

85+
#[allow(unused)] // TODO remove when used
8586
pub fn expect_compile_error(self, expect_error: bool) -> Self {
8687
self.old_expect_compile_error(expect_error)
8788
.new_expect_compile_error(expect_error)
@@ -249,13 +250,6 @@ fn test_fold_let_assign() {
249250
refactor("fold_let_assign").test();
250251
}
251252

252-
#[test]
253-
fn test_let_x_uninitialized() {
254-
refactor("let_x_uninitialized")
255-
.expect_compile_error(true)
256-
.test();
257-
}
258-
259253
#[test]
260254
fn test_reconstruct_while() {
261255
refactor("reconstruct_while").test();

c2rust-refactor/tests/snapshots/snapshots__refactor-let_x_uninitialized.rs.snap

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)