rustc_back: remove slice module in favor of std::slice::from_ref.

This commit is contained in:
Irina-Gabriela Popa 2017-11-23 16:41:51 +02:00
parent fdfbcf85d5
commit d6f70359dc
17 changed files with 28 additions and 54 deletions

3
src/Cargo.lock generated
View File

@ -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",

View File

@ -46,6 +46,7 @@
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![feature(from_ref)]
#![feature(i128)]
#![feature(i128_type)]
#![feature(inclusive_range)]

View File

@ -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)),
}
}
}

View File

@ -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() {

View File

@ -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);

View File

@ -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;

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::mem;
pub fn ref_slice<T>(ptr: &T) -> &[T; 1] {
unsafe { mem::transmute(ptr) }
}
pub fn mut_ref_slice<T>(ptr: &mut T) -> &mut [T; 1] {
unsafe { mem::transmute(ptr) }
}

View File

@ -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" }

View File

@ -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));
}
}

View File

@ -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.

View File

@ -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" }

View File

@ -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));
}
}
}

View File

@ -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;

View File

@ -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" }

View File

@ -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

View File

@ -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<hir::Expr>] = match tail_expr {
Some(e) => ref_slice(e),
Some(e) => slice::from_ref(e),
None => &[],
};
CoerceMany::with_coercion_sites(coerce_to_ty, tail_expr)

View File

@ -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;