-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #68358 - matthewjasper:spec-fix, r=nikomatsakis
Remove some unsound specializations This removes the unsound and exploitable specializations in the standard library * The `PartialEq` and `Hash` implementations for `RangeInclusive` are changed to avoid specialization. * The `PartialOrd` specialization for slices now specializes on a limited set of concrete types. * Added some tests for the soundness problems.
- Loading branch information
Showing
7 changed files
with
168 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/ui/specialization/soundness/partial_eq_range_inclusive.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-pass | ||
|
||
use std::cell::RefCell; | ||
use std::cmp::Ordering; | ||
|
||
struct Evil<'a, 'b> { | ||
values: RefCell<Vec<&'a str>>, | ||
to_insert: &'b String, | ||
} | ||
|
||
impl<'a, 'b> PartialEq for Evil<'a, 'b> { | ||
fn eq(&self, _other: &Self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl<'a> PartialOrd for Evil<'a, 'a> { | ||
fn partial_cmp(&self, _other: &Self) -> Option<Ordering> { | ||
self.values.borrow_mut().push(self.to_insert); | ||
None | ||
} | ||
} | ||
|
||
fn main() { | ||
let e; | ||
let values; | ||
{ | ||
let to_insert = String::from("Hello, world!"); | ||
e = Evil { values: RefCell::new(Vec::new()), to_insert: &to_insert }; | ||
let range = &e..=&e; | ||
let _ = range == range; | ||
values = e.values; | ||
} | ||
assert_eq!(*values.borrow(), Vec::<&str>::new()); | ||
} |
Oops, something went wrong.