Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant use statement? #4186

Closed
Grimmscorpp opened this issue Dec 31, 2024 · 5 comments
Closed

Redundant use statement? #4186

Grimmscorpp opened this issue Dec 31, 2024 · 5 comments

Comments

@Grimmscorpp
Copy link
Contributor

Grimmscorpp commented Dec 31, 2024

Hello, fellow Rustaceans!

I'm new to Rust and reading this nice book on it. I'm currently on chapter 14. In Listing 14-07, it asks me to add a use line to be able to refer to the add_one crate.

use add_one;

fn main() {
    let num = 10;
    println!("Hello, world! {num} plus one is {}!", add_one::add_one(num));
}

However, even if I omit the use statement at the top, the program still compiles (and I tried it based on my current understanding of how the use statement should work).

// use add_one;
// --snip--

Any thoughts? Thanks!

@chriskrycho
Copy link
Contributor

You’re correct; it is extraneous! A long time ago, before the Rust 2018 Edition, it was not, so it likely got missed in cleaning up things from that transition! If you’d like to open a pole request to fix it, that would be very welcome! If not, I will try to get to it sometime this week.

@Grimmscorpp
Copy link
Contributor Author

@chriskrycho thanks for the clarification! I’ll open a PR this week.

@Grimmscorpp
Copy link
Contributor Author

@chriskrycho the PR is up for review 🤞

chriskrycho added a commit that referenced this issue Jan 8, 2025
In Listing 14-7 of Chapter 14, the `use add_one;` statement is redundant
and can be removed. Before the Rust 2018 edition, this statement was
required to bring the `add_one` crate into scope, so it likely got
missed during refactorings from that transition.

By removing this line, the code becomes more concise and reflects the
current best practices for using external crates in Rust.

Issue #4186

---------

Co-authored-by: Chris Krycho <[email protected]>
@Grimmscorpp
Copy link
Contributor Author

Closing the issue as the associated PR was merged. Thanks!

@chriskrycho
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants