Skip to content

On borrow return type, suggest borrowing from arg or owned return type #117914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Tweak wording
  • Loading branch information
estebank committed Nov 20, 2023
commit d30252e3593af0c335f86de4242d581ffa11e270
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3012,7 +3012,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
sugg,
Applicability::MaybeIncorrect,
);
"...or alternatively,"
"...or alternatively, you might want"
} else if let Some((kind, _span)) =
self.diagnostic_metadata.current_function
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
Expand Down Expand Up @@ -3070,9 +3070,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
higher_ranked
},
);
"...or alternatively,"
"alternatively, you might want"
} else {
"instead, you are more likely"
"instead, you are more likely to want"
};
let mut sugg = vec![(lt.span, String::new())];
if let Some((kind, _span)) =
Expand Down Expand Up @@ -3105,7 +3105,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
};
err.multipart_suggestion_verbose(
format!("{pre} to want to return an owned value"),
format!("{pre} to return an owned value"),
sugg,
Applicability::MaybeIncorrect,
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/variadic-ffi-6.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help: instead, you are more likely to want to change one of the arguments to be
|
LL | x: &usize,
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - ) -> &usize {
LL + ) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lifetimes/issue-26638.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ help: instead, you are more likely to want to change the argument to be borrowed
|
LL | fn parse_type_2(iter: &fn(&u8)->&u8) -> &str { iter() }
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> String { iter() }
| ~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ help: instead, you are more likely to want to change the argument to be borrowed
|
LL | fn i(_x: &isize) -> &isize {
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - fn i(_x: isize) -> &isize {
LL + fn i(_x: isize) -> isize {
Expand All @@ -75,7 +75,7 @@ help: instead, you are more likely to want to change the argument to be borrowed
|
LL | fn j(_x: &StaticStr) -> &isize {
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - fn j(_x: StaticStr) -> &isize {
LL + fn j(_x: StaticStr) -> isize {
Expand All @@ -96,7 +96,7 @@ help: instead, you are more likely to want to change the argument to be borrowed
|
LL | fn k<'a, T: WithLifetime<'a>>(_x: &T::Output) -> &isize {
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
LL + fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> isize {
Expand All @@ -117,7 +117,7 @@ help: instead, you are more likely to want to change one of the arguments to be
|
LL | fn l<'a>(_: &&'a str, _: &&'a str) -> &str { "" }
| + +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL | fn l<'a>(_: &'a str, _: &'a str) -> String { "" }
| ~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/self/elision/nested-item.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ help: instead, you are more likely to want to change the argument to be borrowed
|
LL | fn wrap(self: &Wrap<{ fn bar(&self) {} }>) -> &() {
| +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
LL + fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> () {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help: consider introducing a named lifetime parameter
|
LL | fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: ...or alternatively, to want to return an owned value
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() }
Expand All @@ -34,7 +34,7 @@ help: consider introducing a named lifetime parameter
|
LL | async fn i<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~ ~~~
help: ...or alternatively, to want to return an owned value
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() }
Expand Down Expand Up @@ -79,7 +79,7 @@ help: consider introducing a named lifetime parameter
|
LL | fn g<'a>(mut x: impl Foo) -> Option<&'a ()> { x.next() }
| ++++ ~~~
help: ...or alternatively, to want to return an owned value
help: alternatively, you might want to return an owned value
|
LL - fn g(mut x: impl Foo) -> Option<&()> { x.next() }
LL + fn g(mut x: impl Foo) -> Option<()> { x.next() }
Expand All @@ -100,7 +100,7 @@ help: consider introducing a named lifetime parameter
|
LL | fn g<'a>(mut x: impl Foo<()>) -> Option<&'a ()> { x.next() }
| ++++ ~~~
help: ...or alternatively, to want to return an owned value
help: alternatively, you might want to return an owned value
|
LL - fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
LL + fn g(mut x: impl Foo<()>) -> Option<()> { x.next() }
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/return-elided-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ help: instead, you are more likely to want to change one of the arguments to be
|
LL | fn f2(a: &i32, b: &i32) -> &i32 { loop {} }
| + +
help: ...or alternatively, to want to return an owned value
help: ...or alternatively, you might want to return an owned value
|
LL - fn f2(a: i32, b: i32) -> &i32 { loop {} }
LL + fn f2(a: i32, b: i32) -> i32 { loop {} }
Expand Down