[clippy] Pass a few argument types by value, not by reference;

Since Location is basically just a usize, and wasmparser::Type is an
enum, and both are copiable, this passes them down by value instead of
by reference, as suggested by Clippy.
This commit is contained in:
Benjamin Bouvier
2018-07-09 16:15:17 +02:00
committed by Dan Gohman
parent b263a8344c
commit 26523fdf5c
4 changed files with 52 additions and 57 deletions

View File

@@ -51,7 +51,7 @@ pub fn parse_sets_and_triple(
parse_options( parse_options(
flag_set.iter().map(|x| x.as_str()), flag_set.iter().map(|x| x.as_str()),
&mut flag_builder, &mut flag_builder,
&Location { line_number: 0 }, Location { line_number: 0 },
).map_err(|err| err.to_string())?; ).map_err(|err| err.to_string())?;
let mut words = flag_triple.trim().split_whitespace(); let mut words = flag_triple.trim().split_whitespace();
@@ -71,7 +71,7 @@ pub fn parse_sets_and_triple(
), ),
})?; })?;
// Apply the ISA-specific settings to `isa_builder`. // Apply the ISA-specific settings to `isa_builder`.
parse_options(words, &mut isa_builder, &Location { line_number: 0 }) parse_options(words, &mut isa_builder, Location { line_number: 0 })
.map_err(|err| err.to_string())?; .map_err(|err| err.to_string())?;
Ok(OwnedFlagsOrIsa::Isa( Ok(OwnedFlagsOrIsa::Isa(

View File

@@ -35,7 +35,7 @@ impl IsaSpec {
} }
/// Parse an iterator of command line options and apply them to `config`. /// Parse an iterator of command line options and apply them to `config`.
pub fn parse_options<'a, I>(iter: I, config: &mut Configurable, loc: &Location) -> ParseResult<()> pub fn parse_options<'a, I>(iter: I, config: &mut Configurable, loc: Location) -> ParseResult<()>
where where
I: Iterator<Item = &'a str>, I: Iterator<Item = &'a str>,
{ {

View File

@@ -122,7 +122,7 @@ impl<'a> Context<'a> {
} }
// Allocate a new stack slot. // Allocate a new stack slot.
fn add_ss(&mut self, ss: StackSlot, data: StackSlotData, loc: &Location) -> ParseResult<()> { fn add_ss(&mut self, ss: StackSlot, data: StackSlotData, loc: Location) -> ParseResult<()> {
while self.function.stack_slots.next_key().index() <= ss.index() { while self.function.stack_slots.next_key().index() <= ss.index() {
self.function self.function
.create_stack_slot(StackSlotData::new(StackSlotKind::SpillSlot, 0)); .create_stack_slot(StackSlotData::new(StackSlotKind::SpillSlot, 0));
@@ -132,7 +132,7 @@ impl<'a> Context<'a> {
} }
// Resolve a reference to a stack slot. // Resolve a reference to a stack slot.
fn check_ss(&self, ss: StackSlot, loc: &Location) -> ParseResult<()> { fn check_ss(&self, ss: StackSlot, loc: Location) -> ParseResult<()> {
if !self.map.contains_ss(ss) { if !self.map.contains_ss(ss) {
err!(loc, "undefined stack slot {}", ss) err!(loc, "undefined stack slot {}", ss)
} else { } else {
@@ -141,12 +141,7 @@ impl<'a> Context<'a> {
} }
// Allocate a global value slot. // Allocate a global value slot.
fn add_gv( fn add_gv(&mut self, gv: GlobalValue, data: GlobalValueData, loc: Location) -> ParseResult<()> {
&mut self,
gv: GlobalValue,
data: GlobalValueData,
loc: &Location,
) -> ParseResult<()> {
while self.function.global_values.next_key().index() <= gv.index() { while self.function.global_values.next_key().index() <= gv.index() {
self.function.create_global_value(GlobalValueData::Sym { self.function.create_global_value(GlobalValueData::Sym {
name: ExternalName::testcase(""), name: ExternalName::testcase(""),
@@ -158,7 +153,7 @@ impl<'a> Context<'a> {
} }
// Resolve a reference to a global value. // Resolve a reference to a global value.
fn check_gv(&self, gv: GlobalValue, loc: &Location) -> ParseResult<()> { fn check_gv(&self, gv: GlobalValue, loc: Location) -> ParseResult<()> {
if !self.map.contains_gv(gv) { if !self.map.contains_gv(gv) {
err!(loc, "undefined global value {}", gv) err!(loc, "undefined global value {}", gv)
} else { } else {
@@ -167,7 +162,7 @@ impl<'a> Context<'a> {
} }
// Allocate a heap slot. // Allocate a heap slot.
fn add_heap(&mut self, heap: Heap, data: HeapData, loc: &Location) -> ParseResult<()> { fn add_heap(&mut self, heap: Heap, data: HeapData, loc: Location) -> ParseResult<()> {
while self.function.heaps.next_key().index() <= heap.index() { while self.function.heaps.next_key().index() <= heap.index() {
self.function.create_heap(HeapData { self.function.create_heap(HeapData {
base: HeapBase::ReservedReg, base: HeapBase::ReservedReg,
@@ -183,7 +178,7 @@ impl<'a> Context<'a> {
} }
// Resolve a reference to a heap. // Resolve a reference to a heap.
fn check_heap(&self, heap: Heap, loc: &Location) -> ParseResult<()> { fn check_heap(&self, heap: Heap, loc: Location) -> ParseResult<()> {
if !self.map.contains_heap(heap) { if !self.map.contains_heap(heap) {
err!(loc, "undefined heap {}", heap) err!(loc, "undefined heap {}", heap)
} else { } else {
@@ -192,7 +187,7 @@ impl<'a> Context<'a> {
} }
// Allocate a new signature. // Allocate a new signature.
fn add_sig(&mut self, sig: SigRef, data: Signature, loc: &Location) -> ParseResult<()> { fn add_sig(&mut self, sig: SigRef, data: Signature, loc: Location) -> ParseResult<()> {
while self.function.dfg.signatures.next_key().index() <= sig.index() { while self.function.dfg.signatures.next_key().index() <= sig.index() {
self.function self.function
.import_signature(Signature::new(CallConv::Fast)); .import_signature(Signature::new(CallConv::Fast));
@@ -211,7 +206,7 @@ impl<'a> Context<'a> {
} }
// Allocate a new external function. // Allocate a new external function.
fn add_fn(&mut self, fn_: FuncRef, data: ExtFuncData, loc: &Location) -> ParseResult<()> { fn add_fn(&mut self, fn_: FuncRef, data: ExtFuncData, loc: Location) -> ParseResult<()> {
while self.function.dfg.ext_funcs.next_key().index() <= fn_.index() { while self.function.dfg.ext_funcs.next_key().index() <= fn_.index() {
self.function.import_function(ExtFuncData { self.function.import_function(ExtFuncData {
name: ExternalName::testcase(""), name: ExternalName::testcase(""),
@@ -224,7 +219,7 @@ impl<'a> Context<'a> {
} }
// Resolve a reference to a function. // Resolve a reference to a function.
fn check_fn(&self, fn_: FuncRef, loc: &Location) -> ParseResult<()> { fn check_fn(&self, fn_: FuncRef, loc: Location) -> ParseResult<()> {
if !self.map.contains_fn(fn_) { if !self.map.contains_fn(fn_) {
err!(loc, "undefined function {}", fn_) err!(loc, "undefined function {}", fn_)
} else { } else {
@@ -233,7 +228,7 @@ impl<'a> Context<'a> {
} }
// Allocate a new jump table. // Allocate a new jump table.
fn add_jt(&mut self, jt: JumpTable, data: JumpTableData, loc: &Location) -> ParseResult<()> { fn add_jt(&mut self, jt: JumpTable, data: JumpTableData, loc: Location) -> ParseResult<()> {
while self.function.jump_tables.next_key().index() <= jt.index() { while self.function.jump_tables.next_key().index() <= jt.index() {
self.function.create_jump_table(JumpTableData::new()); self.function.create_jump_table(JumpTableData::new());
} }
@@ -242,7 +237,7 @@ impl<'a> Context<'a> {
} }
// Resolve a reference to a jump table. // Resolve a reference to a jump table.
fn check_jt(&self, jt: JumpTable, loc: &Location) -> ParseResult<()> { fn check_jt(&self, jt: JumpTable, loc: Location) -> ParseResult<()> {
if !self.map.contains_jt(jt) { if !self.map.contains_jt(jt) {
err!(loc, "undefined jump table {}", jt) err!(loc, "undefined jump table {}", jt)
} else { } else {
@@ -251,8 +246,8 @@ impl<'a> Context<'a> {
} }
// Assign the global for the stack limit. // Assign the global for the stack limit.
fn set_stack_limit(&mut self, gv: GlobalValue, loc: &Location) -> ParseResult<()> { fn set_stack_limit(&mut self, gv: GlobalValue, loc: Location) -> ParseResult<()> {
if let Some(_) = self.function.set_stack_limit(Some(gv)) { if self.function.set_stack_limit(Some(gv)).is_some() {
err!(loc, "multiple stack_limit declarations") err!(loc, "multiple stack_limit declarations")
} else { } else {
Ok(()) Ok(())
@@ -260,7 +255,7 @@ impl<'a> Context<'a> {
} }
// Allocate a new EBB. // Allocate a new EBB.
fn add_ebb(&mut self, ebb: Ebb, loc: &Location) -> ParseResult<Ebb> { fn add_ebb(&mut self, ebb: Ebb, loc: Location) -> ParseResult<Ebb> {
while self.function.dfg.num_ebbs() <= ebb.index() { while self.function.dfg.num_ebbs() <= ebb.index() {
self.function.dfg.make_ebb(); self.function.dfg.make_ebb();
} }
@@ -703,7 +698,7 @@ impl<'a> Parser<'a> {
isaspec::parse_options( isaspec::parse_options(
self.consume_line().trim().split_whitespace(), self.consume_line().trim().split_whitespace(),
&mut flag_builder, &mut flag_builder,
&self.loc, self.loc,
)?; )?;
} }
"target" => { "target" => {
@@ -732,7 +727,7 @@ impl<'a> Parser<'a> {
last_set_loc = None; last_set_loc = None;
seen_target = true; seen_target = true;
// Apply the target-specific settings to `isa_builder`. // Apply the target-specific settings to `isa_builder`.
isaspec::parse_options(words, &mut isa_builder, &self.loc)?; isaspec::parse_options(words, &mut isa_builder, self.loc)?;
// Construct a trait object with the aggregate settings. // Construct a trait object with the aggregate settings.
targets.push(isa_builder.finish(settings::Flags::new(flag_builder.clone()))); targets.push(isa_builder.finish(settings::Flags::new(flag_builder.clone())));
@@ -1004,35 +999,35 @@ impl<'a> Parser<'a> {
self.start_gathering_comments(); self.start_gathering_comments();
let loc = self.loc; let loc = self.loc;
self.parse_stack_slot_decl() self.parse_stack_slot_decl()
.and_then(|(ss, dat)| ctx.add_ss(ss, dat, &loc)) .and_then(|(ss, dat)| ctx.add_ss(ss, dat, loc))
} }
Some(Token::GlobalValue(..)) => { Some(Token::GlobalValue(..)) => {
self.start_gathering_comments(); self.start_gathering_comments();
self.parse_global_value_decl() self.parse_global_value_decl()
.and_then(|(gv, dat)| ctx.add_gv(gv, dat, &self.loc)) .and_then(|(gv, dat)| ctx.add_gv(gv, dat, self.loc))
} }
Some(Token::Heap(..)) => { Some(Token::Heap(..)) => {
self.start_gathering_comments(); self.start_gathering_comments();
self.parse_heap_decl() self.parse_heap_decl()
.and_then(|(heap, dat)| ctx.add_heap(heap, dat, &self.loc)) .and_then(|(heap, dat)| ctx.add_heap(heap, dat, self.loc))
} }
Some(Token::SigRef(..)) => { Some(Token::SigRef(..)) => {
self.start_gathering_comments(); self.start_gathering_comments();
self.parse_signature_decl(ctx.unique_isa) self.parse_signature_decl(ctx.unique_isa)
.and_then(|(sig, dat)| ctx.add_sig(sig, dat, &self.loc)) .and_then(|(sig, dat)| ctx.add_sig(sig, dat, self.loc))
} }
Some(Token::FuncRef(..)) => { Some(Token::FuncRef(..)) => {
self.start_gathering_comments(); self.start_gathering_comments();
self.parse_function_decl(ctx) self.parse_function_decl(ctx)
.and_then(|(fn_, dat)| ctx.add_fn(fn_, dat, &self.loc)) .and_then(|(fn_, dat)| ctx.add_fn(fn_, dat, self.loc))
} }
Some(Token::JumpTable(..)) => { Some(Token::JumpTable(..)) => {
self.start_gathering_comments(); self.start_gathering_comments();
self.parse_jump_table_decl() self.parse_jump_table_decl()
.and_then(|(jt, dat)| ctx.add_jt(jt, dat, &self.loc)) .and_then(|(jt, dat)| ctx.add_jt(jt, dat, self.loc))
} }
Some(Token::Identifier("stack_limit")) => self.parse_stack_limit_decl() Some(Token::Identifier("stack_limit")) => self.parse_stack_limit_decl()
.and_then(|gv| ctx.set_stack_limit(gv, &self.loc)), .and_then(|gv| ctx.set_stack_limit(gv, self.loc)),
// More to come.. // More to come..
_ => return Ok(()), _ => return Ok(()),
}?; }?;
@@ -1236,7 +1231,7 @@ impl<'a> Parser<'a> {
let sig = self.parse_signature(ctx.unique_isa)?; let sig = self.parse_signature(ctx.unique_isa)?;
let sigref = ctx.function.import_signature(sig); let sigref = ctx.function.import_signature(sig);
ctx.map ctx.map
.def_entity(sigref.into(), &loc) .def_entity(sigref.into(), loc)
.expect("duplicate SigRef entities created"); .expect("duplicate SigRef entities created");
ExtFuncData { ExtFuncData {
name, name,
@@ -1369,7 +1364,7 @@ impl<'a> Parser<'a> {
self.start_gathering_comments(); self.start_gathering_comments();
let ebb_num = self.match_ebb("expected EBB header")?; let ebb_num = self.match_ebb("expected EBB header")?;
let ebb = ctx.add_ebb(ebb_num, &self.loc)?; let ebb = ctx.add_ebb(ebb_num, self.loc)?;
if !self.optional(Token::Colon) { if !self.optional(Token::Colon) {
// ebb-header ::= Ebb(ebb) [ * ebb-params ] ":" // ebb-header ::= Ebb(ebb) [ * ebb-params ] ":"
@@ -1466,7 +1461,7 @@ impl<'a> Parser<'a> {
let t = self.match_type("expected EBB argument type")?; let t = self.match_type("expected EBB argument type")?;
// Allocate the EBB argument. // Allocate the EBB argument.
ctx.function.dfg.append_ebb_param_for_parser(ebb, t, v); ctx.function.dfg.append_ebb_param_for_parser(ebb, t, v);
ctx.map.def_value(v, &v_location)?; ctx.map.def_value(v, v_location)?;
// ebb-param ::= Value(v) ":" Type(t) * arg-loc? // ebb-param ::= Value(v) ":" Type(t) * arg-loc?
if self.optional(Token::LBracket) { if self.optional(Token::LBracket) {
@@ -1492,7 +1487,7 @@ impl<'a> Parser<'a> {
} }
Some(ss) => ss, Some(ss) => ss,
}; };
ctx.check_ss(ss, &self.loc)?; ctx.check_ss(ss, self.loc)?;
Ok(ValueLoc::Stack(ss)) Ok(ValueLoc::Stack(ss))
} }
Some(Token::Name(name)) => { Some(Token::Name(name)) => {
@@ -1610,7 +1605,7 @@ impl<'a> Parser<'a> {
return err!(self.loc, "value {} is already defined"); return err!(self.loc, "value {} is already defined");
} }
} else { } else {
ctx.map.def_value(result, &self.loc)?; ctx.map.def_value(result, self.loc)?;
} }
if !ctx.map.contains_value(dest) { if !ctx.map.contains_value(dest) {
@@ -1638,7 +1633,7 @@ impl<'a> Parser<'a> {
) -> ParseResult<()> { ) -> ParseResult<()> {
// Define the result values. // Define the result values.
for val in results { for val in results {
ctx.map.def_value(*val, &self.loc)?; ctx.map.def_value(*val, self.loc)?;
} }
// Collect comments for the next instruction. // Collect comments for the next instruction.
@@ -1680,7 +1675,7 @@ impl<'a> Parser<'a> {
.make_inst_results_for_parser(inst, ctrl_typevar, results); .make_inst_results_for_parser(inst, ctrl_typevar, results);
ctx.function.layout.append_inst(inst, ebb); ctx.function.layout.append_inst(inst, ebb);
ctx.map ctx.map
.def_entity(inst.into(), &opcode_loc) .def_entity(inst.into(), opcode_loc)
.expect("duplicate inst references created"); .expect("duplicate inst references created");
if !srcloc.is_default() { if !srcloc.is_default() {
@@ -1897,7 +1892,7 @@ impl<'a> Parser<'a> {
}, },
InstructionFormat::UnaryGlobalValue => { InstructionFormat::UnaryGlobalValue => {
let gv = self.match_gv("expected global value")?; let gv = self.match_gv("expected global value")?;
ctx.check_gv(gv, &self.loc)?; ctx.check_gv(gv, self.loc)?;
InstructionData::UnaryGlobalValue { InstructionData::UnaryGlobalValue {
opcode, opcode,
global_value: gv, global_value: gv,
@@ -2009,7 +2004,7 @@ impl<'a> Parser<'a> {
let arg = self.match_value("expected SSA value operand")?; let arg = self.match_value("expected SSA value operand")?;
self.match_token(Token::Comma, "expected ',' between operands")?; self.match_token(Token::Comma, "expected ',' between operands")?;
let table = self.match_jt()?; let table = self.match_jt()?;
ctx.check_jt(table, &self.loc)?; ctx.check_jt(table, self.loc)?;
InstructionData::BranchTable { opcode, arg, table } InstructionData::BranchTable { opcode, arg, table }
} }
InstructionFormat::InsertLane => { InstructionFormat::InsertLane => {
@@ -2089,7 +2084,7 @@ impl<'a> Parser<'a> {
} }
InstructionFormat::Call => { InstructionFormat::Call => {
let func_ref = self.match_fn("expected function reference")?; let func_ref = self.match_fn("expected function reference")?;
ctx.check_fn(func_ref, &self.loc)?; ctx.check_fn(func_ref, self.loc)?;
self.match_token(Token::LPar, "expected '(' before arguments")?; self.match_token(Token::LPar, "expected '(' before arguments")?;
let args = self.parse_value_list()?; let args = self.parse_value_list()?;
self.match_token(Token::RPar, "expected ')' after arguments")?; self.match_token(Token::RPar, "expected ')' after arguments")?;
@@ -2115,12 +2110,12 @@ impl<'a> Parser<'a> {
} }
InstructionFormat::FuncAddr => { InstructionFormat::FuncAddr => {
let func_ref = self.match_fn("expected function reference")?; let func_ref = self.match_fn("expected function reference")?;
ctx.check_fn(func_ref, &self.loc)?; ctx.check_fn(func_ref, self.loc)?;
InstructionData::FuncAddr { opcode, func_ref } InstructionData::FuncAddr { opcode, func_ref }
} }
InstructionFormat::StackLoad => { InstructionFormat::StackLoad => {
let ss = self.match_ss("expected stack slot number: ss«n»")?; let ss = self.match_ss("expected stack slot number: ss«n»")?;
ctx.check_ss(ss, &self.loc)?; ctx.check_ss(ss, self.loc)?;
let offset = self.optional_offset32()?; let offset = self.optional_offset32()?;
InstructionData::StackLoad { InstructionData::StackLoad {
opcode, opcode,
@@ -2132,7 +2127,7 @@ impl<'a> Parser<'a> {
let arg = self.match_value("expected SSA value operand")?; let arg = self.match_value("expected SSA value operand")?;
self.match_token(Token::Comma, "expected ',' between operands")?; self.match_token(Token::Comma, "expected ',' between operands")?;
let ss = self.match_ss("expected stack slot number: ss«n»")?; let ss = self.match_ss("expected stack slot number: ss«n»")?;
ctx.check_ss(ss, &self.loc)?; ctx.check_ss(ss, self.loc)?;
let offset = self.optional_offset32()?; let offset = self.optional_offset32()?;
InstructionData::StackStore { InstructionData::StackStore {
opcode, opcode,
@@ -2143,7 +2138,7 @@ impl<'a> Parser<'a> {
} }
InstructionFormat::HeapAddr => { InstructionFormat::HeapAddr => {
let heap = self.match_heap("expected heap identifier")?; let heap = self.match_heap("expected heap identifier")?;
ctx.check_heap(heap, &self.loc)?; ctx.check_heap(heap, self.loc)?;
self.match_token(Token::Comma, "expected ',' between operands")?; self.match_token(Token::Comma, "expected ',' between operands")?;
let arg = self.match_value("expected SSA value heap address")?; let arg = self.match_value("expected SSA value heap address")?;
self.match_token(Token::Comma, "expected ',' between operands")?; self.match_token(Token::Comma, "expected ',' between operands")?;
@@ -2229,7 +2224,7 @@ impl<'a> Parser<'a> {
let src = self.match_regunit(ctx.unique_isa)?; let src = self.match_regunit(ctx.unique_isa)?;
self.match_token(Token::Arrow, "expected '->' before destination stack slot")?; self.match_token(Token::Arrow, "expected '->' before destination stack slot")?;
let dst = self.match_ss("expected stack slot number: ss«n»")?; let dst = self.match_ss("expected stack slot number: ss«n»")?;
ctx.check_ss(dst, &self.loc)?; ctx.check_ss(dst, self.loc)?;
InstructionData::RegSpill { InstructionData::RegSpill {
opcode, opcode,
arg, arg,
@@ -2241,7 +2236,7 @@ impl<'a> Parser<'a> {
let arg = self.match_value("expected SSA value operand")?; let arg = self.match_value("expected SSA value operand")?;
self.match_token(Token::Comma, "expected ',' between operands")?; self.match_token(Token::Comma, "expected ',' between operands")?;
let src = self.match_ss("expected stack slot number: ss«n»")?; let src = self.match_ss("expected stack slot number: ss«n»")?;
ctx.check_ss(src, &self.loc)?; ctx.check_ss(src, self.loc)?;
self.match_token( self.match_token(
Token::Arrow, Token::Arrow,
"expected '->' before destination register units", "expected '->' before destination register units",

View File

@@ -140,49 +140,49 @@ impl SourceMap {
} }
/// Define the value `entity`. /// Define the value `entity`.
pub fn def_value(&mut self, entity: Value, loc: &Location) -> ParseResult<()> { pub fn def_value(&mut self, entity: Value, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the ebb `entity`. /// Define the ebb `entity`.
pub fn def_ebb(&mut self, entity: Ebb, loc: &Location) -> ParseResult<()> { pub fn def_ebb(&mut self, entity: Ebb, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the stack slot `entity`. /// Define the stack slot `entity`.
pub fn def_ss(&mut self, entity: StackSlot, loc: &Location) -> ParseResult<()> { pub fn def_ss(&mut self, entity: StackSlot, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the global value `entity`. /// Define the global value `entity`.
pub fn def_gv(&mut self, entity: GlobalValue, loc: &Location) -> ParseResult<()> { pub fn def_gv(&mut self, entity: GlobalValue, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the heap `entity`. /// Define the heap `entity`.
pub fn def_heap(&mut self, entity: Heap, loc: &Location) -> ParseResult<()> { pub fn def_heap(&mut self, entity: Heap, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the signature `entity`. /// Define the signature `entity`.
pub fn def_sig(&mut self, entity: SigRef, loc: &Location) -> ParseResult<()> { pub fn def_sig(&mut self, entity: SigRef, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the external function `entity`. /// Define the external function `entity`.
pub fn def_fn(&mut self, entity: FuncRef, loc: &Location) -> ParseResult<()> { pub fn def_fn(&mut self, entity: FuncRef, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define the jump table `entity`. /// Define the jump table `entity`.
pub fn def_jt(&mut self, entity: JumpTable, loc: &Location) -> ParseResult<()> { pub fn def_jt(&mut self, entity: JumpTable, loc: Location) -> ParseResult<()> {
self.def_entity(entity.into(), loc) self.def_entity(entity.into(), loc)
} }
/// Define an entity. This can be used for instructions whose numbers never /// Define an entity. This can be used for instructions whose numbers never
/// appear in source, or implicitly defined signatures. /// appear in source, or implicitly defined signatures.
pub fn def_entity(&mut self, entity: AnyEntity, loc: &Location) -> ParseResult<()> { pub fn def_entity(&mut self, entity: AnyEntity, loc: Location) -> ParseResult<()> {
if self.locations.insert(entity, *loc).is_some() { if self.locations.insert(entity, loc).is_some() {
err!(loc, "duplicate entity: {}", entity) err!(loc, "duplicate entity: {}", entity)
} else { } else {
Ok(()) Ok(())