diff --git a/src/Cargo.lock b/src/Cargo.lock index 97e0bf0a99bb1..9465f45dc19a4 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2049,6 +2049,7 @@ version = "0.0.0" dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", + "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", "syntax 0.0.0", diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 8a74e7c6f1cc6..ea711c69393a4 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -956,7 +956,8 @@ pub fn discriminant(v: &T) -> Discriminant { #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ManuallyDrop { +#[repr(transparent)] +pub struct ManuallyDrop { value: T, } @@ -990,7 +991,9 @@ impl ManuallyDrop { pub fn into_inner(slot: ManuallyDrop) -> T { slot.value } +} +impl ManuallyDrop { /// Manually drops the contained value. /// /// # Safety @@ -1006,7 +1009,7 @@ impl ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl Deref for ManuallyDrop { +impl Deref for ManuallyDrop { type Target = T; #[inline] fn deref(&self) -> &Self::Target { @@ -1015,7 +1018,7 @@ impl Deref for ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl DerefMut for ManuallyDrop { +impl DerefMut for ManuallyDrop { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value diff --git a/src/libcore/tests/manually_drop.rs b/src/libcore/tests/manually_drop.rs index 96bc9247da6e7..82dfb8d4c0b2a 100644 --- a/src/libcore/tests/manually_drop.rs +++ b/src/libcore/tests/manually_drop.rs @@ -21,4 +21,9 @@ fn smoke() { let x = ManuallyDrop::new(TypeWithDrop); drop(x); + + // also test unsizing + let x : Box> = + Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop])); + drop(x); } diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index d2209da0ca30c..e2380f0fe2ff3 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -411,7 +411,7 @@ impl<'a> Parser<'a> { // fill character if let Some(&(_, c)) = self.cur.peek() { - match self.cur.clone().skip(1).next() { + match self.cur.clone().nth(1) { Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => { spec.fill = Some(c); self.cur.next(); @@ -504,13 +504,11 @@ impl<'a> Parser<'a> { if word.is_empty() { self.cur = tmp; CountImplied + } else if self.consume('$') { + CountIsName(word) } else { - if self.consume('$') { - CountIsName(word) - } else { - self.cur = tmp; - CountImplied - } + self.cur = tmp; + CountImplied } } } diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index a8eea18e46461..9fa48adebdf07 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -420,7 +420,8 @@ impl<'a> Id<'a> { if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' ) { return Err(()); } - return Ok(Id { name: name }); + + Ok(Id { name }) } pub fn as_slice(&'a self) -> &'a str { @@ -533,10 +534,10 @@ impl<'a> LabelText<'a> { /// Renders text as string suitable for a label in a .dot file. /// This includes quotes or suitable delimiters. pub fn to_dot_string(&self) -> String { - match self { - &LabelStr(ref s) => format!("\"{}\"", s.escape_default()), - &EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)), - &HtmlStr(ref s) => format!("<{}>", s), + match *self { + LabelStr(ref s) => format!("\"{}\"", s.escape_default()), + EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)), + HtmlStr(ref s) => format!("<{}>", s), } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6b66fd8a2b2ff..9ae5ab7f8be2e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -51,6 +51,8 @@ use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, ELIDED_LIFETIMES_IN_PATHS}; use middle::cstore::CrateStore; use rustc_data_structures::indexed_vec::IndexVec; +use rustc_data_structures::small_vec::OneVector; +use rustc_data_structures::thin_vec::ThinVec; use session::Session; use util::common::FN_OUTPUT_NAME; use util::nodemap::{DefIdMap, NodeMap}; @@ -71,7 +73,6 @@ use syntax::std_inject; use syntax::symbol::{keywords, Symbol}; use syntax::tokenstream::{Delimited, TokenStream, TokenTree}; use syntax::parse::token::Token; -use syntax::util::small_vector::SmallVector; use syntax::visit::{self, Visitor}; use syntax_pos::{Span, MultiSpan}; @@ -3136,12 +3137,12 @@ impl<'a> LoweringContext<'a> { &mut self, decl: &FnDecl, header: &FnHeader, - ids: &mut SmallVector, + ids: &mut OneVector, ) { if let Some(id) = header.asyncness.opt_return_id() { ids.push(hir::ItemId { id }); } - struct IdVisitor<'a> { ids: &'a mut SmallVector } + struct IdVisitor<'a> { ids: &'a mut OneVector } impl<'a, 'b> Visitor<'a> for IdVisitor<'b> { fn visit_ty(&mut self, ty: &'a Ty) { match ty.node { @@ -3174,21 +3175,21 @@ impl<'a> LoweringContext<'a> { } } - fn lower_item_id(&mut self, i: &Item) -> SmallVector { + fn lower_item_id(&mut self, i: &Item) -> OneVector { match i.node { ItemKind::Use(ref use_tree) => { - let mut vec = SmallVector::one(hir::ItemId { id: i.id }); + let mut vec = OneVector::one(hir::ItemId { id: i.id }); self.lower_item_id_use_tree(use_tree, i.id, &mut vec); vec } - ItemKind::MacroDef(..) => SmallVector::new(), + ItemKind::MacroDef(..) => OneVector::new(), ItemKind::Fn(ref decl, ref header, ..) => { - let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + let mut ids = OneVector::one(hir::ItemId { id: i.id }); self.lower_impl_trait_ids(decl, header, &mut ids); ids }, ItemKind::Impl(.., None, _, ref items) => { - let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + let mut ids = OneVector::one(hir::ItemId { id: i.id }); for item in items { if let ImplItemKind::Method(ref sig, _) = item.node { self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids); @@ -3196,14 +3197,14 @@ impl<'a> LoweringContext<'a> { } ids }, - _ => SmallVector::one(hir::ItemId { id: i.id }), + _ => OneVector::one(hir::ItemId { id: i.id }), } } fn lower_item_id_use_tree(&mut self, tree: &UseTree, base_id: NodeId, - vec: &mut SmallVector) + vec: &mut OneVector) { match tree.kind { UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec { @@ -4295,8 +4296,8 @@ impl<'a> LoweringContext<'a> { } } - fn lower_stmt(&mut self, s: &Stmt) -> SmallVector { - SmallVector::one(match s.node { + fn lower_stmt(&mut self, s: &Stmt) -> OneVector { + OneVector::one(match s.node { StmtKind::Local(ref l) => Spanned { node: hir::StmtKind::Decl( P(Spanned { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 521499e476689..589f3c9d87cf5 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -33,13 +33,13 @@ use syntax::ext::hygiene::SyntaxContext; use syntax::ptr::P; use syntax::symbol::{Symbol, keywords}; use syntax::tokenstream::TokenStream; -use syntax::util::ThinVec; use syntax::util::parser::ExprPrecedence; use ty::AdtKind; use ty::query::Providers; use rustc_data_structures::indexed_vec; use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope}; +use rustc_data_structures::thin_vec::ThinVec; use serialize::{self, Encoder, Encodable, Decoder, Decodable}; use std::collections::BTreeMap; diff --git a/src/librustc_allocator/Cargo.toml b/src/librustc_allocator/Cargo.toml index 1cbde181cafae..83a918f2af837 100644 --- a/src/librustc_allocator/Cargo.toml +++ b/src/librustc_allocator/Cargo.toml @@ -10,6 +10,7 @@ test = false [dependencies] rustc = { path = "../librustc" } +rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 05843852ee0de..676dbeeeeb00b 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -9,6 +9,7 @@ // except according to those terms. use rustc::middle::allocator::AllocatorKind; +use rustc_data_structures::small_vec::OneVector; use rustc_errors; use syntax::{ ast::{ @@ -28,8 +29,7 @@ use syntax::{ fold::{self, Folder}, parse::ParseSess, ptr::P, - symbol::Symbol, - util::small_vector::SmallVector, + symbol::Symbol }; use syntax_pos::Span; @@ -65,7 +65,7 @@ struct ExpandAllocatorDirectives<'a> { } impl<'a> Folder for ExpandAllocatorDirectives<'a> { - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { debug!("in submodule {}", self.in_submod); let name = if attr::contains_name(&item.attrs, "global_allocator") { @@ -78,20 +78,20 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { _ => { self.handler .span_err(item.span, "allocators must be statics"); - return SmallVector::one(item); + return OneVector::one(item); } } if self.in_submod > 0 { self.handler .span_err(item.span, "`global_allocator` cannot be used in submodules"); - return SmallVector::one(item); + return OneVector::one(item); } if self.found { self.handler .span_err(item.span, "cannot define more than one #[global_allocator]"); - return SmallVector::one(item); + return OneVector::one(item); } self.found = true; @@ -152,7 +152,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { let module = f.cx.monotonic_expander().fold_item(module).pop().unwrap(); // Return the item and new submodule - let mut ret = SmallVector::with_capacity(2); + let mut ret = OneVector::with_capacity(2); ret.push(item); ret.push(module); diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index a920bb0f2b918..d020fe96335e9 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -13,6 +13,7 @@ #[macro_use] extern crate log; extern crate rustc; +extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_target; extern crate syntax; diff --git a/src/librustc_apfloat/ieee.rs b/src/librustc_apfloat/ieee.rs index b21448df582a9..45279f18117c1 100644 --- a/src/librustc_apfloat/ieee.rs +++ b/src/librustc_apfloat/ieee.rs @@ -536,23 +536,21 @@ impl fmt::Display for IeeeFloat { // Check whether we should use scientific notation. let scientific = if width == 0 { true + } else if exp >= 0 { + // 765e3 --> 765000 + // ^^^ + // But we shouldn't make the number look more precise than it is. + exp as usize > width || digits + exp as usize > precision } else { - if exp >= 0 { - // 765e3 --> 765000 - // ^^^ - // But we shouldn't make the number look more precise than it is. - exp as usize > width || digits + exp as usize > precision + // Power of the most significant digit. + let msd = exp + (digits - 1) as ExpInt; + if msd >= 0 { + // 765e-2 == 7.65 + false } else { - // Power of the most significant digit. - let msd = exp + (digits - 1) as ExpInt; - if msd >= 0 { - // 765e-2 == 7.65 - false - } else { - // 765e-5 == 0.00765 - // ^ ^^ - -msd as usize > width - } + // 765e-5 == 0.00765 + // ^ ^^ + -msd as usize > width } }; @@ -702,7 +700,7 @@ impl Float for IeeeFloat { // exponent = 1..10 // significand = 1..1 IeeeFloat { - sig: [!0 & ((1 << S::PRECISION) - 1)], + sig: [(1 << S::PRECISION) - 1], exp: S::MAX_EXP, category: Category::Normal, sign: false, @@ -1507,10 +1505,11 @@ impl FloatConvert> for IeeeFloat { } // If this is a truncation, perform the shift. - let mut loss = Loss::ExactlyZero; - if shift < 0 && (r.is_finite_non_zero() || r.category == Category::NaN) { - loss = sig::shift_right(&mut r.sig, &mut 0, -shift as usize); - } + let loss = if shift < 0 && (r.is_finite_non_zero() || r.category == Category::NaN) { + sig::shift_right(&mut r.sig, &mut 0, -shift as usize) + } else { + Loss::ExactlyZero + }; // If this is an extension, perform the shift. if shift > 0 && (r.is_finite_non_zero() || r.category == Category::NaN) { @@ -1738,27 +1737,25 @@ impl IeeeFloat { bit_pos -= 4; if bit_pos >= 0 { r.sig[0] |= (hex_value as Limb) << bit_pos; - } else { - // If zero or one-half (the hexadecimal digit 8) are followed - // by non-zero, they're a little more than zero or one-half. - if let Some(ref mut loss) = loss { - if hex_value != 0 { - if *loss == Loss::ExactlyZero { - *loss = Loss::LessThanHalf; - } - if *loss == Loss::ExactlyHalf { - *loss = Loss::MoreThanHalf; - } + // If zero or one-half (the hexadecimal digit 8) are followed + // by non-zero, they're a little more than zero or one-half. + } else if let Some(ref mut loss) = loss { + if hex_value != 0 { + if *loss == Loss::ExactlyZero { + *loss = Loss::LessThanHalf; + } + if *loss == Loss::ExactlyHalf { + *loss = Loss::MoreThanHalf; } - } else { - loss = Some(match hex_value { - 0 => Loss::ExactlyZero, - 1..=7 => Loss::LessThanHalf, - 8 => Loss::ExactlyHalf, - 9..=15 => Loss::MoreThanHalf, - _ => unreachable!(), - }); } + } else { + loss = Some(match hex_value { + 0 => Loss::ExactlyZero, + 1..=7 => Loss::LessThanHalf, + 8 => Loss::ExactlyHalf, + 9..=15 => Loss::MoreThanHalf, + _ => unreachable!(), + }); } } else if c == 'p' || c == 'P' { if !any_digits { @@ -2309,9 +2306,9 @@ mod sig { /// One, not zero, based LSB. That is, returns 0 for a zeroed significand. pub(super) fn olsb(limbs: &[Limb]) -> usize { - for i in 0..limbs.len() { - if limbs[i] != 0 { - return i * LIMB_BITS + limbs[i].trailing_zeros() as usize + 1; + for (i, &limb) in limbs.iter().enumerate() { + if limb != 0 { + return i * LIMB_BITS + limb.trailing_zeros() as usize + 1; } } @@ -2320,9 +2317,9 @@ mod sig { /// One, not zero, based MSB. That is, returns 0 for a zeroed significand. pub(super) fn omsb(limbs: &[Limb]) -> usize { - for i in (0..limbs.len()).rev() { - if limbs[i] != 0 { - return (i + 1) * LIMB_BITS - limbs[i].leading_zeros() as usize; + for (i, &limb) in limbs.iter().enumerate().rev() { + if limb != 0 { + return (i + 1) * LIMB_BITS - limb.leading_zeros() as usize; } } @@ -2378,7 +2375,7 @@ mod sig { limb = dst[i - jump]; if shift > 0 { limb <<= shift; - if i >= jump + 1 { + if i > jump { limb |= dst[i - jump - 1] >> (LIMB_BITS - shift); } } @@ -2448,7 +2445,7 @@ mod sig { let n = dst_limbs * LIMB_BITS - shift; if n < src_bits { let mask = (1 << (src_bits - n)) - 1; - dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << n % LIMB_BITS; + dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << (n % LIMB_BITS); } else if n > src_bits && src_bits % LIMB_BITS > 0 { dst[dst_limbs - 1] &= (1 << (src_bits % LIMB_BITS)) - 1; } diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index ebe8b79741438..d60983d7697b7 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -180,6 +180,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool) let is_pie_binary = !find_features && is_pie_binary(sess); let trap_unreachable = sess.target.target.options.trap_unreachable; + let asm_comments = sess.asm_comments(); + Arc::new(move || { let tm = unsafe { llvm::LLVMRustCreateTargetMachine( @@ -193,6 +195,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool) fdata_sections, trap_unreachable, singlethread, + asm_comments, ) }; diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 5501e915976a3..770a22ad65842 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -230,7 +230,6 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value { } cx.instances.borrow_mut().insert(instance, g); - cx.statics.borrow_mut().insert(g, def_id); g } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 781f8ebbb78c1..32ea2c5eb8f35 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -13,7 +13,6 @@ use common; use llvm; use rustc::dep_graph::DepGraphSafe; use rustc::hir; -use rustc::hir::def_id::DefId; use debuginfo; use callee; use base; @@ -78,9 +77,6 @@ pub struct CodegenCx<'a, 'tcx: 'a> { /// Cache of emitted const globals (value -> global) pub const_globals: RefCell>, - /// Mapping from static definitions to their DefId's. - pub statics: RefCell>, - /// List of globals for static variables which need to be passed to the /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete. /// (We have to make sure we don't invalidate any Values referring @@ -297,7 +293,6 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> { const_cstr_cache: RefCell::new(FxHashMap()), const_unsized: RefCell::new(FxHashMap()), const_globals: RefCell::new(FxHashMap()), - statics: RefCell::new(FxHashMap()), statics_to_rauw: RefCell::new(Vec::new()), used_statics: RefCell::new(Vec::new()), lltypes: RefCell::new(FxHashMap()), diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 68a21a537070b..eec8a3a169ced 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1455,7 +1455,8 @@ extern "C" { FunctionSections: bool, DataSections: bool, TrapUnreachable: bool, - Singlethread: bool) + Singlethread: bool, + AsmComments: bool) -> Option<&'static mut TargetMachine>; pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine); pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module); diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index 8fdb67f5930ce..8bb049be30549 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -574,6 +574,25 @@ fn arg_local_refs( }; let upvar_tys = upvar_substs.upvar_tys(def_id, tcx); + // Store the pointer to closure data in an alloca for debuginfo + // because that's what the llvm.dbg.declare intrinsic expects. + + // FIXME(eddyb) this shouldn't be necessary but SROA seems to + // mishandle DW_OP_plus not preceded by DW_OP_deref, i.e. it + // doesn't actually strip the offset when splitting the closure + // environment into its components so it ends up out of bounds. + // (cuviper) It seems to be fine without the alloca on LLVM 6 and later. + let env_alloca = !env_ref && unsafe { llvm::LLVMRustVersionMajor() < 6 }; + let env_ptr = if env_alloca { + let scratch = PlaceRef::alloca(bx, + bx.cx.layout_of(tcx.mk_mut_ptr(arg.layout.ty)), + "__debuginfo_env_ptr"); + bx.store(place.llval, scratch.llval, scratch.align); + scratch.llval + } else { + place.llval + }; + for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() { let byte_offset_of_var_in_env = closure_layout.fields.offset(i).bytes(); @@ -585,7 +604,10 @@ fn arg_local_refs( }; // The environment and the capture can each be indirect. - let mut ops = if env_ref { &ops[..] } else { &ops[1..] }; + + // FIXME(eddyb) see above why we sometimes have to keep + // a pointer in an alloca for debuginfo atm. + let mut ops = if env_ref || env_alloca { &ops[..] } else { &ops[1..] }; let ty = if let (true, &ty::TyRef(_, ty, _)) = (decl.by_ref, &ty.sty) { ty @@ -595,7 +617,7 @@ fn arg_local_refs( }; let variable_access = VariableAccess::IndirectVariable { - alloca: place.llval, + alloca: env_ptr, address_operations: &ops }; declare_local( diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index a528008e3b4bd..80c4df1d6b005 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -143,7 +143,6 @@ fn predefine_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, } cx.instances.borrow_mut().insert(instance, g); - cx.statics.borrow_mut().insert(g, def_id); } fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 421229a89099d..5699512326a37 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -79,6 +79,7 @@ pub mod sorted_map; #[macro_use] pub mod stable_hasher; pub mod sync; pub mod tiny_list; +pub mod thin_vec; pub mod transitive_relation; pub mod tuple_slice; pub use ena::unify; diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs index e958fd7da613e..6f101b20d8806 100644 --- a/src/librustc_data_structures/small_vec.rs +++ b/src/librustc_data_structures/small_vec.rs @@ -29,6 +29,8 @@ use array_vec::Array; pub struct SmallVec(AccumulateVec); +pub type OneVector = SmallVec<[T; 1]>; + impl Clone for SmallVec where A: Array, A::Element: Clone { @@ -227,6 +229,69 @@ mod tests { use super::*; + #[test] + fn test_len() { + let v: OneVector = OneVector::new(); + assert_eq!(0, v.len()); + + assert_eq!(1, OneVector::one(1).len()); + assert_eq!(5, OneVector::many(vec![1, 2, 3, 4, 5]).len()); + } + + #[test] + fn test_push_get() { + let mut v = OneVector::new(); + v.push(1); + assert_eq!(1, v.len()); + assert_eq!(1, v[0]); + v.push(2); + assert_eq!(2, v.len()); + assert_eq!(2, v[1]); + v.push(3); + assert_eq!(3, v.len()); + assert_eq!(3, v[2]); + } + + #[test] + fn test_from_iter() { + let v: OneVector = (vec![1, 2, 3]).into_iter().collect(); + assert_eq!(3, v.len()); + assert_eq!(1, v[0]); + assert_eq!(2, v[1]); + assert_eq!(3, v[2]); + } + + #[test] + fn test_move_iter() { + let v = OneVector::new(); + let v: Vec = v.into_iter().collect(); + assert_eq!(v, Vec::new()); + + let v = OneVector::one(1); + assert_eq!(v.into_iter().collect::>(), [1]); + + let v = OneVector::many(vec![1, 2, 3]); + assert_eq!(v.into_iter().collect::>(), [1, 2, 3]); + } + + #[test] + #[should_panic] + fn test_expect_one_zero() { + let _: isize = OneVector::new().expect_one(""); + } + + #[test] + #[should_panic] + fn test_expect_one_many() { + OneVector::many(vec![1, 2]).expect_one(""); + } + + #[test] + fn test_expect_one_one() { + assert_eq!(1, OneVector::one(1).expect_one("")); + assert_eq!(1, OneVector::many(vec![1]).expect_one("")); + } + #[bench] fn fill_small_vec_1_10_with_cap(b: &mut Bencher) { b.iter(|| { diff --git a/src/libsyntax/util/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs similarity index 100% rename from src/libsyntax/util/thin_vec.rs rename to src/librustc_data_structures/thin_vec.rs diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index c3bdf07cd2079..df7ab101fec3b 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1513,7 +1513,7 @@ pub fn in_named_rustc_thread(name: String, f: F) -> Result(name: String, f: F) -> Result fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_item_kind(i, s)) } - fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, i: ast::TraitItem) -> OneVector { let is_const = match i.node { ast::TraitItemKind::Const(..) => true, ast::TraitItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => @@ -737,7 +737,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_trait_item(i, s)) } - fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, i: ast::ImplItem) -> OneVector { let is_const = match i.node { ast::ImplItemKind::Const(..) => true, ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => @@ -785,7 +785,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { node: ast::ExprKind::Loop(P(empty_block), None), id: self.sess.next_node_id(), span: syntax_pos::DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); let loop_stmt = ast::Stmt { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 3a449b6a68e4c..88277a7821673 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1927,14 +1927,12 @@ impl Async2018 { ); // Don't suggest about raw identifiers if the feature isn't active - if cx.sess.features_untracked().raw_identifiers { - lint.span_suggestion_with_applicability( - span, - "you can use a raw identifier to stay compatible", - "r#async".to_string(), - Applicability::MachineApplicable, - ); - } + lint.span_suggestion_with_applicability( + span, + "you can use a raw identifier to stay compatible", + "r#async".to_string(), + Applicability::MachineApplicable, + ); lint.emit() } } diff --git a/src/librustc_target/spec/aarch64_unknown_none.rs b/src/librustc_target/spec/aarch64_unknown_none.rs new file mode 100644 index 0000000000000..cfba0614adcd6 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_none.rs @@ -0,0 +1,46 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Generic AArch64 target for bare-metal code +// +// Can be used in conjunction with the `target-feature` and +// `target-cpu` compiler flags to opt-in more hardware-specific +// features. +// +// For example, `-C target-cpu=cortex-a53`. + +use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy}; + +pub fn target() -> Result { + let opts = TargetOptions { + linker: Some("rust-lld".to_owned()), + executables: true, + relocation_model: "static".to_string(), + disable_redzone: true, + linker_is_gnu: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + abi_blacklist: super::arm_base::abi_blacklist(), + .. Default::default() + }; + Ok(Target { + llvm_target: "aarch64-unknown-none".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_os: "none".to_string(), + target_env: "".to_string(), + target_vendor: "".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + options: opts, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index ce3d61cecbb69..d55762e03eee3 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -380,6 +380,8 @@ supported_targets! { ("x86_64-unknown-hermit", x86_64_unknown_hermit), ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf), + + ("aarch64-unknown-none", aarch64_unknown_none), } /// Everything `rustc` knows about how to compile for a specific target. @@ -765,14 +767,10 @@ impl Target { // the JSON parser is not updated to match the structs. let get_req_field = |name: &str| { - match obj.find(name) - .map(|s| s.as_string()) - .and_then(|os| os.map(|s| s.to_string())) { - Some(val) => Ok(val), - None => { - return Err(format!("Field {} in target specification is required", name)) - } - } + obj.find(name) + .map(|s| s.as_string()) + .and_then(|os| os.map(|s| s.to_string())) + .ok_or_else(|| format!("Field {} in target specification is required", name)) }; let get_opt_field = |name: &str, default: &str| { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 4c306d9b2d375..7f3736e82caa6 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -22,7 +22,7 @@ pub trait ToHex { fn to_hex(&self) -> String; } -const CHARS: &'static [u8] = b"0123456789abcdef"; +const CHARS: &[u8] = b"0123456789abcdef"; impl ToHex for [u8] { /// Turn a vector of `u8` bytes into a hexadecimal string. diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index d42132440163c..0361718eb7337 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -438,7 +438,7 @@ fn escape_char(writer: &mut dyn fmt::Write, v: char) -> EncodeResult { } fn spaces(wr: &mut dyn fmt::Write, mut n: usize) -> EncodeResult { - const BUF: &'static str = " "; + const BUF: &str = " "; while n >= BUF.len() { wr.write_str(BUF)?; @@ -799,21 +799,21 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { escape_str(self.writer, name) } else { if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); } - write!(self.writer, "{{\n")?; + writeln!(self.writer, "{{")?; self.curr_indent += self.indent; spaces(self.writer, self.curr_indent)?; write!(self.writer, "\"variant\": ")?; escape_str(self.writer, name)?; - write!(self.writer, ",\n")?; + writeln!(self.writer, ",")?; spaces(self.writer, self.curr_indent)?; - write!(self.writer, "\"fields\": [\n")?; + writeln!(self.writer, "\"fields\": [")?; self.curr_indent += self.indent; f(self)?; self.curr_indent -= self.indent; - write!(self.writer, "\n")?; + writeln!(self.writer)?; spaces(self.writer, self.curr_indent)?; self.curr_indent -= self.indent; - write!(self.writer, "]\n")?; + writeln!(self.writer, "]")?; spaces(self.writer, self.curr_indent)?; write!(self.writer, "}}")?; Ok(()) @@ -825,7 +825,7 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { { if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); } if idx != 0 { - write!(self.writer, ",\n")?; + writeln!(self.writer, ",")?; } spaces(self.writer, self.curr_indent)?; f(self) @@ -864,7 +864,7 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { self.curr_indent += self.indent; f(self)?; self.curr_indent -= self.indent; - write!(self.writer, "\n")?; + writeln!(self.writer)?; spaces(self.writer, self.curr_indent)?; write!(self.writer, "}}")?; } @@ -876,9 +876,9 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { { if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); } if idx == 0 { - write!(self.writer, "\n")?; + writeln!(self.writer)?; } else { - write!(self.writer, ",\n")?; + writeln!(self.writer, ",")?; } spaces(self.writer, self.curr_indent)?; escape_str(self.writer, name)?; @@ -940,7 +940,7 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { self.curr_indent += self.indent; f(self)?; self.curr_indent -= self.indent; - write!(self.writer, "\n")?; + writeln!(self.writer)?; spaces(self.writer, self.curr_indent)?; write!(self.writer, "]")?; } @@ -952,9 +952,9 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { { if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); } if idx == 0 { - write!(self.writer, "\n")?; + writeln!(self.writer)?; } else { - write!(self.writer, ",\n")?; + writeln!(self.writer, ",")?; } spaces(self.writer, self.curr_indent)?; f(self) @@ -971,7 +971,7 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { self.curr_indent += self.indent; f(self)?; self.curr_indent -= self.indent; - write!(self.writer, "\n")?; + writeln!(self.writer)?; spaces(self.writer, self.curr_indent)?; write!(self.writer, "}}")?; } @@ -983,9 +983,9 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { { if self.is_emitting_map_key { return Err(EncoderError::BadHashmapKey); } if idx == 0 { - write!(self.writer, "\n")?; + writeln!(self.writer)?; } else { - write!(self.writer, ",\n")?; + writeln!(self.writer, ",")?; } spaces(self.writer, self.curr_indent)?; self.is_emitting_map_key = true; @@ -1387,10 +1387,10 @@ impl Stack { // Used by Parser to test whether the top-most element is an index. fn last_is_index(&self) -> bool { - if self.is_empty() { return false; } - return match *self.stack.last().unwrap() { - InternalIndex(_) => true, - _ => false, + if let Some(InternalIndex(_)) = self.stack.last() { + true + } else { + false } } @@ -1530,19 +1530,17 @@ impl> Parser { } F64Value(res) - } else { - if neg { - let res = (res as i64).wrapping_neg(); + } else if neg { + let res = (res as i64).wrapping_neg(); - // Make sure we didn't underflow. - if res > 0 { - Error(SyntaxError(InvalidNumber, self.line, self.col)) - } else { - I64Value(res) - } + // Make sure we didn't underflow. + if res > 0 { + Error(SyntaxError(InvalidNumber, self.line, self.col)) } else { - U64Value(res) + I64Value(res) } + } else { + U64Value(res) } } diff --git a/src/libserialize/leb128.rs b/src/libserialize/leb128.rs index ae7f25c7fedbe..eee95d9fa6777 100644 --- a/src/libserialize/leb128.rs +++ b/src/libserialize/leb128.rs @@ -103,8 +103,8 @@ pub fn write_signed_leb128_to(mut value: i128, mut write: W) loop { let mut byte = (value as u8) & 0x7f; value >>= 7; - let more = !((((value == 0) && ((byte & 0x40) == 0)) || - ((value == -1) && ((byte & 0x40) != 0)))); + let more = !(((value == 0) && ((byte & 0x40) == 0)) || + ((value == -1) && ((byte & 0x40) != 0))); if more { byte |= 0x80; // Mark this byte to show that more bytes will follow. diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 08c3e15497843..f8f0bbd5bc250 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -414,12 +414,8 @@ pub fn env() -> Env { unsafe { let _guard = ENV_LOCK.lock(); let mut environ = *environ(); - if environ == ptr::null() { - panic!("os::env() failure getting env string from OS: {}", - io::Error::last_os_error()); - } let mut result = Vec::new(); - while *environ != ptr::null() { + while environ != ptr::null() && *environ != ptr::null() { if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { result.push(key_value); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6925ed2afb83b..919ffcb8d0980 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,6 @@ pub use self::UnsafeSource::*; pub use self::GenericArgs::*; pub use symbol::{Ident, Symbol as Name}; -pub use util::ThinVec; pub use util::parser::ExprPrecedence; use syntax_pos::{Span, DUMMY_SP}; @@ -25,6 +24,7 @@ use ptr::P; use rustc_data_structures::indexed_vec; use rustc_data_structures::indexed_vec::Idx; use symbol::{Symbol, keywords}; +use ThinVec; use tokenstream::{ThinTokenStream, TokenStream}; use serialize::{self, Encoder, Decoder}; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index b3b173db70b89..879f555ba03ee 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -33,8 +33,8 @@ use parse::{self, ParseSess, PResult}; use parse::token::{self, Token}; use ptr::P; use symbol::Symbol; +use ThinVec; use tokenstream::{TokenStream, TokenTree, Delimited}; -use util::ThinVec; use GLOBALS; use std::iter; diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 3364378913952..4fe78bf829a1c 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -15,9 +15,9 @@ use ast; use codemap::Spanned; use edition::Edition; use parse::{token, ParseSess}; +use OneVector; use ptr::P; -use util::small_vector::SmallVector; /// A folder that strips out items that do not belong in the current configuration. pub struct StripUnconfigured<'a> { @@ -319,22 +319,22 @@ impl<'a> fold::Folder for StripUnconfigured<'a> { Some(P(fold::noop_fold_expr(expr, self))) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { match self.configure_stmt(stmt) { Some(stmt) => fold::noop_fold_stmt(stmt, self), - None => return SmallVector::new(), + None => return OneVector::new(), } } - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { fold::noop_fold_item(configure!(self, item), self) } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { fold::noop_fold_impl_item(configure!(self, item), self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { fold::noop_fold_trait_item(configure!(self, item), self) } diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 15abad555f4b6..89af57a085807 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -382,8 +382,9 @@ Erroneous code example: ```ignore (limited to a warning during 2018 edition development) #![feature(rust_2018_preview)] -#![feature(raw_identifiers)] // error: the feature `raw_identifiers` is - // included in the Rust 2018 edition +#![feature(impl_header_lifetime_elision)] // error: the feature + // `impl_header_lifetime_elision` is + // included in the Rust 2018 edition ``` "##, diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 72ce2740190d4..6a5a2a5e500ff 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -19,9 +19,9 @@ use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::build::AstBuilder; use parse::token; use ptr::P; +use OneVector; use symbol::{keywords, Symbol}; use tokenstream::{TokenTree}; -use util::small_vector::SmallVector; use diagnostics::metadata::output_metadata; @@ -131,7 +131,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, let sym = Ident::with_empty_ctxt(Symbol::gensym(&format!( "__register_diagnostic_{}", code ))); - MacEager::items(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ ecx.item_mod( span, span, @@ -214,7 +214,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ), ); - MacEager::items(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ P(ast::Item { ident: *name, attrs: Vec::new(), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index de391ee4219a4..482d8c2cf9866 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -22,8 +22,9 @@ use fold::{self, Folder}; use parse::{self, parser, DirectoryOwnership}; use parse::token; use ptr::P; +use OneVector; use symbol::{keywords, Ident, Symbol}; -use util::small_vector::SmallVector; +use ThinVec; use std::collections::HashMap; use std::iter; @@ -315,7 +316,7 @@ impl IdentMacroExpander for F // Use a macro because forwarding to a simple function has type system issues macro_rules! make_stmts_default { ($me:expr) => { - $me.make_expr().map(|e| SmallVector::one(ast::Stmt { + $me.make_expr().map(|e| OneVector::one(ast::Stmt { id: ast::DUMMY_NODE_ID, span: e.span, node: ast::StmtKind::Expr(e), @@ -331,22 +332,22 @@ pub trait MacResult { None } /// Create zero or more items. - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { None } /// Create zero or more impl items. - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { None } /// Create zero or more trait items. - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { None } /// Create zero or more items in an `extern {}` block - fn make_foreign_items(self: Box) -> Option> { None } + fn make_foreign_items(self: Box) -> Option> { None } /// Create a pattern. fn make_pat(self: Box) -> Option> { @@ -357,7 +358,7 @@ pub trait MacResult { /// /// By default this attempts to create an expression statement, /// returning None if that fails. - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { make_stmts_default!(self) } @@ -393,11 +394,11 @@ macro_rules! make_MacEager { make_MacEager! { expr: P, pat: P, - items: SmallVector>, - impl_items: SmallVector, - trait_items: SmallVector, - foreign_items: SmallVector, - stmts: SmallVector, + items: OneVector>, + impl_items: OneVector, + trait_items: OneVector, + foreign_items: OneVector, + stmts: OneVector, ty: P, } @@ -406,23 +407,23 @@ impl MacResult for MacEager { self.expr } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { self.items } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { self.impl_items } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { self.trait_items } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { self.foreign_items } - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { match self.stmts.as_ref().map_or(0, |s| s.len()) { 0 => make_stmts_default!(self), _ => self.stmts, @@ -482,7 +483,7 @@ impl DummyResult { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))), span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } @@ -513,41 +514,41 @@ impl MacResult for DummyResult { Some(P(DummyResult::raw_pat(self.span))) } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { // this code needs a comment... why not always just return the Some() ? if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_stmts(self: Box) -> Option> { - Some(SmallVector::one(ast::Stmt { + fn make_stmts(self: Box) -> Option> { + Some(OneVector::one(ast::Stmt { id: ast::DUMMY_NODE_ID, node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)), span: self.span, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6135650766569..1a17aa3e8fb64 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -16,6 +16,7 @@ use codemap::{dummy_spanned, respan, Spanned}; use ext::base::ExtCtxt; use ptr::P; use symbol::{Symbol, keywords}; +use ThinVec; // Transitional re-exports so qquote can find the paths it is looking for mod syntax { @@ -519,7 +520,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -547,7 +548,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -564,7 +565,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: None, id: ast::DUMMY_NODE_ID, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -603,7 +604,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, node, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } @@ -678,7 +679,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { expr: e, span, is_shorthand: false, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), } } fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec) -> P { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 12941a8566987..f7ea781e02115 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -26,12 +26,12 @@ use parse::{DirectoryOwnership, PResult, ParseSess}; use parse::token::{self, Token}; use parse::parser::Parser; use ptr::P; +use OneVector; use symbol::Symbol; use symbol::keywords; use syntax_pos::{Span, DUMMY_SP, FileName}; use syntax_pos::hygiene::ExpnFormat; use tokenstream::{TokenStream, TokenTree}; -use util::small_vector::SmallVector; use visit::{self, Visitor}; use std::collections::HashMap; @@ -131,7 +131,7 @@ macro_rules! ast_fragments { self.expand_fragment(AstFragment::$Kind(ast)).$make_ast() })*)* $($(fn $fold_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy { - self.expand_fragment(AstFragment::$Kind(SmallVector::one(ast_elt))).$make_ast() + self.expand_fragment(AstFragment::$Kind(OneVector::one(ast_elt))).$make_ast() })*)* } @@ -148,15 +148,15 @@ ast_fragments! { Expr(P) { "expression"; one fn fold_expr; fn visit_expr; fn make_expr; } Pat(P) { "pattern"; one fn fold_pat; fn visit_pat; fn make_pat; } Ty(P) { "type"; one fn fold_ty; fn visit_ty; fn make_ty; } - Stmts(SmallVector) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; } - Items(SmallVector>) { "item"; many fn fold_item; fn visit_item; fn make_items; } - TraitItems(SmallVector) { + Stmts(OneVector) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; } + Items(OneVector>) { "item"; many fn fold_item; fn visit_item; fn make_items; } + TraitItems(OneVector) { "trait item"; many fn fold_trait_item; fn visit_trait_item; fn make_trait_items; } - ImplItems(SmallVector) { + ImplItems(OneVector) { "impl item"; many fn fold_impl_item; fn visit_impl_item; fn make_impl_items; } - ForeignItems(SmallVector) { + ForeignItems(OneVector) { "foreign item"; many fn fold_foreign_item; fn visit_foreign_item; fn make_foreign_items; } } @@ -279,7 +279,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let orig_mod_span = krate.module.inner; - let krate_item = AstFragment::Items(SmallVector::one(P(ast::Item { + let krate_item = AstFragment::Items(OneVector::one(P(ast::Item { attrs: krate.attrs, span: krate.span, node: ast::ItemKind::Mod(krate.module), @@ -989,28 +989,28 @@ impl<'a> Parser<'a> { -> PResult<'a, AstFragment> { Ok(match kind { AstFragmentKind::Items => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while let Some(item) = self.parse_item()? { items.push(item); } AstFragment::Items(items) } AstFragmentKind::TraitItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { items.push(self.parse_trait_item(&mut false)?); } AstFragment::TraitItems(items) } AstFragmentKind::ImplItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { items.push(self.parse_impl_item(&mut false)?); } AstFragment::ImplItems(items) } AstFragmentKind::ForeignItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { if let Some(item) = self.parse_foreign_item()? { items.push(item); @@ -1019,7 +1019,7 @@ impl<'a> Parser<'a> { AstFragment::ForeignItems(items) } AstFragmentKind::Stmts => { - let mut stmts = SmallVector::new(); + let mut stmts = OneVector::new(); while self.token != token::Eof && // won't make progress on a `}` self.token != token::CloseDelim(token::Brace) { @@ -1086,12 +1086,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { /// Folds the item allowing tests to be expanded because they are still nameable. /// This should probably only be called with module items - fn fold_nameable(&mut self, item: P) -> SmallVector> { + fn fold_nameable(&mut self, item: P) -> OneVector> { fold::noop_fold_item(item, self) } /// Folds the item but doesn't allow tests to occur within it - fn fold_unnameable(&mut self, item: P) -> SmallVector> { + fn fold_unnameable(&mut self, item: P) -> OneVector> { let was_nameable = mem::replace(&mut self.tests_nameable, false); let items = fold::noop_fold_item(item, self); self.tests_nameable = was_nameable; @@ -1254,10 +1254,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { }) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { let mut stmt = match self.cfg.configure_stmt(stmt) { Some(stmt) => stmt, - None => return SmallVector::new(), + None => return OneVector::new(), }; // we'll expand attributes on expressions separately @@ -1313,7 +1313,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { result } - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { let item = configure!(self, item); let (attr, traits, mut item) = self.classify_item(item); @@ -1422,7 +1422,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { ui }); - SmallVector::many( + OneVector::many( self.fold_unnameable(item).into_iter() .chain(self.fold_unnameable(use_item))) } else { @@ -1433,7 +1433,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { let item = configure!(self, item); let (attr, traits, item) = self.classify_item(item); @@ -1453,7 +1453,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { let item = configure!(self, item); let (attr, traits, item) = self.classify_item(item); @@ -1490,7 +1490,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } fn fold_foreign_item(&mut self, - foreign_item: ast::ForeignItem) -> SmallVector { + foreign_item: ast::ForeignItem) -> OneVector { let (attr, traits, foreign_item) = self.classify_item(foreign_item); if attr.is_some() || !traits.is_empty() { diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 968cf508edaaa..1dc9bae8848f3 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -16,9 +16,10 @@ use ext::hygiene::Mark; use tokenstream::TokenStream; use fold::*; use ptr::P; +use OneVector; use symbol::keywords; +use ThinVec; use util::move_map::MoveMap; -use util::small_vector::SmallVector; use std::collections::HashMap; @@ -38,31 +39,31 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { let span = DUMMY_SP; let expr_placeholder = || P(ast::Expr { id, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), node: ast::ExprKind::Mac(mac_placeholder()), }); match kind { AstFragmentKind::Expr => AstFragment::Expr(expr_placeholder()), AstFragmentKind::OptExpr => AstFragment::OptExpr(Some(expr_placeholder())), - AstFragmentKind::Items => AstFragment::Items(SmallVector::one(P(ast::Item { + AstFragmentKind::Items => AstFragment::Items(OneVector::one(P(ast::Item { id, span, ident, vis, attrs, node: ast::ItemKind::Mac(mac_placeholder()), tokens: None, }))), - AstFragmentKind::TraitItems => AstFragment::TraitItems(SmallVector::one(ast::TraitItem { + AstFragmentKind::TraitItems => AstFragment::TraitItems(OneVector::one(ast::TraitItem { id, span, ident, attrs, generics, node: ast::TraitItemKind::Macro(mac_placeholder()), tokens: None, })), - AstFragmentKind::ImplItems => AstFragment::ImplItems(SmallVector::one(ast::ImplItem { + AstFragmentKind::ImplItems => AstFragment::ImplItems(OneVector::one(ast::ImplItem { id, span, ident, vis, attrs, generics, node: ast::ImplItemKind::Macro(mac_placeholder()), defaultness: ast::Defaultness::Final, tokens: None, })), AstFragmentKind::ForeignItems => - AstFragment::ForeignItems(SmallVector::one(ast::ForeignItem { + AstFragment::ForeignItems(OneVector::one(ast::ForeignItem { id, span, ident, vis, attrs, node: ast::ForeignItemKind::Macro(mac_placeholder()), })), @@ -72,8 +73,8 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { AstFragmentKind::Ty => AstFragment::Ty(P(ast::Ty { id, span, node: ast::TyKind::Mac(mac_placeholder()), })), - AstFragmentKind::Stmts => AstFragment::Stmts(SmallVector::one({ - let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::ThinVec::new())); + AstFragmentKind::Stmts => AstFragment::Stmts(OneVector::one({ + let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ThinVec::new())); ast::Stmt { id, span, node: ast::StmtKind::Mac(mac) } })), } @@ -114,31 +115,31 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> { } impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { match item.node { ast::ItemKind::Mac(_) => return self.remove(item.id).make_items(), - ast::ItemKind::MacroDef(_) => return SmallVector::one(item), + ast::ItemKind::MacroDef(_) => return OneVector::one(item), _ => {} } noop_fold_item(item, self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { match item.node { ast::TraitItemKind::Macro(_) => self.remove(item.id).make_trait_items(), _ => noop_fold_trait_item(item, self), } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { match item.node { ast::ImplItemKind::Macro(_) => self.remove(item.id).make_impl_items(), _ => noop_fold_impl_item(item, self), } } - fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> SmallVector { + fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> OneVector { match item.node { ast::ForeignItemKind::Macro(_) => self.remove(item.id).make_foreign_items(), _ => noop_fold_foreign_item(item, self), @@ -159,7 +160,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { } } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { let (style, mut stmts) = match stmt.node { ast::StmtKind::Mac(mac) => (mac.1, self.remove(stmt.id).make_stmts()), _ => return noop_fold_stmt(stmt, self), diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 1ace4d4a880e2..bc891700fc1b6 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -34,6 +34,7 @@ pub mod rt { use parse::token::{self, Token}; use ptr::P; use symbol::Symbol; + use ThinVec; use tokenstream::{self, TokenTree, TokenStream}; @@ -274,7 +275,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(self.clone())), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }).to_tokens(cx) } } @@ -305,7 +306,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(dummy_spanned(lit))), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); if *self >= 0 { return lit.to_tokens(cx); @@ -314,7 +315,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Unary(ast::UnOp::Neg, lit), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }).to_tokens(cx) } } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 0c36c072a0302..9b7e0fe1ae55c 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -17,9 +17,9 @@ use parse::{token, DirectoryOwnership}; use parse; use print::pprust; use ptr::P; +use OneVector; use symbol::Symbol; use tokenstream; -use util::small_vector::SmallVector; use std::fs::File; use std::io::prelude::*; @@ -111,8 +111,8 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T Some(panictry!(self.p.parse_expr())) } fn make_items(mut self: Box>) - -> Option>> { - let mut ret = SmallVector::new(); + -> Option>> { + let mut ret = OneVector::new(); while self.p.token != token::Eof { match panictry!(self.p.parse_item()) { Some(item) => ret.push(item), diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 3046525b7144c..82f88d1d8643e 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -92,9 +92,9 @@ use parse::{Directory, ParseSess}; use parse::parser::{Parser, PathStyle}; use parse::token::{self, DocComment, Nonterminal, Token}; use print::pprust; +use OneVector; use symbol::keywords; use tokenstream::TokenStream; -use util::small_vector::SmallVector; use std::mem; use std::ops::{Deref, DerefMut}; @@ -440,10 +440,10 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { /// A `ParseResult`. Note that matches are kept track of through the items generated. fn inner_parse_loop<'a>( sess: &ParseSess, - cur_items: &mut SmallVector>, + cur_items: &mut OneVector>, next_items: &mut Vec>, - eof_items: &mut SmallVector>, - bb_items: &mut SmallVector>, + eof_items: &mut OneVector>, + bb_items: &mut OneVector>, token: &Token, span: syntax_pos::Span, ) -> ParseResult<()> { @@ -644,15 +644,15 @@ pub fn parse( // This MatcherPos instance is allocated on the stack. All others -- and // there are frequently *no* others! -- are allocated on the heap. let mut initial = initial_matcher_pos(ms, parser.span.lo()); - let mut cur_items = SmallVector::one(MatcherPosHandle::Ref(&mut initial)); + let mut cur_items = OneVector::one(MatcherPosHandle::Ref(&mut initial)); let mut next_items = Vec::new(); loop { // Matcher positions black-box parsed by parser.rs (`parser`) - let mut bb_items = SmallVector::new(); + let mut bb_items = OneVector::new(); // Matcher positions that would be valid if the macro invocation was over now - let mut eof_items = SmallVector::new(); + let mut eof_items = OneVector::new(); assert!(next_items.is_empty()); // Process `cur_items` until either we have finished the input or we need to get some diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 1cdb6b0e5c902..d451227e77cf3 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -15,9 +15,9 @@ use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; use ext::tt::quoted; use fold::noop_fold_tt; use parse::token::{self, Token, NtTT}; +use OneVector; use syntax_pos::{Span, DUMMY_SP}; use tokenstream::{TokenStream, TokenTree, Delimited}; -use util::small_vector::SmallVector; use std::rc::Rc; use rustc_data_structures::sync::Lrc; @@ -70,7 +70,7 @@ pub fn transcribe(cx: &ExtCtxt, interp: Option>>, src: Vec) -> TokenStream { - let mut stack = SmallVector::one(Frame::new(src)); + let mut stack = OneVector::one(Frame::new(src)); let interpolations = interp.unwrap_or_else(HashMap::new); /* just a convenience */ let mut repeats = Vec::new(); let mut result: Vec = Vec::new(); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 976708ae78816..ea65e4f8ccd0c 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -433,9 +433,6 @@ declare_features! ( // `use path as _;` and `extern crate c as _;` (active, underscore_imports, "1.26.0", Some(48216), None), - // Allows keywords to be escaped for use as identifiers - (active, raw_identifiers, "1.26.0", Some(48589), Some(Edition::Edition2018)), - // Allows macro invocations in `extern {}` blocks (active, macros_in_extern, "1.27.0", Some(49476), None), @@ -646,6 +643,8 @@ declare_features! ( (accepted, repr_transparent, "1.28.0", Some(43036), None), // Defining procedural macros in `proc-macro` crates (accepted, proc_macro, "1.29.0", Some(38356), None), + // Allows keywords to be escaped for use as identifiers + (accepted, raw_identifiers, "1.30.0", Some(48589), None), ); // If you change this, please modify src/doc/unstable-book as well. You must @@ -1862,10 +1861,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "existential types are unstable" ); } - - ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { - gate_feature_post!(&self, generic_associated_types, ii.span, - "generic associated types are unstable"); + ast::ImplItemKind::Type(_) => { + if !ii.generics.params.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "generic associated types are unstable"); + } + if !ii.generics.where_clause.predicates.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "where clauses on associated types are unstable"); + } } _ => {} } @@ -2016,16 +2020,6 @@ pub fn check_crate(krate: &ast::Crate, plugin_attributes, }; - if !features.raw_identifiers { - for &span in sess.raw_identifier_spans.borrow().iter() { - if !span.allows_unstable() { - gate_feature!(&ctx, raw_identifiers, span, - "raw identifiers are experimental and subject to change" - ); - } - } - } - let visitor = &mut PostExpansionVisitor { context: &ctx }; visitor.whole_crate_feature_gates(krate); visit::walk_crate(visitor, krate); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 9d5982c1e2861..3209939d9b14d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -24,9 +24,10 @@ use syntax_pos::Span; use codemap::{Spanned, respan}; use parse::token::{self, Token}; use ptr::P; +use OneVector; use symbol::keywords; +use ThinVec; use tokenstream::*; -use util::small_vector::SmallVector; use util::move_map::MoveMap; use rustc_data_structures::sync::Lrc; @@ -60,7 +61,7 @@ pub trait Folder : Sized { noop_fold_use_tree(use_tree, self) } - fn fold_foreign_item(&mut self, ni: ForeignItem) -> SmallVector { + fn fold_foreign_item(&mut self, ni: ForeignItem) -> OneVector { noop_fold_foreign_item(ni, self) } @@ -68,7 +69,7 @@ pub trait Folder : Sized { noop_fold_foreign_item_simple(ni, self) } - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { noop_fold_item(i, self) } @@ -88,11 +89,11 @@ pub trait Folder : Sized { noop_fold_item_kind(i, self) } - fn fold_trait_item(&mut self, i: TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, i: TraitItem) -> OneVector { noop_fold_trait_item(i, self) } - fn fold_impl_item(&mut self, i: ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, i: ImplItem) -> OneVector { noop_fold_impl_item(i, self) } @@ -108,7 +109,7 @@ pub trait Folder : Sized { noop_fold_block(b, self) } - fn fold_stmt(&mut self, s: Stmt) -> SmallVector { + fn fold_stmt(&mut self, s: Stmt) -> OneVector { noop_fold_stmt(s, self) } @@ -960,8 +961,8 @@ pub fn noop_fold_item_kind(i: ItemKind, folder: &mut T) -> ItemKind { } pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) - -> SmallVector { - SmallVector::one(TraitItem { + -> OneVector { + OneVector::one(TraitItem { id: folder.new_id(i.id), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), @@ -989,8 +990,8 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) } pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) - -> SmallVector { - SmallVector::one(ImplItem { + -> OneVector { + OneVector::one(ImplItem { id: folder.new_id(i.id), vis: folder.fold_vis(i.vis), ident: folder.fold_ident(i.ident), @@ -1065,8 +1066,8 @@ pub fn noop_fold_crate(Crate {module, attrs, span}: Crate, } // fold one item into possibly many items -pub fn noop_fold_item(i: P, folder: &mut T) -> SmallVector> { - SmallVector::one(i.map(|i| folder.fold_item_simple(i))) +pub fn noop_fold_item(i: P, folder: &mut T) -> OneVector> { + OneVector::one(i.map(|i| folder.fold_item_simple(i))) } // fold one item into exactly one item @@ -1087,8 +1088,8 @@ pub fn noop_fold_item_simple(Item {id, ident, attrs, node, vis, span, } pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) --> SmallVector { - SmallVector::one(folder.fold_foreign_item_simple(ni)) +-> OneVector { + OneVector::one(folder.fold_foreign_item_simple(ni)) } pub fn noop_fold_foreign_item_simple(ni: ForeignItem, folder: &mut T) -> ForeignItem { @@ -1366,7 +1367,7 @@ pub fn noop_fold_exprs(es: Vec>, folder: &mut T) -> Vec(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVector { +pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> OneVector { let id = folder.new_id(id); let span = folder.new_span(span); noop_fold_stmt_kind(node, folder).into_iter().map(|node| { @@ -1374,9 +1375,9 @@ pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> }).collect() } -pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> SmallVector { +pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> OneVector { match node { - StmtKind::Local(local) => SmallVector::one(StmtKind::Local(folder.fold_local(local))), + StmtKind::Local(local) => OneVector::one(StmtKind::Local(folder.fold_local(local))), StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(), StmtKind::Expr(expr) => { folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect() @@ -1384,7 +1385,7 @@ pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> SmallVe StmtKind::Semi(expr) => { folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect() } - StmtKind::Mac(mac) => SmallVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| { + StmtKind::Mac(mac) => OneVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| { (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into()) }))), } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 12ce478fe1d8b..c48ad0a802cb0 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -45,6 +45,8 @@ extern crate serialize as rustc_serialize; // used by deriving use rustc_data_structures::sync::Lock; use rustc_data_structures::bitvec::BitVector; +pub use rustc_data_structures::small_vec::OneVector; +pub use rustc_data_structures::thin_vec::ThinVec; use ast::AttrId; // A variant of 'try!' that panics on an Err. This is used as a crutch on the @@ -124,12 +126,8 @@ pub mod util { pub mod parser; #[cfg(test)] pub mod parser_testing; - pub mod small_vector; pub mod move_map; - mod thin_vec; - pub use self::thin_vec::ThinVec; - mod rc_slice; pub use self::rc_slice::RcSlice; } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 20a585b6601a5..2c53dbdc402a5 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -63,6 +63,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { if !lines.is_empty() && lines[0].chars().all(|c| c == '*') { i += 1; } + while i < j && lines[i].trim().is_empty() { i += 1; } @@ -74,9 +75,11 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { .all(|c| c == '*') { j -= 1; } + while j > i && lines[j - 1].trim().is_empty() { j -= 1; } + lines[i..j].to_vec() } @@ -85,6 +88,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut i = usize::MAX; let mut can_trim = true; let mut first = true; + for line in &lines { for (j, c) in line.chars().enumerate() { if j > i || !"* \t".contains(c) { @@ -119,7 +123,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { } // one-line comments lose their prefix - const ONELINERS: &'static [&'static str] = &["///!", "///", "//!", "//"]; + const ONELINERS: &[&str] = &["///!", "///", "//!", "//"]; + for prefix in ONELINERS { if comment.starts_with(*prefix) { return (&comment[prefix.len()..]).to_string(); @@ -205,6 +210,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option { let len = s.len(); let mut col = col.to_usize(); let mut cursor: usize = 0; + while col > 0 && cursor < len { let ch = char_at(s, cursor); if !ch.is_whitespace() { @@ -213,7 +219,8 @@ fn all_whitespace(s: &str, col: CharPos) -> Option { cursor += ch.len_utf8(); col -= 1; } - return Some(cursor); + + Some(cursor) } fn trim_whitespace_prefix_and_push_line(lines: &mut Vec, s: String, col: CharPos) { @@ -246,11 +253,13 @@ fn read_block_comment(rdr: &mut StringReader, "src_index={}, end_src_index={}, line_begin_pos={}", src_index, end_src_index, rdr.filemap.line_begin_pos(rdr.pos).to_u32()); let mut n = 0; + while src_index < end_src_index { let c = char_at(&rdr.src, src_index); src_index += c.len_utf8(); n += 1; } + let col = CharPos(n); rdr.bump(); @@ -358,10 +367,10 @@ pub struct Literal { // it appears this function is called only from pprust... that's // probably not a good thing. pub fn gather_comments_and_literals(sess: &ParseSess, path: FileName, srdr: &mut dyn Read) - -> (Vec, Vec) { - let mut src = Vec::new(); - srdr.read_to_end(&mut src).unwrap(); - let src = String::from_utf8(src).unwrap(); + -> (Vec, Vec) +{ + let mut src = String::new(); + srdr.read_to_string(&mut src).unwrap(); let cm = CodeMap::new(sess.codemap().path_mapping().clone()); let filemap = cm.new_filemap(path, src); let mut rdr = lexer::StringReader::new_raw(sess, filemap, None); @@ -370,6 +379,7 @@ pub fn gather_comments_and_literals(sess: &ParseSess, path: FileName, srdr: &mut let mut literals: Vec = Vec::new(); let mut code_to_the_left = false; // Only code let mut anything_to_the_left = false; // Code or comments + while !rdr.is_eof() { loop { // Eat all the whitespace and count blank lines. diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index f9b9e95ead1b6..5913c63bfaa5f 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -73,23 +73,23 @@ impl<'a> StringReader<'a> { fn mk_sp(&self, lo: BytePos, hi: BytePos) -> Span { self.mk_sp_and_raw(lo, hi).0 } + fn mk_sp_and_raw(&self, lo: BytePos, hi: BytePos) -> (Span, Span) { let raw = Span::new(lo, hi, NO_EXPANSION); - let real = unwrap_or!(self.override_span, raw); + let real = self.override_span.unwrap_or(raw); + (real, raw) } + fn mk_ident(&self, string: &str) -> Ident { let mut ident = Ident::from_str(string); if let Some(span) = self.override_span { ident.span = span; } + ident } - fn next_token(&mut self) -> TokenAndSpan where Self: Sized { - let res = self.try_next_token(); - self.unwrap_or_abort(res) - } fn unwrap_or_abort(&mut self, res: Result) -> TokenAndSpan { match res { Ok(tok) => tok, @@ -99,6 +99,25 @@ impl<'a> StringReader<'a> { } } } + + fn next_token(&mut self) -> TokenAndSpan where Self: Sized { + let res = self.try_next_token(); + self.unwrap_or_abort(res) + } + + /// Return the next token. EFFECT: advances the string_reader. + pub fn try_next_token(&mut self) -> Result { + assert!(self.fatal_errs.is_empty()); + let ret_val = TokenAndSpan { + tok: replace(&mut self.peek_tok, token::Whitespace), + sp: self.peek_span, + }; + self.advance_token()?; + self.span_src_raw = self.peek_span_src_raw; + + Ok(ret_val) + } + fn try_real_token(&mut self) -> Result { let mut t = self.try_next_token()?; loop { @@ -109,36 +128,32 @@ impl<'a> StringReader<'a> { _ => break, } } + self.token = t.tok.clone(); self.span = t.sp; + Ok(t) } + pub fn real_token(&mut self) -> TokenAndSpan { let res = self.try_real_token(); self.unwrap_or_abort(res) } + + #[inline] fn is_eof(&self) -> bool { self.ch.is_none() } - /// Return the next token. EFFECT: advances the string_reader. - pub fn try_next_token(&mut self) -> Result { - assert!(self.fatal_errs.is_empty()); - let ret_val = TokenAndSpan { - tok: replace(&mut self.peek_tok, token::Whitespace), - sp: self.peek_span, - }; - self.advance_token()?; - self.span_src_raw = self.peek_span_src_raw; - Ok(ret_val) - } fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: u16) { let mut err = self.struct_span_fatal(pos, pos, "unterminated raw string"); err.span_label(self.mk_sp(pos, pos), "unterminated raw string"); + if hash_count > 0 { err.note(&format!("this raw string should be terminated with `\"{}`", "#".repeat(hash_count as usize))); } + err.emit(); FatalError.raise(); } @@ -146,12 +161,15 @@ impl<'a> StringReader<'a> { fn fatal(&self, m: &str) -> FatalError { self.fatal_span(self.peek_span, m) } + pub fn emit_fatal_errors(&mut self) { for err in &mut self.fatal_errs { err.emit(); } + self.fatal_errs.clear(); } + pub fn peek(&self) -> TokenAndSpan { // FIXME(pcwalton): Bad copy! TokenAndSpan { @@ -161,15 +179,18 @@ impl<'a> StringReader<'a> { } /// For comments.rs, which hackily pokes into next_pos and ch - fn new_raw(sess: &'a ParseSess, filemap: Lrc, - override_span: Option) -> Self { + fn new_raw(sess: &'a ParseSess, filemap: Lrc, override_span: Option) + -> Self + { let mut sr = StringReader::new_raw_internal(sess, filemap, override_span); sr.bump(); + sr } fn new_raw_internal(sess: &'a ParseSess, filemap: Lrc, - override_span: Option) -> Self { + override_span: Option) -> Self + { if filemap.src.is_none() { sess.span_diagnostic.bug(&format!("Cannot lex filemap without source: {}", filemap.name)); @@ -199,12 +220,14 @@ impl<'a> StringReader<'a> { } pub fn new(sess: &'a ParseSess, filemap: Lrc, override_span: Option) - -> Self { + -> Self + { let mut sr = StringReader::new_raw(sess, filemap, override_span); if sr.advance_token().is_err() { sr.emit_fatal_errors(); FatalError.raise(); } + sr } @@ -229,9 +252,11 @@ impl<'a> StringReader<'a> { sr.emit_fatal_errors(); FatalError.raise(); } + sr } + #[inline] fn ch_is(&self, c: char) -> bool { self.ch == Some(c) } @@ -276,26 +301,23 @@ impl<'a> StringReader<'a> { let mut m = m.to_string(); m.push_str(": "); Self::push_escaped_char_for_msg(&mut m, c); + self.fatal_span_(from_pos, to_pos, &m[..]) } - fn struct_span_fatal(&self, - from_pos: BytePos, - to_pos: BytePos, - m: &str) - -> DiagnosticBuilder<'a> { + fn struct_span_fatal(&self, from_pos: BytePos, to_pos: BytePos, m: &str) + -> DiagnosticBuilder<'a> + { self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), m) } - fn struct_fatal_span_char(&self, - from_pos: BytePos, - to_pos: BytePos, - m: &str, - c: char) - -> DiagnosticBuilder<'a> { + fn struct_fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) + -> DiagnosticBuilder<'a> + { let mut m = m.to_string(); m.push_str(": "); Self::push_escaped_char_for_msg(&mut m, c); + self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), &m[..]) } @@ -307,15 +329,14 @@ impl<'a> StringReader<'a> { Self::push_escaped_char_for_msg(&mut m, c); self.err_span_(from_pos, to_pos, &m[..]); } - fn struct_err_span_char(&self, - from_pos: BytePos, - to_pos: BytePos, - m: &str, - c: char) - -> DiagnosticBuilder<'a> { + + fn struct_err_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) + -> DiagnosticBuilder<'a> + { let mut m = m.to_string(); m.push_str(": "); Self::push_escaped_char_for_msg(&mut m, c); + self.sess.span_diagnostic.struct_span_err(self.mk_sp(from_pos, to_pos), &m[..]) } @@ -324,6 +345,7 @@ impl<'a> StringReader<'a> { fn fatal_span_verbose(&self, from_pos: BytePos, to_pos: BytePos, mut m: String) -> FatalError { m.push_str(": "); m.push_str(&self.src[self.src_index(from_pos)..self.src_index(to_pos)]); + self.fatal_span_(from_pos, to_pos, &m[..]) } @@ -354,6 +376,7 @@ impl<'a> StringReader<'a> { }; } } + Ok(()) } @@ -468,6 +491,7 @@ impl<'a> StringReader<'a> { } } + #[inline] fn nextch_is(&self, c: char) -> bool { self.nextch() == Some(c) } @@ -484,6 +508,7 @@ impl<'a> StringReader<'a> { None } + #[inline] fn nextnextch_is(&self, c: char) -> bool { self.nextnextch() == Some(c) } @@ -493,8 +518,10 @@ impl<'a> StringReader<'a> { if !ident_start(self.ch) { return None; } + let start = self.pos; self.bump(); + while ident_continue(self.ch) { self.bump(); } @@ -709,6 +736,7 @@ impl<'a> StringReader<'a> { fn scan_digits(&mut self, real_radix: u32, scan_radix: u32) -> usize { assert!(real_radix <= scan_radix); let mut len = 0; + loop { let c = self.ch; if c == Some('_') { @@ -736,31 +764,29 @@ impl<'a> StringReader<'a> { /// Lex a LIT_INTEGER or a LIT_FLOAT fn scan_number(&mut self, c: char) -> token::Lit { - let num_digits; let mut base = 10; let start_bpos = self.pos; - self.bump(); - if c == '0' { + let num_digits = if c == '0' { match self.ch.unwrap_or('\0') { 'b' => { self.bump(); base = 2; - num_digits = self.scan_digits(2, 10); + self.scan_digits(2, 10) } 'o' => { self.bump(); base = 8; - num_digits = self.scan_digits(8, 10); + self.scan_digits(8, 10) } 'x' => { self.bump(); base = 16; - num_digits = self.scan_digits(16, 16); + self.scan_digits(16, 16) } '0'..='9' | '_' | '.' | 'e' | 'E' => { - num_digits = self.scan_digits(10, 10) + 1; + self.scan_digits(10, 10) + 1 } _ => { // just a 0 @@ -768,15 +794,14 @@ impl<'a> StringReader<'a> { } } } else if c.is_digit(10) { - num_digits = self.scan_digits(10, 10) + 1; + self.scan_digits(10, 10) + 1 } else { - num_digits = 0; - } + 0 + }; if num_digits == 0 { - self.err_span_(start_bpos, - self.pos, - "no valid digits found for number"); + self.err_span_(start_bpos, self.pos, "no valid digits found for number"); + return token::Integer(Symbol::intern("0")); } @@ -794,6 +819,7 @@ impl<'a> StringReader<'a> { } let pos = self.pos; self.check_float_base(start_bpos, pos, base); + token::Float(self.name_from(start_bpos)) } else { // it might be a float if it has an exponent @@ -873,7 +899,8 @@ impl<'a> StringReader<'a> { first_source_char: char, ascii_only: bool, delim: char) - -> bool { + -> bool + { match first_source_char { '\\' => { // '\X' for some X must be a character constant: @@ -1008,6 +1035,7 @@ impl<'a> StringReader<'a> { "overlong unicode escape (must have at most 6 hex digits)"); valid = false; } + loop { match self.ch { Some('}') => { @@ -1043,6 +1071,7 @@ impl<'a> StringReader<'a> { } self.bump(); } + valid } @@ -1050,9 +1079,11 @@ impl<'a> StringReader<'a> { fn scan_float_exponent(&mut self) { if self.ch_is('e') || self.ch_is('E') { self.bump(); + if self.ch_is('-') || self.ch_is('+') { self.bump(); } + if self.scan_digits(10, 10) == 0 { let mut err = self.struct_span_fatal( self.pos, self.next_pos, @@ -1125,6 +1156,7 @@ impl<'a> StringReader<'a> { ('b', Some('r'), Some('#')) => (false, false), _ => (true, false), }; + if is_ident_start { let raw_start = self.pos; if is_raw_ident { @@ -1135,6 +1167,7 @@ impl<'a> StringReader<'a> { let start = self.pos; self.bump(); + while ident_continue(self.ch) { self.bump(); } @@ -1142,16 +1175,19 @@ impl<'a> StringReader<'a> { return Ok(self.with_str_from(start, |string| { // FIXME: perform NFKC normalization here. (Issue #2253) let ident = self.mk_ident(string); + if is_raw_ident && (ident.is_path_segment_keyword() || ident.name == keywords::Underscore.name()) { self.fatal_span_(raw_start, self.pos, &format!("`r#{}` is not currently supported.", ident.name) ).raise(); } + if is_raw_ident { let span = self.mk_sp(raw_start, self.pos); self.sess.raw_identifier_spans.borrow_mut().push(span); } + token::Ident(ident, is_raw_ident) })); } @@ -1337,14 +1373,11 @@ impl<'a> StringReader<'a> { return Ok(token::Lifetime(ident)); } - let valid = self.scan_char_or_byte(start, - c2, - // ascii_only = - false, - '\''); + let valid = self.scan_char_or_byte(start, c2, /* ascii_only */ false, '\''); if !self.ch_is('\'') { let pos = self.pos; + loop { self.bump(); if self.ch_is('\'') { @@ -1370,6 +1403,7 @@ impl<'a> StringReader<'a> { break; } } + self.fatal_span_verbose(start_with_quote, pos, String::from("character literal may only contain one codepoint")).raise(); } @@ -1379,8 +1413,10 @@ impl<'a> StringReader<'a> { } else { Symbol::intern("0") }; + self.bump(); // advance ch past token let suffix = self.scan_optional_raw_name(); + Ok(token::Literal(token::Char(id), suffix)) } 'b' => { @@ -1392,12 +1428,14 @@ impl<'a> StringReader<'a> { _ => unreachable!(), // Should have been a token::Ident above. }; let suffix = self.scan_optional_raw_name(); + Ok(token::Literal(lit, suffix)) } '"' => { let start_bpos = self.pos; let mut valid = true; self.bump(); + while !self.ch_is('"') { if self.is_eof() { let last_bpos = self.pos; @@ -1409,11 +1447,7 @@ impl<'a> StringReader<'a> { let ch_start = self.pos; let ch = self.ch.unwrap(); self.bump(); - valid &= self.scan_char_or_byte(ch_start, - ch, - // ascii_only = - false, - '"'); + valid &= self.scan_char_or_byte(ch_start, ch, /* ascii_only */ false, '"'); } // adjust for the ASCII " at the start of the literal let id = if valid { @@ -1423,6 +1457,7 @@ impl<'a> StringReader<'a> { }; self.bump(); let suffix = self.scan_optional_raw_name(); + Ok(token::Literal(token::Str_(id), suffix)) } 'r' => { @@ -1492,6 +1527,7 @@ impl<'a> StringReader<'a> { } self.bump(); } + self.bump(); let id = if valid { self.name_from_to(content_start_bpos, content_end_bpos) @@ -1499,6 +1535,7 @@ impl<'a> StringReader<'a> { Symbol::intern("??") }; let suffix = self.scan_optional_raw_name(); + Ok(token::Literal(token::StrRaw(id, hash_count), suffix)) } '-' => { @@ -1555,6 +1592,7 @@ impl<'a> StringReader<'a> { c); unicode_chars::check_for_substitution(self, c, &mut err); self.fatal_errs.push(err); + Err(()) } } @@ -1572,9 +1610,11 @@ impl<'a> StringReader<'a> { val.push(self.ch.unwrap()); self.bump(); } + if self.ch_is('\n') { self.bump(); } + val } @@ -1626,9 +1666,11 @@ impl<'a> StringReader<'a> { Symbol::intern("?") }; self.bump(); // advance ch past token + token::Byte(id) } + #[inline] fn scan_byte_escape(&mut self, delim: char, below_0x7f_only: bool) -> bool { self.scan_hex_digits(2, delim, below_0x7f_only) } @@ -1653,12 +1695,14 @@ impl<'a> StringReader<'a> { true, '"'); } + let id = if valid { self.name_from(start) } else { Symbol::intern("??") }; self.bump(); + token::ByteStr(id) } @@ -1716,25 +1760,26 @@ impl<'a> StringReader<'a> { } self.bump(); } + self.bump(); - token::ByteStrRaw(self.name_from_to(content_start_bpos, content_end_bpos), - hash_count) + + token::ByteStrRaw(self.name_from_to(content_start_bpos, content_end_bpos), hash_count) } } // This tests the character for the unicode property 'PATTERN_WHITE_SPACE' which // is guaranteed to be forward compatible. http://unicode.org/reports/tr31/#R3 +#[inline] crate fn is_pattern_whitespace(c: Option) -> bool { c.map_or(false, Pattern_White_Space) } +#[inline] fn in_range(c: Option, lo: char, hi: char) -> bool { - match c { - Some(c) => lo <= c && c <= hi, - _ => false, - } + c.map_or(false, |c| lo <= c && c <= hi) } +#[inline] fn is_dec_digit(c: Option) -> bool { in_range(c, '0', '9') } diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index 36c220fa0d943..1e7855e68ddc6 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -17,9 +17,11 @@ impl<'a> StringReader<'a> { // Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`. crate fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> { let mut tts = Vec::new(); + while self.token != token::Eof { tts.push(self.parse_token_tree()?); } + Ok(TokenStream::concat(tts)) } @@ -30,6 +32,7 @@ impl<'a> StringReader<'a> { if let token::CloseDelim(..) = self.token { return TokenStream::concat(tts); } + match self.parse_token_tree() { Ok(tree) => tts.push(tree), Err(mut e) => { @@ -48,6 +51,7 @@ impl<'a> StringReader<'a> { for &(_, sp) in &self.open_braces { err.span_help(sp, "did you mean to close this delimiter?"); } + Err(err) }, token::OpenDelim(delim) => { @@ -129,6 +133,7 @@ impl<'a> StringReader<'a> { let raw = self.span_src_raw; self.real_token(); let is_joint = raw.hi() == self.span_src_raw.lo() && token::is_op(&self.token); + Ok(if is_joint { tt.joint() } else { tt.into() }) } } diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index a32b515672eca..88ff8582da801 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -15,7 +15,7 @@ use syntax_pos::{Span, NO_EXPANSION}; use errors::DiagnosticBuilder; use super::StringReader; -const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ +const UNICODE_ARRAY: &[(char, &str, char)] = &[ ('
', "Line Separator", ' '), ('
', "Paragraph Separator", ' '), (' ', "Ogham Space mark", ' '), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 746e03d771a88..0e45cacaf38c9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -53,9 +53,9 @@ use util::parser::{AssocOp, Fixity}; use print::pprust; use ptr::P; use parse::PResult; +use ThinVec; use tokenstream::{self, Delimited, ThinTokenStream, TokenTree, TokenStream}; use symbol::{Symbol, keywords}; -use util::ThinVec; use std::borrow::Cow; use std::cmp; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 62dd00387d3ab..1cbaf3cc312b7 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -38,8 +38,9 @@ use parse::{token, ParseSess}; use print::pprust; use ast::{self, Ident}; use ptr::P; +use OneVector; use symbol::{self, Symbol, keywords}; -use util::small_vector::SmallVector; +use ThinVec; enum ShouldPanic { No, @@ -115,7 +116,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { folded } - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { let ident = i.ident; if ident.name != keywords::Invalid.name() { self.cx.path.push(ident); @@ -182,7 +183,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { if ident.name != keywords::Invalid.name() { self.cx.path.pop(); } - SmallVector::one(P(item)) + OneVector::one(P(item)) } fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac } @@ -194,7 +195,7 @@ struct EntryPointCleaner { } impl fold::Folder for EntryPointCleaner { - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { self.depth += 1; let folded = fold::noop_fold_item(i, self).expect_one("noop did something"); self.depth -= 1; @@ -234,7 +235,7 @@ impl fold::Folder for EntryPointCleaner { EntryPointType::OtherMain => folded, }; - SmallVector::one(folded) + OneVector::one(folded) } fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac } @@ -675,10 +676,10 @@ fn mk_test_descs(cx: &TestCtxt) -> P { mk_test_desc_and_fn_rec(cx, test) }).collect()), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/move_map.rs index 8cc37afa354ff..eb2c5a2458c15 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/move_map.rs @@ -9,8 +9,7 @@ // except according to those terms. use std::ptr; - -use util::small_vector::SmallVector; +use OneVector; pub trait MoveMap: Sized { fn move_map(self, mut f: F) -> Self where F: FnMut(T) -> T { @@ -78,7 +77,7 @@ impl MoveMap for ::ptr::P<[T]> { } } -impl MoveMap for SmallVector { +impl MoveMap for OneVector { fn move_flat_map(mut self, mut f: F) -> Self where F: FnMut(T) -> I, I: IntoIterator diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs deleted file mode 100644 index 31e675836fc72..0000000000000 --- a/src/libsyntax/util/small_vector.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rustc_data_structures::small_vec::SmallVec; - -pub type SmallVector = SmallVec<[T; 1]>; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_len() { - let v: SmallVector = SmallVector::new(); - assert_eq!(0, v.len()); - - assert_eq!(1, SmallVector::one(1).len()); - assert_eq!(5, SmallVector::many(vec![1, 2, 3, 4, 5]).len()); - } - - #[test] - fn test_push_get() { - let mut v = SmallVector::new(); - v.push(1); - assert_eq!(1, v.len()); - assert_eq!(1, v[0]); - v.push(2); - assert_eq!(2, v.len()); - assert_eq!(2, v[1]); - v.push(3); - assert_eq!(3, v.len()); - assert_eq!(3, v[2]); - } - - #[test] - fn test_from_iter() { - let v: SmallVector = (vec![1, 2, 3]).into_iter().collect(); - assert_eq!(3, v.len()); - assert_eq!(1, v[0]); - assert_eq!(2, v[1]); - assert_eq!(3, v[2]); - } - - #[test] - fn test_move_iter() { - let v = SmallVector::new(); - let v: Vec = v.into_iter().collect(); - assert_eq!(v, Vec::new()); - - let v = SmallVector::one(1); - assert_eq!(v.into_iter().collect::>(), [1]); - - let v = SmallVector::many(vec![1, 2, 3]); - assert_eq!(v.into_iter().collect::>(), [1, 2, 3]); - } - - #[test] - #[should_panic] - fn test_expect_one_zero() { - let _: isize = SmallVector::new().expect_one(""); - } - - #[test] - #[should_panic] - fn test_expect_one_many() { - SmallVector::many(vec![1, 2]).expect_one(""); - } - - #[test] - fn test_expect_one_one() { - assert_eq!(1, SmallVector::one(1).expect_one("")); - assert_eq!(1, SmallVector::many(vec![1]).expect_one("")); - } -} diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 4ebb1fcb65393..026ddccd7be97 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -12,6 +12,8 @@ // use self::State::*; +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast; use syntax::ext::base; use syntax::ext::base::*; @@ -263,6 +265,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, ctxt: cx.backtrace(), })), span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index a3c5c3df66e4c..c8cc11e43545a 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast; use syntax::ext::base::*; use syntax::ext::base; @@ -68,7 +70,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path::from_ident(self.ident)), span: self.ident.span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })) } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index c2a7dea331673..df9c351ef1c95 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -12,6 +12,8 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast::{self, Ident}; use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; @@ -139,7 +141,7 @@ fn stmt_let_undescore(cx: &mut ExtCtxt, sp: Span, expr: P) -> ast::St init: Some(expr), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index f5e607fc23d22..2e0ba65dc6509 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -191,6 +191,7 @@ use std::cell::RefCell; use std::iter; use std::vec; +use rustc_data_structures::thin_vec::ThinVec; use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; @@ -1624,7 +1625,7 @@ impl<'a> TraitDef<'a> { ident: ident.unwrap(), pat, is_shorthand: false, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }, } }) diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 40ecd6e1519c3..7290b701e4dec 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -18,6 +18,8 @@ /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats /// therefore apply. +use rustc_data_structures::small_vec::OneVector; + use syntax::ast; use syntax::codemap::respan; use syntax::ext::base; @@ -28,8 +30,6 @@ use syntax::symbol::Symbol; use syntax_pos::Span; use syntax::tokenstream; -use syntax::util::small_vector::SmallVector; - pub const MACRO: &'static str = "global_asm"; pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, @@ -52,7 +52,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, None => return DummyResult::any(sp), }; - MacEager::items(SmallVector::one(P(ast::Item { + MacEager::items(OneVector::one(P(ast::Item { ident: ast::Ident::with_empty_ctxt(Symbol::intern("")), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index 51e0fa315f435..adfc7078ebacb 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -60,8 +60,8 @@ impl error::Error for Error { fn cause(&self) -> Option<&dyn error::Error> { use self::Error::*; - match self { - &IoError(ref e) => Some(e), + match *self { + IoError(ref e) => Some(e), _ => None, } } @@ -70,10 +70,10 @@ impl error::Error for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::Error::*; - match self { - &TermUnset => Ok(()), - &MalformedTerminfo(ref e) => e.fmt(f), - &IoError(ref e) => e.fmt(f), + match *self { + TermUnset => Ok(()), + MalformedTerminfo(ref e) => e.fmt(f), + IoError(ref e) => e.fmt(f), } } } @@ -109,9 +109,9 @@ impl TermInfo { } // Keep the metadata small fn _from_path(path: &Path) -> Result { - let file = File::open(path).map_err(|e| Error::IoError(e))?; + let file = File::open(path).map_err(Error::IoError)?; let mut reader = BufReader::new(file); - parse(&mut reader, false).map_err(|e| Error::MalformedTerminfo(e)) + parse(&mut reader, false).map_err(Error::MalformedTerminfo) } } diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index b720d55594fd1..31e1b18485ca4 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -12,8 +12,6 @@ use self::Param::*; use self::States::*; -use self::FormatState::*; -use self::FormatOp::*; use std::iter::repeat; @@ -36,9 +34,9 @@ enum States { #[derive(Copy, PartialEq, Clone)] enum FormatState { - FormatStateFlags, - FormatStateWidth, - FormatStatePrecision, + Flags, + Width, + Precision, } /// Types of parameters a capability can use @@ -210,22 +208,22 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result { let mut flags = Flags::new(); - let mut fstate = FormatStateFlags; + let mut fstate = FormatState::Flags; match cur { ':' => (), '#' => flags.alternate = true, ' ' => flags.space = true, - '.' => fstate = FormatStatePrecision, + '.' => fstate = FormatState::Precision, '0'..='9' => { flags.width = cur as usize - '0' as usize; - fstate = FormatStateWidth; + fstate = FormatState::Width; } _ => unreachable!(), } @@ -318,43 +316,43 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result { if let Some(arg) = stack.pop() { let res = format(arg, FormatOp::from_char(cur), *flags)?; - output.extend(res.iter().map(|x| *x)); + output.extend(res.iter().cloned()); // will cause state to go to Nothing old_state = FormatPattern(*flags, *fstate); } else { return Err("stack is empty".to_string()); } } - (FormatStateFlags, '#') => { + (FormatState::Flags, '#') => { flags.alternate = true; } - (FormatStateFlags, '-') => { + (FormatState::Flags, '-') => { flags.left = true; } - (FormatStateFlags, '+') => { + (FormatState::Flags, '+') => { flags.sign = true; } - (FormatStateFlags, ' ') => { + (FormatState::Flags, ' ') => { flags.space = true; } - (FormatStateFlags, '0'..='9') => { + (FormatState::Flags, '0'..='9') => { flags.width = cur as usize - '0' as usize; - *fstate = FormatStateWidth; + *fstate = FormatState::Width; } - (FormatStateFlags, '.') => { - *fstate = FormatStatePrecision; + (FormatState::Flags, '.') => { + *fstate = FormatState::Precision; } - (FormatStateWidth, '0'..='9') => { + (FormatState::Width, '0'..='9') => { let old = flags.width; flags.width = flags.width * 10 + (cur as usize - '0' as usize); if flags.width < old { return Err("format width overflow".to_string()); } } - (FormatStateWidth, '.') => { - *fstate = FormatStatePrecision; + (FormatState::Width, '.') => { + *fstate = FormatState::Precision; } - (FormatStatePrecision, '0'..='9') => { + (FormatState::Precision, '0'..='9') => { let old = flags.precision; flags.precision = flags.precision * 10 + (cur as usize - '0' as usize); if flags.precision < old { @@ -437,31 +435,31 @@ impl Flags { #[derive(Copy, Clone)] enum FormatOp { - FormatDigit, - FormatOctal, - FormatHex, - FormatHEX, - FormatString, + Digit, + Octal, + LowerHex, + UpperHex, + String, } impl FormatOp { fn from_char(c: char) -> FormatOp { match c { - 'd' => FormatDigit, - 'o' => FormatOctal, - 'x' => FormatHex, - 'X' => FormatHEX, - 's' => FormatString, + 'd' => FormatOp::Digit, + 'o' => FormatOp::Octal, + 'x' => FormatOp::LowerHex, + 'X' => FormatOp::UpperHex, + 's' => FormatOp::String, _ => panic!("bad FormatOp char"), } } fn to_char(self) -> char { match self { - FormatDigit => 'd', - FormatOctal => 'o', - FormatHex => 'x', - FormatHEX => 'X', - FormatString => 's', + FormatOp::Digit => 'd', + FormatOp::Octal => 'o', + FormatOp::LowerHex => 'x', + FormatOp::UpperHex => 'X', + FormatOp::String => 's', } } } @@ -470,7 +468,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result, String> { let mut s = match val { Number(d) => { match op { - FormatDigit => { + FormatOp::Digit => { if flags.sign { format!("{:+01$}", d, flags.precision) } else if d < 0 { @@ -482,7 +480,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result, String> { format!("{:01$}", d, flags.precision) } } - FormatOctal => { + FormatOp::Octal => { if flags.alternate { // Leading octal zero counts against precision. format!("0{:01$o}", d, flags.precision.saturating_sub(1)) @@ -490,27 +488,27 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result, String> { format!("{:01$o}", d, flags.precision) } } - FormatHex => { + FormatOp::LowerHex => { if flags.alternate && d != 0 { format!("0x{:01$x}", d, flags.precision) } else { format!("{:01$x}", d, flags.precision) } } - FormatHEX => { + FormatOp::UpperHex => { if flags.alternate && d != 0 { format!("0X{:01$X}", d, flags.precision) } else { format!("{:01$X}", d, flags.precision) } } - FormatString => return Err("non-number on stack with %s".to_string()), + FormatOp::String => return Err("non-number on stack with %s".to_string()), } .into_bytes() } Words(s) => { match op { - FormatString => { + FormatOp::String => { let mut s = s.into_bytes(); if flags.precision > 0 && flags.precision < s.len() { s.truncate(flags.precision); diff --git a/src/libterm/win.rs b/src/libterm/win.rs index d36b182710b97..e0b60eead497a 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -198,11 +198,11 @@ impl Terminal for WinConsole { Ok(true) } - fn get_ref<'a>(&'a self) -> &'a T { + fn get_ref(&self) -> &T { &self.buf } - fn get_mut<'a>(&'a mut self) -> &'a mut T { + fn get_mut(&mut self) -> &mut T { &mut self.buf } diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 7305dc71cbf63..d9fbd494ab348 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -366,7 +366,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( bool PositionIndependentExecutable, bool FunctionSections, bool DataSections, bool TrapUnreachable, - bool Singlethread) { + bool Singlethread, + bool AsmComments) { auto OptLevel = fromRust(RustOptLevel); auto RM = fromRust(RustReloc); @@ -393,6 +394,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( } Options.DataSections = DataSections; Options.FunctionSections = FunctionSections; + Options.MCOptions.AsmVerbose = AsmComments; + Options.MCOptions.PreserveAsmComments = AsmComments; if (TrapUnreachable) { // Tell LLVM to codegen `unreachable` into an explicit trap instruction. diff --git a/src/test/debuginfo/by-value-non-immediate-argument.rs b/src/test/debuginfo/by-value-non-immediate-argument.rs index 9007b44296bcc..86034b221cf12 100644 --- a/src/test/debuginfo/by-value-non-immediate-argument.rs +++ b/src/test/debuginfo/by-value-non-immediate-argument.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-windows // ignore-tidy-linelength -// ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155 // min-lldb-version: 310 // compile-flags:-g diff --git a/src/test/debuginfo/function-arg-initialization.rs b/src/test/debuginfo/function-arg-initialization.rs index 90088a0297aa8..953a468d046de 100644 --- a/src/test/debuginfo/function-arg-initialization.rs +++ b/src/test/debuginfo/function-arg-initialization.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-windows // ignore-tidy-linelength -// ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155 // min-lldb-version: 310 // This test case checks if function arguments already have the correct value diff --git a/src/test/debuginfo/function-prologue-stepping-regular.rs b/src/test/debuginfo/function-prologue-stepping-regular.rs index d50d105e009ff..529a8cd635a92 100644 --- a/src/test/debuginfo/function-prologue-stepping-regular.rs +++ b/src/test/debuginfo/function-prologue-stepping-regular.rs @@ -13,7 +13,6 @@ // min-lldb-version: 310 // ignore-gdb -// ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155 // compile-flags:-g // lldb-command:breakpoint set --name immediate_args diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 7bc566480e763..d26e7b8a4c81b 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -10,7 +10,6 @@ // ignore-windows failing on win32 bot // ignore-freebsd: gdb package too new -// ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155 // ignore-android: FIXME(#10381) // compile-flags:-g // min-gdb-version 7.7 @@ -40,14 +39,15 @@ // gdbr-check:$6 = core::option::Option::None // gdb-command: print os_string -// gdb-check:$7 = "IAMA OS string 😃" +// gdb-check:$7 = "IAMA OS string" -// gdb-command: print some_string -// gdb-check:$8 = Some = {"IAMA optional string!"} +// Disabled due to https://github.com/rust-lang/rust/issues/53153 +// g d b-command: print some_string +// g d b-check:$8 = Some = {"IAMA optional string!"} -// gdb-command: set print length 5 -// gdb-command: print some_string -// gdb-check:$8 = Some = {"IAMA "...} +// g d b-command: set print length 5 +// g d b-command: print some_string +// g d b-check:$8 = Some = {"IAMA "...} // === LLDB TESTS ================================================================================== @@ -92,7 +92,7 @@ fn main() { let string = "IAMA string!".to_string(); // OsString - let os_string = OsString::from("IAMA OS string \u{1F603}"); + let os_string = OsString::from("IAMA OS string"); // Option let some = Some(8i16); diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs index 7f8a741465b30..ff5d9a59bfa00 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs @@ -15,12 +15,12 @@ extern crate syntax; extern crate rustc; +extern crate rustc_data_structures; extern crate rustc_plugin; extern crate syntax_pos; -use syntax::ast; +use rustc_data_structures::small_vec::OneVector; use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; -use syntax::util::small_vector::SmallVector; use syntax::tokenstream; use rustc_plugin::Registry; @@ -31,7 +31,7 @@ pub fn plugin_registrar(reg: &mut Registry) { fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree]) -> Box { - MacEager::items(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ quote_item!(cx, struct Struct1;).unwrap(), quote_item!(cx, struct Struct2;).unwrap() ])) diff --git a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs index bbd81e790b838..3da50f1696545 100644 --- a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs @@ -30,8 +30,10 @@ #![feature(rustc_private)] +extern crate rustc_data_structures; extern crate syntax; +use rustc_data_structures::thin_vec::ThinVec; use syntax::ast::*; use syntax::codemap::{Spanned, DUMMY_SP, FileName}; use syntax::codemap::FilePathMapping; @@ -39,7 +41,6 @@ use syntax::fold::{self, Folder}; use syntax::parse::{self, ParseSess}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::util::ThinVec; fn parse_expr(ps: &ParseSess, src: &str) -> P { diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs index 69952e9f90af6..f8ed2c7f432eb 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs @@ -10,8 +10,6 @@ // edition:2015 -#![feature(raw_identifiers)] - #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) diff --git a/src/test/run-pass/edition-keywords-2015-2015.rs b/src/test/run-pass/edition-keywords-2015-2015.rs index 73869e63de7c4..1751eacc6b7ce 100644 --- a/src/test/run-pass/edition-keywords-2015-2015.rs +++ b/src/test/run-pass/edition-keywords-2015-2015.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2015.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/run-pass/edition-keywords-2015-2018.rs b/src/test/run-pass/edition-keywords-2015-2018.rs index 0a1c6505854c9..f2794a4b8d81a 100644 --- a/src/test/run-pass/edition-keywords-2015-2018.rs +++ b/src/test/run-pass/edition-keywords-2015-2018.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/ui/feature-gate-raw-identifiers.rs b/src/test/run-pass/env-null-vars.rs similarity index 60% rename from src/test/ui/feature-gate-raw-identifiers.rs rename to src/test/run-pass/env-null-vars.rs index 38024feb432d9..296764269dec0 100644 --- a/src/test/ui/feature-gate-raw-identifiers.rs +++ b/src/test/run-pass/env-null-vars.rs @@ -8,7 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-windows +// ignore-wasm32-bare no libc to test ffi with + +// issue-53200 + +#![feature(libc)] +extern crate libc; + +use std::env; + +// FIXME: more platforms? +#[cfg(target_os = "linux")] fn main() { - let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change - println!("{}", foo); + unsafe { libc::clearenv(); } + assert_eq!(env::vars().count(), 0); } + +#[cfg(not(target_os = "linux"))] +fn main() {} diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs b/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs index 6cea75cf1d11e..2ef9fba2076ad 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - use std::mem; #[r#repr(r#C, r#packed)] diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs b/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs index 5d495c4e9e557..eefce3981bec1 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - fn r#fn(r#match: u32) -> u32 { r#match } diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/items.rs b/src/test/run-pass/rfc-2151-raw-identifiers/items.rs index 256bd263d38d4..4306ffe2042af 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/items.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/items.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - #[derive(Debug, PartialEq, Eq)] struct IntWrapper(u32); diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs b/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs index 4bd16ded52fbd..9e89b79266cfa 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs @@ -9,7 +9,6 @@ // except according to those terms. #![feature(decl_macro)] -#![feature(raw_identifiers)] r#macro_rules! r#struct { ($r#struct:expr) => { $r#struct } diff --git a/src/test/run-pass/simd-intrinsic-float-minmax.rs b/src/test/run-pass/simd-intrinsic-float-minmax.rs index 71c0139bb03bb..d35123e2235e2 100644 --- a/src/test/run-pass/simd-intrinsic-float-minmax.rs +++ b/src/test/run-pass/simd-intrinsic-float-minmax.rs @@ -29,7 +29,14 @@ extern "platform-intrinsic" { fn main() { let x = f32x4(1.0, 2.0, 3.0, 4.0); let y = f32x4(2.0, 1.0, 4.0, 3.0); + + #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))] let nan = ::std::f32::NAN; + // MIPS hardware treats f32::NAN as SNAN. Clear the signaling bit. + // See https://github.com/rust-lang/rust/issues/52746. + #[cfg(any(target_arch = "mips", target_arch = "mips64"))] + let nan = f32::from_bits(::std::f32::NAN.to_bits() - 1); + let n = f32x4(nan, nan, nan, nan); unsafe { diff --git a/src/test/ui/E0705.rs b/src/test/ui/E0705.rs index a0ce95e3e02c1..0d3f68ee7c464 100644 --- a/src/test/ui/E0705.rs +++ b/src/test/ui/E0705.rs @@ -11,10 +11,7 @@ // compile-pass #![feature(rust_2018_preview)] -#![feature(raw_identifiers)] -//~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition +#![feature(impl_header_lifetime_elision)] +//~^ WARN the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition -fn main() { - let foo = 0; - let bar = r#foo; -} +fn main() {} diff --git a/src/test/ui/E0705.stderr b/src/test/ui/E0705.stderr index ebb8dd4975d6f..2bdb6dc354a67 100644 --- a/src/test/ui/E0705.stderr +++ b/src/test/ui/E0705.stderr @@ -1,6 +1,6 @@ -warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition +warning[E0705]: the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition --> $DIR/E0705.rs:14:12 | -LL | #![feature(raw_identifiers)] - | ^^^^^^^^^^^^^^^ +LL | #![feature(impl_header_lifetime_elision)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs index 8f80e000e3caf..5b8832ddaf27c 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -10,7 +10,6 @@ // edition:2015 -#![feature(raw_identifiers)] #![allow(async_idents)] #[macro_export] diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.rs b/src/test/ui/edition-keywords-2015-2015-expansion.rs index 3b78ce80be208..a9037a50ecb6b 100644 --- a/src/test/ui/edition-keywords-2015-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2015-expansion.rs @@ -12,7 +12,6 @@ // aux-build:edition-kw-macro-2015.rs // compile-pass -#![feature(raw_identifiers)] #![allow(async_idents)] #[macro_use] diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.rs b/src/test/ui/edition-keywords-2015-2015-parsing.rs index 08cba2d2908a6..bdb190c748ace 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2015-parsing.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2015.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.stderr b/src/test/ui/edition-keywords-2015-2015-parsing.stderr index 5b6fd3e1c9c43..a629d13e6c31b 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2015-parsing.stderr @@ -1,11 +1,11 @@ error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:24:31 + --> $DIR/edition-keywords-2015-2015-parsing.rs:22:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:25:35 + --> $DIR/edition-keywords-2015-2015-parsing.rs:23:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.rs b/src/test/ui/edition-keywords-2015-2018-expansion.rs index 41d5ebd3e7db1..291fd0285e57c 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2018-expansion.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.stderr b/src/test/ui/edition-keywords-2015-2018-expansion.stderr index 5852d56e6d374..d087146d7a14a 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.stderr +++ b/src/test/ui/edition-keywords-2015-2018-expansion.stderr @@ -1,5 +1,5 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2015-2018-expansion.rs:20:5 + --> $DIR/edition-keywords-2015-2018-expansion.rs:18:5 | LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword | ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.rs b/src/test/ui/edition-keywords-2015-2018-parsing.rs index 337d6be6bbcd8..1b7bfb530596a 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2018-parsing.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.stderr b/src/test/ui/edition-keywords-2015-2018-parsing.stderr index 60cfbce3ff0e4..ab8a34a4a9e3d 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2018-parsing.stderr @@ -1,11 +1,11 @@ error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:24:31 + --> $DIR/edition-keywords-2015-2018-parsing.rs:22:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:25:35 + --> $DIR/edition-keywords-2015-2018-parsing.rs:23:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ diff --git a/src/test/ui/feature-gate-generic_associated_types.rs b/src/test/ui/feature-gate-generic_associated_types.rs index 3470662686643..bbaae1ef449fc 100644 --- a/src/test/ui/feature-gate-generic_associated_types.rs +++ b/src/test/ui/feature-gate-generic_associated_types.rs @@ -19,6 +19,7 @@ trait PointerFamily { } struct Foo; + impl PointerFamily for Foo { type Pointer = Box; //~^ ERROR generic associated types are unstable @@ -31,5 +32,9 @@ trait Bar { //~^ ERROR where clauses on associated types are unstable } +impl Bar for Foo { + type Assoc where Self: Sized = Foo; + //~^ ERROR where clauses on associated types are unstable +} fn main() {} diff --git a/src/test/ui/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gate-generic_associated_types.stderr index d7891f13c6b4d..f12cbe727fbed 100644 --- a/src/test/ui/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gate-generic_associated_types.stderr @@ -23,7 +23,7 @@ LL | type Pointer2: Deref where T: Clone, U: Clone; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:23:5 + --> $DIR/feature-gate-generic_associated_types.rs:24:5 | LL | type Pointer = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | type Pointer = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:25:5 + --> $DIR/feature-gate-generic_associated_types.rs:26:5 | LL | type Pointer2 = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,13 +39,21 @@ LL | type Pointer2 = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: where clauses on associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:30:5 + --> $DIR/feature-gate-generic_associated_types.rs:31:5 | LL | type Assoc where Self: Sized; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(generic_associated_types)] to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: where clauses on associated types are unstable (see issue #44265) + --> $DIR/feature-gate-generic_associated_types.rs:36:5 + | +LL | type Assoc where Self: Sized = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(generic_associated_types)] to the crate attributes to enable + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gate-raw-identifiers.stderr b/src/test/ui/feature-gate-raw-identifiers.stderr deleted file mode 100644 index 02eff7247c47b..0000000000000 --- a/src/test/ui/feature-gate-raw-identifiers.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: raw identifiers are experimental and subject to change (see issue #48589) - --> $DIR/feature-gate-raw-identifiers.rs:12:9 - | -LL | let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change - | ^^^^^ - | - = help: add #![feature(raw_identifiers)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/raw-literal-keywords.rs b/src/test/ui/raw-literal-keywords.rs index 9bb6653d77080..f1bfbc95eb395 100644 --- a/src/test/ui/raw-literal-keywords.rs +++ b/src/test/ui/raw-literal-keywords.rs @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -#![feature(raw_identifiers)] - fn test_if() { r#if true { } //~ ERROR found `true` } diff --git a/src/test/ui/raw-literal-keywords.stderr b/src/test/ui/raw-literal-keywords.stderr index 022f80ae8a4ec..8a6b91b4b4b6f 100644 --- a/src/test/ui/raw-literal-keywords.stderr +++ b/src/test/ui/raw-literal-keywords.stderr @@ -1,17 +1,17 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `true` - --> $DIR/raw-literal-keywords.rs:16:10 + --> $DIR/raw-literal-keywords.rs:14:10 | LL | r#if true { } //~ ERROR found `true` | ^^^^ expected one of 8 possible tokens here error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test` - --> $DIR/raw-literal-keywords.rs:20:14 + --> $DIR/raw-literal-keywords.rs:18:14 | LL | r#struct Test; //~ ERROR found `Test` | ^^^^ expected one of 8 possible tokens here error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test` - --> $DIR/raw-literal-keywords.rs:24:13 + --> $DIR/raw-literal-keywords.rs:22:13 | LL | r#union Test; //~ ERROR found `Test` | ^^^^ expected one of 8 possible tokens here diff --git a/src/test/ui/raw-literal-self.rs b/src/test/ui/raw-literal-self.rs index f88d6cf9a67bd..17496d767b622 100644 --- a/src/test/ui/raw-literal-self.rs +++ b/src/test/ui/raw-literal-self.rs @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -#![feature(raw_identifiers)] - fn self_test(r#self: u32) { //~^ ERROR `r#self` is not currently supported. } diff --git a/src/test/ui/raw-literal-self.stderr b/src/test/ui/raw-literal-self.stderr index e3345847aa895..f4b759372471c 100644 --- a/src/test/ui/raw-literal-self.stderr +++ b/src/test/ui/raw-literal-self.stderr @@ -1,5 +1,5 @@ error: `r#self` is not currently supported. - --> $DIR/raw-literal-self.rs:15:14 + --> $DIR/raw-literal-self.rs:13:14 | LL | fn self_test(r#self: u32) { | ^^^^^^ diff --git a/src/test/ui/rust-2018/async-ident-allowed.stderr b/src/test/ui/rust-2018/async-ident-allowed.stderr index 1644102cdca1a..741c1c70209bc 100644 --- a/src/test/ui/rust-2018/async-ident-allowed.stderr +++ b/src/test/ui/rust-2018/async-ident-allowed.stderr @@ -2,7 +2,7 @@ error: `async` is a keyword in the 2018 edition --> $DIR/async-ident-allowed.rs:19:9 | LL | let async = 3; //~ ERROR: is a keyword - | ^^^^^ + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` | note: lint level defined here --> $DIR/async-ident-allowed.rs:13:9 diff --git a/src/test/ui/rust-2018/async-ident.fixed b/src/test/ui/rust-2018/async-ident.fixed index 228bf91125337..15b8eec3bea99 100644 --- a/src/test/ui/rust-2018/async-ident.fixed +++ b/src/test/ui/rust-2018/async-ident.fixed @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] #![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] #![deny(async_idents)] diff --git a/src/test/ui/rust-2018/async-ident.rs b/src/test/ui/rust-2018/async-ident.rs index cc400c2a92e0e..6087d2c16423e 100644 --- a/src/test/ui/rust-2018/async-ident.rs +++ b/src/test/ui/rust-2018/async-ident.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] #![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] #![deny(async_idents)] diff --git a/src/test/ui/rust-2018/async-ident.stderr b/src/test/ui/rust-2018/async-ident.stderr index 94fd3e70434cb..06d68a38c5f38 100644 --- a/src/test/ui/rust-2018/async-ident.stderr +++ b/src/test/ui/rust-2018/async-ident.stderr @@ -1,11 +1,11 @@ error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:18:4 + --> $DIR/async-ident.rs:17:4 | LL | fn async() {} //~ ERROR async | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` | note: lint level defined here - --> $DIR/async-ident.rs:13:9 + --> $DIR/async-ident.rs:12:9 | LL | #![deny(async_idents)] | ^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | #![deny(async_idents)] = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:23:7 + --> $DIR/async-ident.rs:22:7 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -22,7 +22,7 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:23:19 + --> $DIR/async-ident.rs:22:19 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -31,7 +31,7 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:37:11 + --> $DIR/async-ident.rs:36:11 | LL | trait async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -40,7 +40,7 @@ LL | trait async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:41:10 + --> $DIR/async-ident.rs:40:10 | LL | impl async for MyStruct {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -49,7 +49,7 @@ LL | impl async for MyStruct {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:47:12 + --> $DIR/async-ident.rs:46:12 | LL | static async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -58,7 +58,7 @@ LL | static async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:53:11 + --> $DIR/async-ident.rs:52:11 | LL | const async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -67,7 +67,7 @@ LL | const async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:59:15 + --> $DIR/async-ident.rs:58:15 | LL | impl Foo { fn async() {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -76,7 +76,7 @@ LL | impl Foo { fn async() {} } = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:64:12 + --> $DIR/async-ident.rs:63:12 | LL | struct async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -85,7 +85,7 @@ LL | struct async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:9 + --> $DIR/async-ident.rs:66:9 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -94,7 +94,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:16 + --> $DIR/async-ident.rs:66:16 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -103,7 +103,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:24 + --> $DIR/async-ident.rs:66:24 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -112,7 +112,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:78:19 + --> $DIR/async-ident.rs:77:19 | LL | () => (pub fn async() {}) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -121,7 +121,7 @@ LL | () => (pub fn async() {}) = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:85:6 + --> $DIR/async-ident.rs:84:6 | LL | (async) => (1) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` diff --git a/src/tools/compiletest/src/raise_fd_limit.rs b/src/tools/compiletest/src/raise_fd_limit.rs index 220082799a8b0..d1071231530d6 100644 --- a/src/tools/compiletest/src/raise_fd_limit.rs +++ b/src/tools/compiletest/src/raise_fd_limit.rs @@ -57,14 +57,16 @@ pub unsafe fn raise_fd_limit() { panic!("raise_fd_limit: error calling getrlimit: {}", err); } - // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard - // limit - rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max); + // Make sure we're only ever going to increase the rlimit. + if rlim.rlim_cur < maxfiles as libc::rlim_t { + // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard limit. + rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max); - // Set our newly-increased resource limit - if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 { - let err = io::Error::last_os_error(); - panic!("raise_fd_limit: error calling setrlimit: {}", err); + // Set our newly-increased resource limit. + if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 { + let err = io::Error::last_os_error(); + panic!("raise_fd_limit: error calling setrlimit: {}", err); + } } }