Skip to content

Commit 36381fa

Browse files
committed
Warn on repr without hints
1 parent 41affd0 commit 36381fa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,7 @@ register_diagnostics! {
21392139
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
21402140
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
21412141
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
2142+
E0689, // `#[repr]` must have a hint
21422143

21432144
E0906, // closures cannot be static
21442145
}

src/librustc/hir/check_attr.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,22 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
154154
let hints: Vec<_> = item.attrs
155155
.iter()
156156
.filter(|attr| attr.name() == "repr")
157-
.filter_map(|attr| attr.meta_item_list())
157+
.filter_map(|attr| {
158+
let list = attr.meta_item_list();
159+
let mut has_hints = false;
160+
if let Some(ref list) = list {
161+
has_hints = !list.is_empty();
162+
}
163+
if !has_hints {
164+
span_warn!(
165+
self.tcx.sess,
166+
item.span,
167+
E0689,
168+
"`repr` attribute cannot be empty",
169+
);
170+
}
171+
list
172+
})
158173
.flat_map(|hints| hints)
159174
.collect();
160175

0 commit comments

Comments
 (0)