Skip to content

Don't format!() string literals #52805

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 1 commit into from
Jul 30, 2018
Merged

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Jul 28, 2018

Prefer to_string() to format!() take 2, this time targetting string literals. In some cases (&format!("...") -> "...") also removes allocations. Occurences of format!("") are changed to String::new().

@rust-highfive
Copy link
Contributor

r? @petrochenkov

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 28, 2018
@@ -99,30 +99,26 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
let span_label_var1 = if let Some(simple_ident) = anon_arg_sup.pat.simple_ident() {
format!(" from `{}`", simple_ident)
} else {
format!("")
"".to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using String::new() instead of "".to_string() would be even faster. (Similar for every other occurrences)

@@ -229,7 +229,7 @@ fn check_paths<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

fn dump_graph(tcx: TyCtxt) {
let path: String = env::var("RUST_DEP_GRAPH").unwrap_or_else(|_| format!("dep_graph"));
let path: String = env::var("RUST_DEP_GRAPH").unwrap_or("dep_graph".to_string());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the unwrap_or_else where. .to_string() is not free.

@ljedrz ljedrz force-pushed the format_str_literal branch from 01bed0e to 421b2ba Compare July 28, 2018 16:03
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 28, 2018

@kennytm thanks, done.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 29, 2018

📌 Commit 421b2ba has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2018
@bors
Copy link
Collaborator

bors commented Jul 29, 2018

⌛ Testing commit 421b2ba with merge 7ff3098...

bors added a commit that referenced this pull request Jul 29, 2018
Don't format!() string literals

Prefer `to_string()` to `format!()` take 2, this time targetting string literals. In some cases (`&format!("...")` -> `"..."`) also removes allocations. Occurences of `format!("")` are changed to `String::new()`.
@bors
Copy link
Collaborator

bors commented Jul 29, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 29, 2018
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 29, 2018

Build execution time has reached the maximum allowed time for your plan (180 minutes).

Spurious?

@kennytm
Copy link
Member

kennytm commented Jul 30, 2018

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2018
@bors
Copy link
Collaborator

bors commented Jul 30, 2018

⌛ Testing commit 421b2ba with merge 6a3fada2b42a3fba3e4d872d555d743ab711b999...

@bors
Copy link
Collaborator

bors commented Jul 30, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 30, 2018
@rust-highfive
Copy link
Contributor

The job dist-mipsel-linux 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.
######################################################################    97.8%
######################################################################## 100.0%
[00:00:59] extracting /checkout/obj/build/cache/2018-07-27/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz
[00:00:59] downloading https://static.rust-lang.org/dist/2018-07-27/rustc-beta-x86_64-unknown-linux-gnu.tar.gz
No output has been received in the last 30m0s, this potentially indicates a stalled build or something wrong with the build itself.
Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received
The build has been terminated

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)

@kennytm
Copy link
Member

kennytm commented Jul 30, 2018

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2018
@bors
Copy link
Collaborator

bors commented Jul 30, 2018

⌛ Testing commit 421b2ba with merge 988b7451140651f904f5d8147a0d4accb2f7e6c2...

@bors
Copy link
Collaborator

bors commented Jul 30, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 30, 2018
@rust-highfive
Copy link
Contributor

The job dist-x86_64-musl 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.
[01:00:56] test [run-pass] run-pass/trivial-message.rs ... ok
[01:00:56] test [run-pass] run-pass/try-operator-hygiene.rs ... ok
[01:00:57] test [run-pass] run-pass/try-macro.rs ... ok

Broadcast message from root@travis-job-feee2b13-5b2a-4a1d-ad05-039941501fc5
 (unknown) at 4:33 ...
The system is going down for power off NOW!
[01:00:57] 
[01:00:57] Session terminated, terminating shell... ...terminated.

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 143.
travis_time:start:2abf60c1
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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)

@kennytm
Copy link
Member

kennytm commented Jul 30, 2018

@bors retry travis-ci/travis-ci#4924

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2018
@bors
Copy link
Collaborator

bors commented Jul 30, 2018

⌛ Testing commit 421b2ba with merge 7bbcd00...

bors added a commit that referenced this pull request Jul 30, 2018
Don't format!() string literals

Prefer `to_string()` to `format!()` take 2, this time targetting string literals. In some cases (`&format!("...")` -> `"..."`) also removes allocations. Occurences of `format!("")` are changed to `String::new()`.
@bors
Copy link
Collaborator

bors commented Jul 30, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 7bbcd00 to master...

@bors bors merged commit 421b2ba into rust-lang:master Jul 30, 2018
@ljedrz ljedrz deleted the format_str_literal branch July 30, 2018 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants