Skip to content
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

experiment with stable-only rustfmt options #28

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 1 addition & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ jobs:
steps:
# actions/checkout@v2
- uses: actions/checkout@28c7f3d2b5162b5ddd3dfd9a45aa55eaf396478b
- uses: actions-rs/toolchain@b223206e28798aa3c3668bdd6409258e6dc29172
with:
toolchain: nightly-2020-06-02
default: false
components: rustfmt
- name: Check style
run: cargo +nightly-2020-06-02 fmt -- --check
run: cargo fmt -- --check

build-and-test:
runs-on: ${{ matrix.os }}
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"rust-analyzer.rustfmt.overrideCommand": [
"rustup",
"run",
"nightly-2020-06-02",
"rustfmt"
]
}
13 changes: 5 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ https://61.rfd.oxide.computer[RFD 61].

For design and API docs, see the
https://rust.docs.corp.oxide.computer/oxide_api_prototype/[generated
documentation]. You can generate this yourself withfootnote:[Like many other
Rust crates, the rustdoc in this crate makes heavy use of
https://doc.rust-lang.org/rustdoc/unstable-features.html?highlight=link#linking-to-items-by-type[intra-document
linking], which requires a nightly version of `rustdoc`.]:
documentation]. You can generate this yourself with:

[source,text]
----
$ cargo +nightly doc --document-private-items
$ cargo doc --document-private-items
----

Note that `--document-private-items` is configured by default, so you can
actually just use `cargo +nightly doc`.
actually just use `cargo doc`.

== Status

Expand All @@ -59,8 +56,8 @@ See TODO.adoc for more info.
You can **build and run the whole test suite** with `cargo test`. The test
suite runs cleanly and should remain clean.

You can **format the code** using `cargo +nightly fmt`. Make sure to run this
before pushing changes. The CI checks that the code is correctly formatted.
You can **format the code** using `cargo fmt`. Make sure to run this before
pushing changes. The CI checks that the code is correctly formatted.

To **run the system:** there are two executables: the `oxide_controller` (which
is a real prototype backed by an in-memory store; this component manages an
Expand Down
90 changes: 0 additions & 90 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,4 @@
# ---------------------------------------------------------------------------
max_width = 80
use_small_heuristics = "max"
unstable_features = true

#
# ---------------------------------------------------------------------------
# Unstable features that we customize locally
# ---------------------------------------------------------------------------
#
# We would like to use "wrap_comments = true" and "comment_width = 80", but
# there are several issues with our use of it today, including rustfmt#4079 and
# rustfmt#4020.
#
# "overflow_delimited_expr" and "struct_lit_single_line" are both fairly minor,
# but improve readability.
#
format_strings = true
overflow_delimited_expr = true
struct_lit_single_line = false

#
# ---------------------------------------------------------------------------
# Below are all other flags that we do NOT customize. We specify these
# explicitly here to minimize churn if the upstream defaults change. If you
# modify any of these, move them above this line!
#
# The following can be generated by starting with:
#
# rustfmt +nightly --print-config=default
#
# and removing anything that we've configured above.
# ---------------------------------------------------------------------------
#
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
indent_style = "Block"
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
merge_imports = false
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = false
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2018"
smklein marked this conversation as resolved.
Show resolved Hide resolved
version = "One"
inline_attribute_width = 0
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.15"
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false
35 changes: 11 additions & 24 deletions src/api_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ impl ApiError {
* include more information in the HttpErrorResponseBody.
*/
match error_response.error_code.as_deref() {
Some("InvalidRequest") => ApiError::InvalidRequest {
message: error_response.message,
},
Some("InvalidRequest") => {
ApiError::InvalidRequest { message: error_response.message }
}
_ => ApiError::InternalError {
message: format!(
"{}: unknown error from dependency: {:?}",
Expand All @@ -131,10 +131,7 @@ impl From<ApiError> for HttpError {
*/
fn from(error: ApiError) -> HttpError {
match error {
ApiError::ObjectNotFound {
type_name: t,
lookup_type: lt,
} => {
ApiError::ObjectNotFound { type_name: t, lookup_type: lt } => {
if let LookupType::Other(message) = lt {
HttpError::for_client_error(
Some(String::from("ObjectNotFound")),
Expand All @@ -160,28 +157,20 @@ impl From<ApiError> for HttpError {
}
}

ApiError::ObjectAlreadyExists {
type_name: t,
object_name: n,
} => {
ApiError::ObjectAlreadyExists { type_name: t, object_name: n } => {
let message = format!("already exists: {} \"{}\"", t, n);
HttpError::for_bad_request(
Some(String::from("ObjectAlreadyExists")),
message,
)
}

ApiError::InvalidRequest {
message,
} => HttpError::for_bad_request(
ApiError::InvalidRequest { message } => HttpError::for_bad_request(
Some(String::from("InvalidRequest")),
message,
),

ApiError::InvalidValue {
label,
message,
} => {
ApiError::InvalidValue { label, message } => {
let message =
format!("unsupported value for \"{}\": {}", label, message);
HttpError::for_bad_request(
Expand All @@ -190,13 +179,11 @@ impl From<ApiError> for HttpError {
)
}

ApiError::InternalError {
message,
} => HttpError::for_internal_error(message),
ApiError::InternalError { message } => {
HttpError::for_internal_error(message)
}

ApiError::ServiceUnavailable {
message,
} => HttpError::for_unavail(
ApiError::ServiceUnavailable { message } => HttpError::for_unavail(
Some(String::from("ServiceNotAvailable")),
message,
),
Expand Down
28 changes: 14 additions & 14 deletions src/api_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,18 @@ pub enum ApiResourceType {

impl Display for ApiResourceType {
fn fmt(&self, f: &mut Formatter) -> FormatResult {
write!(f, "{}", match self {
ApiResourceType::Project => "project",
ApiResourceType::Disk => "disk",
ApiResourceType::DiskAttachment => "disk attachment",
ApiResourceType::Instance => "instance",
ApiResourceType::Rack => "rack",
ApiResourceType::Sled => "sled",
})
write!(
f,
"{}",
match self {
ApiResourceType::Project => "project",
ApiResourceType::Disk => "disk",
ApiResourceType::DiskAttachment => "disk attachment",
ApiResourceType::Instance => "instance",
ApiResourceType::Rack => "rack",
ApiResourceType::Sled => "sled",
}
)
}
}

Expand Down Expand Up @@ -454,9 +458,7 @@ pub struct ApiProject {
impl ApiObject for ApiProject {
type View = ApiProjectView;
fn to_view(&self) -> ApiProjectView {
ApiProjectView {
identity: self.identity.clone(),
}
ApiProjectView { identity: self.identity.clone() }
}
}

Expand Down Expand Up @@ -946,9 +948,7 @@ pub struct ApiRack {
impl ApiObject for ApiRack {
type View = ApiRackView;
fn to_view(&self) -> ApiRackView {
ApiRackView {
identity: self.identity.clone(),
}
ApiRackView { identity: self.identity.clone() }
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/bin/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ async fn do_run() -> Result<(), CmdError> {
bind_address: sa_addr,
..Default::default()
},
log: ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Info,
},
log: ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info },
};

sa_run_server(&config).await.map_err(CmdError::Failure)
Expand Down
Loading