1
Fork 0
rust/library/std/src
Matthias Krüger 4f4a819fa9
Rollup merge of #97316 - CAD97:bound-misbehavior, r=dtolnay
Put a bound on collection misbehavior

As currently written, when a logic error occurs in a collection's trait parameters, this allows *completely arbitrary* misbehavior, so long as it does not cause undefined behavior in std. However, because the extent of misbehavior is not specified, it is allowed for *any* code in std to start misbehaving in arbitrary ways which are not formally UB; consider the theoretical example of a global which gets set on an observed logic error. Because the misbehavior is only bound by not resulting in UB from safe APIs and the crate-level encapsulation boundary of all of std, this makes writing user unsafe code that utilizes std theoretically impossible, as it now relies on undocumented QOI (quality of implementation) that unrelated parts of std cannot be caused to misbehave by a misuse of std::collections APIs.

In practice, this is a nonconcern, because std has reasonable QOI and an implementation that takes advantage of this freedom is essentially a malicious implementation and only compliant by the most langauage-lawyer reading of the documentation.

To close this hole, we just add a small clause to the existing logic error paragraph that ensures that any misbehavior is limited to the collection which observed the logic error, making it more plausible to prove the soundness of user unsafe code.

This is not meant to be formal; a formal refinement would likely need to mention that values derived from the collection can also misbehave after a logic error is observed, as well as define what it means to "observe" a logic error in the first place. This fix errs on the side of informality in order to close the hole without complicating a normal reading which can assume a reasonable nonmalicious QOI.

See also [discussion on IRLO][1].

[1]: https://internals.rust-lang.org/t/using-std-collections-and-unsafe-anything-can-happen/16640

r? rust-lang/libs-api ```@rustbot``` label +T-libs-api -T-libs

This technically adds a new guarantee to the documentation, though I argue as written it's one already implicitly provided.
2022-05-31 23:11:34 +02:00
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Put a bound on collection misbehavior 2022-05-23 09:20:57 -05:00
env
error Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
f32 Implement IEEE 754-2019 minimun and maximum functions for f32/f64 2021-11-20 10:14:03 +01:00
f64 Remove fNN::lerp - consensus unlikely 2021-10-25 22:44:41 -05:00
ffi Auto merge of #96881 - est31:join_osstr, r=dtolnay 2022-05-31 04:28:29 +00:00
fs Use gender neutral terms 2022-04-07 08:51:59 +01:00
io Use Box::new() instead of box syntax in std tests 2022-05-29 01:44:11 +02:00
lazy
net Fix stabilization version of Ipv6Addr::to_ipv4_mapped 2022-05-24 01:05:06 +02:00
num
os Disable unix::net::ancillary on BSD. 2022-05-25 20:09:59 -07:00
panic
path Allow unused_macro_rules in path tests 2022-05-16 08:55:05 +02:00
prelude Finish bumping stage0 2022-05-27 07:36:17 -04:00
process Add test for issue #95178 2022-03-23 05:33:44 +00:00
sync Use Box::new() instead of box syntax in std tests 2022-05-29 01:44:11 +02:00
sys Remove "sys isn't exported yet" phrase 2022-05-30 12:07:43 +02:00
sys_common Remove "sys isn't exported yet" phrase 2022-05-30 12:07:43 +02:00
thread Use Box::new() instead of box syntax in std tests 2022-05-29 01:44:11 +02:00
time Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
alloc.rs update jemallocator example to use 2018 edition import syntax 2022-05-04 13:43:33 +02:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs revert changes that cast functions to raw pointers, portability hazard 2022-03-29 20:18:27 -04:00
env.rs add aliases for current_dir 2022-05-24 19:41:40 -07:00
error.rs Fix typo (panick -> panic) 2022-05-29 13:14:59 +04:00
f32.rs Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplett 2022-05-09 18:45:35 +02:00
f64.rs Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplett 2022-05-09 18:45:35 +02:00
fs.rs Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errors 2022-05-09 04:47:30 +00:00
keyword_docs.rs Fix weird indentation in continue_keyword docs 2022-05-24 11:10:56 -07:00
lazy.rs Add #[must_use] to core and std constructors 2021-10-10 02:44:26 -04:00
lib.rs Auto merge of #97574 - Dylan-DPC:rollup-jq850l6, r=Dylan-DPC 2022-05-31 06:53:02 +00:00
macros.rs Make write/print macros eagerly drop temporaries 2022-05-22 16:11:08 -07:00
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Configure panic hook backtrace behavior 2022-02-02 13:46:42 -05:00
panicking.rs Auto merge of #92461 - rust-lang:const_tls_local_panic_count, r=Mark-Simulacrum 2022-05-23 13:04:59 +00:00
path.rs fix panic in Path::strip_prefix 2022-05-08 22:15:26 +08:00
primitive_docs.rs Rollup merge of #97321 - RalfJung:int-to-fnptr, r=Dylan-DPC 2022-05-24 15:58:26 +02:00
process.rs small change 2022-05-22 17:52:04 +05:30
rt.rs Change Termination::report return type to ExitCode 2022-01-28 12:53:36 -08:00
time.rs std::time : fix doc variable name 2022-05-23 00:02:09 +02:00