# "Unexpected panic" message

**URL:** <https://internals.rust-lang.org/t/unexpected-panic-message/11665>\
**Category:** Uncategorized\
**Created:** [January 21, 2020, 7:32pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665 "2020-01-21T19:32:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkettle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dkettle/32/6468_2.png) [@dkettle](https://internals.rust-lang.org/u/dkettle)\
**Post date:** [January 21, 2020, 7:32pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/1 "2020-01-21T19:32:16Z")

</div>

I don't really think this is a bug, but according to the error message I received ("note: the compiler unexpectedly panicked. this is a bug.") it is. It's more likely something I'm doing wrong, though (I've just started to learn the language). I'm trying to compile the "guessing game" example from "The Rust Programming Language" and received this error message. I have been able to compile and run the "Hello World" program, though.

Attached is a listing of the source code and a screen capture. If there's any more information you need, let me know.

David.

```
use std::io;

fn main() {
    println!("Guess the number!");
    println!("please input your guess.");
    let mut guess = String::new();
    io::stdin().read_line(&mut guess).expect("Failed to read line");
    println!("You guessed: {}",guess);
}

```

 ![Screenshot 2020-01-21 14.15.22](https://us1.discourse-cdn.com/flex002/uploads/rustlang/original/2X/2/2400f9e6f41b449bc3a52213fa29c6e365aaec79.png)

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [January 21, 2020, 8:18pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/2 "2020-01-21T20:18:13Z")

</div>

You didn't do anything wrong, and there's absolutely a bug somewhere.

Can you make sure that no stale rust process or linker process is hung in the background, keeping that file open?

In any case, this shouldn't be an internal compiler error, it should be a graceful error (but still an error).

---

<div class="post-metadata">

**Author:** ![NoamB](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/noamb/32/6998_2.png) [@NoamB](https://internals.rust-lang.org/u/NoamB)\
**Post date:** [January 21, 2020, 10:38pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/3 "2020-01-21T22:38:18Z")

</div>

It looks like Dropbox was backing up an incremental compilation folder while the compiler tried to delete it. I don't know what the correct behavior should be: Crash, silently fail, retry, or something else?

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [January 21, 2020, 11:16pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/4 "2020-01-21T23:16:15Z")

</div>

Ah, good catch, I didn't notice the "dropbox" in the folder name. Yeah, that seems like the most likely scenario.

I think this should be an error, just not an internal compiler error.

@dkettle I would suggest, at a minimum, arranging to put the results of compilation outside a Dropbox folder; you can set Rust's target directory, for instance.

---

<div class="post-metadata">

**Author:** ![dkettle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dkettle/32/6468_2.png) [@dkettle](https://internals.rust-lang.org/u/dkettle)\
**Post date:** [January 22, 2020, 12:27am UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/5 "2020-01-22T00:27:51Z")

</div>

I think you're right. I couldn't see any processes running that were obviously related to Rust, although I'm not sure what names the processes would have. So I rebooted the computer and I was able to compile and run the program. I haven't been able to reproduce the problem since I rebooted, even though I'm still compiling inside a Dropbox folder. I also do some development in Python, C, etc., in Dropbox folders and this has never been a problem. If the problem reoccurs, I'll move my Rust folder outside of my Dropbox folder and see if that fixes the problem. Maybe it was just a timing issue.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![dkettle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dkettle/32/6468_2.png) [@dkettle](https://internals.rust-lang.org/u/dkettle)\
**Post date:** [January 22, 2020, 12:54am UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/6 "2020-01-22T00:54:11Z")

</div>

P.S. I looked in the 'incremental' directory and noticed that there are dozens of object files with names that seem to be randomly generated. I guess these are the files that the compiler couldn't delete. Is it safe to delete them manually?

 ![Screenshot 2020-01-21 19.48.55](https://us1.discourse-cdn.com/flex002/uploads/rustlang/original/2X/9/90b3dc743c0572c78fd808712690a4d3ed03d199.png)

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [January 22, 2020, 4:43am UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/7 "2020-01-22T04:43:24Z")

</div>

It's always safe to delete the entire `target` directory; you'll just have to re-run `cargo build` or `cargo run` at that point.

---

<div class="post-metadata">

**Author:** ![HadrienG](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hadrieng/32/3294_2.png) [@HadrienG](https://internals.rust-lang.org/u/HadrienG)\
**Post date:** [January 22, 2020, 7:17am UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/8 "2020-01-22T07:17:56Z")

</div>

These files are cached intermediary compilation products, kept around to speed up future recompilations of a project. In that sense, you can think about them like the .o files of C/++, though the underlying compilation process is actually different.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [January 22, 2020, 3:31pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/9 "2020-01-22T15:31:39Z")

</div>

That's another case where it'd help if Cargo was using a proper system temp directory (e.g. `C:\temp\somehash\`) instead of dumping temp files in `./target`.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [January 22, 2020, 4:56pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/10 "2020-01-22T16:56:04Z")

</div>

I don't think the system temporary directory is necessarily the right place, as these files have value to avoid rebuilds, so they should stick around as long as the user has space. Something like `$XDG_CACHE_DIR` might make sense as an option, though. That would certainly make it easier to clean up object files in a central place.

We might want to talk about that on one of the cargo issues or threads that's already talking about sharing builds between projects on the system, since those seem quite related.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [April 21, 2020, 4:56pm UTC](https://internals.rust-lang.org/t/unexpected-panic-message/11665/11 "2020-04-21T16:56:07Z")

</div>

Closed on April 21, 2020, 4:56pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
