mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 17:42:47 +00:00
Preserve mutability for typed self arguments
This commit is contained in:
parent
c0b7de7c52
commit
954dd0869e
32
src/items.rs
32
src/items.rs
@ -930,27 +930,35 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf, args: &[ast::Arg]) -
|
||||
}
|
||||
}
|
||||
ast::ExplicitSelf_::SelfExplicit(ref ty, _) => {
|
||||
Some(format!("self: {}", pprust::ty_to_string(ty)))
|
||||
assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty.");
|
||||
|
||||
let mutability = explicit_self_mutability(&args[0]);
|
||||
|
||||
Some(format!("{}self: {}",
|
||||
format_mutability(mutability),
|
||||
pprust::ty_to_string(ty)))
|
||||
}
|
||||
ast::ExplicitSelf_::SelfValue(_) => {
|
||||
assert!(args.len() >= 1, "&[ast::Arg] shouldn't be empty.");
|
||||
assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty.");
|
||||
|
||||
// this hacky solution caused by absence of `Mutability` in `SelfValue`.
|
||||
let mut_str = {
|
||||
if let ast::Pat_::PatIdent(ast::BindingMode::BindByValue(mutability), _, _) =
|
||||
args[0].pat.node {
|
||||
format_mutability(mutability)
|
||||
} else {
|
||||
panic!("there is a bug or change in structure of AST, aborting.");
|
||||
}
|
||||
};
|
||||
let mutability = explicit_self_mutability(&args[0]);
|
||||
|
||||
Some(format!("{}self", mut_str))
|
||||
Some(format!("{}self", format_mutability(mutability)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Hacky solution caused by absence of `Mutability` in `SelfValue` and
|
||||
// `SelfExplicit` variants of `ast::ExplicitSelf_`.
|
||||
fn explicit_self_mutability(arg: &ast::Arg) -> ast::Mutability {
|
||||
if let ast::Pat_::PatIdent(ast::BindingMode::BindByValue(mutability), _, _) = arg.pat.node {
|
||||
mutability
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn span_lo_for_arg(arg: &ast::Arg) -> BytePos {
|
||||
if is_named_arg(arg) {
|
||||
arg.pat.span.lo
|
||||
|
@ -58,3 +58,5 @@ impl Blah {
|
||||
fn boop() {}
|
||||
add_fun!();
|
||||
}
|
||||
|
||||
impl X { fn do_parse( mut self : X ) {} }
|
||||
|
@ -72,3 +72,7 @@ impl Blah {
|
||||
fn boop() {}
|
||||
add_fun!();
|
||||
}
|
||||
|
||||
impl X {
|
||||
fn do_parse(mut self: X) {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user