mirror of
https://github.com/github/codeql.git
synced 2026-04-22 15:25:18 +02:00
Rust: replace singleton vectors with Option
This commit is contained in:
@@ -346,12 +346,9 @@ fn emit_function(
|
||||
trap: &mut TrapFile,
|
||||
function: ra_ap_hir_def::FunctionId,
|
||||
visibility: Visibility,
|
||||
) -> Vec<trap::Label<generated::Item>> {
|
||||
let mut items = Vec::new();
|
||||
if let Some(type_) = db.value_ty(function.into()) {
|
||||
items.push(const_or_function(db, name, trap, type_, visibility));
|
||||
}
|
||||
items
|
||||
) -> Option<trap::Label<generated::Item>> {
|
||||
db.value_ty(function.into())
|
||||
.map(|type_| const_or_function(db, name, trap, type_, visibility))
|
||||
}
|
||||
|
||||
fn emit_const(
|
||||
@@ -360,8 +357,7 @@ fn emit_const(
|
||||
trap: &mut TrapFile,
|
||||
konst: ra_ap_hir_def::ConstId,
|
||||
visibility: Visibility,
|
||||
) -> Vec<trap::Label<generated::Item>> {
|
||||
let mut items = Vec::new();
|
||||
) -> Option<trap::Label<generated::Item>> {
|
||||
let type_ = db.value_ty(konst.into());
|
||||
let type_repr = type_.and_then(|type_| emit_hir_ty(trap, db, type_.skip_binders()));
|
||||
let name = Some(trap.emit(generated::Name {
|
||||
@@ -370,7 +366,7 @@ fn emit_const(
|
||||
}));
|
||||
let konst = db.const_data(konst);
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Const {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -382,8 +378,7 @@ fn emit_const(
|
||||
visibility,
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
items
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_static(
|
||||
@@ -392,8 +387,7 @@ fn emit_static(
|
||||
trap: &mut TrapFile,
|
||||
statik: ra_ap_hir_def::StaticId,
|
||||
visibility: Visibility,
|
||||
) -> Vec<trap::Label<generated::Item>> {
|
||||
let mut items = Vec::new();
|
||||
) -> Option<trap::Label<generated::Item>> {
|
||||
let type_ = db.value_ty(statik.into());
|
||||
let type_repr = type_.and_then(|type_| emit_hir_ty(trap, db, type_.skip_binders()));
|
||||
let name = Some(trap.emit(generated::Name {
|
||||
@@ -402,7 +396,7 @@ fn emit_static(
|
||||
}));
|
||||
let statik = db.static_data(statik);
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Static {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -415,8 +409,7 @@ fn emit_static(
|
||||
is_unsafe: statik.has_unsafe_kw(),
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
items
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_generic_param_list(
|
||||
@@ -517,9 +510,7 @@ fn emit_adt(
|
||||
trap: &mut TrapFile,
|
||||
adt_id: ra_ap_hir_def::AdtId,
|
||||
visibility: Visibility,
|
||||
) -> Vec<trap::Label<generated::Item>> {
|
||||
let mut items = Vec::new();
|
||||
|
||||
) -> Option<trap::Label<generated::Item>> {
|
||||
match adt_id {
|
||||
ra_ap_hir_def::AdtId::StructId(struct_id) => {
|
||||
let name = Some(trap.emit(generated::Name {
|
||||
@@ -529,7 +520,7 @@ fn emit_adt(
|
||||
let field_list = emit_variant_data(trap, db, struct_id.into()).into();
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
let generic_param_list = emit_generic_param_list(trap, db, adt_id.into());
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Struct {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -540,7 +531,7 @@ fn emit_adt(
|
||||
where_clause: None,
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
)
|
||||
}
|
||||
ra_ap_hir_def::AdtId::EnumId(enum_id) => {
|
||||
let data = db.enum_variants(enum_id);
|
||||
@@ -574,7 +565,7 @@ fn emit_adt(
|
||||
}));
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
let generic_param_list = emit_generic_param_list(trap, db, adt_id.into());
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Enum {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -585,7 +576,7 @@ fn emit_adt(
|
||||
where_clause: None,
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
)
|
||||
}
|
||||
ra_ap_hir_def::AdtId::UnionId(union_id) => {
|
||||
let name = Some(trap.emit(generated::Name {
|
||||
@@ -595,7 +586,7 @@ fn emit_adt(
|
||||
let struct_field_list = emit_variant_data(trap, db, union_id.into()).into();
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
let generic_param_list = emit_generic_param_list(trap, db, adt_id.into());
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Union {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -606,10 +597,9 @@ fn emit_adt(
|
||||
where_clause: None,
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
fn emit_trait(
|
||||
@@ -618,8 +608,7 @@ fn emit_trait(
|
||||
trap: &mut TrapFile,
|
||||
trait_id: ra_ap_hir_def::TraitId,
|
||||
visibility: Visibility,
|
||||
) -> Vec<trap::Label<generated::Item>> {
|
||||
let mut items = Vec::new();
|
||||
) -> Option<trap::Label<generated::Item>> {
|
||||
let trait_items = db.trait_items(trait_id);
|
||||
let assoc_items: Vec<trap::Label<generated::AssocItem>> = trait_items
|
||||
.items
|
||||
@@ -696,7 +685,7 @@ fn emit_trait(
|
||||
}));
|
||||
let visibility = emit_visibility(db, trap, visibility);
|
||||
let generic_param_list = emit_generic_param_list(trap, db, trait_id.into());
|
||||
items.push(
|
||||
Some(
|
||||
trap.emit(generated::Trait {
|
||||
id: trap::TrapId::Star,
|
||||
name,
|
||||
@@ -710,8 +699,7 @@ fn emit_trait(
|
||||
where_clause: None,
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
items
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_module_impls(
|
||||
|
||||
Reference in New Issue
Block a user