This is kind of a usability regression from v0.11. That version only exposed syn::parse_expr if full feature was enabled:
// syn = { version = "0.11.11", features = ["full"] }
let _ = syn::parse_expr("|| 5").unwrap(); // Expr { Closure { .. } }
which meant the user obviously knew to enable the feature if they wanted to be able to parse expressions.
Now that parse_* have been replaced by syn::parse_str, the user can write this code that only fails at runtime with a somewhat unclear message:
// syn = { git = "https://github.com/dtolnay/syn/", rev = "24f128215d93f197ae0d7750c5248eee7df0272e" }
let _: syn::Expr = syn::parse_str("|| 5").unwrap(); // ParseError(Some("failed to parse expression: failed to parse"))
... until the user reads the source of syn and realizes that the full feature is (still) necessary:
// syn = { git = "https://github.com/dtolnay/syn/", rev = "24f128215d93f197ae0d7750c5248eee7df0272e", features = ["full"] }
let _: syn::Expr = syn::parse_str("|| 5".unwrap(); // Expr { Closure { .. } }
The example for syn::parse_str even shows itself parsing an Expr successfully, which further confused me until I read the code. I guess it can't be a compiler error since it seems intentional that some expressions are allowed to be parsed even when full is disabled (and it's a trait method anyway). Is there a way to make the feature requirement more obvious, like in the doc comment of parse_str or the error message?
This is kind of a usability regression from v0.11. That version only exposed
syn::parse_expriffullfeature was enabled:which meant the user obviously knew to enable the feature if they wanted to be able to parse expressions.
Now that
parse_*have been replaced bysyn::parse_str, the user can write this code that only fails at runtime with a somewhat unclear message:... until the user reads the source of
synand realizes that thefullfeature is (still) necessary:The example for
syn::parse_streven shows itself parsing anExprsuccessfully, which further confused me until I read the code. I guess it can't be a compiler error since it seems intentional that some expressions are allowed to be parsed even whenfullis disabled (and it's a trait method anyway). Is there a way to make the feature requirement more obvious, like in the doc comment ofparse_stror the error message?