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

Merged
merged 3 commits into from Oct 25, 2018

Conversation

Projects
None yet
4 participants
@estebank
Contributor

estebank commented Oct 18, 2018

Suggest using 'static when a lifetime is missing in the return type
with a structured suggestion instead of a note.

Fix #55170.

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Oct 18, 2018

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

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(

This comment has been minimized.

@oli-obk

oli-obk Oct 18, 2018

Contributor

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) {

This comment has been minimized.

@oli-obk

oli-obk Oct 18, 2018

Contributor

same here, in fact, this could probably be unified into a function

| ^ expected lifetime parameter
| ^
| |
| expected lifetime parameter

This comment has been minimized.

@oli-obk

oli-obk Oct 18, 2018

Contributor

maybe remove the "expected lifetime parameter" message completely? It already says "missing lifetime specifier" in the error message

@rust-highfive

This comment was marked as resolved.

Collaborator

rust-highfive commented Oct 18, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

[00:03:47] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:47] tidy error: /checkout/src/librustc/middle/resolve_lifetime.rs: missing trailing newline
[00:03:48] some tidy checks failed
[00:03:48] 
[00:03:48] 
[00:03:48] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:48] 
[00:03:48] 
[00:03:48] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:48] Build completed unsuccessfully in 0:00:45
[00:03:48] Build completed unsuccessfully in 0:00:45
[00:03:48] Makefile:79: recipe for target 'tidy' failed
[00:03:48] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:13843998
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:02e736e8:start=1539893531075197459,finish=1539893531079592490,duration=4395031
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:001825e4
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:232b0b2b
travis_time:start:232b0b2b
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0e680d58
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@estebank

This comment has been minimized.

Contributor

estebank commented Oct 18, 2018

@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[..] == "&" {

This comment has been minimized.

@oli-obk

oli-obk Oct 19, 2018

Contributor
Suggested change Beta
let (sugg, applicability) = if &snippet[..] == "&" {
let (sugg, applicability) = if snippet == "&" {
@oli-obk

This comment has been minimized.

Contributor

oli-obk commented Oct 19, 2018

r=me with nits applied

@estebank

This comment has been minimized.

Contributor

estebank commented Oct 19, 2018

@bors r=oli-obk

@bors

This comment has been minimized.

Contributor

bors commented Oct 19, 2018

📌 Commit 3c096ec has been approved by oli-obk

@bors

This comment was marked as resolved.

Contributor

bors commented Oct 20, 2018

☔️ The latest upstream changes (presumably #55162) made this pull request unmergeable. Please resolve the merge conflicts.

estebank and others added some commits Oct 18, 2018

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.
[review comments] modify test and clean up code
Co-Authored-By: estebank <esteban@kuber.com.ar>
@estebank

This comment has been minimized.

Contributor

estebank commented Oct 22, 2018

@bors r=oli-obk rollup

@bors

This comment has been minimized.

Contributor

bors commented Oct 22, 2018

📌 Commit dd91c8f has been approved by oli-obk

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Oct 23, 2018

Rollup merge of rust-lang#55173 - estebank:suggest-static, r=oli-obk
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.

bors added a commit that referenced this pull request Oct 24, 2018

Auto merge of #55295 - pietroalbini:rollup, r=pietroalbini
Rollup of 19 pull requests

Successful merges:

 - #54125 (Less conservative uninhabitedness check)
 - #54626 (rustc: Tweak filenames encoded into metadata)
 - #54965 (update tcp stream documentation)
 - #55150 (Do not allow moving out of thread local under ast borrowck)
 - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type)
 - #55185 (path suggestions in Rust 2018 should point out the change in semantics )
 - #55225 (Move cg_llvm:🔙:linker to cg_utils)
 - #55245 (submodules: update clippy from 5afdf8b7 to b1d03437)
 - #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)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55269 (fix typos in various places)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55282 (Remove redundant clone)
 - #55285 (Do some copy editing on the release notes)
 - #55291 (Update stdsimd submodule)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Oct 24, 2018

Auto merge of #55295 - pietroalbini:rollup, r=pietroalbini
Rollup of 19 pull requests

Successful merges:

 - #54125 (Less conservative uninhabitedness check)
 - #54626 (rustc: Tweak filenames encoded into metadata)
 - #54965 (update tcp stream documentation)
 - #55150 (Do not allow moving out of thread local under ast borrowck)
 - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type)
 - #55185 (path suggestions in Rust 2018 should point out the change in semantics )
 - #55225 (Move cg_llvm:🔙:linker to cg_utils)
 - #55245 (submodules: update clippy from 5afdf8b7 to b1d03437)
 - #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)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55269 (fix typos in various places)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55282 (Remove redundant clone)
 - #55285 (Do some copy editing on the release notes)
 - #55291 (Update stdsimd submodule)

Failed merges:

r? @ghost

kennytm added a commit to kennytm/rust that referenced this pull request Oct 24, 2018

Rollup merge of rust-lang#55173 - estebank:suggest-static, r=oli-obk
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.

bors added a commit that referenced this pull request Oct 25, 2018

Auto merge of #55320 - kennytm:rollup, r=kennytm
Rollup of 22 pull requests

Successful merges:

 - #53507 (Add doc for impl From for Waker)
 - #54626 (rustc: Tweak filenames encoded into metadata)
 - #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)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type)
 - #55225 (Move cg_llvm:🔙:linker to cg_utils)
 - #55245 (submodules: update clippy from 5afdf8b7 to b1d03437)
 - #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)
 - #55257 (Allow extern statics with an extern type)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55269 (fix typos in various places)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55282 (Remove redundant clone)
 - #55285 (Do some copy editing on the release notes)
 - #55291 (Update stdsimd submodule)
 - #55303 (Update compiler-builtins submodule)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Oct 25, 2018

Auto merge of #55320 - kennytm:rollup, r=kennytm
Rollup of 28 pull requests

Successful merges:

 - #53507 (Add doc for impl From for Waker)
 - #53931 (Gradually expanding libstd's keyword documentation)
 - #54626 (rustc: Tweak filenames encoded into metadata)
 - #54921 (Add line numbers option to rustdoc)
 - #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)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type)
 - #55200 (Documents `From` implementations for `Stdio`)
 - #55225 (Move cg_llvm:🔙:linker to cg_utils)
 - #55245 (submodules: update clippy from 5afdf8b7 to b1d03437)
 - #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)
 - #55257 (Allow extern statics with an extern type)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #55269 (fix typos in various places)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #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)
 - #55303 (Update compiler-builtins submodule)
 - #55306 (Regression test for #54478.)
 - #55328 (Fix doc for new copysign functions)

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Oct 25, 2018

Rollup merge of rust-lang#55173 - estebank:suggest-static, r=oli-obk
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.

bors added a commit that referenced this pull request Oct 25, 2018

Auto merge of #55347 - pietroalbini:rollup, r=pietroalbini
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 5afdf8b7 to b1d03437)
 - #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

@bors bors merged commit dd91c8f into rust-lang:master Oct 25, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment