Skip to content

Commit

Permalink
Rollup merge of #58312 - taiki-e:librustc_data_structures-2018, r=Cen…
Browse files Browse the repository at this point in the history
…tril

librustc_data_structures => 2018

Transitions `librustc_data_structures` to Rust 2018; cc #58099

r? @Centril
  • Loading branch information
Centril authored Feb 8, 2019
2 parents 5e208f6 + 3e2b5a4 commit 068a926
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 107 deletions.
5 changes: 3 additions & 2 deletions src/librustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_data_structures"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_data_structures"
Expand All @@ -16,8 +17,8 @@ serialize = { path = "../libserialize" }
graphviz = { path = "../libgraphviz" }
cfg-if = "0.1.2"
stable_deref_trait = "1.0.0"
rustc-rayon = "0.1.1"
rustc-rayon-core = "0.1.1"
rayon = { version = "0.1.1", package = "rustc-rayon" }
rayon-core = { version = "0.1.1", package = "rustc-rayon-core" }
rustc-hash = "1.0.1"
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/bit_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexed_vec::{Idx, IndexVec};
use crate::indexed_vec::{Idx, IndexVec};
use smallvec::SmallVec;
use std::fmt;
use std::iter;
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<T: Idx> SubtractFromBitSet<T> for BitSet<T> {
}

impl<T: Idx> fmt::Debug for BitSet<T> {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
w.debug_list()
.entries(self.iter())
.finish()
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<T: Idx> SparseBitSet<T> {
dense
}

fn iter(&self) -> slice::Iter<T> {
fn iter(&self) -> slice::Iter<'_, T> {
self.elems.iter()
}
}
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<T: Idx> HybridBitSet<T> {
}
}

pub fn iter(&self) -> HybridIter<T> {
pub fn iter(&self) -> HybridIter<'_, T> {
match self {
HybridBitSet::Sparse(sparse) => HybridIter::Sparse(sparse.iter()),
HybridBitSet::Dense(dense) => HybridIter::Dense(dense.iter()),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_data_structures/fingerprint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stable_hasher;
use std::mem;
use stable_hasher;
use serialize;
use serialize::opaque::{EncodeResult, Encoder, Decoder};

Expand Down Expand Up @@ -70,7 +70,7 @@ impl Fingerprint {
}

impl ::std::fmt::Display for Fingerprint {
fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fn fmt(&self, formatter: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(formatter, "{:x}-{:x}", self.0, self.1)
}
}
Expand Down
13 changes: 0 additions & 13 deletions src/librustc_data_structures/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ cfg_if! {
if #[cfg(unix)] {
use std::ffi::{CString, OsStr};
use std::os::unix::prelude::*;
use libc;

#[cfg(any(target_os = "linux", target_os = "android"))]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_type: libc::c_short,
Expand All @@ -35,8 +32,6 @@ cfg_if! {

#[cfg(target_os = "freebsd")]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_start: libc::off_t,
Expand All @@ -53,8 +48,6 @@ cfg_if! {
target_os = "netbsd",
target_os = "openbsd"))]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_start: libc::off_t,
Expand All @@ -70,8 +63,6 @@ cfg_if! {

#[cfg(target_os = "haiku")]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_type: libc::c_short,
Expand All @@ -87,8 +78,6 @@ cfg_if! {

#[cfg(any(target_os = "macos", target_os = "ios"))]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_start: libc::off_t,
Expand All @@ -104,8 +93,6 @@ cfg_if! {

#[cfg(target_os = "solaris")]
mod os {
use libc;

#[repr(C)]
pub struct flock {
pub l_type: libc::c_short,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<Node: Idx> Dominators<Node> {
self.immediate_dominators[node].unwrap()
}

pub fn dominators(&self, node: Node) -> Iter<Node> {
pub fn dominators(&self, node: Node) -> Iter<'_, Node> {
assert!(self.is_reachable(node), "node {:?} is not reachable", node);
Iter {
dominators: self,
Expand All @@ -136,7 +136,7 @@ impl<Node: Idx> Dominators<Node> {
}
}

pub struct Iter<'dom, Node: Idx + 'dom> {
pub struct Iter<'dom, Node: Idx> {
dominators: &'dom Dominators<Node>,
node: Option<Node>,
}
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<Node: Idx> DominatorTree<Node> {
}

impl<Node: Idx> fmt::Debug for DominatorTree<Node> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(
&DominatorTreeNode {
tree: self,
Expand All @@ -188,7 +188,7 @@ struct DominatorTreeNode<'tree, Node: Idx> {
}

impl<'tree, Node: Idx> fmt::Debug for DominatorTreeNode<'tree, Node> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let subtrees: Vec<_> = self.tree
.children(self.node)
.iter()
Expand Down
26 changes: 11 additions & 15 deletions src/librustc_data_structures/graph/implementation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
//! the field `next_edge`). Each of those fields is an array that should
//! be indexed by the direction (see the type `Direction`).

use bit_set::BitSet;
use crate::bit_set::BitSet;
use crate::snapshot_vec::{SnapshotVec, SnapshotVecDelegate};
use std::fmt::Debug;
use std::usize;
use snapshot_vec::{SnapshotVec, SnapshotVecDelegate};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -212,15 +212,19 @@ impl<N: Debug, E: Debug> Graph<N, E> {
.all(|(edge_idx, edge)| f(edge_idx, edge))
}

pub fn outgoing_edges(&self, source: NodeIndex) -> AdjacentEdges<N, E> {
pub fn outgoing_edges(&self, source: NodeIndex) -> AdjacentEdges<'_, N, E> {
self.adjacent_edges(source, OUTGOING)
}

pub fn incoming_edges(&self, source: NodeIndex) -> AdjacentEdges<N, E> {
pub fn incoming_edges(&self, source: NodeIndex) -> AdjacentEdges<'_, N, E> {
self.adjacent_edges(source, INCOMING)
}

pub fn adjacent_edges(&self, source: NodeIndex, direction: Direction) -> AdjacentEdges<N, E> {
pub fn adjacent_edges(
&self,
source: NodeIndex,
direction: Direction
) -> AdjacentEdges<'_, N, E> {
let first_edge = self.node(source).first_edge[direction.repr];
AdjacentEdges {
graph: self,
Expand Down Expand Up @@ -291,11 +295,7 @@ impl<N: Debug, E: Debug> Graph<N, E> {

// # Iterators

pub struct AdjacentEdges<'g, N, E>
where
N: 'g,
E: 'g,
{
pub struct AdjacentEdges<'g, N, E> {
graph: &'g Graph<N, E>,
direction: Direction,
next: EdgeIndex,
Expand Down Expand Up @@ -331,11 +331,7 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
}
}

pub struct DepthFirstTraversal<'g, N, E>
where
N: 'g,
E: 'g,
{
pub struct DepthFirstTraversal<'g, N, E> {
graph: &'g Graph<N, E>,
stack: Vec<NodeIndex>,
visited: BitSet<usize>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/graph/implementation/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use graph::implementation::*;
use crate::graph::implementation::*;
use std::fmt::Debug;

type TestGraph = Graph<&'static str, &'static str>;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! node in the graph. This uses Tarjan's algorithm that completes in
//! O(n) time.

use fx::FxHashSet;
use graph::{DirectedGraph, WithNumNodes, WithSuccessors};
use indexed_vec::{Idx, IndexVec};
use crate::fx::FxHashSet;
use crate::graph::{DirectedGraph, WithNumNodes, WithSuccessors};
use crate::indexed_vec::{Idx, IndexVec};
use std::ops::Range;

mod test;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl<S: Idx> SccData<S> {
}
}

struct SccsConstruction<'c, G: DirectedGraph + WithNumNodes + WithSuccessors + 'c, S: Idx> {
struct SccsConstruction<'c, G: DirectedGraph + WithNumNodes + WithSuccessors, S: Idx> {
graph: &'c G,

/// The state of each node; used during walk to record the stack
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/graph/scc/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

use graph::test::TestGraph;
use crate::graph::test::TestGraph;
use super::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/graph/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fx::FxHashMap;
use crate::fx::FxHashMap;
use std::cmp::max;
use std::slice;
use std::iter;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/indexed_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ macro_rules! newtype_index {
@type [$type:ident]
@debug_format [$debug_format:tt]) => (
impl ::std::fmt::Debug for $type {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(fmt, $debug_format, self.as_u32())
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ impl<I: Idx, T: serialize::Decodable> serialize::Decodable for IndexVec<I, T> {
}

impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.raw, fmt)
}
}
Expand Down Expand Up @@ -573,7 +573,7 @@ impl<I: Idx, T> IndexVec<I, T> {
}

#[inline]
pub fn iter(&self) -> slice::Iter<T> {
pub fn iter(&self) -> slice::Iter<'_, T> {
self.raw.iter()
}

Expand All @@ -589,7 +589,7 @@ impl<I: Idx, T> IndexVec<I, T> {
}

#[inline]
pub fn iter_mut(&mut self) -> slice::IterMut<T> {
pub fn iter_mut(&mut self) -> slice::IterMut<'_, T> {
self.raw.iter_mut()
}

Expand Down
13 changes: 3 additions & 10 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,16 @@
#![cfg_attr(unix, feature(libc))]
#![cfg_attr(test, feature(test))]

extern crate core;
extern crate ena;
#![deny(rust_2018_idioms)]

#[macro_use]
extern crate log;
#[allow(unused_extern_crates)]
extern crate serialize as rustc_serialize; // used by deriving
#[cfg(unix)]
extern crate libc;
extern crate parking_lot;
#[macro_use]
extern crate cfg_if;
extern crate stable_deref_trait;
extern crate rustc_rayon as rayon;
extern crate rustc_rayon_core as rayon_core;
extern crate rustc_hash;
extern crate serialize;
extern crate graphviz;
extern crate smallvec;

// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
#[allow(unused_extern_crates)]
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_data_structures/obligation_forest/graphviz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::obligation_forest::{ForestObligation, ObligationForest};
use graphviz as dot;
use obligation_forest::{ForestObligation, ObligationForest};
use std::env::var_os;
use std::fs::File;
use std::path::Path;
Expand Down Expand Up @@ -41,22 +41,22 @@ impl<'a, O: ForestObligation + 'a> dot::Labeller<'a> for &'a ObligationForest<O>
type Node = usize;
type Edge = (usize, usize);

fn graph_id(&self) -> dot::Id {
fn graph_id(&self) -> dot::Id<'_> {
dot::Id::new("trait_obligation_forest").unwrap()
}

fn node_id(&self, index: &Self::Node) -> dot::Id {
fn node_id(&self, index: &Self::Node) -> dot::Id<'_> {
dot::Id::new(format!("obligation_{}", index)).unwrap()
}

fn node_label(&self, index: &Self::Node) -> dot::LabelText {
fn node_label(&self, index: &Self::Node) -> dot::LabelText<'_> {
let node = &self.nodes[*index];
let label = format!("{:?} ({:?})", node.obligation.as_predicate(), node.state.get());

dot::LabelText::LabelStr(label.into())
}

fn edge_label(&self, (_index_source, _index_target): &Self::Edge) -> dot::LabelText {
fn edge_label(&self, (_index_source, _index_target): &Self::Edge) -> dot::LabelText<'_> {
dot::LabelText::LabelStr("".into())
}
}
Expand All @@ -65,11 +65,11 @@ impl<'a, O: ForestObligation + 'a> dot::GraphWalk<'a> for &'a ObligationForest<O
type Node = usize;
type Edge = (usize, usize);

fn nodes(&self) -> dot::Nodes<Self::Node> {
fn nodes(&self) -> dot::Nodes<'_, Self::Node> {
(0..self.nodes.len()).collect()
}

fn edges(&self) -> dot::Edges<Self::Edge> {
fn edges(&self) -> dot::Edges<'_, Self::Edge> {
(0..self.nodes.len())
.flat_map(|i| {
let node = &self.nodes[i];
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_data_structures/obligation_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
//! processing step, we compress the vector to remove completed and error
//! nodes, which aren't needed anymore.

use fx::{FxHashMap, FxHashSet};
use crate::fx::{FxHashMap, FxHashSet};

use std::cell::Cell;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -733,7 +733,7 @@ impl<O> Node<O> {

// I need a Clone closure
#[derive(Clone)]
struct GetObligation<'a, O: 'a>(&'a [Node<O>]);
struct GetObligation<'a, O>(&'a [Node<O>]);

impl<'a, 'b, O> FnOnce<(&'b usize,)> for GetObligation<'a, O> {
type Output = &'a O;
Expand Down
Loading

0 comments on commit 068a926

Please sign in to comment.