This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +17
-7
lines changed
tests/ui/type-alias-impl-trait/define_opaques_attr Expand file tree Collapse file tree 6 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -1696,7 +1696,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16961696 ) ;
16971697 return None ;
16981698 } ;
1699- Some ( did)
1699+ Some ( ( self . lower_span ( path . span ) , did) )
17001700 } ) ;
17011701 let define_opaque = self . arena . alloc_from_iter ( define_opaque) ;
17021702 self . define_opaque = Some ( define_opaque) ;
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
9999 /// Bodies inside the owner being lowered.
100100 bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
101101 /// `#[define_opaque]` attributes
102- define_opaque : Option < & ' hir [ LocalDefId ] > ,
102+ define_opaque : Option < & ' hir [ ( Span , LocalDefId ) ] > ,
103103 /// Attributes inside the owner being lowered.
104104 attrs : SortedMap < hir:: ItemLocalId , & ' hir [ hir:: Attribute ] > ,
105105 /// Collect items that were created by lowering the current owner.
Original file line number Diff line number Diff line change @@ -1308,7 +1308,7 @@ impl Attribute {
13081308pub struct AttributeMap < ' tcx > {
13091309 pub map : SortedMap < ItemLocalId , & ' tcx [ Attribute ] > ,
13101310 /// Preprocessed `#[define_opaque]` attribute.
1311- pub define_opaque : Option < & ' tcx [ LocalDefId ] > ,
1311+ pub define_opaque : Option < & ' tcx [ ( Span , LocalDefId ) ] > ,
13121312 // Only present when the crate hash is needed.
13131313 pub opt_hash : Option < Fingerprint > ,
13141314}
Original file line number Diff line number Diff line change @@ -190,11 +190,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
190190 let Some ( defines) = self . tcx . hir_attrs ( hir_id. owner ) . define_opaque else {
191191 return ;
192192 } ;
193- for & define in defines {
193+ for & ( span , define) in defines {
194194 trace ! ( ?define) ;
195195 let mode = std:: mem:: replace ( & mut self . mode , CollectionMode :: Taits ) ;
196- // TODO: check that opaque types were introduced and error otherwise (also add tests)
196+ let n = self . opaques . len ( ) ;
197197 super :: sig_types:: walk_types ( self . tcx , define, self ) ;
198+ if n == self . opaques . len ( ) {
199+ self . tcx . dcx ( ) . span_err ( span, "item does not contain any opaque types" ) ;
200+ }
198201 self . mode = mode;
199202 }
200203 // Allow using `#[define_opaque]` on assoc methods and type aliases to override the default collection mode in
Original file line number Diff line number Diff line change 1- //@ check-pass
2-
31#![ feature( type_alias_impl_trait) ]
42
53type Thing = ( ) ;
64
75#[ define_opaque( Thing ) ]
6+ //~^ ERROR item does not contain any opaque types
87fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: item does not contain any opaque types
2+ --> $DIR/no_opaque.rs:5:17
3+ |
4+ LL | #[define_opaque(Thing)]
5+ | ^^^^^
6+
7+ error: aborting due to 1 previous error
8+
You can’t perform that action at this time.
0 commit comments