Skip to content

Commit d7e660f

Browse files
committed
Fix merge conflicts
1 parent 07c65cd commit d7e660f

File tree

2 files changed

+2
-123
lines changed

2 files changed

+2
-123
lines changed

rustfmt-core/rustfmt-lib/src/formatting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io;
44
use std::time::{Duration, Instant};
55

66
use rustc_ast::ast;
7+
use rustc_span::symbol;
78

89
pub(crate) use syntux::session::ParseSess;
910

@@ -499,7 +500,7 @@ impl Input {
499500
let file_stem = file.file_stem()?;
500501
if file.parent()?.to_path_buf().join(file_stem).is_dir() {
501502
Some(DirectoryOwnership::Owned {
502-
relative: file_stem.to_str().map(ast::Ident::from_str),
503+
relative: file_stem.to_str().map(symbol::Ident::from_str),
503504
})
504505
} else {
505506
None

rustfmt-core/rustfmt-lib/src/lib.rs

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -70,125 +70,3 @@ pub enum Input {
7070
/// A UTF-8 string, in many cases from stdin.
7171
Text(String),
7272
}
73-
74-
impl Input {
75-
fn file_name(&self) -> FileName {
76-
match *self {
77-
Input::File(ref file) => FileName::Real(file.clone()),
78-
Input::Text(..) => FileName::Stdin,
79-
}
80-
}
81-
82-
fn to_directory_ownership(&self) -> Option<DirectoryOwnership> {
83-
match self {
84-
Input::File(ref file) => {
85-
// If there exists a directory with the same name as an input,
86-
// then the input should be parsed as a sub module.
87-
let file_stem = file.file_stem()?;
88-
if file.parent()?.to_path_buf().join(file_stem).is_dir() {
89-
Some(DirectoryOwnership::Owned {
90-
relative: file_stem.to_str().map(symbol::Ident::from_str),
91-
})
92-
} else {
93-
None
94-
}
95-
}
96-
_ => None,
97-
}
98-
}
99-
}
100-
101-
#[cfg(test)]
102-
mod unit_tests {
103-
use super::*;
104-
105-
#[test]
106-
fn test_no_panic_on_format_snippet_and_format_code_block() {
107-
// `format_snippet()` and `format_code_block()` should not panic
108-
// even when we cannot parse the given snippet.
109-
let snippet = "let";
110-
assert!(format_snippet(snippet, &Config::default()).is_none());
111-
assert!(format_code_block(snippet, &Config::default()).is_none());
112-
}
113-
114-
fn test_format_inner<F>(formatter: F, input: &str, expected: &str) -> bool
115-
where
116-
F: Fn(&str, &Config) -> Option<FormattedSnippet>,
117-
{
118-
let output = formatter(input, &Config::default());
119-
output.is_some() && output.unwrap().snippet == expected
120-
}
121-
122-
#[test]
123-
fn test_format_snippet() {
124-
let snippet = "fn main() { println!(\"hello, world\"); }";
125-
#[cfg(not(windows))]
126-
let expected = "fn main() {\n \
127-
println!(\"hello, world\");\n\
128-
}\n";
129-
#[cfg(windows)]
130-
let expected = "fn main() {\r\n \
131-
println!(\"hello, world\");\r\n\
132-
}\r\n";
133-
assert!(test_format_inner(format_snippet, snippet, expected));
134-
}
135-
136-
#[test]
137-
fn test_format_code_block_fail() {
138-
#[rustfmt::skip]
139-
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
140-
assert!(format_code_block(code_block, &Config::default()).is_none());
141-
}
142-
143-
#[test]
144-
fn test_format_code_block() {
145-
// simple code block
146-
let code_block = "let x=3;";
147-
let expected = "let x = 3;";
148-
assert!(test_format_inner(format_code_block, code_block, expected));
149-
150-
// more complex code block, taken from chains.rs.
151-
let code_block =
152-
"let (nested_shape, extend) = if !parent_rewrite_contains_newline && is_continuable(&parent) {
153-
(
154-
chain_indent(context, shape.add_offset(parent_rewrite.len())),
155-
context.config.indent_style() == IndentStyle::Visual || is_small_parent,
156-
)
157-
} else if is_block_expr(context, &parent, &parent_rewrite) {
158-
match context.config.indent_style() {
159-
// Try to put the first child on the same line with parent's last line
160-
IndentStyle::Block => (parent_shape.block_indent(context.config.tab_spaces()), true),
161-
// The parent is a block, so align the rest of the chain with the closing
162-
// brace.
163-
IndentStyle::Visual => (parent_shape, false),
164-
}
165-
} else {
166-
(
167-
chain_indent(context, shape.add_offset(parent_rewrite.len())),
168-
false,
169-
)
170-
};
171-
";
172-
let expected =
173-
"let (nested_shape, extend) = if !parent_rewrite_contains_newline && is_continuable(&parent) {
174-
(
175-
chain_indent(context, shape.add_offset(parent_rewrite.len())),
176-
context.config.indent_style() == IndentStyle::Visual || is_small_parent,
177-
)
178-
} else if is_block_expr(context, &parent, &parent_rewrite) {
179-
match context.config.indent_style() {
180-
// Try to put the first child on the same line with parent's last line
181-
IndentStyle::Block => (parent_shape.block_indent(context.config.tab_spaces()), true),
182-
// The parent is a block, so align the rest of the chain with the closing
183-
// brace.
184-
IndentStyle::Visual => (parent_shape, false),
185-
}
186-
} else {
187-
(
188-
chain_indent(context, shape.add_offset(parent_rewrite.len())),
189-
false,
190-
)
191-
};";
192-
assert!(test_format_inner(format_code_block, code_block, expected));
193-
}
194-
}

0 commit comments

Comments
 (0)