Skip to content

Regression in glob imports vs. macro and type namespaces (lib bytemuck) #112860

Closed
@kpreid

Description

@kpreid

I could not produce a standalone reproducer, but compiling bytemuck from the repository or as a dependency will reproduce the issue by failing to compile.

  • Version it works on: stable and nightly-2023-06-19
  • Version with regression: nightly-2023-06-20

To reproduce, run:

cargo +nightly-2023-06-20 build --features extern_crate_alloc,derive

Version with regression

rustc --version --verbose:

rustc 1.72.0-nightly (fe7454bf4 2023-06-19)
binary: rustc
commit-hash: fe7454bf439c93cbe9ac8a8f7fcfacd5a40244c2
commit-date: 2023-06-19
host: x86_64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5

Compilation errors

   Compiling bytemuck v1.13.2 (/Users/kpreid/Projects/rust/reference/bytemuck)
error[E0404]: expected trait, found derive macro `NoUninit`
  --> src/allocation.rs:25:20
   |
25 | pub fn cast_box<A: NoUninit, B: AnyBitPattern>(input: Box<A>) -> Box<B> {
   |                    ^^^^^^^^ not a trait
   |
help: consider importing this trait instead
   |
12 + use crate::NoUninit;
   |

error[E0404]: expected trait, found derive macro `AnyBitPattern`
  --> src/allocation.rs:25:33
   |
25 | pub fn cast_box<A: NoUninit, B: AnyBitPattern>(input: Box<A>) -> Box<B> {
   |                                 ^^^^^^^^^^^^^ not a trait
   |
help: consider importing this trait instead
   |
12 + use crate::AnyBitPattern;
   |

and many more. The notable thing here is that NoUninit and friends are imported via use super::*;, and in super (the root), there is both a non-glob derive macro import (from the macro crate) and a glob trait import (from another module).

Failed reproducer

I tried to reproduce this import situation in a single file as follows:

#[cfg(feature = "derive")]
use scratchpad_macros::Foo; // a proc macro, nothing special

mod f {
    pub trait Foo {}
}
pub use f::*;

#[cfg(feature = "alloc")]
mod b {
    use super::*;
    pub fn bar<T: Foo>() {}
}
#[cfg(feature = "alloc")]
pub use b::*;

However, this compiles on all tested versions.

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions