Warn on repr without hints

This commit is contained in:
Esteban Küber 2018-06-06 10:02:09 -07:00
parent 41affd03eb
commit 36381fabaf
2 changed files with 17 additions and 1 deletions

View file

@ -2139,6 +2139,7 @@ register_diagnostics! {
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0689, // `#[repr]` must have a hint
E0906, // closures cannot be static
}

View file

@ -154,7 +154,22 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
let hints: Vec<_> = item.attrs
.iter()
.filter(|attr| attr.name() == "repr")
.filter_map(|attr| attr.meta_item_list())
.filter_map(|attr| {
let list = attr.meta_item_list();
let mut has_hints = false;
if let Some(ref list) = list {
has_hints = !list.is_empty();
}
if !has_hints {
span_warn!(
self.tcx.sess,
item.span,
E0689,
"`repr` attribute cannot be empty",
);
}
list
})
.flat_map(|hints| hints)
.collect();