Rust-clippy: borrowed_box gives syntactically invalid suggestion

Created on 4 Sep 2018  路  8Comments  路  Source: rust-lang/rust-clippy

It suggests &mut Trait + 'a, which is invalid syntax. It should be &mut (Trait + 'a) instead.

L-bug L-suggestion-causes-error

Most helpful comment

Actually, borrowed_box in the context of a trait object might usually be an incorrect lint... (not confident enough to say always).

All 8 comments

Thank you for the report!
Could you provide a small code snippet that produces the lint with the incorrect suggestion? You can use play.rust-lang.org which has Clippy available under 'Tools' on the right.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=07873a52c9615f8f6b6ba782fdf3e9fe

It isn't really an incorrect suggestion (though it may be a bad one - I dont know) so much that if you do it verbatim it cannot possibly compile due to rustc parsing limitations. Though it can also require changing the callsite which may or may not be unwanted for this lint.

Actually, borrowed_box in the context of a trait object might usually be an incorrect lint... (not confident enough to say always).

@logannc it builds and applying clippy suggestion causes compiler error similar to OP's. Therefore that's good example, thanks!

I just stumbled upon the same issue, here's one more link to the playground :)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1f119c4d2e02176783b3106b0ca743b7

Weird but it seems that the lint doesn't trigger anymore, can anyone confirm? Same for #3971 no?

I believe it's because of the lint now ignores every mutable references (#5491), and both of the two playground link uses mutable references. However, this issue is actually unrelated to mutability. It happens when the trait objects have auto traits or lifetime bounds.

playground link that uses an immutable reference

@rust-lang/clippy. I think you'd better reopen this issue.

Was this page helpful?
0 / 5 - 0 ratings