diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index ca852fe7622cc..049029a62f786 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -51,8 +51,8 @@ pub fn construct(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG { tables, graph, fn_exit, - loop_scopes: Vec::new(), - breakable_block_scopes: Vec::new(), + loop_scopes: vec![], + breakable_block_scopes: vec![], }; body_exit = cfg_builder.expr(&body.value, entry); cfg_builder.add_contained_edge(body_exit, fn_exit); diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 7eea336cbbfa1..91a81b7c00762 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -124,7 +124,7 @@ impl DepGraph { pub fn query(&self) -> DepGraphQuery { let current_dep_graph = self.data.as_ref().unwrap().current.borrow(); let nodes: Vec<_> = current_dep_graph.data.iter().map(|n| n.node).collect(); - let mut edges = Vec::new(); + let mut edges = vec![]; for (from, edge_targets) in current_dep_graph.data.iter() .map(|d| (d.node, &d.edges)) { for &edge_target in edge_targets.iter() { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 7e7bb5f61a324..a0a77dd465b4b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -251,10 +251,10 @@ pub fn lower_crate( bodies: BTreeMap::new(), trait_impls: BTreeMap::new(), modules: BTreeMap::new(), - exported_macros: Vec::new(), - non_exported_macro_attrs: Vec::new(), - catch_scopes: Vec::new(), - loop_scopes: Vec::new(), + exported_macros: vec![], + non_exported_macro_attrs: vec![], + catch_scopes: vec![], + loop_scopes: vec![], is_in_loop_condition: false, is_in_trait_impl: false, is_in_dyn_type: false, @@ -266,9 +266,9 @@ pub fn lower_crate( node_id_to_hir_id: IndexVec::new(), generator_kind: None, current_item: None, - lifetimes_to_define: Vec::new(), + lifetimes_to_define: vec![], is_collecting_in_band_lifetimes: false, - in_scope_lifetimes: Vec::new(), + in_scope_lifetimes: vec![], allow_try_trait: Some([sym::try_trait][..].into()), allow_gen_future: Some([sym::gen_future][..].into()), }.lower_crate(krate) @@ -1093,7 +1093,7 @@ impl<'a> LoweringContext<'a> { &generics.params, |this| { this.collect_in_band_defs(parent_id, anonymous_lifetime_mode, |this| { - let mut params = Vec::new(); + let mut params = vec![]; // Note: it is necessary to lower generics *before* calling `f`. // When lowering `async fn`, there's a final step when lowering // the return type that assumes that all in-scope lifetimes have @@ -1954,10 +1954,10 @@ impl<'a> LoweringContext<'a> { parent: parent_index, exist_ty_id, collect_elided_lifetimes: true, - currently_bound_lifetimes: Vec::new(), + currently_bound_lifetimes: vec![], already_defined_lifetimes: FxHashSet::default(), - output_lifetimes: Vec::new(), - output_lifetime_params: Vec::new(), + output_lifetimes: vec![], + output_lifetime_params: vec![], }; for bound in bounds { @@ -3225,8 +3225,8 @@ impl<'a> LoweringContext<'a> { }; self.lower_body(|this| { - let mut arguments: Vec = Vec::new(); - let mut statements: Vec = Vec::new(); + let mut arguments: Vec = vec![]; + let mut statements: Vec = vec![]; // Async function arguments are lowered into the closure body so that they are // captured and so that the drop order matches the equivalent non-async functions. diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 12ea772c1fb31..1e1f0a81517ff 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -107,7 +107,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { -> NodeCollector<'a, 'hir> { let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX); - let mut hir_body_nodes = Vec::new(); + let mut hir_body_nodes = vec![]; // Allocate `DepNode`s for the root module. let (root_mod_sig_dep_index, root_mod_full_dep_index) = { diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 889659382d060..4c9fcc1ba2a8e 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -7,7 +7,7 @@ use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter}; pub fn check_crate(hir_map: &hir::map::Map<'_>) { hir_map.dep_graph.assert_ignored(); - let errors = Lock::new(Vec::new()); + let errors = Lock::new(vec![]); par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| { let local_def_id = hir_map.local_def_id_from_node_id(*module_id); diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index ad481417d5e5f..5be4e4b42fe9b 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -257,7 +257,7 @@ fn dump_region_data_to<'a, 'tcx>( path); let g = ConstraintGraph::new("region_data".to_string(), region_rels, map); debug!("dump_region_data calling render"); - let mut v = Vec::new(); + let mut v = vec![]; dot::render(&g, &mut v).unwrap(); fs::write(path, &v) } diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index d06c4434b3aaf..225ba71b74ac5 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -792,7 +792,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let mut state = WalkState { set: Default::default(), stack: vec![orig_node_idx], - result: Vec::new(), + result: vec![], dup_found: false, }; state.set.insert(orig_node_idx); diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index e30e86998a8c6..ee6b9b30b4b03 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -312,7 +312,7 @@ impl<'tcx> TypeVariableTable<'tcx> { /// unified `V1` with `T1`, this function would return `{T0}`. pub fn types_escaping_snapshot(&mut self, s: &Snapshot<'tcx>) -> Vec> { let mut new_elem_threshold = u32::MAX; - let mut escaping_types = Vec::new(); + let mut escaping_types = vec![]; let actions_since_snapshot = self.values.actions_since_snapshot(&s.snapshot); debug!("actions_since_snapshot.len() = {}", actions_since_snapshot.len()); for action in actions_since_snapshot { diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index 0b514f5927d30..d52607b1c37f7 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -1,7 +1,9 @@ //! Some lints that are only useful in the compiler or crates that use compiler internals, such as //! Clippy. -use crate::hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind}; +use crate::hir::{ + Expr, GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind, +}; use crate::lint::{ EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass, }; @@ -255,3 +257,51 @@ fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool { false } } + +declare_tool_lint! { + pub rustc::VEC_NEW, + Allow, + "Using Vec::new() instead of vec![]" +} + +declare_lint_pass!(VecNew => [VEC_NEW]); + +const VEC_PATH: &[Symbol; 3] = &[sym::alloc, sym::vec, sym::Vec]; + +impl LateLintPass<'_, '_> for VecNew { + fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { + use crate::hir::ExprKind; + if let ExprKind::Call(func, args) = &expr.node { + if !args.is_empty() { + return; + } + + if let ExprKind::Path(qpath) = &func.node { + if let QPath::TypeRelative(ty, segment) = qpath { + if segment.ident.name.as_str() == "new" { + if let TyKind::Path(ty_path) = &ty.node { + if let QPath::Resolved(_, path) = ty_path { + if let Some(def_id) = path.res.opt_def_id() { + if cx.match_def_path(def_id, VEC_PATH) { + cx.struct_span_lint( + VEC_NEW, + expr.span, + "usage of `Vec::new()`", + ) + .span_suggestion( + expr.span, + "use", + "vec![]".to_string(), + Applicability::MachineApplicable, + ) + .emit(); + } + } + } + } + } + } + } + } + } +} diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 139f4343117af..7bfb034375136 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -37,7 +37,7 @@ enum LintSet { impl LintLevelSets { pub fn new(sess: &Session) -> LintLevelSets { let mut me = LintLevelSets { - list: Vec::new(), + list: vec![], lint_cap: Level::Forbid, }; me.process_command_line(sess); diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 5a580dfa420b3..c03815e9561c9 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -154,7 +154,7 @@ pub struct EncodedMetadata { impl EncodedMetadata { pub fn new() -> EncodedMetadata { EncodedMetadata { - raw_data: Vec::new(), + raw_data: vec![], } } } diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 96b99fe4cdce2..8df870cdf941b 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -96,7 +96,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { let sess = &tcx.sess; if !sess.opts.output_types.should_codegen() { - return Vec::new(); + return vec![]; } let preferred_linkage = match ty { @@ -128,7 +128,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { if preferred_linkage == Linkage::NotLinked { // If the crate is not linked, there are no link-time dependencies. - return Vec::new(); + return vec![]; } if preferred_linkage == Linkage::Static { @@ -151,7 +151,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { but was not found in this form", tcx.crate_name(cnum))); } - return Vec::new(); + return vec![]; } } diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index cba4d0f1598c4..68b31289d5696 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -69,7 +69,7 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> { main_fn: None, attr_main_fn: None, start_fn: None, - non_main_fns: Vec::new(), + non_main_fns: vec![], }; tcx.hir().krate().visit_all_item_likes(&mut ctxt); diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index bdd48b3447498..e14d6ac67c326 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -66,7 +66,7 @@ impl LanguageItems { Self { items: vec![$(init_none($variant)),*], - missing: Vec::new(), + missing: vec![], } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index daf0d8103a2c0..ed30d4ce9b1a4 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -269,8 +269,8 @@ impl IrMaps<'tcx> { live_node_map: HirIdMap::default(), variable_map: HirIdMap::default(), capture_info_map: Default::default(), - var_kinds: Vec::new(), - lnks: Vec::new(), + var_kinds: vec![], + lnks: vec![], } } @@ -484,7 +484,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr) { // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. - let mut call_caps = Vec::new(); + let mut call_caps = vec![]; let closure_def_id = ir.tcx.hir().local_def_id(expr.hir_id); if let Some(upvars) = ir.tcx.upvars(closure_def_id) { let parent_upvars = ir.tcx.upvars(ir.body_owner); @@ -833,7 +833,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { #[allow(unused_must_use)] fn ln_str(&self, ln: LiveNode) -> String { - let mut wr = Vec::new(); + let mut wr = vec![]; { let wr = &mut wr as &mut dyn Write; write!(wr, "[ln({:?}) of kind {:?} reads", ln.get(), self.ir.lnk(ln)); diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index b9a95219d3146..1dc97461101f7 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -404,7 +404,7 @@ fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet { tcx, tables: &ty::TypeckTables::empty(None), reachable_symbols: Default::default(), - worklist: Vec::new(), + worklist: vec![], any_library, }; diff --git a/src/librustc/mir/traversal.rs b/src/librustc/mir/traversal.rs index 1416a5f0a6e9f..ddc3e5e5f7fef 100644 --- a/src/librustc/mir/traversal.rs +++ b/src/librustc/mir/traversal.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> { let mut po = Postorder { body, visited: BitSet::new_empty(body.basic_blocks().len()), - visit_stack: Vec::new(), + visit_stack: vec![], root_is_start_block: root == START_BLOCK, }; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index db8e2f64e3066..fef3d1d4ab8fc 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -597,10 +597,10 @@ pub fn host_triple() -> &'static str { impl Default for Options { fn default() -> Options { Options { - crate_types: Vec::new(), + crate_types: vec![], optimize: OptLevel::No, debuginfo: DebugInfo::None, - lint_opts: Vec::new(), + lint_opts: vec![], lint_cap: None, describe_lints: false, output_types: OutputTypes(BTreeMap::new()), @@ -610,20 +610,20 @@ impl Default for Options { test: false, incremental: None, debugging_opts: basic_debugging_options(), - prints: Vec::new(), + prints: vec![], borrowck_mode: BorrowckMode::Migrate, cg: basic_codegen_options(), error_format: ErrorOutputType::default(), externs: Externs(BTreeMap::new()), crate_name: None, alt_std_name: None, - libs: Vec::new(), + libs: vec![], unstable_features: UnstableFeatures::Disallow, debug_assertions: true, actually_rustdoc: false, cli_forced_codegen_units: None, cli_forced_thinlto_off: false, - remap_path_prefix: Vec::new(), + remap_path_prefix: vec![], edition: DEFAULT_EDITION, } } @@ -1147,9 +1147,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "select target processor (rustc --print target-cpus for details)"), target_feature: String = (String::new(), parse_string, [TRACKED], "target specific attributes (rustc --print target-features for details)"), - passes: Vec = (Vec::new(), parse_list, [TRACKED], + passes: Vec = (vec![], parse_list, [TRACKED], "a list of extra LLVM passes to run (space separated)"), - llvm_args: Vec = (Vec::new(), parse_list, [TRACKED], + llvm_args: Vec = (vec![], parse_list, [TRACKED], "a list of arguments to pass to llvm (space separated)"), save_temps: bool = (false, parse_bool, [UNTRACKED], "save all temporary output files during compilation"), @@ -1175,13 +1175,13 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "choose the relocation model to use (rustc --print relocation-models for details)"), code_model: Option = (None, parse_opt_string, [TRACKED], "choose the code model to use (rustc --print code-models for details)"), - metadata: Vec = (Vec::new(), parse_list, [TRACKED], + metadata: Vec = (vec![], parse_list, [TRACKED], "metadata to mangle symbol names with"), extra_filename: String = (String::new(), parse_string, [UNTRACKED], "extra data to put in each output filename"), codegen_units: Option = (None, parse_opt_uint, [UNTRACKED], "divide crate into N units to optimize in parallel"), - remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED], + remark: Passes = (Passes::Some(vec![]), parse_passes, [UNTRACKED], "print remarks for these optimization passes (space separated, or \"all\")"), no_stack_check: bool = (false, parse_bool, [UNTRACKED], "the --no-stack-check flag is deprecated and does nothing"), @@ -1315,7 +1315,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "trace and profile the queries and keys of the incremental compilation framework"), no_analysis: bool = (false, parse_bool, [UNTRACKED], "parse and expand the source, but run no analysis"), - extra_plugins: Vec = (Vec::new(), parse_list, [TRACKED], + extra_plugins: Vec = (vec![], parse_list, [TRACKED], "load extra plugins"), unstable_options: bool = (false, parse_bool, [UNTRACKED], "adds unstable command line options to rustc interface"), @@ -1445,7 +1445,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "disables the 'leak check' for subtyping; unsound, but useful for tests"), no_interleave_lints: bool = (false, parse_bool, [UNTRACKED], "don't interleave execution of lints; allows benchmarking individual lints"), - crate_attr: Vec = (Vec::new(), parse_string_push, [TRACKED], + crate_attr: Vec = (vec![], parse_string_push, [TRACKED], "inject the given attribute in the crate"), self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled, parse_switch_with_opt_path, [UNTRACKED], @@ -2152,7 +2152,7 @@ pub fn build_session_options_and_crate_config( ); } - let mut prints = Vec::::new(); + let mut prints: Vec = vec![]; if cg.target_cpu.as_ref().map_or(false, |s| s == "help") { prints.push(PrintRequest::TargetCPUs); cg.target_cpu = None; @@ -2449,7 +2449,7 @@ pub fn build_session_options_and_crate_config( } pub fn parse_crate_types_from_list(list_list: Vec) -> Result, String> { - let mut crate_types: Vec = Vec::new(); + let mut crate_types: Vec = vec![]; for unparsed_crate_type in &list_list { for part in unparsed_crate_type.split(',') { let new_part = match part { diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index b17ba8de73049..07a3529419471 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1234,8 +1234,8 @@ fn build_session_( lint_store: RwLock::new(lint::LintStore::new()), buffered_lints: Lock::new(Some(Default::default())), one_time_diagnostics: Default::default(), - plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())), - plugin_attributes: Lock::new(Vec::new()), + plugin_llvm_passes: OneThread::new(RefCell::new(vec![])), + plugin_attributes: Lock::new(vec![]), crate_types: Once::new(), dependency_formats: Once::new(), crate_disambiguator: Once::new(), diff --git a/src/librustc/traits/chalk_fulfill.rs b/src/librustc/traits/chalk_fulfill.rs index 0c7c94b684a9f..77e31c9ffe787 100644 --- a/src/librustc/traits/chalk_fulfill.rs +++ b/src/librustc/traits/chalk_fulfill.rs @@ -91,7 +91,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { &mut self, infcx: &InferCtxt<'_, 'tcx>, ) -> Result<(), Vec>> { - let mut errors = Vec::new(); + let mut errors = vec![]; let mut next_round = FxHashSet::default(); let mut making_progress; diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 99b5ef3894b9c..ca8b5bdd66c94 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> { ) -> Result<(), Vec>> { debug!("select(obligation-forest-size={})", self.predicates.len()); - let mut errors = Vec::new(); + let mut errors = vec![]; loop { debug!("select: starting another iteration"); diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 798a25fe7b1bc..54e692cd1df01 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1717,7 +1717,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } let mut candidates = SelectionCandidateSet { - vec: Vec::new(), + vec: vec![], ambiguous: false, }; @@ -2550,7 +2550,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Never | ty::Error => { // safe for everything - Where(ty::Binder::dummy(Vec::new())) + Where(ty::Binder::dummy(vec![])) } ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => None, @@ -2602,7 +2602,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Infer(ty::FloatVar(_)) | ty::FnDef(..) | ty::FnPtr(_) - | ty::Error => Where(ty::Binder::dummy(Vec::new())), + | ty::Error => Where(ty::Binder::dummy(vec![])), ty::Uint(_) | ty::Int(_) @@ -2691,7 +2691,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Infer(ty::IntVar(_)) | ty::Infer(ty::FloatVar(_)) | ty::Never - | ty::Char => Vec::new(), + | ty::Char => vec![], ty::UnnormalizedProjection(..) | ty::Placeholder(..) @@ -2849,7 +2849,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ProjectionCandidate => { self.confirm_projection_candidate(obligation); - Ok(VtableParam(Vec::new())) + Ok(VtableParam(vec![])) } ClosureCandidate => { @@ -2883,7 +2883,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // because that's what the object type is telling us, // and there's really no additional obligations to // prove and no types in particular to unify etc. - Ok(VtableParam(Vec::new())) + Ok(VtableParam(vec![])) } BuiltinUnsizeCandidate => { diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index f736c5ef9b1c0..78f302a8d1bf6 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -121,7 +121,7 @@ impl<'tcx> Children { simplified_self: Option, ) -> Result { let mut last_lint = None; - let mut replace_children = Vec::new(); + let mut replace_children = vec![]; debug!( "insert(impl_def_id={:?}, simplified_self={:?})", diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index e889f2edef2bb..2cadc9d1402d2 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -231,7 +231,7 @@ pub trait PrettyPrinter<'tcx>: self, def_id: DefId, ) -> Result<(Self, bool), Self::Error> { - let mut callers = Vec::new(); + let mut callers = vec![]; self.try_print_visible_def_path_recur(def_id, &mut callers) } diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs index dcc467a61b541..81bdb7dc09159 100644 --- a/src/librustc/ty/query/job.rs +++ b/src/librustc/ty/query/job.rs @@ -103,7 +103,7 @@ impl<'tcx> QueryJob<'tcx> { pub(super) fn find_cycle_in_stack(&self, tcx: TyCtxt<'tcx>, span: Span) -> CycleError<'tcx> { // Get the current executing query (waiter) and find the waitee amongst its parents let mut current_job = tls::with_related_context(tcx, |icx| icx.query.clone()); - let mut cycle = Vec::new(); + let mut cycle = vec![]; while let Some(job) = current_job { cycle.push(job.info.clone()); @@ -176,7 +176,7 @@ impl<'tcx> QueryLatch<'tcx> { QueryLatch { info: Mutex::new(QueryLatchInfo { complete: false, - waiters: Vec::new(), + waiters: vec![], }), } } @@ -365,7 +365,7 @@ fn remove_cycle<'tcx>( tcx: TyCtxt<'tcx>, ) -> bool { let mut visited = FxHashSet::default(); - let mut stack = Vec::new(); + let mut stack = vec![]; // Look for a cycle starting with the last query in `jobs` if let Some(waiter) = cycle_check(jobs.pop().unwrap(), DUMMY_SP, @@ -395,7 +395,7 @@ fn remove_cycle<'tcx>( // This query is connected to the root (it has no query parent) Some((*span, query.clone(), None)) } else { - let mut waiters = Vec::new(); + let mut waiters = vec![]; // Find all the direct waiters who lead to the root visit_waiters(query.clone(), |span, waiter| { // Mark all the other queries in the cycle as already visited @@ -507,7 +507,7 @@ fn deadlock(tcx: TyCtxt<'_>, registry: &rayon_core::Registry) { process::abort(); }); - let mut wakelist = Vec::new(); + let mut wakelist = vec![]; let mut jobs: Vec<_> = tcx.queries.collect_active_jobs(); let mut found_cycle = false; diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index a508d9846bce3..6d29097e5c756 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -142,7 +142,7 @@ impl<'sess> OnDiskCache<'sess> { pub fn new_empty(source_map: &'sess SourceMap) -> OnDiskCache<'sess> { OnDiskCache { - serialized_data: Vec::new(), + serialized_data: vec![], file_index_to_stable_id: Default::default(), file_index_to_file: Default::default(), prev_cnums: vec![], @@ -152,7 +152,7 @@ impl<'sess> OnDiskCache<'sess> { query_result_index: Default::default(), prev_diagnostics_index: Default::default(), synthetic_expansion_infos: Default::default(), - alloc_decoding_state: AllocDecodingState::new(Vec::new()), + alloc_decoding_state: AllocDecodingState::new(vec![]), } } @@ -187,7 +187,7 @@ impl<'sess> OnDiskCache<'sess> { predicate_shorthands: Default::default(), expn_info_shorthands: Default::default(), interpret_allocs: Default::default(), - interpret_allocs_inverse: Vec::new(), + interpret_allocs_inverse: vec![], source_map: CachingSourceMapView::new(tcx.sess.source_map()), file_to_file_index, }; @@ -237,7 +237,7 @@ impl<'sess> OnDiskCache<'sess> { .collect::>()?; let interpret_alloc_index = { - let mut interpret_alloc_index = Vec::new(); + let mut interpret_alloc_index = vec![]; let mut n = 0; loop { let new_n = encoder.interpret_allocs_inverse.len(); @@ -354,7 +354,7 @@ impl<'sess> OnDiskCache<'sess> { diagnostics: ThinVec) { let mut current_diagnostics = self.current_diagnostics.borrow_mut(); - let x = current_diagnostics.entry(dep_node_index).or_insert(Vec::new()); + let x = current_diagnostics.entry(dep_node_index).or_insert(vec![]); x.extend(Into::>::into(diagnostics)); } diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 0c9e31e1ff28e..fb736fb54dc43 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -738,7 +738,7 @@ macro_rules! define_queries_inner { #[cfg(parallel_compiler)] pub fn collect_active_jobs(&self) -> Vec>> { - let mut jobs = Vec::new(); + let mut jobs = vec![]; // We use try_lock here since we are only called from the // deadlock handler, and this shouldn't be locked. @@ -758,7 +758,7 @@ macro_rules! define_queries_inner { } pub fn print_stats(&self) { - let mut queries = Vec::new(); + let mut queries = vec![]; #[derive(Clone)] struct QueryStats { diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index c3ecc04b12e01..f368895ee7dd4 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -191,7 +191,7 @@ impl<'tcx> ty::ParamEnv<'tcx> { _ => return Err(CopyImplementationError::NotAnAdt), }; - let mut infringing = Vec::new(); + let mut infringing = vec![]; for variant in &adt.variants { for field in &variant.fields { let ty = field.ty(tcx, substs); @@ -987,7 +987,7 @@ impl<'tcx> ty::TyS<'tcx> { // To avoid a stack overflow when checking an enum variant or struct that // contains a different, structurally recursive type, maintain a stack // of seen types and check recursion for each of them (issues #3008, #3779). - let mut seen: Vec> = Vec::new(); + let mut seen: Vec> = vec![]; let mut representable_cache = FxHashMap::default(); let r = is_type_structurally_recursive( tcx, sp, &mut seen, &mut representable_cache, self); diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 9803ee99f1a47..8afdbf61ae8c6 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -128,7 +128,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { // Generate the submodule itself let name = f.kind.fn_name("allocator_abi"); let allocator_abi = Ident::from_str(&name).gensym(); - let module = f.cx.item_mod(span, span, allocator_abi, Vec::new(), items); + let module = f.cx.item_mod(span, span, allocator_abi, vec![], items); let module = f.cx.monotonic_expander().flat_map_item(module).pop().unwrap(); // Return the item and new submodule @@ -160,7 +160,7 @@ struct AllocFnFactory<'a> { impl AllocFnFactory<'_> { fn allocator_fn(&self, method: &AllocatorMethod) -> P { - let mut abi_args = Vec::new(); + let mut abi_args = vec![]; let mut i = 0; let ref mut mk = || { let name = Ident::from_str(&format!("arg{}", i)); @@ -277,7 +277,7 @@ impl AllocFnFactory<'_> { (self.ptr_u8(), expr) } - AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(Vec::new())), expr), + AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(vec![])), expr), AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { panic!("can't convert AllocatorTy to an output") diff --git a/src/librustc_ast_borrowck/borrowck/check_loans.rs b/src/librustc_ast_borrowck/borrowck/check_loans.rs index 3d824ee6ce1e8..69590b2d258d5 100644 --- a/src/librustc_ast_borrowck/borrowck/check_loans.rs +++ b/src/librustc_ast_borrowck/borrowck/check_loans.rs @@ -320,7 +320,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { //! Returns a vector of the loans that are generated as //! we enter `node`. - let mut result = Vec::new(); + let mut result = vec![]; self.dfcx_loans.each_gen_bit(node, |loan_index| { result.push(loan_index); true diff --git a/src/librustc_ast_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_ast_borrowck/borrowck/gather_loans/mod.rs index 16fef705ec953..c93baccb400a0 100644 --- a/src/librustc_ast_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_ast_borrowck/borrowck/gather_loans/mod.rs @@ -31,7 +31,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, let param_env = bccx.tcx.param_env(def_id); let mut glcx = GatherLoanCtxt { bccx, - all_loans: Vec::new(), + all_loans: vec![], item_ub: region::Scope { id: bccx.tcx.hir().body(body).value.hir_id.local_id, data: region::ScopeData::Node diff --git a/src/librustc_codegen_ssa/back/command.rs b/src/librustc_codegen_ssa/back/command.rs index d610805b5bbd0..aa98349572b5c 100644 --- a/src/librustc_codegen_ssa/back/command.rs +++ b/src/librustc_codegen_ssa/back/command.rs @@ -39,8 +39,8 @@ impl Command { fn _new(program: Program) -> Command { Command { program, - args: Vec::new(), - env: Vec::new(), + args: vec![], + env: vec![], } } diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 707b7cae16ce7..1d94d98b979a2 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1085,7 +1085,7 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker, let mut position_independent_executable = false; if t.options.position_independent_executables { - let empty_vec = Vec::new(); + let empty_vec = vec![]; let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec); let more_args = &sess.opts.cg.link_arg; let mut args = args.iter().chain(more_args.iter()).chain(used_link_args.iter()); diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index 32696d46cd577..0c48fc6154569 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -1010,7 +1010,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec { return exports.clone() } - let mut symbols = Vec::new(); + let mut symbols = vec![]; let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); for &(symbol, level) in tcx.exported_symbols(LOCAL_CRATE).iter() { diff --git a/src/librustc_codegen_ssa/back/rpath.rs b/src/librustc_codegen_ssa/back/rpath.rs index e27cb6d8dda89..ba38cb17c7f23 100644 --- a/src/librustc_codegen_ssa/back/rpath.rs +++ b/src/librustc_codegen_ssa/back/rpath.rs @@ -18,7 +18,7 @@ pub struct RPathConfig<'a> { pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec { // No rpath on windows if !config.has_rpath { - return Vec::new(); + return vec![]; } debug!("preparing the RPATH!"); @@ -163,7 +163,7 @@ fn get_install_prefix_rpath(config: &mut RPathConfig<'_>) -> String { fn minimize_rpaths(rpaths: &[String]) -> Vec { let mut set = FxHashSet::default(); - let mut minimized = Vec::new(); + let mut minimized = vec![]; for rpath in rpaths { if set.insert(rpath) { minimized.push(rpath.clone()); diff --git a/src/librustc_codegen_ssa/back/wasm.rs b/src/librustc_codegen_ssa/back/wasm.rs index f90bb89fbe87d..17c2641e5372f 100644 --- a/src/librustc_codegen_ssa/back/wasm.rs +++ b/src/librustc_codegen_ssa/back/wasm.rs @@ -38,7 +38,7 @@ pub fn add_producer_section( name: "Rust", version: rust_version, }; - let mut fields = Vec::new(); + let mut fields = vec![]; let mut wrote_rustc = false; let mut wrote_rust = false; @@ -64,7 +64,7 @@ pub fn add_producer_section( for _ in 0..decoder.u32() { let name = decoder.str(); - let mut values = Vec::new(); + let mut values = vec![]; for _ in 0..decoder.u32() { let name = decoder.str(); let version = decoder.str(); @@ -169,7 +169,7 @@ struct WasmEncoder { impl WasmEncoder { fn new() -> WasmEncoder { - WasmEncoder { data: Vec::new() } + WasmEncoder { data: vec![] } } fn u32(&mut self, val: u32) { diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 7bb2cc7c08977..100d892b5bb61 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -1048,7 +1048,7 @@ fn start_executing_work( drop(coordinator_send2.send(Box::new(Message::Token::(token)))); }).expect("failed to spawn helper thread"); - let mut each_linked_rlib_for_lto = Vec::new(); + let mut each_linked_rlib_for_lto = vec![]; drop(link::each_linked_rlib(sess, crate_info, &mut |cnum, path| { if link::ignored_for_lto(sess, crate_info, cnum) { return @@ -1250,7 +1250,7 @@ fn start_executing_work( let max_workers = ::num_cpus::get(); let mut worker_id_counter = 0; - let mut free_worker_ids = Vec::new(); + let mut free_worker_ids = vec![]; let mut get_worker_id = |free_worker_ids: &mut Vec| { if let Some(id) = free_worker_ids.pop() { id @@ -1266,9 +1266,9 @@ fn start_executing_work( let mut compiled_modules = vec![]; let mut compiled_metadata_module = None; let mut compiled_allocator_module = None; - let mut needs_fat_lto = Vec::new(); - let mut needs_thin_lto = Vec::new(); - let mut lto_import_only_modules = Vec::new(); + let mut needs_fat_lto = vec![]; + let mut needs_thin_lto = vec![]; + let mut lto_import_only_modules = vec![]; let mut started_lto = false; let mut codegen_aborted = false; @@ -1276,11 +1276,11 @@ fn start_executing_work( let mut codegen_done = false; // This is the queue of LLVM work items that still need processing. - let mut work_items = Vec::<(WorkItem, u64)>::new(); + let mut work_items: Vec<(WorkItem, u64)> = vec![]; // This are the Jobserver Tokens we currently hold. Does not include // the implicit Token the compiler process owns no matter what. - let mut tokens = Vec::new(); + let mut tokens = vec![]; let mut main_thread_worker_state = MainThreadWorkerState::Idle; let mut running = 0; diff --git a/src/librustc_data_structures/graph/scc/mod.rs b/src/librustc_data_structures/graph/scc/mod.rs index 78554cda77b44..2a419ab0c906a 100644 --- a/src/librustc_data_structures/graph/scc/mod.rs +++ b/src/librustc_data_structures/graph/scc/mod.rs @@ -219,10 +219,10 @@ where graph, node_states: IndexVec::from_elem_n(NodeState::NotVisited, num_nodes), node_stack: Vec::with_capacity(num_nodes), - successors_stack: Vec::new(), + successors_stack: vec![], scc_data: SccData { ranges: IndexVec::new(), - all_successors: Vec::new(), + all_successors: vec![], }, duplicate_set: FxHashSet::default(), }; diff --git a/src/librustc_data_structures/indexed_vec.rs b/src/librustc_data_structures/indexed_vec.rs index c3c76e8160615..6aba4b9a34eb3 100644 --- a/src/librustc_data_structures/indexed_vec.rs +++ b/src/librustc_data_structures/indexed_vec.rs @@ -546,7 +546,7 @@ pub type Enumerated = iter::Map, IntoIdx>; impl IndexVec { #[inline] pub fn new() -> Self { - IndexVec { raw: Vec::new(), _marker: PhantomData } + IndexVec { raw: vec![], _marker: PhantomData } } #[inline] diff --git a/src/librustc_data_structures/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs index 6692903cd4fe9..5054cb269e2b6 100644 --- a/src/librustc_data_structures/thin_vec.rs +++ b/src/librustc_data_structures/thin_vec.rs @@ -25,7 +25,7 @@ impl From> for ThinVec { impl Into> for ThinVec { fn into(self) -> Vec { match self { - ThinVec(None) => Vec::new(), + ThinVec(None) => vec![], ThinVec(Some(vec)) => *vec, } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e615f8a484692..10dd1e313f7da 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -582,7 +582,7 @@ impl RustcDefaultCalls { match input { &Input::File(ref ifile) => { let path = &(*ifile); - let mut v = Vec::new(); + let mut v = vec![]; locator::list_file_metadata(&sess.target.target, path, &*cstore.metadata_loader, @@ -1086,7 +1086,7 @@ fn extra_compiler_flags() -> Option<(Vec, bool)> { return None; }; - let mut result = Vec::new(); + let mut result = vec![]; let mut excluded_cargo_defaults = false; for flag in ICE_REPORT_COMPILER_FLAGS { let prefix = if flag.len() == 1 { "-" } else { "--" }; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index af00037604430..88fc41375d332 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -502,7 +502,7 @@ fn gather_flowgraph_variants(sess: &Session) -> Vec { let print_moves = sess.opts.debugging_opts.flowgraph_print_moves; let print_assigns = sess.opts.debugging_opts.flowgraph_print_assigns; let print_all = sess.opts.debugging_opts.flowgraph_print_all; - let mut variants = Vec::new(); + let mut variants = vec![]; if print_all || print_loans { variants.push(borrowck_dot::Loans); } @@ -864,7 +864,7 @@ fn print_with_analysis( None }; - let mut out = Vec::new(); + let mut out = vec![]; tcx.analysis(LOCAL_CRATE)?; diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 361b5cd935712..19d4fb7d452d2 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -241,12 +241,12 @@ impl EmitterWriter { width_offset: usize, code_offset: usize) -> Vec<(usize, Style)> { if line.line_index == 0 { - return Vec::new(); + return vec![]; } let source_string = match file.get_line(line.line_index - 1) { Some(s) => s, - None => return Vec::new(), + None => return vec![], }; let line_offset = buffer.num_lines(); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 3269b85d0dd13..1dc6811499d5b 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -414,7 +414,7 @@ impl Handler { deduplicated_err_count: AtomicUsize::new(0), emitter: Lock::new(e), continue_after_error: AtomicBool::new(true), - delayed_span_bugs: Lock::new(Vec::new()), + delayed_span_bugs: Lock::new(vec![]), taught_diagnostics: Default::default(), emitted_diagnostic_codes: Default::default(), emitted_diagnostics: Default::default(), diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index ba893f5f93691..ae297e4fcb8dd 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -246,7 +246,7 @@ fn dump_graph(tcx: TyCtxt<'_>) { { // dump a .dot file in graphviz format: let dot_path = format!("{}.dot", path); - let mut v = Vec::new(); + let mut v = vec![]; dot::render(&GraphvizDepGraph(nodes, edges), &mut v).unwrap(); fs::write(dot_path, v).unwrap(); } diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index 13e2c5d1c574d..cb719ac42cafe 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -110,7 +110,7 @@ fn save_in(sess: &Session, path_buf: PathBuf, encode: F) } // generate the data in a memory buffer - let mut encoder = Encoder::new(Vec::new()); + let mut encoder = Encoder::new(vec![]); file_format::write_file_header(&mut encoder); encode(&mut encoder); diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index bb58d13498996..c9f42e61a3bb6 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -585,7 +585,7 @@ fn generated_output_paths( exact_name: bool, crate_name: &str, ) -> Vec { - let mut out_filenames = Vec::new(); + let mut out_filenames = vec![]; for output_type in sess.opts.output_types.keys() { let file = outputs.path(*output_type); match *output_type { diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 6ae5e94b11af3..321fb5e8a409d 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -42,7 +42,7 @@ use syntax_pos::edition::Edition; use std::{thread, panic}; pub fn diagnostics_registry() -> Registry { - let mut all_errors = Vec::new(); + let mut all_errors = vec![]; all_errors.extend_from_slice(&rustc::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_typeck::DIAGNOSTICS); all_errors.extend_from_slice(&rustc_resolve::DIAGNOSTICS); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c9605445c2401..02366056c0265 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1558,7 +1558,7 @@ impl ExplicitOutlivesRequirements { hir::GenericParamKind::Type { .. } => { Self::lifetimes_outliving_type(inferred_outlives, index) } - hir::GenericParamKind::Const { .. } => Vec::new(), + hir::GenericParamKind::Const { .. } => vec![], } } @@ -1612,7 +1612,7 @@ impl ExplicitOutlivesRequirements { bound_spans: Vec<(usize, Span)> ) -> Vec { if bounds.is_empty() { - return Vec::new(); + return vec![]; } if bound_spans.len() == bounds.len() { let (_, last_bound_span) = bound_spans[bound_spans.len()-1]; @@ -1620,7 +1620,7 @@ impl ExplicitOutlivesRequirements { // start from just after the parameter (span passed as argument) vec![lo.to(last_bound_span)] } else { - let mut merged = Vec::new(); + let mut merged = vec![]; let mut last_merged_i = None; let mut from_start = true; @@ -1680,7 +1680,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { let ty_generics = cx.tcx.generics_of(def_id); let mut bound_count = 0; - let mut lint_spans = Vec::new(); + let mut lint_spans = vec![]; for param in &hir_generics.params { let has_lifetime_bounds = param.bounds.iter().any(|bound| { @@ -1715,7 +1715,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements { ); } - let mut where_lint_spans = Vec::new(); + let mut where_lint_spans = vec![]; let mut dropped_predicate_count = 0; let num_predicates = hir_generics.where_clause.predicates.len(); for (i, where_predicate) in hir_generics.where_clause.predicates.iter().enumerate() { diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 82348e330f5b6..d3506a0e1a5ed 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -496,6 +496,7 @@ pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_early_pass(sess, false, false, box DefaultHashTypes::new()); store.register_early_pass(sess, false, false, box LintPassImpl); store.register_late_pass(sess, false, false, false, box TyTyKind); + store.register_late_pass(sess, false, false, false, box VecNew); store.register_group( sess, false, @@ -503,10 +504,11 @@ pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) { None, vec![ LintId::of(DEFAULT_HASH_TYPES), - LintId::of(USAGE_OF_TY_TYKIND), LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO), LintId::of(TY_PASS_BY_REFERENCE), LintId::of(USAGE_OF_QUALIFIED_TY), + LintId::of(USAGE_OF_TY_TYKIND), + LintId::of(VEC_NEW), ], ); } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 2073b317939d7..6903bf0b14a28 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -624,10 +624,10 @@ impl<'a> CrateLoader<'a> { ) } ProcMacro::Attr { name, client } => ( - name, SyntaxExtensionKind::Attr(Box::new(AttrProcMacro { client })), Vec::new() + name, SyntaxExtensionKind::Attr(Box::new(AttrProcMacro { client })), vec![] ), ProcMacro::Bang { name, client } => ( - name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new() + name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), vec![] ) }; diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index 5d8fabc7e69ae..1a5781f361ce1 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -143,7 +143,7 @@ impl CStore { } pub(super) fn crate_dependencies_in_rpo(&self, krate: CrateNum) -> Vec { - let mut ordering = Vec::new(); + let mut ordering = vec![]; self.push_dependencies_in_postorder(&mut ordering, krate); ordering.reverse(); ordering @@ -167,7 +167,7 @@ impl CStore { } pub(super) fn do_postorder_cnums_untracked(&self) -> Vec { - let mut ordering = Vec::new(); + let mut ordering = vec![]; for (num, v) in self.metas.borrow().iter_enumerated() { if let &Some(_) = v { self.push_dependencies_in_postorder(&mut ordering, num); diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 567b6b1a891bf..271560c98fca1 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -430,7 +430,7 @@ impl<'tcx> EncodeContext<'tcx> { // Encode the allocation index let interpret_alloc_index = { - let mut interpret_alloc_index = Vec::new(); + let mut interpret_alloc_index = vec![]; let mut n = 0; trace!("beginning to encode alloc ids"); loop { diff --git a/src/librustc_metadata/foreign_modules.rs b/src/librustc_metadata/foreign_modules.rs index b2e40282d9332..8d5b777535a47 100644 --- a/src/librustc_metadata/foreign_modules.rs +++ b/src/librustc_metadata/foreign_modules.rs @@ -6,7 +6,7 @@ use rustc::ty::TyCtxt; pub fn collect(tcx: TyCtxt<'_>) -> Vec { let mut collector = Collector { tcx, - modules: Vec::new(), + modules: vec![], }; tcx.hir().krate().visit_all_item_likes(&mut collector); return collector.modules; diff --git a/src/librustc_metadata/link_args.rs b/src/librustc_metadata/link_args.rs index 728fd004fcb69..052ddb6bf5b87 100644 --- a/src/librustc_metadata/link_args.rs +++ b/src/librustc_metadata/link_args.rs @@ -6,7 +6,7 @@ use syntax::symbol::sym; pub fn collect(tcx: TyCtxt<'_>) -> Vec { let mut collector = Collector { - args: Vec::new(), + args: vec![], }; tcx.hir().krate().visit_all_item_likes(&mut collector); diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 3832c8ee227de..1079b06e3e694 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -898,7 +898,7 @@ fn get_metadata_section_imp(target: &Target, // Header is okay -> inflate the actual metadata let compressed_bytes = &buf[header_len..]; debug!("inflating {} bytes of compressed metadata", compressed_bytes.len()); - let mut inflated = Vec::new(); + let mut inflated = vec![]; match DeflateDecoder::new(compressed_bytes).read_to_end(&mut inflated) { Ok(_) => { rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()) diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 5da5384f8aaa7..f6037030627ef 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -14,7 +14,7 @@ use syntax::{span_err, struct_span_err}; pub fn collect(tcx: TyCtxt<'_>) -> Vec { let mut collector = Collector { tcx, - libs: Vec::new(), + libs: vec![], }; tcx.hir().krate().visit_all_item_likes(&mut collector); collector.process_command_line(); diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 7b5fce4abbc4b..d38e9919d60c0 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -1254,7 +1254,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn get_moved_indexes(&mut self, location: Location, mpi: MovePathIndex) -> Vec { let body = self.body; - let mut stack = Vec::new(); + let mut stack = vec![]; stack.extend(body.predecessor_locations(location).map(|predecessor| { let is_back_edge = location.dominates(predecessor, &self.dominators); (predecessor, is_back_edge) @@ -1788,7 +1788,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ty::Ref(return_region, _, _) if return_region.has_name() && !is_closure => { // This is case 1 from above, return type is a named reference so we need to // search for relevant arguments. - let mut arguments = Vec::new(); + let mut arguments = vec![]; for (index, argument) in sig.inputs().skip_binder().iter().enumerate() { if let ty::Ref(argument_region, _, _) = argument.sty { if argument_region == return_region { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 31a9766af303a..93f5ec7787ef7 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -153,7 +153,7 @@ fn do_mir_borrowck<'a, 'tcx>( let body = &body; // no further changes let location_table = &LocationTable::new(body); - let mut errors_buffer = Vec::new(); + let mut errors_buffer = vec![]; let (move_data, move_errors): (MoveData<'tcx>, Option, MoveError<'tcx>)>>) = match MoveData::gather_moves(body, tcx) { Ok(move_data) => (move_data, None), @@ -2213,7 +2213,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // ``` // fn foo(_f: F) { } // fn main() { - // let var = Vec::new(); + // let var = vec![]; // foo(move || { // var.push(1); // }); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 3130b7cec5b4a..7f5d47d38882f 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -67,7 +67,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { &self, errors: Vec<(Place<'tcx>, MoveError<'tcx>)> ) -> Vec> { - let mut grouped_errors = Vec::new(); + let mut grouped_errors = vec![]; for (original_path, error) in errors { self.append_to_grouped_errors(&mut grouped_errors, original_path, error); } @@ -501,7 +501,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { - let mut suggestions: Vec<(Span, &str, String)> = Vec::new(); + let mut suggestions: Vec<(Span, &str, String)> = vec![]; for local in binds_to { let bind_to = &self.body.local_decls[*local]; if let Some( @@ -551,7 +551,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { - let mut noncopy_var_spans = Vec::new(); + let mut noncopy_var_spans = vec![]; for (j, local) in binds_to.into_iter().enumerate() { let bind_to = &self.body.local_decls[*local]; let binding_span = bind_to.source_info.span; diff --git a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs index fdf2af9f44ebc..5481cc71ea451 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs @@ -17,7 +17,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { crate fn dump_graphviz_scc_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> { let mut nodes_per_scc: IndexVec = self.constraint_sccs .all_sccs() - .map(|_| Vec::new()) + .map(|_| vec![]) .collect(); for region in self.definitions.indices() { diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 40388722bcac9..53711d8b24c68 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -277,7 +277,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { constraint_sccs, rev_constraint_graph: None, member_constraints, - member_constraints_applied: Vec::new(), + member_constraints_applied: vec![], closure_bounds_mapping, scc_universes, scc_representatives, diff --git a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs index d18a8e87453a5..7332ecd9b8de7 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs @@ -67,7 +67,7 @@ crate fn create( implicit_region_bound, constraints, universal_regions: universal_regions.clone(), - region_bound_pairs: Vec::new(), + region_bound_pairs: vec![], relations: UniversalRegionRelations { universal_regions: universal_regions.clone(), outlives: Default::default(), diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index dafb8c5f8f706..e24957a873dd2 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -224,7 +224,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = if let Some(ref borrows) = fake_borrows { self.calculate_fake_borrows(borrows, scrutinee_span) } else { - Vec::new() + vec![] }; // Step 5. Create everything else: the guards and the arms. @@ -636,7 +636,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }; let projection = UserTypeProjection { base: self.canonical_user_type_annotations.push(annotation), - projs: Vec::new(), + projs: vec![], }; let subpattern_user_ty = pattern_user_ty.push_projection(&projection, user_ty_span); self.visit_bindings(subpattern, subpattern_user_ty, f) diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs index b0d8581784606..1183160bb5f52 100644 --- a/src/librustc_mir/dataflow/graphviz.rs +++ b/src/librustc_mir/dataflow/graphviz.rs @@ -47,7 +47,7 @@ pub(crate) fn print_borrowck_graph_to<'a, 'tcx, BD, P>( P: Fn(&BD, BD::Idx) -> DebugFormatted, { let g = Graph { mbcx, phantom: PhantomData, render_idx }; - let mut v = Vec::new(); + let mut v = vec![]; dot::render(&g, &mut v)?; debug!("print_borrowck_graph_to path: {} def_id: {:?}", path.display(), mbcx.def_id); @@ -98,7 +98,7 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P> // +---------+----------------------------------+------------------+------------------+ // | [00-00] | _7 = const Foo::twiddle(move _8) | [0c-00] | [f3-0f] | // +---------+----------------------------------+------------------+------------------+ - let mut v = Vec::new(); + let mut v = vec![]; self.node_label_internal(n, &mut v, *n, self.mbcx.body()).unwrap(); dot::LabelText::html(String::from_utf8(v).unwrap()) } diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index f282c276e0926..b9135bb6282be 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -28,7 +28,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { MoveDataBuilder { body, tcx, - errors: Vec::new(), + errors: vec![], data: MoveData { moves: IndexVec::new(), loc_map: LocationMap::new(body), diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 938450c63aefc..5732eeaf5268f 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -61,7 +61,7 @@ impl<'tcx> MovePath<'tcx> { &self, move_paths: &IndexVec>, ) -> Vec { - let mut parents = Vec::new(); + let mut parents = vec![]; let mut curr_parent = self.parent; while let Some(parent_mpi) = curr_parent { diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 3d9349df5bedb..e616ab928b9f9 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -90,7 +90,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { body_owner: src_def_id, body_owner_kind, check_overflow, - control_flow_destroyed: Vec::new(), + control_flow_destroyed: vec![], } } diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 32a8c5cd3bb28..1c07a8c6f49c1 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -564,7 +564,7 @@ fn check_legality_of_move_bindings( } }) } - let span_vec = &mut Vec::new(); + let span_vec = &mut vec![]; let check_move = |p: &Pat, sub: Option<&Pat>, span_vec: &mut Vec| { // check legality of moving out of the enum diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 1baeda41498ed..fdb9cea7aab12 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -85,7 +85,7 @@ impl<'tcx> PatternTypeProjection<'tcx> { user_ty: self.user_ty, inferred_ty, }), - projs: Vec::new(), + projs: vec![], } } } @@ -1127,7 +1127,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { .map(|i| adt_subpattern(i as usize, None)) .collect(), slice: None, - suffix: Vec::new(), + suffix: vec![], } } _ => { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 007ec8cb2db5c..172836aa16132 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -207,7 +207,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { tcx, param_env, memory: Memory::new(tcx, memory_extra), - stack: Vec::new(), + stack: vec![], vtables: FxHashMap::default(), } } @@ -708,7 +708,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } match place { Place::Local { frame, local } => { - let mut allocs = Vec::new(); + let mut allocs = vec![]; let mut msg = format!("{:?}", local); if frame != self.cur_frame() { write!(msg, " ({} frames up)", self.cur_frame() - frame).unwrap(); @@ -767,7 +767,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn generate_stacktrace(&self, explicit_span: Option) -> Vec> { let mut last_span = None; - let mut frames = Vec::new(); + let mut frames = vec![]; for &Frame { instance, span, body, block, stmt, .. } in self.stack().iter().rev() { // make sure we don't emit frames that are duplicates of the previous if explicit_span == Some(span) { diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 3f2a76a77be36..f79a422175344 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -781,7 +781,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { let relocations = self.get(src.alloc_id)?.relocations(self, src, size); if relocations.is_empty() { // nothing to copy, ignore even the `length` loop - Vec::new() + vec![] } else { let mut new_relocations = Vec::with_capacity(relocations.len() * (length as usize)); for i in 0..length { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6e9390f77508b..1cf39edaf6960 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -225,7 +225,7 @@ impl<'tcx> InliningMap<'tcx> { fn new() -> InliningMap<'tcx> { InliningMap { index: FxHashMap::default(), - targets: Vec::new(), + targets: vec![], inlines: GrowableBitSet::with_capacity(1024), } } @@ -317,7 +317,7 @@ pub fn collect_crate_mono_items( // start monomorphizing from. fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec> { debug!("collecting roots"); - let mut roots = Vec::new(); + let mut roots = vec![]; { let entry_fn = tcx.entry_fn(LOCAL_CRATE); @@ -358,7 +358,7 @@ fn collect_items_rec<'tcx>( } debug!("BEGIN collect_items_rec({})", starting_point.to_string(tcx, true)); - let mut neighbors = Vec::new(); + let mut neighbors = vec![]; let recursion_depth_reset; match starting_point { diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index ad9db4e0aa8d8..53efcaf05b858 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -505,7 +505,7 @@ fn merge_codegen_units<'tcx>( fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<'tcx>, inlining_map: &InliningMap<'tcx>) -> PostInliningPartitioning<'tcx> { - let mut new_partitioning = Vec::new(); + let mut new_partitioning = vec![]; let mut mono_item_placements = FxHashMap::default(); let PreInliningPartitioning { @@ -922,7 +922,7 @@ fn collect_and_partition_mono_items( .map(|i| { let mut output = i.to_string(tcx, false); output.push_str(" @@"); - let mut empty = Vec::new(); + let mut empty = vec![]; let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty); cgus.sort_by_key(|(name, _)| *name); cgus.dedup(); diff --git a/src/librustc_mir/transform/add_call_guards.rs b/src/librustc_mir/transform/add_call_guards.rs index c08c33bc6ff8b..d0dc62583a55f 100644 --- a/src/librustc_mir/transform/add_call_guards.rs +++ b/src/librustc_mir/transform/add_call_guards.rs @@ -42,7 +42,7 @@ impl AddCallGuards { body.predecessors().iter().map(|ps| ps.len()).collect(); // We need a place to store the new blocks generated - let mut new_blocks = Vec::new(); + let mut new_blocks = vec![]; let cur_len = body.basic_blocks().len(); diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index de5af0a46b534..c4bd4ea75db7e 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -111,7 +111,7 @@ impl MirPass for AddRetag { // PART 2 // Retag return values of functions. Also escape-to-raw the argument of `drop`. // We collect the return destinations because we cannot mutate while iterating. - let mut returns: Vec<(SourceInfo, Place<'tcx>, BasicBlock)> = Vec::new(); + let mut returns: Vec<(SourceInfo, Place<'tcx>, BasicBlock)> = vec![]; for block_data in basic_blocks.iter_mut() { match block_data.terminator().kind { TerminatorKind::Call { ref destination, .. } => { diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 2ed3f7d5c26e2..7661338007aed 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -464,7 +464,7 @@ fn locals_live_across_suspend_points( ); let mut storage_liveness_map = FxHashMap::default(); - let mut live_locals_at_suspension_points = Vec::new(); + let mut live_locals_at_suspension_points = vec![]; for (block, data) in body.basic_blocks().iter_enumerated() { if let TerminatorKind::Yield { .. } = data.terminator().kind { @@ -942,7 +942,7 @@ fn insert_term_block<'tcx>(body: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> let term_block = BasicBlock::new(body.basic_blocks().len()); let source_info = source_info(body); body.basic_blocks_mut().push(BasicBlockData { - statements: Vec::new(), + statements: vec![], terminator: Some(Terminator { source_info, kind, @@ -973,7 +973,7 @@ fn insert_panic_block<'tcx>( let source_info = source_info(body); body.basic_blocks_mut().push(BasicBlockData { - statements: Vec::new(), + statements: vec![], terminator: Some(Terminator { source_info, kind: term, @@ -1047,7 +1047,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock { }; let source_info = source_info(body); body.basic_blocks_mut().push(BasicBlockData { - statements: Vec::new(), + statements: vec![], terminator: Some(Terminator { source_info, kind: term, @@ -1072,7 +1072,7 @@ where // Find the target for this suspension point, if applicable target(point).map(|target| { let block = BasicBlock::new(body.basic_blocks().len()); - let mut statements = Vec::new(); + let mut statements = vec![]; // Create StorageLive instructions for locals with live storage for i in 0..(body.local_decls.len()) { @@ -1163,7 +1163,7 @@ impl MirPass for StateTransform { state_substs, remap, storage_liveness, - suspension_points: Vec::new(), + suspension_points: vec![], new_ret_local, discr_ty, }; diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index f09a77d486c7e..53d6dff2b629d 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -23,7 +23,7 @@ impl MirPass for Lower128Bit { impl Lower128Bit { fn lower_128bit_ops<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let mut new_blocks = Vec::new(); + let mut new_blocks = vec![]; let cur_len = body.basic_blocks().len(); let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); diff --git a/src/librustc_plugin/build.rs b/src/librustc_plugin/build.rs index f1bf1111cf700..f946dc2878878 100644 --- a/src/librustc_plugin/build.rs +++ b/src/librustc_plugin/build.rs @@ -37,7 +37,7 @@ pub fn find_plugin_registrar(tcx: TyCtxt<'_>) -> Option { fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option { assert_eq!(cnum, LOCAL_CRATE); - let mut finder = RegistrarFinder { registrars: Vec::new() }; + let mut finder = RegistrarFinder { registrars: vec![] }; tcx.hir().krate().visit_all_item_likes(&mut finder); match finder.registrars.len() { diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 16fd8cccc8920..2f0fae0b544d6 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -389,7 +389,7 @@ impl<'a> Resolver<'a> { use_span: item.span, root_span: item.span, span: item.span, - module_path: Vec::new(), + module_path: vec![], vis: Cell::new(vis), used: Cell::new(used), }); @@ -808,7 +808,7 @@ impl<'a> Resolver<'a> { fn process_legacy_macro_imports(&mut self, item: &Item, module: Module<'a>, parent_scope: &ParentScope<'a>) -> bool { let mut import_all = None; - let mut single_imports = Vec::new(); + let mut single_imports = vec![]; for attr in &item.attrs { if attr.check_name(sym::macro_use) { if self.current_module.parent.is_some() { @@ -853,7 +853,7 @@ impl<'a> Resolver<'a> { use_span: item.span, root_span: span, span, - module_path: Vec::new(), + module_path: vec![], vis: Cell::new(ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))), used: Cell::new(false), }); @@ -977,7 +977,7 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> { module: self.resolver.current_module, expansion: self.expansion, legacy: self.current_legacy_scope, - derives: Vec::new(), + derives: vec![], }; self.resolver.build_reduced_graph_for_item(item, parent_scope); visit::walk_item(self, item); @@ -1061,7 +1061,7 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> { expansion: self.expansion, legacy: self.current_legacy_scope, // Let's hope discerning built-in attributes from derive helpers is not necessary - derives: Vec::new(), + derives: vec![], }; parent_scope.module.builtin_attrs.borrow_mut().push(( attr.path.segments[0].ident, parent_scope diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 4fee15c59b33d..07753b0b8c2f3 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -179,8 +179,8 @@ fn calc_unused_spans( return UnusedSpanResult::FlatUnused(use_tree.span, full_span); } - let mut unused_spans = Vec::new(); - let mut to_remove = Vec::new(); + let mut unused_spans = vec![]; + let mut to_remove = vec![]; let mut all_nested_unused = true; let mut previous_unused = false; for (pos, (use_tree, use_tree_id)) in nested.iter().enumerate() { @@ -284,7 +284,7 @@ pub fn check_crate(resolver: &mut Resolver<'_>, krate: &ast::Crate) { visit::walk_crate(&mut visitor, krate); for unused in visitor.unused_imports.values() { - let mut fixes = Vec::new(); + let mut fixes = vec![]; let mut spans = match calc_unused_spans(unused, unused.use_tree, unused.use_tree_id) { UnusedSpanResult::Used => continue, UnusedSpanResult::FlatUnused(span, remove) => { diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index e93a2315ca321..0ea60ff30d636 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -86,7 +86,7 @@ impl<'a> Resolver<'a> { err.code(DiagnosticId::Error("E0411".into())); err.span_label(span, format!("`Self` is only available in impls, traits, \ and type definitions")); - return (err, Vec::new()); + return (err, vec![]); } if is_self_value(path, ns) { debug!("smart_resolve_path_fragment: E0424, source={:?}", source); @@ -105,7 +105,7 @@ impl<'a> Resolver<'a> { with `self` parameter") } }); - return (err, Vec::new()); + return (err, vec![]); } // Try to lookup name in more relaxed fashion for better error reporting. @@ -489,7 +489,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { - Some((path, Vec::new())) + Some((path, vec![])) } else { None } @@ -544,7 +544,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result); if let PathResult::Module(..) = result { - Some((path, Vec::new())) + Some((path, vec![])) } else { None } @@ -584,7 +584,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { debug!("make_external_crate_suggestion: name={:?} path={:?} result={:?}", name, path, result); if let PathResult::Module(..) = result { - return Some((path, Vec::new())); + return Some((path, vec![])); } } @@ -636,7 +636,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { _ => format!("{}", ident), }; - let mut corrections: Vec<(Span, String)> = Vec::new(); + let mut corrections: Vec<(Span, String)> = vec![]; if !directive.is_nested() { // Assume this is the easy case of `use issue_59764::foo::makro;` and just remove // intermediate segments. diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1216a083700d9..46354bdaa3aba 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1203,13 +1203,13 @@ impl<'a> ModuleData<'a> { kind, normal_ancestor_id, resolutions: Default::default(), - single_segment_macro_resolutions: RefCell::new(Vec::new()), - multi_segment_macro_resolutions: RefCell::new(Vec::new()), - builtin_attrs: RefCell::new(Vec::new()), + single_segment_macro_resolutions: RefCell::new(vec![]), + multi_segment_macro_resolutions: RefCell::new(vec![]), + builtin_attrs: RefCell::new(vec![]), unresolved_invocations: Default::default(), no_implicit_prelude: false, - glob_importers: RefCell::new(Vec::new()), - globs: RefCell::new(Vec::new()), + glob_importers: RefCell::new(vec![]), + globs: RefCell::new(vec![]), traits: RefCell::new(None), populated: Cell::new(normal_ancestor_id.is_local()), span, @@ -1959,8 +1959,8 @@ impl<'a> Resolver<'a> { has_self: FxHashSet::default(), field_names: FxHashMap::default(), - determined_imports: Vec::new(), - indeterminate_imports: Vec::new(), + determined_imports: vec![], + indeterminate_imports: vec![], current_module: graph_root, ribs: PerNS { @@ -1968,7 +1968,7 @@ impl<'a> Resolver<'a> { type_ns: vec![Rib::new(ModuleRibKind(graph_root))], macro_ns: vec![Rib::new(ModuleRibKind(graph_root))], }, - label_ribs: Vec::new(), + label_ribs: vec![], current_trait_ref: None, current_self_type: None, @@ -1992,13 +1992,13 @@ impl<'a> Resolver<'a> { used_imports: FxHashSet::default(), maybe_unused_trait_imports: Default::default(), - maybe_unused_extern_crates: Vec::new(), + maybe_unused_extern_crates: vec![], unused_labels: FxHashMap::default(), - privacy_errors: Vec::new(), - ambiguity_errors: Vec::new(), - use_injections: Vec::new(), + privacy_errors: vec![], + ambiguity_errors: vec![], + use_injections: vec![], macro_expanded_macro_export_errors: BTreeSet::new(), arenas, @@ -2023,11 +2023,11 @@ impl<'a> Resolver<'a> { macro_defs, local_macro_def_scopes: FxHashMap::default(), name_already_seen: FxHashMap::default(), - potentially_unused_imports: Vec::new(), + potentially_unused_imports: vec![], struct_constructors: Default::default(), unused_macros: Default::default(), proc_macro_stubs: Default::default(), - current_type_ascription: Vec::new(), + current_type_ascription: vec![], injected_crate: None, active_features: features.declared_lib_features.iter().map(|(feat, ..)| *feat) @@ -4181,7 +4181,7 @@ impl<'a> Resolver<'a> { } }; - let mut names = Vec::new(); + let mut names = vec![]; if path.len() == 1 { // Search in lexical scope. // Walk backwards up the ribs in scope and collect candidates. @@ -4472,7 +4472,7 @@ impl<'a> Resolver<'a> { -> Vec { debug!("(getting traits containing item) looking for '{}'", ident.name); - let mut found_traits = Vec::new(); + let mut found_traits = vec![]; // Look for the current trait. if let Some((module, _)) = self.current_trait_ref { if self.resolve_ident_in_module( @@ -4514,7 +4514,7 @@ impl<'a> Resolver<'a> { assert!(ns == TypeNS || ns == ValueNS); let mut traits = module.traits.borrow_mut(); if traits.is_none() { - let mut collected_traits = Vec::new(); + let mut collected_traits = vec![]; module.for_each_child(|name, ns, binding| { if ns != TypeNS { return } match binding.res() { @@ -4580,10 +4580,11 @@ impl<'a> Resolver<'a> { -> Vec where FilterFn: Fn(Res) -> bool { - let mut candidates = Vec::new(); + let mut candidates = vec![]; let mut seen_modules = FxHashSet::default(); let not_local_module = crate_name.name != kw::Crate; - let mut worklist = vec![(start_module, Vec::::new(), not_local_module)]; + let mut worklist: Vec<(_, Vec, _)> + = vec![(start_module, vec![], not_local_module)]; while let Some((in_module, path_segments, @@ -4702,7 +4703,7 @@ impl<'a> Resolver<'a> { fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion)> { let mut result = None; let mut seen_modules = FxHashSet::default(); - let mut worklist = vec![(self.graph_root, Vec::new())]; + let mut worklist = vec![(self.graph_root, vec![])]; while let Some((in_module, path_segments)) = worklist.pop() { // abort if the module is already found @@ -4743,7 +4744,7 @@ impl<'a> Resolver<'a> { self.find_module(def_id).map(|(enum_module, enum_import_suggestion)| { self.populate_module_if_necessary(enum_module); - let mut variants = Vec::new(); + let mut variants = vec![]; enum_module.for_each_child_stable(|ident, _, name_binding| { if let Res::Def(DefKind::Variant, _) = name_binding.res() { let mut segms = enum_import_suggestion.path.segments.clone(); @@ -4906,7 +4907,7 @@ impl<'a> Resolver<'a> { let note_msg = format!("`{ident}` could{also} refer to {what}", ident = ident, also = also, what = what); - let mut help_msgs = Vec::new(); + let mut help_msgs = vec![]; if b.is_glob_import() && (kind == AmbiguityKind::GlobVsGlob || kind == AmbiguityKind::GlobVsExpanded || kind == AmbiguityKind::GlobVsOuter && @@ -5359,7 +5360,7 @@ fn show_candidates(err: &mut DiagnosticBuilder<'_>, /// A somewhat inefficient routine to obtain the name of a module. fn module_to_string(module: Module<'_>) -> Option { - let mut names = Vec::new(); + let mut names = vec![]; fn collect_mod(names: &mut Vec, module: Module<'_>) { if let ModuleKind::Def(.., name) = module.kind { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index fc1becfe30960..3e33a04055845 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -224,9 +224,9 @@ impl<'a> base::Resolver for Resolver<'a> { InvocationKind::Attr { ref attr, ref derives, after_derive, .. } => (&attr.path, MacroKind::Attr, derives.clone(), after_derive), InvocationKind::Bang { ref mac, .. } => - (&mac.node.path, MacroKind::Bang, Vec::new(), false), + (&mac.node.path, MacroKind::Bang, vec![], false), InvocationKind::Derive { ref path, .. } => - (path, MacroKind::Derive, Vec::new(), false), + (path, MacroKind::Derive, vec![], false), InvocationKind::DeriveContainer { .. } => return Ok(None), }; @@ -262,7 +262,7 @@ impl<'a> base::Resolver for Resolver<'a> { impl<'a> Resolver<'a> { pub fn dummy_parent_scope(&self) -> ParentScope<'a> { - self.invoc_parent_scope(Mark::root(), Vec::new()) + self.invoc_parent_scope(Mark::root(), vec![]) } fn invoc_parent_scope(&self, invoc_id: Mark, derives: Vec) -> ParentScope<'a> { @@ -598,7 +598,7 @@ impl<'a> Resolver<'a> { WhereToResolve::DeriveHelpers => { let mut result = Err(Determinacy::Determined); for derive in &parent_scope.derives { - let parent_scope = ParentScope { derives: Vec::new(), ..*parent_scope }; + let parent_scope = ParentScope { derives: vec![], ..*parent_scope }; match self.resolve_macro_path(derive, MacroKind::Derive, &parent_scope, true, force) { Ok((Some(ext), _)) => if ext.helper_attrs.contains(&ident.name) { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 5edfe923e68a2..9caedf0271cdf 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -951,7 +951,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { UnresolvedImportError { span, label: Some(label), - note: Vec::new(), + note: vec![], suggestion, } } @@ -996,7 +996,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { return Some(UnresolvedImportError { span: directive.span, label: Some(String::from("cannot glob-import a module into itself")), - note: Vec::new(), + note: vec![], suggestion: None, }); } @@ -1116,7 +1116,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { directive, module, ident, ) { Some((suggestion, note)) => (suggestion.or(lev_suggestion), note), - _ => (lev_suggestion, Vec::new()), + _ => (lev_suggestion, vec![]), }; let label = match module { @@ -1367,9 +1367,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> { // reporting conflicts, and reporting unresolved imports. fn finalize_resolutions_in(&mut self, module: Module<'b>) { // Since import resolution is finished, globs will not define any more names. - *module.globs.borrow_mut() = Vec::new(); + *module.globs.borrow_mut() = vec![]; - let mut reexports = Vec::new(); + let mut reexports = vec![]; for (&(ident, ns), resolution) in module.resolutions.borrow().iter() { let resolution = &mut *resolution.borrow_mut(); diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs index e294e63982de4..ffc7af7773695 100644 --- a/src/librustc_target/spec/linux_musl_base.rs +++ b/src/librustc_target/spec/linux_musl_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { // Make sure that the linker/gcc really don't pull in anything, including // default objects, libs, etc. - base.pre_link_args_crt.insert(LinkerFlavor::Gcc, Vec::new()); + base.pre_link_args_crt.insert(LinkerFlavor::Gcc, vec![]); base.pre_link_args_crt.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string()); // At least when this was tested, the linker would not add the diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 3054ffabb4f1f..c3dbba42b855d 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -780,7 +780,7 @@ impl Default for TargetOptions { pre_link_args: LinkArgs::new(), pre_link_args_crt: LinkArgs::new(), post_link_args: LinkArgs::new(), - asm_args: Vec::new(), + asm_args: vec![], cpu: "generic".to_string(), features: String::new(), dynamic_linking: false, @@ -813,13 +813,13 @@ impl Default for TargetOptions { position_independent_executables: false, needs_plt: false, relro_level: RelroLevel::None, - pre_link_objects_exe: Vec::new(), - pre_link_objects_exe_crt: Vec::new(), - pre_link_objects_dll: Vec::new(), - post_link_objects: Vec::new(), - post_link_objects_crt: Vec::new(), + pre_link_objects_exe: vec![], + pre_link_objects_exe_crt: vec![], + pre_link_objects_dll: vec![], + post_link_objects: vec![], + post_link_objects_crt: vec![], late_link_args: LinkArgs::new(), - link_env: Vec::new(), + link_env: vec![], archive_format: "gnu".to_string(), custom_unwind_resume: false, allow_asm: true, diff --git a/src/librustc_target/spec/wasm32_base.rs b/src/librustc_target/spec/wasm32_base.rs index 39a8ce9282573..d2148eba22b1f 100644 --- a/src/librustc_target/spec/wasm32_base.rs +++ b/src/librustc_target/spec/wasm32_base.rs @@ -2,8 +2,8 @@ use std::collections::BTreeMap; use super::{LldFlavor, TargetOptions, PanicStrategy, LinkerFlavor}; pub fn options() -> TargetOptions { - let mut lld_args = Vec::new(); - let mut clang_args = Vec::new(); + let mut lld_args = vec![]; + let mut clang_args = vec![]; let mut arg = |arg: &str| { lld_args.push(arg.to_string()); clang_args.push(format!("-Wl,{}", arg)); diff --git a/src/librustc_target/spec/wasm32_wasi.rs b/src/librustc_target/spec/wasm32_wasi.rs index bb33493a77333..3c7cf2f9f9df8 100644 --- a/src/librustc_target/spec/wasm32_wasi.rs +++ b/src/librustc_target/spec/wasm32_wasi.rs @@ -81,7 +81,7 @@ pub fn target() -> Result { options .pre_link_args .entry(LinkerFlavor::Gcc) - .or_insert(Vec::new()) + .or_insert(vec![]) .push("--target=wasm32-wasi".to_string()); // When generating an executable be sure to put the startup object at the diff --git a/src/librustc_traits/chalk_context/unify.rs b/src/librustc_traits/chalk_context/unify.rs index 1f9090324414b..52c40dbac09f9 100644 --- a/src/librustc_traits/chalk_context/unify.rs +++ b/src/librustc_traits/chalk_context/unify.rs @@ -54,8 +54,8 @@ impl ChalkTypeRelatingDelegate<'me, 'tcx> { Self { infcx, environment, - goals: Vec::new(), - constraints: Vec::new(), + goals: vec![], + constraints: vec![], } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d314228a232c9..dd6cf56b1e9ca 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -969,8 +969,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ast_bounds: &[hir::GenericBound], bounds: &mut Bounds<'tcx>, ) { - let mut trait_bounds = Vec::new(); - let mut region_bounds = Vec::new(); + let mut trait_bounds = vec![]; + let mut region_bounds = vec![]; for ast_bound in ast_bounds { match *ast_bound { @@ -1214,7 +1214,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.tcx(); let mut bounds = Bounds::default(); - let mut potential_assoc_types = Vec::new(); + let mut potential_assoc_types = vec![]; let dummy_self = self.tcx().types.trait_object_dummy_self; // FIXME: we want to avoid collecting into a `Vec` here, but simply cloning the iterator is // not straightforward due to the borrow checker. @@ -1351,9 +1351,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // `Iterator`. (true, potential_assoc_types) } else { - (false, Vec::new()) + (false, vec![]) }; - let mut suggestions = Vec::new(); + let mut suggestions = vec![]; for (i, item_def_id) in associated_types.iter().enumerate() { let assoc_item = tcx.associated_item(*item_def_id); err.span_label( diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 531ecd11dcb20..b870aa4616b20 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -116,7 +116,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { param(0)) } "fence" | "singlethreadfence" => { - (0, Vec::new(), tcx.mk_unit()) + (0, vec![], tcx.mk_unit()) } op => { struct_span_err!(tcx.sess, it.span, E0092, @@ -128,13 +128,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { }; (n_tps, inputs, output, hir::Unsafety::Unsafe) } else if &name[..] == "abort" || &name[..] == "unreachable" { - (0, Vec::new(), tcx.types.never, hir::Unsafety::Unsafe) + (0, vec![], tcx.types.never, hir::Unsafety::Unsafe) } else { let unsafety = intrisic_operation_unsafety(&name[..]); let (n_tps, inputs, output) = match &name[..] { - "breakpoint" => (0, Vec::new(), tcx.mk_unit()), + "breakpoint" => (0, vec![], tcx.mk_unit()), "size_of" | - "pref_align_of" | "min_align_of" => (1, Vec::new(), tcx.types.usize), + "pref_align_of" | "min_align_of" => (1, vec![], tcx.types.usize), "size_of_val" | "min_align_of_val" => { (1, vec![ tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::INNERMOST, @@ -143,8 +143,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { ], tcx.types.usize) } "rustc_peek" => (1, vec![param(0)], param(0)), - "panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()), - "init" => (1, Vec::new(), param(0)), + "panic_if_uninhabited" => (1, vec![], tcx.mk_unit()), + "init" => (1, vec![], param(0)), "forget" => (1, vec![param(0)], tcx.mk_unit()), "transmute" => (2, vec![ param(0) ], param(1)), "move_val_init" => { @@ -166,10 +166,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { "drop_in_place" => { (1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_unit()) } - "needs_drop" => (1, Vec::new(), tcx.types.bool), + "needs_drop" => (1, vec![], tcx.types.bool), - "type_name" => (1, Vec::new(), tcx.mk_static_str()), - "type_id" => (1, Vec::new(), tcx.types.u64), + "type_name" => (1, vec![], tcx.mk_static_str()), + "type_id" => (1, vec![], tcx.types.u64), "offset" | "arith_offset" => { (1, vec![ diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index a7e4f8e5c6289..a59d2bd49332a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -236,7 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) .collect() } - _ => Vec::new(), + _ => vec![], }; return Err(IllegalSizedBound(candidates)); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 41979509a3c5d..67eac96598f19 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -360,9 +360,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .unwrap_or_else(|_| span_bug!(span, "instantiating {:?} failed?", ty)); let ty = self.structurally_resolved_type(span, ty.value); assert_eq!(ty, self.tcx.types.err); - return Err(MethodError::NoMatch(NoMatchData::new(Vec::new(), - Vec::new(), - Vec::new(), + return Err(MethodError::NoMatch(NoMatchData::new(vec![], + vec![], + vec![], None, mode))); } @@ -482,15 +482,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { mode, method_name, return_type, - inherent_candidates: Vec::new(), - extension_candidates: Vec::new(), + inherent_candidates: vec![], + extension_candidates: vec![], impl_dups: FxHashSet::default(), orig_steps_var_values, steps, - static_candidates: Vec::new(), + static_candidates: vec![], allow_similar_names: false, private_candidate: None, - unsatisfied_predicates: Vec::new(), + unsatisfied_predicates: vec![], is_suggestion, } } @@ -1112,8 +1112,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { fn pick_method(&mut self, self_ty: Ty<'tcx>) -> Option> { debug!("pick_method(self_ty={})", self.ty_to_string(self_ty)); - let mut possibly_unsatisfied_predicates = Vec::new(); - let mut unstable_candidates = Vec::new(); + let mut possibly_unsatisfied_predicates = vec![]; + let mut unstable_candidates = vec![]; for (kind, candidates) in &[ ("inherent", &self.inherent_candidates), @@ -1635,7 +1635,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } else { self.fcx .associated_item(def_id, name, Namespace::Value) - .map_or(Vec::new(), |x| vec![x]) + .map_or(vec![], |x| vec![x]) } } else { self.tcx.associated_items(def_id).collect() diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 77d45cfa63c10..8d7defed659df 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -640,10 +640,10 @@ impl Inherited<'a, 'tcx> { infcx, fulfillment_cx: RefCell::new(TraitEngine::new(tcx)), locals: RefCell::new(Default::default()), - deferred_sized_obligations: RefCell::new(Vec::new()), + deferred_sized_obligations: RefCell::new(vec![]), deferred_call_resolutions: RefCell::new(Default::default()), - deferred_cast_checks: RefCell::new(Vec::new()), - deferred_generator_interiors: RefCell::new(Vec::new()), + deferred_cast_checks: RefCell::new(vec![]), + deferred_generator_interiors: RefCell::new(vec![]), opaque_types: RefCell::new(Default::default()), implicit_region_bound, body_id, @@ -1636,8 +1636,8 @@ fn check_impl_items_against_trait<'tcx>( } // Check for missing items from trait - let mut missing_items = Vec::new(); - let mut invalidated_items = Vec::new(); + let mut missing_items = vec![]; + let mut invalidated_items = vec![]; let associated_type_overridden = overridden_associated_type.is_some(); for trait_item in tcx.associated_items(impl_trait_ref.def_id) { let is_implemented = trait_def.ancestors(tcx, impl_id) @@ -1759,7 +1759,7 @@ fn check_packed(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { struct_span_err!(tcx.sess, sp, E0587, "type has conflicting packed and align representation hints").emit(); } - else if check_packed_inner(tcx, def_id, &mut Vec::new()) { + else if check_packed_inner(tcx, def_id, &mut vec![]) { struct_span_err!(tcx.sess, sp, E0588, "packed type cannot transitively contain a `[repr(align)]` type").emit(); } @@ -2143,7 +2143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { diverges: Cell::new(Diverges::Maybe), has_errors: Cell::new(false), enclosing_breakables: RefCell::new(EnclosingBreakables { - stack: Vec::new(), + stack: vec![], by_id: Default::default(), }), inh, @@ -3284,7 +3284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let formal_ret = self.resolve_type_vars_with_obligations(formal_ret); let ret_ty = match expected_ret.only_has_type(self) { Some(ret) => ret, - None => return Vec::new() + None => return vec![] }; let expect_args = self.fudge_inference_if_ok(|| { // Attempt to apply a subtyping relationship between the formal diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 68e5e7d4fd245..63cfd93cce968 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -632,7 +632,7 @@ fn check_existential_types<'fcx, 'tcx>( ty: Ty<'tcx>, ) -> Vec> { trace!("check_existential_types(ty={:?})", ty); - let mut substituted_predicates = Vec::new(); + let mut substituted_predicates = vec![]; ty.fold_with(&mut ty::fold::BottomUpFolder { tcx: fcx.tcx, ty_op: |ty| { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 145b37ff907ab..9ce786ace0625 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -370,7 +370,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root); let common_local_id_root = fcx_tables.local_id_root.unwrap(); - let mut errors_buffer = Vec::new(); + let mut errors_buffer = vec![]; for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() { let hir_id = hir::HirId { owner: common_local_id_root.index, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5420a2407e66f..74099f78f27bf 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2150,7 +2150,7 @@ fn explicit_predicates_of( let trait_item = tcx.hir().trait_item(trait_item_ref.id); let bounds = match trait_item.node { hir::TraitItemKind::Type(ref bounds, _) => bounds, - _ => return Vec::new().into_iter() + _ => return vec![].into_iter() }; let assoc_ty = diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index b75a0912657fa..bfc58cc24b625 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -58,7 +58,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>) contravariant, invariant, bivariant, - constraints: Vec::new(), + constraints: vec![], }; tcx.hir().krate().visit_all_item_likes(&mut constraint_cx); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8801e89a0cfc4..b963ac3617b60 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -366,9 +366,9 @@ impl Default for Generics { /// Creates an instance of `Generics`. fn default() -> Generics { Generics { - params: Vec::new(), + params: vec![], where_clause: WhereClause { - predicates: Vec::new(), + predicates: vec![], span: DUMMY_SP, }, span: DUMMY_SP, @@ -979,7 +979,7 @@ impl Expr { fn to_bound(&self) -> Option { match &self.node { ExprKind::Path(None, path) => Some(GenericBound::Trait( - PolyTraitRef::new(Vec::new(), path.clone(), self.span), + PolyTraitRef::new(vec![], path.clone(), self.span), TraitBoundModifier::None, )), _ => None, diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index b41f1047fcba3..a6ef3e3a23d2c 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -739,7 +739,7 @@ impl IntType { pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { use ReprAttr::*; - let mut acc = Vec::new(); + let mut acc = vec![]; let diagnostic = &sess.span_diagnostic; if attr.path == sym::repr { if let Some(items) = attr.meta_item_list() { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index a9f2429560ad2..19a5ecefe9192 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -293,11 +293,11 @@ impl Attribute { where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { if self.tokens.is_empty() { - return Ok(Vec::new()); + return Ok(vec![]); } self.parse(sess, |parser| { parser.expect(&token::OpenDelim(token::Paren))?; - let mut list = Vec::new(); + let mut list = vec![]; while !parser.eat(&token::CloseDelim(token::Paren)) { list.push(f(parser)?); if !parser.eat(&token::Comma) { @@ -535,7 +535,7 @@ impl MetaItemKind { TokenStream::new(vec) } MetaItemKind::List(ref list) => { - let mut tokens = Vec::new(); + let mut tokens = vec![]; for (i, item) in list.iter().enumerate() { if i > 0 { tokens.push(TokenTree::token(token::Comma, span).into()); @@ -571,7 +571,7 @@ impl MetaItemKind { }; let mut tokens = delimited.into_trees().peekable(); - let mut result = Vec::new(); + let mut result = vec![]; while let Some(..) = tokens.peek() { let item = NestedMetaItem::from_tokens(&mut tokens)?; result.push(item); diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 1ab367f73c1b3..fbf456d789d0c 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -39,8 +39,8 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, edition: Edition, if let Some(attrs) = strip_unconfigured.configure(krate.attrs) { krate.attrs = attrs; } else { // the entire crate is unconfigured - krate.attrs = Vec::new(); - krate.module.items = Vec::new(); + krate.attrs = vec![]; + krate.module.items = vec![]; return (krate, Features::new()); } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index ee640a1603a6c..7c95dfb0c190c 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -61,7 +61,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt<'_>, } } }); - MacEager::expr(ecx.expr_tuple(span, Vec::new())) + MacEager::expr(ecx.expr_tuple(span, vec![])) } pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>, @@ -199,7 +199,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt<'_>, MacEager::items(smallvec![ P(ast::Item { ident, - attrs: Vec::new(), + attrs: vec![], id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Const( ty, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 37d5885db60c3..ee42ea874883f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -437,7 +437,7 @@ impl DummyResult { pub fn raw_expr(sp: Span, is_error: bool) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) }, + node: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(vec![]) }, span: sp, attrs: ThinVec::new(), }) @@ -456,7 +456,7 @@ impl DummyResult { pub fn raw_ty(sp: Span, is_error: bool) -> P { P(ast::Ty { id: ast::DUMMY_NODE_ID, - node: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(Vec::new()) }, + node: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(vec![]) }, span: sp }) } @@ -634,7 +634,7 @@ impl SyntaxExtension { local_inner_macros: false, stability: None, deprecation: None, - helper_attrs: Vec::new(), + helper_attrs: vec![], edition, kind, } @@ -651,7 +651,7 @@ impl SyntaxExtension { pub fn dummy_derive(edition: Edition) -> SyntaxExtension { fn expander(_: &mut ExtCtxt<'_>, _: Span, _: &ast::MetaItem, _: Annotatable) -> Vec { - Vec::new() + vec![] } SyntaxExtension::default(SyntaxExtensionKind::Derive(Box::new(expander)), edition) } @@ -737,7 +737,7 @@ impl<'a> ExtCtxt<'a> { current_expansion: ExpansionData { mark: Mark::root(), depth: 0, - module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }), + module: Rc::new(ModuleData { mod_path: vec![], directory: PathBuf::new() }), directory_ownership: DirectoryOwnership::Owned { relative: None }, }, expansions: FxHashMap::default(), @@ -966,7 +966,7 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree]) -> Option>> { let mut p = cx.new_parser_from_tts(tts); - let mut es = Vec::new(); + let mut es = vec![]; while p.token != token::Eof { let mut expr = panictry!(p.parse_expr()); cx.expander().visit_expr(&mut expr); diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index baf1031de1e7c..ecce86bc250bf 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -454,7 +454,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef { ast::PolyTraitRef { - bound_generic_params: Vec::new(), + bound_generic_params: vec![], trait_ref: self.trait_ref(path), span, } @@ -723,7 +723,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_vec_ng(&self, sp: Span) -> P { self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]), - Vec::new()) + vec![]) } fn expr_vec_slice(&self, sp: Span, exprs: Vec>) -> P { self.expr_addr_of(sp, self.expr_vec(sp, exprs)) @@ -938,7 +938,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn lambda0(&self, span: Span, body: P) -> P { - self.lambda(span, Vec::new(), body) + self.lambda(span, vec![], body) } fn lambda1(&self, span: Span, body: P, ident: ast::Ident) -> P { @@ -1003,7 +1003,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { body: P) -> P { self.item(span, name, - Vec::new(), + vec![], ast::ItemKind::Fn(self.fn_decl(inputs, ast::FunctionRetTy::Ty(output)), ast::FnHeader { unsafety: ast::Unsafety::Normal, @@ -1038,7 +1038,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ty, ident: None, vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited), - attrs: Vec::new(), + attrs: vec![], id: ast::DUMMY_NODE_ID, } }).collect(); @@ -1053,7 +1053,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::Variant_ { ident, id: ast::DUMMY_NODE_ID, - attrs: Vec::new(), + attrs: vec![], data: vdata, disr_expr: None, }) @@ -1062,7 +1062,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_enum_poly(&self, span: Span, name: Ident, enum_definition: ast::EnumDef, generics: Generics) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::Enum(enum_definition, generics)) + self.item(span, name, vec![], ast::ItemKind::Enum(enum_definition, generics)) } fn item_enum(&self, span: Span, name: Ident, @@ -1083,7 +1083,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_struct_poly(&self, span: Span, name: Ident, struct_def: ast::VariantData, generics: Generics) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::Struct(struct_def, generics)) + self.item(span, name, vec![], ast::ItemKind::Struct(struct_def, generics)) } fn item_mod(&self, span: Span, inner_span: Span, name: Ident, @@ -1102,7 +1102,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn item_extern_crate(&self, span: Span, name: Ident) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::ExternCrate(None)) + self.item(span, name, vec![], ast::ItemKind::ExternCrate(None)) } fn item_static(&self, @@ -1112,7 +1112,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability, expr: P) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::Static(ty, mutbl, expr)) + self.item(span, name, vec![], ast::ItemKind::Static(ty, mutbl, expr)) } fn item_const(&self, @@ -1121,12 +1121,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ty: P, expr: P) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::Const(ty, expr)) + self.item(span, name, vec![], ast::ItemKind::Const(ty, expr)) } fn item_ty_poly(&self, span: Span, name: Ident, ty: P, generics: Generics) -> P { - self.item(span, name, Vec::new(), ast::ItemKind::Ty(ty, generics)) + self.item(span, name, vec![], ast::ItemKind::Ty(ty, generics)) } fn item_ty(&self, span: Span, name: Ident, ty: P) -> P { diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 1c15deab37377..206aeafa9faf9 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -11,7 +11,7 @@ use syntax_pos::Span; use rustc_data_structures::fx::FxHashSet; pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec) -> Vec { - let mut result = Vec::new(); + let mut result = vec![]; attrs.retain(|attr| { if attr.path != sym::derive { return true; diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 7fc62e357c5c4..de948026eac47 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -303,9 +303,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // The output fragments also go through expansion recursively until no invocations are left. // Unresolved macros produce dummy outputs as a recovery measure. invocations.reverse(); - let mut expanded_fragments = Vec::new(); + let mut expanded_fragments = vec![]; let mut derives: FxHashMap> = FxHashMap::default(); - let mut undetermined_invocations = Vec::new(); + let mut undetermined_invocations = vec![]; let (mut progress, mut force) = (false, !self.monotonic); loop { let invoc = if let Some(invoc) = invocations.pop() { @@ -390,7 +390,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; if expanded_fragments.len() < depth { - expanded_fragments.push(Vec::new()); + expanded_fragments.push(vec![]); } expanded_fragments[depth - 1].push((mark, expanded_fragment)); if !self.cx.ecfg.single_step { @@ -435,7 +435,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { features: self.cx.ecfg.features, }, cx: self.cx, - invocations: Vec::new(), + invocations: vec![], monotonic: self.monotonic, }; fragment.mut_visit_with(&mut collector); @@ -878,7 +878,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { -> (Option, Vec, /* after_derive */ bool) where T: HasAttrs, { - let (mut attr, mut traits, mut after_derive) = (None, Vec::new(), false); + let (mut attr, mut traits, mut after_derive) = (None, vec![], false); item.visit_attrs(|mut attrs| { attr = self.find_attr_invoc(&mut attrs, &mut after_derive); diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index b2b8bfb09b45e..c4a37898b86a6 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -15,14 +15,14 @@ use rustc_data_structures::fx::FxHashMap; pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { fn mac_placeholder() -> ast::Mac { dummy_spanned(ast::Mac_ { - path: ast::Path { span: DUMMY_SP, segments: Vec::new() }, + path: ast::Path { span: DUMMY_SP, segments: vec![] }, tts: TokenStream::empty().into(), delim: ast::MacDelimiter::Brace, }) } let ident = ast::Ident::invalid(); - let attrs = Vec::new(); + let attrs = vec![]; let generics = ast::Generics::default(); let vis = dummy_spanned(ast::VisibilityKind::Inherited); let span = DUMMY_SP; diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index fc8aa4793bc61..8c7559d119d88 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -677,7 +677,7 @@ pub fn parse( // there are frequently *no* others! -- are allocated on the heap. let mut initial = initial_matcher_pos(ms, parser.token.span); let mut cur_items = smallvec![MatcherPosHandle::Ref(&mut initial)]; - let mut next_items = Vec::new(); + let mut next_items = vec![]; loop { // Matcher positions black-box parsed by parser.rs (`parser`) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 5c6438a7ef534..f0f9d0b8047d9 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -436,7 +436,7 @@ pub fn compile( local_inner_macros, stability: attr::find_stability(&sess, &def.attrs, def.span), deprecation: attr::find_deprecation(&sess, &def.attrs, def.span), - helper_attrs: Vec::new(), + helper_attrs: vec![], edition, } } @@ -728,7 +728,7 @@ struct TokenSet { impl TokenSet { // Returns a set for the empty sequence. fn empty() -> Self { - TokenSet { tokens: Vec::new(), maybe_empty: true } + TokenSet { tokens: vec![], maybe_empty: true } } // Returns the set `{ tok }` for the single-token (and thus diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index ccf9db842ab6e..15ea301843dea 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -177,7 +177,7 @@ pub fn parse( macro_node_id: NodeId, ) -> Vec { // Will contain the final collection of `self::TokenTree` - let mut result = Vec::new(); + let mut result = vec![]; // For each token tree in `input`, parse the token into a `self::TokenTree`, consuming // additional trees if need be. diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index e04fd2ddc05bc..9d9c9a7836d05 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -82,7 +82,7 @@ pub fn transcribe( // As we descend in the RHS, we will need to be able to match nested sequences of matchers. // `repeats` keeps track of where we are in matching at each level, with the last element being // the most deeply nested sequence. This is used as a stack. - let mut repeats = Vec::new(); + let mut repeats = vec![]; // `result` contains resulting token stream from the TokenTree we just finished processing. At // the end, this will contain the full result of transcription, but at arbitrary points during @@ -95,8 +95,8 @@ pub fn transcribe( // // Thus, if we try to pop the `result_stack` and it is empty, we have reached the top-level // again, and we are done transcribing. - let mut result: Vec = Vec::new(); - let mut result_stack = Vec::new(); + let mut result: Vec = vec![]; + let mut result_stack = vec![]; loop { // Look at the last frame on the stack. diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e3628d908fb1e..50778e2b75d09 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -69,8 +69,8 @@ macro_rules! declare_features { impl Features { pub fn new() -> Features { Features { - declared_lang_features: Vec::new(), - declared_lib_features: Vec::new(), + declared_lang_features: vec![], + declared_lib_features: vec![], $($feature: false),+ } } diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index b28d48b9445fd..b8122f93a9a2a 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -28,7 +28,7 @@ impl<'a> Parser<'a> { /// Parse attributes that appear before an item crate fn parse_outer_attributes(&mut self) -> PResult<'a, Vec> { - let mut attrs: Vec = Vec::new(); + let mut attrs: Vec = vec![]; let mut just_parsed_doc_comment = false; loop { debug!("parse_outer_attributes: self.token={:?}", self.token); diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index ae24047ac8249..85012e3a017a4 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -664,7 +664,7 @@ impl<'a> Parser<'a> { self.expect(&token::ModSep)?; let mut path = ast::Path { - segments: Vec::new(), + segments: vec![], span: DUMMY_SP, }; self.parse_path_segments(&mut path.segments, T::PATH_STYLE)?; diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 6ed2a7adad1c2..13a7e4d520c31 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -139,7 +139,7 @@ fn push_blank_line_comment(rdr: &StringReader<'_>, comments: &mut Vec) debug!(">>> blank-line comment"); comments.push(Comment { style: BlankLine, - lines: Vec::new(), + lines: vec![], pos: rdr.pos, }); } @@ -174,7 +174,7 @@ fn read_line_comments(rdr: &mut StringReader<'_>, comments: &mut Vec) { debug!(">>> line comments"); let p = rdr.pos; - let mut lines: Vec = Vec::new(); + let mut lines: Vec = vec![]; while rdr.ch_is('/') && rdr.nextch_is('/') { let line = rdr.read_one_line_comment(); debug!("{}", line); @@ -230,7 +230,7 @@ fn read_block_comment(rdr: &mut StringReader<'_>, comments: &mut Vec) { debug!(">>> block comment"); let p = rdr.pos; - let mut lines: Vec = Vec::new(); + let mut lines: Vec = vec![]; // Count the number of chars since the start of the line by rescanning. let src_index = rdr.src_index(rdr.source_file.line_begin_pos(rdr.pos)); @@ -345,7 +345,7 @@ pub fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec = Vec::new(); + let mut comments: Vec = vec![]; let mut code_to_the_left = false; // Only code let mut anything_to_the_left = false; // Code or comments diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index d0c4e8d6a5634..2c7961c355228 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -92,7 +92,7 @@ impl<'a> StringReader<'a> { source_file, end_src_index: src.len(), src, - fatal_errs: Vec::new(), + fatal_errs: vec![], override_span, } } @@ -167,7 +167,7 @@ impl<'a> StringReader<'a> { } pub fn buffer_fatal_errors(&mut self) -> Vec { - let mut buffer = Vec::new(); + let mut buffer = vec![]; for err in self.fatal_errs.drain(..) { err.buffer(&mut buffer); @@ -1377,17 +1377,17 @@ mod tests { span_diagnostic: errors::Handler::with_emitter(true, None, Box::new(emitter)), unstable_features: UnstableFeatures::from_environment(), config: CrateConfig::default(), - included_mod_stack: Lock::new(Vec::new()), + included_mod_stack: Lock::new(vec![]), source_map: sm, missing_fragment_specifiers: Lock::new(FxHashSet::default()), - raw_identifier_spans: Lock::new(Vec::new()), + raw_identifier_spans: Lock::new(vec![]), registered_diagnostics: Lock::new(ErrorMap::new()), buffered_lints: Lock::new(vec![]), edition: Edition::from_session(), ambiguous_block_expr_parse: Lock::new(FxHashMap::default()), - param_attr_spans: Lock::new(Vec::new()), - let_chains_spans: Lock::new(Vec::new()), - async_closure_spans: Lock::new(Vec::new()), + param_attr_spans: Lock::new(vec![]), + let_chains_spans: Lock::new(vec![]), + async_closure_spans: Lock::new(vec![]), } } diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index 830fbec58ded9..08c89b5587f41 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -12,9 +12,9 @@ impl<'a> StringReader<'a> { string_reader: self, token: Token::dummy(), joint_to_prev: Joint, - open_braces: Vec::new(), - unmatched_braces: Vec::new(), - matching_delim_spans: Vec::new(), + open_braces: vec![], + unmatched_braces: vec![], + matching_delim_spans: vec![], last_unclosed_found_span: None, }; let res = tt_reader.parse_all_token_trees(); @@ -39,7 +39,7 @@ struct TokenTreesReader<'a> { impl<'a> TokenTreesReader<'a> { // Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`. fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> { - let mut tts = Vec::new(); + let mut tts = vec![]; self.real_token(); while self.token != token::Eof { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 4c4551b1757ac..936823aefec07 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -77,16 +77,16 @@ impl ParseSess { unstable_features: UnstableFeatures::from_environment(), config: FxHashSet::default(), missing_fragment_specifiers: Lock::new(FxHashSet::default()), - raw_identifier_spans: Lock::new(Vec::new()), + raw_identifier_spans: Lock::new(vec![]), registered_diagnostics: Lock::new(ErrorMap::new()), included_mod_stack: Lock::new(vec![]), source_map, buffered_lints: Lock::new(vec![]), edition: Edition::from_session(), ambiguous_block_expr_parse: Lock::new(FxHashMap::default()), - param_attr_spans: Lock::new(Vec::new()), - let_chains_spans: Lock::new(Vec::new()), - async_closure_spans: Lock::new(Vec::new()), + param_attr_spans: Lock::new(vec![]), + let_chains_spans: Lock::new(vec![]), + async_closure_spans: Lock::new(vec![]), } } @@ -552,7 +552,7 @@ mod tests { } } } - let mut v = PatIdentVisitor { spans: Vec::new() }; + let mut v = PatIdentVisitor { spans: vec![] }; crate::visit::walk_item(&mut v, &item); return v.spans; } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 83030e89af310..f915be3e67236 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -487,20 +487,20 @@ impl<'a> Parser<'a> { ownership: DirectoryOwnership::Owned { relative: None } }, root_module_name: None, - expected_tokens: Vec::new(), + expected_tokens: vec![], token_cursor: TokenCursor { frame: TokenCursorFrame::new( DelimSpan::dummy(), token::NoDelim, &tokens.into(), ), - stack: Vec::new(), + stack: vec![], }, desugar_doc_comments, cfg_mods: true, unmatched_angle_bracket_count: 0, max_angle_bracket_count: 0, - unclosed_delims: Vec::new(), + unclosed_delims: vec![], last_unexpected_token_span: None, subparser_name, }; @@ -1302,7 +1302,7 @@ impl<'a> Parser<'a> { match ty.node { // `(TY_BOUND_NOPAREN) + BOUND + ...`. TyKind::Path(None, ref path) if maybe_bounds => { - self.parse_remaining_bounds(Vec::new(), path.clone(), lo, true)? + self.parse_remaining_bounds(vec![], path.clone(), lo, true)? } TyKind::TraitObject(ref bounds, TraitObjectSyntax::None) if maybe_bounds && bounds.len() == 1 && !trailing_plus => { @@ -1310,7 +1310,7 @@ impl<'a> Parser<'a> { GenericBound::Trait(ref pt, ..) => pt.trait_ref.path.clone(), GenericBound::Outlives(..) => self.bug("unexpected lifetime bound"), }; - self.parse_remaining_bounds(Vec::new(), path, lo, true)? + self.parse_remaining_bounds(vec![], path, lo, true)? } // `(TYPE)` _ => TyKind::Paren(P(ty)) @@ -1356,7 +1356,7 @@ impl<'a> Parser<'a> { TyKind::Infer } else if self.token_is_bare_fn_keyword() { // Function pointer type - self.parse_ty_bare_fn(Vec::new())? + self.parse_ty_bare_fn(vec![])? } else if self.check_keyword(kw::For) { // Function pointer type or bound list (trait object type) starting with a poly-trait. // `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T` @@ -1406,7 +1406,7 @@ impl<'a> Parser<'a> { // `Type` // `Trait1 + Trait2 + 'a` if allow_plus && self.check_plus() { - self.parse_remaining_bounds(Vec::new(), path, lo, true)? + self.parse_remaining_bounds(vec![], path, lo, true)? } else { TyKind::Path(None, path) } @@ -1659,7 +1659,7 @@ impl<'a> Parser<'a> { path_span = path_lo.to(self.prev_span); } else { path_span = self.token.span.to(self.token.span); - path = ast::Path { segments: Vec::new(), span: path_span }; + path = ast::Path { segments: vec![], span: path_span }; } // See doc comment for `unmatched_angle_bracket_count`. @@ -1697,7 +1697,7 @@ impl<'a> Parser<'a> { }); let lo = self.meta_var_span.unwrap_or(self.token.span); - let mut segments = Vec::new(); + let mut segments = vec![]; let mod_sep_ctxt = self.token.span.ctxt(); if self.eat(&token::ModSep) { segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); @@ -2070,7 +2070,7 @@ impl<'a> Parser<'a> { if self.eat(&token::CloseDelim(token::Bracket)) { // Empty vector. - ex = ExprKind::Array(Vec::new()); + ex = ExprKind::Array(vec![]); } else { // Nonempty vector. let first_expr = self.parse_expr()?; @@ -2336,7 +2336,7 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { let struct_sp = lo.to(self.prev_span); self.bump(); - let mut fields = Vec::new(); + let mut fields = vec![]; let mut base = None; attrs.extend(self.parse_inner_attributes()?); @@ -2688,7 +2688,7 @@ impl<'a> Parser<'a> { /// Parses a stream of tokens into a list of `TokenTree`s, up to EOF. pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec> { - let mut tts = Vec::new(); + let mut tts = vec![]; while self.token != token::Eof { tts.push(self.parse_token_tree()); } @@ -2696,7 +2696,7 @@ impl<'a> Parser<'a> { } pub fn parse_tokens(&mut self) -> TokenStream { - let mut result = Vec::new(); + let mut result = vec![]; loop { match self.token.kind { token::Eof | token::CloseDelim(..) => break, @@ -3375,7 +3375,7 @@ impl<'a> Parser<'a> { } attrs.extend(self.parse_inner_attributes()?); - let mut arms: Vec = Vec::new(); + let mut arms: Vec = vec![]; while self.token != token::CloseDelim(token::Brace) { match self.parse_arm() { Ok(arm) => arms.push(arm), @@ -3511,7 +3511,7 @@ impl<'a> Parser<'a> { // Allow a '|' before the pats (RFC 1925 + RFC 2530) self.eat(&token::BinOp(token::Or)); - let mut pats = Vec::new(); + let mut pats = vec![]; loop { pats.push(self.parse_top_level_pat()?); @@ -3556,7 +3556,7 @@ impl<'a> Parser<'a> { } fn parse_pat_list(&mut self) -> PResult<'a, (Vec>, Option, bool)> { - let mut fields = Vec::new(); + let mut fields = vec![]; let mut ddpos = None; let mut prev_dd_sp = None; let mut trailing_comma = false; @@ -3603,9 +3603,9 @@ impl<'a> Parser<'a> { fn parse_pat_vec_elements( &mut self, ) -> PResult<'a, (Vec>, Option>, Vec>)> { - let mut before = Vec::new(); + let mut before = vec![]; let mut slice = None; - let mut after = Vec::new(); + let mut after = vec![]; let mut first = true; let mut before_slice = true; @@ -3711,7 +3711,7 @@ impl<'a> Parser<'a> { /// Parses the fields of a struct-like pattern. fn parse_pat_fields(&mut self) -> PResult<'a, (Vec>, bool)> { - let mut fields = Vec::new(); + let mut fields = vec![]; let mut etc = false; let mut ate_comma = true; let mut delayed_err: Option> = None; @@ -4616,7 +4616,7 @@ impl<'a> Parser<'a> { /// Parses a block. Inner attributes are allowed. fn parse_inner_attrs_and_block(&mut self) -> PResult<'a, (Vec, P)> { - maybe_whole!(self, NtBlock, |x| (Vec::new(), x)); + maybe_whole!(self, NtBlock, |x| (vec![], x)); let lo = self.token.span; self.expect(&token::OpenDelim(token::Brace))?; @@ -4732,8 +4732,8 @@ impl<'a> Parser<'a> { fn parse_generic_bounds_common(&mut self, allow_plus: bool, colon_span: Option) -> PResult<'a, GenericBounds> { - let mut bounds = Vec::new(); - let mut negative_bounds = Vec::new(); + let mut bounds = vec![]; + let mut negative_bounds = vec![]; let mut last_plus_span = None; let mut was_negative = false; loop { @@ -4851,7 +4851,7 @@ impl<'a> Parser<'a> { /// BOUND = LT_BOUND (e.g., `'a`) /// ``` fn parse_lt_param_bounds(&mut self) -> GenericBounds { - let mut lifetimes = Vec::new(); + let mut lifetimes = vec![]; while self.check_lifetime() { lifetimes.push(ast::GenericBound::Outlives(self.expect_lifetime())); @@ -4872,7 +4872,7 @@ impl<'a> Parser<'a> { let bounds = if self.eat(&token::Colon) { self.parse_generic_bounds(Some(self.prev_span))? } else { - Vec::new() + vec![] }; let default = if self.eat(&token::Eq) { @@ -4904,7 +4904,7 @@ impl<'a> Parser<'a> { let bounds = if self.eat(&token::Colon) { self.parse_generic_bounds(None)? } else { - Vec::new() + vec![] }; generics.where_clause = self.parse_where_clause()?; @@ -4928,7 +4928,7 @@ impl<'a> Parser<'a> { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs.into(), - bounds: Vec::new(), + bounds: vec![], kind: GenericParamKind::Const { ty, } @@ -4938,7 +4938,7 @@ impl<'a> Parser<'a> { /// Parses a (possibly empty) list of lifetime and type parameters, possibly including /// a trailing comma and erroneous trailing attributes. crate fn parse_generic_params(&mut self) -> PResult<'a, Vec> { - let mut params = Vec::new(); + let mut params = vec![]; loop { let attrs = self.parse_outer_attributes()?; if self.check_lifetime() { @@ -4947,7 +4947,7 @@ impl<'a> Parser<'a> { let bounds = if self.eat(&token::Colon) { self.parse_lt_param_bounds() } else { - Vec::new() + vec![] }; params.push(ast::GenericParam { ident: lifetime.ident, @@ -5013,7 +5013,7 @@ impl<'a> Parser<'a> { Ok(ast::Generics { params, where_clause: WhereClause { - predicates: Vec::new(), + predicates: vec![], span: DUMMY_SP, }, span, @@ -5169,10 +5169,10 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. fn parse_generic_args(&mut self) -> PResult<'a, (Vec, Vec)> { - let mut args = Vec::new(); - let mut constraints = Vec::new(); - let mut misplaced_assoc_ty_constraints: Vec = Vec::new(); - let mut assoc_ty_constraints: Vec = Vec::new(); + let mut args = vec![]; + let mut constraints = vec![]; + let mut misplaced_assoc_ty_constraints: Vec = vec![]; + let mut assoc_ty_constraints: Vec = vec![]; let args_lo = self.token.span; @@ -5271,7 +5271,7 @@ impl<'a> Parser<'a> { /// ``` fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> { let mut where_clause = WhereClause { - predicates: Vec::new(), + predicates: vec![], span: self.prev_span.to(self.prev_span), }; @@ -5606,7 +5606,7 @@ impl<'a> Parser<'a> { fn parse_fn_block_decl(&mut self) -> PResult<'a, P> { let inputs_captures = { if self.eat(&token::OrOr) { - Vec::new() + vec![] } else { self.expect(&token::BinOp(token::Or))?; let args = self.parse_seq_to_before_tokens( @@ -5864,7 +5864,7 @@ impl<'a> Parser<'a> { let bounds = if self.eat(&token::Colon) { self.parse_generic_bounds(Some(self.prev_span))? } else { - Vec::new() + vec![] }; if self.eat(&token::Eq) { @@ -5951,7 +5951,7 @@ impl<'a> Parser<'a> { self.expect(&token::OpenDelim(token::Brace))?; let attrs = self.parse_inner_attributes()?; - let mut impl_items = Vec::new(); + let mut impl_items = vec![]; while !self.eat(&token::CloseDelim(token::Brace)) { let mut at_end = false; match self.parse_impl_item(&mut at_end) { @@ -6068,7 +6068,7 @@ impl<'a> Parser<'a> { // parameters, and the lifetime parameters must not have bounds. Ok(params) } else { - Ok(Vec::new()) + Ok(vec![]) } } @@ -6155,7 +6155,7 @@ impl<'a> Parser<'a> { fn parse_record_struct_body( &mut self, ) -> PResult<'a, (Vec, /* recovered */ bool)> { - let mut fields = Vec::new(); + let mut fields = vec![]; let mut recovered = false; if self.eat(&token::OpenDelim(token::Brace)) { while self.token != token::CloseDelim(token::Brace) { @@ -6468,7 +6468,7 @@ impl<'a> Parser<'a> { } else { let placeholder = ast::Mod { inner: DUMMY_SP, - items: Vec::new(), + items: vec![], inline: false }; Ok((id, ItemKind::Mod(placeholder), None)) @@ -6904,7 +6904,7 @@ impl<'a> Parser<'a> { /// Parses the part of an enum declaration following the `{`. fn parse_enum_def(&mut self, _generics: &ast::Generics) -> PResult<'a, EnumDef> { - let mut variants = Vec::new(); + let mut variants = vec![]; while self.token != token::CloseDelim(token::Brace) { let variant_attrs = self.parse_outer_attributes()?; let vlo = self.token.span; @@ -7646,7 +7646,7 @@ impl<'a> Parser<'a> { where F: FnOnce(&mut Self) -> PResult<'a, R> { // Record all tokens we parse when parsing this item. - let mut tokens = Vec::new(); + let mut tokens = vec![]; let prev_collecting = match self.token_cursor.frame.last_token { LastToken::Collecting(ref mut list) => { Some(mem::take(list)) @@ -7722,7 +7722,7 @@ impl<'a> Parser<'a> { fn parse_use_tree(&mut self) -> PResult<'a, UseTree> { let lo = self.token.span; - let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo() }; + let mut prefix = ast::Path { segments: vec![], span: lo.shrink_to_lo() }; let kind = if self.check(&token::OpenDelim(token::Brace)) || self.check(&token::BinOp(token::Star)) || self.is_import_coupler() { diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 660e77f77d0f2..ad8b3b36024ee 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -253,7 +253,7 @@ pub fn mk_printer() -> Printer { left_total: 0, right_total: 0, scan_stack: VecDeque::new(), - print_stack: Vec::new(), + print_stack: vec![], pending_indentation: 0 } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3b6064fcdf7bf..b1b3aeb60839c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2842,9 +2842,9 @@ impl<'a> State<'a> { self.print_generic_params(generic_params); } let generics = ast::Generics { - params: Vec::new(), + params: vec![], where_clause: ast::WhereClause { - predicates: Vec::new(), + predicates: vec![], span: syntax_pos::DUMMY_SP, }, span: syntax_pos::DUMMY_SP, @@ -2929,7 +2929,7 @@ mod tests { let abba_ident = ast::Ident::from_str("abba"); let decl = ast::FnDecl { - inputs: Vec::new(), + inputs: vec![], output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP), c_variadic: false }; @@ -2958,7 +2958,7 @@ mod tests { let var = source_map::respan(syntax_pos::DUMMY_SP, ast::Variant_ { ident, - attrs: Vec::new(), + attrs: vec![], id: ast::DUMMY_NODE_ID, // making this up as I go.... ? data: ast::VariantData::Unit(ast::DUMMY_NODE_ID), diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 799d64a996237..b0ce9723ac603 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -235,7 +235,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>, cx.ext_cx.current_expansion.mark = cx.ext_cx.resolver.get_module_scope(parent); let it = cx.ext_cx.monotonic_expander().flat_map_item(P(ast::Item { ident: name, - attrs: Vec::new(), + attrs: vec![], id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Mod(reexport_mod), vis: dummy_spanned(ast::VisibilityKind::Public), @@ -264,8 +264,8 @@ fn generate_test_harness(sess: &ParseSess, let cx = TestCtxt { span_diagnostic: sd, ext_cx: ExtCtxt::new(sess, econfig, resolver), - path: Vec::new(), - test_cases: Vec::new(), + path: vec![], + test_cases: vec![], reexport_test_harness_main, // N.B., doesn't consider the value of `--crate-name` passed on the command line. is_libtest: attr::find_crate_name(&krate.attrs) @@ -277,8 +277,8 @@ fn generate_test_harness(sess: &ParseSess, TestHarnessGenerator { cx, - tests: Vec::new(), - tested_submods: Vec::new(), + tests: vec![], + tested_submods: vec![], }.visit_crate(krate); } diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index c1c2732605c46..b3fbb42497e47 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -87,9 +87,9 @@ fn parse_inline_asm<'a>( let mut p = cx.new_parser_from_tts(&tts[first_colon..]); let mut asm = kw::Invalid; let mut asm_str_style = None; - let mut outputs = Vec::new(); - let mut inputs = Vec::new(); - let mut clobs = Vec::new(); + let mut outputs = vec![]; + let mut inputs = vec![]; + let mut clobs = vec![]; let mut volatile = false; let mut alignstack = false; let mut dialect = AsmDialect::Att; diff --git a/src/libsyntax_ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs index d5b8a00c75b83..551d0b4597355 100644 --- a/src/libsyntax_ext/deriving/bounds.rs +++ b/src/libsyntax_ext/deriving/bounds.rs @@ -13,14 +13,14 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>, push: &mut dyn FnMut(Annotatable)) { let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, marker::Copy), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: true, - methods: Vec::new(), - associated_types: Vec::new(), + methods: vec![], + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index b3b6328e2ca73..c4614af6a2611 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -80,7 +80,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, clone::Clone), additional_bounds: bounds, generics: LifetimeBounds::empty(), @@ -90,14 +90,14 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, name: "clone", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), - args: Vec::new(), + args: vec![], ret_ty: Self_, attributes: attrs, is_unsafe: false, unify_fieldless_variants: false, combine_substructure: substructure, }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand_ext(cx, mitem, item, push, is_shallow) @@ -126,7 +126,7 @@ fn cs_clone_shallow(name: &str, } } - let mut stmts = Vec::new(); + let mut stmts = vec![]; if is_union { // let _: AssertParamIsCopy; let self_ty = diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index 1d981e0ff7906..ae2b838fb9471 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -20,9 +20,9 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)]; let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, cmp::Eq), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: true, @@ -39,7 +39,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, cs_total_eq_assert(a, b, c) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand_ext(cx, mitem, item, push, true) } @@ -67,7 +67,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>, } } - let mut stmts = Vec::new(); + let mut stmts = vec![]; match *substr.fields { StaticStruct(vdata, ..) => { process_variant(cx, &mut stmts, vdata); diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 844865d57c7ad..9ae25c146759d 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -18,9 +18,9 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>, let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, cmp::Ord), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, @@ -37,7 +37,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>, cs_cmp(a, b, c) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 732bb234389a0..355aa7eb6afb4 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -90,14 +90,14 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, cmp::PartialEq), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, methods, - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) } diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index a30a7d78222f4..b8cfedaba2c18 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -81,7 +81,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, is_unsafe: false, supports_unions: false, methods, - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) } diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 98465d75e4680..64e4d9834baf1 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -51,7 +51,7 @@ impl MultiItemModifier for ProcMacroDerive { Annotatable::Expr(_) => { ecx.span_err(span, "proc-macro derives may only be \ applied to a struct, enum, or union"); - return Vec::new() + return vec![] } }; match item.node { @@ -61,7 +61,7 @@ impl MultiItemModifier for ProcMacroDerive { _ => { ecx.span_err(span, "proc-macro derives may only be \ applied to a struct, enum, or union"); - return Vec::new() + return vec![] } } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 44ddbb98809b4..f5cb60e948df8 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -23,9 +23,9 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>, let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, fmt::Debug), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, @@ -35,14 +35,14 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>, explicit_self: borrowed_explicit_self(), args: vec![(fmtr, "f")], ret_ty: Literal(path_std!(cx, fmt::Result)), - attributes: Vec::new(), + attributes: vec![], is_unsafe: false, unify_fieldless_variants: false, combine_substructure: combine_substructure(Box::new(|a, b, c| { show_substructure(a, b, c) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) } diff --git a/src/libsyntax_ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs index 8009f42b8cf95..2a22336c1812f 100644 --- a/src/libsyntax_ext/deriving/decodable.rs +++ b/src/libsyntax_ext/deriving/decodable.rs @@ -38,16 +38,16 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt<'_>, let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: "decode", generics: LifetimeBounds { - lifetimes: Vec::new(), + lifetimes: vec![], bounds: vec![(typaram, vec![Path::new_(vec![krate, "Decoder"], None, @@ -64,14 +64,14 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt<'_>, vec![typaram, "Error"], None, vec![], PathKind::Local )))], PathKind::Std)), - attributes: Vec::new(), + attributes: vec![], is_unsafe: false, unify_fieldless_variants: false, combine_substructure: combine_substructure(Box::new(|a, b, c| { decodable_substructure(a, b, c, krate) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index fd8e87e2fefd1..0a26d0205d7e5 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -19,9 +19,9 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: path_std!(cx, default::Default), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, @@ -29,7 +29,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, name: "default", generics: LifetimeBounds::empty(), explicit_self: None, - args: Vec::new(), + args: vec![], ret_ty: Self_, attributes: attrs, is_unsafe: false, @@ -38,7 +38,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, default_substructure(a, b, c) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) } @@ -49,7 +49,7 @@ fn default_substructure(cx: &mut ExtCtxt<'_>, -> P { // Note that `kw::Default` is "default" and `sym::Default` is "Default"! let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]); - let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new()); + let default_call = |span| cx.expr_call_global(span, default_ident.clone(), vec![]); return match *substr.fields { StaticStruct(_, ref summary) => { diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index cd89a42cf8270..9b24a577ba978 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -119,9 +119,9 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>, let trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path: Path::new_(vec![krate, "Encodable"], None, vec![], PathKind::Global), - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, @@ -129,7 +129,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>, MethodDef { name: "encode", generics: LifetimeBounds { - lifetimes: Vec::new(), + lifetimes: vec![], bounds: vec![ (typaram, vec![Path::new_(vec![krate, "Encoder"], None, vec![], PathKind::Global)]) @@ -141,12 +141,12 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>, ret_ty: Literal(Path::new_( pathvec_std!(cx, result::Result), None, - vec![Box::new(Tuple(Vec::new())), Box::new(Literal(Path::new_( + vec![Box::new(Tuple(vec![])), Box::new(Literal(Path::new_( vec![typaram, "Error"], None, vec![], PathKind::Local )))], PathKind::Std )), - attributes: Vec::new(), + attributes: vec![], is_unsafe: false, unify_fieldless_variants: false, combine_substructure: combine_substructure(Box::new(|a, b, c| { @@ -154,7 +154,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>, })), } ], - associated_types: Vec::new(), + associated_types: vec![], }; trait_def.expand(cx, mitem, item, push) @@ -177,7 +177,7 @@ fn encodable_substructure(cx: &mut ExtCtxt<'_>, return match *substr.fields { Struct(_, ref fields) => { let emit_struct_field = cx.ident_of("emit_struct_field"); - let mut stmts = Vec::new(); + let mut stmts = vec![]; for (i, &FieldInfo { name, ref self_, span, .. }) in fields.iter().enumerate() { let name = match name { Some(id) => id.name, @@ -229,7 +229,7 @@ fn encodable_substructure(cx: &mut ExtCtxt<'_>, let me = cx.stmt_let(trait_span, false, blkarg, encoder); let encoder = cx.expr_ident(trait_span, blkarg); let emit_variant_arg = cx.ident_of("emit_enum_variant_arg"); - let mut stmts = Vec::new(); + let mut stmts = vec![]; if !fields.is_empty() { let last = fields.len() - 1; for (i, &FieldInfo { ref self_, span, .. }) in fields.iter().enumerate() { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 12482f7248e90..7a52605303e11 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -375,7 +375,7 @@ fn find_type_parameters( let mut visitor = Visitor { ty_param_names, - types: Vec::new(), + types: vec![], span, cx, }; @@ -528,7 +528,7 @@ impl<'a> TraitDef<'a> { ident, vis: respan(self.span.shrink_to_lo(), ast::VisibilityKind::Inherited), defaultness: ast::Defaultness::Final, - attrs: Vec::new(), + attrs: vec![], generics: Generics::default(), node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, type_ident, generics)), tokens: None, @@ -629,7 +629,7 @@ impl<'a> TraitDef<'a> { let predicate = ast::WhereBoundPredicate { span: self.span, - bound_generic_params: Vec::new(), + bound_generic_params: vec![], bounded_ty: ty, bounds, }; @@ -755,7 +755,7 @@ impl<'a> TraitDef<'a> { generics: &Generics, from_scratch: bool) -> P { - let mut field_tys = Vec::new(); + let mut field_tys = vec![]; for variant in &enum_def.variants { field_tys.extend(variant.node @@ -874,9 +874,9 @@ impl<'a> MethodDef<'a> { generics: &Generics) -> (Option, Vec>, Vec>, Vec<(Ident, P)>) { - let mut self_args = Vec::new(); - let mut nonself_args = Vec::new(); - let mut arg_tys = Vec::new(); + let mut self_args = vec![]; + let mut nonself_args = vec![]; + let mut arg_tys = vec![]; let mut nonstatic = false; let ast_explicit_self = self.explicit_self.as_ref().map(|self_ptr| { @@ -1015,9 +1015,9 @@ impl<'a> MethodDef<'a> { use_temporaries: bool) -> P { - let mut raw_fields = Vec::new(); // Vec<[fields of self], + let mut raw_fields = vec![]; // Vec<[fields of self], // [fields of next Self arg], [etc]> - let mut patterns = Vec::new(); + let mut patterns = vec![]; for i in 0..self_args.len() { let struct_path = cx.path(DUMMY_SP, vec![type_ident]); let (pat, ident_expr) = trait_.create_struct_pattern(cx, @@ -1320,7 +1320,7 @@ impl<'a> MethodDef<'a> { // We need a default case that handles the fieldless variants. // The index and actual variant aren't meaningful in this case, // so just use whatever - let substructure = EnumMatching(0, variants.len(), v, Vec::new()); + let substructure = EnumMatching(0, variants.len(), v, vec![]); Some(self.call_substructure_method(cx, trait_, type_ident, @@ -1529,8 +1529,8 @@ impl<'a> MethodDef<'a> { // general helper methods. impl<'a> TraitDef<'a> { fn summarise_struct(&self, cx: &mut ExtCtxt<'_>, struct_def: &VariantData) -> StaticFields { - let mut named_idents = Vec::new(); - let mut just_spans = Vec::new(); + let mut named_idents = vec![]; + let mut just_spans = vec![]; for field in struct_def.fields() { let sp = field.span.with_ctxt(self.span.ctxt()); match field.ident { @@ -1551,7 +1551,7 @@ impl<'a> TraitDef<'a> { // unnamed fields (false, _) => Unnamed(just_spans, is_tuple), // empty - _ => Named(Vec::new()), + _ => Named(vec![]), } } @@ -1584,8 +1584,8 @@ impl<'a> TraitDef<'a> { use_temporaries: bool) -> (P, Vec<(Span, Option, P, &'a [ast::Attribute])>) { - let mut paths = Vec::new(); - let mut ident_exprs = Vec::new(); + let mut paths = vec![]; + let mut ident_exprs = vec![]; for (i, struct_field) in struct_def.fields().iter().enumerate() { let sp = struct_field.span.with_ctxt(self.span.ctxt()); let ident = cx.ident_of(&format!("{}_{}", prefix, i)).gensym(); diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 02b02e9b83695..a57e15e2859c5 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -40,10 +40,10 @@ pub enum PathKind { impl<'a> Path<'a> { pub fn new(path: Vec<&str>) -> Path<'_> { - Path::new_(path, None, Vec::new(), PathKind::Std) + Path::new_(path, None, vec![], PathKind::Std) } pub fn new_local(path: &str) -> Path<'_> { - Path::new_(vec![path], None, Vec::new(), PathKind::Local) + Path::new_(vec![path], None, vec![], PathKind::Local) } pub fn new_<'r>(path: Vec<&'r str>, lifetime: Option<&'r str>, @@ -82,12 +82,12 @@ impl<'a> Path<'a> { .collect(); match self.kind { - PathKind::Global => cx.path_all(span, true, idents, params, Vec::new()), - PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()), + PathKind::Global => cx.path_all(span, true, idents, params, vec![]), + PathKind::Local => cx.path_all(span, false, idents, params, vec![]), PathKind::Std => { let def_site = DUMMY_SP.apply_mark(cx.current_expansion.mark); idents.insert(0, Ident::new(kw::DollarCrate, def_site)); - cx.path_all(span, false, idents, params, Vec::new()) + cx.path_all(span, false, idents, params, vec![]) } } @@ -130,7 +130,7 @@ pub fn borrowed_self<'r>() -> Ty<'r> { } pub fn nil_ty<'r>() -> Ty<'r> { - Tuple(Vec::new()) + Tuple(vec![]) } fn mk_lifetime(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Option { @@ -223,7 +223,7 @@ fn mk_generics(params: Vec, span: Span) -> Generics { Generics { params, where_clause: ast::WhereClause { - predicates: Vec::new(), + predicates: vec![], span, }, span, @@ -240,8 +240,8 @@ pub struct LifetimeBounds<'a> { impl<'a> LifetimeBounds<'a> { pub fn empty() -> LifetimeBounds<'a> { LifetimeBounds { - lifetimes: Vec::new(), - bounds: Vec::new(), + lifetimes: vec![], + bounds: vec![], } } pub fn to_generics(&self, diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index 7ad04aebf6e2e..240c9be1c6476 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -22,16 +22,16 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>, let arg = Path::new_local(typaram); let hash_trait_def = TraitDef { span, - attributes: Vec::new(), + attributes: vec![], path, - additional_bounds: Vec::new(), + additional_bounds: vec![], generics: LifetimeBounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: "hash", generics: LifetimeBounds { - lifetimes: Vec::new(), + lifetimes: vec![], bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])], }, explicit_self: borrowed_explicit_self(), @@ -45,7 +45,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>, hash_substructure(a, b, c) })), }], - associated_types: Vec::new(), + associated_types: vec![], }; hash_trait_def.expand(cx, mitem, item, push); @@ -69,7 +69,7 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu let expr = cx.expr_call(span, hash_path, vec![ref_thing, state_expr.clone()]); cx.stmt_expr(expr) }; - let mut stmts = Vec::new(); + let mut stmts = vec![]; let fields = match *substr.fields { Struct(_, ref fs) | EnumMatching(_, 1, .., ref fs) => fs, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index e491e93256d1c..a32886ef08bc2 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -54,7 +54,7 @@ impl MultiItemModifier for BuiltinDerive { meta_item: &MetaItem, item: Annotatable) -> Vec { - let mut items = Vec::new(); + let mut items = vec![]; (self.0)(ecx, span, meta_item, &item, &mut |a| items.push(a)); items } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index c3dbd48cc6e4e..5642d44a20760 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -127,7 +127,7 @@ fn parse_args<'a>( sp: Span, tts: &[tokenstream::TokenTree] ) -> Result<(P, Vec>, FxHashMap), DiagnosticBuilder<'a>> { - let mut args = Vec::>::new(); + let mut args: Vec> = vec![]; let mut names = FxHashMap::::default(); let mut p = ecx.new_parser_from_tts(tts); @@ -730,8 +730,8 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>, -> P { // NOTE: this verbose way of initializing `Vec>` is because // `ArgumentType` does not derive `Clone`. - let arg_types: Vec<_> = (0..args.len()).map(|_| Vec::new()).collect(); - let arg_unique_types: Vec<_> = (0..args.len()).map(|_| Vec::new()).collect(); + let arg_types: Vec<_> = (0..args.len()).map(|_| vec![]).collect(); + let arg_unique_types: Vec<_> = (0..args.len()).map(|_| vec![]).collect(); let mut macsp = ecx.call_site(); macsp = macsp.apply_mark(ecx.current_expansion.mark); @@ -876,7 +876,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>, let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline); - let mut unverified_pieces = Vec::new(); + let mut unverified_pieces = vec![]; while let Some(piece) = parser.next() { if !parser.errors.is_empty() { break; @@ -914,8 +914,8 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>, names, curarg: 0, curpiece: 0, - arg_index_map: Vec::new(), - count_args: Vec::new(), + arg_index_map: vec![], + count_args: vec![], count_positions: FxHashMap::default(), count_positions_count: 0, count_args_index_offset: 0, @@ -925,7 +925,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>, all_pieces_simple: true, macsp, fmtsp: fmt.span, - invalid_refs: Vec::new(), + invalid_refs: vec![], arg_spans, is_literal, }; diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 112192fac5d26..fd40ffb559cfc 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -26,7 +26,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, Ok(Some(global_asm)) => { MacEager::items(smallvec![P(ast::Item { ident: ast::Ident::invalid(), - attrs: Vec::new(), + attrs: vec![], id: ast::DUMMY_NODE_ID, node: ast::ItemKind::GlobalAsm(P(global_asm)), vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index 2f78644dff2aa..7c76038497869 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -59,9 +59,9 @@ pub fn modify(sess: &ParseSess, let (derives, attr_macros, bang_macros) = { let mut collect = CollectProcMacros { - derives: Vec::new(), - attr_macros: Vec::new(), - bang_macros: Vec::new(), + derives: vec![], + attr_macros: vec![], + bang_macros: vec![], in_root: true, handler, is_proc_macro_crate, @@ -176,7 +176,7 @@ impl<'a> CollectProcMacros<'a> { Some(ident.name) }).collect() } else { - Vec::new() + vec![] }; if self.in_root && item.vis.node.is_pub() { @@ -358,7 +358,7 @@ fn mk_decls( let proc_macro = Ident::with_empty_ctxt(sym::proc_macro); let krate = cx.item(span, proc_macro, - Vec::new(), + vec![], ast::ItemKind::ExternCrate(None)); let bridge = Ident::from_str("bridge"); diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 5df1443923090..9b2f93d6b0253 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -240,7 +240,7 @@ impl HygieneData { } fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(Mark, Transparency)> { - let mut marks = Vec::new(); + let mut marks = vec![]; while ctxt != SyntaxContext::empty() { let outer_mark = self.outer(ctxt); let transparency = self.transparency(ctxt); @@ -537,7 +537,7 @@ impl SyntaxContext { } let mut glob_ctxt = data.modern(glob_span.ctxt()); - let mut marks = Vec::new(); + let mut marks = vec![]; while !data.is_descendant_of(expansion, data.outer(glob_ctxt)) { marks.push(data.remove_mark(&mut glob_ctxt)); } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index a983180ac01e1..0655e9c4f3b38 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -123,6 +123,7 @@ symbols! { align, alignstack, all, + alloc, allocator, allocator_internals, alloc_error_handler, diff --git a/src/test/ui-fulldeps/internal-lints/vec_new.rs b/src/test/ui-fulldeps/internal-lints/vec_new.rs new file mode 100644 index 0000000000000..972fc3b9ee6a3 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/vec_new.rs @@ -0,0 +1,8 @@ +// compile-flags: -Z unstable-options + +#![deny(rustc::vec_new)] + +fn main() { + let _: Vec = Vec::new(); //~ ERROR usage of `Vec::new()` + let _: Vec = vec![]; +} diff --git a/src/test/ui-fulldeps/internal-lints/vec_new.stderr b/src/test/ui-fulldeps/internal-lints/vec_new.stderr new file mode 100644 index 0000000000000..5675845a66655 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/vec_new.stderr @@ -0,0 +1,14 @@ +error: usage of `Vec::new()` + --> $DIR/vec_new.rs:6:22 + | +LL | let _: Vec = Vec::new(); + | ^^^^^^^^^^ help: use: `vec![]` + | +note: lint level defined here + --> $DIR/vec_new.rs:3:9 + | +LL | #![deny(rustc::vec_new)] + | ^^^^^^^^^^^^^^ + +error: aborting due to previous error +