-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Compile-time stack overflow when trait impl contains extern crate #55779
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Mentioning @petrochenkov who seems to know about extern_prelude. |
(Also, the issue reproduces on 2015 edition as well.) |
I'm hitting this on stable 1.32.0 with a |
Just ran into this on |
Copying @jonas-schievink's I-nominated from #67817. |
pre-triage: P-high. Leaving nominated for discussion at compiler triage meeting tomorrow. |
From what I can tell, this was fixed sometime between nightly-2020-01-04 and nightly-2020-01-05. Here's what landed during that time:
|
I just discovered a detail about this bug that I did not previously appreciate: It needed the The bug as described here ended up being fixed by PR #67874. I suspect that's due to that rollup PR's inclusion of PR #67137, but I have not yet verified this. The question I have remaining: Is the bug here really fixed, or is it merely masked by the changes from PR #67874? E.g. PR #67137 makes heavy revisions to the expansion of Anyway, even if the bug here is truly fixed, we should add the code from the description here as a regression test. |
It's not fixed, the repro at the top still overflows rustc's stack as of 1.42.0-nightly (72b2bd5 2020-01-09). We would need to minimize again to get a different minimal repro post-#67874. // [dependencies]
// serde = "1.0"
// serde_derive = "1.0"
use serde::{Serialize, Serializer};
use serde_derive::Serialize;
struct _Local {
range: std::ops::Range<usize>,
}
impl Serialize for _Local {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
#[derive(Serialize)]
struct Helper {
min: usize,
max: usize,
}
let helper = Helper {
min: self.range.start,
max: self.range.end,
};
helper.serialize(serializer)
}
}
fn main() {} |
Okay I've got a new reproduction now, thanks for the pointer @dtolnay extern_trait/src/lib.rs: pub trait Trait { fn no_op(&self); } redo/src/main.rs: use extern_trait::Trait;
struct Local;
struct Helper;
impl Trait for Local {
fn no_op(&self)
{
// (Unused) extern crate declaration necessary to reproduce bug
extern crate extern_trait;
// This one works
// impl Trait for Helper { fn no_op(&self) { } }
// This one infinite-loops
const _IMPL_SERIALIZE_FOR_HELPER: () = {
// (extern crate can also appear here to reproduce bug,
// as in originating example from serde)
impl Trait for Helper { fn no_op(&self) { } }
};
}
}
fn main() { } |
removing nomination tag since I do not think this needs explicit discussion. However, it should get assignment. I'm not yet sure if I will take it on myself or try to get someone else to investigate it. |
For posterity, here's the current backtrace (since the
|
The issue is here rust/src/librustc_middle/ty/print/pretty.rs Lines 296 to 303 in 1241447
Removing the
an example of the changes:
I'll see what can be done. |
@estebank Just checking, did you see this? #55779 (comment) I don't remember all the details but I found that comment after looking at the context around the code you linked, which seemed vaguely familiar. |
@eddyb I'd seen that comment, but didn't grok the full meaning of it until I looked at this in more detail. Is there any reason not to change the |
I found this separately in #71157 (comment). Workaround: add an |
triage: nominating for discussion as part of attempt to burn down set of unassigned P-high issues at an otherwise light triage meeting. |
discussed at T-compiler meeting. Assigning to @eddyb |
@DevinR528 just ran into this bug in their GSoC project when adding a trybuild test (ruma-events#108 (Files)). EDIT: Rest of the comment was probably nonsense.
|
Just to confirm, still there in 1.46.0 (same repro with serde as posted above). |
Didn't see this when it was posted, my bad, but I wanted to reply because it's not that simple because that recursion tracking is limited to |
I ran into this as well with |
Uh oh!
There was an error while loading. Please reload this page.
I have two crates:
helper/src/lib.rs
repro/src/main.rs
Notice that the implementation of
helper::Trait
contains anextern crate helper
. Something is not happy about that.This currently affects Serde trait impls that use a private helper type with a Serde derive, which is a common pattern.
The following script reproduces the issue as of rustc 1.31.0-beta.4 (04da282 2018-11-01) as well as rustc 1.32.0-nightly (25a42b2 2018-11-07).
The text was updated successfully, but these errors were encountered: