Avoid an unwrap
in RustcMirAttrs::set_field
.
This commit is contained in:
parent
2fef0a30ae
commit
846c10fecf
1 changed files with 23 additions and 22 deletions
|
@ -109,8 +109,9 @@ impl RustcMirAttrs {
|
|||
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
|
||||
|
||||
for attr in rustc_mir_attrs {
|
||||
let attr_result = if attr.has_name(sym::borrowck_graphviz_postflow) {
|
||||
Self::set_field(&mut ret.basename_and_suffix, tcx, &attr, |s| {
|
||||
let attr_result = match attr.name() {
|
||||
Some(name @ sym::borrowck_graphviz_postflow) => {
|
||||
Self::set_field(&mut ret.basename_and_suffix, tcx, name, &attr, |s| {
|
||||
let path = PathBuf::from(s.to_string());
|
||||
match path.file_name() {
|
||||
Some(_) => Ok(path),
|
||||
|
@ -120,16 +121,17 @@ impl RustcMirAttrs {
|
|||
}
|
||||
}
|
||||
})
|
||||
} else if attr.has_name(sym::borrowck_graphviz_format) {
|
||||
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
|
||||
}
|
||||
Some(name @ sym::borrowck_graphviz_format) => {
|
||||
Self::set_field(&mut ret.formatter, tcx, name, &attr, |s| match s {
|
||||
sym::two_phase => Ok(s),
|
||||
_ => {
|
||||
tcx.dcx().emit_err(UnknownFormatter { span: attr.span() });
|
||||
Err(())
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
};
|
||||
|
||||
result = result.and(attr_result);
|
||||
|
@ -141,13 +143,12 @@ impl RustcMirAttrs {
|
|||
fn set_field<T>(
|
||||
field: &mut Option<T>,
|
||||
tcx: TyCtxt<'_>,
|
||||
name: Symbol,
|
||||
attr: &ast::MetaItemInner,
|
||||
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
|
||||
) -> Result<(), ()> {
|
||||
// Unwrapping the name is safe because this is only called when `has_name` has succeeded.
|
||||
if field.is_some() {
|
||||
tcx.dcx()
|
||||
.emit_err(DuplicateValuesFor { span: attr.span(), name: attr.name().unwrap() });
|
||||
tcx.dcx().emit_err(DuplicateValuesFor { span: attr.span(), name });
|
||||
|
||||
return Err(());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue