Merge attrs, better validation
This commit is contained in:
parent
91e5c3f2e5
commit
ca68cf0d46
16 changed files with 140 additions and 73 deletions
|
@ -985,8 +985,50 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
|||
|
||||
no_dups.then_some(list)
|
||||
});
|
||||
let do_not_implement_via_object = tcx.has_attr(def_id, sym::rustc_do_not_implement_via_object);
|
||||
let deny_explicit_impl = tcx.has_attr(def_id, sym::rustc_deny_explicit_impl);
|
||||
|
||||
let mut deny_explicit_impl = false;
|
||||
let mut implement_via_object = true;
|
||||
if let Some(attr) = tcx.get_attr(def_id, sym::rustc_deny_explicit_impl) {
|
||||
deny_explicit_impl = true;
|
||||
let mut seen_attr = false;
|
||||
for meta in attr.meta_item_list().iter().flatten() {
|
||||
if let Some(meta) = meta.meta_item()
|
||||
&& meta.name_or_empty() == sym::implement_via_object
|
||||
&& let Some(lit) = meta.name_value_literal()
|
||||
{
|
||||
if seen_attr {
|
||||
tcx.sess.span_err(
|
||||
meta.span,
|
||||
"duplicated `implement_via_object` meta item",
|
||||
);
|
||||
}
|
||||
seen_attr = true;
|
||||
|
||||
match lit.symbol {
|
||||
kw::True => {
|
||||
implement_via_object = true;
|
||||
}
|
||||
kw::False => {
|
||||
implement_via_object = false;
|
||||
}
|
||||
_ => {
|
||||
tcx.sess.span_err(
|
||||
meta.span,
|
||||
format!("unknown literal passed to `implement_via_object` attribute: {}", lit.symbol),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tcx.sess.span_err(
|
||||
meta.span(),
|
||||
format!("unknown meta item passed to `rustc_deny_explicit_impl` {:?}", meta),
|
||||
);
|
||||
}
|
||||
}
|
||||
if !seen_attr {
|
||||
tcx.sess.span_err(attr.span, "missing `implement_via_object` meta item");
|
||||
}
|
||||
}
|
||||
|
||||
ty::TraitDef {
|
||||
def_id: def_id.to_def_id(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue