-
Notifications
You must be signed in to change notification settings - Fork 888
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
String literals with unescaped \ in the end of line is not formatted #4321
Comments
I think the issues are different; in 2876, the whitespace is significant and it's more about formatting in the context of a call |
You can already do this with the format_strings option, which does a little more: pub fn foo() -> &'static str {
"use of std::thread::current() is not \
possible after the thread's local \
data has been destroyed"
} would go to pub fn foo() -> &'static str {
"use of std::thread::current() is not possible after the thread's local data has been \
destroyed";
} Would that work for your use case? |
Thanks. Never know about this configuration. |
It just was never turned on as a stable option, there is a tracking issue here: #4036 |
I try that configuration a bit. It is useful and nice. But I would like to preserve the ending rustflags.arg("-Zsave-analysis");
cargo.env(
"RUST_SAVE_ANALYSIS_CONFIG",
- "{\"output_file\": null,\"full_docs\": false,\
- \"pub_only\": true,\"reachable_only\": false,\
- \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}",
+ "{\"output_file\": null,\"full_docs\": false,\"pub_only\": \
+ true,\"reachable_only\": false,\"distro_crate\": true,\"signatures\": \
+ false,\"borrow_data\": false}",
);
} if !pass_sanity_check {
println!("{}\n", subcommand_help);
println!(
- "Sorry, I couldn't figure out which subcommand you were trying to specify.\n\
- You may need to move some options to after the subcommand.\n"
+ "Sorry, I couldn't figure out which subcommand you were trying to specify.\nYou \
+ may need to move some options to after the subcommand.\n"
);
process::exit(1);
} if !output.status.success() {
println!(
- "\n\ncommand did not execute successfully: {:?}\n\
- expected success, got: {}\n\n\
- stdout ----\n{}\n\
- stderr ----\n{}\n\n",
+ "\n\ncommand did not execute successfully: {:?}\nexpected success, got: {}\n\nstdout \
+ ----\n{}\nstderr ----\n{}\n\n",
cmd,
output.status,
String::from_utf8_lossy(&output.stdout), |
Also, is this a bug? #[bench]
fn bench_contains_short_long(b: &mut Bencher) {
- let haystack = "\
+ let haystack =
+ "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
-ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \
-eros. Suspendisse sit amet magna mollis, mollis nunc luctus, imperdiet mi. Integer fringilla non \
-sem ut lacinia. Fusce varius tortor a risus porttitor hendrerit. Morbi mauris dui, ultricies nec \
-tempus vel, gravida nec quam.
+ ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis \
+ sed orci eros. Suspendisse sit amet magna mollis, mollis nunc luctus, imperdiet mi. \
+ Integer fringilla non sem ut lacinia. Fusce varius tortor a risus porttitor hendrerit. \
+ Morbi mauris dui, ultricies nec tempus vel, gravida nec quam.
|
Yeah that makes sense. I agree the formatted version is harder to read. But I think it is unlikely that an option to only format the alignment of a string without formatting other parts of the string would be accepted. In some sense this is a custom formatting.
Yes, it looks like it. Can you share the entire bench function where that happened? |
Yes, it here: https://github.com/rust-lang/rust/blob/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/liballoc/benches/str.rs#L131 I was trying to use that formatting configuration on Rust repo. But I'm afraid it couldn't be accepted |
Yes I think it’s unlikely to be accepted.
…________________________________
От: lzutao <notifications@github.com>
Отправлено: Saturday, July 11, 2020 9:40:52 PM
Кому: rust-lang/rustfmt <rustfmt@noreply.github.com>
Копия: hafiz <ayaz.hafiz.1@gmail.com>; Comment <comment@noreply.github.com>
Тема: Re: [rust-lang/rustfmt] String literals with unescaped \ in the end of line is not formatted (#4321)
Yes, it here: https://github.com/rust-lang/rust/blob/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/liballoc/benches/str.rs#L131
I was trying to use that formatting configuration on Rust repo. But I'm afraid it couldn't be accepted
as the result is not nicer to read.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#4321 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AE6GL6SXVEEI7KI4FJSYGT3R3EPDJANCNFSM4OXKHXWQ>.
|
I still don't like that strings are merged and formatted. But that's probably a separate issue/RFC for fmts. |
Describe the bug
The Rust reference has an exception rule about unescaped
\
at the end of lineof string literals, quoted here:
It would be nice if rustfmt format this snippet:
into
Meta
The text was updated successfully, but these errors were encountered: