Rollup merge of #125258 - compiler-errors:static-if-no-lt, r=nnethercote
Resolve elided lifetimes in assoc const to static if no other lifetimes are in scope Implements the change to elided lifetime resolution in *associated consts* subject to FCP here: https://github.com/rust-lang/rust/issues/125190#issue-2301532282 Specifically, walk the enclosing lifetime ribs in an associated const, and if we find no other lifetimes, then resolve to `'static`. Also make it work for traits, but don't lint -- just give a hard error in that case.
This commit is contained in:
commit
23b936f981
21 changed files with 385 additions and 209 deletions
|
@ -14,6 +14,7 @@ lint_associated_const_elided_lifetime = {$elided ->
|
|||
*[false] `'_` cannot be used here
|
||||
}
|
||||
.suggestion = use the `'static` lifetime
|
||||
.note = cannot automatically infer `'static` because of other lifetimes in scope
|
||||
|
||||
lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
|
||||
.note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`
|
||||
|
|
|
@ -319,11 +319,20 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
|
|||
BuiltinLintDiag::UnusedQualifications { removal_span } => {
|
||||
lints::UnusedQualifications { removal_span }.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span: lt_span } => {
|
||||
BuiltinLintDiag::AssociatedConstElidedLifetime {
|
||||
elided,
|
||||
span: lt_span,
|
||||
lifetimes_in_scope,
|
||||
} => {
|
||||
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
|
||||
let code = if elided { "'static " } else { "'static" };
|
||||
lints::AssociatedConstElidedLifetime { span: lt_span, code, elided }
|
||||
.decorate_lint(diag);
|
||||
lints::AssociatedConstElidedLifetime {
|
||||
span: lt_span,
|
||||
code,
|
||||
elided,
|
||||
lifetimes_in_scope,
|
||||
}
|
||||
.decorate_lint(diag);
|
||||
}
|
||||
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
|
||||
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis }
|
||||
|
|
|
@ -2873,6 +2873,8 @@ pub struct AssociatedConstElidedLifetime {
|
|||
|
||||
pub code: &'static str,
|
||||
pub elided: bool,
|
||||
#[note]
|
||||
pub lifetimes_in_scope: MultiSpan,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue