fn format_file(
        &mut self,
        path: FileName,
        module: &ast::Mod,
        is_root: bool,
    ) -> Result<(), ErrorKind> {
        let source_file = self
            .parse_session
            .source_map()
            .lookup_char_pos(module.inner.lo())
            .file;
        let big_snippet = source_file.src.as_ref().unwrap();
        let snippet_provider = SnippetProvider::new(source_file.start_pos, big_snippet);
        let mut visitor = FmtVisitor::from_source_map(
            &self.parse_session,
            &self.config,
            &snippet_provider,
            self.report.clone(),
        );
        visitor
            .skip_macro_names
            .borrow_mut()
            .append(&mut get_skip_macro_names(&self.krate.attrs));

        // Format inner attributes if available.
        if !self.krate.attrs.is_empty() && is_root {
            visitor.skip_empty_lines(source_file.end_pos);
            if visitor.visit_attrs(&self.krate.attrs, ast::AttrStyle::Inner) {
                visitor.push_rewrite(module.inner, None);
            } else {
                visitor.format_separate_mod(module, &*source_file);
            }
        } else {
            visitor.last_pos = source_file.start_pos;
            visitor.skip_empty_lines(source_file.end_pos);
            visitor.format_separate_mod(module, &*source_file);
        };

        debug_assert_eq!(visitor.line_number, count_newlines(&visitor.buffer));

        // For some reason, the source_map does not include terminating
        // newlines so we must add one on for each file. This is sad.
        source_file::append_newline(&mut visitor.buffer);

        format_lines(
            &mut visitor.buffer,
            &path,
            &visitor.skipped_range,
            &self.config,
            &self.report,
        );
        self.config
            .newline_style()
            .apply(&mut visitor.buffer, &big_snippet);

        if visitor.macro_rewrite_failure {
            self.report.add_macro_format_failure();
        }
        self.report
            .add_non_formatted_ranges(visitor.skipped_range.clone());

        self.handler.handle_formatted_file(
            self.parse_session.source_map(),
            path,
            visitor.buffer.to_owned(),
            &mut self.report,
        )
    }
// Formats a single file/module.
Formats a single file/module.
Formats a single file / module .
fn format_file(
        &mut self,
        path: FileName,
        module: &ast::Mod,
        is_root: bool,
    ) -> Result<(), ErrorKind> {
        let source_file = self
            .parse_session
            .source_map()
            .lookup_char_pos(module.inner.lo())
            .file;
        let big_snippet = source_file.src.as_ref().unwrap();
        let snippet_provider = SnippetProvider::new(source_file.start_pos, big_snippet);
        let mut visitor = FmtVisitor::from_source_map(
            &self.parse_session,
            &self.config,
            &snippet_provider,
            self.report.clone(),
        );
        visitor
            .skip_macro_names
            .borrow_mut()
            .append(&mut get_skip_macro_names(&self.krate.attrs));
        // Format inner attributes if available.
        if !self.krate.attrs.is_empty() && is_root {
            visitor.skip_empty_lines(source_file.end_pos);
            if visitor.visit_attrs(&self.krate.attrs, ast::AttrStyle::Inner) {
                visitor.push_rewrite(module.inner, None);
            } else {
                visitor.format_separate_mod(module, &*source_file);
            }
        } else {
            visitor.last_pos = source_file.start_pos;
            visitor.skip_empty_lines(source_file.end_pos);
            visitor.format_separate_mod(module, &*source_file);
        };
        debug_assert_eq!(visitor.line_number, count_newlines(&visitor.buffer));
        // For some reason, the source_map does not include terminating
        // newlines so we must add one on for each file. This is sad.
        source_file::append_newline(&mut visitor.buffer);
        format_lines(
            &mut visitor.buffer,
            &path,
            &visitor.skipped_range,
            &self.config,
            &self.report,
        );
        self.config
            .newline_style()
            .apply(&mut visitor.buffer, &big_snippet);
        if visitor.macro_rewrite_failure {
            self.report.add_macro_format_failure();
        }
        self.report
            .add_non_formatted_ranges(visitor.skipped_range.clone());
        self.handler.handle_formatted_file(
            self.parse_session.source_map(),
            path,
            visitor.buffer.to_owned(),
            &mut self.report,
        )
    }
fn format_file ( & mut self , path : FileName , module : & ast :: Mod , is_root : bool , ) -> Result < ( ) , ErrorKind > { let source_file = self . parse_session . source_map ( ) . lookup_char_pos ( module . inner . lo ( ) ) . file ; let big_snippet = source_file . src . as_ref ( ) . unwrap ( ) ; let snippet_provider = SnippetProvider :: new ( source_file . start_pos , big_snippet ) ; let mut visitor = FmtVisitor :: from_source_map ( & self . parse_session , & self . config , & snippet_provider , self . report . clone ( ) , ) ; visitor . skip_macro_names . borrow_mut ( ) . append ( & mut get_skip_macro_names ( & self . krate . attrs ) ) ; // Format inner attributes if available. if ! self . krate . attrs . is_empty ( ) && is_root { visitor . skip_empty_lines ( source_file . end_pos ) ; if visitor . visit_attrs ( & self . krate . attrs , ast :: AttrStyle :: Inner ) { visitor . push_rewrite ( module . inner , None ) ; } else { visitor . format_separate_mod ( module , & * source_file ) ; } } else { visitor . last_pos = source_file . start_pos ; visitor . skip_empty_lines ( source_file . end_pos ) ; visitor . format_separate_mod ( module , & * source_file ) ; } ; debug_assert_eq ! ( visitor line_number count_newlines ( visitor buffer ) ) ; // For some reason, the source_map does not include terminating // newlines so we must add one on for each file. This is sad. source_file :: append_newline ( & mut visitor . buffer ) ; format_lines ( & mut visitor . buffer , & path , & visitor . skipped_range , & self . config , & self . report , ) ; self . config . newline_style ( ) . apply ( & mut visitor . buffer , & big_snippet ) ; if visitor . macro_rewrite_failure { self . report . add_macro_format_failure ( ) ; } self . report . add_non_formatted_ranges ( visitor . skipped_range . clone ( ) ) ; self . handler . handle_formatted_file ( self . parse_session . source_map ( ) , path , visitor . buffer . to_owned ( ) , & mut self . report , ) }
Formats a single file/module.
Formats a single file / module .
&mut self
path
FileName
module
&ast::Mod
is_root
bool
&mut self
path
FileName
module
&ast::Mod
is_root
bool