Skip to content

Using an interpolated variable by-ref twice in a macro causes borrowck errors #8367

Closed

Description

@huonw

Using only the by_val line compiles fine:

trait Foo {
    fn by_val(self) {}
    fn by_ref(&self) {}
}
impl Foo for int {}

fn main() {
    macro_rules! t (
        ($a:expr) => { {
            // $a.by_val(); $a.by_val();
            $a.by_ref(); $a.by_ref();
        } }
    );

    t!(1i);
}
macro-use-twice.rs:15:7: 15:9 error: borrowed value does not live long enough
macro-use-twice.rs:15     t!(1i);
                             ^~
macro-use-twice.rs:8:4: 13:6 note: in expansion of t!
macro-use-twice.rs:15:4: 15:11 note: expansion site
macro-use-twice.rs:9:23: 12:9 note: borrowed pointer must be valid for the block at 9:23...
macro-use-twice.rs:9         ($a:expr) => { {
macro-use-twice.rs:10             //$a.by_val(); $a.by_val();
macro-use-twice.rs:11             $a.by_ref(); $a.by_ref();
macro-use-twice.rs:12         } }
macro-use-twice.rs:15:7: 11:37 note: ...but borrowed value is only valid for the method call at 15:7
macro-use-twice.rs:8:4: 13:6 note: in expansion of t!
macro-use-twice.rs:15:4: 15:11 note: expansion site
macro-use-twice.rs:15:7: 15:9 error: borrowed value does not live long enough
macro-use-twice.rs:15     t!(1i);
                             ^~
macro-use-twice.rs:8:4: 13:6 note: in expansion of t!
macro-use-twice.rs:15:4: 15:11 note: expansion site
macro-use-twice.rs:9:23: 12:9 note: borrowed pointer must be valid for the block at 9:23...
macro-use-twice.rs:9         ($a:expr) => { {
macro-use-twice.rs:10             //$a.by_val(); $a.by_val();
macro-use-twice.rs:11             $a.by_ref(); $a.by_ref();
macro-use-twice.rs:12         } }
macro-use-twice.rs:15:7: 11:37 note: ...but borrowed value is only valid for the method call at 15:7
macro-use-twice.rs:8:4: 13:6 note: in expansion of t!
macro-use-twice.rs:15:4: 15:11 note: expansion site
error: aborting due to 2 previous errors

Activity

  1. added 3 commits that reference this issue on Sep 7, 2013
    32c4d9b
  2. added a commit that references this issue on Sep 10, 2013
    a5ad4c3
  3. added a commit that references this issue on Sep 10, 2013
    753d8c2
  4. added a commit that references this issue on Feb 24, 2022
    7ee2081
  5. added a commit that references this issue on Jun 30, 2022
    a4130e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions