Skip to content

"use std" before #[link(...)] in .rc file causes an error #2243

Closed

Description

@erickt

rustc errors out when compiling a ".rc" file if use std comes before the #link(...):

test:rc

use std;

#[link(name="test", vers="0.1")];

mod test;

test.rs:

fn main() {}

Errors with:

test.rc:3:32: 3:33 error: expecting mod, found ;
test.rc:3 #[link(name="test", vers="0.1")];

Activity

  1. brson commented on Apr 19, 2012

    @brson
    Contributor

    That inner attributes (attributes terminated with a semi) must come before any module contents is intentional, but this gotcha has come up before. Should we allow attributes anywhere in a module to apply to that module? It seems like too much action at a distance if, e.g. 2000 lines into parser.rs you wrote #[cfg(target_os = "macos")];.

    Maybe we could have a better error message.

  2. ghost assigned on Apr 19, 2012
  3. jbclements commented on Apr 25, 2013

    @jbclements
    Contributor

    Agreed. Would it be worth while to have a "better error message please" category? Similar to #1208 . Also, #2569 seems to be the canonical bug on the topic of inner attributes.

  4. pcwalton commented on May 16, 2013

    @pcwalton
    Contributor

    I don't believe this is backwards incompatible, renominating.

  5. graydon commented on Jun 6, 2013

    @graydon
    Contributor

    just a bug, removing milestone/nomination.

  6. bblum commented on Aug 12, 2013

    @bblum
    Contributor

    It's definitely a worse gotcha to have accidental semicolons cause entire modules to be #[ignore]d or whatever. Improved error message is the way to go.

  7. flaper87 commented on Apr 16, 2014

    @flaper87
    Contributor

    Visiting for triage: @cmr are you planing to create a PR for those commits?

  8. emberian commented on Apr 16, 2014

    @emberian
    Contributor

    Oops. I'll get to it in ~2 weeks.

  9. alexcrichton commented on Aug 10, 2014

    @alexcrichton
    Member

    I believe this has been satisfactorily fixed with unused attribute warnings.

  10. added a commit that references this issue on Sep 22, 2022
  11. added a commit that references this issue on Jun 4, 2024
    38179ae
  12. added a commit that references this issue on Feb 11, 2025
  13. added a commit that references this issue on Aug 21, 2026
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-diagnosticsArea: Messages for errors, warnings, and lintsA-frontendArea: Compiler frontend (errors, parsing and HIR)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions