Documentation problem: "expected enum `Option`, found enum `std::option::Option`"

So I've recently started learning the Rust language, I've been reading and writing the given figures as I go I'm currently at Chapter 6.2 of the documentation book (The match Control Flow Construct - The Rust Programming Language). For some reason, Listing 6-5 just will not compile on my setup

    fn plus_one(x: Option<i32>) -> Option<i32> {
        match x {
            None => None,
            Some(i) => Some(i + 1),

    let five = Some(5);
    let six = plus_one(five);
    let none = plus_one(None);

No matter what, it spits out 2 errors of the same type - one for None => None, and one for Some(i) => Some(i + 1), as follows:

error[E0308]: mismatched types
   --> src/
92  | fn plus_one(x: Option<i32>) -> Option<i32> {
    |                                ----------- expected `Option<i32>` because of return type
93  |     match x {
94  |         None => None,
    |                 ^^^^ expected enum `Option`, found enum `std::option::Option`

I feel like I'm losing my mind here, am I missing something? What is going wrong with this?

Seems like you have a lot more in than the 12 line snippet from the Book. Is there perchance some conflicting definition or import of Option?


Turns out you're right. I had

enum Option<T> {

from a previous listing, I forgot it was there and it must've been conflicting with that code. Thanks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.