Skip to content

strange scoping issue when trying to use alloc::vec![]  #61699

@alex

Description

@alex
Member

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=74f146f90570f0e4bb9e2b957532290a

#![no_std]

extern crate alloc;

use alloc::vec::Vec;

pub fn f() -> Vec<u8> {
    let x = alloc::vec![
        0,
    ].into_boxed_slice();
    return x.to_vec();
}
   Compiling playground v0.0.1 (/playground)
error: cannot find macro `vec!` in this scope
  --> src/lib.rs:8:13
   |
8  |       let x = alloc::vec![
   |  _____________^
9  | |         0,
10 | |     ].into_boxed_slice();
   | |_____^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

error: Could not compile `playground`.

If I change the invocation to alloc::vec![] it has no trouble finding the invocation. I have no idea what to make of this.

Activity

added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
T-langRelevant to the language team
on Jun 9, 2019
petrochenkov

petrochenkov commented on Jun 9, 2019

@petrochenkov
Contributor

Fixed in #61629

alex

alex commented on Jun 9, 2019

@alex
MemberAuthor

Thanks!

petrochenkov

petrochenkov commented on Jun 9, 2019

@petrochenkov
Contributor

The workaround is to remove the trailing comma after 0 inside vec![], then vec won't call itself recursively (which is causing the error).

alex

alex commented on Jun 9, 2019

@alex
MemberAuthor

Yup, now that you've pointed it out it's completely clear what was happening :-/

added 2 commits that reference this issue on Jun 12, 2019
55df67d
96b5830
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-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alex@jonas-schievink@petrochenkov

      Issue actions

        strange scoping issue when trying to use alloc::vec![] · Issue #61699 · rust-lang/rust