Skip to content

Commit 0da1532

Browse files
committed
Minor code style
1 parent 4368a3b commit 0da1532

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

crates/ide/src/runnables.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,17 @@ pub(crate) fn runnable(
111111
}
112112
}
113113

114-
fn runnable_fn(
115-
sema: &Semantics<RootDatabase>,
116-
fn_def: ast::Fn,
117-
file_id: FileId,
118-
) -> Option<Runnable> {
119-
let def = sema.to_def(&fn_def)?;
120-
let name_string = fn_def.name()?.text().to_string();
114+
fn runnable_fn(sema: &Semantics<RootDatabase>, func: ast::Fn, file_id: FileId) -> Option<Runnable> {
115+
let def = sema.to_def(&func)?;
116+
let name_string = func.name()?.text().to_string();
121117

122118
let attrs = def.attrs(sema.db);
123119
let kind = if name_string == "main" {
124120
RunnableKind::Bin
125121
} else {
126-
let test_id = match sema.to_def(&fn_def).map(|def| def.module(sema.db)) {
122+
let test_id = match sema.to_def(&func).map(|def| def.module(sema.db)) {
127123
Some(module) => {
128-
let def = sema.to_def(&fn_def)?;
124+
let def = sema.to_def(&func)?;
129125
let impl_trait_name = def.as_assoc_item(sema.db).and_then(|assoc_item| {
130126
match assoc_item.container(sema.db) {
131127
hir::AssocItemContainer::Trait(trait_item) => {
@@ -159,10 +155,10 @@ fn runnable_fn(
159155
None => TestId::Name(name_string),
160156
};
161157

162-
if test_related_attribute(&fn_def).is_some() {
163-
let attr = TestAttr::from_fn(&fn_def);
158+
if test_related_attribute(&func).is_some() {
159+
let attr = TestAttr::from_fn(&func);
164160
RunnableKind::Test { test_id, attr }
165-
} else if fn_def.has_atom_attr("bench") {
161+
} else if func.has_atom_attr("bench") {
166162
RunnableKind::Bench { test_id }
167163
} else if has_runnable_doc_test(&attrs) {
168164
RunnableKind::DocTest { test_id }
@@ -171,35 +167,31 @@ fn runnable_fn(
171167
}
172168
};
173169

174-
let cfg = attrs.cfg();
175-
176170
let nav = if let RunnableKind::DocTest { .. } = kind {
177171
NavigationTarget::from_doc_commented(
178172
sema.db,
179-
InFile::new(file_id.into(), &fn_def),
180-
InFile::new(file_id.into(), &fn_def),
173+
InFile::new(file_id.into(), &func),
174+
InFile::new(file_id.into(), &func),
181175
)
182176
} else {
183-
NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def))
177+
NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &func))
184178
};
185-
Some(Runnable { nav, kind, cfg })
179+
Some(Runnable { nav, kind, cfg: attrs.cfg() })
186180
}
187181

188182
fn runnable_struct(
189183
sema: &Semantics<RootDatabase>,
190-
struct_def: ast::Struct,
184+
strukt: ast::Struct,
191185
file_id: FileId,
192186
) -> Option<Runnable> {
193-
let def = sema.to_def(&struct_def)?;
194-
let name_string = struct_def.name()?.text().to_string();
187+
let def = sema.to_def(&strukt)?;
188+
let name_string = strukt.name()?.text().to_string();
195189

196190
let attrs = def.attrs(sema.db);
197191
if !has_runnable_doc_test(&attrs) {
198192
return None;
199193
}
200-
let cfg = attrs.cfg();
201-
202-
let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) {
194+
let test_id = match sema.to_def(&strukt).map(|def| def.module(sema.db)) {
203195
Some(module) => {
204196
let path_iter = module
205197
.path_to_root(sema.db)
@@ -216,10 +208,10 @@ fn runnable_struct(
216208

217209
let nav = NavigationTarget::from_doc_commented(
218210
sema.db,
219-
InFile::new(file_id.into(), &struct_def),
220-
InFile::new(file_id.into(), &struct_def),
211+
InFile::new(file_id.into(), &strukt),
212+
InFile::new(file_id.into(), &strukt),
221213
);
222-
Some(Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg })
214+
Some(Runnable { nav, kind: RunnableKind::DocTest { test_id }, cfg: attrs.cfg() })
223215
}
224216

225217
#[derive(Debug, Copy, Clone)]

0 commit comments

Comments
 (0)