Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5907a8c
Fix incorrect feature flags
jhpratt Nov 14, 2021
64cca29
Fix method name reference in stream documentation
jplatte Nov 21, 2021
15a4ed6
adjust const_eval_select documentation
RalfJung Nov 28, 2021
85558ad
adjust some const_eval_select safety comments
RalfJung Nov 28, 2021
80a308d
Use `HashMap::from()` instead of using `HashMap::new()` with `HashMap…
JosephTLyons Dec 2, 2021
440cffd
Use `BTreeMap::from()` instead of using `BTreeMap::new()` with `BTree…
JosephTLyons Dec 2, 2021
72a6974
Make `HashMap`s mutable again
JosephTLyons Dec 3, 2021
d5f6b9c
code-cov: generate dead functions with private/default linkage
wesleywiser Dec 2, 2021
8bfc76d
Fix Vec::extend_from_slice docs
rukai Dec 4, 2021
41f7692
Document all public items in `rustc_incremental`
pierwill Oct 29, 2021
d9e4502
fix documentation for `core::ready::Ready`
ibraheemdev Dec 8, 2021
15de4cb
Remove redundant [..]s
est31 Dec 3, 2021
99bd24e
Fix span calculation on secondary_label as well
compiler-errors Dec 5, 2021
71c1d56
Rollup merge of #90407 - pierwill:edit-rustc-incremental-docs, r=cjgi…
matthiaskrgr Dec 10, 2021
616f9ef
Rollup merge of #90897 - jhpratt:fix-incorrect-feature-flags, r=dtolnay
matthiaskrgr Dec 10, 2021
60aa03a
Rollup merge of #91105 - jplatte:stream-docs, r=dtolnay
matthiaskrgr Dec 10, 2021
d317da4
Rollup merge of #91325 - RalfJung:const_eval_select, r=dtolnay
matthiaskrgr Dec 10, 2021
b7b4d77
Rollup merge of #91470 - wesleywiser:code_coverage_link_error, r=tmandry
matthiaskrgr Dec 10, 2021
5510803
Rollup merge of #91482 - JosephTLyons:update-HashMap-and-BTreeMap-doc…
matthiaskrgr Dec 10, 2021
ca352c4
Rollup merge of #91524 - rukai:fix_extend_from_slice_docs, r=dtolnay
matthiaskrgr Dec 10, 2021
6cfe9af
Rollup merge of #91575 - compiler-errors:issue-91556, r=cjgillot
matthiaskrgr Dec 10, 2021
4098859
Rollup merge of #91625 - est31:remove_indexes, r=oli-obk
matthiaskrgr Dec 10, 2021
1fca934
Rollup merge of #91646 - ibraheemdev:patch-9, r=dtolnay
matthiaskrgr Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,8 +2070,8 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
#[cfg(debug_assertions)]
const fn compiletime_check<T>(_src: *const T, _dst: *mut T, _count: usize) {}
#[cfg(debug_assertions)]
// SAFETY: runtime debug-assertions are a best-effort basis; it's fine to
// not do them during compile time
// SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached.
// Therefore, compiletime_check and runtime_check are observably equivalent.
unsafe {
const_eval_select((src, dst, count), compiletime_check, runtime_check);
}
Expand Down Expand Up @@ -2161,8 +2161,8 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
#[cfg(debug_assertions)]
const fn compiletime_check<T>(_src: *const T, _dst: *mut T) {}
#[cfg(debug_assertions)]
// SAFETY: runtime debug-assertions are a best-effort basis; it's fine to
// not do them during compile time
// SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached.
// Therefore, compiletime_check and runtime_check are observably equivalent.
unsafe {
const_eval_select((src, dst), compiletime_check, runtime_check);
}
Expand Down Expand Up @@ -2273,19 +2273,40 @@ pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
///
/// # Safety
///
/// This intrinsic allows breaking [referential transparency] in `const fn`
/// and is therefore `unsafe`.
/// The two functions must behave observably equivalent. Safe code in other
/// crates may assume that calling a `const fn` at compile-time and at run-time
/// produces the same result. A function that produces a different result when
/// evaluated at run-time, or has any other observable side-effects, is
/// *unsound*.
///
/// Code that uses this intrinsic must be extremely careful to ensure that
/// `const fn`s remain referentially-transparent independently of when they
/// are evaluated.
/// Here is an example of how this could cause a problem:
/// ```no_run
/// #![feature(const_eval_select)]
/// use std::hint::unreachable_unchecked;
/// use std::intrinsics::const_eval_select;
///
/// The Rust compiler assumes that it is sound to replace a call to a `const
/// fn` with the result produced by evaluating it at compile-time. If
/// evaluating the function at run-time were to produce a different result,
/// or have any other observable side-effects, the behavior is undefined.
/// // Crate A
/// pub const fn inconsistent() -> i32 {
/// fn runtime() -> i32 { 1 }
/// const fn compiletime() -> i32 { 2 }
///
/// [referential transparency]: https://en.wikipedia.org/wiki/Referential_transparency
/// unsafe {
// // ⚠ This code violates the required equivalence of `compiletime`
/// // and `runtime`.
/// const_eval_select((), compiletime, runtime)
/// }
/// }
///
/// // Crate B
/// const X: i32 = inconsistent();
/// let x = inconsistent();
/// if x != X { unsafe { unreachable_unchecked(); }}
/// ```
///
/// This code causes Undefined Behavior when being run, since the
/// `unreachable_unchecked` is actually being reached. The bug is in *crate A*,
/// which violates the principle that a `const fn` must behave the same at
/// compile-time and at run-time. The unsafe code in crate B is fine.
#[unstable(
feature = "const_eval_select",
issue = "none",
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ const fn debug_check_data_len<T>(data: *const T, len: usize) {
// it is not required for safety (the safety must be guatanteed by
// the `from_raw_parts[_mut]` caller).
//
// Since the checks are not required, we ignore them in CTFE as they can't
// be done there (alignment does not make much sense there).
// As per our safety precondition, we may assume that assertion above never fails.
// Therefore, noop and rt_check are observably equivalent.
unsafe {
crate::intrinsics::const_eval_select((data,), noop, rt_check);
}
Expand Down