Skip to content

When passing too many lifetimes to a struct, there are tons of unrelated errors about needing explicit lifetime annotations #125604

Description

@RalfJung

To reproduce, check out commit cdc509f of rustc and then edit this line:

dcx: &mut DiagnosticCx<'_, '_, '_, 'tcx>,

Specifically, add another '_, before the 'tcx. Then run ./x.py check miri. This results in some surprising errors:

error[E0107]: struct takes 4 lifetime arguments but 5 lifetime arguments were supplied
   --> src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs:278:19
    |
278 |         dcx: &mut DiagnosticCx<'_, '_, '_, '_,'tcx>,
    |                   ^^^^^^^^^^^^                ---- help: remove this lifetime argument
    |                   |
    |                   expected 4 lifetime arguments
    |
note: struct defined here, with 4 lifetime parameters: `'history`, `'ecx`, `'mir`, `'tcx`
   --> src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs:123:12
    |
123 | pub struct DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
    |            ^^^^^^^^^^^^ --------  ----  ----  ----

error[E0621]: explicit lifetime required in the type of `dcx`
   --> src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs:285:13
    |
278 |         dcx: &mut DiagnosticCx<'_, '_, '_, '_,'tcx>,
    |              -------------------------------------- help: add explicit lifetime `'tcx` to the type of `dcx`: `&mut DiagnosticCx<'_, '_, '_, 'tcx>`
...
285 |             self.find_granting(access, tag, exposed_tags).map_err(|()| dcx.access_error(self))?;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'tcx` required

error[E0621]: explicit lifetime required in the type of `dcx`
   --> src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs:305:17
    |
278 |         dcx: &mut DiagnosticCx<'_, '_, '_, '_,'tcx>,
    |              -------------------------------------- help: add explicit lifetime `'tcx` to the type of `dcx`: `&mut DiagnosticCx<'_, 'tcx, '_, '_>`
...
305 |                 dcx.log_invalidation(item.tag());
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'tcx` required

The first error is what I expected, but the other two are not useful: they are referring to an argument type that's not even a valid type, so they should not be shown. When doing refactoring, it can be quite hard to spot the actual errors in this sea of false errors.

So far I have not managed to reproduce this with a smaller example.

Cc @oli-obk is this a consequence of your recent work to keep compiling in more cases?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions