Auto merge of #102234 - matthiaskrgr:rollup-5cb20l1, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #100823 (Refactor some `std` code that works with pointer offstes)
 - #102088 (Fix wrongly refactored Lift impl)
 - #102109 (resolve: Set effective visibilities for imports more precisely)
 - #102186 (Add const_closure, Constify Try trait)
 - #102203 (rustdoc: remove no-op CSS `#source-sidebar { z-index }`)
 - #102204 (Make `ManuallyDrop` satisfy `~const Destruct`)
 - #102210 (diagnostics: avoid syntactically invalid suggestion in if conditionals)
 - #102226 (bootstrap/miri: switch to non-deprecated env var for setting the sysroot folder)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-09-24 14:37:01 +00:00
commit 6580010551
24 changed files with 310 additions and 102 deletions

View File

@ -272,7 +272,10 @@ fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
type Lifted = Option<T::Lifted>; type Lifted = Option<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(self?).map(Some) Some(match self {
Some(x) => Some(tcx.lift(x)?),
None => None,
})
} }
} }

View File

@ -1,4 +1,3 @@
use crate::imports::ImportKind;
use crate::NameBinding; use crate::NameBinding;
use crate::NameBindingKind; use crate::NameBindingKind;
use crate::Resolver; use crate::Resolver;
@ -54,15 +53,11 @@ fn set_bindings_access_level(&mut self, module_id: LocalDefId) {
// sets the rest of the `use` chain to `AccessLevel::Exported` until // sets the rest of the `use` chain to `AccessLevel::Exported` until
// we hit the actual exported item. // we hit the actual exported item.
let set_import_binding_access_level = let set_import_binding_access_level =
|this: &mut Self, mut binding: &NameBinding<'a>, mut access_level| { |this: &mut Self, mut binding: &NameBinding<'a>, mut access_level, ns| {
while let NameBindingKind::Import { binding: nested_binding, import, .. } = while let NameBindingKind::Import { binding: nested_binding, import, .. } =
binding.kind binding.kind
{ {
this.set_access_level(import.id, access_level); this.set_access_level(this.r.import_id_for_ns(import, ns), access_level);
if let ImportKind::Single { additional_ids, .. } = import.kind {
this.set_access_level(additional_ids.0, access_level);
this.set_access_level(additional_ids.1, access_level);
}
access_level = Some(AccessLevel::Exported); access_level = Some(AccessLevel::Exported);
binding = nested_binding; binding = nested_binding;
@ -72,11 +67,11 @@ fn set_bindings_access_level(&mut self, module_id: LocalDefId) {
let module = self.r.get_module(module_id.to_def_id()).unwrap(); let module = self.r.get_module(module_id.to_def_id()).unwrap();
let resolutions = self.r.resolutions(module); let resolutions = self.r.resolutions(module);
for (.., name_resolution) in resolutions.borrow().iter() { for (key, name_resolution) in resolutions.borrow().iter() {
if let Some(binding) = name_resolution.borrow().binding() && binding.vis.is_public() && !binding.is_ambiguity() { if let Some(binding) = name_resolution.borrow().binding() && binding.vis.is_public() && !binding.is_ambiguity() {
let access_level = match binding.is_import() { let access_level = match binding.is_import() {
true => { true => {
set_import_binding_access_level(self, binding, module_level); set_import_binding_access_level(self, binding, module_level, key.ns);
Some(AccessLevel::Exported) Some(AccessLevel::Exported)
}, },
false => module_level, false => module_level,

View File

@ -2,7 +2,7 @@
use crate::diagnostics::Suggestion; use crate::diagnostics::Suggestion;
use crate::Determinacy::{self, *}; use crate::Determinacy::{self, *};
use crate::Namespace::{MacroNS, TypeNS}; use crate::Namespace::{self, *};
use crate::{module_to_string, names_to_string}; use crate::{module_to_string, names_to_string};
use crate::{AmbiguityKind, BindingKey, ModuleKind, ResolutionError, Resolver, Segment}; use crate::{AmbiguityKind, BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet}; use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet};
@ -371,6 +371,31 @@ fn import_dummy_binding(&mut self, import: &'a Import<'a>) {
self.used_imports.insert(import.id); self.used_imports.insert(import.id);
} }
} }
/// Take primary and additional node IDs from an import and select one that corresponds to the
/// given namespace. The logic must match the corresponding logic from `fn lower_use_tree` that
/// assigns resolutons to IDs.
pub(crate) fn import_id_for_ns(&self, import: &Import<'_>, ns: Namespace) -> NodeId {
if let ImportKind::Single { additional_ids: (id1, id2), .. } = import.kind {
if let Some(resolutions) = self.import_res_map.get(&import.id) {
assert!(resolutions[ns].is_some(), "incorrectly finalized import");
return match ns {
TypeNS => import.id,
ValueNS => match resolutions.type_ns {
Some(_) => id1,
None => import.id,
},
MacroNS => match (resolutions.type_ns, resolutions.value_ns) {
(Some(_), Some(_)) => id2,
(Some(_), None) | (None, Some(_)) => id1,
(None, None) => import.id,
},
};
}
}
import.id
}
} }
/// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved /// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved

View File

@ -1224,6 +1224,9 @@ fn confirm_const_destruct_candidate(
| ty::Never | ty::Never
| ty::Foreign(_) => {} | ty::Foreign(_) => {}
// `ManuallyDrop` is trivially drop
ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().manually_drop() => {}
// These types are built-in, so we can fast-track by registering // These types are built-in, so we can fast-track by registering
// nested predicates for their constituent type(s) // nested predicates for their constituent type(s)
ty::Array(ty, _) | ty::Slice(ty) => { ty::Array(ty, _) | ty::Slice(ty) => {

View File

@ -417,6 +417,16 @@ fn suggest_compatible_variants(
hir::def::CtorKind::Const => unreachable!(), hir::def::CtorKind::Const => unreachable!(),
}; };
// Suggest constructor as deep into the block tree as possible.
// This fixes https://github.com/rust-lang/rust/issues/101065,
// and also just helps make the most minimal suggestions.
let mut expr = expr;
while let hir::ExprKind::Block(block, _) = &expr.kind
&& let Some(expr_) = &block.expr
{
expr = expr_
}
vec![ vec![
(expr.span.shrink_to_lo(), format!("{prefix}{variant}{open}")), (expr.span.shrink_to_lo(), format!("{prefix}{variant}{open}")),
(expr.span.shrink_to_hi(), close.to_owned()), (expr.span.shrink_to_hi(), close.to_owned()),

View File

@ -0,0 +1,63 @@
use crate::marker::Destruct;
/// Struct representing a closure with mutably borrowed data.
///
/// Example:
/// ```no_build
/// #![feature(const_mut_refs)]
/// use crate::const_closure::ConstFnMutClosure;
/// const fn imp(state: &mut i32, (arg,): (i32,)) -> i32 {
/// *state += arg;
/// *state
/// }
/// let mut i = 5;
/// let mut cl = ConstFnMutClosure::new(&mut i, imp);
///
/// assert!(7 == cl(2));
/// assert!(8 == cl(1));
/// ```
pub(crate) struct ConstFnMutClosure<'a, CapturedData: ?Sized, Function> {
data: &'a mut CapturedData,
func: Function,
}
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Function> {
/// Function for creating a new closure.
///
/// `data` is the a mutable borrow of data that is captured from the environment.
///
/// `func` is the function of the closure, it gets the data and a tuple of the arguments closure
/// and return the return value of the closure.
pub(crate) const fn new<ClosureArguments, ClosureReturnValue>(
data: &'a mut CapturedData,
func: Function,
) -> Self
where
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
{
Self { data, func }
}
}
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
FnOnce<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
where
Function:
~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct,
{
type Output = ClosureReturnValue;
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
self.call_mut(args)
}
}
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
FnMut<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
where
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
{
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
(self.func)(self.data, args)
}
}

View File

@ -211,7 +211,7 @@ macro_rules! impl_Display {
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// 2^128 is about 3*10^38, so 39 gives an extra byte of space // 2^128 is about 3*10^38, so 39 gives an extra byte of space
let mut buf = [MaybeUninit::<u8>::uninit(); 39]; let mut buf = [MaybeUninit::<u8>::uninit(); 39];
let mut curr = buf.len() as isize; let mut curr = buf.len();
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf); let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
let lut_ptr = DEC_DIGITS_LUT.as_ptr(); let lut_ptr = DEC_DIGITS_LUT.as_ptr();
@ -228,7 +228,7 @@ fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Re
// eagerly decode 4 characters at a time // eagerly decode 4 characters at a time
while n >= 10000 { while n >= 10000 {
let rem = (n % 10000) as isize; let rem = (n % 10000) as usize;
n /= 10000; n /= 10000;
let d1 = (rem / 100) << 1; let d1 = (rem / 100) << 1;
@ -238,29 +238,29 @@ fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Re
// We are allowed to copy to `buf_ptr[curr..curr + 3]` here since // We are allowed to copy to `buf_ptr[curr..curr + 3]` here since
// otherwise `curr < 0`. But then `n` was originally at least `10000^10` // otherwise `curr < 0`. But then `n` was originally at least `10000^10`
// which is `10^40 > 2^128 > n`. // which is `10^40 > 2^128 > n`.
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1), buf_ptr.add(curr), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2); ptr::copy_nonoverlapping(lut_ptr.add(d2), buf_ptr.add(curr + 2), 2);
} }
// if we reach here numbers are <= 9999, so at most 4 chars long // if we reach here numbers are <= 9999, so at most 4 chars long
let mut n = n as isize; // possibly reduce 64bit math let mut n = n as usize; // possibly reduce 64bit math
// decode 2 more chars, if > 2 chars // decode 2 more chars, if > 2 chars
if n >= 100 { if n >= 100 {
let d1 = (n % 100) << 1; let d1 = (n % 100) << 1;
n /= 100; n /= 100;
curr -= 2; curr -= 2;
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1), buf_ptr.add(curr), 2);
} }
// decode last 1 or 2 chars // decode last 1 or 2 chars
if n < 10 { if n < 10 {
curr -= 1; curr -= 1;
*buf_ptr.offset(curr) = (n as u8) + b'0'; *buf_ptr.add(curr) = (n as u8) + b'0';
} else { } else {
let d1 = n << 1; let d1 = n << 1;
curr -= 2; curr -= 2;
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1), buf_ptr.add(curr), 2);
} }
} }
@ -268,7 +268,7 @@ fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Re
// UTF-8 since `DEC_DIGITS_LUT` is // UTF-8 since `DEC_DIGITS_LUT` is
let buf_slice = unsafe { let buf_slice = unsafe {
str::from_utf8_unchecked( str::from_utf8_unchecked(
slice::from_raw_parts(buf_ptr.offset(curr), buf.len() - curr as usize)) slice::from_raw_parts(buf_ptr.add(curr), buf.len() - curr))
}; };
f.pad_integral(is_nonnegative, "", buf_slice) f.pad_integral(is_nonnegative, "", buf_slice)
} }
@ -339,18 +339,18 @@ fn $name(
// Since `curr` always decreases by the number of digits copied, this means // Since `curr` always decreases by the number of digits copied, this means
// that `curr >= 0`. // that `curr >= 0`.
let mut buf = [MaybeUninit::<u8>::uninit(); 40]; let mut buf = [MaybeUninit::<u8>::uninit(); 40];
let mut curr = buf.len() as isize; //index for buf let mut curr = buf.len(); //index for buf
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf); let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
let lut_ptr = DEC_DIGITS_LUT.as_ptr(); let lut_ptr = DEC_DIGITS_LUT.as_ptr();
// decode 2 chars at a time // decode 2 chars at a time
while n >= 100 { while n >= 100 {
let d1 = ((n % 100) as isize) << 1; let d1 = ((n % 100) as usize) << 1;
curr -= 2; curr -= 2;
// SAFETY: `d1 <= 198`, so we can copy from `lut_ptr[d1..d1 + 2]` since // SAFETY: `d1 <= 198`, so we can copy from `lut_ptr[d1..d1 + 2]` since
// `DEC_DIGITS_LUT` has a length of 200. // `DEC_DIGITS_LUT` has a length of 200.
unsafe { unsafe {
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1), buf_ptr.add(curr), 2);
} }
n /= 100; n /= 100;
exponent += 2; exponent += 2;
@ -362,7 +362,7 @@ fn $name(
curr -= 1; curr -= 1;
// SAFETY: Safe since `40 > curr >= 0` (see comment) // SAFETY: Safe since `40 > curr >= 0` (see comment)
unsafe { unsafe {
*buf_ptr.offset(curr) = (n as u8 % 10_u8) + b'0'; *buf_ptr.add(curr) = (n as u8 % 10_u8) + b'0';
} }
n /= 10; n /= 10;
exponent += 1; exponent += 1;
@ -372,7 +372,7 @@ fn $name(
curr -= 1; curr -= 1;
// SAFETY: Safe since `40 > curr >= 0` // SAFETY: Safe since `40 > curr >= 0`
unsafe { unsafe {
*buf_ptr.offset(curr) = b'.'; *buf_ptr.add(curr) = b'.';
} }
} }
@ -380,10 +380,10 @@ fn $name(
let buf_slice = unsafe { let buf_slice = unsafe {
// decode last character // decode last character
curr -= 1; curr -= 1;
*buf_ptr.offset(curr) = (n as u8) + b'0'; *buf_ptr.add(curr) = (n as u8) + b'0';
let len = buf.len() - curr as usize; let len = buf.len() - curr as usize;
slice::from_raw_parts(buf_ptr.offset(curr), len) slice::from_raw_parts(buf_ptr.add(curr), len)
}; };
// stores 'e' (or 'E') and the up to 2-digit exponent // stores 'e' (or 'E') and the up to 2-digit exponent
@ -392,13 +392,13 @@ fn $name(
// SAFETY: In either case, `exp_buf` is written within bounds and `exp_ptr[..len]` // SAFETY: In either case, `exp_buf` is written within bounds and `exp_ptr[..len]`
// is contained within `exp_buf` since `len <= 3`. // is contained within `exp_buf` since `len <= 3`.
let exp_slice = unsafe { let exp_slice = unsafe {
*exp_ptr.offset(0) = if upper { b'E' } else { b'e' }; *exp_ptr.add(0) = if upper { b'E' } else { b'e' };
let len = if exponent < 10 { let len = if exponent < 10 {
*exp_ptr.offset(1) = (exponent as u8) + b'0'; *exp_ptr.add(1) = (exponent as u8) + b'0';
2 2
} else { } else {
let off = exponent << 1; let off = exponent << 1;
ptr::copy_nonoverlapping(lut_ptr.offset(off), exp_ptr.offset(1), 2); ptr::copy_nonoverlapping(lut_ptr.add(off), exp_ptr.add(1), 2);
3 3
}; };
slice::from_raw_parts(exp_ptr, len) slice::from_raw_parts(exp_ptr, len)
@ -479,7 +479,7 @@ mod imp {
impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128); impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128);
/// Helper function for writing a u64 into `buf` going from last to first, with `curr`. /// Helper function for writing a u64 into `buf` going from last to first, with `curr`.
fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], curr: &mut isize) { fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], curr: &mut usize) {
let buf_ptr = MaybeUninit::slice_as_mut_ptr(buf); let buf_ptr = MaybeUninit::slice_as_mut_ptr(buf);
let lut_ptr = DEC_DIGITS_LUT.as_ptr(); let lut_ptr = DEC_DIGITS_LUT.as_ptr();
assert!(*curr > 19); assert!(*curr > 19);
@ -505,14 +505,14 @@ mod imp {
*curr -= 16; *curr -= 16;
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1 as usize), buf_ptr.add(*curr + 0), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2); ptr::copy_nonoverlapping(lut_ptr.add(d2 as usize), buf_ptr.add(*curr + 2), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2); ptr::copy_nonoverlapping(lut_ptr.add(d3 as usize), buf_ptr.add(*curr + 4), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2); ptr::copy_nonoverlapping(lut_ptr.add(d4 as usize), buf_ptr.add(*curr + 6), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d5 as isize), buf_ptr.offset(*curr + 8), 2); ptr::copy_nonoverlapping(lut_ptr.add(d5 as usize), buf_ptr.add(*curr + 8), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d6 as isize), buf_ptr.offset(*curr + 10), 2); ptr::copy_nonoverlapping(lut_ptr.add(d6 as usize), buf_ptr.add(*curr + 10), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d7 as isize), buf_ptr.offset(*curr + 12), 2); ptr::copy_nonoverlapping(lut_ptr.add(d7 as usize), buf_ptr.add(*curr + 12), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d8 as isize), buf_ptr.offset(*curr + 14), 2); ptr::copy_nonoverlapping(lut_ptr.add(d8 as usize), buf_ptr.add(*curr + 14), 2);
} }
if n >= 1e8 as u64 { if n >= 1e8 as u64 {
let to_parse = n % 1e8 as u64; let to_parse = n % 1e8 as u64;
@ -525,10 +525,10 @@ mod imp {
let d4 = ((to_parse / 1e0 as u64) % 100) << 1; let d4 = ((to_parse / 1e0 as u64) % 100) << 1;
*curr -= 8; *curr -= 8;
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1 as usize), buf_ptr.add(*curr + 0), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2); ptr::copy_nonoverlapping(lut_ptr.add(d2 as usize), buf_ptr.add(*curr + 2), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d3 as isize), buf_ptr.offset(*curr + 4), 2); ptr::copy_nonoverlapping(lut_ptr.add(d3 as usize), buf_ptr.add(*curr + 4), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d4 as isize), buf_ptr.offset(*curr + 6), 2); ptr::copy_nonoverlapping(lut_ptr.add(d4 as usize), buf_ptr.add(*curr + 6), 2);
} }
// `n` < 1e8 < (1 << 32) // `n` < 1e8 < (1 << 32)
let mut n = n as u32; let mut n = n as u32;
@ -540,8 +540,8 @@ mod imp {
let d2 = (to_parse % 100) << 1; let d2 = (to_parse % 100) << 1;
*curr -= 4; *curr -= 4;
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr + 0), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1 as usize), buf_ptr.add(*curr + 0), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2 as isize), buf_ptr.offset(*curr + 2), 2); ptr::copy_nonoverlapping(lut_ptr.add(d2 as usize), buf_ptr.add(*curr + 2), 2);
} }
// `n` < 1e4 < (1 << 16) // `n` < 1e4 < (1 << 16)
@ -550,17 +550,17 @@ mod imp {
let d1 = (n % 100) << 1; let d1 = (n % 100) << 1;
n /= 100; n /= 100;
*curr -= 2; *curr -= 2;
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1 as usize), buf_ptr.add(*curr), 2);
} }
// decode last 1 or 2 chars // decode last 1 or 2 chars
if n < 10 { if n < 10 {
*curr -= 1; *curr -= 1;
*buf_ptr.offset(*curr) = (n as u8) + b'0'; *buf_ptr.add(*curr) = (n as u8) + b'0';
} else { } else {
let d1 = n << 1; let d1 = n << 1;
*curr -= 2; *curr -= 2;
ptr::copy_nonoverlapping(lut_ptr.offset(d1 as isize), buf_ptr.offset(*curr), 2); ptr::copy_nonoverlapping(lut_ptr.add(d1 as usize), buf_ptr.add(*curr), 2);
} }
} }
} }
@ -593,21 +593,21 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// 2^128 is about 3*10^38, so 39 gives an extra byte of space // 2^128 is about 3*10^38, so 39 gives an extra byte of space
let mut buf = [MaybeUninit::<u8>::uninit(); 39]; let mut buf = [MaybeUninit::<u8>::uninit(); 39];
let mut curr = buf.len() as isize; let mut curr = buf.len();
let (n, rem) = udiv_1e19(n); let (n, rem) = udiv_1e19(n);
parse_u64_into(rem, &mut buf, &mut curr); parse_u64_into(rem, &mut buf, &mut curr);
if n != 0 { if n != 0 {
// 0 pad up to point // 0 pad up to point
let target = (buf.len() - 19) as isize; let target = buf.len() - 19;
// SAFETY: Guaranteed that we wrote at most 19 bytes, and there must be space // SAFETY: Guaranteed that we wrote at most 19 bytes, and there must be space
// remaining since it has length 39 // remaining since it has length 39
unsafe { unsafe {
ptr::write_bytes( ptr::write_bytes(
MaybeUninit::slice_as_mut_ptr(&mut buf).offset(target), MaybeUninit::slice_as_mut_ptr(&mut buf).add(target),
b'0', b'0',
(curr - target) as usize, curr - target,
); );
} }
curr = target; curr = target;
@ -616,16 +616,16 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
parse_u64_into(rem, &mut buf, &mut curr); parse_u64_into(rem, &mut buf, &mut curr);
// Should this following branch be annotated with unlikely? // Should this following branch be annotated with unlikely?
if n != 0 { if n != 0 {
let target = (buf.len() - 38) as isize; let target = buf.len() - 38;
// The raw `buf_ptr` pointer is only valid until `buf` is used the next time, // The raw `buf_ptr` pointer is only valid until `buf` is used the next time,
// buf `buf` is not used in this scope so we are good. // buf `buf` is not used in this scope so we are good.
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf); let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
// SAFETY: At this point we wrote at most 38 bytes, pad up to that point, // SAFETY: At this point we wrote at most 38 bytes, pad up to that point,
// There can only be at most 1 digit remaining. // There can only be at most 1 digit remaining.
unsafe { unsafe {
ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); ptr::write_bytes(buf_ptr.add(target), b'0', curr - target);
curr = target - 1; curr = target - 1;
*buf_ptr.offset(curr) = (n as u8) + b'0'; *buf_ptr.add(curr) = (n as u8) + b'0';
} }
} }
} }
@ -634,8 +634,8 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
// UTF-8 since `DEC_DIGITS_LUT` is // UTF-8 since `DEC_DIGITS_LUT` is
let buf_slice = unsafe { let buf_slice = unsafe {
str::from_utf8_unchecked(slice::from_raw_parts( str::from_utf8_unchecked(slice::from_raw_parts(
MaybeUninit::slice_as_mut_ptr(&mut buf).offset(curr), MaybeUninit::slice_as_mut_ptr(&mut buf).add(curr),
buf.len() - curr as usize, buf.len() - curr,
)) ))
}; };
f.pad_integral(is_nonnegative, "", buf_slice) f.pad_integral(is_nonnegative, "", buf_slice)

View File

@ -1,4 +1,5 @@
use crate::array; use crate::array;
use crate::const_closure::ConstFnMutClosure;
use crate::iter::{ByRefSized, FusedIterator, Iterator}; use crate::iter::{ByRefSized, FusedIterator, Iterator};
use crate::ops::{ControlFlow, NeverShortCircuit, Try}; use crate::ops::{ControlFlow, NeverShortCircuit, Try};
@ -82,12 +83,12 @@ fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
} }
} }
fn fold<B, F>(mut self, init: B, f: F) -> B fn fold<B, F>(mut self, init: B, mut f: F) -> B
where where
Self: Sized, Self: Sized,
F: FnMut(B, Self::Item) -> B, F: FnMut(B, Self::Item) -> B,
{ {
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0 self.try_fold(init, ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp)).0
} }
} }
@ -126,12 +127,12 @@ fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R
try { acc } try { acc }
} }
fn rfold<B, F>(mut self, init: B, f: F) -> B fn rfold<B, F>(mut self, init: B, mut f: F) -> B
where where
Self: Sized, Self: Sized,
F: FnMut(B, Self::Item) -> B, F: FnMut(B, Self::Item) -> B,
{ {
self.try_rfold(init, NeverShortCircuit::wrap_mut_2(f)).0 self.try_rfold(init, ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp)).0
} }
} }

View File

@ -1,4 +1,7 @@
use crate::ops::{NeverShortCircuit, Try}; use crate::{
const_closure::ConstFnMutClosure,
ops::{NeverShortCircuit, Try},
};
/// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics. /// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics.
/// ///
@ -36,12 +39,13 @@ fn nth(&mut self, n: usize) -> Option<Self::Item> {
} }
#[inline] #[inline]
fn fold<B, F>(self, init: B, f: F) -> B fn fold<B, F>(self, init: B, mut f: F) -> B
where where
F: FnMut(B, Self::Item) -> B, F: FnMut(B, Self::Item) -> B,
{ {
// `fold` needs ownership, so this can't forward directly. // `fold` needs ownership, so this can't forward directly.
I::try_fold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0 I::try_fold(self.0, init, ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp))
.0
} }
#[inline] #[inline]
@ -72,12 +76,17 @@ fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
} }
#[inline] #[inline]
fn rfold<B, F>(self, init: B, f: F) -> B fn rfold<B, F>(self, init: B, mut f: F) -> B
where where
F: FnMut(B, Self::Item) -> B, F: FnMut(B, Self::Item) -> B,
{ {
// `rfold` needs ownership, so this can't forward directly. // `rfold` needs ownership, so this can't forward directly.
I::try_rfold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0 I::try_rfold(
self.0,
init,
ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp),
)
.0
} }
#[inline] #[inline]

View File

@ -1,3 +1,4 @@
use crate::const_closure::ConstFnMutClosure;
use crate::iter::{InPlaceIterable, Iterator}; use crate::iter::{InPlaceIterable, Iterator};
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, NeverShortCircuit, Residual, Try}; use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, NeverShortCircuit, Residual, Try};
@ -203,12 +204,12 @@ fn try_fold<B, F, T>(&mut self, init: B, mut f: F) -> T
.into_try() .into_try()
} }
fn fold<B, F>(mut self, init: B, fold: F) -> B fn fold<B, F>(mut self, init: B, mut fold: F) -> B
where where
Self: Sized, Self: Sized,
F: FnMut(B, Self::Item) -> B, F: FnMut(B, Self::Item) -> B,
{ {
self.try_fold(init, NeverShortCircuit::wrap_mut_2(fold)).0 self.try_fold(init, ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0
} }
} }

View File

@ -356,6 +356,8 @@ pub mod assert_matches {
mod tuple; mod tuple;
mod unit; mod unit;
mod const_closure;
#[stable(feature = "core_primitive", since = "1.43.0")] #[stable(feature = "core_primitive", since = "1.43.0")]
pub mod primitive; pub mod primitive;

View File

@ -126,7 +126,8 @@ fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
} }
#[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[unstable(feature = "try_trait_v2_residual", issue = "91285")]
impl<B, C> ops::Residual<C> for ControlFlow<B, convert::Infallible> { #[rustc_const_unstable(feature = "const_try", issue = "74935")]
impl<B, C> const ops::Residual<C> for ControlFlow<B, convert::Infallible> {
type TryType = ControlFlow<B, C>; type TryType = ControlFlow<B, C>;
} }

View File

@ -129,7 +129,7 @@
#[doc(alias = "?")] #[doc(alias = "?")]
#[lang = "Try"] #[lang = "Try"]
#[const_trait] #[const_trait]
pub trait Try: FromResidual { pub trait Try: ~const FromResidual {
/// The type of the value produced by `?` when *not* short-circuiting. /// The type of the value produced by `?` when *not* short-circuiting.
#[unstable(feature = "try_trait_v2", issue = "84277")] #[unstable(feature = "try_trait_v2", issue = "84277")]
type Output; type Output;
@ -438,10 +438,11 @@ pub fn from_yeet<T, Y>(yeeted: Y) -> T
/// and in the other direction, /// and in the other direction,
/// `<Result<Infallible, E> as Residual<T>>::TryType = Result<T, E>`. /// `<Result<Infallible, E> as Residual<T>>::TryType = Result<T, E>`.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[unstable(feature = "try_trait_v2_residual", issue = "91285")]
#[const_trait]
pub trait Residual<O> { pub trait Residual<O> {
/// The "return" type of this meta-function. /// The "return" type of this meta-function.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[unstable(feature = "try_trait_v2_residual", issue = "91285")]
type TryType: Try<Output = O, Residual = Self>; type TryType: ~const Try<Output = O, Residual = Self>;
} }
#[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")] #[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")]
@ -460,14 +461,17 @@ pub trait Residual<O> {
impl<T> NeverShortCircuit<T> { impl<T> NeverShortCircuit<T> {
/// Wrap a binary `FnMut` to return its result wrapped in a `NeverShortCircuit`. /// Wrap a binary `FnMut` to return its result wrapped in a `NeverShortCircuit`.
#[inline] #[inline]
pub fn wrap_mut_2<A, B>(mut f: impl FnMut(A, B) -> T) -> impl FnMut(A, B) -> Self { pub const fn wrap_mut_2_imp<A, B, F: ~const FnMut(A, B) -> T>(
move |a, b| NeverShortCircuit(f(a, b)) f: &mut F,
(a, b): (A, B),
) -> NeverShortCircuit<T> {
NeverShortCircuit(f(a, b))
} }
} }
pub(crate) enum NeverShortCircuitResidual {} pub(crate) enum NeverShortCircuitResidual {}
impl<T> Try for NeverShortCircuit<T> { impl<T> const Try for NeverShortCircuit<T> {
type Output = T; type Output = T;
type Residual = NeverShortCircuitResidual; type Residual = NeverShortCircuitResidual;
@ -482,14 +486,14 @@ fn from_output(x: T) -> Self {
} }
} }
impl<T> FromResidual for NeverShortCircuit<T> { impl<T> const FromResidual for NeverShortCircuit<T> {
#[inline] #[inline]
fn from_residual(never: NeverShortCircuitResidual) -> Self { fn from_residual(never: NeverShortCircuitResidual) -> Self {
match never {} match never {}
} }
} }
impl<T> Residual<T> for NeverShortCircuitResidual { impl<T> const Residual<T> for NeverShortCircuitResidual {
type TryType = NeverShortCircuit<T>; type TryType = NeverShortCircuit<T>;
} }

View File

@ -2321,7 +2321,8 @@ fn from_residual(ops::Yeet(()): ops::Yeet<()>) -> Self {
} }
#[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[unstable(feature = "try_trait_v2_residual", issue = "91285")]
impl<T> ops::Residual<T> for Option<convert::Infallible> { #[rustc_const_unstable(feature = "const_try", issue = "74935")]
impl<T> const ops::Residual<T> for Option<convert::Infallible> {
type TryType = Option<T>; type TryType = Option<T>;
} }

View File

@ -2116,6 +2116,7 @@ fn from_residual(ops::Yeet(e): ops::Yeet<E>) -> Self {
} }
#[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[unstable(feature = "try_trait_v2_residual", issue = "91285")]
impl<T, E> ops::Residual<T> for Result<convert::Infallible, E> { #[rustc_const_unstable(feature = "const_try", issue = "74935")]
impl<T, E> const ops::Residual<T> for Result<convert::Infallible, E> {
type TryType = Result<T, E>; type TryType = Result<T, E>;
} }

View File

@ -141,8 +141,8 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
// SAFETY: offset starts at len - suffix.len(), as long as it is greater than // SAFETY: offset starts at len - suffix.len(), as long as it is greater than
// min_aligned_offset (prefix.len()) the remaining distance is at least 2 * chunk_bytes. // min_aligned_offset (prefix.len()) the remaining distance is at least 2 * chunk_bytes.
unsafe { unsafe {
let u = *(ptr.offset(offset as isize - 2 * chunk_bytes as isize) as *const Chunk); let u = *(ptr.add(offset - 2 * chunk_bytes) as *const Chunk);
let v = *(ptr.offset(offset as isize - chunk_bytes as isize) as *const Chunk); let v = *(ptr.add(offset - chunk_bytes) as *const Chunk);
// Break if there is a matching byte. // Break if there is a matching byte.
let zu = contains_zero_byte(u ^ repeated_x); let zu = contains_zero_byte(u ^ repeated_x);

View File

@ -316,9 +316,9 @@ pub unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Self {
// | small1 | Chunk smaller than 8 bytes // | small1 | Chunk smaller than 8 bytes
// +--------+ // +--------+
fn region_as_aligned_chunks(ptr: *const u8, len: usize) -> (usize, usize, usize) { fn region_as_aligned_chunks(ptr: *const u8, len: usize) -> (usize, usize, usize) {
let small0_size = if ptr as usize % 8 == 0 { 0 } else { 8 - ptr as usize % 8 }; let small0_size = if ptr.is_aligned_to(8) { 0 } else { 8 - ptr.addr() % 8 };
let small1_size = (len - small0_size as usize) % 8; let small1_size = (len - small0_size) % 8;
let big_size = len - small0_size as usize - small1_size as usize; let big_size = len - small0_size - small1_size;
(small0_size, big_size, small1_size) (small0_size, big_size, small1_size)
} }
@ -364,8 +364,8 @@ unsafe fn copy_bytewise_to_userspace(src: *const u8, dst: *mut u8, len: usize) {
mfence mfence
lfence lfence
", ",
val = in(reg_byte) *src.offset(off as isize), val = in(reg_byte) *src.add(off),
dst = in(reg) dst.offset(off as isize), dst = in(reg) dst.add(off),
seg_sel = in(reg) &mut seg_sel, seg_sel = in(reg) &mut seg_sel,
options(nostack, att_syntax) options(nostack, att_syntax)
); );
@ -378,8 +378,8 @@ unsafe fn copy_bytewise_to_userspace(src: *const u8, dst: *mut u8, len: usize) {
assert!(is_enclave_range(src, len)); assert!(is_enclave_range(src, len));
assert!(is_user_range(dst, len)); assert!(is_user_range(dst, len));
assert!(len < isize::MAX as usize); assert!(len < isize::MAX as usize);
assert!(!(src as usize).overflowing_add(len).1); assert!(!src.addr().overflowing_add(len).1);
assert!(!(dst as usize).overflowing_add(len).1); assert!(!dst.addr().overflowing_add(len).1);
if len < 8 { if len < 8 {
// Can't align on 8 byte boundary: copy safely byte per byte // Can't align on 8 byte boundary: copy safely byte per byte
@ -404,17 +404,17 @@ unsafe fn copy_bytewise_to_userspace(src: *const u8, dst: *mut u8, len: usize) {
unsafe { unsafe {
// Copy small0 // Copy small0
copy_bytewise_to_userspace(src, dst, small0_size as _); copy_bytewise_to_userspace(src, dst, small0_size);
// Copy big // Copy big
let big_src = src.offset(small0_size as _); let big_src = src.add(small0_size);
let big_dst = dst.offset(small0_size as _); let big_dst = dst.add(small0_size);
copy_quadwords(big_src as _, big_dst, big_size); copy_quadwords(big_src, big_dst, big_size);
// Copy small1 // Copy small1
let small1_src = src.offset(big_size as isize + small0_size as isize); let small1_src = src.add(big_size + small0_size);
let small1_dst = dst.offset(big_size as isize + small0_size as isize); let small1_dst = dst.add(big_size + small0_size);
copy_bytewise_to_userspace(small1_src, small1_dst, small1_size as _); copy_bytewise_to_userspace(small1_src, small1_dst, small1_size);
} }
} }
} }

View File

@ -520,7 +520,7 @@ fn run(self, builder: &Builder<'_>) {
cargo.arg("--").arg("miri").arg("setup"); cargo.arg("--").arg("miri").arg("setup");
// Tell `cargo miri setup` where to find the sources. // Tell `cargo miri setup` where to find the sources.
cargo.env("XARGO_RUST_SRC", builder.src.join("library")); cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
// Tell it where to find Miri. // Tell it where to find Miri.
cargo.env("MIRI", &miri); cargo.env("MIRI", &miri);
// Debug things. // Debug things.

View File

@ -1412,7 +1412,6 @@ pre.rust {
} }
#source-sidebar { #source-sidebar {
width: 100%; width: 100%;
z-index: 1;
overflow: auto; overflow: auto;
} }
#source-sidebar > .title { #source-sidebar > .title {
@ -1918,10 +1917,6 @@ in storage.js plus the media query with (min-width: 701px)
border-bottom: 1px solid; border-bottom: 1px solid;
} }
#source-sidebar {
z-index: 11;
}
#main-content > .line-numbers { #main-content > .line-numbers {
margin-top: 0; margin-top: 0;
} }

View File

@ -55,8 +55,21 @@ pub struct ReachableStruct { //~ ERROR Public: pub(self), Exported: pub(self), R
} }
} }
pub use outer::inner1; #[rustc_effective_visibility]
pub use outer::inner1; //~ ERROR Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
pub fn foo() -> outer::ReachableStruct { outer::ReachableStruct {a: 0} } pub fn foo() -> outer::ReachableStruct { outer::ReachableStruct {a: 0} }
mod half_public_import {
#[rustc_effective_visibility]
pub type HalfPublicImport = u8; //~ ERROR Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
#[rustc_effective_visibility]
#[allow(non_upper_case_globals)]
pub(crate) const HalfPublicImport: u8 = 0; //~ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self)
}
#[rustc_effective_visibility]
pub use half_public_import::HalfPublicImport; //~ ERROR Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
//~^ ERROR Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self)
fn main() {} fn main() {}

View File

@ -88,6 +88,36 @@ error: Public: pub(self), Exported: pub(self), Reachable: pub, ReachableFromImpl
LL | pub a: u8, LL | pub a: u8,
| ^^^^^^^^^ | ^^^^^^^^^
error: Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
--> $DIR/access_levels.rs:59:9
|
LL | pub use outer::inner1;
| ^^^^^^^^^^^^^
error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
--> $DIR/access_levels.rs:65:5
|
LL | pub type HalfPublicImport = u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self)
--> $DIR/access_levels.rs:68:5
|
LL | pub(crate) const HalfPublicImport: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Public: pub, Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
--> $DIR/access_levels.rs:72:9
|
LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Public: pub(self), Exported: pub(self), Reachable: pub(self), ReachableFromImplTrait: pub(self)
--> $DIR/access_levels.rs:72:9
|
LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait: pub
--> $DIR/access_levels.rs:14:13 --> $DIR/access_levels.rs:14:13
| |
@ -100,5 +130,5 @@ error: Public: pub(self), Exported: pub, Reachable: pub, ReachableFromImplTrait:
LL | type B; LL | type B;
| ^^^^^^ | ^^^^^^
error: aborting due to 17 previous errors error: aborting due to 22 previous errors

View File

@ -0,0 +1,14 @@
// check-fail
// run-rustfix
enum FakeResult<T> {
Ok(T)
}
fn main() {
let _x = if true {
FakeResult::Ok(FakeResult::Ok(()))
} else {
FakeResult::Ok(FakeResult::Ok(())) //~ERROR E0308
};
}

View File

@ -0,0 +1,14 @@
// check-fail
// run-rustfix
enum FakeResult<T> {
Ok(T)
}
fn main() {
let _x = if true {
FakeResult::Ok(FakeResult::Ok(()))
} else {
FakeResult::Ok(()) //~ERROR E0308
};
}

View File

@ -0,0 +1,23 @@
error[E0308]: `if` and `else` have incompatible types
--> $DIR/issue-101065.rs:12:9
|
LL | let _x = if true {
| ______________-
LL | | FakeResult::Ok(FakeResult::Ok(()))
| | ---------------------------------- expected because of this
LL | | } else {
LL | | FakeResult::Ok(())
| | ^^^^^^^^^^^^^^^^^^ expected enum `FakeResult`, found `()`
LL | | };
| |_____- `if` and `else` have incompatible types
|
= note: expected enum `FakeResult<FakeResult<()>>`
found enum `FakeResult<()>`
help: try wrapping the expression in `FakeResult::Ok`
|
LL | FakeResult::Ok(FakeResult::Ok(()))
| +++++++++++++++ +
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.