diff --git a/lib/bforest/src/map.rs b/lib/bforest/src/map.rs index 636cee2df5..97ab7e6d90 100644 --- a/lib/bforest/src/map.rs +++ b/lib/bforest/src/map.rs @@ -266,12 +266,8 @@ where C: Comparator, { /// Create a cursor with a default (off-the-end) location. - fn new( - container: &'a mut Map, - forest: &'a mut MapForest, - comp: &'a C, - ) -> MapCursor<'a, K, V, C> { - MapCursor { + fn new(container: &'a mut Map, forest: &'a mut MapForest, comp: &'a C) -> Self { + Self { root: &mut container.root, pool: &mut forest.nodes, comp, diff --git a/lib/bforest/src/set.rs b/lib/bforest/src/set.rs index cf4acdf9e3..f950e1e3cb 100644 --- a/lib/bforest/src/set.rs +++ b/lib/bforest/src/set.rs @@ -207,12 +207,8 @@ where C: Comparator, { /// Create a cursor with a default (invalid) location. - fn new( - container: &'a mut Set, - forest: &'a mut SetForest, - comp: &'a C, - ) -> SetCursor<'a, K, C> { - SetCursor { + fn new(container: &'a mut Set, forest: &'a mut SetForest, comp: &'a C) -> Self { + Self { root: &mut container.root, pool: &mut forest.nodes, comp, diff --git a/lib/codegen/meta/src/cdsl/types.rs b/lib/codegen/meta/src/cdsl/types.rs index 90438e9179..9d2e9a16dc 100644 --- a/lib/codegen/meta/src/cdsl/types.rs +++ b/lib/codegen/meta/src/cdsl/types.rs @@ -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. diff --git a/lib/codegen/meta/src/srcgen.rs b/lib/codegen/meta/src/srcgen.rs index 53a4dc5f75..2e2babe512 100644 --- a/lib/codegen/meta/src/srcgen.rs +++ b/lib/codegen/meta/src/srcgen.rs @@ -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(), } diff --git a/lib/codegen/src/binemit/memorysink.rs b/lib/codegen/src/binemit/memorysink.rs index c7ec60de89..1e8a6ab15f 100644 --- a/lib/codegen/src/binemit/memorysink.rs +++ b/lib/codegen/src/binemit/memorysink.rs @@ -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, diff --git a/lib/codegen/src/cfg_printer.rs b/lib/codegen/src/cfg_printer.rs index ebc2058489..382c83c658 100644 --- a/lib/codegen/src/cfg_printer.rs +++ b/lib/codegen/src/cfg_printer.rs @@ -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), } diff --git a/lib/codegen/src/cursor.rs b/lib/codegen/src/cursor.rs index 6d475331ad..daa23308f2 100644 --- a/lib/codegen/src/cursor.rs +++ b/lib/codegen/src/cursor.rs @@ -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, diff --git a/lib/codegen/src/ir/builder.rs b/lib/codegen/src/ir/builder.rs index 9128092f67..4e3866ad17 100644 --- a/lib/codegen/src/ir/builder.rs +++ b/lib/codegen/src/ir/builder.rs @@ -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 } } } diff --git a/lib/codegen/src/ir/layout.rs b/lib/codegen/src/ir/layout.rs index a251822847..f598246b84 100644 --- a/lib/codegen/src/ir/layout.rs +++ b/lib/codegen/src/ir/layout.rs @@ -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, } diff --git a/lib/codegen/src/regalloc/liverange.rs b/lib/codegen/src/regalloc/liverange.rs index cc6a985641..7e56b88fb9 100644 --- a/lib/codegen/src/regalloc/liverange.rs +++ b/lib/codegen/src/regalloc/liverange.rs @@ -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, - ) -> LiveRangeContext<'a, PO> { - LiveRangeContext { order, forest } + pub fn new(order: &'a PO, forest: &'a bforest::MapForest) -> Self { + Self { order, forest } } } diff --git a/lib/codegen/src/settings.rs b/lib/codegen/src/settings.rs index c9374d9e47..3f7d684a87 100644 --- a/lib/codegen/src/settings.rs +++ b/lib/codegen/src/settings.rs @@ -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) } diff --git a/lib/codegen/src/verifier/mod.rs b/lib/codegen/src/verifier/mod.rs index 49deccd777..0219b18db4 100644 --- a/lib/codegen/src/verifier/mod.rs +++ b/lib/codegen/src/verifier/mod.rs @@ -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, diff --git a/lib/frontend/src/frontend.rs b/lib/frontend/src/frontend.rs index e637d6bf18..716f5cf3de 100644 --- a/lib/frontend/src/frontend.rs +++ b/lib/frontend/src/frontend.rs @@ -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, diff --git a/lib/reader/src/lexer.rs b/lib/reader/src/lexer.rs index c1d9a81d93..5ac84ab773 100644 --- a/lib/reader/src/lexer.rs +++ b/lib/reader/src/lexer.rs @@ -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, diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index 4840387e5a..8951fb8dab 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -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, diff --git a/lib/reader/src/testcommand.rs b/lib/reader/src/testcommand.rs index 229957b17e..17896a070c 100644 --- a/lib/reader/src/testcommand.rs +++ b/lib/reader/src/testcommand.rs @@ -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..]),