1
Fork 0
rust/compiler/rustc_span/src
Matthias Krüger ca28e9554f
Rollup merge of #123654 - jieyouxu:question-mark-span, r=Nadrieril
typeck: fix `?` suggestion span

Noticed in <https://github.com/rust-lang/rust/pull/112043#issuecomment-2043565292>, if the

```
use the `?` operator to extract the `Result<(), std::fmt::Error>` value, propagating a `Result::Err` value to the caller
```

suggestion is applied to a macro that comes from a non-local crate (e.g. the stdlib), the suggestion span can become non-local, which will cause newer rustfix versions to fail.

This PR tries to remedy the problem by recursively probing ancestors of the expression span, trying to identify the most ancestor span that is (1) still local, and (2) still shares the same syntax context as the expression.

This is the same strategy used in https://github.com/rust-lang/rust/pull/112043.

The test unfortunately cannot `//@ run-rustfix` because there are two conflicting MaybeIncorrect suggestions that when collectively applied, cause the fixed source file to become non-compilable.

Also avoid running `//@ run-rustfix` for `tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.rs` because that also contains conflicting suggestions.

cc `@ehuss` who noticed this. This question mark span fix + not running rustfix on the tests containing conflicting MaybeIncorrect suggestions should hopefully unblock rustfix from updating.
2024-04-12 21:46:57 +02:00
..
analyze_source_file Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
edit_distance Add test for precise algorithm used 2023-02-19 22:59:22 +00:00
source_map rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
symbol Use FxIndexSet in the symbol interner. 2023-11-03 07:19:41 +11:00
analyze_source_file.rs Initiate the inner usage of cfg_match 2023-10-19 20:18:51 -03:00
caching_source_map_view.rs Add better ICE messages for some undescriptive panics 2023-12-15 00:50:55 -05:00
def_id.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
edit_distance.rs check rust lints when an unknown lint is detected 2024-01-12 18:50:36 +08:00
edition.rs Remove edition umbrella features. 2023-12-10 13:03:28 -08:00
fatal_error.rs Auto merge of #117557 - Zoxc:panic-prio, r=petrochenkov 2023-11-09 00:39:02 +00:00
hygiene.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
lib.rs typeck: fix ? operator suggestion span 2024-04-10 19:37:48 +00:00
profiling.rs Remove an unnecessary use of with_session_globals. 2023-03-31 15:34:00 +11:00
source_map.rs Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix 2024-04-12 17:41:32 +02:00
span_encoding.rs rustc_span: Optimize syntax context comparisons 2024-01-06 01:25:20 +03:00
symbol.rs Add pattern types to parser 2024-04-08 11:57:17 +00:00
tests.rs Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00