-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest appropriate syntax on missing lifetime specifier in return type #55173
Conversation
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
7f7ca81
to
e2a83e4
Compare
help!(db, "consider giving it a 'static lifetime"); | ||
let msg = "consider giving it a 'static lifetime"; | ||
match self.tcx.sess.source_map().span_to_snippet(span) { | ||
Ok(ref snippet) if snippet == "&" => db.span_suggestion_with_applicability( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match has some formattings that threw me off. I think it would be easier on the eyes to have something along the lines of
Ok(ref snippet) => {
let (sugg, app) = match &snippet[..] {
"&" => ("&'static ".to_owned(), Applicability::MachineApplicable),
"'_" => ("'static ".to_owned(), Applicability::MachineApplicable),
snippet => (format!("{} + 'static", snippet), Applicability::MaybeIncorrect),
};
db.span_suggestion_with_applicability(span, msg, sugg, app);
}
lifetime" | ||
); | ||
let msg = "consider giving it an explicit bounded or 'static lifetime"; | ||
match self.tcx.sess.source_map().span_to_snippet(span) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, in fact, this could probably be unified into a function
| ^ expected lifetime parameter | ||
| ^ | ||
| | | ||
| expected lifetime parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe remove the "expected lifetime parameter" message completely? It already says "missing lifetime specifier" in the error message
This comment has been minimized.
This comment has been minimized.
8cd303b
to
abd3856
Compare
@oli-obk addressed review comments |
fn suggest_lifetime(&self, db: &mut DiagnosticBuilder<'_>, span: Span, msg: &str) -> bool { | ||
match self.tcx.sess.source_map().span_to_snippet(span) { | ||
Ok(ref snippet) => { | ||
let (sugg, applicability) = if &snippet[..] == "&" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let (sugg, applicability) = if &snippet[..] == "&" { | |
let (sugg, applicability) = if snippet == "&" { |
r=me with nits applied |
cb07fa1
to
3c096ec
Compare
@bors r=oli-obk |
📌 Commit 3c096ec2f46542adf968139ce8709c8e690b6b1b has been approved by |
This comment has been minimized.
This comment has been minimized.
Suggest using `'static` when a lifetime is missing in the return type with a structured suggestion instead of a note.
Co-Authored-By: estebank <[email protected]>
3c096ec
to
dd91c8f
Compare
@bors r=oli-obk rollup |
📌 Commit dd91c8f has been approved by |
Suggest appropriate syntax on missing lifetime specifier in return type Suggest using `'static` when a lifetime is missing in the return type with a structured suggestion instead of a note. Fix rust-lang#55170.
Suggest appropriate syntax on missing lifetime specifier in return type Suggest using `'static` when a lifetime is missing in the return type with a structured suggestion instead of a note. Fix rust-lang#55170.
Suggest appropriate syntax on missing lifetime specifier in return type Suggest using `'static` when a lifetime is missing in the return type with a structured suggestion instead of a note. Fix rust-lang#55170.
Rollup of 22 pull requests Successful merges: - #53507 (Add doc for impl From for Waker) - #53931 (Gradually expanding libstd's keyword documentation) - #54965 (update tcp stream documentation) - #54977 (Accept `Option<Box<$t:ty>>` in macro argument) - #55138 (in which unused-parens suggestions heed what the user actually wrote) - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type) - #55200 (Documents `From` implementations for `Stdio`) - #55245 (submodules: update clippy from 5afdf8b to b1d0343) - #55247 (Clarified code example in char primitive doc) - #55251 (Fix a typo in the documentation of RangeInclusive) - #55253 (only issue "variant of the expected type" suggestion for enums) - #55254 (Correct trailing ellipsis in name_from_pat) - #55269 (fix typos in various places) - #55282 (Remove redundant clone) - #55285 (Do some copy editing on the release notes) - #55291 (Update stdsimd submodule) - #55296 (Set RUST_BACKTRACE=0 for rustdoc-ui/failed-doctest-output.rs) - #55306 (Regression test for #54478.) - #55328 (Fix doc for new copysign functions) - #55340 (Operands no longer appear in places) - #55345 (Remove is_null) - #55348 (Update RELEASES.md after destabilization of non_modrs_mods) Failed merges: r? @ghost
Suggest using
'static
when a lifetime is missing in the return typewith a structured suggestion instead of a note.
Fix #55170.