Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a812c1
Clarify how to choose a FutureIncompatibilityReason variant.
ehuss Nov 15, 2023
b7a23bc
On borrow return type, suggest borrowing from arg or owned return type
estebank Nov 14, 2023
5fce361
Account for impl Trait in lifetime suggestion
estebank Nov 14, 2023
d30252e
Tweak wording
estebank Nov 14, 2023
dec7f00
Fix incorrect lifetime suggestion
estebank Nov 15, 2023
2a92d82
Suggest 'a when trait object assoc type has '_
estebank Nov 15, 2023
85f26ad
Account for '_ in lifetime suggestion
estebank Nov 15, 2023
bb9d720
Do not consider traits as ownable in suggestion
estebank Nov 15, 2023
02bea16
Rely in resolve and not on path name for `&str` -> `String` suggestion
estebank Nov 15, 2023
eee4cc6
let-chain fmt
estebank Nov 16, 2023
69a2bd6
report_not_const_evaluatable_error to avoid ICEing on ConstKind::Expr
lenko-d Oct 14, 2023
226edf6
Improve an error involving attribute values.
nnethercote Dec 11, 2023
4f80833
rustdoc-search: clean up parser
notriddle Dec 12, 2023
f44ccba
rustc_codegen_llvm: Enforce `rustc::potential_query_instability` lint
Enselic Dec 12, 2023
46a8015
llvm-wrapper: adapt for LLVM API change
krasimirgg Dec 12, 2023
e274372
Correctly gate the parsing of match arms without body
Nadrieril Dec 12, 2023
19e0c98
Don't gate the feature twice
Nadrieril Dec 12, 2023
41c9404
tests: CGU tests require build-pass, not check-pass (remove FIXME)
Enselic Dec 12, 2023
b2a0175
Rollup merge of #116740 - lenko-d:const_evaluatable_failed_for_non_un…
matthiaskrgr Dec 12, 2023
ffdb471
Rollup merge of #117914 - estebank:issue-85843, r=wesleywiser
matthiaskrgr Dec 12, 2023
111c40e
Rollup merge of #117927 - ehuss:future-incompat-docs, r=wesleywiser
matthiaskrgr Dec 12, 2023
cd7809b
Rollup merge of #118855 - nnethercote:improve-attribute-value-error, …
matthiaskrgr Dec 12, 2023
6459121
Rollup merge of #118856 - notriddle:notriddle/search-js, r=GuillaumeG…
matthiaskrgr Dec 12, 2023
04c77a5
Rollup merge of #118865 - Enselic:rustc_codegen_llvm-lint-fix, r=petr…
matthiaskrgr Dec 12, 2023
9ed12f8
Rollup merge of #118866 - krasimirgg:llvm-18-ref, r=durin42
matthiaskrgr Dec 12, 2023
d661974
Rollup merge of #118868 - Nadrieril:correctly-gate-never_patterns-par…
matthiaskrgr Dec 12, 2023
010f301
Rollup merge of #118877 - Enselic:remove-cgu-fixme, r=Nilstrieb
matthiaskrgr Dec 12, 2023
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
Prev Previous commit
Next Next commit
Account for '_ in lifetime suggestion
  • Loading branch information
estebank committed Nov 20, 2023
commit 85f26ade8dc3364f29a2c0b0d8f5fe2068df8969
19 changes: 15 additions & 4 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
} else {
"instead, you are more likely to want"
};
let mut owned_sugg = lt.kind == MissingLifetimeKind::Ampersand;
let mut sugg = vec![(lt.span, String::new())];
if let Some((kind, _span)) =
self.diagnostic_metadata.current_function
Expand All @@ -3092,6 +3093,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
};
lt_finder.visit_ty(&ty);

if let [Ty { span, kind: TyKind::Ref(_, mut_ty), ..}]
= &lt_finder.seen[..]
{
// We might have a situation like
// fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()>
// but `lt.span` only points at `'_`, so to suggest `-> Option<()>`
// we need to find a more accurate span to end up with
// fn g<'a>(mut x: impl Iterator<Item = &'_ ()>) -> Option<()>
sugg = vec![(span.with_hi(mut_ty.ty.span.lo()), String::new())];
owned_sugg = true;
}
if let Some(ty) = lt_finder.found {
if let TyKind::Path(None, Path { segments, .. }) = &ty.kind
&& segments.len() == 1
Expand All @@ -3101,17 +3113,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
sugg = vec![
(lt.span.with_hi(ty.span.hi()), "String".to_string()),
];
}
if let TyKind::Slice(inner_ty) = &ty.kind {
} else if let TyKind::Slice(inner_ty) = &ty.kind {
// Don't suggest `-> [T]`, suggest `-> Vec<T>`.
sugg = vec![
(lt.span.with_hi(inner_ty.span.lo()), "Vec<".to_string()),
(ty.span.with_lo(inner_ty.span.hi()), ">".to_string()),
];
}
}
};
if lt.kind == MissingLifetimeKind::Ampersand {
}
if owned_sugg {
err.multipart_suggestion_verbose(
format!("{pre} to return an owned value"),
sugg,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ help: consider introducing a named lifetime parameter
|
LL | fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: alternatively, you might want to return an owned value
|
LL - fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
LL + fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|

error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:37:64
Expand All @@ -71,6 +76,11 @@ help: consider introducing a named lifetime parameter
|
LL | async fn i<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: alternatively, you might want to return an owned value
|
LL - async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
LL + async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|

error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:47:37
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/suggestions/impl-trait-missing-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ help: consider introducing a named lifetime parameter
|
LL | fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: alternatively, you might want to return an owned value
|
LL - fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
LL + fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|

error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime.rs:16:60
Expand All @@ -29,6 +34,11 @@ help: consider introducing a named lifetime parameter
|
LL | async fn i<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: alternatively, you might want to return an owned value
|
LL - async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
LL + async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|

error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime.rs:16:69
Expand Down