Skip to content

Triage issues #4242

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 3 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn format_project(
}

// Parse the crate.
let directory_ownership = input.to_directory_ownership();
let directory_ownership = input.to_directory_ownership(operation_setting.recursive);
let original_snippet = if let Input::Text(ref str) = input {
Some(str.to_owned())
} else {
Expand Down Expand Up @@ -488,8 +488,10 @@ impl Input {
}
}

fn to_directory_ownership(&self) -> Option<DirectoryOwnership> {
fn to_directory_ownership(&self, recursive: bool) -> Option<DirectoryOwnership> {
match self {
// On recursive mode, we assume that input is the root file.
Input::File(..) if recursive => None,
Input::File(ref file) => {
// If there exists a directory with the same name as an input,
// then the input should be parsed as a sub module.
Expand All @@ -502,7 +504,7 @@ impl Input {
None
}
}
_ => None,
Input::Text(..) => None,
}
}
}
6 changes: 6 additions & 0 deletions tests/source/configs/normalize_comments/true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ fn adipiscing() -> usize {}
////////////////////////////////////////////////////////////////////////////////
// Basic slice extension methods
////////////////////////////////////////////////////////////////////////////////

struct Foo {
field1: u32,
// field2: u32,
// field3: u32,
}
6 changes: 6 additions & 0 deletions tests/target/configs/normalize_comments/true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ fn adipiscing() -> usize {}
////////////////////////////////////////////////////////////////////////////////
// Basic slice extension methods
////////////////////////////////////////////////////////////////////////////////

struct Foo {
field1: u32,
/* field2: u32,
* field3: u32, */
}
83 changes: 83 additions & 0 deletions tests/target/issue-3762.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// rustfmt-format_macro_bodies: true

extern crate toml;
#[macro_use]
extern crate serde_derive;

use toml::Value;

macro_rules! float_inf_tests {
($ty:ty) => {{
#[derive(Serialize, Deserialize)]
struct S {
sf1: $ty,
sf2: $ty,
sf3: $ty,
sf4: $ty,
sf5: $ty,
sf6: $ty,
sf7: $ty,
sf8: $ty,
}
let inf: S = toml::from_str(
r"
# infinity
sf1 = inf # positive infinity
sf2 = +inf # positive infinity
sf3 = -inf # negative infinity

# not a number
sf4 = nan # actual sNaN/qNaN encoding is implementation specific
sf5 = +nan # same as `nan`
sf6 = -nan # valid, actual encoding is implementation specific

# zero
sf7 = +0.0
sf8 = -0.0
",
)
.expect("Parse infinities.");

assert!(inf.sf1.is_infinite());
assert!(inf.sf1.is_sign_positive());
assert!(inf.sf2.is_infinite());
assert!(inf.sf2.is_sign_positive());
assert!(inf.sf3.is_infinite());
assert!(inf.sf3.is_sign_negative());

assert!(inf.sf4.is_nan());
assert!(inf.sf4.is_sign_positive());
assert!(inf.sf5.is_nan());
assert!(inf.sf5.is_sign_positive());
assert!(inf.sf6.is_nan());
assert!(inf.sf6.is_sign_negative());

assert_eq!(inf.sf7, 0.0);
assert!(inf.sf7.is_sign_positive());
assert_eq!(inf.sf8, 0.0);
assert!(inf.sf8.is_sign_negative());

let s = toml::to_string(&inf).unwrap();
assert_eq!(
s,
"\
sf1 = inf
sf2 = inf
sf3 = -inf
sf4 = nan
sf5 = nan
sf6 = -nan
sf7 = 0.0
sf8 = -0.0
"
);

toml::from_str::<Value>(&s).expect("roundtrip");
}};
}

#[test]
fn float_inf() {
float_inf_tests!(f32);
float_inf_tests!(f64);
}