Skip to content

Commit

Permalink
transition to Rust 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
fyrchik committed Feb 4, 2019
1 parent bfcfaf1 commit ece629b
Show file tree
Hide file tree
Showing 39 changed files with 311 additions and 296 deletions.
4 changes: 1 addition & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ fn main() {
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (channel(), commit_hash(), commit_date()) {
(channel, Some(hash), Some(date)) => {
format!("{} ({} {})", channel, hash.trim_end(), date)
}
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_end(), date),
_ => String::new(),
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

//! Format attributes and meta items.

use comment::{contains_comment, rewrite_doc_comment, CommentStyle};
use config::lists::*;
use config::IndentStyle;
use expr::rewrite_literal;
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use overflow;
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use types::{rewrite_path, PathContext};
use utils::{count_newlines, mk_sp};

use syntax::ast;
use syntax::source_map::{BytePos, Span, DUMMY_SP};

use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
use crate::config::lists::*;
use crate::config::IndentStyle;
use crate::expr::rewrite_literal;
use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use crate::overflow;
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::Shape;
use crate::types::{rewrite_path, PathContext};
use crate::utils::{count_newlines, mk_sp};

/// Returns attributes on the given statement.
pub fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
match stmt.node {
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Rewrite for ast::MetaItem {
}
ast::MetaItemKind::List(ref list) => {
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let has_trailing_comma = ::expr::span_ends_with_comma(context, self.span);
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
overflow::rewrite_with_parens(
context,
&path,
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'a> Rewrite for [ast::Attribute] {
if let Some(missing_span) = missing_span {
let snippet = context.snippet(missing_span);
let (mla, mlb) = has_newlines_before_after_comment(snippet);
let comment = ::comment::recover_missing_comment_in_span(
let comment = crate::comment::recover_missing_comment_in_span(
missing_span,
shape.with_max_width(context.config),
context,
Expand Down Expand Up @@ -418,7 +418,7 @@ impl<'a> Rewrite for [ast::Attribute] {
.get(derives.len())
.map(|next| mk_sp(attrs[derives.len() - 1].span.hi(), next.span.lo()));
if let Some(missing_span) = missing_span {
let comment = ::comment::recover_missing_comment_in_span(
let comment = crate::comment::recover_missing_comment_in_span(
missing_span,
shape.with_max_width(context.config),
context,
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'a> Rewrite for [ast::Attribute] {
.get(1)
.map(|next| mk_sp(attrs[0].span.hi(), next.span.lo()));
if let Some(missing_span) = missing_span {
let comment = ::comment::recover_missing_comment_in_span(
let comment = crate::comment::recover_missing_comment_in_span(
missing_span,
shape.with_max_width(context.config),
context,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use failure::err_msg;

use getopts::{Matches, Options};

use rustfmt::{
use crate::rustfmt::{
load_config, CliOptions, Color, Config, Edition, EmitMode, ErrorKind, FileLines, FileName,
Input, Session, Verbosity,
};
Expand Down
26 changes: 13 additions & 13 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@
//! .qux
//! ```

use comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
use config::IndentStyle;
use expr::rewrite_call;
use lists::extract_pre_comment;
use macros::convert_try_mac;
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{
self, first_line_width, last_line_extendable, last_line_width, mk_sp, rewrite_ident,
trimmed_last_line_width, wrap_str,
};

use std::borrow::Cow;
use std::cmp::min;

use syntax::source_map::{BytePos, Span};
use syntax::{ast, ptr};

use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
use crate::config::IndentStyle;
use crate::expr::rewrite_call;
use crate::lists::extract_pre_comment;
use crate::macros::convert_try_mac;
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::Shape;
use crate::source_map::SpanUtils;
use crate::utils::{
self, first_line_width, last_line_extendable, last_line_width, mk_sp, rewrite_ident,
trimmed_last_line_width, wrap_str,
};

pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<String> {
let chain = Chain::from_ast(expr, context);
debug!("rewrite_chain {:?} {:?}", chain, shape);
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::io::{self, Write};
use std::path::Path;

use rustfmt_diff::{DiffLine, Mismatch};
use crate::rustfmt_diff::{DiffLine, Mismatch};

/// The checkstyle header - should be emitted before the output of Rustfmt.
///
Expand Down
21 changes: 11 additions & 10 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use config::lists::*;
use syntax::parse::classify;
use syntax::source_map::Span;
use syntax::{ast, ptr};

use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
use items::{span_hi_for_arg, span_lo_for_arg};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use overflow::OverflowableItem;
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
use crate::config::lists::*;
use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
use crate::items::{span_hi_for_arg, span_lo_for_arg};
use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use crate::overflow::OverflowableItem;
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::Shape;
use crate::source_map::SpanUtils;
use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};

// This module is pretty messy because of the rules around closures and blocks:
// FIXME - the below is probably no longer true in full.
Expand Down Expand Up @@ -159,7 +159,8 @@ fn rewrite_closure_with_block(
span: body.span,
recovered: false,
};
let block = ::expr::rewrite_block_with_visitor(context, "", &block, None, None, shape, false)?;
let block =
crate::expr::rewrite_block_with_visitor(context, "", &block, None, None, shape, false)?;
Some(format!("{} {}", prefix, block))
}

Expand Down
20 changes: 10 additions & 10 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use std::{self, borrow::Cow, iter};
use itertools::{multipeek, MultiPeek};
use syntax::source_map::Span;

use config::Config;
use rewrite::RewriteContext;
use shape::{Indent, Shape};
use string::{rewrite_string, StringFormat};
use utils::{
use crate::config::Config;
use crate::rewrite::RewriteContext;
use crate::shape::{Indent, Shape};
use crate::string::{rewrite_string, StringFormat};
use crate::utils::{
count_newlines, first_line_width, last_line_width, trim_left_preserve_layout, unicode_str_width,
};
use {ErrorKind, FormattingError};
use crate::{ErrorKind, FormattingError};

fn is_custom_comment(comment: &str) -> bool {
if !comment.starts_with("//") {
Expand Down Expand Up @@ -657,7 +657,7 @@ impl<'a> CommentRewrite<'a> {
_ => {
let mut config = self.fmt.config.clone();
config.set().wrap_comments(false);
match ::format_code_block(&self.code_block_buffer, &config) {
match crate::format_code_block(&self.code_block_buffer, &config) {
Some(ref s) => trim_custom_comment_prefix(&s.snippet),
None => trim_custom_comment_prefix(&self.code_block_buffer),
}
Expand Down Expand Up @@ -1672,7 +1672,7 @@ fn remove_comment_header(comment: &str) -> &str {
#[cfg(test)]
mod test {
use super::*;
use shape::{Indent, Shape};
use crate::shape::{Indent, Shape};

#[test]
fn char_classes() {
Expand Down Expand Up @@ -1733,11 +1733,11 @@ mod test {
#[test]
#[rustfmt::skip]
fn format_doc_comments() {
let mut wrap_normalize_config: ::config::Config = Default::default();
let mut wrap_normalize_config: crate::config::Config = Default::default();
wrap_normalize_config.set().wrap_comments(true);
wrap_normalize_config.set().normalize_comments(true);

let mut wrap_config: ::config::Config = Default::default();
let mut wrap_config: crate::config::Config = Default::default();
wrap_config.set().wrap_comments(true);

let comment = rewrite_comment(" //test",
Expand Down
4 changes: 2 additions & 2 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use config::file_lines::FileLines;
use config::options::{IgnoreList, WidthHeuristics};
use crate::config::file_lines::FileLines;
use crate::config::options::{IgnoreList, WidthHeuristics};

/// Trait for types that can be used in `Config`.
pub trait ConfigType: Sized {
Expand Down
4 changes: 2 additions & 2 deletions src/config/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

//! Configuration options related to rewriting a list.

use config::config_type::ConfigType;
use config::IndentStyle;
use crate::config::config_type::ConfigType;
use crate::config::IndentStyle;

/// The definitive formatting tactic for lists.
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
Expand Down
11 changes: 6 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use regex::Regex;
use std::cell::Cell;
use std::default::Default;
use std::fs::File;
use std::io::{Error, ErrorKind, Read};
use std::path::{Path, PathBuf};
use std::{env, fs};

use config::config_type::ConfigType;
pub use config::file_lines::{FileLines, FileName, Range};
pub use config::lists::*;
pub use config::options::*;
use regex::Regex;

use crate::config::config_type::ConfigType;
pub use crate::config::file_lines::{FileLines, FileName, Range};
pub use crate::config::lists::*;
pub use crate::config::options::*;

#[macro_use]
pub mod config_type;
Expand Down
12 changes: 6 additions & 6 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use config::config_type::ConfigType;
use config::lists::*;
use config::{Config, FileName};
use std::collections::HashSet;
use std::path::{Path, PathBuf};

use atty;

use std::collections::HashSet;
use std::path::{Path, PathBuf};
use crate::config::config_type::ConfigType;
use crate::config::lists::*;
use crate::config::{Config, FileName};

/// Macro that will stringify the enum variants or a provided textual repr
#[macro_export]
Expand Down Expand Up @@ -169,7 +169,7 @@ impl NewlineStyle {
/// If the style is set to `Auto` and `raw_input_text` contains no
/// newlines, the `Native` style will be used.
pub(crate) fn apply(self, formatted_text: &mut String, raw_input_text: &str) {
use NewlineStyle::*;
use crate::NewlineStyle::*;
let mut style = self;
if style == Auto {
style = Self::auto_detect(raw_input_text);
Expand Down
40 changes: 20 additions & 20 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@
use std::borrow::Cow;
use std::cmp::min;

use config::lists::*;
use syntax::parse::token::DelimToken;
use syntax::source_map::{BytePos, SourceMap, Span};
use syntax::{ast, ptr};

use chains::rewrite_chain;
use closures;
use comment::{
use crate::chains::rewrite_chain;
use crate::closures;
use crate::comment::{
combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment,
rewrite_missing_comment, CharClasses, FindUncommented,
};
use config::{Config, ControlBraceStyle, IndentStyle, Version};
use lists::{
use crate::config::lists::*;
use crate::config::{Config, ControlBraceStyle, IndentStyle, Version};
use crate::lists::{
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
struct_lit_tactic, write_list, ListFormatting, ListItem, Separator,
};
use macros::{rewrite_macro, MacroPosition};
use matches::rewrite_match;
use overflow::{self, IntoOverflowableItem, OverflowableItem};
use pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
use patterns::is_short_pattern;
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use source_map::{LineRangeUtils, SpanUtils};
use spanned::Spanned;
use string::{rewrite_string, StringFormat};
use types::{rewrite_path, PathContext};
use utils::{
use crate::macros::{rewrite_macro, MacroPosition};
use crate::matches::rewrite_match;
use crate::overflow::{self, IntoOverflowableItem, OverflowableItem};
use crate::pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
use crate::patterns::is_short_pattern;
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::{Indent, Shape};
use crate::source_map::{LineRangeUtils, SpanUtils};
use crate::spanned::Spanned;
use crate::string::{rewrite_string, StringFormat};
use crate::types::{rewrite_path, PathContext};
use crate::utils::{
colon_spaces, contains_skip, count_newlines, first_line_ends_with, inner_attributes,
last_line_extendable, last_line_width, mk_sp, outer_attributes, ptr_vec_to_ref_vec,
semicolon_for_expr, semicolon_for_stmt, wrap_str,
};
use vertical::rewrite_with_alignment;
use visitor::FmtVisitor;
use crate::vertical::rewrite_with_alignment;
use crate::visitor::FmtVisitor;

impl Rewrite for ast::Expr {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
Expand Down
12 changes: 6 additions & 6 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use syntax::errors::{DiagnosticBuilder, Handler};
use syntax::parse::{self, ParseSess};
use syntax::source_map::{FilePathMapping, SourceMap, Span};

use comment::{CharClasses, FullCodeCharKind};
use config::{Config, FileName, Verbosity};
use issues::BadIssueSeeker;
use visitor::{FmtVisitor, SnippetProvider};
use {modules, source_file, ErrorKind, FormatReport, Input, Session};
use crate::comment::{CharClasses, FullCodeCharKind};
use crate::config::{Config, FileName, Verbosity};
use crate::issues::BadIssueSeeker;
use crate::visitor::{FmtVisitor, SnippetProvider};
use crate::{modules, source_file, ErrorKind, FormatReport, Input, Session};

// A map of the files of a crate, with their new content
pub(crate) type SourceFile = Vec<FileRecord>;
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {

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

// For some reason, the source_map does not include terminating
Expand Down
2 changes: 1 addition & 1 deletion src/git-rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::str::FromStr;

use getopts::{Matches, Options};

use rustfmt::{load_config, CliOptions, Input, Session};
use crate::rustfmt::{load_config, CliOptions, Input, Session};

fn prune_files(files: Vec<&str>) -> Vec<&str> {
let prefixes: Vec<_> = files
Expand Down
Loading

0 comments on commit ece629b

Please sign in to comment.