Skip to content

Commit ea8a285

Browse files
authored
experiment with stable-only rustfmt options (#28)
1 parent e2393f8 commit ea8a285

16 files changed

+130
-289
lines changed

.github/workflows/rust.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ jobs:
1111
steps:
1212
# actions/checkout@v2
1313
- uses: actions/checkout@28c7f3d2b5162b5ddd3dfd9a45aa55eaf396478b
14-
- uses: actions-rs/toolchain@b223206e28798aa3c3668bdd6409258e6dc29172
15-
with:
16-
toolchain: nightly-2020-06-02
17-
default: false
18-
components: rustfmt
1914
- name: Check style
20-
run: cargo +nightly-2020-06-02 fmt -- --check
15+
run: cargo fmt -- --check
2116

2217
build-and-test:
2318
runs-on: ${{ matrix.os }}

.vscode/settings.json

-8
This file was deleted.

README.adoc

+5-8
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ https://61.rfd.oxide.computer[RFD 61].
2323

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

3128
[source,text]
3229
----
33-
$ cargo +nightly doc --document-private-items
30+
$ cargo doc --document-private-items
3431
----
3532

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

3936
== Status
4037

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

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

6562
To **run the system:** there are two executables: the `oxide_controller` (which
6663
is a real prototype backed by an in-memory store; this component manages an

rustfmt.toml

-90
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,4 @@
33
# ---------------------------------------------------------------------------
44
max_width = 80
55
use_small_heuristics = "max"
6-
unstable_features = true
7-
8-
#
9-
# ---------------------------------------------------------------------------
10-
# Unstable features that we customize locally
11-
# ---------------------------------------------------------------------------
12-
#
13-
# We would like to use "wrap_comments = true" and "comment_width = 80", but
14-
# there are several issues with our use of it today, including rustfmt#4079 and
15-
# rustfmt#4020.
16-
#
17-
# "overflow_delimited_expr" and "struct_lit_single_line" are both fairly minor,
18-
# but improve readability.
19-
#
20-
format_strings = true
21-
overflow_delimited_expr = true
22-
struct_lit_single_line = false
23-
24-
#
25-
# ---------------------------------------------------------------------------
26-
# Below are all other flags that we do NOT customize. We specify these
27-
# explicitly here to minimize churn if the upstream defaults change. If you
28-
# modify any of these, move them above this line!
29-
#
30-
# The following can be generated by starting with:
31-
#
32-
# rustfmt +nightly --print-config=default
33-
#
34-
# and removing anything that we've configured above.
35-
# ---------------------------------------------------------------------------
36-
#
37-
hard_tabs = false
38-
tab_spaces = 4
39-
newline_style = "Auto"
40-
indent_style = "Block"
41-
wrap_comments = false
42-
format_code_in_doc_comments = false
43-
comment_width = 80
44-
normalize_comments = false
45-
normalize_doc_attributes = false
46-
license_template_path = ""
47-
format_macro_matchers = false
48-
format_macro_bodies = true
49-
empty_item_single_line = true
50-
fn_single_line = false
51-
where_single_line = false
52-
imports_indent = "Block"
53-
imports_layout = "Mixed"
54-
merge_imports = false
55-
reorder_imports = true
56-
reorder_modules = true
57-
reorder_impl_items = false
58-
type_punctuation_density = "Wide"
59-
space_before_colon = false
60-
space_after_colon = true
61-
spaces_around_ranges = false
62-
binop_separator = "Front"
63-
remove_nested_parens = true
64-
combine_control_expr = true
65-
struct_field_align_threshold = 0
66-
enum_discrim_align_threshold = 0
67-
match_arm_blocks = true
68-
force_multiline_blocks = false
69-
fn_args_layout = "Tall"
70-
brace_style = "SameLineWhere"
71-
control_brace_style = "AlwaysSameLine"
72-
trailing_semicolon = true
73-
trailing_comma = "Vertical"
74-
match_block_trailing_comma = false
75-
blank_lines_upper_bound = 1
76-
blank_lines_lower_bound = 0
776
edition = "2018"
78-
version = "One"
79-
inline_attribute_width = 0
80-
merge_derives = true
81-
use_try_shorthand = false
82-
use_field_init_shorthand = false
83-
force_explicit_abi = true
84-
condense_wildcard_suffixes = false
85-
color = "Auto"
86-
required_version = "1.4.15"
87-
disable_all_formatting = false
88-
skip_children = false
89-
hide_parse_errors = false
90-
error_on_line_overflow = false
91-
error_on_unformatted = false
92-
report_todo = "Never"
93-
report_fixme = "Never"
94-
ignore = []
95-
emit_mode = "Files"
96-
make_backup = false

src/api_error.rs

+11-24
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ impl ApiError {
110110
* include more information in the HttpErrorResponseBody.
111111
*/
112112
match error_response.error_code.as_deref() {
113-
Some("InvalidRequest") => ApiError::InvalidRequest {
114-
message: error_response.message,
115-
},
113+
Some("InvalidRequest") => {
114+
ApiError::InvalidRequest { message: error_response.message }
115+
}
116116
_ => ApiError::InternalError {
117117
message: format!(
118118
"{}: unknown error from dependency: {:?}",
@@ -131,10 +131,7 @@ impl From<ApiError> for HttpError {
131131
*/
132132
fn from(error: ApiError) -> HttpError {
133133
match error {
134-
ApiError::ObjectNotFound {
135-
type_name: t,
136-
lookup_type: lt,
137-
} => {
134+
ApiError::ObjectNotFound { type_name: t, lookup_type: lt } => {
138135
if let LookupType::Other(message) = lt {
139136
HttpError::for_client_error(
140137
Some(String::from("ObjectNotFound")),
@@ -160,28 +157,20 @@ impl From<ApiError> for HttpError {
160157
}
161158
}
162159

163-
ApiError::ObjectAlreadyExists {
164-
type_name: t,
165-
object_name: n,
166-
} => {
160+
ApiError::ObjectAlreadyExists { type_name: t, object_name: n } => {
167161
let message = format!("already exists: {} \"{}\"", t, n);
168162
HttpError::for_bad_request(
169163
Some(String::from("ObjectAlreadyExists")),
170164
message,
171165
)
172166
}
173167

174-
ApiError::InvalidRequest {
175-
message,
176-
} => HttpError::for_bad_request(
168+
ApiError::InvalidRequest { message } => HttpError::for_bad_request(
177169
Some(String::from("InvalidRequest")),
178170
message,
179171
),
180172

181-
ApiError::InvalidValue {
182-
label,
183-
message,
184-
} => {
173+
ApiError::InvalidValue { label, message } => {
185174
let message =
186175
format!("unsupported value for \"{}\": {}", label, message);
187176
HttpError::for_bad_request(
@@ -190,13 +179,11 @@ impl From<ApiError> for HttpError {
190179
)
191180
}
192181

193-
ApiError::InternalError {
194-
message,
195-
} => HttpError::for_internal_error(message),
182+
ApiError::InternalError { message } => {
183+
HttpError::for_internal_error(message)
184+
}
196185

197-
ApiError::ServiceUnavailable {
198-
message,
199-
} => HttpError::for_unavail(
186+
ApiError::ServiceUnavailable { message } => HttpError::for_unavail(
200187
Some(String::from("ServiceNotAvailable")),
201188
message,
202189
),

src/api_model.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,18 @@ pub enum ApiResourceType {
320320

321321
impl Display for ApiResourceType {
322322
fn fmt(&self, f: &mut Formatter) -> FormatResult {
323-
write!(f, "{}", match self {
324-
ApiResourceType::Project => "project",
325-
ApiResourceType::Disk => "disk",
326-
ApiResourceType::DiskAttachment => "disk attachment",
327-
ApiResourceType::Instance => "instance",
328-
ApiResourceType::Rack => "rack",
329-
ApiResourceType::Sled => "sled",
330-
})
323+
write!(
324+
f,
325+
"{}",
326+
match self {
327+
ApiResourceType::Project => "project",
328+
ApiResourceType::Disk => "disk",
329+
ApiResourceType::DiskAttachment => "disk attachment",
330+
ApiResourceType::Instance => "instance",
331+
ApiResourceType::Rack => "rack",
332+
ApiResourceType::Sled => "sled",
333+
}
334+
)
331335
}
332336
}
333337

@@ -454,9 +458,7 @@ pub struct ApiProject {
454458
impl ApiObject for ApiProject {
455459
type View = ApiProjectView;
456460
fn to_view(&self) -> ApiProjectView {
457-
ApiProjectView {
458-
identity: self.identity.clone(),
459-
}
461+
ApiProjectView { identity: self.identity.clone() }
460462
}
461463
}
462464

@@ -946,9 +948,7 @@ pub struct ApiRack {
946948
impl ApiObject for ApiRack {
947949
type View = ApiRackView;
948950
fn to_view(&self) -> ApiRackView {
949-
ApiRackView {
950-
identity: self.identity.clone(),
951-
}
951+
ApiRackView { identity: self.identity.clone() }
952952
}
953953
}
954954

src/bin/sled_agent.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ async fn do_run() -> Result<(), CmdError> {
8484
bind_address: sa_addr,
8585
..Default::default()
8686
},
87-
log: ConfigLogging::StderrTerminal {
88-
level: ConfigLoggingLevel::Info,
89-
},
87+
log: ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info },
9088
};
9189

9290
sa_run_server(&config).await.map_err(CmdError::Failure)

0 commit comments

Comments
 (0)