Skip to content

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

Open
@Boscop

Description

@Boscop

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    e-trailing whitespaceerror[internal]: left behind trailing whitespaceonly-with-optionrequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions