PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, December 11, 2022

[FIXED] What is the Rust compiler saying here?

 December 11, 2022     lifetime-scoping, rust, syntax     No comments   

Issue

error[E0621]: explicit lifetime required in the type of `is`
  --> src/bee.rs:76:45
   |
75 | fn compute_instruction_set<'a>(is: &'a mut InstructionSet) {
   |                                    ---------------------- help: add explicit lifetime `'a` to the type of `is`: `&'a mut [OpCode<'a>; 255]`
76 |     let mut isb = InstructionSetBuilder{is: is, pos: 0};
   |                                             ^^ lifetime `'a` required

This is the code:

type InstructionSet<'a> = [OpCode<'a>; 0xff];
...
struct InstructionSetBuilder<'a> {
    is: &'a mut [OpCode<'a>],
    pos: usize,
}
...
fn compute_instruction_set<'a>(is: &'a mut InstructionSet) {
    let mut isb = InstructionSetBuilder{is: is, pos: 0};
...
}

Why do I need to set yet another 'a lifetime param?

Where?

I tried several combinations, all broke the syntax...


Solution

type InstructionSet<'a> = [OpCode<'a>; 0xff];

This type alias is generic over a lifetime 'a. So you must specify it. Try this instead.

fn compute_instruction_set<'a>(is: &'a mut InstructionSet<'a>) {
    let mut isb = InstructionSetBuilder{is: is, pos: 0};
...
}


Answered By - Aleksander Krauze
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing