Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0170: pattern binding `GET` is named the same as one of the variants of the type `Method`

What it meansA pattern binding is using the same name as one of the variants of a type.

What rustc prints

error[E0170]: pattern binding `GET` is named the same as one of the variants of the type `Method`
 --> main.rs:8:9
  |
8 |         GET => true,
  |         ^^^ help: to match on the variant, qualify the path: `Method::GET`
  |
  = note: `#[deny(bindings_with_variant_name)]` on by default

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

E0170Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

A pattern binding is using the same name as one of the variants of a type.

Erroneous code example:

enum Method {
    GET,
    POST,
}

fn is_empty(s: Method) -> bool {
    match s {
        GET => true,
        _ => false
    }
}

fn main() {}

Enum variants are qualified by default. For example, given this type:

enum Method {
    GET,
    POST,
}

You would match it using:

enum Method {
    GET,
    POST,
}

let m = Method::GET;

match m {
    Method::GET => {},
    Method::POST => {},
}

If you don't qualify the names, the code will bind new variables named "GET" and "POST" instead. This behavior is likely not what you want, so rustc warns when that happens.

Qualified names are good practice, and most code works well with them. But if you prefer them unqualified, you can import the variants into scope:

use Method::*;
enum Method { GET, POST }

If you want others to be able to import variants from your module directly, use pub use:

pub use Method::*;
pub enum Method { GET, POST }

From rustc --explain E0170 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ