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

async fn presence affects an unrelated error message #66312

Closed
tguser402 opened this issue Nov 11, 2019 · 10 comments · Fixed by #70376
Closed

async fn presence affects an unrelated error message #66312

tguser402 opened this issue Nov 11, 2019 · 10 comments · Fixed by #70376
Assignees
Labels
A-async-await A-traits AsyncAwait-Polish AsyncAwait-Triaged C-bug P-high T-compiler

Comments

@tguser402
Copy link

@tguser402 tguser402 commented Nov 11, 2019

The following code

trait Test<T> {
    fn is_some(self: T);
}

fn f() {
    let x = Some(2);
    if x.is_some() {
        println!("Some");
    }
}

produces an expected error:

error[E0307]: invalid `self` parameter type: T
 --> src/lib.rs:2:22
  |
2 |     fn is_some(self: T);
  |                      ^
  |
  = note: type of `self` must be `Self` or a type that dereferences to it
  = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

If I make f async,

trait Test<T> {
    fn is_some(self: T);
}

async fn f() {
    let x = Some(2);
    if x.is_some() {
        println!("Some");
    }
}

the original error is replaced with this:

error[E0308]: mismatched types
 --> src/lib.rs:7:8
  |
7 |     if x.is_some() {
  |        ^^^^^^^^^^^ expected bool, found ()
  |
  = note: expected type `bool`
             found type `()`

Meta

rustc --version --verbose:

rustc 1.39.0 (4560ea788 2019-11-04)
binary: rustc
commit-hash: 4560ea788cb760f0a34127156c78e2552949f734
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.39.0
LLVM version: 9.0
@jonas-schievink jonas-schievink added A-async-await A-traits C-bug T-compiler I-nominated labels Nov 11, 2019
@jonas-schievink
Copy link
Member

@jonas-schievink jonas-schievink commented Nov 11, 2019

Nominating because:

  • The trait impl does not exist, the compiler hallucinated it into existence
  • Inherent methods are supposed to take precedence over trait methods

This might indicate a quite serious bug in the compiler.

@Centril
Copy link
Contributor

@Centril Centril commented Nov 12, 2019

I would suggest stable- and beta-nominating the fix for this PR; it seems like this could warrant a point release. cc @rust-lang/release @rust-lang/lang

@Centril Centril added the P-high label Nov 12, 2019
@pietroalbini
Copy link
Member

@pietroalbini pietroalbini commented Nov 12, 2019

@rustbot modify labels: beta-nominated stable-nominated

@rustbot rustbot added beta-nominated stable-nominated labels Nov 12, 2019
@Centril
Copy link
Contributor

@Centril Centril commented Nov 12, 2019

Phew; looks like precedence works correctly in non-error code at least:

trait Test {
    fn is_some(&self) -> u8;
}

impl<T> Test for Option<T> {
    fn is_some(&self) -> u8 {
        self.is_some() as u8
    }
}

async fn f() {
    let x = Some(2);
    let _: () = x.is_some(); // type is bool.
}

Crisis averted? :)

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Nov 12, 2019

@rustbot assign @csmoe

@nikomatsakis nikomatsakis added AsyncAwait-Polish AsyncAwait-OnDeck AsyncAwait-Triaged and removed I-nominated labels Nov 12, 2019
@pnkfelix
Copy link
Member

@pnkfelix pnkfelix commented Nov 14, 2019

unnominating for back ports; we don't backport nominate issues, just Pull Requests.

@pnkfelix pnkfelix removed beta-nominated stable-nominated labels Nov 14, 2019
@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Dec 17, 2019

@rfcbot claim

I'll take a look, since @csmoe is finding this to be mighty tricky to track down

@tguser402
Copy link
Author

@tguser402 tguser402 commented Dec 24, 2019

I managed to get similar symptoms without async but with #![feature(arbitrary_self_types)]. But this time the trait compiles.

#![feature(arbitrary_self_types)]
trait Test<T: core::ops::Deref<Target = Self>> {
    fn is_some(self: T);
}

fn f() {
    let x = Some(2);
    if x.is_some() {
        println!("Some");
    }
}

Playground link

error[E0277]: the trait bound `std::option::Option<{integer}>: std::ops::Deref` is not satisfied
 --> src/lib.rs:8:10
  |
8 |     if x.is_some() {
  |          ^^^^^^^ the trait `std::ops::Deref` is not implemented for `std::option::Option<{integer}>`

error[E0308]: mismatched types
 --> src/lib.rs:8:8
  |
8 |     if x.is_some() {
  |        ^^^^^^^^^^^ expected `bool`, found `()`

error: aborting due to 2 previous errors

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Jan 8, 2020

I am 99% sure that the diagnosis I posted on #67651 also applies here.

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Feb 7, 2020

The async case is fixed by #68884, I think we should break out the arbitrary self types case into a distinct bug.

@tmandry tmandry added this to High priority in wg-async-foundations triage Feb 11, 2020
@tmandry tmandry added this to To do in wg-async work Feb 11, 2020
@tmandry tmandry moved this from To do to In progress in wg-async work Mar 3, 2020
@tmandry tmandry moved this from In progress to Done in wg-async work Mar 24, 2020
@tmandry tmandry moved this from Done to In progress in wg-async work Mar 24, 2020
@tmandry tmandry assigned tmandry and unassigned nikomatsakis Mar 24, 2020
Centril added a commit to Centril/rust that referenced this issue Mar 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2020
Rollup of 4 pull requests

Successful merges:

 - rust-lang#70361 (Update backtrace crate to 0.3.46)
 - rust-lang#70364 (resolve: Remove `rustc_attrs` as a standalone feature gate)
 - rust-lang#70373 (normalize some imports & prefer direct ones)
 - rust-lang#70376 (Add test for rust-lang#66312)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Mar 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#70331 (Increase verbosity when using update syntax with private fields)
 - rust-lang#70361 (Update backtrace crate to 0.3.46)
 - rust-lang#70364 (resolve: Remove `rustc_attrs` as a standalone feature gate)
 - rust-lang#70369 (Fix smaller issues with invalid placeholder type errors)
 - rust-lang#70373 (normalize some imports & prefer direct ones)
 - rust-lang#70376 (Add test for rust-lang#66312)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Mar 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#70331 (Increase verbosity when using update syntax with private fields)
 - rust-lang#70349 (move `hir_id_validation` to `rustc_passes` + simplify `hir::map` code)
 - rust-lang#70361 (Update backtrace crate to 0.3.46)
 - rust-lang#70364 (resolve: Remove `rustc_attrs` as a standalone feature gate)
 - rust-lang#70369 (Fix smaller issues with invalid placeholder type errors)
 - rust-lang#70373 (normalize some imports & prefer direct ones)
 - rust-lang#70376 (Add test for rust-lang#66312)

Failed merges:

r? @ghost
wg-async work automation moved this from In progress to Done Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await A-traits AsyncAwait-Polish AsyncAwait-Triaged C-bug P-high T-compiler
Projects
Development

Successfully merging a pull request may close this issue.

9 participants