Skip to content

Commit

Permalink
Warn on repr without hints
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 6, 2018
1 parent 41affd0 commit 36381fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 16 additions & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 36381fa

Please sign in to comment.