Skip to content

Too lenient #[may_dangle] on BTreeMap; misses PhantomData for dropck #99408

Closed
@steffahn

Description

@steffahn
struct PrintOnDrop<'a>(&'a str);

impl Drop for PrintOnDrop<'_> {
    fn drop(&mut self) {
        println!("printint: {}", self.0);
    }
}

use std::collections::BTreeMap;

fn main() {
    let s = String::from("Hello World!");
    let map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
    drop(s);
}

(playground)

printing: ��J��U��J�

@rustbot label T-libs, I-unsound
@rustbot claim

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions