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>, C: Comparator<K>,
{ {
/// Create a cursor with a default (off-the-end) location. /// Create a cursor with a default (off-the-end) location.
fn new( fn new(container: &'a mut Map<K, V>, forest: &'a mut MapForest<K, V>, comp: &'a C) -> Self {
container: &'a mut Map<K, V>, Self {
forest: &'a mut MapForest<K, V>,
comp: &'a C,
) -> MapCursor<'a, K, V, C> {
MapCursor {
root: &mut container.root, root: &mut container.root,
pool: &mut forest.nodes, pool: &mut forest.nodes,
comp, comp,

View File

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

View File

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

View File

@@ -38,8 +38,8 @@ pub struct Formatter {
impl Formatter { impl Formatter {
/// Source code formatter class. Used to collect source code to be written /// Source code formatter class. Used to collect source code to be written
/// to a file, and keep track of indentation. /// to a file, and keep track of indentation.
pub fn new() -> Formatter { pub fn new() -> Self {
Formatter { Self {
indent: 0, indent: 0,
lines: Vec::new(), 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 /// 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. /// memory buffer, and it can't guarantee that the `data` pointer is valid.
pub unsafe fn new<'sink>( pub unsafe fn new(data: *mut u8, relocs: &'a mut RelocSink, traps: &'a mut TrapSink) -> Self {
data: *mut u8, Self {
relocs: &'sink mut RelocSink,
traps: &'sink mut TrapSink,
) -> MemoryCodeSink<'sink> {
MemoryCodeSink {
data, data,
offset: 0, offset: 0,
code_size: 0, code_size: 0,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -182,7 +182,7 @@ impl<'a> PredicateView<'a> {
/// Create a new view of a precomputed predicate vector. /// Create a new view of a precomputed predicate vector.
/// ///
/// See the `predicate_view()` method on the various `Flags` types defined for each ISA. /// 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) PredicateView(bits)
} }

View File

@@ -311,10 +311,10 @@ struct Verifier<'a> {
} }
impl<'a> 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_cfg = ControlFlowGraph::with_function(func);
let expected_domtree = DominatorTree::with_function(func, &expected_cfg); let expected_domtree = DominatorTree::with_function(func, &expected_cfg);
Verifier { Self {
func, func,
expected_cfg, expected_cfg,
expected_domtree, expected_domtree,

View File

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

View File

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

View File

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

View File

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