-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATsI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundnessrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
I tried this code:
#![feature(generic_associated_types)]
#![feature(associated_type_defaults)]
use core::ops::Deref;
trait UnsafeCopy {
type Copy<T>: Copy = Box<T>;
fn copy<T>(x: &Self::Copy<T>) -> Self::Copy<T> {
*x
}
}
impl <T> UnsafeCopy for T {}
fn main() {
let b = Box::new(42usize);
let copy = <()>::copy(&b);
let raw_b = Box::deref(&b) as *const _;
let raw_copy = Box::deref(©) as *const _;
// assert the addresses.
assert_eq!(raw_b, raw_copy);
}
I expected to see this happen: Getting some errors that Box<usize>
does not satisfy the Copy
bound.
Instead, this happened: The program compiled and resulted in a double free, b
and copy
both are of type Box<usize>
and point to the same memory...
Meta
rustc --version --verbose
:
1.47.0-nightly (2020-07-26 6c8927b0cf80ceee1938)
Backtrace
warning: 1 warning emitted
Finished dev [unoptimized + debuginfo] target(s) in 0.80s
Running `target/debug/playground`
free(): double free detected in tcache 2
timeout: the monitored command dumped core
/playground/tools/entrypoint.sh: line 11: 7 Aborted timeout --signal=KILL ${timeout} "$@"
95th
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs`#![feature(generic_associated_types)]` a.k.a. GATsI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundnessrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.