Skip to content

Commit

Permalink
Update to rustfmt 0.4.2-stable (febbb36 2018-04-12).
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed May 31, 2018
1 parent 81343f5 commit a6763b9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 100 deletions.
23 changes: 13 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Allow dead code in triple.rs and targets.rs for our purposes here.
#![allow(dead_code)]

use serde_json::Value;
use std::env;
use std::fs::File;
use std::io::{self, prelude::*, Write};
use std::path::PathBuf;
use std::str::FromStr;
use serde_json::Value;

extern crate serde_json;

Expand Down Expand Up @@ -37,12 +37,11 @@ mod parse_error {
use triple::Triple;

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").expect(
"The OUT_DIR environment variable must be set",
));
let out_dir =
PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"));

let target = env::var("TARGET").expect("The TARGET environment variable must be set");

let triple = match Triple::from_str(&target) {
Ok(triple) => {
assert_eq!(target, triple.to_string(), "host is unrecognized");
Expand All @@ -51,14 +50,18 @@ fn main() {
Err(_) => {
let mut file = File::open(&target).expect("error opening target file");
let mut json = String::new();
file.read_to_string(&mut json).expect("error reading target file");
file.read_to_string(&mut json)
.expect("error reading target file");
let v: Value = serde_json::from_str(&json).expect("error parsing target file as json");
let target = v["llvm-target"]
.as_str()
.expect("error parsing \"llvm-target\" as a string");
.as_str()
.expect("error parsing \"llvm-target\" as a string");
let triple = Triple::from_str(target).expect("error parsing host target");
assert_eq!(target, triple.to_string(),
"host is unrecognized (as defined in target json file)");
assert_eq!(
target,
triple.to_string(),
"host is unrecognized (as defined in target json file)"
);
triple
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/misc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate target_lexicon;

use target_lexicon::{Triple, HOST};
use std::str::FromStr;
use target_lexicon::{Triple, HOST};

fn main() {
println!("The host triple is {}.", HOST);
Expand Down
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use {Architecture, Vendor, OperatingSystem, Environment, BinaryFormat, Triple};
use {Architecture, BinaryFormat, Environment, OperatingSystem, Triple, Vendor};

// Include the implementations of the `HOST` object containing information
// about the current host.
Expand Down
24 changes: 10 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces)]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
print_stdout,
unicode_not_nfc,
use_self,
))]

#![cfg_attr(
feature = "cargo-clippy",
warn(
float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else,
print_stdout, unicode_not_nfc, use_self
)
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]

Expand All @@ -25,8 +21,8 @@ extern crate failure_derive;

#[cfg(not(feature = "std"))]
mod std {
pub use core::*;
pub use alloc::{borrow, string};
pub use core::*;
}

mod host;
Expand All @@ -37,5 +33,5 @@ mod triple;

pub use host::HOST;
pub use parse_error::ParseError;
pub use targets::{Architecture, Vendor, OperatingSystem, Environment, BinaryFormat};
pub use triple::{Triple, PointerWidth, Endianness};
pub use targets::{Architecture, BinaryFormat, Environment, OperatingSystem, Vendor};
pub use triple::{Endianness, PointerWidth, Triple};
122 changes: 60 additions & 62 deletions src/targets.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This file defines all the identifier enums and target-aware logic.

use std::str::FromStr;
use std::fmt;
use triple::{Triple, PointerWidth, Endianness};
use std::str::FromStr;
use triple::{Endianness, PointerWidth, Triple};

/// The "architecture" field, which in some cases also specifies a specific
/// subarchitecture.
Expand Down Expand Up @@ -120,35 +120,35 @@ impl Architecture {
pub fn endianness(&self) -> Result<Endianness, ()> {
match *self {
Architecture::Unknown => Err(()),
Architecture::Aarch64 |
Architecture::Arm |
Architecture::Armv4t |
Architecture::Armv5te |
Architecture::Armv7 |
Architecture::Armv7s |
Architecture::Asmjs |
Architecture::I386 |
Architecture::I586 |
Architecture::I686 |
Architecture::Mips64el |
Architecture::Mipsel |
Architecture::Msp430 |
Architecture::Powerpc64le |
Architecture::Riscv32 |
Architecture::Riscv64 |
Architecture::Thumbv6m |
Architecture::Thumbv7em |
Architecture::Thumbv7m |
Architecture::Wasm32 |
Architecture::X86_64 => Ok(Endianness::Little),
Architecture::Mips |
Architecture::Mips64 |
Architecture::Powerpc |
Architecture::Powerpc64 |
Architecture::S390x |
Architecture::Sparc |
Architecture::Sparc64 |
Architecture::Sparcv9 => Ok(Endianness::Big),
Architecture::Aarch64
| Architecture::Arm
| Architecture::Armv4t
| Architecture::Armv5te
| Architecture::Armv7
| Architecture::Armv7s
| Architecture::Asmjs
| Architecture::I386
| Architecture::I586
| Architecture::I686
| Architecture::Mips64el
| Architecture::Mipsel
| Architecture::Msp430
| Architecture::Powerpc64le
| Architecture::Riscv32
| Architecture::Riscv64
| Architecture::Thumbv6m
| Architecture::Thumbv7em
| Architecture::Thumbv7m
| Architecture::Wasm32
| Architecture::X86_64 => Ok(Endianness::Little),
Architecture::Mips
| Architecture::Mips64
| Architecture::Powerpc
| Architecture::Powerpc64
| Architecture::S390x
| Architecture::Sparc
| Architecture::Sparc64
| Architecture::Sparcv9 => Ok(Endianness::Big),
}
}

Expand All @@ -157,34 +157,34 @@ impl Architecture {
match *self {
Architecture::Unknown => Err(()),
Architecture::Msp430 => Ok(PointerWidth::U16),
Architecture::Arm |
Architecture::Armv4t |
Architecture::Armv5te |
Architecture::Armv7 |
Architecture::Armv7s |
Architecture::Asmjs |
Architecture::I386 |
Architecture::I586 |
Architecture::I686 |
Architecture::Mipsel |
Architecture::Riscv32 |
Architecture::Sparc |
Architecture::Thumbv6m |
Architecture::Thumbv7em |
Architecture::Thumbv7m |
Architecture::Wasm32 |
Architecture::Mips |
Architecture::Powerpc => Ok(PointerWidth::U32),
Architecture::Aarch64 |
Architecture::Mips64el |
Architecture::Powerpc64le |
Architecture::Riscv64 |
Architecture::X86_64 |
Architecture::Mips64 |
Architecture::Powerpc64 |
Architecture::S390x |
Architecture::Sparc64 |
Architecture::Sparcv9 => Ok(PointerWidth::U64),
Architecture::Arm
| Architecture::Armv4t
| Architecture::Armv5te
| Architecture::Armv7
| Architecture::Armv7s
| Architecture::Asmjs
| Architecture::I386
| Architecture::I586
| Architecture::I686
| Architecture::Mipsel
| Architecture::Riscv32
| Architecture::Sparc
| Architecture::Thumbv6m
| Architecture::Thumbv7em
| Architecture::Thumbv7m
| Architecture::Wasm32
| Architecture::Mips
| Architecture::Powerpc => Ok(PointerWidth::U32),
Architecture::Aarch64
| Architecture::Mips64el
| Architecture::Powerpc64le
| Architecture::Riscv64
| Architecture::X86_64
| Architecture::Mips64
| Architecture::Powerpc64
| Architecture::S390x
| Architecture::Sparc64
| Architecture::Sparcv9 => Ok(PointerWidth::U64),
}
}
}
Expand All @@ -195,9 +195,7 @@ pub fn default_binary_format(triple: &Triple) -> BinaryFormat {
match triple.operating_system {
OperatingSystem::Darwin | OperatingSystem::Ios => BinaryFormat::Macho,
OperatingSystem::Windows => BinaryFormat::Coff,
OperatingSystem::Nebulet |
OperatingSystem::Emscripten |
OperatingSystem::Unknown => {
OperatingSystem::Nebulet | OperatingSystem::Emscripten | OperatingSystem::Unknown => {
match triple.architecture {
Architecture::Wasm32 => BinaryFormat::Wasm,
_ => BinaryFormat::Unknown,
Expand Down
24 changes: 12 additions & 12 deletions src/triple.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This file defines the `Triple` type and support code shared by all targets.

use parse_error::ParseError;
use std::borrow::ToOwned;
use std::str::FromStr;
use std::fmt;
use parse_error::ParseError;
use targets::{Architecture, Vendor, OperatingSystem, Environment, BinaryFormat,
default_binary_format};
use std::str::FromStr;
use targets::{default_binary_format, Architecture, BinaryFormat, Environment, OperatingSystem,
Vendor};

/// The target memory endianness.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -121,15 +121,15 @@ impl fmt::Display for Triple {
let implied_binary_format = default_binary_format(&self);

write!(f, "{}", self.architecture)?;
if self.vendor == Vendor::Unknown && self.operating_system == OperatingSystem::Unknown &&
(self.environment != Environment::Unknown ||
self.binary_format != implied_binary_format)
if self.vendor == Vendor::Unknown && self.operating_system == OperatingSystem::Unknown
&& (self.environment != Environment::Unknown
|| self.binary_format != implied_binary_format)
{
// "none" is special-case shorthand for unknown vendor and unknown operating system.
f.write_str("-none")?;
} else if self.operating_system == OperatingSystem::Linux &&
(self.environment == Environment::Android ||
self.environment == Environment::Androideabi)
} else if self.operating_system == OperatingSystem::Linux
&& (self.environment == Environment::Android
|| self.environment == Environment::Androideabi)
{
// As a special case, omit the vendor for Android targets.
write!(f, "-{}", self.operating_system)?;
Expand Down Expand Up @@ -244,9 +244,9 @@ impl FromStr for Triple {
/// or so to report errors at compile time instead.
#[macro_export]
macro_rules! triple {
($str: tt) => (
($str:tt) => {
target_lexicon::Triple::from_str($str).expect("invalid triple literal")
);
};
}

#[cfg(test)]
Expand Down

0 comments on commit a6763b9

Please sign in to comment.