Commit a978e7c
committed
Permit duplicate macro imports
Consider a crate that depends on both `serde` (without the `derive`
feature) and `serde_derive`, and imports `serde::Serialize` (a trait)
and `serde_derive::Serialize` (a macro). Then, imagine some other crate
in a build graph depends on `serde` *with* the `derive` feature; they
import both the macro and trait simultaneously with `use
serde::Serialize`. If duplicate imports of the same item are always
forbidden, these crates cannot co-exist in the same build-graph; the
former crate will fail to build, as its first import (which will now
also import the `Serialize` macro) conflicts with its second import.
This build hazard is confusing — the author of the second crate had no
idea that their dependence on the `derive` feature might be problematic
for other crates. The author of the first crate can mitigate the hazard
by only glob-importing from proc-macro crates, but glob imports run
against many's personal preference and tooling affordances (e.g.,
`rust-analyzer`'s auto-import feature).
We mitigate this hazard across the ecosystem by permitting duplicate
imports of macros. We don't limit this exception to proc macros, as it
should not be a breaking change to rewrite a proc macro into a
by-example macro. Although it would be semantically unproblematic to
permit *all* duplicate imports (not just those of macros), other kinds
of imports have not, in practice, posed the same hazard, and there might
be cases we'd like to warn-by-default against. For now, we only permit
duplicate macro imports.
See https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Allowing.20same-name.20imports.20of.20the.20same.20item/near/5167772211 parent 414482f commit a978e7c
File tree
2 files changed
+54
-3
lines changed- compiler/rustc_resolve/src
- tests/ui/proc-macro
2 files changed
+54
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
| 334 | + | |
334 | 335 | | |
335 | 336 | | |
336 | 337 | | |
| |||
347 | 348 | | |
348 | 349 | | |
349 | 350 | | |
350 | | - | |
| 351 | + | |
351 | 352 | | |
352 | 353 | | |
353 | 354 | | |
| |||
395 | 396 | | |
396 | 397 | | |
397 | 398 | | |
398 | | - | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
399 | 436 | | |
400 | 437 | | |
401 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments