Cannot compile with cargo

I have recently changed my device to a Dell G15 with ubuntu installed and NVIDIA GPU 4060. To use Bevy I needed to install vulkan, OpenGL, and other libraries. Also one of my complex bevy applications needed to be compiled to wasm, and there was a problem because only Cargo.lock wanted to compile at some point(there were some serde errors, but I have no problems with that because this app used serde, so I thought that may be some inconsistencies because the app was not used and not updated for a time). But now I created a new project with Axum, and have the same errors when compiling:

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:367:64
    |
367 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), M::Error>
    |            ---------------                                     ^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:411:14
    |
407 |         fn serialize_field<T: ?Sized>(
    |            --------------- implicitly returns `()` as its body has no tail or `return` expression
...
411 |         ) -> Result<(), M::Error>
    |              ^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
    |
    = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:785:66
    |
785 |         fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
    |            -----------------                                     ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:811:66
    |
811 |         fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
    |            -----------------                                     ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:838:64
    |
838 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
    |            ---------------                                     ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:867:64
    |
867 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
    |            ---------------                                     ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:899:60
    |
899 |         fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), E>
    |            -------------                                   ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:908:64
    |
908 |         fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
    |            ---------------                                     ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:925:84
    |
925 |         fn serialize_entry<K: ?Sized, V: ?Sized>(&mut self, key: &K, value: &V) -> Result<(), E>
    |            ---------------                                                         ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:950:83
    |
950 |         fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
    |            ---------------                                                        ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
   --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:979:83
    |
979 |         fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
    |            ---------------                                                        ^^^^^^^^^^^^^ expected `Result<(), E>`, found `()`
    |            |
    |            implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<(), E>`
            found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1087:32
     |
1087 |     fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
     |        --------------          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1098:32
     |
1098 |     fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
     |        --------------          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1231:21
     |
1231 |     fn end(self) -> Result<(), Self::Error> {
     |        ---          ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1258:21
     |
1258 |     fn end(self) -> Result<(), Self::Error> {
     |        ---          ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1292:60
     |
1292 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
     |        ---------------                                     ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1301:21
     |
1301 |     fn end(self) -> Result<(), Self::Error> {
     |        ---          ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1342:10
     |
1338 |     fn serialize_field<T: ?Sized>(
     |        --------------- implicitly returns `()` as its body has no tail or `return` expression
...
1342 |     ) -> Result<(), Self::Error>
     |          ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

error[E0308]: mismatched types
    --> /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs:1351:21
     |
1351 |     fn end(self) -> Result<(), Self::Error> {
     |        ---          ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), <M as SerializeMap>::Error>`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `Result<(), <M as ser::SerializeMap>::Error>`
             found unit type `()`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `serde` (lib) due to 19 previous errors

Also rust-analyzer(vs code extension) returns this:

2024-03-11T21:22:42.134659Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs

2024-03-11T21:22:42.134676Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /home/wiktor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.197/src/private/ser.rs

It seems like something is broken with cargo or rustc.

If two unrelated projects are affected, then the source files in /home/wiktor/.cargo/registry may have been corrupted (e.g. by accidentally editing them). You can delete the entire registry directory and Cargo will automatically re-download everything needed.

1 Like

Exactly, I just found it. For some reason, I needed to comment Ok(()) in my project which was used "anyhow" library probably, but it seems somehow it replaced it globally which is extremely weird because I wanted to comment that only in the project src directory.