-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 from stable to nightly: nested impl trait is not allowed #57979
Comments
Likely cuplrit: #57730 (this comment seems relevant) cc @Zoxc |
Also nominated for T-Lang's Thursday meeting; from what I can tell, this shouldn't have been allowed in the first place and appears to have been allowed due to a bug in the nested-impl-trait checking logic. IOW, the snippet above could be interpreted as: pub fn collect(_: impl IntoIterator<Item = impl for<T: AsRef<[u8]>> Borrow<Data<T>>>) {
unimplemented!()
} |
I do not know that we have to discuss in the @rust-lang/lang meeting, but I'm not opposed. I agree with @Centril that this should not have been accepted. In particular, we decided to forbid nested impl trait of this kind: fn foo() -> impl Foo<impl Bar> { .. } Basically there are two hidden variables here, let's call them
However, the user is only giving us the return type The same seems to apply in this situation. Here there are three impl traits, so we have
Now, based on So I would argue that this is a bug fix and we should tag the issue as E-needstest (I'd prefer not to issue a warning period unless we know that this affects a broader swath of code). |
This issue is more subtle than the compiler error message leads us to believe:
and is a bit perplexing without the explanation @nikomatsakis gave, given it can be worked around by mechanically replacing
Hmm, I'm not sure how we could reasonably determine that given the dark matter closed-source floating around? It certainly affected our product code. Is there a reason not to issue a warning period? |
Why can we not support "I return something implementing Iterator where the items implement Foo"? That seems useful. |
@joshtriplett We can and we do (playground): fn foo() -> impl Iterator<Item = impl core::fmt::Debug> { 0..10 } This issue is about something else. The distinction is between |
+1 to "this was a bug" |
This isn't just a bug, it's also stabilized behaviour. I'm all for patching this up, but am not so keen on an immediate hard error on the next stable release. |
is this going to be addressed (in some manner) by PR #57981? Is the manner in which that PR addresses this also "acceptable"? Its not 100% clear whether a warning-cycle makes sense in this case, versus jumping to an immediate hard error. I suppose it depends on what semantics is being assigned when this code is accepted in the first place. |
triage: P-high, assigning to self. |
In case people want further illustration of this point, here is an example of the above scenario (play): #![allow(dead_code)]
pub trait Quux { type Assoc; }
pub trait Foo<T> { }
pub trait Bar { }
struct S1;
struct S2;
struct S3;
struct S4;
impl Quux for S1 { type Assoc = S2; }
impl Foo<S3> for S2 { }
impl Bar for S3 { }
impl Bar for S4 { }
// The presence/absence of this line dictates whether
// we get inference failures or not
impl Foo<S4> for S2 { }
pub fn foobar(_: impl Quux<Assoc=impl Foo<impl Bar>>) {
}
fn main() {
foobar(S1);
} (and, as far as I know, there's no way to add type annotations to the call site within |
Having said that, it seems like we at least attempt to do inference when encountering the code in question (at least back when we managed to sneak it pass the compiler's initial static checks). This leads me to wonder if a warning cycle is at least possible via a relatively small delta to the |
…dence over an ICE.
@Zoxc oops sorry about that. |
visiting for triage: if we approve beta-backport of PR #58608, then we'll plan to land that PR and subsequently close this as fixed. If we don't approve beta-backport of PR #58608, then I currently assume we won't land that PR at all, and will instead just close this as an unfortunate "wont fix" (in the sense that we'll just live with the absence of a warning-period)
|
Given that this slipped, I agree with the sentiment that there's little point in a hard error then warning then hard error so I'd say let's not 🔙. |
@Centril current pre-disposition of compiler team is to go ahead and backport to beta; see #58608 (comment) But we haven't "finalized" that decision; we decided to leave the PR open a week to give people a chance to object asynchronously to the backport. So, @Centril, are you actually objecting to a backport of PR #58608 ? |
@pnkfelix Yep; I think it is of little value to make things a hard error and then a warning again and I also think the chance of this occurring in the wild is low due to the inference problems per your notes. |
(Discussed in @Centril during T-compiler meeting, and clarified that when I said that this "slipped", I meant that the PR didn't manage to make it into nightly in time for the nightly-to-beta lift. @Centril had thought I meant that the bug had already leaked into the stable channel. Once we clarified that, @Centril retracted their objection.) |
…mpl-trait, r=zoxc Warning period for detecting nested impl trait Here is some proposed code for making a warning period for the new checking of nested impl trait. It undoes some of the corrective effects of PR #57730, by using boolean flags to track parts of the analysis that were previously skipped prior to PRs #57730 and #57981 landing. Cc #57979
I have some code that looks a bit like this:
On
1.32.0
(and the current beta1.33.0-beta.4 2019-01-24 635817b9db20ecdcd036
) this compiles successfully.On the current nightly
1.34.0-nightly 2019-01-28 d8a0dd7ae88023bd09fa
this fails with:A workaround is just to use generics. Did we mean to change the rules around nested impl trait here?
The text was updated successfully, but these errors were encountered: