From d6f70359dcedc2b864c47d08dd57a4d25961bc3c Mon Sep 17 00:00:00 2001 From: Irina-Gabriela Popa Date: Thu, 23 Nov 2017 16:41:51 +0200 Subject: [PATCH 1/3] rustc_back: remove slice module in favor of std::slice::from_ref. --- src/Cargo.lock | 3 --- src/librustc/lib.rs | 1 + src/librustc/lint/context.rs | 4 ++-- src/librustc/middle/resolve_lifetime.rs | 4 ++-- src/librustc/mir/mod.rs | 14 +++++++------- src/librustc_back/lib.rs | 1 - src/librustc_back/slice.rs | 19 ------------------- src/librustc_borrowck/Cargo.toml | 1 - src/librustc_borrowck/borrowck/unused.rs | 6 +++--- src/librustc_borrowck/lib.rs | 2 +- src/librustc_const_eval/Cargo.toml | 1 - src/librustc_const_eval/check_match.rs | 6 +++--- src/librustc_const_eval/lib.rs | 2 +- src/librustc_typeck/Cargo.toml | 1 - src/librustc_typeck/astconv.rs | 6 +++--- src/librustc_typeck/check/mod.rs | 9 ++++----- src/librustc_typeck/lib.rs | 2 +- 17 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 src/librustc_back/slice.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index a8107bc47c6aa..87903731f6612 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1687,7 +1687,6 @@ dependencies = [ "graphviz 0.0.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", - "rustc_back 0.0.0", "rustc_errors 0.0.0", "rustc_mir 0.0.0", "syntax 0.0.0", @@ -1701,7 +1700,6 @@ dependencies = [ "arena 0.0.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", - "rustc_back 0.0.0", "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", @@ -1999,7 +1997,6 @@ dependencies = [ "fmt_macros 0.0.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", - "rustc_back 0.0.0", "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index a8c80aaa0309e..06c9995663e68 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -46,6 +46,7 @@ #![feature(const_fn)] #![feature(core_intrinsics)] #![feature(drain_filter)] +#![feature(from_ref)] #![feature(i128)] #![feature(i128_type)] #![feature(inclusive_range)] diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 2b9d5f27c661e..75cd230e1e5e2 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -26,7 +26,7 @@ use self::TargetLint::*; -use rustc_back::slice; +use std::slice; use lint::{EarlyLintPassObject, LateLintPassObject}; use lint::{Level, Lint, LintId, LintPass, LintBuffer}; use lint::levels::{LintLevelSets, LintLevelsBuilder}; @@ -308,7 +308,7 @@ impl LintStore { Some(ids) => CheckLintNameResult::Ok(&ids.0), } } - Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::ref_slice(id)), + Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)), } } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 4856fa3fc45ac..3683425cee5b4 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -31,7 +31,7 @@ use syntax_pos::Span; use errors::DiagnosticBuilder; use util::common::ErrorReported; use util::nodemap::{NodeMap, NodeSet, FxHashSet, FxHashMap, DefIdMap}; -use rustc_back::slice; +use std::slice; use hir; use hir::intravisit::{self, Visitor, NestedVisitorMap}; @@ -530,7 +530,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) { if lifetime_ref.is_elided() { - self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref)); + self.resolve_elided_lifetimes(slice::from_ref(lifetime_ref)); return; } if lifetime_ref.is_static() { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index cd4ed8081c3bd..5e5b9dc4d8493 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -25,7 +25,7 @@ use ty::subst::{Subst, Substs}; use ty::{self, AdtDef, ClosureSubsts, Region, Ty, TyCtxt, GeneratorInterior}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use util::ppaux; -use rustc_back::slice; +use std::slice; use hir::{self, InlineAsm}; use std::ascii; use std::borrow::{Cow}; @@ -754,28 +754,28 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn successors(&self) -> Cow<[BasicBlock]> { use self::TerminatorKind::*; match *self { - Goto { target: ref b } => slice::ref_slice(b).into_cow(), + Goto { target: ref b } => slice::from_ref(b).into_cow(), SwitchInt { targets: ref b, .. } => b[..].into_cow(), Resume | GeneratorDrop => (&[]).into_cow(), Return => (&[]).into_cow(), Unreachable => (&[]).into_cow(), Call { destination: Some((_, t)), cleanup: Some(c), .. } => vec![t, c].into_cow(), Call { destination: Some((_, ref t)), cleanup: None, .. } => - slice::ref_slice(t).into_cow(), - Call { destination: None, cleanup: Some(ref c), .. } => slice::ref_slice(c).into_cow(), + slice::from_ref(t).into_cow(), + Call { destination: None, cleanup: Some(ref c), .. } => slice::from_ref(c).into_cow(), Call { destination: None, cleanup: None, .. } => (&[]).into_cow(), Yield { resume: t, drop: Some(c), .. } => vec![t, c].into_cow(), - Yield { resume: ref t, drop: None, .. } => slice::ref_slice(t).into_cow(), + Yield { resume: ref t, drop: None, .. } => slice::from_ref(t).into_cow(), DropAndReplace { target, unwind: Some(unwind), .. } | Drop { target, unwind: Some(unwind), .. } => { vec![target, unwind].into_cow() } DropAndReplace { ref target, unwind: None, .. } | Drop { ref target, unwind: None, .. } => { - slice::ref_slice(target).into_cow() + slice::from_ref(target).into_cow() } Assert { target, cleanup: Some(unwind), .. } => vec![target, unwind].into_cow(), - Assert { ref target, .. } => slice::ref_slice(target).into_cow(), + Assert { ref target, .. } => slice::from_ref(target).into_cow(), FalseEdges { ref real_target, ref imaginary_targets } => { let mut s = vec![*real_target]; s.extend_from_slice(imaginary_targets); diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 824b553104760..5ed7b7f75bbfc 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -40,7 +40,6 @@ extern crate serialize as rustc_serialize; // used by deriving pub mod tempdir; pub mod target; -pub mod slice; pub mod dynamic_lib; use std::str::FromStr; diff --git a/src/librustc_back/slice.rs b/src/librustc_back/slice.rs deleted file mode 100644 index 5d8fc3acefd6f..0000000000000 --- a/src/librustc_back/slice.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::mem; - -pub fn ref_slice(ptr: &T) -> &[T; 1] { - unsafe { mem::transmute(ptr) } -} - -pub fn mut_ref_slice(ptr: &mut T) -> &mut [T; 1] { - unsafe { mem::transmute(ptr) } -} diff --git a/src/librustc_borrowck/Cargo.toml b/src/librustc_borrowck/Cargo.toml index 4c09a9e003ddb..25f02537490fa 100644 --- a/src/librustc_borrowck/Cargo.toml +++ b/src/librustc_borrowck/Cargo.toml @@ -15,6 +15,5 @@ syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } graphviz = { path = "../libgraphviz" } rustc = { path = "../librustc" } -rustc_back = { path = "../librustc_back" } rustc_mir = { path = "../librustc_mir" } rustc_errors = { path = "../librustc_errors" } diff --git a/src/librustc_borrowck/borrowck/unused.rs b/src/librustc_borrowck/borrowck/unused.rs index 228824b663d66..ddee122d0a6bd 100644 --- a/src/librustc_borrowck/borrowck/unused.rs +++ b/src/librustc_borrowck/borrowck/unused.rs @@ -13,7 +13,7 @@ use rustc::hir::{self, HirId}; use rustc::lint::builtin::UNUSED_MUT; use rustc::ty; use rustc::util::nodemap::{FxHashMap, FxHashSet}; -use rustc_back::slice; +use std::slice; use syntax::ptr::P; use borrowck::BorrowckCtxt; @@ -26,7 +26,7 @@ pub fn check<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, body: &'tcx hir::Body) { }.visit_expr(&body.value); let mut cx = UnusedMutCx { bccx, used_mut }; for arg in body.arguments.iter() { - cx.check_unused_mut_pat(slice::ref_slice(&arg.pat)); + cx.check_unused_mut_pat(slice::from_ref(&arg.pat)); } cx.visit_expr(&body.value); } @@ -101,7 +101,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnusedMutCx<'a, 'tcx> { } fn visit_local(&mut self, local: &hir::Local) { - self.check_unused_mut_pat(slice::ref_slice(&local.pat)); + self.check_unused_mut_pat(slice::from_ref(&local.pat)); } } diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index c8b71be86f862..be173db23a52a 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -15,6 +15,7 @@ #![allow(non_camel_case_types)] +#![feature(from_ref)] #![feature(match_default_bindings)] #![feature(quote)] @@ -22,7 +23,6 @@ extern crate syntax; extern crate syntax_pos; extern crate rustc_errors as errors; -extern crate rustc_back; // for "clarity", rename the graphviz crate to dot; graphviz within `borrowck` // refers to the borrowck-specific graphviz adapter traits. diff --git a/src/librustc_const_eval/Cargo.toml b/src/librustc_const_eval/Cargo.toml index bbc6148082494..e8d404af4defa 100644 --- a/src/librustc_const_eval/Cargo.toml +++ b/src/librustc_const_eval/Cargo.toml @@ -12,7 +12,6 @@ crate-type = ["dylib"] arena = { path = "../libarena" } log = "0.3" rustc = { path = "../librustc" } -rustc_back = { path = "../librustc_back" } rustc_const_math = { path = "../librustc_const_math" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 762b9787c8d35..e22f7f141642d 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -31,7 +31,7 @@ use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::{self, Pat, PatKind}; -use rustc_back::slice; +use std::slice; use syntax::ast; use syntax::ptr::P; @@ -114,7 +114,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> { }); // Check legality of move bindings and `@` patterns. - self.check_patterns(false, slice::ref_slice(&loc.pat)); + self.check_patterns(false, slice::from_ref(&loc.pat)); } fn visit_body(&mut self, body: &'tcx hir::Body) { @@ -122,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> { for arg in &body.arguments { self.check_irrefutable(&arg.pat, "function argument"); - self.check_patterns(false, slice::ref_slice(&arg.pat)); + self.check_patterns(false, slice::from_ref(&arg.pat)); } } } diff --git a/src/librustc_const_eval/lib.rs b/src/librustc_const_eval/lib.rs index 5e569e21de7b7..d4110f0091aeb 100644 --- a/src/librustc_const_eval/lib.rs +++ b/src/librustc_const_eval/lib.rs @@ -24,12 +24,12 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(i128_type)] +#![feature(from_ref)] extern crate arena; #[macro_use] extern crate syntax; #[macro_use] extern crate log; #[macro_use] extern crate rustc; -extern crate rustc_back; extern crate rustc_const_math; extern crate rustc_data_structures; extern crate rustc_errors; diff --git a/src/librustc_typeck/Cargo.toml b/src/librustc_typeck/Cargo.toml index 194d37dcb81c2..c3245842b4256 100644 --- a/src/librustc_typeck/Cargo.toml +++ b/src/librustc_typeck/Cargo.toml @@ -15,7 +15,6 @@ syntax = { path = "../libsyntax" } arena = { path = "../libarena" } fmt_macros = { path = "../libfmt_macros" } rustc = { path = "../librustc" } -rustc_back = { path = "../librustc_back" } rustc_const_math = { path = "../librustc_const_math" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_platform_intrinsics = { path = "../librustc_platform_intrinsics" } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8b849a9e52f3a..e20706a0d5abb 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -23,7 +23,7 @@ use rustc::ty::subst::{Kind, Subst, Substs}; use rustc::traits; use rustc::ty::{self, RegionKind, Ty, TyCtxt, ToPredicate, TypeFoldable}; use rustc::ty::wf::object_region_bounds; -use rustc_back::slice; +use std::slice; use require_c_abi_if_variadic; use util::common::ErrorReported; use util::nodemap::FxHashSet; @@ -782,7 +782,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name); - self.prohibit_type_params(slice::ref_slice(item_segment)); + self.prohibit_type_params(slice::from_ref(item_segment)); // Find the type of the associated item, and the trait where the associated // item is declared. @@ -859,7 +859,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let tcx = self.tcx(); let trait_def_id = tcx.parent_def_id(item_def_id).unwrap(); - self.prohibit_type_params(slice::ref_slice(item_segment)); + self.prohibit_type_params(slice::from_ref(item_segment)); let self_ty = if let Some(ty) = opt_self_ty { ty diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 09dd334a62d8a..3b32148358087 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -87,7 +87,7 @@ use self::TupleArgumentsFlag::*; use astconv::AstConv; use hir::def::{Def, CtorKind}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc_back::slice::ref_slice; +use std::slice; use namespace::Namespace; use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin}; use rustc::infer::type_variable::{TypeVariableOrigin}; @@ -130,7 +130,6 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::map::Node; use rustc::hir::{self, PatKind}; use rustc::middle::lang_items; -use rustc_back::slice; use rustc_const_math::ConstInt; mod autoderef; @@ -4168,7 +4167,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) { // Return directly on cache hit. This is useful to avoid doubly reporting // errors with default match binding modes. See #44614. - return (*cached_def, Some(ty), slice::ref_slice(&**item_segment)) + return (*cached_def, Some(ty), slice::from_ref(&**item_segment)) } let item_name = item_segment.name; let def = match self.resolve_ufcs(span, item_name, ty, node_id) { @@ -4187,7 +4186,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Write back the new resolution. self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, def); - (def, Some(ty), slice::ref_slice(&**item_segment)) + (def, Some(ty), slice::from_ref(&**item_segment)) } pub fn check_decl_initializer(&self, @@ -4325,7 +4324,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { CoerceMany::new(coerce_to_ty) } else { let tail_expr: &[P] = match tail_expr { - Some(e) => ref_slice(e), + Some(e) => slice::from_ref(e), None => &[], }; CoerceMany::with_coercion_sites(coerce_to_ty, tail_expr) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 014b8b14edb83..bf8f9d8b24a0d 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -77,6 +77,7 @@ This API is completely unstable and subject to change. #![feature(box_syntax)] #![feature(crate_visibility_modifier)] #![feature(conservative_impl_trait)] +#![feature(from_ref)] #![feature(match_default_bindings)] #![feature(never_type)] #![feature(quote)] @@ -90,7 +91,6 @@ extern crate syntax_pos; extern crate arena; #[macro_use] extern crate rustc; extern crate rustc_platform_intrinsics as intrinsics; -extern crate rustc_back; extern crate rustc_const_math; extern crate rustc_data_structures; extern crate rustc_errors as errors; From dda924ab6a15ebccfa1be0bff5b88390f4195afd Mon Sep 17 00:00:00 2001 From: Irina-Gabriela Popa Date: Thu, 23 Nov 2017 18:07:18 +0200 Subject: [PATCH 2/3] rustc_back: move dynamic_lib to rustc_metadata. --- src/Cargo.lock | 1 - src/librustc_back/lib.rs | 3 --- src/librustc_metadata/creader.rs | 2 +- src/{librustc_back => librustc_metadata}/dynamic_lib.rs | 0 src/librustc_metadata/lib.rs | 3 +++ src/librustc_plugin/Cargo.toml | 1 - src/librustc_plugin/lib.rs | 1 - src/librustc_plugin/load.rs | 2 +- src/librustdoc/plugins.rs | 2 +- src/librustdoc/test.rs | 2 +- src/test/run-make/extern-fn-reachable/main.rs | 4 ++-- src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs | 4 ++-- 12 files changed, 11 insertions(+), 14 deletions(-) rename src/{librustc_back => librustc_metadata}/dynamic_lib.rs (100%) diff --git a/src/Cargo.lock b/src/Cargo.lock index 87903731f6612..0ee46910f7d6e 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1889,7 +1889,6 @@ name = "rustc_plugin" version = "0.0.0" dependencies = [ "rustc 0.0.0", - "rustc_back 0.0.0", "rustc_errors 0.0.0", "rustc_metadata 0.0.0", "syntax 0.0.0", diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 5ed7b7f75bbfc..e338ee7bd9328 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -28,10 +28,8 @@ #![feature(box_syntax)] #![feature(const_fn)] -#![feature(libc)] extern crate syntax; -extern crate libc; extern crate rand; extern crate serialize; #[macro_use] extern crate log; @@ -40,7 +38,6 @@ extern crate serialize as rustc_serialize; // used by deriving pub mod tempdir; pub mod target; -pub mod dynamic_lib; use std::str::FromStr; diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 155097cdbe26c..e1c5cde42eccf 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -556,7 +556,7 @@ impl<'a> CrateLoader<'a> { use std::{env, mem}; use proc_macro::TokenStream; use proc_macro::__internal::Registry; - use rustc_back::dynamic_lib::DynamicLibrary; + use dynamic_lib::DynamicLibrary; use syntax_ext::deriving::custom::ProcMacroDerive; use syntax_ext::proc_macro_impl::{AttrProcMacro, BangProcMacro}; diff --git a/src/librustc_back/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs similarity index 100% rename from src/librustc_back/dynamic_lib.rs rename to src/librustc_metadata/dynamic_lib.rs diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index 20bdfaea0d0bb..6c1ca36232307 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -16,12 +16,14 @@ #![feature(box_patterns)] #![feature(conservative_impl_trait)] #![feature(i128_type)] +#![feature(libc)] #![feature(proc_macro_internals)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(specialization)] #![feature(rustc_private)] +extern crate libc; #[macro_use] extern crate log; #[macro_use] @@ -54,6 +56,7 @@ mod link_args; pub mod creader; pub mod cstore; +pub mod dynamic_lib; pub mod locator; __build_diagnostic_array! { librustc_metadata, DIAGNOSTICS } diff --git a/src/librustc_plugin/Cargo.toml b/src/librustc_plugin/Cargo.toml index 7f41d0527617a..d8fa1da1ce219 100644 --- a/src/librustc_plugin/Cargo.toml +++ b/src/librustc_plugin/Cargo.toml @@ -11,7 +11,6 @@ crate-type = ["dylib"] [dependencies] rustc = { path = "../librustc" } -rustc_back = { path = "../librustc_back" } rustc_metadata = { path = "../librustc_metadata" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index a2a6d183e9ccc..3df56c4e728ca 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -71,7 +71,6 @@ #[macro_use] extern crate syntax; extern crate rustc; -extern crate rustc_back; extern crate rustc_metadata; extern crate syntax_pos; extern crate rustc_errors as errors; diff --git a/src/librustc_plugin/load.rs b/src/librustc_plugin/load.rs index aba56788928af..8a4ec03b20efc 100644 --- a/src/librustc_plugin/load.rs +++ b/src/librustc_plugin/load.rs @@ -115,7 +115,7 @@ impl<'a> PluginLoader<'a> { span: Span, path: PathBuf, symbol: String) -> PluginRegistrarFun { - use rustc_back::dynamic_lib::DynamicLibrary; + use rustc_metadata::dynamic_lib::DynamicLibrary; // Make sure the path contains a / or the linker will search for it. let path = env::current_dir().unwrap().join(&path); diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 4fc5159588d86..1a1e60a6945ed 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -16,7 +16,7 @@ use std::mem; use std::string::String; use std::path::PathBuf; -use rustc_back::dynamic_lib as dl; +use rustc_metadata::dynamic_lib as dl; pub type PluginResult = clean::Crate; pub type PluginCallback = fn (clean::Crate) -> PluginResult; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index ee0d9a7f3e2d2..98369949c02a4 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -27,7 +27,7 @@ use rustc::hir::intravisit; use rustc::session::{self, CompileIncomplete, config}; use rustc::session::config::{OutputType, OutputTypes, Externs}; use rustc::session::search_paths::{SearchPaths, PathKind}; -use rustc_back::dynamic_lib::DynamicLibrary; +use rustc_metadata::dynamic_lib::DynamicLibrary; use rustc_back::tempdir::TempDir; use rustc_driver::{self, driver, Compilation}; use rustc_driver::driver::phase_2_configure_and_expand; diff --git a/src/test/run-make/extern-fn-reachable/main.rs b/src/test/run-make/extern-fn-reachable/main.rs index a1bd1041d145e..27387332c1c1f 100644 --- a/src/test/run-make/extern-fn-reachable/main.rs +++ b/src/test/run-make/extern-fn-reachable/main.rs @@ -10,9 +10,9 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate rustc_metadata; -use rustc_back::dynamic_lib::DynamicLibrary; +use rustc_metadata::dynamic_lib::DynamicLibrary; use std::path::Path; pub fn main() { diff --git a/src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs b/src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs index 09a2e8ecd876d..7a15a4cb3a2e8 100644 --- a/src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs +++ b/src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs @@ -14,9 +14,9 @@ // do the runtime check that these functions aren't exported. #![allow(private_no_mangle_fns)] -extern crate rustc_back; +extern crate rustc_metadata; -use rustc_back::dynamic_lib::DynamicLibrary; +use rustc_metadata::dynamic_lib::DynamicLibrary; #[no_mangle] pub fn foo() { bar(); } From 2c175df013a701321e44bcdba3c7ba7772ed3b94 Mon Sep 17 00:00:00 2001 From: Irina-Gabriela Popa Date: Mon, 27 Nov 2017 17:21:13 +0200 Subject: [PATCH 3/3] rustc_back: replace tempdir with crates.io version. --- src/Cargo.lock | 2 + src/librustc_back/lib.rs | 1 - src/librustc_back/tempdir.rs | 114 ------------------ src/librustc_trans/Cargo.toml | 1 + src/librustc_trans/back/link.rs | 2 +- src/librustc_trans/lib.rs | 1 + src/librustdoc/Cargo.toml | 1 + src/librustdoc/lib.rs | 1 + src/librustdoc/test.rs | 2 +- .../run-pass-fulldeps/create-dir-all-bare.rs | 4 +- src/test/run-pass-fulldeps/issue-15149.rs | 4 +- .../run-pass-fulldeps/rename-directory.rs | 4 +- src/test/run-pass-fulldeps/stdio-from.rs | 4 +- src/test/run-pass-fulldeps/switch-stdout.rs | 4 +- 14 files changed, 18 insertions(+), 127 deletions(-) delete mode 100644 src/librustc_back/tempdir.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 0ee46910f7d6e..dc15486fe7cb2 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1960,6 +1960,7 @@ dependencies = [ "serialize 0.0.0", "syntax 0.0.0", "syntax_pos 0.0.0", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2013,6 +2014,7 @@ dependencies = [ "html-diff 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index e338ee7bd9328..ccf1db778d296 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -36,7 +36,6 @@ extern crate serialize; extern crate serialize as rustc_serialize; // used by deriving -pub mod tempdir; pub mod target; use std::str::FromStr; diff --git a/src/librustc_back/tempdir.rs b/src/librustc_back/tempdir.rs deleted file mode 100644 index 1a2515366224c..0000000000000 --- a/src/librustc_back/tempdir.rs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::env; -use std::io::{self, Error, ErrorKind}; -use std::fs; -use std::path::{self, PathBuf, Path}; -use rand::{thread_rng, Rng}; - -/// A wrapper for a path to temporary directory implementing automatic -/// scope-based deletion. -pub struct TempDir { - path: Option, -} - -// How many times should we (re)try finding an unused random name? It should be -// enough that an attacker will run out of luck before we run out of patience. -const NUM_RETRIES: u32 = 1 << 31; -// How many characters should we include in a random file name? It needs to -// be enough to dissuade an attacker from trying to preemptively create names -// of that length, but not so huge that we unnecessarily drain the random number -// generator of entropy. -const NUM_RAND_CHARS: usize = 12; - -impl TempDir { - /// Attempts to make a temporary directory inside of `tmpdir` whose name - /// will have the prefix `prefix`. The directory will be automatically - /// deleted once the returned wrapper is destroyed. - /// - /// If no directory can be created, `Err` is returned. - #[allow(deprecated)] // rand usage - pub fn new_in>(tmpdir: P, prefix: &str) - -> io::Result { - Self::_new_in(tmpdir.as_ref(), prefix) - } - - fn _new_in(tmpdir: &Path, prefix: &str) -> io::Result { - let storage; - let mut tmpdir = tmpdir; - if !tmpdir.is_absolute() { - let cur_dir = env::current_dir()?; - storage = cur_dir.join(tmpdir); - tmpdir = &storage; - // return TempDir::new_in(&cur_dir.join(tmpdir), prefix); - } - - let mut rng = thread_rng(); - for _ in 0..NUM_RETRIES { - let suffix: String = rng.gen_ascii_chars().take(NUM_RAND_CHARS).collect(); - let leaf = if !prefix.is_empty() { - format!("{}.{}", prefix, suffix) - } else { - // If we're given an empty string for a prefix, then creating a - // directory starting with "." would lead to it being - // semi-invisible on some systems. - suffix - }; - let path = tmpdir.join(&leaf); - match fs::create_dir(&path) { - Ok(_) => return Ok(TempDir { path: Some(path) }), - Err(ref e) if e.kind() == ErrorKind::AlreadyExists => {} - Err(e) => return Err(e) - } - } - - Err(Error::new(ErrorKind::AlreadyExists, - "too many temporary directories already exist")) - } - - /// Attempts to make a temporary directory inside of `env::temp_dir()` whose - /// name will have the prefix `prefix`. The directory will be automatically - /// deleted once the returned wrapper is destroyed. - /// - /// If no directory can be created, `Err` is returned. - pub fn new(prefix: &str) -> io::Result { - TempDir::new_in(&env::temp_dir(), prefix) - } - - /// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper. - /// This discards the wrapper so that the automatic deletion of the - /// temporary directory is prevented. - pub fn into_path(mut self) -> PathBuf { - self.path.take().unwrap() - } - - /// Access the wrapped `std::path::Path` to the temporary directory. - pub fn path(&self) -> &path::Path { - self.path.as_ref().unwrap() - } - - fn cleanup_dir(&mut self) -> io::Result<()> { - match self.path { - Some(ref p) => fs::remove_dir_all(p), - None => Ok(()) - } - } -} - -impl Drop for TempDir { - fn drop(&mut self) { - let _ = self.cleanup_dir(); - } -} - -// the tests for this module need to change the path using change_dir, -// and this doesn't play nicely with other tests so these unit tests are located -// in src/test/run-pass/tempfile.rs diff --git a/src/librustc_trans/Cargo.toml b/src/librustc_trans/Cargo.toml index 96102cad3ef5e..d8318ea808221 100644 --- a/src/librustc_trans/Cargo.toml +++ b/src/librustc_trans/Cargo.toml @@ -32,6 +32,7 @@ rustc_trans_utils = { path = "../librustc_trans_utils" } serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } +tempdir = "0.3" [target."cfg(windows)".dependencies] cc = "1.0.1" diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index e0eef1f5764b2..a182d7c6fbe06 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -26,7 +26,7 @@ use {CrateTranslation, CrateInfo}; use rustc::util::common::time; use rustc::util::fs::fix_windows_verbatim_for_gcc; use rustc::hir::def_id::CrateNum; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; use rustc_back::{PanicStrategy, RelroLevel, LinkerFlavor}; use context::get_reloc_model; use llvm; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 3d1bd81fe21a3..3c2e56bf2a127 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -63,6 +63,7 @@ extern crate rustc_errors as errors; extern crate serialize; #[cfg(windows)] extern crate cc; // Used to locate MSVC +extern crate tempdir; pub use base::trans_crate; use back::bytecode::RLIB_BYTECODE_EXTENSION; diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index eca3ebe9130fd..fd8a6e0b59326 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -14,6 +14,7 @@ doctest = false log = "0.3" pulldown-cmark = { version = "0.1.0", default-features = false } html-diff = "0.0.5" +tempdir = "0.3" [build-dependencies] build_helper = { path = "../build_helper" } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 967076779add0..f0bb87015f805 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -48,6 +48,7 @@ extern crate std_unicode; #[macro_use] extern crate log; extern crate rustc_errors as errors; extern crate pulldown_cmark; +extern crate tempdir; extern crate serialize as rustc_serialize; // used by deriving diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 98369949c02a4..74a16cb867d74 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -28,7 +28,7 @@ use rustc::session::{self, CompileIncomplete, config}; use rustc::session::config::{OutputType, OutputTypes, Externs}; use rustc::session::search_paths::{SearchPaths, PathKind}; use rustc_metadata::dynamic_lib::DynamicLibrary; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; use rustc_driver::{self, driver, Compilation}; use rustc_driver::driver::phase_2_configure_and_expand; use rustc_metadata::cstore::CStore; diff --git a/src/test/run-pass-fulldeps/create-dir-all-bare.rs b/src/test/run-pass-fulldeps/create-dir-all-bare.rs index e22736d77856a..ba42cb870c97e 100644 --- a/src/test/run-pass-fulldeps/create-dir-all-bare.rs +++ b/src/test/run-pass-fulldeps/create-dir-all-bare.rs @@ -12,11 +12,11 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate tempdir; use std::env; use std::fs; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; fn main() { let td = TempDir::new("create-dir-all-bare").unwrap(); diff --git a/src/test/run-pass-fulldeps/issue-15149.rs b/src/test/run-pass-fulldeps/issue-15149.rs index c0ed7165afeca..121fd4a9825df 100644 --- a/src/test/run-pass-fulldeps/issue-15149.rs +++ b/src/test/run-pass-fulldeps/issue-15149.rs @@ -13,13 +13,13 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate tempdir; use std::env; use std::fs; use std::process; use std::str; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; fn main() { // If we're the child, make sure we were invoked correctly diff --git a/src/test/run-pass-fulldeps/rename-directory.rs b/src/test/run-pass-fulldeps/rename-directory.rs index f107e1042816f..7a2a4343522bb 100644 --- a/src/test/run-pass-fulldeps/rename-directory.rs +++ b/src/test/run-pass-fulldeps/rename-directory.rs @@ -15,11 +15,11 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate tempdir; use std::ffi::CString; use std::fs::{self, File}; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; fn rename_directory() { let tmpdir = TempDir::new("rename_directory").ok().expect("rename_directory failed"); diff --git a/src/test/run-pass-fulldeps/stdio-from.rs b/src/test/run-pass-fulldeps/stdio-from.rs index f64bbf9312cd8..535ab711f5bcf 100644 --- a/src/test/run-pass-fulldeps/stdio-from.rs +++ b/src/test/run-pass-fulldeps/stdio-from.rs @@ -12,7 +12,7 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate tempdir; use std::env; use std::fs::File; @@ -20,7 +20,7 @@ use std::io; use std::io::{Read, Write}; use std::process::{Command, Stdio}; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; fn main() { if env::args().len() > 1 { diff --git a/src/test/run-pass-fulldeps/switch-stdout.rs b/src/test/run-pass-fulldeps/switch-stdout.rs index 4542e27545a4c..16f7e28328536 100644 --- a/src/test/run-pass-fulldeps/switch-stdout.rs +++ b/src/test/run-pass-fulldeps/switch-stdout.rs @@ -10,12 +10,12 @@ #![feature(rustc_private)] -extern crate rustc_back; +extern crate tempdir; use std::fs::File; use std::io::{Read, Write}; -use rustc_back::tempdir::TempDir; +use tempdir::TempDir; #[cfg(unix)] fn switch_stdout_to(file: File) {