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

variable in macro output incorrectly reported as unused #5718

Closed
metajack opened this issue Apr 4, 2013 · 6 comments · Fixed by #17721
Closed

variable in macro output incorrectly reported as unused #5718

metajack opened this issue Apr 4, 2013 · 6 comments · Fixed by #17721
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-syntaxext Area: Syntax extensions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority

Comments

@metajack
Copy link
Contributor

metajack commented Apr 4, 2013

In the code here:

macro_rules! handle_heading_element(
    ($tag:expr, $string:expr, $ctor:ident, $type_id:expr, $level:expr) => (
        if eq_slice($tag, $string) {
            let _element = ~HTMLHeadingElement {
                parent: Element::new($type_id, ($tag).to_str()),
                level: $level
            };
            unsafe {
                return Node::as_abstract_node(_element);
            }
        }
    )
)

(taken from jack's servo repo.)

The compiler will complain that element is unused unless I prefix it with _, even though it is clearly used shortly after.

metajack referenced this issue in metajack/servo Apr 4, 2013
@pnkfelix
Copy link
Member

Nominating for milestone 5 (production-ready), as this is analogous to issue #4381 which was accepted for that milestone 3 weeks ago.

@graydon
Copy link
Contributor

graydon commented May 23, 2013

accepted for production-ready milestone

@catamorphism
Copy link
Contributor

Bug triage. Milestone still looks fine.

@pnkfelix
Copy link
Member

This need not block 1.0, since macro_rules are feature gated. Assigning P-low.

@pnkfelix
Copy link
Member

(also suspected not-a-bug-anymore as fixed, but need to check...)

@huonw
Copy link
Member

huonw commented Sep 9, 2014

Seems to be fixed, e.g.

#![feature(macro_rules)]

struct Element;

macro_rules! foo {
    ($tag: expr, $string: expr) => {
        if $tag == $string {
            let element = box Element;
            unsafe {
                return std::mem::transmute::<_, uint>(element);
            }
        }
    }
}

fn bar() -> uint {
    foo!("a", "b");
    0
}

fn main() {
    bar();
}

@huonw huonw added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-syntaxext Area: Syntax extensions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants