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

@@ -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..]),