Skip to content
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

ICE: "unprintable span" with macro and two files, no backtrace #29084

Closed
khernyo opened this issue Oct 15, 2015 · 1 comment · Fixed by #31089
Closed

ICE: "unprintable span" with macro and two files, no backtrace #29084

khernyo opened this issue Oct 15, 2015 · 1 comment · Fixed by #31089
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@khernyo
Copy link
Contributor

khernyo commented Oct 15, 2015

Compiling the following two files results in an ICE without a backtrace:

  • lib.rs:
macro_rules! foo {
    ($d:expr) => {{
        fn bar(d: u8) { }
        bar(&mut $d);
    }}
}

mod m;
  • m.rs:
fn f() {
    foo!(0u8);
}

Compiled with the command: rustc lib.rs --crate-type lib

Results in the following output:

lib.rs:4:13: 2:13 error: mismatched types:
 expected `u8`,
    found `&mut u8`
(expected u8,
    found &-ptr) [E0308]
(internal compiler error: unprintable span)
lib.rs:1:1: 6:2 note: in expansion of foo!
m.rs:2:5: 2:15 note: expansion site
lib.rs:4:13: 2:13 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error

I could not reproduce it when module m is inlined in lib.rs.
Same result on stable, beta and nightly:

multirust: checking metadata version
multirust: got metadata version 2
rustc 1.3.0 (9a92aaf19 2015-09-15)
binary: rustc
commit-hash: 9a92aaf19a64603b02b4130fe52958cc12488900
commit-date: 2015-09-15
host: x86_64-unknown-linux-gnu
release: 1.3.0
multirust: checking metadata version
multirust: got metadata version 2
rustc 1.4.0-beta.2 (4b9b1f3b0 2015-10-01)
binary: rustc
commit-hash: 4b9b1f3b0fe6cd99e1e929b7def63c37f286f335
commit-date: 2015-10-01
host: x86_64-unknown-linux-gnu
release: 1.4.0-beta.2
multirust: checking metadata version
multirust: got metadata version 2
rustc 1.5.0-nightly (eafe106ef 2015-10-15)
binary: rustc
commit-hash: eafe106ef3dcf35b05edc2fb7c835ea83431fd34
commit-date: 2015-10-15
host: x86_64-unknown-linux-gnu
release: 1.5.0-nightly
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 29, 2015
@Nashenas88
Copy link
Contributor

The following code also has the same problem:

fn main() {
    macro_rules! call_mut {
        ($e:expr, $i:expr) => {
            $e.call_mut()
        };
        ($e:expr, $i:expr, $($is:expr),+) => {
            call_mut!($e.call(), $($is),+)
            //          ^ this is the problem, it should be call_mut
        };
    }

    struct S;

    impl S {
        fn call(&self) -> &S { self }
        fn call_mut(&mut self) -> &mut S { self }
    }

    let mut s = S;
    let mut s2: &mut S = call_mut!(s, 1, 2);
}

which gives the following output on https://play.rust-lang.org/ (this is the same on stable, beta, and nightly):

<anon>:20:36: 7:32 error: cannot borrow immutable borrowed content as mutable
(internal compiler error: unprintable span)
<anon>:7:13: 7:43 note: in this expansion of call_mut! (defined in <anon>)
<anon>:20:26: 20:44 note: in this expansion of call_mut! (defined in <anon>)
error: aborting due to previous error
playpen: application terminated with error code 101

bors added a commit that referenced this issue Jan 27, 2016
This is a  work in progress PR that potentially should fix #29084, #28308, #25385, #28288, #31011. I think this may also adresse parts of  #2887.

The problem in this issues seems to be that when transcribing macro arguments, we just clone the argument Nonterminal, which still has to original spans. This leads to the unprintable spans. One solution would be to update the spans of the inserted argument to match the argument in the macro definition. So for [this testcase](https://github.com/rust-lang/rust/compare/master...fhahn:macro-ice?expand=1#diff-f7def7420c51621640707b6337726876R2) the error message would be displayed in the macro definition:

    src/test/compile-fail/issue-31011.rs:4:12: 4:22 error: attempted access of field `trace` on type `&T`, but no field with that name was found
    src/test/compile-fail/issue-31011.rs:4         if $ctx.trace {

Currently I've added a very simple `update_span` function, which updates the span of the outer-most expression of a `NtExpr`, but this `update_span` function should be updated to handle all Nonterminals. But I'm pretty new to the macro system and would like to check if this approach makes sense, before doing that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants