rust/tests
Matthias Krüger 44d6d86ccb
Rollup merge of #135602 - estebank:issue-135589, r=Nadrieril
Tweak output of missing lifetime on associated type

Each commit can be reviewed independently. Address parts of #135589.

---

When an associated type is missing a lifetime, point at its enclosing `impl`, whether it has or doesn't have lifetimes defined. If it does have a lifetime, suggest using it.

```
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $DIR/missing-lifetime-in-assoc-type-1.rs:8:17
   |
LL | impl<'a> IntoIterator for &S {
   |     ---- there is a named lifetime specified on the impl block you could use
...
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
   |
help: consider using the lifetime from the impl block
   |
LL |     type Item = &'a T;
   |                  ++
```

```
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
   |
LL | impl IntoIterator for &S {
   |     - you could add a lifetime on the impl block, if the trait or the self type can have one
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
```

---

On unconstrained lifetime on impl block, suggest using it if there's an implicit borrow in the self type
```
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
  --> $DIR/missing-lifetime-in-assoc-type-1.rs:4:6
   |
LL | impl<'a> IntoIterator for &S {
   |      ^^ unconstrained lifetime parameter
   |
help: consider using the named lifetime here instead of an implict lifetime
   |
LL | impl<'a> IntoIterator for &'a S {
   |                            ++
```

---

Do not suggest introducing lifetime in impl assoc type

---

Previously we only showed the trait's assoc item if the trait was local, because we were looking for a small span only for the generics, which we don't have for foreign traits. We now use `def_span` for the item, so we at least provide some context, even if its span is too wide.

```
error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
   --> tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs:7:18
    |
7   |     type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
    |                  ^^^^ lifetimes do not match type in trait
    |
   ::: /home/gh-estebank/rust/library/core/src/iter/traits/collect.rs:292:5
    |
292 |     type IntoIter: Iterator<Item = Self::Item>;
    |     ------------------------------------------ lifetimes in impl do not match this type in trait
```
2025-11-01 08:25:43 +01:00
..
assembly-llvm Add riscv64gc-unknown-redox 2025-10-29 13:15:12 +00:00
auxiliary Add test for addrspacecasting global vars 2025-09-03 08:40:51 +02:00
codegen-llvm Move wasm throw intrinsic back to unwind 2025-10-30 15:13:32 +03:00
codegen-units pub async fn implementation coroutine (func::{closure#0}) is monomorphized, when func itself is monomorphized 2025-09-01 13:45:00 +07:00
coverage Add coverage scope for controlling paths in code coverage 2025-10-27 12:54:24 +01:00
coverage-run-rustdoc
crashes add crashes tests for overlapping spans 2025-10-23 22:15:34 +00:00
debuginfo Re-enable macro-stepping test for AArch64 2025-10-27 10:26:57 +00:00
incremental Add a fast path for lowering trivial consts 2025-10-25 16:59:53 -04:00
mir-opt Auto merge of #147083 - dianne:non-extended-indices, r=matthewjasper 2025-10-28 03:02:00 +00:00
pretty Remove QPath::LangItem from ranges 2025-10-27 21:19:38 -05:00
run-make Rollup merge of #148115 - fmease:rustdoc-no-capture, r=notriddle 2025-10-30 02:43:43 -04:00
run-make-cargo Skip the panic-immediate-abort-works test when cross-compiling 2025-09-22 21:13:38 -04:00
rustdoc Move rustdoc tests to appropriate subdirectories 2025-10-26 19:16:41 -07:00
rustdoc-gui rustdoc-search: add test case for throbber 2025-10-07 12:59:58 -07:00
rustdoc-js rustdoc-search: add an integration test for CCI 2025-10-27 11:57:32 -07:00
rustdoc-js-std Add regression test for including derive macros in macro filtering 2025-10-27 16:00:32 +01:00
rustdoc-json Add tests for doc(attribute = "...") attribute 2025-08-28 15:56:30 +02:00
rustdoc-ui Rollup merge of #148115 - fmease:rustdoc-no-capture, r=notriddle 2025-10-30 02:43:43 -04:00
ui Rollup merge of #135602 - estebank:issue-135589, r=Nadrieril 2025-11-01 08:25:43 +01:00
ui-fulldeps Replace NullOp::SizeOf and NullOp::AlignOf by lang items. 2025-10-23 00:38:28 +00:00
COMPILER_TESTS.md