Tidy up some match bindings to be more consistent with the rest of the codebase.

This commit is contained in:
Dan Gohman
2018-12-11 13:22:28 -08:00
parent c8e457e834
commit 8bd35e154b
3 changed files with 11 additions and 10 deletions

View File

@@ -101,7 +101,8 @@ impl Preset {
let mask = setting.byte_mask();
let val = setting.byte_for_value(true);
assert!((val & !mask) == 0);
let (l_mask, l_val) = layout.get_mut(setting.byte_offset as usize).unwrap();
let (ref mut l_mask, ref mut l_val) =
*layout.get_mut(setting.byte_offset as usize).unwrap();
*l_mask |= mask;
*l_val = (*l_val & !mask) | val;
}
@@ -186,15 +187,15 @@ impl<'a> Into<PredicateNode> for (BoolSettingIndex, &'a SettingGroup) {
impl PredicateNode {
fn render(&self, group: &SettingGroup) -> String {
match self {
match *self {
PredicateNode::OwnedBool(bool_setting_index) => format!(
"{}.{}()",
group.name, group.settings[bool_setting_index.0].name
),
PredicateNode::SharedBool(group_name, bool_name) => {
PredicateNode::SharedBool(ref group_name, ref bool_name) => {
format!("{}.{}()", group_name, bool_name)
}
PredicateNode::And(lhs, rhs) => {
PredicateNode::And(ref lhs, ref rhs) => {
format!("{} && {}", lhs.render(group), rhs.render(group))
}
}

View File

@@ -224,7 +224,7 @@ enum SettingOrPreset<'a> {
impl<'a> SettingOrPreset<'a> {
fn name(&self) -> &str {
match self {
match *self {
SettingOrPreset::Setting(s) => s.name,
SettingOrPreset::Preset(p) => p.name,
}
@@ -248,14 +248,14 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
fmt.indent(|fmt| {
fmt.line(&format!("name: \"{}\",", setting.name));
fmt.line(&format!("offset: {},", setting.byte_offset));
match &setting.specific {
match setting.specific {
SpecificSetting::Bool(BoolSetting { bit_offset, .. }) => {
fmt.line(&format!(
"detail: detail::Detail::Bool {{ bit: {} }},",
bit_offset
));
}
SpecificSetting::Enum(values) => {
SpecificSetting::Enum(ref values) => {
let offset = enum_table.add(values);
fmt.line(&format!(
"detail: detail::Detail::Enum {{ last: {}, enumerators: {} }},",
@@ -322,7 +322,7 @@ fn gen_descriptors(group: &SettingGroup, fmt: &mut Formatter) {
));
fmt.indent(|fmt| {
for h in &hash_table {
match h {
match *h {
Some(setting_or_preset) => fmt.line(&format!(
"{},",
&descriptor_index_map

View File

@@ -122,7 +122,7 @@ impl Formatter {
pub fn add_match(&mut self, m: Match) {
self.line(&format!("match {} {{", m.expr));
self.indent(|fmt| {
for ((fields, body), names) in m.arms.iter() {
for (&(ref fields, ref body), ref names) in m.arms.iter() {
// name { fields } | name { fields } => { body }
let conditions: Vec<String> = names
.iter()
@@ -252,7 +252,7 @@ mod srcgen_tests {
use super::Formatter;
use super::Match;
fn from_raw_string(s: impl Into<String>) -> Vec<String> {
fn from_raw_string<S: Into<String>>(s: S) -> Vec<String> {
s.into()
.trim()
.split("\n")