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

rustc makes claims about Cargo.toml when there is none in async context #94646

Closed
matthiaskrgr opened this issue Mar 5, 2022 · 4 comments · Fixed by #94708
Closed

rustc makes claims about Cargo.toml when there is none in async context #94646

matthiaskrgr opened this issue Mar 5, 2022 · 4 comments · Fixed by #94708
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:

#![feature(type_alias_impl_trait)]
#![no_std]

pub trait Tr<'x> {
    type Fut: core::future::Future<Output = ()>;

    fn f() -> Self::Fut;
}

impl<'x> Tr<'x> for () {
    type Fut = impl core::future::Future<Output = ()>;

    fn f() -> Self::Fut {
        async {
            //if false {
            return ();
            //}
            let res: Undef = ();
            res
        }
    }
}

When I check this file with rustc async.rs --crate-type lib, rust errors

  --> async.rs:16:13
   |
14 |         async {
   |         ----- `async` blocks are only allowed in Rust 2018 or later
15 |             //if false {
16 |             return ();
   |             ^^^^^^ expected identifier, found keyword
   |
   = help: set `edition = "2021"` in `Cargo.toml`
   = note: for more on editions, read https://doc.rust-lang.org/edition-guide

Which is a bit confusing.
Does it want me to set edition = 2021 in Cargo.toml (as in "please set edition = 2021...")?
Why does it complain about a Cargo.toml when there isn't one (as I just checked the file directly with rustc x.rs).

For some other examples, the message is even more confusing

   = note: to `.await` a `Future`, switch to Rust 2018 or later
   = help: set `edition = "2021"` in `Cargo.toml`

because it is not clear if rustc want to say "2021 is set" or "2021 should be set"

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Mar 5, 2022
@ehuss
Copy link
Contributor

ehuss commented Mar 5, 2022

It is giving instructions on how to resolve the issue. It reads fine to me, though maybe a bit terse. Perhaps a few more words could make it clearer.

As for the hint being given when not using cargo, these suggestions should be gated like this to only be shown when using cargo.

@mati865
Copy link
Contributor

mati865 commented Mar 5, 2022

IMO rustc should tell the user to add --edition x command line argument when running without Cargo.

@ChayimFriedman2
Copy link
Contributor

Does rustc have a way to know it's being run by Cargo?

@ehuss
Copy link
Contributor

ehuss commented Mar 6, 2022

The link in the comment above shows how to do it.

@notriddle notriddle self-assigned this Mar 7, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 8, 2022
…ing, r=lcnr

diagnostics: only talk about `Cargo.toml` if running under Cargo

Fixes rust-lang#94646
@bors bors closed this as completed in fbd4cfa Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants