Rust-GCC / Rust-GCC/gccrs

You aren't allowed to `use i32` or `use self::i32`

Open
#3,429 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
20h 2m
Merged PRs (30d)
66

Description

I tried the following code:

use i32 as B; // { dg-error "unresolved import .self::i32." }

fn main() -> isize {
    let i: i32 = 0 as i32;
    i as isize
}

What I expected:

TRS-E14 build $ rustc issue-3315-2.rs
error[E0432]: unresolved import `i32`
 --> issue-3315-2.rs:2:5
  |
2 | use i32 as B; // { dg-error "unresolved import .self::i32." }
  |     ^^^^^^^^ no `i32` in the root
  |
help: consider importing one of these items instead
  |
2 | use std::i32 as B; // { dg-error "unresolved import .self::i32." }
  |     ~~~~~~~~~~~~~
2 | use std::primitive::i32 as B; // { dg-error "unresolved import .self::i32." }
  |     ~~~~~~~~~~~~~~~~~~~~~~~~

What I got:
gccrs compiles this code with no error

Source: https://doc.rust-lang.org/reference/names/preludes.html, "These prelude names are not part of the module itself: they are implicitly queried during name resolution. For example, even though something like Box is in scope in every module, you cannot refer to it as self::Box because it is not a member of the current module."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Rust reproduction in the issue and read the referenced Rust Reference sections on preludes and name resolution. Verify that use i32 and use self::i32 are rejected while ordinary i32 type usage remains valid; the expected result is an unresolved-import diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.