Skip to content
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

Multiline comment causes error[internal]: left behind trailing whitespace #4824

Open
Boscop opened this issue May 1, 2021 · 1 comment · May be fixed by #5502
Open

Multiline comment causes error[internal]: left behind trailing whitespace #4824

Boscop opened this issue May 1, 2021 · 1 comment · May be fixed by #5502
Labels
e-trailing whitespace error[internal]: left behind trailing whitespace only-with-option requires a non-default option value to reproduce

Comments

@Boscop
Copy link

Boscop commented May 1, 2021

This input file:

#[cfg(windows)]
fn main() {
	use common_util::get_version_for_rc;
	use std::env;
	use winres::{VersionInfo, WindowsResource};

	println!("cargo:rerun-if-changed=favicon.ico");
	println!("cargo:rerun-if-changed=Cargo.toml"); // rerun when version changed
	/*let profile = env::var("PROFILE").unwrap();
	if profile == "release"*/ {
		let mut res = WindowsResource::new();
		res.set_icon("favicon.ico");
		let version = get_version_for_rc!();
		res.set_version_info(VersionInfo::PRODUCTVERSION, version);
		res.set_version_info(VersionInfo::FILEVERSION, version);
		res.compile().unwrap();
	}
}

#[cfg(not(windows))]
fn main() {}

causes this error:

error[internal]: left behind trailing whitespace
  --> \\?\D:\projects\myproject\build.rs:9:9:0
   |
 9 |
   | ^
   |

warning: rustfmt has failed to format. See previous 1 errors.

and this formatted file:

#[cfg(windows)]
fn main() {
	use common_util::get_version_for_rc;
	use std::env;
	use winres::{VersionInfo, WindowsResource};

	println!("cargo:rerun-if-changed=favicon.ico");
	println!("cargo:rerun-if-changed=Cargo.toml"); // rerun when version changed
	
	/*let profile = env::var("PROFILE").unwrap();
	if profile == "release"*/
	{
		let mut res = WindowsResource::new();
		res.set_icon("favicon.ico");
		let version = get_version_for_rc!();
		res.set_version_info(VersionInfo::PRODUCTVERSION, version);
		res.set_version_info(VersionInfo::FILEVERSION, version);
		res.compile().unwrap();
	}
}

#[cfg(not(windows))]
fn main() {}

(I'm invoking it with cargo +nightly fmt.)
Note that there was a new line inserted before the multiline comment, but it's not empty, it contains a TAB character (I'm using tabs for indentation).
This is the trailing whitespace that the error is referring to.

My config:

edition = "2018"
version = "Two"
max_width = 110
newline_style = "Unix"
use_small_heuristics = "Max"
hard_tabs = true
merge_imports = true
reorder_impl_items = true
use_field_init_shorthand = true
use_try_shorthand = true
spaces_around_ranges = true
overflow_delimited_expr = true

rustfmt version:

> cargo +nightly fmt --version
rustfmt 1.4.37-nightly (0bd2b192 2021-04-03)
@calebcartwright calebcartwright added the only-with-option requires a non-default option value to reproduce label May 16, 2021
@ytmimi ytmimi added e-trailing whitespace error[internal]: left behind trailing whitespace and removed only-with-option requires a non-default option value to reproduce labels Jul 22, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

confirming this is still an issue with rustfmt 1.5.1-nightly (5c41baf8 2022-07-14) and I don't need any configuration options besides version=Two to trigger it.

Linking tracking issue for version #3383

@ytmimi ytmimi added the only-with-option requires a non-default option value to reproduce label Jul 26, 2022
davidBar-On added a commit to davidBar-On/rustfmt that referenced this issue Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e-trailing whitespace error[internal]: left behind trailing whitespace only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants