rust/compiler
Matthias Krüger 37c9478b1a
Rollup merge of #111761 - bvanjoi:fix-109148, r=petrochenkov
fix(resolve): not defined `extern crate shadow_name`

Fixes https://github.com/rust-lang/rust/issues/109148

## Why does #109148 panic?

When resolving `use std::xx` it enters `visit_scopes` from `early_resolve_ident_in_lexical_scope`, and iters twice during the loop:

|iter| `scope` | `break_result` | result |
|-|-|-|-|
| 0 | `Module` pointed to root | binding pointed to `Undetermined`, so result is `None` | scope changed to `ExternPrelude` |
| 1 | `ExternPrelude` | binding pointed to `std` | - |

Then, the result of `maybe_resolve_path` is `Module(std)`, so `import.imported_module.set` is executed.

Finally, during the `finalize_import` of `use std::xx`, `resolve_path` returns `NonModule` because `Binding(Ident(std), Module(root)`'s binding points to `extern crate blah as std`, which causes the assertion to fail at `assert!(import.imported_module.get().is_none());`.

## Investigation

The question is why `#[a] extern crate blah as std` is not defined as a binding of `std::xxx`, which causes the iteration twice during `visit_scopes` when resolving `std::xxx`. Ideally, the value of `break_result.is_some()` should have been valid in the first iteration.

After debugging, I found that because `#[a] extern crate blah as std` had been dummied by `placeholder` during `collect_invocations`, so it had lost its attrs, span, etc..., so it will not be defined. However, `expand_invoc` added them back, then the next `build_reduced_graph`, `#[a] extern crate blah as std` would have been defined, so it makes the result of `resolved_path` unexpected, and the program panics.

## Try to solve

I think there has two-way to solve this issue:

- Expand invocations before the first `resolve_imports` during `fully_expand_fragment`. However, I do not think this is a good idea because it would mess up the current design.
- As my PR described: do not define to `extern crate blah as std` during the second `build_reduced_graph`, which is very easy and more reasonable.

r? `@petrochenkov`
2023-05-23 19:53:42 +02:00
..
rustc fix link 2023-03-11 10:53:47 -06:00
rustc_abi Avoid &format("...") calls in error message code. 2023-05-16 17:59:56 +10:00
rustc_apfloat compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_arena Deny the unsafe_op_in_unsafe_fn lint in 2023-04-28 21:00:54 -07:00
rustc_ast refactor: add chunks method to TokenStream to obviate rustdoc clones 2023-05-13 16:59:28 -05:00
rustc_ast_lowering Turn debugger_visualizers from feed- into regular query. 2023-05-16 18:50:36 +02:00
rustc_ast_passes Add feature gate 2023-05-05 21:44:48 +02:00
rustc_ast_pretty Migrate offset_of from a macro to builtin # syntax 2023-05-05 21:44:13 +02:00
rustc_attr Only depend on CFG_VERSION in rustc_interface 2023-05-17 23:54:21 -05:00
rustc_baked_icu_data Regen baked data 2023-05-02 10:45:16 -07:00
rustc_borrowck Check opaques for mismatch during writeback 2023-05-22 23:33:34 +00:00
rustc_builtin_macros Rollup merge of #111054 - cjgillot:cfg-eval-recover, r=b-naber 2023-05-18 17:37:08 +05:30
rustc_codegen_cranelift Rollup merge of #111633 - nnethercote:avoid-ref-format, r=WaffleLapkin 2023-05-18 10:52:35 +05:30
rustc_codegen_gcc Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
rustc_codegen_llvm Auto merge of #111413 - workingjubilee:bump-object-0-31-1, r=MarkSimulacrum 2023-05-20 13:19:37 +00:00
rustc_codegen_ssa Auto merge of #111675 - Urgau:fix-local-libs-for-native-static-libs, r=bjorn3 2023-05-21 01:12:45 +00:00
rustc_const_eval Rollup merge of #111486 - fmease:pp-inh-proj, r=petrochenkov 2023-05-23 19:53:41 +02:00
rustc_data_structures Auto merge of #111596 - cjgillot:dominator-bucket, r=Mark-Simulacrum 2023-05-20 07:41:15 +00:00
rustc_driver Remove unneeded extern crate 2023-02-02 07:47:39 +01:00
rustc_driver_impl Rollup merge of #111606 - jyn514:nightly-diagnostics, r=lcnr 2023-05-20 12:20:59 +05:30
rustc_error_codes Rollup merge of #111215 - BoxyUwU:resolve_anon_consts_differently, r=cjgillot 2023-05-09 20:49:32 +02:00
rustc_error_messages correct literals for dyn thread safe 2023-05-06 09:34:53 +08:00
rustc_errors Check opaques for mismatch during writeback 2023-05-22 23:33:34 +00:00
rustc_expand fix: emit error when fragment is MethodReceiverExpr and items is empty 2023-05-19 21:21:05 +08:00
rustc_feature fixup version placeholder for cfi_encoding feature 2023-05-15 19:19:13 +03:00
rustc_fluent_macro Remove unused synstructure dep 2023-04-22 22:03:33 +01:00
rustc_fs_util Add try_canonicalize to rustc_fs_util and use it over fs::canonicalize 2023-03-16 21:50:23 +01:00
rustc_graphviz enable rust_2018_idioms for doctests 2023-05-07 00:12:29 +03:00
rustc_hir Auto merge of #111345 - jyn514:cfg-release-caching, r=cjgillot,est31 2023-05-18 21:45:02 +00:00
rustc_hir_analysis Rollup merge of #111853 - compiler-errors:opaque-check, r=oli-obk 2023-05-23 16:44:28 +05:30
rustc_hir_pretty Rip it out 2023-05-01 16:15:13 +08:00
rustc_hir_typeck Rollup merge of #111860 - compiler-errors:issue-111838, r=WaffleLapkin 2023-05-23 16:44:29 +05:30
rustc_incremental Only depend on CFG_VERSION in rustc_interface 2023-05-17 23:54:21 -05:00
rustc_index Decorative changes to IndexVec 2023-04-24 13:53:37 +00:00
rustc_infer Rollup merge of #111450 - compiler-errors:opaque-ty-key, r=oli-obk 2023-05-20 15:37:23 +02:00
rustc_interface Auto merge of #111641 - michaelwoerister:debugger-visualizer-fixes, r=cjgillot 2023-05-19 11:30:44 +00:00
rustc_lexer Don't try to eat non-existent decimal digits. 2023-05-15 18:33:12 +10:00
rustc_lint Rename forget_ref lint to forgetting_references 2023-05-21 14:28:09 +02:00
rustc_lint_defs Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum 2023-05-08 04:50:28 +00:00
rustc_llvm Auto merge of #111364 - cuviper:unhack-thinlto, r=nikic 2023-05-18 01:35:41 +00:00
rustc_log Stabilize IsTerminal 2023-04-10 17:24:23 +09:00
rustc_macros Merge query property modules into one 2023-05-18 09:45:12 +02:00
rustc_metadata Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic 2023-05-23 07:37:16 +00:00
rustc_middle Rollup merge of #111486 - fmease:pp-inh-proj, r=petrochenkov 2023-05-23 19:53:41 +02:00
rustc_mir_build Rollup merge of #111579 - scottmcm:enum-as-signed, r=oli-obk 2023-05-23 16:44:27 +05:30
rustc_mir_dataflow Rollup merge of #110930 - b-naber:normalize-elaborate-drops, r=cjgillot 2023-05-17 19:11:53 +05:30
rustc_mir_transform Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obk 2023-05-23 00:32:17 +05:30
rustc_monomorphize Improve CGU partitioning debug output. 2023-05-19 08:48:28 +10:00
rustc_parse Rollup merge of #111708 - jyn514:delay-span-bug-msg, r=compiler-errors 2023-05-20 12:21:00 +05:30
rustc_parse_format Fix typos in compiler 2023-04-10 22:02:52 +02:00
rustc_passes Don't sort output of debugger_visualizer query because it already is in deterministic order. 2023-05-17 16:02:22 +02:00
rustc_plugin_impl Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
rustc_privacy Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
rustc_query_impl Add comment 2023-05-21 11:25:07 +02:00
rustc_query_system Delay a bug when overwriting fed value. 2023-05-17 20:42:03 +00:00
rustc_resolve fix(resolve): not defined extern crate shadow_name 2023-05-23 13:14:34 +08:00
rustc_serialize Fix the FileEncoder buffer size. 2023-05-15 08:59:11 +10:00
rustc_session Rollup merge of #111606 - jyn514:nightly-diagnostics, r=lcnr 2023-05-20 12:20:59 +05:30
rustc_smir Encode types in SMIR 2023-05-08 14:23:19 +00:00
rustc_span Auto merge of #111641 - michaelwoerister:debugger-visualizer-fixes, r=cjgillot 2023-05-19 11:30:44 +00:00
rustc_symbol_mangling Rollup merge of #111486 - fmease:pp-inh-proj, r=petrochenkov 2023-05-23 19:53:41 +02:00
rustc_target asm: loongarch64: Drop efiapi 2023-05-12 17:22:47 +08:00
rustc_trait_selection Rollup merge of #111704 - compiler-errors:sized-return-cleanup, r=oli-obk 2023-05-23 16:44:27 +05:30
rustc_traits Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
rustc_transmute Remove unused TypeFoldable/TypeVisitable impls. 2023-04-26 15:19:50 +10:00
rustc_ty_utils ensure !Unpin types do not get noalias 2023-05-20 19:34:31 -04:00
rustc_type_ir Implement references VarDebugInfo. 2023-05-13 10:12:14 +00:00