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

Inference disrupted by trait bound that is redundant with a HRTB #41617

Open
dtolnay opened this issue Apr 29, 2017 · 4 comments
Open

Inference disrupted by trait bound that is redundant with a HRTB #41617

dtolnay opened this issue Apr 29, 2017 · 4 comments
Labels
A-inference Area: Type inference A-lifetimes Area: Lifetimes / regions A-traits Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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.

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 29, 2017

This compiles:

trait Trait<'a> {}

struct S<T>(T);

impl<'a, T> Trait<'a> for S<T> where T: for<'b> Trait<'b> {}

fn main() {}

This following does not. It seems like the impl already has T: for<'b> Trait<'b> so adding T: Trait<'a> should not affect the behavior.

trait Trait<'a> {}

struct S<T>(T);

// Added T: Trait<'a>
impl<'a, T> Trait<'a> for S<T> where T: for<'b> Trait<'b>, T: Trait<'a> {}

fn main() {}
error[E0283]: type annotations required: cannot resolve `T: Trait<'a>`
 --> src/main.rs:6:1
  |
6 | impl<'a, T> Trait<'a> for S<T> where T: for<'b> Trait<'b>, T: Trait<'a> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: required by `Trait`

This currently affects the following and many people have run into it. The workaround is to remove the bound (rust-lang/rust-clippy#1689).

#[derive(Deserialize)]
struct S<T: serde::de::DeserializeOwned>(T);
@aturon
Copy link
Member

aturon commented May 4, 2017

cc @nikomatsakis @eddyb @arielb1

@dtolnay
Copy link
Member Author

dtolnay commented May 4, 2017

This may be a consequence of #21974.

@jethrogb
Copy link
Contributor

add search keywords: higher ranked lifetime bound

@jethrogb
Copy link
Contributor

If this is unlikely to be fixed soon, can we at least make the error message better? It's unclear what type annotations could be added and where, and as @dtolnay writes, the fix is actually to be less restrictive.

@dtolnay dtolnay added the A-lifetimes Area: Lifetimes / regions label Jun 7, 2020
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 7, 2020
dlubarov added a commit to 0xPolygonZero/plonky that referenced this issue Sep 25, 2020
Since Field is already a subtrait of `Serialize` and `DeserializeOwned`, we don't need serde to add its own bounds `where F: Serialize`. The redundant bounds would normally be harmless, but they cause an error due to a compiler bug: rust-lang/rust#41617
dlubarov added a commit to 0xPolygonZero/plonky that referenced this issue Sep 25, 2020
Since `Field` is already a subtrait of `Serialize` and `DeserializeOwned`, we don't need serde to add its own bounds `where F: Serialize`. The redundant bounds would normally be harmless, but they cause an error due to a compiler bug: rust-lang/rust#41617
dlubarov added a commit to 0xPolygonZero/plonky that referenced this issue Sep 25, 2020
Since `Field` is already a subtrait of `Serialize` and `DeserializeOwned`, we don't need serde to add its own bounds like `where F: Serialize`. The redundant bounds would normally be harmless, but they cause an error due to a compiler bug: rust-lang/rust#41617
dlubarov added a commit to 0xPolygonZero/plonky that referenced this issue Sep 26, 2020
* Prevent Serde from adding redundant bounds on `F`

Since `Field` is already a subtrait of `Serialize` and `DeserializeOwned`, we don't need serde to add its own bounds like `where F: Serialize`. The redundant bounds would normally be harmless, but they cause an error due to a compiler bug: rust-lang/rust#41617

* Added FFT+MSM precomputations to the VK serialization + Move to serde_cbor.

* Remove unused import.

* Use struct destructuring

Co-authored-by: wborgeaud <williamborgeaud@gmail.com>
@fmease fmease added fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. A-traits Area: Trait system T-types Relevant to the types team, which will review and decide on the PR/issue. labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference A-lifetimes Area: Lifetimes / regions A-traits Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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

No branches or pull requests

6 participants