diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-08-03 21:43:17 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-08-04 13:17:39 +0200 |
| commit | 5706be1854db74d0aafcc4658423884689f139e9 (patch) | |
| tree | 5e4a3543de6a955d72ece8459d3e3353a05cc906 /tests | |
| parent | fcf3006e0133365ecd26894689c086387edcbecb (diff) | |
| download | rust-5706be1854db74d0aafcc4658423884689f139e9.tar.gz rust-5706be1854db74d0aafcc4658423884689f139e9.zip | |
Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
Diffstat (limited to 'tests')
21 files changed, 81 insertions, 54 deletions
diff --git a/tests/ui/array-slice-vec/slice-2.stderr b/tests/ui/array-slice-vec/slice-2.stderr index 561feb90f0a..b122b46914c 100644 --- a/tests/ui/array-slice-vec/slice-2.stderr +++ b/tests/ui/array-slice-vec/slice-2.stderr @@ -1,26 +1,26 @@ error[E0608]: cannot index into a value of type `Foo` - --> $DIR/slice-2.rs:7:6 + --> $DIR/slice-2.rs:7:7 | LL | &x[..]; - | ^^^^^ + | ^^^^ error[E0608]: cannot index into a value of type `Foo` - --> $DIR/slice-2.rs:8:6 + --> $DIR/slice-2.rs:8:7 | LL | &x[Foo..]; - | ^^^^^^^^ + | ^^^^^^^ error[E0608]: cannot index into a value of type `Foo` - --> $DIR/slice-2.rs:9:6 + --> $DIR/slice-2.rs:9:7 | LL | &x[..Foo]; - | ^^^^^^^^ + | ^^^^^^^ error[E0608]: cannot index into a value of type `Foo` - --> $DIR/slice-2.rs:10:6 + --> $DIR/slice-2.rs:10:7 | LL | &x[Foo..Foo]; - | ^^^^^^^^^^^ + | ^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/tests/ui/borrowck/suggest-local-var-for-vector.stderr b/tests/ui/borrowck/suggest-local-var-for-vector.stderr index ea92d76b4ec..c8d00f7b222 100644 --- a/tests/ui/borrowck/suggest-local-var-for-vector.stderr +++ b/tests/ui/borrowck/suggest-local-var-for-vector.stderr @@ -3,10 +3,10 @@ error[E0502]: cannot borrow `vec` as immutable because it is also borrowed as mu | LL | vec[vec.len() - 1] = 123; | ----^^^----------- - | | | - | | immutable borrow occurs here + | | || + | | |immutable borrow occurs here + | | mutable borrow later used here | mutable borrow occurs here - | mutable borrow later used here | help: try adding a local storing this... --> $DIR/suggest-local-var-for-vector.rs:3:9 @@ -14,10 +14,10 @@ help: try adding a local storing this... LL | vec[vec.len() - 1] = 123; | ^^^^^^^^^ help: ...and then using that local here - --> $DIR/suggest-local-var-for-vector.rs:3:5 + --> $DIR/suggest-local-var-for-vector.rs:3:8 | LL | vec[vec.len() - 1] = 123; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/borrowck/suggest-storing-local-var-for-vector.stderr b/tests/ui/borrowck/suggest-storing-local-var-for-vector.stderr index 6007beb7753..368d728101c 100644 --- a/tests/ui/borrowck/suggest-storing-local-var-for-vector.stderr +++ b/tests/ui/borrowck/suggest-storing-local-var-for-vector.stderr @@ -3,10 +3,10 @@ error[E0502]: cannot borrow `vec` as immutable because it is also borrowed as mu | LL | vec[vec.len() - 1] = 123; | ----^^^----------- - | | | - | | immutable borrow occurs here + | | || + | | |immutable borrow occurs here + | | mutable borrow later used here | mutable borrow occurs here - | mutable borrow later used here | help: try adding a local storing this... --> $DIR/suggest-storing-local-var-for-vector.rs:3:9 @@ -14,10 +14,10 @@ help: try adding a local storing this... LL | vec[vec.len() - 1] = 123; | ^^^^^^^^^ help: ...and then using that local here - --> $DIR/suggest-storing-local-var-for-vector.rs:3:5 + --> $DIR/suggest-storing-local-var-for-vector.rs:3:8 | LL | vec[vec.len() - 1] = 123; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr b/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr index efd63a08aae..e122977b9f2 100644 --- a/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr +++ b/tests/ui/borrowck/two-phase-nonrecv-autoref.base.stderr @@ -50,42 +50,42 @@ error[E0502]: cannot borrow `i` as immutable because it is also borrowed as muta | LL | i[i[3]] = 4; | --^---- - | | | - | | immutable borrow occurs here + | ||| + | ||immutable borrow occurs here + | |mutable borrow later used here | mutable borrow occurs here - | mutable borrow later used here | help: try adding a local storing this... - --> $DIR/two-phase-nonrecv-autoref.rs:132:7 + --> $DIR/two-phase-nonrecv-autoref.rs:132:8 | LL | i[i[3]] = 4; - | ^^^^ + | ^^^ help: ...and then using that local here - --> $DIR/two-phase-nonrecv-autoref.rs:132:5 + --> $DIR/two-phase-nonrecv-autoref.rs:132:6 | LL | i[i[3]] = 4; - | ^^^^^^^ + | ^^^^^^ error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable --> $DIR/two-phase-nonrecv-autoref.rs:138:7 | LL | i[i[3]] = i[4]; | --^---- - | | | - | | immutable borrow occurs here + | ||| + | ||immutable borrow occurs here + | |mutable borrow later used here | mutable borrow occurs here - | mutable borrow later used here | help: try adding a local storing this... - --> $DIR/two-phase-nonrecv-autoref.rs:138:7 + --> $DIR/two-phase-nonrecv-autoref.rs:138:8 | LL | i[i[3]] = i[4]; - | ^^^^ + | ^^^ help: ...and then using that local here - --> $DIR/two-phase-nonrecv-autoref.rs:138:5 + --> $DIR/two-phase-nonrecv-autoref.rs:138:6 | LL | i[i[3]] = i[4]; - | ^^^^^^^ + | ^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/consts/issue-94675.stderr b/tests/ui/consts/issue-94675.stderr index cee4dfda2c9..f51f305ac38 100644 --- a/tests/ui/consts/issue-94675.stderr +++ b/tests/ui/consts/issue-94675.stderr @@ -7,10 +7,10 @@ LL | self.bar[0] = baz.len(); = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot call non-const operator in constant functions - --> $DIR/issue-94675.rs:11:9 + --> $DIR/issue-94675.rs:11:17 | LL | self.bar[0] = baz.len(); - | ^^^^^^^^^^^ + | ^^^ | note: impl defined here, but it is not `const` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL diff --git a/tests/ui/error-codes/E0608.stderr b/tests/ui/error-codes/E0608.stderr index 3aec509934b..f23f9977ba0 100644 --- a/tests/ui/error-codes/E0608.stderr +++ b/tests/ui/error-codes/E0608.stderr @@ -1,8 +1,8 @@ error[E0608]: cannot index into a value of type `u8` - --> $DIR/E0608.rs:2:5 + --> $DIR/E0608.rs:2:8 | LL | 0u8[2]; - | ^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/tests/ui/index-bot.rs b/tests/ui/indexing/index-bot.rs index e69c4019f61..e69c4019f61 100644 --- a/tests/ui/index-bot.rs +++ b/tests/ui/indexing/index-bot.rs diff --git a/tests/ui/index-bot.stderr b/tests/ui/indexing/index-bot.stderr index b5d78297505..bf231c92cad 100644 --- a/tests/ui/index-bot.stderr +++ b/tests/ui/indexing/index-bot.stderr @@ -1,8 +1,8 @@ error[E0608]: cannot index into a value of type `!` - --> $DIR/index-bot.rs:2:5 + --> $DIR/index-bot.rs:2:13 | LL | (return)[0]; - | ^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/tests/ui/index-help.rs b/tests/ui/indexing/index-help.rs index 66571ec41a0..66571ec41a0 100644 --- a/tests/ui/index-help.rs +++ b/tests/ui/indexing/index-help.rs diff --git a/tests/ui/index-help.stderr b/tests/ui/indexing/index-help.stderr index e020d029875..e020d029875 100644 --- a/tests/ui/index-help.stderr +++ b/tests/ui/indexing/index-help.stderr diff --git a/tests/ui/index_message.rs b/tests/ui/indexing/index_message.rs index 88b848d6f85..88b848d6f85 100644 --- a/tests/ui/index_message.rs +++ b/tests/ui/indexing/index_message.rs diff --git a/tests/ui/index_message.stderr b/tests/ui/indexing/index_message.stderr index 56d1d70809d..80f2bd52314 100644 --- a/tests/ui/index_message.stderr +++ b/tests/ui/indexing/index_message.stderr @@ -1,8 +1,8 @@ error[E0608]: cannot index into a value of type `({integer},)` - --> $DIR/index_message.rs:3:13 + --> $DIR/index_message.rs:3:14 | LL | let _ = z[0]; - | ^^^^ help: to access tuple elements, use: `z.0` + | ^^^ help: to access tuple elements, use: `.0` error: aborting due to previous error diff --git a/tests/ui/indexing-requires-a-uint.rs b/tests/ui/indexing/indexing-requires-a-uint.rs index dbe9b44a138..dbe9b44a138 100644 --- a/tests/ui/indexing-requires-a-uint.rs +++ b/tests/ui/indexing/indexing-requires-a-uint.rs diff --git a/tests/ui/indexing-requires-a-uint.stderr b/tests/ui/indexing/indexing-requires-a-uint.stderr index 7a741cfc7de..7a741cfc7de 100644 --- a/tests/ui/indexing-requires-a-uint.stderr +++ b/tests/ui/indexing/indexing-requires-a-uint.stderr diff --git a/tests/ui/indexing/indexing-spans-caller-location.rs b/tests/ui/indexing/indexing-spans-caller-location.rs new file mode 100644 index 00000000000..2652f00211d --- /dev/null +++ b/tests/ui/indexing/indexing-spans-caller-location.rs @@ -0,0 +1,27 @@ +// run-pass + +// Regression test for https://github.com/rust-lang/rust/issues/114388 + +#[track_caller] +fn caller_line() -> u32 { + std::panic::Location::caller().line() +} + +fn main() { + let prev_line = caller_line(); // first line + (A { prev_line }) // second line + [0]; // third line +} + +struct A { + prev_line: u32, +} +impl std::ops::Index<usize> for A { + type Output = (); + + fn index(&self, _idx: usize) -> &() { + // Use the relative number to make it resistent to header changes. + assert_eq!(caller_line(), self.prev_line + 2); + &() + } +} diff --git a/tests/ui/intrinsics/const-eval-select-backtrace-std.run.stderr b/tests/ui/intrinsics/const-eval-select-backtrace-std.run.stderr index 69c7491b2af..a0024c0920f 100644 --- a/tests/ui/intrinsics/const-eval-select-backtrace-std.run.stderr +++ b/tests/ui/intrinsics/const-eval-select-backtrace-std.run.stderr @@ -1,3 +1,3 @@ -thread 'main' panicked at $DIR/const-eval-select-backtrace-std.rs:6:6: +thread 'main' panicked at $DIR/const-eval-select-backtrace-std.rs:6:8: byte index 1 is out of bounds of `` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/ui/issues/issue-27842.stderr b/tests/ui/issues/issue-27842.stderr index 83333aa0c47..b18fe1512b5 100644 --- a/tests/ui/issues/issue-27842.stderr +++ b/tests/ui/issues/issue-27842.stderr @@ -1,24 +1,24 @@ error[E0608]: cannot index into a value of type `({integer}, {integer}, {integer})` - --> $DIR/issue-27842.rs:4:13 + --> $DIR/issue-27842.rs:4:16 | LL | let _ = tup[0]; - | ^^^^^^ help: to access tuple elements, use: `tup.0` + | ^^^ help: to access tuple elements, use: `.0` error[E0608]: cannot index into a value of type `({integer}, {integer}, {integer})` - --> $DIR/issue-27842.rs:9:13 + --> $DIR/issue-27842.rs:9:16 | LL | let _ = tup[i]; - | ^^^^-^ + | ^-^ | | | cannot access tuple elements at a variable index | = help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`) error[E0608]: cannot index into a value of type `({integer},)` - --> $DIR/issue-27842.rs:14:13 + --> $DIR/issue-27842.rs:14:16 | LL | let _ = tup[3]; - | ^^^^^^ + | ^^^ | = help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`) diff --git a/tests/ui/issues/issue-40861.stderr b/tests/ui/issues/issue-40861.stderr index 84e38b9bb05..9b6469d05e9 100644 --- a/tests/ui/issues/issue-40861.stderr +++ b/tests/ui/issues/issue-40861.stderr @@ -1,8 +1,8 @@ error[E0608]: cannot index into a value of type `()` - --> $DIR/issue-40861.rs:4:5 + --> $DIR/issue-40861.rs:4:7 | LL | ()[f(&[1.0])]; - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^ | = help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`) diff --git a/tests/ui/lint/lint-unconditional-recursion.stderr b/tests/ui/lint/lint-unconditional-recursion.stderr index 9d200a7898e..d75754bf9f9 100644 --- a/tests/ui/lint/lint-unconditional-recursion.stderr +++ b/tests/ui/lint/lint-unconditional-recursion.stderr @@ -139,7 +139,7 @@ error: function cannot return without recursing LL | fn index(&self, x: usize) -> &Baz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing LL | &self[x] - | ------- recursive call site + | --- recursive call site | = help: a `loop` may express intention better if this is on purpose diff --git a/tests/ui/span/suggestion-non-ascii.stderr b/tests/ui/span/suggestion-non-ascii.stderr index b14632d4e1b..21f8bb62a0c 100644 --- a/tests/ui/span/suggestion-non-ascii.stderr +++ b/tests/ui/span/suggestion-non-ascii.stderr @@ -1,8 +1,8 @@ error[E0608]: cannot index into a value of type `({integer},)` - --> $DIR/suggestion-non-ascii.rs:3:21 + --> $DIR/suggestion-non-ascii.rs:3:24 | LL | println!("☃{}", tup[0]); - | ^^^^^^ help: to access tuple elements, use: `tup.0` + | ^^^ help: to access tuple elements, use: `.0` error: aborting due to previous error diff --git a/tests/ui/typeck/issue-112252-ptr-arithmetics-help.stderr b/tests/ui/typeck/issue-112252-ptr-arithmetics-help.stderr index c55930da225..f81736245f3 100644 --- a/tests/ui/typeck/issue-112252-ptr-arithmetics-help.stderr +++ b/tests/ui/typeck/issue-112252-ptr-arithmetics-help.stderr @@ -38,10 +38,10 @@ LL | let _c = unsafe { _ptr2.offset_from(_ptr1) }; | ++++++++ ~~~~~~~~~~~~~ +++ error[E0608]: cannot index into a value of type `*const u32` - --> $DIR/issue-112252-ptr-arithmetics-help.rs:9:14 + --> $DIR/issue-112252-ptr-arithmetics-help.rs:9:19 | LL | let _d = _ptr1[5]; - | ^^^^^^^^ + | ^^^ | help: consider using `wrapping_add` or `add` for indexing into raw pointer | |
