Trying Rust2018, getting many warnings on `try` is a keyword


#1

Hi there,

I’m trying out Rust 2018 on my small project and on all the #[derive(Serialize, Deserialize)] from serde, I’m getting this warning: warning:tryis a keyword in the 2018 edition

How do we solves these?

Thanks!


#2

Ok forget my question. These were reported by cargo fix. Once edition properly activated, I got errors because the macro was not imported with a use, all solved now!


#3

You shouldn’t be getting these warnings from dependencies (this case in particular might be bug in rustc or cargo fix), but if you wish to use try, in the 2018 edition you can use r#try. That being said, on your code you really want to use the ? operator instead.


#4

I’m not using try at all, these traits come from serde I believe


#5

This originates from: https://github.com/serde-rs/serde/blob/master/serde_derive/src/try.rs


#6

Should this be reported to serde?


#7

cc @dtolnay


#8

I tried using serde_derive from a 2018 crate and was not able to reproduce this warning as of rustc 1.30.0-nightly (2f1547c0a 2018-09-11). How do I trigger the warning?


#9

Let me check my Cargo.toml when I get home. And I was getting these when doing cargo fix only


#10

serde related cargo config:

serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"

cargo lock:

[[package]]
name = "serde"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "serde_derive"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "proc-macro2 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)",
 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "syn 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde_json"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "serde 1.0.77 (registry+https://github.com/rust-lang/crates.io-index)",
]

#11

Could you also post rustc --version and what feature flags you had turned on with !#[feature]?


#12

What are the steps to take that trigger this warning? What do I write in main.rs and what commands do I run?


#13

The warning was triggered only by using cargo fix and having #![feature(rust_2018_preview, uniform_paths)] in main.rs

The rustc version was nightly from the 8th in the evening (UK time)


#14

in main.rs: #![feature(rust_2018_preview, uniform_paths)]

command line:

cargo +nightly fix --edition

#15

@dtolnay to get rid of the warnings for all users on 2015, it might make sense to rename the try! macro to check! or something else internally.


#16

Would this imply all crates keeping 2015 compatibility need to do these kinds of fixes to silence 2018 lints? If so, that feels like a poor user experience and is something the edition was supposed to hide. Should perhaps the link be updated?


#17

Serde issue: serde-rs/serde/1385.

I am not planning to rename anything in Serde right now. I believe our use of try is within the space of what needs to be supported by edition hygiene and cargo fix.