Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4305769
Tweak handling of "struct like start" where a struct isn't supported
estebank Sep 24, 2025
a4e87e9
Support `#[rustc_align_static]` inside `thread_local!`
Jules-Bertholet Sep 10, 2025
bb48c16
Simplify logic slightly
estebank Sep 24, 2025
4d32b9a
Hoist non-platform-specific code out of `thread_local_inner!`
Jules-Bertholet Sep 27, 2025
86f2d42
indexing: reword help
hkBst Sep 15, 2025
5b809b3
Don't enable shared memory with Wasm atomics
daxpedda Oct 1, 2025
8dfea22
implement `Box::take`
edwloef Oct 1, 2025
6961953
Switch `citool` to 2024 edition
GuillaumeGomez Oct 1, 2025
4baf920
Initialize llvm submodule if not already the case to run citool
GuillaumeGomez Oct 1, 2025
3e8ce2b
Adjust WASI and WALI targets
daxpedda Oct 1, 2025
94f00f4
Fix memory leak in `os` impl
Jules-Bertholet Oct 1, 2025
5991c87
Update books
rustbot Oct 1, 2025
30d57ab
mbe: Rename a local variable to match corresponding field names
joshtriplett Sep 14, 2025
6bff1ab
mbe: Support `unsafe` attribute rules
joshtriplett Sep 14, 2025
05c5b87
mbe: Add parsing tests for `unsafe` macro rules
joshtriplett Sep 14, 2025
ea0e00c
mbe: Add tests for `unsafe` attr invocation
joshtriplett Sep 14, 2025
4fc0a0d
mbe: `expand_invoc`: Add comment about not needing to check safety of…
joshtriplett Sep 28, 2025
59c4dfe
Forbid `//@ compile-flags: -Cincremental=` in tests
Zalathar Oct 1, 2025
92aac1b
Rollup merge of #146281 - Jules-Bertholet:static-align-thread-local, …
matthiaskrgr Oct 2, 2025
ac7beab
Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov
matthiaskrgr Oct 2, 2025
7320d3e
Rollup merge of #146585 - hkBst:indexing-1, r=jdonszelmann
matthiaskrgr Oct 2, 2025
e041b2c
Rollup merge of #147004 - estebank:ascription-in-pat, r=fee1-dead
matthiaskrgr Oct 2, 2025
b78b107
Rollup merge of #147221 - Zalathar:incremental, r=lqd
matthiaskrgr Oct 2, 2025
8a18176
Rollup merge of #147225 - daxpedda:wasm-u-u-atomics-threads, r=alexcr…
matthiaskrgr Oct 2, 2025
fbe6834
Rollup merge of #147227 - edwloef:box_take, r=joboet
matthiaskrgr Oct 2, 2025
f4dcfa6
Rollup merge of #147233 - GuillaumeGomez:citool-submodule-init, r=Kobzol
matthiaskrgr Oct 2, 2025
2d1efe7
Rollup merge of #147236 - rustbot:docs-update, r=ehuss
matthiaskrgr Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0608.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
An attempt to use index on a type which doesn't implement the `std::ops::Index`
trait was performed.
Attempted to index a value whose type doesn't implement the
`std::ops::Index` trait.

Erroneous code example:

```compile_fail,E0608
0u8[2]; // error: cannot index into a value of type `u8`
```

To be able to index into a type it needs to implement the `std::ops::Index`
trait. Example:
Only values with types that implement the `std::ops::Index` trait
can be indexed with square brackets. Example:

```
let v: Vec<u8> = vec![0, 1, 2, 3];

// The `Vec` type implements the `Index` trait so you can do:
println!("{}", v[2]);
```

Tuples and structs are indexed with dot (`.`), not with brackets (`[]`),
and tuple element names are their positions:
```ignore(pseudo code)
// this (pseudo code) expression is true for any tuple:
tuple == (tuple.0, tuple.1, ...)
```
27 changes: 6 additions & 21 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3551,35 +3551,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
// Try to give some advice about indexing tuples.
if let ty::Tuple(types) = base_t.kind() {
let mut needs_note = true;
// If the index is an integer, we can show the actual
// fixed expression:
err.help(
"tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.",
);
// If index is an unsuffixed integer, show the fixed expression:
if let ExprKind::Lit(lit) = idx.kind
&& let ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) = lit.node
&& i.get()
< types
.len()
.try_into()
.expect("expected tuple index to be < usize length")
&& i.get() < types.len().try_into().expect("tuple length fits in u128")
{
err.span_suggestion(
brackets_span,
"to access tuple elements, use",
format!("to access tuple element `{i}`, use"),
format!(".{i}"),
Applicability::MachineApplicable,
);
needs_note = false;
} else if let ExprKind::Path(..) = idx.peel_borrows().kind {
err.span_label(
idx.span,
"cannot access tuple elements at a variable index",
);
}
if needs_note {
err.help(
"to access tuple elements, use tuple indexing \
syntax (e.g., `tuple.0`)",
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/indexing/index_message.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0608]: cannot index into a value of type `({integer},)`
--> $DIR/index_message.rs:3:14
|
LL | let _ = z[0];
| ^^^ help: to access tuple elements, use: `.0`
| ^^^ help: to access tuple element `0`, use: `.0`
|
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error: aborting due to 1 previous error

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/issues/issue-27842.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ error[E0608]: cannot index into a value of type `({integer}, {integer}, {integer
--> $DIR/issue-27842.rs:4:16
|
LL | let _ = tup[0];
| ^^^ help: to access tuple elements, use: `.0`
| ^^^ help: to access tuple element `0`, use: `.0`
|
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error[E0608]: cannot index into a value of type `({integer}, {integer}, {integer})`
--> $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`)
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error[E0608]: cannot index into a value of type `({integer},)`
--> $DIR/issue-27842.rs:14:16
|
LL | let _ = tup[3];
| ^^^
|
= help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`)
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error: aborting due to 3 previous errors

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/span/suggestion-non-ascii.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0608]: cannot index into a value of type `({integer},)`
--> $DIR/suggestion-non-ascii.rs:3:24
|
LL | println!("☃{}", tup[0]);
| ^^^ help: to access tuple elements, use: `.0`
| ^^^ help: to access tuple element `0`, use: `.0`
|
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0608]: cannot index into a value of type `()`
LL | ()[f(&[1.0])];
| ^^^^^^^^^^^
|
= help: to access tuple elements, use tuple indexing syntax (e.g., `tuple.0`)
= help: tuples are indexed with a dot and a literal index: `tuple.0`, `tuple.1`, etc.

error: aborting due to 1 previous error

Expand Down