Giter VIP home page Giter VIP logo

Comments (8)

lcnr avatar lcnr commented on July 26, 2024 1

has already been reverted on beta in #125629.

from rust.

konnorandrews avatar konnorandrews commented on July 26, 2024

I just discovered that swapping the bounds on the Raise::Higher causes it to work again on 1.79.0 and later.

(not working)

trait Raise{
    type Higher<'lt, 'ctx, B>: for<'a, 'b> Lower<'a, 'b, Bound<'a, 'b>> + Lower<'lt, 'ctx, B, T = Self>;
}

(working)

trait Raise{
    type Higher<'lt, 'ctx, B>: Lower<'lt, 'ctx, B, T = Self> + for<'a, 'b> Lower<'a, 'b, Bound<'a, 'b>>;
}

from rust.

konnorandrews avatar konnorandrews commented on July 26, 2024

I have simplified the code to this

fn main() {}

trait Raise{
    type Higher<'lt>: for<'a> Lower<'a> + Lower<'lt, T = Self>;
}

trait Lower<'lt> {
    type T: Raise<Higher<'lt> = Self>;
}

fn use_lower<'a, T: Raise>(x: T) {
    use_higher::<<T as Raise>::Higher::<'a>>(x);
}

fn use_higher<'a, H: for<'b> Lower<'b>>(x: <H as Lower<'a>>::T) {}

As before switching it with

 type Higher<'lt>: Lower<'lt, T = Self> + for<'a> Lower<'a>;

works

from rust.

fmease avatar fmease commented on July 26, 2024

cc @lcnr

from rust.

lcnr avatar lcnr commented on July 26, 2024

the unstable result depending on whether the associated type bounds are swapped is caused by

(ProjectionCandidate(i), ProjectionCandidate(j))
| (ObjectCandidate(i), ObjectCandidate(j)) => {
// Arbitrarily pick the lower numbered candidate for backwards
// compatibility reasons. Don't let this affect inference.
DropVictim::drop_if(i < j && !has_non_region_infer)
}

before #119820 we already discarded the non-hr item bounds - ProjectionCandidate - before using fn candidate_should_be_dropped_in_favor_of, causing us to always use the hr one, regardless of order.

from rust.

konnorandrews avatar konnorandrews commented on July 26, 2024

Here is a smaller example that doesn't use GATs.

pub trait ForLt<'a> {
    type T;
}

pub trait Hrt: for<'a> ForLt<'a> {}

pub trait Other<'a> {
    type Higher: Hrt + ForLt<'a>;
}
error: implementation of `ForLt` is not general enough
  --> src/main.rs:10:18
   |
7  | pub trait Hrt: for<'a> ForLt<'a> {}
   | --------------------------------
   | |              |
   | |              doesn't satisfy where-clause
   | due to a where-clause on `Hrt`...
...
10 |     type Higher: Hrt + ForLt<'a>;
   |                  ^^^
   |
   = note: ...`<Self as Other<'a>>::Higher` must implement `ForLt<'0>`, for any lifetime `'0`...
   = note: ...but it actually implements `ForLt<'a>`

(A more meaningful example is to use type Higher: Hrt + ForLt<'a, T = i32>;. As this actually adds a extra bound instead of it being a duplicate bound.)

Is the type Higher: ForLt<'a> + Hrt; supposed to be allowed? I do use the stable behavior in some code and am wondering if I need to change to some other method to achieve this.

from rust.

apiraino avatar apiraino commented on July 26, 2024

Same as #125194 . Changes in #119820 were reverted so in theory this regression should be neutralized in the current nightly. Can you check @konnorandrews ? thanks

from rust.

lcnr avatar lcnr commented on July 26, 2024

I only reverted it on beta, it still affects nightly (and the new beta)

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.