You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
With a generic struct, Self(x) works where x is of the wrong type argument #61882
This does seem like a bug to me... In particular, type_alias_enum_variants does not allow Self::Some(transform(x)) where Self == Option<T> but where Option<U> is expected.
Ouch, this explains why we were able to remove the Ty result from rewrite_self_ctor as redundant in #61085 / #61189 - there was a subst call missing on that type.
But that's not the end of it, this is incorrectly allowed right now, as well:
In that Res::SelfCtorreally needs to be treated like Res::Local.
In general, I think instead of rewrite_self_ctor we need a method that only returns the right information (such as the modified Res and substituted Ty) given the implDefId inside Res::SelfCtor.
And every call should be audited.EDIT: there's only one call now, huh, so it can be inlined.
I guess I could prepare a master and beta PR?
Looks like the test added in #59025 for #57924 has an explicit generic arg: Self::<E>(e), but somehow @varkor and I didn't spot that during the review, whoops.
Activity
petrochenkov commentedon Jun 16, 2019
Yes, that's a bug,
Selfin the example should beA<bool>andA::<bool>(0)should report an error.We missed a test for this in #53751 somehow (for
Selftypes this property is tested instruct-path-self-type-mismatch.rs).petrochenkov commentedon Jun 16, 2019
Self constructors were stabilized not too long ago, so this should preferably be fixed soon and backported to beta.
eddyb commentedon Jun 16, 2019
Ouch, this explains why we were able to remove the
Tyresult fromrewrite_self_ctoras redundant in #61085 / #61189 - there was asubstcall missing on that type.But that's not the end of it, this is incorrectly allowed right now, as well:
So the order here is wrong:
rust/src/librustc_typeck/check/mod.rs
Lines 5368 to 5377 in 374c63e
In that
Res::SelfCtorreally needs to be treated likeRes::Local.In general, I think instead ofEDIT: there's only one call now, huh, so it can be inlined.rewrite_self_ctorwe need a method that only returns the right information (such as the modifiedResand substitutedTy) given theimplDefIdinsideRes::SelfCtor.And every call should be audited.
I guess I could prepare a master and beta PR?
eddyb commentedon Jun 16, 2019
We shouldn't forget tests like
A<&'static T>being created withSelf(non_static_ref).eddyb commentedon Jun 16, 2019
Looks like the test added in #59025 for #57924 has an explicit generic arg:
Self::<E>(e), but somehow @varkor and I didn't spot that during the review, whoops.Rollup merge of rust-lang#61896 - eddyb:correct-self-ctor, r=petroche…
Rollup merge of rust-lang#61896 - eddyb:correct-self-ctor, r=petroche…