Duplicate compilation errors

Very often when I make some code modifications and run my tests again I get a few compilation errors. I noticed that some compilation errors appear twice, like this:

$ cargo test -p offst-funder
   Compiling offst-funder v0.1.0 (/home/real/projects/d/offst/components/funder)                                                                                                                                   
error[E0308]: mismatched types                                                                                                                                                                                     
   --> components/funder/src/handler/handle_friend.rs:220:13                                                                                                                                                       
    |                                                                                                                                                                                                              
220 |             self.state.local_public_key).unwrap();                                                                                                                                                           
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                      
    |             |                                                                                                                                                                                                
    |             expected reference, found struct `offst_crypto::identity::PublicKey`                                                                                                                             
    |             help: consider borrowing here: `&self.state.local_public_key`                                                                                                                                    
    |                                                                                                                                                                                                              
    = note: expected type `&offst_crypto::identity::PublicKey`                                                                                                                                                     
               found type `offst_crypto::identity::PublicKey`                                                                                                                                                      
                                                                                                                                                                                                                   
error[E0308]: mismatched types                                                                                                                                                                                     
   --> components/funder/src/handler/handle_friend.rs:220:13                                                                                                                                                       
    |                                                                                                                                                                                                              
220 |             self.state.local_public_key).unwrap();                                                                                                                                                           
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                      
    |             |                                                                                                                                                                                                
    |             expected reference, found struct `offst_crypto::identity::PublicKey`                                                                                                                             
    |             help: consider borrowing here: `&self.state.local_public_key`                                                                                                                                    
    |                                                                                                                                                                                                              
    = note: expected type `&offst_crypto::identity::PublicKey`                                                                                                                                                     
               found type `offst_crypto::identity::PublicKey`

After a year of coding I got used to this, but today I was rethinking this issue and I realized that maybe this is not something that one should get used to. I googled a bit, and found this closed issue: Duplicate message on compilation errors · Issue #3167 · rust-lang/cargo · GitHub . It says: "This is intended behavior though".

My guess is that the duplicate error messages happen because the compiler runs twice (or more?) in parallel, but having only one output for each error message doesn't sound like something that is impossible to do. I also don't remember having this kind of phenomenon with any other programming language I used in the past.

I didn't want to reopen the closed issue, but I was wondering if someone knows why having the duplicate error messages is the intended behaviour, and whether one can change the intended behaviour to something else.

1 Like