Why doesn't `use std:: self, … ;` compile?How do I see the expanded macro code that's causing my compile error?Why doesn't println! work in Rust unit tests?Why doesn't this compile - use of undeclared type name `thread::scoped`Cannot compile code that uses std::io - There is no `File` in `std::io`Why do try!() and ? not compile when used in a function that doesn't return Option or Result?Why does Drop take &mut self instead of self?What's the difference between self and Self?Why is the `std` module undeclared?Why doesn't `Box::into_raw` take `self` as parameter?Why doesn't the Godbolt compiler explorer show any output for my function when compiled in release mode?Why does a plain match expression compile, while a map_err call doesn't?
When do you stop "pushing" a book?
Row vectors and column vectors (Mathematica vs Matlab)
What does the "DS" in "DS-..." US visa application forms stand for?
how to find out if there's files in a folder and exit accordingly (in KSH)
Probability of taking balls without replacement from a bag question
Which spells are in some way related to shadows or the Shadowfell?
What is the Ancient One's mistake?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
Employee is self-centered and affects the team negatively
Do Rabbis admit emotional involvement in their rulings?
Ugin's Conjurant vs. un-preventable damage
Can a planet still function with a damaged moon?
if i accidentally leaked my schools ip address and someone d doses my school am i at fault
Has there been evidence of any other gods?
resoldering copper waste pipe
Are on’yomi words loanwords?
Are double contractions formal? Eg: "couldn't've" for "could not have"
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Can the president of the United States be guilty of insider trading?
Not taking the bishop with the knight, why?
Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech
Why do the Avengers care about returning these items in Endgame?
What is the status of the three crises in the history of mathematics?
Why do unstable nuclei form?
Why doesn't `use std:: self, … ;` compile?
How do I see the expanded macro code that's causing my compile error?Why doesn't println! work in Rust unit tests?Why doesn't this compile - use of undeclared type name `thread::scoped`Cannot compile code that uses std::io - There is no `File` in `std::io`Why do try!() and ? not compile when used in a function that doesn't return Option or Result?Why does Drop take &mut self instead of self?What's the difference between self and Self?Why is the `std` module undeclared?Why doesn't `Box::into_raw` take `self` as parameter?Why doesn't the Godbolt compiler explorer show any output for my function when compiled in release mode?Why does a plain match expression compile, while a map_err call doesn't?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have no idea why this code can't be compiled with Rust 1.27.0.
This is test.rs as it is on my hard drive:
use std::
self,
io::prelude::*,
net:: TcpListener, TcpStream ,
;
fn main()
Output when trying to compile it with rustc test.rs
:
error[E0254]: the name `std` is defined multiple times
--> test.rs:2:5
|
2 | self,
| ^^^^ `std` reimported here
|
= note: `std` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
2 | self as other_std,
| ^^^^^^^^^^^^^^^^^
warning: unused imports: `TcpListener`, `TcpStream`, `io::prelude::*`, `self`
--> test.rs:2:5
|
2 | self,
| ^^^^
3 | io::prelude::*,
| ^^^^^^^^^^^^^^
4 | net::TcpListener, TcpStream,
| ^^^^^^^^^^^ ^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
rust
add a comment |
I have no idea why this code can't be compiled with Rust 1.27.0.
This is test.rs as it is on my hard drive:
use std::
self,
io::prelude::*,
net:: TcpListener, TcpStream ,
;
fn main()
Output when trying to compile it with rustc test.rs
:
error[E0254]: the name `std` is defined multiple times
--> test.rs:2:5
|
2 | self,
| ^^^^ `std` reimported here
|
= note: `std` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
2 | self as other_std,
| ^^^^^^^^^^^^^^^^^
warning: unused imports: `TcpListener`, `TcpStream`, `io::prelude::*`, `self`
--> test.rs:2:5
|
2 | self,
| ^^^^
3 | io::prelude::*,
| ^^^^^^^^^^^^^^
4 | net::TcpListener, TcpStream,
| ^^^^^^^^^^^ ^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
rust
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57
add a comment |
I have no idea why this code can't be compiled with Rust 1.27.0.
This is test.rs as it is on my hard drive:
use std::
self,
io::prelude::*,
net:: TcpListener, TcpStream ,
;
fn main()
Output when trying to compile it with rustc test.rs
:
error[E0254]: the name `std` is defined multiple times
--> test.rs:2:5
|
2 | self,
| ^^^^ `std` reimported here
|
= note: `std` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
2 | self as other_std,
| ^^^^^^^^^^^^^^^^^
warning: unused imports: `TcpListener`, `TcpStream`, `io::prelude::*`, `self`
--> test.rs:2:5
|
2 | self,
| ^^^^
3 | io::prelude::*,
| ^^^^^^^^^^^^^^
4 | net::TcpListener, TcpStream,
| ^^^^^^^^^^^ ^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
rust
I have no idea why this code can't be compiled with Rust 1.27.0.
This is test.rs as it is on my hard drive:
use std::
self,
io::prelude::*,
net:: TcpListener, TcpStream ,
;
fn main()
Output when trying to compile it with rustc test.rs
:
error[E0254]: the name `std` is defined multiple times
--> test.rs:2:5
|
2 | self,
| ^^^^ `std` reimported here
|
= note: `std` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
2 | self as other_std,
| ^^^^^^^^^^^^^^^^^
warning: unused imports: `TcpListener`, `TcpStream`, `io::prelude::*`, `self`
--> test.rs:2:5
|
2 | self,
| ^^^^
3 | io::prelude::*,
| ^^^^^^^^^^^^^^
4 | net::TcpListener, TcpStream,
| ^^^^^^^^^^^ ^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
rust
rust
edited Mar 24 at 12:33
Shepmaster
165k16345494
165k16345494
asked Mar 23 at 9:04
AnonymousAnonymous
85
85
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57
add a comment |
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57
add a comment |
1 Answer
1
active
oldest
votes
This works fine in Rust 2018. You probably just want to update by adding edition = "2018"
to your Cargo.toml
or --edition=2018
to your rustc
invocation. Below is the answer for why this doesn't work in Rust 2015.
From the std::prelude
documentation:
On a technical level, Rust inserts
extern crate std;
into the crate root of every crate, and
use std::prelude::v1::*;
into every module.
You can also see that in action when looking at your code after macro expansion (e.g. via cargo-expand
). For your code this results in:
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
// No external crates imports or anything else.
use std::
self,
net::TcpListener, TcpStream,
;
fn main()
// Empty.
As you can see, std
is already in scope due to the extern crate std;
statement. Thus, importing it another time results in this error.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312186%2fwhy-doesnt-use-std-self-compile%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This works fine in Rust 2018. You probably just want to update by adding edition = "2018"
to your Cargo.toml
or --edition=2018
to your rustc
invocation. Below is the answer for why this doesn't work in Rust 2015.
From the std::prelude
documentation:
On a technical level, Rust inserts
extern crate std;
into the crate root of every crate, and
use std::prelude::v1::*;
into every module.
You can also see that in action when looking at your code after macro expansion (e.g. via cargo-expand
). For your code this results in:
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
// No external crates imports or anything else.
use std::
self,
net::TcpListener, TcpStream,
;
fn main()
// Empty.
As you can see, std
is already in scope due to the extern crate std;
statement. Thus, importing it another time results in this error.
add a comment |
This works fine in Rust 2018. You probably just want to update by adding edition = "2018"
to your Cargo.toml
or --edition=2018
to your rustc
invocation. Below is the answer for why this doesn't work in Rust 2015.
From the std::prelude
documentation:
On a technical level, Rust inserts
extern crate std;
into the crate root of every crate, and
use std::prelude::v1::*;
into every module.
You can also see that in action when looking at your code after macro expansion (e.g. via cargo-expand
). For your code this results in:
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
// No external crates imports or anything else.
use std::
self,
net::TcpListener, TcpStream,
;
fn main()
// Empty.
As you can see, std
is already in scope due to the extern crate std;
statement. Thus, importing it another time results in this error.
add a comment |
This works fine in Rust 2018. You probably just want to update by adding edition = "2018"
to your Cargo.toml
or --edition=2018
to your rustc
invocation. Below is the answer for why this doesn't work in Rust 2015.
From the std::prelude
documentation:
On a technical level, Rust inserts
extern crate std;
into the crate root of every crate, and
use std::prelude::v1::*;
into every module.
You can also see that in action when looking at your code after macro expansion (e.g. via cargo-expand
). For your code this results in:
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
// No external crates imports or anything else.
use std::
self,
net::TcpListener, TcpStream,
;
fn main()
// Empty.
As you can see, std
is already in scope due to the extern crate std;
statement. Thus, importing it another time results in this error.
This works fine in Rust 2018. You probably just want to update by adding edition = "2018"
to your Cargo.toml
or --edition=2018
to your rustc
invocation. Below is the answer for why this doesn't work in Rust 2015.
From the std::prelude
documentation:
On a technical level, Rust inserts
extern crate std;
into the crate root of every crate, and
use std::prelude::v1::*;
into every module.
You can also see that in action when looking at your code after macro expansion (e.g. via cargo-expand
). For your code this results in:
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
// No external crates imports or anything else.
use std::
self,
net::TcpListener, TcpStream,
;
fn main()
// Empty.
As you can see, std
is already in scope due to the extern crate std;
statement. Thus, importing it another time results in this error.
edited Mar 24 at 12:04
answered Mar 23 at 9:48
Lukas KalbertodtLukas Kalbertodt
27.9k361127
27.9k361127
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312186%2fwhy-doesnt-use-std-self-compile%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Wild guess: std::self references std itself, so you import std twice with a single use statement. Is there a specific reason why you want to import std::self?
– Frank Schmitt
Mar 23 at 9:41
This works fine in a Rust 2018 project, not in a 2015. Please upgrade.
– Shepmaster
Mar 24 at 11:57