-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Trait object allowed to escape its lifetime #14285
Comments
Can you provide some contextual information such as rustc version and platform you're running on? I cannot reproduce the segfault you've mentioned on either OSX or ubuntu. |
This fails: https://gist.github.com/1f36060fd4e533ae0d8b (I'm surprised this one compiles actually.) So does this: https://gist.github.com/6ee5ffe1de090ff3a2d0 Version:
|
Try with:
|
Alex, Sorry if I didn't make it clear enough. The gist has the working version uncommented, and the bug code is actually commented out. That was probably a poor decision on my part. |
Updating to a more minimal description. Nominating and cc @nikomatsakis |
It appears the bug is that the argument taken in the buggy examples is |
Is it relevant that different errors would be encountered based on whether you piped data in or not? Or is that a red herring? The assertion error is encountered in the original gist if you pipe data in, while if you do not pipe data in then the program segfaults before exiting. |
The problem appears to be that the I/O object is being dropped, and then being used. This basically amounts to use-after-free, and LLVM optimizations can do really weird things to that, causing segfaults/asserts and whatnot. |
The root cause lies in variance.rs#L744-L748, where the lifetime parameter of a possible trait reference should be accounted for but isn't. The fix is rather straightforward and had been tried before, but unfortunately never landed. It invalidates json.rs#L379-L388. BTW, with that fix rustc does reject the code in question: // error: cannot infer an appropriate lifetime
fn foo<'a>(a: &Foo) -> B<'a> { B(a) } |
The rust-lang#14869 removed `TraitStore` from `ty_trait` and represented trait reference as regular `ty_rptr`. An old bug of the missing constraint upon lifetime parameter of trait reference then is fixed as a side effect. Adds tests for affected bugs and closes them. Closes rust-lang#12470. Closes rust-lang#14285.
Closes rust-lang#14482 (std: Bring back half of Add on String) Closes rust-lang#15026 (librustc: Remove the fallback to `int` from typechecking.) Closes rust-lang#15119 (Add more description to c_str::unwrap().) Closes rust-lang#15120 (Add tests for rust-lang#12470 and rust-lang#14285) Closes rust-lang#15122 (Remove the cheat sheet.) Closes rust-lang#15126 (rustc: Always include the morestack library) Closes rust-lang#15127 (Improve ambiguous pronoun.) Closes rust-lang#15130 (Fix rust-lang#15129) Closes rust-lang#15131 (Add the Guide, add warning to tutorial.) Closes rust-lang#15134 (Xfailed tests for hygiene, etc.) Closes rust-lang#15135 (core: Add stability attributes to Clone) Closes rust-lang#15136 (Some minor improvements to core::bool) Closes rust-lang#15137 (std: Add stability attributes to primitive numeric modules) Closes rust-lang#15141 (Fix grammar in tutorial) Closes rust-lang#15143 (Remove few FIXMEs) Closes rust-lang#15145 (Avoid unnecessary temporary on assignments) Closes rust-lang#15147 (Small improvements for metaprogramming) Closes rust-lang#15153 (librustc: Check function argument patterns for legality of by-move) Closes rust-lang#15154 (test: Add a test for regions, traits, and variance.) Closes rust-lang#15159 (rustc: Don't register syntax crates twice) Closes rust-lang#13816 (Stabilize version output for rustc and rustdoc)
Evaluate consts in `path_to_const` fix rust-lang#14275
Updated description
This code should be rejected from the compiler, but it is not:
Original Issue
Crash when reading from stdin
Depending on whether you let the compiler infer traits for you or not, you can make a program reading input from stdin crash in a couple different ways.
Repro here: https://gist.github.com/brandonw/3a3d040b7c6213740794
The text was updated successfully, but these errors were encountered: