mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Auto merge of #78767 - m-ou-se:rollup-eu5wgxl, r=m-ou-se
Rollup of 15 pull requests Successful merges: - #76718 (Move Vec UI tests to unit tests when possible) - #78093 (Clean up docs for 'as' keyword) - #78425 (Move f64::NAN ui tests into `library`) - #78465 (Change as_str → to_string in proc_macro::Ident::span() docs) - #78584 (Add keyboard handling to the theme picker menu) - #78716 (Array trait impl comment/doc fixes) - #78727 ((rustdoc) fix test for trait impl display) - #78733 (fix a couple of clippy warnings:) - #78735 (Simplify the implementation of `get_mut` (no unsafe)) - #78738 (Move range in ui test to ops test in library/core) - #78739 (Fix ICE on type error in async function) - #78742 (make intern_const_alloc_recursive return error) - #78756 (Update cargo) - #78757 (Improve and clean up some intra-doc links) - #78758 (Fixed typo in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
f7801d6c7c
@ -91,9 +91,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.32"
|
||||
version = "1.0.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
||||
checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
|
@ -360,7 +360,7 @@ pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
|
||||
impl MetaItem {
|
||||
fn token_trees_and_spacings(&self) -> Vec<TreeAndSpacing> {
|
||||
let mut idents = vec![];
|
||||
let mut last_pos = BytePos(0 as u32);
|
||||
let mut last_pos = BytePos(0_u32);
|
||||
for (i, segment) in self.path.segments.iter().enumerate() {
|
||||
let is_first = i == 0;
|
||||
if !is_first {
|
||||
|
@ -739,7 +739,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
"cannot infer {} {} {} `{}`{}",
|
||||
kind_str, preposition, descr, type_name, parent_desc
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,10 +246,10 @@ pub fn get_codegen_backend(sopts: &config::Options) -> Box<dyn CodegenBackend> {
|
||||
|
||||
INIT.call_once(|| {
|
||||
#[cfg(feature = "llvm")]
|
||||
const DEFAULT_CODEGEN_BACKEND: &'static str = "llvm";
|
||||
const DEFAULT_CODEGEN_BACKEND: &str = "llvm";
|
||||
|
||||
#[cfg(not(feature = "llvm"))]
|
||||
const DEFAULT_CODEGEN_BACKEND: &'static str = "cranelift";
|
||||
const DEFAULT_CODEGEN_BACKEND: &str = "cranelift";
|
||||
|
||||
let codegen_name = sopts
|
||||
.debugging_opts
|
||||
@ -414,11 +414,10 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
|
||||
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
|
||||
sysroot.join(libdir).with_file_name("codegen-backends")
|
||||
})
|
||||
.filter(|f| {
|
||||
.find(|f| {
|
||||
info!("codegen backend candidate: {}", f.display());
|
||||
f.exists()
|
||||
})
|
||||
.next();
|
||||
});
|
||||
let sysroot = sysroot.unwrap_or_else(|| {
|
||||
let candidates = sysroot_candidates
|
||||
.iter()
|
||||
|
@ -399,7 +399,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
def_id: DefId,
|
||||
id: Option<HirId>,
|
||||
span: Span,
|
||||
unmarked: impl FnOnce(Span, DefId) -> (),
|
||||
unmarked: impl FnOnce(Span, DefId),
|
||||
) {
|
||||
let soft_handler = |lint, span, msg: &_| {
|
||||
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
|
||||
|
@ -81,6 +81,12 @@ impl From<ErrorHandled> for InterpErrorInfo<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorReported> for InterpErrorInfo<'_> {
|
||||
fn from(err: ErrorReported) -> Self {
|
||||
InterpError::InvalidProgram(InvalidProgramInfo::AlreadyReported(err)).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
|
||||
fn from(kind: InterpError<'tcx>) -> Self {
|
||||
let capture_backtrace = tls::with_opt(|tcx| {
|
||||
@ -115,8 +121,8 @@ pub enum InvalidProgramInfo<'tcx> {
|
||||
/// Cannot compute this constant because it depends on another one
|
||||
/// which already produced an error.
|
||||
ReferencedConstant,
|
||||
/// Abort in case type errors are reached.
|
||||
TypeckError(ErrorReported),
|
||||
/// Abort in case errors are already reported.
|
||||
AlreadyReported(ErrorReported),
|
||||
/// An error occurred during layout computation.
|
||||
Layout(layout::LayoutError<'tcx>),
|
||||
/// An invalid transmute happened.
|
||||
@ -129,7 +135,7 @@ impl fmt::Display for InvalidProgramInfo<'_> {
|
||||
match self {
|
||||
TooGeneric => write!(f, "encountered overly generic constant"),
|
||||
ReferencedConstant => write!(f, "referenced constant has errors"),
|
||||
TypeckError(ErrorReported) => {
|
||||
AlreadyReported(ErrorReported) => {
|
||||
write!(f, "encountered constants with type errors, stopping evaluation")
|
||||
}
|
||||
Layout(ref err) => write!(f, "{}", err),
|
||||
|
@ -46,7 +46,7 @@ impl SwitchTargets {
|
||||
pub fn new(targets: impl Iterator<Item = (u128, BasicBlock)>, otherwise: BasicBlock) -> Self {
|
||||
let (values, mut targets): (SmallVec<_>, SmallVec<_>) = targets.unzip();
|
||||
targets.push(otherwise);
|
||||
Self { values: values.into(), targets }
|
||||
Self { values, targets }
|
||||
}
|
||||
|
||||
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
|
||||
|
@ -1641,7 +1641,7 @@ pub type PlaceholderConst = Placeholder<BoundVar>;
|
||||
#[derive(Hash, HashStable)]
|
||||
pub struct WithOptConstParam<T> {
|
||||
pub did: T,
|
||||
/// The `DefId` of the corresponding generic paramter in case `did` is
|
||||
/// The `DefId` of the corresponding generic parameter in case `did` is
|
||||
/// a const argument.
|
||||
///
|
||||
/// Note that even if `did` is a const argument, this may still be `None`.
|
||||
|
@ -120,7 +120,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let move_out = self.move_data.moves[(*move_site).moi];
|
||||
let moved_place = &self.move_data.move_paths[move_out.path].place;
|
||||
// `*(_1)` where `_1` is a `Box` is actually a move out.
|
||||
let is_box_move = moved_place.as_ref().projection == &[ProjectionElem::Deref]
|
||||
let is_box_move = moved_place.as_ref().projection == [ProjectionElem::Deref]
|
||||
&& self.body.local_decls[moved_place.local].ty.is_box();
|
||||
|
||||
!is_box_move
|
||||
|
@ -141,7 +141,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
|
||||
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
|
||||
return ErrorHandled::TooGeneric;
|
||||
}
|
||||
err_inval!(TypeckError(error_reported)) => {
|
||||
err_inval!(AlreadyReported(error_reported)) => {
|
||||
return ErrorHandled::Reported(error_reported);
|
||||
}
|
||||
// We must *always* hard error on these, even if the caller wants just a lint.
|
||||
|
@ -67,7 +67,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|
||||
None => InternKind::Constant,
|
||||
}
|
||||
};
|
||||
intern_const_alloc_recursive(ecx, intern_kind, ret);
|
||||
intern_const_alloc_recursive(ecx, intern_kind, ret)?;
|
||||
|
||||
debug!("eval_body_using_ecx done: {:?}", *ret);
|
||||
Ok(ret)
|
||||
|
@ -29,7 +29,9 @@ pub(crate) fn const_caller_location(
|
||||
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), false);
|
||||
|
||||
let loc_place = ecx.alloc_caller_location(file, line, col);
|
||||
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place);
|
||||
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place).is_err() {
|
||||
bug!("intern_const_alloc_recursive should not error in this case")
|
||||
}
|
||||
ConstValue::Scalar(loc_place.ptr)
|
||||
}
|
||||
|
||||
|
@ -469,7 +469,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
if let Some(def) = def.as_local() {
|
||||
if self.tcx.has_typeck_results(def.did) {
|
||||
if let Some(error_reported) = self.tcx.typeck_opt_const_arg(def).tainted_by_errors {
|
||||
throw_inval!(TypeckError(error_reported))
|
||||
throw_inval!(AlreadyReported(error_reported))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -525,8 +525,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
Ok(Some(instance)) => Ok(instance),
|
||||
Ok(None) => throw_inval!(TooGeneric),
|
||||
|
||||
// FIXME(eddyb) this could be a bit more specific than `TypeckError`.
|
||||
Err(error_reported) => throw_inval!(TypeckError(error_reported)),
|
||||
// FIXME(eddyb) this could be a bit more specific than `AlreadyReported`.
|
||||
Err(error_reported) => throw_inval!(AlreadyReported(error_reported)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use super::validity::RefTracking;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::mir::interpret::InterpResult;
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
|
||||
@ -285,11 +286,13 @@ pub enum InternKind {
|
||||
/// tracks where in the value we are and thus can show much better error messages.
|
||||
/// Any errors here would anyway be turned into `const_err` lints, whereas validation failures
|
||||
/// are hard errors.
|
||||
#[tracing::instrument(skip(ecx))]
|
||||
pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
|
||||
ecx: &mut InterpCx<'mir, 'tcx, M>,
|
||||
intern_kind: InternKind,
|
||||
ret: MPlaceTy<'tcx>,
|
||||
) where
|
||||
) -> Result<(), ErrorReported>
|
||||
where
|
||||
'tcx: 'mir,
|
||||
{
|
||||
let tcx = ecx.tcx;
|
||||
@ -405,12 +408,14 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
|
||||
// Codegen does not like dangling pointers, and generally `tcx` assumes that
|
||||
// all allocations referenced anywhere actually exist. So, make sure we error here.
|
||||
ecx.tcx.sess.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
|
||||
return Err(ErrorReported);
|
||||
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
|
||||
// We have hit an `AllocId` that is neither in local or global memory and isn't
|
||||
// marked as dangling by local memory. That should be impossible.
|
||||
span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
@ -544,7 +544,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// Early-return cases.
|
||||
let val_val = match val.val {
|
||||
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
|
||||
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
|
||||
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorReported)),
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => {
|
||||
let instance = self.resolve(def, substs)?;
|
||||
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
|
||||
|
@ -63,7 +63,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
||||
};
|
||||
|
||||
// Check that destinations are identical, and if not, then don't optimize this block
|
||||
if &bbs[first].terminator().kind != &bbs[second].terminator().kind {
|
||||
if bbs[first].terminator().kind != bbs[second].terminator().kind {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1886,9 +1886,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
||||
if snippet.starts_with('&') && !snippet.starts_with("&'") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[1..])));
|
||||
} else if snippet.starts_with("&'_ ") {
|
||||
introduce_suggestion
|
||||
.push((param.span, format!("&'a {}", &snippet[4..])));
|
||||
} else if let Some(stripped) = snippet.strip_prefix("&'_ ") {
|
||||
introduce_suggestion.push((param.span, format!("&'a {}", &stripped)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1574,7 +1574,7 @@ fn normalize_src(src: &mut String, start_pos: BytePos) -> Vec<NormalizedPos> {
|
||||
|
||||
/// Removes UTF-8 BOM, if any.
|
||||
fn remove_bom(src: &mut String, normalized_pos: &mut Vec<NormalizedPos>) {
|
||||
if src.starts_with("\u{feff}") {
|
||||
if src.starts_with('\u{feff}') {
|
||||
src.drain(..3);
|
||||
normalized_pos.push(NormalizedPos { pos: BytePos(0), diff: 3 });
|
||||
}
|
||||
|
@ -1388,11 +1388,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
||||
) {
|
||||
let get_trait_impl = |trait_def_id| {
|
||||
self.tcx.find_map_relevant_impl(
|
||||
trait_def_id,
|
||||
trait_ref.skip_binder().self_ty(),
|
||||
|impl_def_id| Some(impl_def_id),
|
||||
)
|
||||
self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some)
|
||||
};
|
||||
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
|
||||
let all_traits = self.tcx.all_traits(LOCAL_CRATE);
|
||||
|
@ -499,7 +499,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
pending_obligation.stalled_on = substs
|
||||
.iter()
|
||||
.filter_map(|ty| TyOrConstInferVar::maybe_from_generic_arg(ty))
|
||||
.filter_map(TyOrConstInferVar::maybe_from_generic_arg)
|
||||
.collect();
|
||||
ProcessResult::Unchanged
|
||||
}
|
||||
|
@ -605,6 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
|
||||
let ret_vid = match *ret_ty.kind() {
|
||||
ty::Infer(ty::TyVar(ret_vid)) => ret_vid,
|
||||
ty::Error(_) => return None,
|
||||
_ => span_bug!(
|
||||
self.tcx.def_span(expr_def_id),
|
||||
"async fn generator return type not an inference variable"
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::cell::Cell;
|
||||
use std::cmp::Ordering::{self, Equal, Greater, Less};
|
||||
use std::convert::identity;
|
||||
use std::mem;
|
||||
use std::panic;
|
||||
use std::rc::Rc;
|
||||
@ -1778,3 +1779,122 @@ fn repeat_generic_slice() {
|
||||
assert_eq!([1, 2, 3, 4].repeat(1), vec![1, 2, 3, 4]);
|
||||
assert_eq!([1, 2, 3, 4].repeat(3), vec![1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unreachable_patterns)]
|
||||
fn subslice_patterns() {
|
||||
// This test comprehensively checks the passing static and dynamic semantics
|
||||
// of subslice patterns `..`, `x @ ..`, `ref x @ ..`, and `ref mut @ ..`
|
||||
// in slice patterns `[$($pat), $(,)?]` .
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
struct N(u8);
|
||||
|
||||
macro_rules! n {
|
||||
($($e:expr),* $(,)?) => {
|
||||
[$(N($e)),*]
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! c {
|
||||
($inp:expr, $typ:ty, $out:expr $(,)?) => {
|
||||
assert_eq!($out, identity::<$typ>($inp));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
($e:expr, $p:pat => $b:expr) => {
|
||||
match $e {
|
||||
$p => $b,
|
||||
_ => panic!(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// == Slices ==
|
||||
|
||||
// Matching slices using `ref` patterns:
|
||||
let mut v = vec![N(0), N(1), N(2), N(3), N(4)];
|
||||
let mut vc = (0..=4).collect::<Vec<u8>>();
|
||||
|
||||
let [..] = v[..]; // Always matches.
|
||||
m!(v[..], [N(0), ref sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
|
||||
m!(v[..], [N(0), ref sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
|
||||
m!(v[..], [ref sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
|
||||
m!(v[..], [ref sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(v[..], [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching slices using `ref mut` patterns:
|
||||
let [..] = v[..]; // Always matches.
|
||||
m!(v[..], [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
|
||||
m!(v[..], [N(0), ref mut sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
|
||||
m!(v[..], [ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
|
||||
m!(v[..], [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(v[..], [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching slices using default binding modes (&):
|
||||
let [..] = &v[..]; // Always matches.
|
||||
m!(&v[..], [N(0), sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
|
||||
m!(&v[..], [N(0), sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
|
||||
m!(&v[..], [sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
|
||||
m!(&v[..], [sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(&v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(&vc[..], [x, .., y] => c!((x, y), (&u8, &u8), (&0, &4)));
|
||||
|
||||
// Matching slices using default binding modes (&mut):
|
||||
let [..] = &mut v[..]; // Always matches.
|
||||
m!(&mut v[..], [N(0), sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
|
||||
m!(&mut v[..], [N(0), sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
|
||||
m!(&mut v[..], [sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
|
||||
m!(&mut v[..], [sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(&mut v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(&mut vc[..], [x, .., y] => c!((x, y), (&mut u8, &mut u8), (&mut 0, &mut 4)));
|
||||
|
||||
// == Arrays ==
|
||||
let mut v = n![0, 1, 2, 3, 4];
|
||||
let vc = [0, 1, 2, 3, 4];
|
||||
|
||||
// Matching arrays by value:
|
||||
m!(v.clone(), [N(0), sub @ .., N(4)] => c!(sub, [N; 3], n![1, 2, 3]));
|
||||
m!(v.clone(), [N(0), sub @ ..] => c!(sub, [N; 4], n![1, 2, 3, 4]));
|
||||
m!(v.clone(), [sub @ .., N(4)] => c!(sub, [N; 4], n![0, 1, 2, 3]));
|
||||
m!(v.clone(), [sub @ .., _, _, _, _, _] => c!(sub, [N; 0], n![] as [N; 0]));
|
||||
m!(v.clone(), [_, _, _, _, _, sub @ ..] => c!(sub, [N; 0], n![] as [N; 0]));
|
||||
m!(v.clone(), [x, .., y] => c!((x, y), (N, N), (N(0), N(4))));
|
||||
m!(v.clone(), [..] => ());
|
||||
|
||||
// Matching arrays by ref patterns:
|
||||
m!(v, [N(0), ref sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
|
||||
m!(v, [N(0), ref sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
|
||||
m!(v, [ref sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
|
||||
m!(v, [ref sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(v, [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(vc, [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching arrays by ref mut patterns:
|
||||
m!(v, [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
|
||||
m!(v, [N(0), ref mut sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
|
||||
m!(v, [ref mut sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
|
||||
m!(v, [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));
|
||||
m!(v, [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));
|
||||
|
||||
// Matching arrays by default binding modes (&):
|
||||
m!(&v, [N(0), sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
|
||||
m!(&v, [N(0), sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
|
||||
m!(&v, [sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
|
||||
m!(&v, [sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(&v, [_, _, _, _, _, sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(&v, [..] => ());
|
||||
m!(&v, [x, .., y] => c!((x, y), (&N, &N), (&N(0), &N(4))));
|
||||
|
||||
// Matching arrays by default binding modes (&mut):
|
||||
m!(&mut v, [N(0), sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
|
||||
m!(&mut v, [N(0), sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
|
||||
m!(&mut v, [sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
|
||||
m!(&mut v, [sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
|
||||
m!(&mut v, [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
|
||||
m!(&mut v, [..] => ());
|
||||
m!(&mut v, [x, .., y] => c!((x, y), (&mut N, &mut N), (&mut N(0), &mut N(4))));
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::cell::Cell;
|
||||
use std::collections::TryReserveError::*;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::InPlaceIterable;
|
||||
use std::mem::size_of;
|
||||
use std::mem::{size_of, swap};
|
||||
use std::ops::Bound::*;
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
use std::rc::Rc;
|
||||
@ -1912,3 +1912,45 @@ fn test_vec_cycle_wrapped() {
|
||||
c3.refs.v[0].set(Some(&c1));
|
||||
c3.refs.v[1].set(Some(&c2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_sized_vec_push() {
|
||||
const N: usize = 8;
|
||||
|
||||
for len in 0..N {
|
||||
let mut tester = Vec::with_capacity(len);
|
||||
assert_eq!(tester.len(), 0);
|
||||
assert!(tester.capacity() >= len);
|
||||
for _ in 0..len {
|
||||
tester.push(());
|
||||
}
|
||||
assert_eq!(tester.len(), len);
|
||||
assert_eq!(tester.iter().count(), len);
|
||||
tester.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec_macro_repeat() {
|
||||
assert_eq!(vec![1; 3], vec![1, 1, 1]);
|
||||
assert_eq!(vec![1; 2], vec![1, 1]);
|
||||
assert_eq!(vec![1; 1], vec![1]);
|
||||
assert_eq!(vec![1; 0], vec![]);
|
||||
|
||||
// from_elem syntax (see RFC 832)
|
||||
let el = Box::new(1);
|
||||
let n = 3;
|
||||
assert_eq!(vec![el; n], vec![Box::new(1), Box::new(1), Box::new(1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec_swap() {
|
||||
let mut a: Vec<isize> = vec![0, 1, 2, 3, 4, 5, 6];
|
||||
a.swap(2, 4);
|
||||
assert_eq!(a[2], 4);
|
||||
assert_eq!(a[4], 2);
|
||||
let mut n = 42;
|
||||
swap(&mut n, &mut a[0]);
|
||||
assert_eq!(a[0], 42);
|
||||
assert_eq!(n, 0);
|
||||
}
|
||||
|
@ -1698,3 +1698,33 @@ fn test_binary_search_by_key() {
|
||||
assert_eq!(deque.binary_search_by_key(&3, |&(v,)| v), Ok(2));
|
||||
assert_eq!(deque.binary_search_by_key(&4, |&(v,)| v), Err(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_sized_push() {
|
||||
const N: usize = 8;
|
||||
|
||||
// Zero sized type
|
||||
struct Zst;
|
||||
|
||||
// Test that for all possible sequences of push_front / push_back,
|
||||
// we end up with a deque of the correct size
|
||||
|
||||
for len in 0..N {
|
||||
let mut tester = VecDeque::with_capacity(len);
|
||||
assert_eq!(tester.len(), 0);
|
||||
assert!(tester.capacity() >= len);
|
||||
for case in 0..(1 << len) {
|
||||
assert_eq!(tester.len(), 0);
|
||||
for bit in 0..len {
|
||||
if case & (1 << bit) != 0 {
|
||||
tester.push_front(Zst);
|
||||
} else {
|
||||
tester.push_back(Zst);
|
||||
}
|
||||
}
|
||||
assert_eq!(tester.len(), len);
|
||||
assert_eq!(tester.iter().count(), len);
|
||||
tester.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,8 +353,9 @@ impl<T: Ord, const N: usize> Ord for [T; N] {
|
||||
}
|
||||
}
|
||||
|
||||
// The Default impls cannot be generated using the array_impls! macro because
|
||||
// they require array literals.
|
||||
// The Default impls cannot be done with const generics because `[T; 0]` doesn't
|
||||
// require Default to be implemented, and having different impl blocks for
|
||||
// different numbers isn't supported yet.
|
||||
|
||||
macro_rules! array_impl_default {
|
||||
{$n:expr, $t:ident $($ts:ident)*} => {
|
||||
|
@ -1733,8 +1733,7 @@ impl<T: ?Sized> UnsafeCell<T> {
|
||||
#[inline]
|
||||
#[unstable(feature = "unsafe_cell_get_mut", issue = "76943")]
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
// SAFETY: (outer) `&mut` guarantees unique access.
|
||||
unsafe { &mut *self.get() }
|
||||
&mut self.value
|
||||
}
|
||||
|
||||
/// Gets a mutable pointer to the wrapped value.
|
||||
|
@ -719,7 +719,7 @@ extern "rust-intrinsic" {
|
||||
/// macro, which panics when it is executed, it is *undefined behavior* to
|
||||
/// reach code marked with this function.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::hint::unreachable_unchecked`].
|
||||
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`](crate::hint::unreachable_unchecked).
|
||||
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
|
||||
pub fn unreachable() -> !;
|
||||
|
||||
@ -764,7 +764,7 @@ extern "rust-intrinsic" {
|
||||
/// More specifically, this is the offset in bytes between successive
|
||||
/// items of the same type, including alignment padding.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::mem::size_of`].
|
||||
/// The stabilized version of this intrinsic is [`core::mem::size_of`](crate::mem::size_of).
|
||||
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
|
||||
pub fn size_of<T>() -> usize;
|
||||
|
||||
@ -772,12 +772,12 @@ extern "rust-intrinsic" {
|
||||
///
|
||||
/// Drop glue is not run on the destination.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::ptr::write`].
|
||||
/// The stabilized version of this intrinsic is [`core::ptr::write`](crate::ptr::write).
|
||||
pub fn move_val_init<T>(dst: *mut T, src: T);
|
||||
|
||||
/// The minimum alignment of a type.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::mem::align_of`].
|
||||
/// The stabilized version of this intrinsic is [`core::mem::align_of`](crate::mem::align_of).
|
||||
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
|
||||
pub fn min_align_of<T>() -> usize;
|
||||
/// The preferred alignment of a type.
|
||||
@ -793,13 +793,13 @@ extern "rust-intrinsic" {
|
||||
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
/// The required alignment of the referenced value.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::mem::align_of_val`].
|
||||
/// The stabilized version of this intrinsic is [`core::mem::align_of_val`](crate::mem::align_of_val).
|
||||
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
|
||||
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
|
||||
|
||||
/// Gets a static string slice containing the name of a type.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::any::type_name`].
|
||||
/// The stabilized version of this intrinsic is [`core::any::type_name`](crate::any::type_name).
|
||||
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
|
||||
pub fn type_name<T: ?Sized>() -> &'static str;
|
||||
|
||||
@ -807,7 +807,7 @@ extern "rust-intrinsic" {
|
||||
/// function will return the same value for a type regardless of whichever
|
||||
/// crate it is invoked in.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::any::TypeId::of`].
|
||||
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`](crate::any::TypeId::of).
|
||||
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
|
||||
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
||||
|
||||
@ -831,7 +831,7 @@ extern "rust-intrinsic" {
|
||||
|
||||
/// Gets a reference to a static `Location` indicating where it was called.
|
||||
///
|
||||
/// Consider using [`crate::panic::Location::caller`] instead.
|
||||
/// Consider using [`core::panic::Location::caller`](crate::panic::Location::caller) instead.
|
||||
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
|
||||
pub fn caller_location() -> &'static crate::panic::Location<'static>;
|
||||
|
||||
@ -1152,11 +1152,11 @@ extern "rust-intrinsic" {
|
||||
|
||||
/// Performs a volatile load from the `src` pointer.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::ptr::read_volatile`].
|
||||
/// The stabilized version of this intrinsic is [`core::ptr::read_volatile`](crate::ptr::read_volatile).
|
||||
pub fn volatile_load<T>(src: *const T) -> T;
|
||||
/// Performs a volatile store to the `dst` pointer.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::ptr::write_volatile`].
|
||||
/// The stabilized version of this intrinsic is [`core::ptr::write_volatile`](crate::ptr::write_volatile).
|
||||
pub fn volatile_store<T>(dst: *mut T, val: T);
|
||||
|
||||
/// Performs a volatile load from the `src` pointer
|
||||
@ -1697,7 +1697,7 @@ extern "rust-intrinsic" {
|
||||
/// Returns the value of the discriminant for the variant in 'v',
|
||||
/// cast to a `u64`; if `T` has no discriminant, returns 0.
|
||||
///
|
||||
/// The stabilized version of this intrinsic is [`crate::mem::discriminant`].
|
||||
/// The stabilized version of this intrinsic is [`core::mem::discriminant`](crate::mem::discriminant).
|
||||
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
|
||||
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
|
||||
|
||||
|
@ -27,6 +27,8 @@ mod bignum;
|
||||
mod dec2flt;
|
||||
mod flt2dec;
|
||||
|
||||
mod nan;
|
||||
|
||||
/// Adds the attribute to all items in the block.
|
||||
macro_rules! cfg_block {
|
||||
($(#[$attr:meta]{$($it:item)*})*) => {$($(
|
||||
|
@ -1,7 +1,6 @@
|
||||
// run-pass
|
||||
|
||||
pub fn main() {
|
||||
use std::f64;
|
||||
#[test]
|
||||
fn test_nan() {
|
||||
use core::f64;
|
||||
let x = "NaN".to_string();
|
||||
assert_eq!(format!("{}", f64::NAN), x);
|
||||
assert_eq!(format!("{:e}", f64::NAN), x);
|
@ -1,6 +1,6 @@
|
||||
use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
|
||||
|
||||
// Test the Range structs without the syntactic sugar.
|
||||
// Test the Range structs and syntax.
|
||||
|
||||
#[test]
|
||||
fn test_range() {
|
||||
@ -94,3 +94,60 @@ fn test_bound_cloned_included() {
|
||||
fn test_bound_cloned_excluded() {
|
||||
assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unused_comparisons)]
|
||||
#[allow(unused_mut)]
|
||||
fn test_range_syntax() {
|
||||
let mut count = 0;
|
||||
for i in 0_usize..10 {
|
||||
assert!(i >= 0 && i < 10);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 45);
|
||||
|
||||
let mut count = 0;
|
||||
let mut range = 0_usize..10;
|
||||
for i in range {
|
||||
assert!(i >= 0 && i < 10);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 45);
|
||||
|
||||
let mut count = 0;
|
||||
let mut rf = 3_usize..;
|
||||
for i in rf.take(10) {
|
||||
assert!(i >= 3 && i < 13);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 75);
|
||||
|
||||
let _ = 0_usize..4 + 4 - 3;
|
||||
|
||||
fn foo() -> isize {
|
||||
42
|
||||
}
|
||||
let _ = 0..foo();
|
||||
|
||||
let _ = { &42..&100 }; // references to literals are OK
|
||||
let _ = ..42_usize;
|
||||
|
||||
// Test we can use two different types with a common supertype.
|
||||
let x = &42;
|
||||
{
|
||||
let y = 42;
|
||||
let _ = x..&y;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(dead_code)]
|
||||
fn test_range_syntax_in_return_statement() {
|
||||
fn return_range_to() -> RangeTo<i32> {
|
||||
return ..1;
|
||||
}
|
||||
fn return_full_range() -> RangeFull {
|
||||
return ..;
|
||||
}
|
||||
// Not much to test.
|
||||
}
|
||||
|
@ -882,7 +882,7 @@ impl Ident {
|
||||
}
|
||||
|
||||
/// Returns the span of this `Ident`, encompassing the entire string returned
|
||||
/// by `as_str`.
|
||||
/// by [`to_string`](Self::to_string).
|
||||
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
|
||||
pub fn span(&self) -> Span {
|
||||
Span(self.0.span())
|
||||
|
@ -15,18 +15,24 @@
|
||||
/// ```
|
||||
///
|
||||
/// In general, any cast that can be performed via ascribing the type can also be done using `as`,
|
||||
/// so instead of writing `let x: u32 = 123`, you can write `let x = 123 as u32` (Note: `let x: u32
|
||||
/// = 123` would be best in that situation). The same is not true in the other direction, however,
|
||||
/// so instead of writing `let x: u32 = 123`, you can write `let x = 123 as u32` (note: `let x: u32
|
||||
/// = 123` would be best in that situation). The same is not true in the other direction, however;
|
||||
/// explicitly using `as` allows a few more coercions that aren't allowed implicitly, such as
|
||||
/// changing the type of a raw pointer or turning closures into raw pointers.
|
||||
///
|
||||
/// Other places `as` is used include as extra syntax for [`crate`] and `use`, to change the name
|
||||
/// something is imported as.
|
||||
/// `as` is also used to rename imports in [`use`] and [`extern crate`] statements:
|
||||
///
|
||||
/// For more information on what `as` is capable of, see the [Reference]
|
||||
/// ```
|
||||
/// # #[allow(unused_imports)]
|
||||
/// use std::{mem as memory, net as network};
|
||||
/// // Now you can use the names `memory` and `network` to refer to `std::mem` and `std::net`.
|
||||
/// ```
|
||||
///
|
||||
/// For more information on what `as` is capable of, see the [Reference].
|
||||
///
|
||||
/// [Reference]: ../reference/expressions/operator-expr.html#type-cast-expressions
|
||||
/// [`crate`]: keyword.crate.html
|
||||
/// [`use`]: keyword.use.html
|
||||
/// [`extern crate`]: keyword.crate.html
|
||||
mod as_keyword {}
|
||||
|
||||
#[doc(keyword = "break")]
|
||||
@ -397,6 +403,7 @@ mod enum_keyword {}
|
||||
/// [Rust book]:
|
||||
/// ../book/ch19-01-unsafe-rust.html#using-extern-functions-to-call-external-code
|
||||
/// [Reference]: ../reference/items/external-blocks.html
|
||||
/// [`crate`]: keyword.crate.html
|
||||
mod extern_keyword {}
|
||||
|
||||
#[doc(keyword = "false")]
|
||||
|
@ -389,7 +389,7 @@ mod prim_unit {}
|
||||
//
|
||||
/// Raw, unsafe pointers, `*const T`, and `*mut T`.
|
||||
///
|
||||
/// *[See also the `std::ptr` module][`ptr`].*
|
||||
/// *[See also the `std::ptr` module](ptr).*
|
||||
///
|
||||
/// Working with raw pointers in Rust is uncommon, typically limited to a few patterns.
|
||||
/// Raw pointers can be unaligned or [`null`]. However, when a raw pointer is
|
||||
@ -491,6 +491,8 @@ mod prim_pointer {}
|
||||
///
|
||||
/// Arrays of *any* size implement the following traits if the element type allows it:
|
||||
///
|
||||
/// - [`Copy`]
|
||||
/// - [`Clone`]
|
||||
/// - [`Debug`]
|
||||
/// - [`IntoIterator`] (implemented for `&[T; N]` and `&mut [T; N]`)
|
||||
/// - [`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]
|
||||
@ -498,15 +500,10 @@ mod prim_pointer {}
|
||||
/// - [`AsRef`], [`AsMut`]
|
||||
/// - [`Borrow`], [`BorrowMut`]
|
||||
///
|
||||
/// Arrays of sizes from 0 to 32 (inclusive) implement [`Default`] trait
|
||||
/// Arrays of sizes from 0 to 32 (inclusive) implement the [`Default`] trait
|
||||
/// if the element type allows it. As a stopgap, trait implementations are
|
||||
/// statically generated up to size 32.
|
||||
///
|
||||
/// Arrays of *any* size are [`Copy`] if the element type is [`Copy`]
|
||||
/// and [`Clone`] if the element type is [`Clone`]. This works
|
||||
/// because [`Copy`] and [`Clone`] traits are specially known
|
||||
/// to the compiler.
|
||||
///
|
||||
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
|
||||
/// an array. Indeed, this provides most of the API for working with arrays.
|
||||
/// Slices have a dynamic size and do not coerce to arrays.
|
||||
@ -580,7 +577,7 @@ mod prim_array {}
|
||||
/// means that elements are laid out so that every element is the same
|
||||
/// distance from its neighbors.
|
||||
///
|
||||
/// *[See also the `std::slice` module][`crate::slice`].*
|
||||
/// *[See also the `std::slice` module](crate::slice).*
|
||||
///
|
||||
/// Slices are a view into a block of memory represented as a pointer and a
|
||||
/// length.
|
||||
@ -625,7 +622,7 @@ mod prim_slice {}
|
||||
//
|
||||
/// String slices.
|
||||
///
|
||||
/// *[See also the `std::str` module][`crate::str`].*
|
||||
/// *[See also the `std::str` module](crate::str).*
|
||||
///
|
||||
/// The `str` type, also called a 'string slice', is the most primitive string
|
||||
/// type. It is usually seen in its borrowed form, `&str`. It is also the type
|
||||
@ -800,7 +797,7 @@ mod prim_tuple {}
|
||||
/// calculation with floats round to a nearby representable number. For example,
|
||||
/// `5.0` and `1.0` can be exactly represented as `f32`, but `1.0 / 5.0` results
|
||||
/// in `0.20000000298023223876953125` since `0.2` cannot be exactly represented
|
||||
/// as `f32`. Note however, that printing floats with `println` and friends will
|
||||
/// as `f32`. Note, however, that printing floats with `println` and friends will
|
||||
/// often discard insignificant digits: `println!("{}", 1.0f32 / 5.0f32)` will
|
||||
/// print `0.2`.
|
||||
///
|
||||
@ -820,7 +817,7 @@ mod prim_tuple {}
|
||||
///
|
||||
/// For more information on floating point numbers, see [Wikipedia][wikipedia].
|
||||
///
|
||||
/// *[See also the `std::f32::consts` module][`crate::f32::consts`].*
|
||||
/// *[See also the `std::f32::consts` module](crate::f32::consts).*
|
||||
///
|
||||
/// [wikipedia]: https://en.wikipedia.org/wiki/Single-precision_floating-point_format
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -834,7 +831,7 @@ mod prim_f32 {}
|
||||
/// `f32`][`f32`] or [Wikipedia on double precision
|
||||
/// values][wikipedia] for more information.
|
||||
///
|
||||
/// *[See also the `std::f64::consts` module][`crate::f64::consts`].*
|
||||
/// *[See also the `std::f64::consts` module](crate::f64::consts).*
|
||||
///
|
||||
/// [`f32`]: prim@f32
|
||||
/// [wikipedia]: https://en.wikipedia.org/wiki/Double-precision_floating-point_format
|
||||
|
@ -79,12 +79,12 @@ pub fn render<T: Print, S: Print>(
|
||||
{sidebar}\
|
||||
</nav>\
|
||||
<div class=\"theme-picker\">\
|
||||
<button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
|
||||
<button id=\"theme-picker\" aria-label=\"Pick another theme!\" aria-haspopup=\"menu\">\
|
||||
<img src=\"{static_root_path}brush{suffix}.svg\" \
|
||||
width=\"18\" \
|
||||
alt=\"Pick another theme!\">\
|
||||
</button>\
|
||||
<div id=\"theme-choices\"></div>\
|
||||
<div id=\"theme-choices\" role=\"menu\"></div>\
|
||||
</div>\
|
||||
<script src=\"{static_root_path}theme{suffix}.js\"></script>\
|
||||
<nav class=\"sub\">\
|
||||
|
@ -798,10 +798,10 @@ function handleThemeButtonsBlur(e) {{
|
||||
var active = document.activeElement;
|
||||
var related = e.relatedTarget;
|
||||
|
||||
if (active.id !== "themePicker" &&
|
||||
if (active.id !== "theme-picker" &&
|
||||
(!active.parentNode || active.parentNode.id !== "theme-choices") &&
|
||||
(!related ||
|
||||
(related.id !== "themePicker" &&
|
||||
(related.id !== "theme-picker" &&
|
||||
(!related.parentNode || related.parentNode.id !== "theme-choices")))) {{
|
||||
hideThemeButtonState();
|
||||
}}
|
||||
|
@ -4,6 +4,7 @@
|
||||
// Local js definitions:
|
||||
/* global addClass, getCurrentValue, hasClass */
|
||||
/* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
|
||||
/* global hideThemeButtonState, showThemeButtonState */
|
||||
|
||||
if (!String.prototype.startsWith) {
|
||||
String.prototype.startsWith = function(searchString, position) {
|
||||
@ -47,6 +48,14 @@ function getSearchElement() {
|
||||
return document.getElementById("search");
|
||||
}
|
||||
|
||||
function getThemesElement() {
|
||||
return document.getElementById("theme-choices");
|
||||
}
|
||||
|
||||
function getThemePickerElement() {
|
||||
return document.getElementById("theme-picker");
|
||||
}
|
||||
|
||||
// Sets the focus on the search bar at the top of the page
|
||||
function focusSearchBar() {
|
||||
getSearchInput().focus();
|
||||
@ -137,10 +146,6 @@ function defocusSearchBar() {
|
||||
sidebar.appendChild(div);
|
||||
}
|
||||
}
|
||||
var themePickers = document.getElementsByClassName("theme-picker");
|
||||
if (themePickers && themePickers.length > 0) {
|
||||
themePickers[0].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
function hideSidebar() {
|
||||
@ -155,10 +160,6 @@ function defocusSearchBar() {
|
||||
filler.remove();
|
||||
}
|
||||
document.getElementsByTagName("body")[0].style.marginTop = "";
|
||||
var themePickers = document.getElementsByClassName("theme-picker");
|
||||
if (themePickers && themePickers.length > 0) {
|
||||
themePickers[0].style.display = null;
|
||||
}
|
||||
}
|
||||
|
||||
function showSearchResults(search) {
|
||||
@ -376,6 +377,7 @@ function defocusSearchBar() {
|
||||
document.title = titleBeforeSearch;
|
||||
}
|
||||
defocusSearchBar();
|
||||
hideThemeButtonState();
|
||||
}
|
||||
|
||||
function handleShortcut(ev) {
|
||||
@ -412,10 +414,60 @@ function defocusSearchBar() {
|
||||
case "?":
|
||||
displayHelp(true, ev);
|
||||
break;
|
||||
|
||||
default:
|
||||
var themePicker = getThemePickerElement();
|
||||
if (themePicker.parentNode.contains(ev.target)) {
|
||||
handleThemeKeyDown(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleThemeKeyDown(ev) {
|
||||
var active = document.activeElement;
|
||||
var themes = getThemesElement();
|
||||
switch (getVirtualKey(ev)) {
|
||||
case "ArrowUp":
|
||||
ev.preventDefault();
|
||||
if (active.previousElementSibling && ev.target.id !== "theme-picker") {
|
||||
active.previousElementSibling.focus();
|
||||
} else {
|
||||
showThemeButtonState();
|
||||
themes.lastElementChild.focus();
|
||||
}
|
||||
break;
|
||||
case "ArrowDown":
|
||||
ev.preventDefault();
|
||||
if (active.nextElementSibling && ev.target.id !== "theme-picker") {
|
||||
active.nextElementSibling.focus();
|
||||
} else {
|
||||
showThemeButtonState();
|
||||
themes.firstElementChild.focus();
|
||||
}
|
||||
break;
|
||||
case "Enter":
|
||||
case "Return":
|
||||
case "Space":
|
||||
if (ev.target.id === "theme-picker" && themes.style.display === "none") {
|
||||
ev.preventDefault();
|
||||
showThemeButtonState();
|
||||
themes.firstElementChild.focus();
|
||||
}
|
||||
break;
|
||||
case "Home":
|
||||
ev.preventDefault();
|
||||
themes.firstElementChild.focus();
|
||||
break;
|
||||
case "End":
|
||||
ev.preventDefault();
|
||||
themes.lastElementChild.focus();
|
||||
break;
|
||||
// The escape key is handled in handleEscape, not here,
|
||||
// so that pressing escape will close the menu even if it isn't focused
|
||||
}
|
||||
}
|
||||
|
||||
function findParentElement(elem, tagName) {
|
||||
do {
|
||||
if (elem && elem.tagName === tagName) {
|
||||
|
@ -8,23 +8,23 @@ pub struct Bar;
|
||||
impl Foo for Bar {}
|
||||
impl Foo2 for Bar {}
|
||||
|
||||
// @!has foo/fn.foo.html '//section[@id="main"]//pre' "x: &\'x impl Foo"
|
||||
// @!has foo/fn.foo.html '//section[@id="main"]//pre' "-> &\'x impl Foo {"
|
||||
// @has foo/fn.foo.html '//section[@id="main"]//pre' "x: &'x impl Foo"
|
||||
// @has foo/fn.foo.html '//section[@id="main"]//pre' "-> &'x impl Foo"
|
||||
pub fn foo<'x>(x: &'x impl Foo) -> &'x impl Foo {
|
||||
x
|
||||
}
|
||||
|
||||
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' "x: &\'x impl Foo"
|
||||
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' '-> impl Foo2 {'
|
||||
// @has foo/fn.foo2.html '//section[@id="main"]//pre' "x: &'x impl Foo"
|
||||
// @has foo/fn.foo2.html '//section[@id="main"]//pre' '-> impl Foo2'
|
||||
pub fn foo2<'x>(_x: &'x impl Foo) -> impl Foo2 {
|
||||
Bar
|
||||
}
|
||||
|
||||
// @!has foo/fn.foo_foo.html '//section[@id="main"]//pre' '-> impl Foo + Foo2 {'
|
||||
// @has foo/fn.foo_foo.html '//section[@id="main"]//pre' '-> impl Foo + Foo2'
|
||||
pub fn foo_foo() -> impl Foo + Foo2 {
|
||||
Bar
|
||||
}
|
||||
|
||||
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' "x: &'x (impl Foo + Foo2)"
|
||||
// @has foo/fn.foo_foo_foo.html '//section[@id="main"]//pre' "x: &'x impl Foo + Foo2"
|
||||
pub fn foo_foo_foo<'x>(_x: &'x (impl Foo + Foo2)) {
|
||||
}
|
||||
|
@ -1,126 +0,0 @@
|
||||
// This test comprehensively checks the passing static and dynamic semantics
|
||||
// of subslice patterns `..`, `x @ ..`, `ref x @ ..`, and `ref mut @ ..`
|
||||
// in slice patterns `[$($pat), $(,)?]` .
|
||||
|
||||
// run-pass
|
||||
|
||||
#![allow(unreachable_patterns)]
|
||||
|
||||
use std::convert::identity;
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
struct N(u8);
|
||||
|
||||
macro_rules! n {
|
||||
($($e:expr),* $(,)?) => {
|
||||
[$(N($e)),*]
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! c {
|
||||
($inp:expr, $typ:ty, $out:expr $(,)?) => {
|
||||
assert_eq!($out, identity::<$typ>($inp));
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
($e:expr, $p:pat => $b:expr) => {
|
||||
match $e {
|
||||
$p => $b,
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
slices();
|
||||
arrays();
|
||||
}
|
||||
|
||||
fn slices() {
|
||||
// Matching slices using `ref` patterns:
|
||||
let mut v = vec![N(0), N(1), N(2), N(3), N(4)];
|
||||
let mut vc = (0..=4).collect::<Vec<u8>>();
|
||||
|
||||
let [..] = v[..]; // Always matches.
|
||||
m!(v[..], [N(0), ref sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
|
||||
m!(v[..], [N(0), ref sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
|
||||
m!(v[..], [ref sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
|
||||
m!(v[..], [ref sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(v[..], [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching slices using `ref mut` patterns:
|
||||
let [..] = v[..]; // Always matches.
|
||||
m!(v[..], [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
|
||||
m!(v[..], [N(0), ref mut sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
|
||||
m!(v[..], [ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
|
||||
m!(v[..], [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(v[..], [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching slices using default binding modes (&):
|
||||
let [..] = &v[..]; // Always matches.
|
||||
m!(&v[..], [N(0), sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
|
||||
m!(&v[..], [N(0), sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
|
||||
m!(&v[..], [sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
|
||||
m!(&v[..], [sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(&v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &[N], &n![] as &[N]));
|
||||
m!(&vc[..], [x, .., y] => c!((x, y), (&u8, &u8), (&0, &4)));
|
||||
|
||||
// Matching slices using default binding modes (&mut):
|
||||
let [..] = &mut v[..]; // Always matches.
|
||||
m!(&mut v[..], [N(0), sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
|
||||
m!(&mut v[..], [N(0), sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
|
||||
m!(&mut v[..], [sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
|
||||
m!(&mut v[..], [sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(&mut v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
|
||||
m!(&mut vc[..], [x, .., y] => c!((x, y), (&mut u8, &mut u8), (&mut 0, &mut 4)));
|
||||
}
|
||||
|
||||
fn arrays() {
|
||||
let mut v = n![0, 1, 2, 3, 4];
|
||||
let vc = [0, 1, 2, 3, 4];
|
||||
|
||||
// Matching arrays by value:
|
||||
m!(v.clone(), [N(0), sub @ .., N(4)] => c!(sub, [N; 3], n![1, 2, 3]));
|
||||
m!(v.clone(), [N(0), sub @ ..] => c!(sub, [N; 4], n![1, 2, 3, 4]));
|
||||
m!(v.clone(), [sub @ .., N(4)] => c!(sub, [N; 4], n![0, 1, 2, 3]));
|
||||
m!(v.clone(), [sub @ .., _, _, _, _, _] => c!(sub, [N; 0], n![] as [N; 0]));
|
||||
m!(v.clone(), [_, _, _, _, _, sub @ ..] => c!(sub, [N; 0], n![] as [N; 0]));
|
||||
m!(v.clone(), [x, .., y] => c!((x, y), (N, N), (N(0), N(4))));
|
||||
m!(v.clone(), [..] => ());
|
||||
|
||||
// Matching arrays by ref patterns:
|
||||
m!(v, [N(0), ref sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
|
||||
m!(v, [N(0), ref sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
|
||||
m!(v, [ref sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
|
||||
m!(v, [ref sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(v, [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(vc, [x, .., y] => c!((x, y), (u8, u8), (0, 4)));
|
||||
|
||||
// Matching arrays by ref mut patterns:
|
||||
m!(v, [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
|
||||
m!(v, [N(0), ref mut sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
|
||||
m!(v, [ref mut sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
|
||||
m!(v, [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));
|
||||
m!(v, [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));
|
||||
|
||||
// Matching arrays by default binding modes (&):
|
||||
m!(&v, [N(0), sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
|
||||
m!(&v, [N(0), sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
|
||||
m!(&v, [sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
|
||||
m!(&v, [sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(&v, [_, _, _, _, _, sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
|
||||
m!(&v, [..] => ());
|
||||
m!(&v, [x, .., y] => c!((x, y), (&N, &N), (&N(0), &N(4))));
|
||||
|
||||
// Matching arrays by default binding modes (&mut):
|
||||
m!(&mut v, [N(0), sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
|
||||
m!(&mut v, [N(0), sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
|
||||
m!(&mut v, [sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
|
||||
m!(&mut v, [sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
|
||||
m!(&mut v, [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
|
||||
m!(&mut v, [..] => ());
|
||||
m!(&mut v, [x, .., y] => c!((x, y), (&mut N, &mut N), (&mut N(0), &mut N(4))));
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(vec![1; 3], vec![1, 1, 1]);
|
||||
assert_eq!(vec![1; 2], vec![1, 1]);
|
||||
assert_eq!(vec![1; 1], vec![1]);
|
||||
assert_eq!(vec![1; 0], vec![]);
|
||||
|
||||
// from_elem syntax (see RFC 832)
|
||||
let el = Box::new(1);
|
||||
let n = 3;
|
||||
assert_eq!(vec![el; n], vec![Box::new(1), Box::new(1), Box::new(1)]);
|
||||
}
|
19
src/test/ui/async-await/issues/issue-78654.full.stderr
Normal file
19
src/test/ui/async-await/issues/issue-78654.full.stderr
Normal file
@ -0,0 +1,19 @@
|
||||
error[E0573]: expected type, found built-in attribute `feature`
|
||||
--> $DIR/issue-78654.rs:10:15
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^^^^^^^ not a type
|
||||
|
||||
error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/issue-78654.rs:10:12
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^ unconstrained const parameter
|
||||
|
|
||||
= note: expressions using a const parameter must map each value to a distinct output value
|
||||
= note: proving the result of expressions other than the parameter are unique is not supported
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0207, E0573.
|
||||
For more information about an error, try `rustc --explain E0207`.
|
19
src/test/ui/async-await/issues/issue-78654.min.stderr
Normal file
19
src/test/ui/async-await/issues/issue-78654.min.stderr
Normal file
@ -0,0 +1,19 @@
|
||||
error[E0573]: expected type, found built-in attribute `feature`
|
||||
--> $DIR/issue-78654.rs:10:15
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^^^^^^^ not a type
|
||||
|
||||
error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/issue-78654.rs:10:12
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^ unconstrained const parameter
|
||||
|
|
||||
= note: expressions using a const parameter must map each value to a distinct output value
|
||||
= note: proving the result of expressions other than the parameter are unique is not supported
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0207, E0573.
|
||||
For more information about an error, try `rustc --explain E0207`.
|
16
src/test/ui/async-await/issues/issue-78654.rs
Normal file
16
src/test/ui/async-await/issues/issue-78654.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// edition:2018
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl<const H: feature> Foo {
|
||||
//~^ ERROR: expected type, found built-in attribute `feature`
|
||||
//~^^ ERROR: the const parameter `H` is not constrained by the impl trait, self type, or predicates
|
||||
async fn biz() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -6,7 +6,7 @@ union Foo<'a> {
|
||||
long_live_the_unit: &'static (),
|
||||
}
|
||||
|
||||
const FOO: &() = { //~ ERROR it is undefined behavior to use this value
|
||||
const FOO: &() = {
|
||||
//~^ ERROR encountered dangling pointer in final constant
|
||||
let y = ();
|
||||
unsafe { Foo { y: &y }.long_live_the_unit }
|
||||
|
@ -8,18 +8,5 @@ LL | | unsafe { Foo { y: &y }.long_live_the_unit }
|
||||
LL | | };
|
||||
| |__^
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/dangling-alloc-id-ice.rs:9:1
|
||||
|
|
||||
LL | / const FOO: &() = {
|
||||
LL | |
|
||||
LL | | let y = ();
|
||||
LL | | unsafe { Foo { y: &y }.long_live_the_unit }
|
||||
LL | | };
|
||||
| |__^ type validation failed: encountered a dangling reference (use-after-free)
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
10
src/test/ui/consts/issue-78655.rs
Normal file
10
src/test/ui/consts/issue-78655.rs
Normal file
@ -0,0 +1,10 @@
|
||||
const FOO: *const u32 = { //~ ERROR encountered dangling pointer in final constant
|
||||
let x;
|
||||
&x //~ ERROR borrow of possibly-uninitialized variable: `x`
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let FOO = FOO;
|
||||
//~^ ERROR could not evaluate constant pattern
|
||||
//~| ERROR could not evaluate constant pattern
|
||||
}
|
30
src/test/ui/consts/issue-78655.stderr
Normal file
30
src/test/ui/consts/issue-78655.stderr
Normal file
@ -0,0 +1,30 @@
|
||||
error[E0381]: borrow of possibly-uninitialized variable: `x`
|
||||
--> $DIR/issue-78655.rs:3:5
|
||||
|
|
||||
LL | &x
|
||||
| ^^ use of possibly-uninitialized `x`
|
||||
|
||||
error: encountered dangling pointer in final constant
|
||||
--> $DIR/issue-78655.rs:1:1
|
||||
|
|
||||
LL | / const FOO: *const u32 = {
|
||||
LL | | let x;
|
||||
LL | | &x
|
||||
LL | | };
|
||||
| |__^
|
||||
|
||||
error: could not evaluate constant pattern
|
||||
--> $DIR/issue-78655.rs:7:9
|
||||
|
|
||||
LL | let FOO = FOO;
|
||||
| ^^^
|
||||
|
||||
error: could not evaluate constant pattern
|
||||
--> $DIR/issue-78655.rs:7:9
|
||||
|
|
||||
LL | let FOO = FOO;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0381`.
|
@ -1,51 +0,0 @@
|
||||
// run-pass
|
||||
#![allow(unused_braces)]
|
||||
#![allow(unused_comparisons)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_mut)]
|
||||
// Test range syntax.
|
||||
|
||||
|
||||
fn foo() -> isize { 42 }
|
||||
|
||||
// Test that range syntax works in return statements
|
||||
fn return_range_to() -> ::std::ops::RangeTo<i32> { return ..1; }
|
||||
fn return_full_range() -> ::std::ops::RangeFull { return ..; }
|
||||
|
||||
pub fn main() {
|
||||
let mut count = 0;
|
||||
for i in 0_usize..10 {
|
||||
assert!(i >= 0 && i < 10);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 45);
|
||||
|
||||
let mut count = 0;
|
||||
let mut range = 0_usize..10;
|
||||
for i in range {
|
||||
assert!(i >= 0 && i < 10);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 45);
|
||||
|
||||
let mut count = 0;
|
||||
let mut rf = 3_usize..;
|
||||
for i in rf.take(10) {
|
||||
assert!(i >= 3 && i < 13);
|
||||
count += i;
|
||||
}
|
||||
assert_eq!(count, 75);
|
||||
|
||||
let _ = 0_usize..4+4-3;
|
||||
let _ = 0..foo();
|
||||
|
||||
let _ = { &42..&100 }; // references to literals are OK
|
||||
let _ = ..42_usize;
|
||||
|
||||
// Test we can use two different types with a common supertype.
|
||||
let x = &42;
|
||||
{
|
||||
let y = 42;
|
||||
let _ = x..&y;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
use std::mem::swap;
|
||||
|
||||
pub fn main() {
|
||||
let mut a: Vec<isize> = vec![0, 1, 2, 3, 4, 5, 6];
|
||||
a.swap(2, 4);
|
||||
assert_eq!(a[2], 4);
|
||||
assert_eq!(a[4], 2);
|
||||
let mut n = 42;
|
||||
swap(&mut n, &mut a[0]);
|
||||
assert_eq!(a[0], 42);
|
||||
assert_eq!(n, 0);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// run-pass
|
||||
use std::collections::VecDeque;
|
||||
use std::iter::Iterator;
|
||||
|
||||
fn main() {
|
||||
const N: usize = 8;
|
||||
|
||||
// Zero sized type
|
||||
struct Zst;
|
||||
|
||||
// Test that for all possible sequences of push_front / push_back,
|
||||
// we end up with a deque of the correct size
|
||||
|
||||
for len in 0..N {
|
||||
let mut tester = VecDeque::with_capacity(len);
|
||||
assert_eq!(tester.len(), 0);
|
||||
assert!(tester.capacity() >= len);
|
||||
for case in 0..(1 << len) {
|
||||
assert_eq!(tester.len(), 0);
|
||||
for bit in 0..len {
|
||||
if case & (1 << bit) != 0 {
|
||||
tester.push_front(Zst);
|
||||
} else {
|
||||
tester.push_back(Zst);
|
||||
}
|
||||
}
|
||||
assert_eq!(tester.len(), len);
|
||||
assert_eq!(tester.iter().count(), len);
|
||||
tester.clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
// run-pass
|
||||
#![allow(unused_variables)]
|
||||
use std::iter::Iterator;
|
||||
use std::vec::Vec;
|
||||
|
||||
fn main() {
|
||||
const N: usize = 8;
|
||||
|
||||
for len in 0..N {
|
||||
let mut tester = Vec::with_capacity(len);
|
||||
assert_eq!(tester.len(), 0);
|
||||
assert!(tester.capacity() >= len);
|
||||
for bit in 0..len {
|
||||
tester.push(());
|
||||
}
|
||||
assert_eq!(tester.len(), len);
|
||||
assert_eq!(tester.iter().count(), len);
|
||||
tester.clear();
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit becb4c282b8f37469efb8f5beda45a5501f9d367
|
||||
Subproject commit d5556aeb8405b1fe696adb6e297ad7a1f2989b62
|
Loading…
Reference in New Issue
Block a user