Skip to content

Unexpected panic with derive debug on non-item #43023

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

Closed
alexbowers opened this issue Jul 3, 2017 · 9 comments
Closed

Unexpected panic with derive debug on non-item #43023

alexbowers opened this issue Jul 3, 2017 · 9 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@alexbowers
Copy link

alexbowers commented Jul 3, 2017

Compiling mount v0.3.0 (file:///var/www/sites/current/mount)
error: `derive` can be only be applied to items
  --> /var/www/sites/current/mount/src/mount.rs:63:14
   |
63 |     #[derive(Debug)]
   |              ^^^^^

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'adding a def'n for node-id NodeId(4294967295) and data TypeParam("H") but a previous def'n exists: DefKey { parent: Some(DefIndex(29)), disambiguated_data: DisambiguatedDefPathData { data: ValueNs("mount"), disambiguator: 0 } }', /checkout/src/librustc/hir/map/definitions.rs:479
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `mount`.

Code:

impl Mount {
    /// Creates a new instance of `Mount`.
    pub fn new() -> Mount {
        Mount {
            inner: SequenceTrie::new()
        }
    }

    /// Mounts a given `Handler` onto a route.
    ///
    /// This method may be called multiple times with different routes.
    /// For a given request, the *most specific* handler will be selected.
    ///
    /// Existing handlers on the same route will be overwritten.
    #[derive(Debug)]
    pub fn mount<H: Handler>(&mut self, route: &str, handler: H) -> &mut Mount {
        // Parse the route into a list of strings. The unwrap is safe because strs are UTF-8.
        let key: Vec<&str> = Path::new(route).components().flat_map(|c|
            match c {
                Component::RootDir => None,
                c => Some(c.as_os_str().to_str().unwrap())
            }
        ).collect();

        // Insert a match struct into the trie.
        let match_length = key.len();
        self.inner.insert(key, Match {
            handler: Box::new(handler) as Box<Handler>,
            length: match_length,
        });
        self
    }
}

I assume this is because of where I put the derive debug line.

@strangeglyph
Copy link
Contributor

Minimized:

struct Mount;
impl Mount {
    #[derive(Debug)]
    fn mount(a: ()) {}
}

Though I'm only able to reproduce on stable and beta, not nightly

@alexbowers
Copy link
Author

This is on stable

rustc 1.18.0 (03fc9d622 2017-06-06)
cargo 0.19.0 (28d1d60d4 2017-05-16)

@TimNN TimNN added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 3, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@iWritei
Copy link

iWritei commented Aug 9, 2017

I also seen this bug with the following code:

fn main() {
let test = test_it::GoodMessage(String::from("Hi Good Looking") );
test.printme();
}
enum test_it{
GoodMessage(String),
BadMessage(String),
}
impl test_it{
#[derive(Debug)]
fn printme(&self)
{
println!("{:?}",self);
}
}

rustc 1.19.0 (0ade339 2017-07-17)
binary: rustc
commit-hash: 0ade339
commit-date: 2017-07-17
host: x86_64-unknown-linux-gnu
release: 1.19.0
LLVM version: 4.0

@kennytm
Copy link
Member

kennytm commented Aug 9, 2017

@iWritei's ICE seems to be a different issue from @Boreeas's. Several reduced test cases:

// ICE everywhere.
struct S;
impl S {
    #[derive(Debug)]
    fn f() {
        file!(); // must invoke a macro.
    }
}
// ICE on beta, nightly; no ICE on stable.
trait TT {
    #[derive(Debug)]
    fn f();
}
// ICE on beta, nightly; no ICE on stable.
trait TT {
    #[derive(Debug)]
    type F;
}

The first new ICE happens with the unwrap on this line: https://github.com/rust-lang/rust/blob/3f977baf/src/libsyntax/ext/placeholders.rs#L105

impl<'a, 'b> PlaceholderExpander<'a, 'b> {
    fn remove(&mut self, id: ast::NodeId) -> Expansion {
        self.expansions.remove(&id).unwrap()
    }
}

Not sure about the rest, but they all involve an unwrap() somewhere.

@alexbowers
Copy link
Author

I ran into this again today, can this be improved somehow?

@arielb1 arielb1 added regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 3, 2017
@arielb1 arielb1 changed the title Unexpected panic with derive debug Unexpected panic with derive debug on non-struct Sep 3, 2017
@arielb1
Copy link
Contributor

arielb1 commented Sep 3, 2017

Current compiler output is:

   Compiling playground v0.0.1 (file:///playground)
error: `derive` can be only be applied to items
  --> src/main.rs:10:10
   |
10 | #[derive(Debug)]
   |          ^^^^^

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.22.0-nightly (744dd6c1d 2017-09-02) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:335:20
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@arielb1 arielb1 changed the title Unexpected panic with derive debug on non-struct Unexpected panic with derive debug on non-item Sep 3, 2017
@jseyfried jseyfried self-assigned this Sep 7, 2017
@nikomatsakis
Copy link
Contributor

triage: P-high

@jseyfried
Copy link
Contributor

Fixed in #44757.

@alexbowers
Copy link
Author

@jseyfried Thanks for the fix, hope it gets merged soon.

For my understanding and learning, is it possible for you to detail how you went about debugging this?

I wouldn't know where to start, and since this PR is fairly simple in its changes, it would be probably a good one to learn from.

Thanks :)

bors added a commit that referenced this issue Sep 23, 2017
macros: fix bug in collecting trait and impl items with derives.

Fixes #43023.
r? @nrc
bors added a commit that referenced this issue Sep 26, 2017
macros: fix bug in collecting trait and impl items with derives.

Fixes #43023.
r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests