Error on define_opaques
entries without any opaques actually referenced
This commit is contained in:
parent
43e39260f9
commit
69a1bb8bdb
6 changed files with 17 additions and 7 deletions
|
@ -1696,7 +1696,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
);
|
);
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
Some(did)
|
Some((self.lower_span(path.span), did))
|
||||||
});
|
});
|
||||||
let define_opaque = self.arena.alloc_from_iter(define_opaque);
|
let define_opaque = self.arena.alloc_from_iter(define_opaque);
|
||||||
self.define_opaque = Some(define_opaque);
|
self.define_opaque = Some(define_opaque);
|
||||||
|
|
|
@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
|
||||||
/// Bodies inside the owner being lowered.
|
/// Bodies inside the owner being lowered.
|
||||||
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
|
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
|
||||||
/// `#[define_opaque]` attributes
|
/// `#[define_opaque]` attributes
|
||||||
define_opaque: Option<&'hir [LocalDefId]>,
|
define_opaque: Option<&'hir [(Span, LocalDefId)]>,
|
||||||
/// Attributes inside the owner being lowered.
|
/// Attributes inside the owner being lowered.
|
||||||
attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
|
attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
|
||||||
/// Collect items that were created by lowering the current owner.
|
/// Collect items that were created by lowering the current owner.
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ impl Attribute {
|
||||||
pub struct AttributeMap<'tcx> {
|
pub struct AttributeMap<'tcx> {
|
||||||
pub map: SortedMap<ItemLocalId, &'tcx [Attribute]>,
|
pub map: SortedMap<ItemLocalId, &'tcx [Attribute]>,
|
||||||
/// Preprocessed `#[define_opaque]` attribute.
|
/// Preprocessed `#[define_opaque]` attribute.
|
||||||
pub define_opaque: Option<&'tcx [LocalDefId]>,
|
pub define_opaque: Option<&'tcx [(Span, LocalDefId)]>,
|
||||||
// Only present when the crate hash is needed.
|
// Only present when the crate hash is needed.
|
||||||
pub opt_hash: Option<Fingerprint>,
|
pub opt_hash: Option<Fingerprint>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,11 +190,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
|
||||||
let Some(defines) = self.tcx.hir_attrs(hir_id.owner).define_opaque else {
|
let Some(defines) = self.tcx.hir_attrs(hir_id.owner).define_opaque else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
for &define in defines {
|
for &(span, define) in defines {
|
||||||
trace!(?define);
|
trace!(?define);
|
||||||
let mode = std::mem::replace(&mut self.mode, CollectionMode::Taits);
|
let mode = std::mem::replace(&mut self.mode, CollectionMode::Taits);
|
||||||
// TODO: check that opaque types were introduced and error otherwise (also add tests)
|
let n = self.opaques.len();
|
||||||
super::sig_types::walk_types(self.tcx, define, self);
|
super::sig_types::walk_types(self.tcx, define, self);
|
||||||
|
if n == self.opaques.len() {
|
||||||
|
self.tcx.dcx().span_err(span, "item does not contain any opaque types");
|
||||||
|
}
|
||||||
self.mode = mode;
|
self.mode = mode;
|
||||||
}
|
}
|
||||||
// Allow using `#[define_opaque]` on assoc methods and type aliases to override the default collection mode in
|
// Allow using `#[define_opaque]` on assoc methods and type aliases to override the default collection mode in
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
//@ check-pass
|
|
||||||
|
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
type Thing = ();
|
type Thing = ();
|
||||||
|
|
||||||
#[define_opaque(Thing)]
|
#[define_opaque(Thing)]
|
||||||
|
//~^ ERROR item does not contain any opaque types
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
error: item does not contain any opaque types
|
||||||
|
--> $DIR/no_opaque.rs:5:17
|
||||||
|
|
|
||||||
|
LL | #[define_opaque(Thing)]
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue