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

False double-borrow and/or ICE in macro expansion (only with macro arguments) #7971

Closed
bblum opened this issue Jul 22, 2013 · 0 comments
Closed
Labels
A-lifetimes Area: Lifetimes / regions A-syntaxext Area: Syntax extensions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@bblum
Copy link
Contributor

bblum commented Jul 22, 2013

fn main() {
    macro_rules! foo(
        ($a: expr) => {{
            let mut x = ~[0];
            x.push($a);
            x.push($a);
        }}
    );
    foo!(1);
}

Error:

shit.rs:6:12: 6:13 error: cannot borrow `x` as mutable more than once at a time
shit.rs:6             x.push($a);
                      ^
shit.rs:2:4: 8:6 note: in expansion of foo!
shit.rs:9:4: 9:12 note: expansion site
shit.rs:6:12: 6:13 note: second borrow of `x` as mutable occurs here
shit.rs:6             x.push($a);
                      ^

If the macro is written with no arguments, or if the argument is not used in the expansion, then the error goes away. I believe the double-borrow error is because the borrow-checker tracks on a line-granularity instead of an expression-granularity, but I've no idea why the arguments affect it.

Here is a variation that causes an ICE instead:

fn main() {
    macro_rules! foo(
        ($a: expr) => {{
            let mut x = ~[$a];
            x.push(0);
            x.push($a);
        }}
    );
    foo!(1);
}

The ICE error, with an old build of rustc, is:

rust: task failed at 'assertion failed: region_maps.scopes_intersect(old_loan.kill_scope,
new_loan.kill_scope)', /home/bblum/rust/src/librustc/middle/borrowck/check_loans.rs:181

and with a new (today) build, is:

rust: task failed at 'index out of bounds: the len is 41 but the index is 41',
/home/bblum/rust/src/librustc/middle/lang_items.rs:374
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Sep 7, 2013
…node has a

unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes rust-lang#7971
Fixes rust-lang#6304
Fixes rust-lang#8367
Fixes rust-lang#8754
Fixes rust-lang#8852
bors added a commit that referenced this issue Sep 10, 2013
…r=catamorphism

Ensures that each AST node has a unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes #7971
Fixes #6304
Fixes #8367
Fixes #8754
Fixes #8852
Fixes #2543
Fixes #7654
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 23, 2021
…logiq

fix suggestion in option_map_or_none

fix: rust-lang#7960
changelog: change suggestion in the lint rule `option_map_or_none`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-syntaxext Area: Syntax extensions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
1 participant