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

regression 1.49: problem with autoderef and trait method #80816

Closed
kodieg opened this issue Jan 8, 2021 · 4 comments · Fixed by #105944
Closed

regression 1.49: problem with autoderef and trait method #80816

kodieg opened this issue Jan 8, 2021 · 4 comments · Fixed by #105944
Assignees
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Milestone

Comments

@kodieg
Copy link

kodieg commented Jan 8, 2021

A code attached below used to compile with rustc 1.48 (stable) and stopped to work with 1.49 (stable). Two thing help to make the code compile:

  1. comment out use arc_swap::access::Access;
  2. explicitly deref (*s).load().

To compile code below one need to add arc-swap = "1.2" to Cargo.toml dependencies. Maybe this is due to some conflict between ArcSwap instance method and Access load method?

Code

I tried this code:

use arc_swap;
use std::sync::Arc;
use arc_swap::access::Access;

pub fn foo() {
    let s: Arc<arc_swap::ArcSwap<usize>> = Arc::new(arc_swap::ArcSwap::from_pointee(32))
    let guard: arc_swap::Guard<Arc<usize>> = s.load();
}

I expected to see this happen: It should compile properly (it worked with rustc version 1.48 and earlier versions as well).

Instead, this happened: I got compilation error

error[E0283]: type annotations needed
 --> src/lib.rs:9:50
  |
9 |     let guard: arc_swap::Guard<Arc<usize>> =   s.load();
  |                                                  ^^^^ cannot infer type for type parameter `T`
  |
  = note: cannot satisfy `ArcSwapAny<Arc<usize>>: arc_swap::access::Access<_>`
  = note: required because of the requirements on the impl of `arc_swap::access::Access<_>` for `Arc<ArcSwapAny<Arc<usize>>>`

Version it worked on

It most recently worked on: Rust 1.48

Version with regression

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0
@jonas-schievink jonas-schievink added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jan 8, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 8, 2021
@jyn514 jyn514 added A-inference Area: Type inference T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2021
@Mark-Simulacrum Mark-Simulacrum added this to the 1.49.0 milestone Jan 8, 2021
@SNCPlay42
Copy link
Contributor

searched nightlies: from nightly-2020-10-01 to nightly-2020-11-14
regressed nightly: nightly-2020-10-07
searched commits: from a1dfd24 to 98edd1f
regressed commit: 08e2d46 (#73905)

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve --start=2020-10-01 --end=2020-11-14 -- check 

@JohnTitor JohnTitor added C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jan 12, 2021
@apiraino apiraino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 13, 2021
@apiraino
Copy link
Contributor

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Mar 27, 2021

Reduced:

use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::Arc;

pub struct Guard<T> {
    _phantom: PhantomData<T>,
}
impl<T> Deref for Guard<T> {
    type Target = T;
    fn deref(&self) -> &T {
        unimplemented!()
    }
}

pub struct DirectDeref<T>(T);
impl<T> Deref for DirectDeref<Arc<T>> {
    type Target = T;
    fn deref(&self) -> &T {
        unimplemented!()
    }
}

pub trait Access<T> {
    type Guard: Deref<Target = T>;
    fn load(&self) -> Self::Guard {
        unimplemented!()
    }
}
impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
    type Guard = A::Guard;
}
impl<T> Access<T> for ArcSwapAny<T> {
    type Guard = Guard<T>;
}
impl<T> Access<T> for ArcSwapAny<Arc<T>> {
    type Guard = DirectDeref<Arc<T>>;
}

pub struct ArcSwapAny<T> {
    _phantom_arc: PhantomData<T>,
}

pub fn foo() {
    let s: Arc<ArcSwapAny<Arc<usize>>> = unimplemented!();
    let guard: Guard<Arc<usize>> = s.load();
}

@estebank estebank removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Sep 23, 2021
@jackh726 jackh726 added the WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 label Feb 3, 2022
@oli-obk oli-obk self-assigned this Jul 15, 2022
@oli-obk oli-obk added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 labels Jul 15, 2022
@pnkfelix
Copy link
Member

The examples now print actionable feedback for the user, in the form of errors complaining about multiple applicable impl's.

For example, the code from the description now prints:

error[[E0283]](https://doc.rust-lang.org/nightly/error-index.html#E0283): type annotations needed
 --> src/lib.rs:7:48
  |
7 |     let guard: arc_swap::Guard<Arc<usize>> = s.load();
  |                                                ^^^^
  |
  = note: multiple `impl`s satisfying `ArcSwapAny<Arc<usize>>: arc_swap::access::Access<_>` found in the `arc_swap` crate:
          - impl<T, S> arc_swap::access::Access<T> for ArcSwapAny<Arc<T>, S>
            where S: Strategy<Arc<T>>;
          - impl<T, S> arc_swap::access::Access<T> for ArcSwapAny<T, S>
            where T: RefCnt, S: Strategy<T>;
  = note: required for `Arc<ArcSwapAny<Arc<usize>>>` to implement `arc_swap::access::Access<_>`
help: try using a fully qualified path to specify the expected types
  |
7 |     let guard: arc_swap::Guard<Arc<usize>> = <Arc<ArcSwapAny<Arc<usize>>> as arc_swap::access::Access<T>>::load(&s);
  |                                              ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ~

For more information about this error, try `rustc --explain E0283`.

So I think this might just need a regression test.

@rustbot label: E-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 16, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Dec 20, 2022
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 20, 2022
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#105835 (Refactor post borrowck cleanup passes)
 - rust-lang#105930 (Disable `NormalizeArrayLen`)
 - rust-lang#105938 (Update coerce_unsized tracking issue from rust-lang#27732 to rust-lang#18598)
 - rust-lang#105939 (Improve description of struct-fields GUI test)
 - rust-lang#105943 (Add regression test for rust-lang#102206)
 - rust-lang#105944 (Add regression test for rust-lang#80816)
 - rust-lang#105945 (Add regression test for rust-lang#57404)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in b149315 Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.