-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
We generally emit an additional error if a trait object lifetime bound defaults to an unresolved lifetime in item signatures #152014
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
If we fail to deduce a trait object lifetime default in an item signature1 we generally emit an error for that. More specifically, we generally do that if
TyCtxt::named_bound_varreturnsNone. For context,named_bound_varactually returnsNoneiff RBV didn't register a mapping from a givenhir::Lifetimeto aResolvedArg. Now, since RBV doesn't actually map unresolved lifetimes toResolvedArg::Error, we ultimately emit two errors in certain cases (1st: unresolved lifetime, 2nd: indeterminate trait object lifetime bound).I'm not super familiar with the early resolution of lifetimes. Therefore, I don't know if we map unresolved lifetimes to
LifetimeRes::Errorinrustc_resolveor not (I have a hunch we don't (possibly a remnant of the now removed feature inband lifetimes?)). In any case, ideally we would map unresolved lifetimes toResolvedArg::Error(_)in RBV which would automatically suppress the "indeterminate trait object lifetime bound" error.Between AST lowering, name resolution and HIR ty lowering, we have
LifetimeRes::Error,hir::LifetimeKind::Error,ResolvedArg::Error(ErrorGuaranteed)&ty::RegionKind::Error(ErrorGuaranteed)but none or only some are actually used for unresolved lifetimes IINM (they're mainly used for other early lifetime issues). Ideally, we'd use these for unresolved lifetimes, too, I guess (for that, ideallyLifetimeResandLifetimeKind::Errorwould carry anErrorGuaranteed).I've used the word "generally" a few times above, that's because in the special case of
&'undefined dyn Trait(i.e., trait object type passed to a reference type constructor), we manually suppress the follow-up error. However, if we were to implement the scheme I'm describing above that would become unnecessary allowing us to remove this minor hack in HIR ty lowering:rust/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs
Lines 454 to 464 in f60a0f1
Example Reproducer
Footnotes
aka item ctxt aka non-body ↩