Skip to content

Suggested replacement code for E0139 results in memory unsafety #29922

Closed
@wthrowe

Description

@wthrowe

The message for E0139 suggests replacing let y: SomeType = unsafe { mem::transmute(v) }; with let y: SomeType = unsafe { ptr::read(&v as *const _ as *const SomeType) };. Actually performing such a replacement will result in double drops, since the transmute version consumes v but the read version does not. (It presumably needs a mem::forget(v) or something.)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions