rust/compiler
bors c94cb834d0 Auto merge of #112500 - lukas-code:span-ctxt, r=petrochenkov
Fix argument removal suggestion around macros

Fixes #112437.
Fixes #113866.
Helps with #114255.

The issue was that `span.find_ancestor_inside(outer)` could previously return a span with a different expansion context from `outer`.

This happens for example for the built-in macro `panic!`, which expands to another macro call of `panic_2021!` or `panic_2015!`. Because the call site of `panic_20xx!` has not associated source code, its span currently points to the call site of `panic!` instead.

Something similar also happens items that get desugared in AST->HIR lowering. For example, `for` loops get two spans: One "inner" span that has the `.desugaring_kind()` kind set to `DesugaringKind::ForLoop` and one "outer" span that does not. Similar to the macro situation, both of these spans point to the same source code, but have different expansion contexts.

This causes problems, because joining two spans with different expansion contexts will usually[^1] not actually join them together to avoid creating "spaghetti" spans that go from the macro definition to the macro call. For example, in the following snippet `full_span` might not actually contain the `adjusted_start` and `adjusted_end`. This caused the broken suggestion / debug ICE in the linked issues.
```rust
let adjusted_start = start.find_ancestor_inside(shared_ancestor);
let adjusted_end = end.find_ancestor_inside(shared_ancestor);
let full_span = adjusted_start.to(adjusted_end)
```

To fix the issue, this PR introduces a new method, `find_ancestor_inside_same_ctxt`, which combines the functionality of `find_ancestor_inside` and `find_ancestor_in_same_ctxt`: It finds an ancestor span that is contained within the parent *and* has the same syntax context, and is therefore safe to extend. This new method should probably be used everywhere, where the returned span is extended, but for now it is just used for the argument removal suggestion.

Additionally, this PR fixes a second issue where the function call itself is inside a macro but the arguments come from outside the macro. The test is added in the first commit to include stderr diff, so this is best reviewed commit by commit.

[^1]: If one expansion context is the root context and the other is not.
2023-08-16 14:47:01 +00:00
..
rustc
rustc_abi
rustc_arena
rustc_ast Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk 2023-08-08 19:23:41 +00:00
rustc_ast_lowering Move scrutinee HirId into MatchSource::TryDesugar 2023-08-14 21:43:56 +00:00
rustc_ast_passes rustc: Move features from Session to GlobalCtxt 2023-08-11 16:51:50 +08:00
rustc_ast_pretty
rustc_attr rustc: Move features from Session to GlobalCtxt 2023-08-11 16:51:50 +08:00
rustc_baked_icu_data
rustc_borrowck review 2023-08-14 15:27:14 +02:00
rustc_builtin_macros rustc: Move features from Session to GlobalCtxt 2023-08-11 16:51:50 +08:00
rustc_codegen_cranelift reverse change in rustc_codegen_cranelift 2023-08-15 00:09:20 +08:00
rustc_codegen_gcc Auto merge of #114467 - Amanieu:asm-unstable-features, r=davidtwco 2023-08-15 11:59:02 +00:00
rustc_codegen_llvm Auto merge of #114467 - Amanieu:asm-unstable-features, r=davidtwco 2023-08-15 11:59:02 +00:00
rustc_codegen_ssa Rollup merge of #114711 - lqd:linker-inference, r=petrochenkov 2023-08-15 14:29:45 +02:00
rustc_const_eval Remove constness from ImplSource::Param 2023-08-14 02:17:30 +00:00
rustc_data_structures Auto merge of #114339 - ttsugriy:unsafe-utf8, r=davidtwco 2023-08-08 10:25:37 +00:00
rustc_driver
rustc_driver_impl rustc: Move crate_types from Session to GlobalCtxt 2023-08-09 14:17:54 +08:00
rustc_error_codes
rustc_error_messages
rustc_errors
rustc_expand rustc: Move features from Session to GlobalCtxt 2023-08-11 16:51:50 +08:00
rustc_feature Update compiler/rustc_feature/src/active.rs 2023-08-15 02:13:17 +08:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Move scrutinee HirId into MatchSource::TryDesugar 2023-08-14 21:43:56 +00:00
rustc_hir_analysis Rollup merge of #114746 - compiler-errors:atb-no-const, r=TaKO8Ki 2023-08-16 08:43:50 +02:00
rustc_hir_pretty Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk 2023-08-08 19:23:41 +00:00
rustc_hir_typeck Auto merge of #112500 - lukas-code:span-ctxt, r=petrochenkov 2023-08-16 14:47:01 +00:00
rustc_incremental Pass WorkProductMap to build_dep_graph instead of FxIndexMap 2023-08-13 16:07:48 +00:00
rustc_index
rustc_infer Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors 2023-08-15 20:34:25 +02:00
rustc_interface Fix review comment 2023-08-14 16:16:51 +00:00
rustc_lexer
rustc_lint Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naber 2023-08-15 14:29:45 +02:00
rustc_lint_defs more nits 2023-08-15 03:44:21 +00:00
rustc_llvm add a csky-unknown-linux-gnuabiv2 target 2023-08-14 23:02:36 +08:00
rustc_log
rustc_macros
rustc_metadata Remove metadata_loader query 2023-08-13 16:38:50 +00:00
rustc_middle Auto merge of #114536 - cjgillot:eval-lint-levels, r=TaKO8Ki 2023-08-16 04:26:12 +00:00
rustc_mir_build Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors 2023-08-15 20:34:25 +02:00
rustc_mir_dataflow Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung 2023-08-06 17:26:29 +02:00
rustc_mir_transform Store BCB counters externally, not directly in the BCB graph 2023-08-13 12:18:06 +10:00
rustc_monomorphize Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
rustc_parse Remove reached_eof from ParseSess 2023-08-13 13:33:37 +00:00
rustc_parse_format
rustc_passes Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors 2023-08-15 20:34:25 +02:00
rustc_plugin_impl
rustc_privacy Use {Local}ModDefId in many queries 2023-08-14 07:22:48 +00:00
rustc_query_impl
rustc_query_system Pass WorkProductMap to build_dep_graph instead of FxIndexMap 2023-08-13 16:07:48 +00:00
rustc_resolve rustc: Move features from Session to GlobalCtxt 2023-08-11 16:51:50 +08:00
rustc_serialize
rustc_session Remove reached_eof from ParseSess 2023-08-13 13:33:37 +00:00
rustc_smir Rollup merge of #114859 - spastorino:add-smir-cx-trait-fns, r=compiler-errors 2023-08-16 08:43:52 +02:00
rustc_span Auto merge of #112500 - lukas-code:span-ctxt, r=petrochenkov 2023-08-16 14:47:01 +00:00
rustc_symbol_mangling Auto merge of #114672 - lenawanel:master, r=compiler-errors 2023-08-11 09:30:41 +00:00
rustc_target Rollup merge of #114711 - lqd:linker-inference, r=petrochenkov 2023-08-15 14:29:45 +02:00
rustc_trait_selection Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors 2023-08-15 20:34:25 +02:00
rustc_traits
rustc_transmute
rustc_ty_utils Rollup merge of #114670 - compiler-errors:issue-114660, r=cjgillot 2023-08-09 23:00:00 +02:00
rustc_type_ir Comment nits 2023-08-10 23:22:03 +00:00