Skip to content

single_match fires on same code with 2 conflicting suggestions in macro #5359

@matthiaskrgr

Description

@matthiaskrgr

Perhaps macros should be ignored?

One suggestion contains make_value_visitor!(MutValueVisitor, mut); while the other one just contains make_value_visitor!(MutValueVisitor, ); (which probably does not even compile)

    Checking rustc_privacy v0.0.0 (/home/matthias/vcs/github/rust/src/librustc_privacy)
warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
   --> src/librustc_mir/interpret/visitor.rs:183:17
    |
104 |  / macro_rules! make_value_visitor {
105 |  |     ($visitor_trait_name:ident, $($mutability:ident)?) => {
106 |  |         // How to traverse a value and what to do when we are at the leaves.
107 |  |         pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
...    |
183 | /|                 match v.layout().ty.kind {
184 | ||                     // If it is a trait object, switch to the real type that was used to create it.
185 | ||                     ty::Dynamic(..) => {
186 | ||                         // immediate trait objects are not a thing
...   ||
196 | ||                     _ => {},
197 | ||                 };
    | ||_________________^ help: try this: `if let ty::Dynamic(..) = v.layout().ty.kind { make_value_visitor!(ValueVisitor,); }`
...    |
244 |  |     }
245 |  | }
    |  |_- in this expansion of `make_value_visitor!`
246 | 
247 |    make_value_visitor!(ValueVisitor,);
    |    ----------------------------------- in this macro invocation
    |
    = note: requested on the command line with `-W clippy::single-match`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match

warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
   --> src/librustc_mir/interpret/visitor.rs:183:17
    |
104 |  / macro_rules! make_value_visitor {
105 |  |     ($visitor_trait_name:ident, $($mutability:ident)?) => {
106 |  |         // How to traverse a value and what to do when we are at the leaves.
107 |  |         pub trait $visitor_trait_name<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
...    |
183 | /|                 match v.layout().ty.kind {
184 | ||                     // If it is a trait object, switch to the real type that was used to create it.
185 | ||                     ty::Dynamic(..) => {
186 | ||                         // immediate trait objects are not a thing
...   ||
196 | ||                     _ => {},
197 | ||                 };
    | ||_________________^ help: try this: `if let ty::Dynamic(..) = v.layout().ty.kind { make_value_visitor!(MutValueVisitor, mut); }`
...    |
244 |  |     }
245 |  | }
    |  |_- in this expansion of `make_value_visitor!`
...
248 |    make_value_visitor!(MutValueVisitor, mut);
    |    ------------------------------------------ in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions