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

Fix a bug with statics inside blocks in generic fns #8843

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

Whenever a generic function was encountered, only the top-level items were
recursed upon, even though the function could contain items inside blocks or
nested inside of other expressions. This fixes the existing code from traversing
just the top level items to using a Visitor to deeply recurse and find any items
which need to be translated.

This was uncovered when building code with --lib, because the encode_symbol
function would panic once it found that an item hadn't been translated.

Closes #8134

@emberian
Copy link
Member

@alexcrichton how does this handle the following case:

pub fn foo() {
    static x: int = 42;
    {
        static x; int = 42;
        printfln!(x);
    }
    printfln!(x);
}

@alexcrichton
Copy link
Member Author

It uses a visitor to recurse inside of a function to visit all the items, and the default implementation of a visitor would recurse to each of those items. The name mangling for them happens elsewhere.

That also compiles fine today, the problem that this is addressing is when those statics are inside of a generic function which is then compiled into a library because the function itself isn't actually instantiated anywhere.

@@ -37,6 +37,8 @@ use std::vec;
use syntax::ast_map::{path, path_mod, path_name};
use syntax::ast_util;
use syntax::{ast, ast_map};
use syntax::visit;
use syntax::visit::Visitor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visitor isn't actually used; this line causes an unused-import error at stage1 compilation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you are correct, the perils of not running tests!

@lilyball
Copy link
Contributor

This appears to fix #8835, though I'm not done compiling yet (stage1 compilation seems to be working though).

Whenever a generic function was encountered, only the top-level items were
recursed upon, even though the function could contain items inside blocks or
nested inside of other expressions. This fixes the existing code from traversing
just the top level items to using a Visitor to deeply recurse and find any items
which need to be translated.

This was uncovered when building code with --lib, because the encode_symbol
function would panic once it found that an item hadn't been translated.

Closes rust-lang#8134
@lilyball
Copy link
Contributor

This definitely fixes #8835. Hopefully it will fix the problem I'm having in #8203 as well, although I won't know that for a while.

bors added a commit that referenced this pull request Aug 30, 2013
Whenever a generic function was encountered, only the top-level items were
recursed upon, even though the function could contain items inside blocks or
nested inside of other expressions. This fixes the existing code from traversing
just the top level items to using a Visitor to deeply recurse and find any items
which need to be translated.

This was uncovered when building code with --lib, because the encode_symbol
function would panic once it found that an item hadn't been translated.

Closes #8134
@bors bors closed this Aug 30, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 4, 2022
Collect renamed lints

changelog: Display past names of renamed lints on Clippy's lint list

cc rust-lang#7172

r? `@xFrednet`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: encode_symbol: id not found
5 participants