Use more Self keywords instead of repeating the type name.

This commit is contained in:
Dan Gohman
2018-10-05 16:40:50 -07:00
parent 9a1e966156
commit 17a9631981
16 changed files with 40 additions and 58 deletions

View File

@@ -266,12 +266,8 @@ where
C: Comparator<K>,
{
/// Create a cursor with a default (off-the-end) location.
fn new(
container: &'a mut Map<K, V>,
forest: &'a mut MapForest<K, V>,
comp: &'a C,
) -> MapCursor<'a, K, V, C> {
MapCursor {
fn new(container: &'a mut Map<K, V>, forest: &'a mut MapForest<K, V>, comp: &'a C) -> Self {
Self {
root: &mut container.root,
pool: &mut forest.nodes,
comp,

View File

@@ -207,12 +207,8 @@ where
C: Comparator<K>,
{
/// Create a cursor with a default (invalid) location.
fn new(
container: &'a mut Set<K>,
forest: &'a mut SetForest<K>,
comp: &'a C,
) -> SetCursor<'a, K, C> {
SetCursor {
fn new(container: &'a mut Set<K>, forest: &'a mut SetForest<K>, comp: &'a C) -> Self {
Self {
root: &mut container.root,
pool: &mut forest.nodes,
comp,

View File

@@ -300,8 +300,8 @@ pub struct VectorType {
impl VectorType {
/// Initialize a new integer type with `n` bits.
pub fn new(base: LaneType, lanes: u64) -> VectorType {
VectorType { base, lanes }
pub fn new(base: LaneType, lanes: u64) -> Self {
Self { base, lanes }
}
/// Return a string containing the documentation comment for this vector type.

View File

@@ -38,8 +38,8 @@ pub struct Formatter {
impl Formatter {
/// Source code formatter class. Used to collect source code to be written
/// to a file, and keep track of indentation.
pub fn new() -> Formatter {
Formatter {
pub fn new() -> Self {
Self {
indent: 0,
lines: Vec::new(),
}

View File

@@ -43,12 +43,8 @@ impl<'a> MemoryCodeSink<'a> {
///
/// This function is unsafe since `MemoryCodeSink` does not perform bounds checking on the
/// memory buffer, and it can't guarantee that the `data` pointer is valid.
pub unsafe fn new<'sink>(
data: *mut u8,
relocs: &'sink mut RelocSink,
traps: &'sink mut TrapSink,
) -> MemoryCodeSink<'sink> {
MemoryCodeSink {
pub unsafe fn new(data: *mut u8, relocs: &'a mut RelocSink, traps: &'a mut TrapSink) -> Self {
Self {
data,
offset: 0,
code_size: 0,

View File

@@ -15,8 +15,8 @@ pub struct CFGPrinter<'a> {
/// A utility for pretty-printing the CFG of a `Function`.
impl<'a> CFGPrinter<'a> {
/// Create a new CFGPrinter.
pub fn new(func: &'a Function) -> CFGPrinter<'a> {
CFGPrinter {
pub fn new(func: &'a Function) -> Self {
Self {
func,
cfg: ControlFlowGraph::with_function(func),
}

View File

@@ -580,8 +580,8 @@ pub struct FuncCursor<'f> {
impl<'f> FuncCursor<'f> {
/// Create a new `FuncCursor` pointing nowhere.
pub fn new(func: &'f mut ir::Function) -> FuncCursor<'f> {
FuncCursor {
pub fn new(func: &'f mut ir::Function) -> Self {
Self {
pos: CursorPosition::Nowhere,
srcloc: Default::default(),
func,
@@ -662,8 +662,8 @@ pub struct EncCursor<'f> {
impl<'f> EncCursor<'f> {
/// Create a new `EncCursor` pointing nowhere.
pub fn new(func: &'f mut ir::Function, isa: &'f TargetIsa) -> EncCursor<'f> {
EncCursor {
pub fn new(func: &'f mut ir::Function, isa: &'f TargetIsa) -> Self {
Self {
pos: CursorPosition::Nowhere,
srcloc: Default::default(),
built_inst: None,

View File

@@ -74,8 +74,8 @@ pub struct InsertBuilder<'f, IIB: InstInserterBase<'f>> {
impl<'f, IIB: InstInserterBase<'f>> InsertBuilder<'f, IIB> {
/// Create a new builder which inserts instructions at `pos`.
/// The `dfg` and `pos.layout` references should be from the same `Function`.
pub fn new(inserter: IIB) -> InsertBuilder<'f, IIB> {
InsertBuilder {
pub fn new(inserter: IIB) -> Self {
Self {
inserter,
unused: PhantomData,
}
@@ -185,8 +185,8 @@ pub struct ReplaceBuilder<'f> {
impl<'f> ReplaceBuilder<'f> {
/// Create a `ReplaceBuilder` that will overwrite `inst`.
pub fn new(dfg: &'f mut DataFlowGraph, inst: Inst) -> ReplaceBuilder {
ReplaceBuilder { dfg, inst }
pub fn new(dfg: &'f mut DataFlowGraph, inst: Inst) -> Self {
Self { dfg, inst }
}
}

View File

@@ -782,8 +782,8 @@ mod tests {
impl<'f> LayoutCursor<'f> {
/// Create a new `LayoutCursor` for `layout`.
/// The cursor holds a mutable reference to `layout` for its entire lifetime.
pub fn new(layout: &'f mut Layout) -> LayoutCursor<'f> {
LayoutCursor {
pub fn new(layout: &'f mut Layout) -> Self {
Self {
layout,
pos: CursorPosition::Nowhere,
}

View File

@@ -188,11 +188,8 @@ pub struct LiveRangeContext<'a, PO: 'a + ProgramOrder> {
impl<'a, PO: ProgramOrder> LiveRangeContext<'a, PO> {
/// Make a new context.
pub fn new(
order: &'a PO,
forest: &'a bforest::MapForest<Ebb, Inst>,
) -> LiveRangeContext<'a, PO> {
LiveRangeContext { order, forest }
pub fn new(order: &'a PO, forest: &'a bforest::MapForest<Ebb, Inst>) -> Self {
Self { order, forest }
}
}

View File

@@ -182,7 +182,7 @@ impl<'a> PredicateView<'a> {
/// Create a new view of a precomputed predicate vector.
///
/// See the `predicate_view()` method on the various `Flags` types defined for each ISA.
pub fn new(bits: &'a [u8]) -> PredicateView {
pub fn new(bits: &'a [u8]) -> Self {
PredicateView(bits)
}

View File

@@ -311,10 +311,10 @@ struct Verifier<'a> {
}
impl<'a> Verifier<'a> {
pub fn new(func: &'a Function, fisa: FlagsOrIsa<'a>) -> Verifier<'a> {
pub fn new(func: &'a Function, fisa: FlagsOrIsa<'a>) -> Self {
let expected_cfg = ControlFlowGraph::with_function(func);
let expected_domtree = DominatorTree::with_function(func, &expected_cfg);
Verifier {
Self {
func,
expected_cfg,
expected_domtree,

View File

@@ -103,8 +103,8 @@ pub struct FuncInstBuilder<'short, 'long: 'short> {
}
impl<'short, 'long> FuncInstBuilder<'short, 'long> {
fn new<'s, 'l>(builder: &'s mut FunctionBuilder<'l>, ebb: Ebb) -> FuncInstBuilder<'s, 'l> {
FuncInstBuilder { builder, ebb }
fn new(builder: &'short mut FunctionBuilder<'long>, ebb: Ebb) -> Self {
Self { builder, ebb }
}
}
@@ -210,12 +210,9 @@ impl<'short, 'long> InstBuilderBase<'short> for FuncInstBuilder<'short, 'long> {
impl<'a> FunctionBuilder<'a> {
/// Creates a new FunctionBuilder structure that will operate on a `Function` using a
/// `FunctionBuilderContext`.
pub fn new(
func: &'a mut Function,
func_ctx: &'a mut FunctionBuilderContext,
) -> FunctionBuilder<'a> {
pub fn new(func: &'a mut Function, func_ctx: &'a mut FunctionBuilderContext) -> Self {
debug_assert!(func_ctx.is_empty());
FunctionBuilder {
Self {
func,
srcloc: Default::default(),
func_ctx,

View File

@@ -128,8 +128,8 @@ pub struct Lexer<'a> {
}
impl<'a> Lexer<'a> {
pub fn new(s: &'a str) -> Lexer {
let mut lex = Lexer {
pub fn new(s: &'a str) -> Self {
let mut lex = Self {
source: s,
chars: s.char_indices(),
lookahead: None,

View File

@@ -117,8 +117,8 @@ struct Context<'a> {
}
impl<'a> Context<'a> {
fn new(f: Function, unique_isa: Option<&'a TargetIsa>) -> Context<'a> {
Context {
fn new(f: Function, unique_isa: Option<&'a TargetIsa>) -> Self {
Self {
function: f,
map: SourceMap::new(),
unique_isa,
@@ -309,8 +309,8 @@ impl<'a> Context<'a> {
impl<'a> Parser<'a> {
/// Create a new `Parser` which reads `text`. The referenced text must outlive the parser.
pub fn new(text: &'a str) -> Parser {
Parser {
pub fn new(text: &'a str) -> Self {
Self {
lex: Lexer::new(text),
lex_error: None,
lookahead: None,

View File

@@ -35,10 +35,10 @@ pub enum TestOption<'a> {
impl<'a> TestCommand<'a> {
/// Create a new TestCommand by parsing `s`.
/// The returned command contains references into `s`.
pub fn new(s: &'a str) -> TestCommand<'a> {
pub fn new(s: &'a str) -> Self {
let mut parts = s.split_whitespace();
let cmd = parts.next().unwrap_or("");
TestCommand {
Self {
command: cmd,
options: parts
.filter(|s| !s.is_empty())
@@ -61,7 +61,7 @@ impl<'a> Display for TestCommand<'a> {
impl<'a> TestOption<'a> {
/// Create a new TestOption by parsing `s`.
/// The returned option contains references into `s`.
pub fn new(s: &'a str) -> TestOption<'a> {
pub fn new(s: &'a str) -> Self {
match s.find('=') {
None => TestOption::Flag(s),
Some(p) => TestOption::Value(&s[0..p], &s[p + 1..]),