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> {
1696
1696
) ;
1697
1697
return None ;
1698
1698
} ;
1699
- Some ( did)
1699
+ Some ( ( self . lower_span ( path . span ) , did) )
1700
1700
} ) ;
1701
1701
let define_opaques = self . arena . alloc_from_iter ( define_opaques) ;
1702
1702
self . define_opaques = Some ( define_opaques) ;
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
99
99
/// Bodies inside the owner being lowered.
100
100
bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
101
101
/// `#[define_opaques]` attributes
102
- define_opaques : Option < & ' hir [ LocalDefId ] > ,
102
+ define_opaques : Option < & ' hir [ ( Span , LocalDefId ) ] > ,
103
103
/// Attributes inside the owner being lowered.
104
104
attrs : SortedMap < hir:: ItemLocalId , & ' hir [ hir:: Attribute ] > ,
105
105
/// 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 {
1308
1308
pub struct AttributeMap < ' tcx > {
1309
1309
pub map : SortedMap < ItemLocalId , & ' tcx [ Attribute ] > ,
1310
1310
/// Preprocessed `#[define_opaques]` attribute.
1311
- pub define_opaques : Option < & ' tcx [ LocalDefId ] > ,
1311
+ pub define_opaques : Option < & ' tcx [ ( Span , LocalDefId ) ] > ,
1312
1312
// Only present when the crate hash is needed.
1313
1313
pub opt_hash : Option < Fingerprint > ,
1314
1314
}
Original file line number Diff line number Diff line change @@ -190,11 +190,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
190
190
let Some ( defines) = self . tcx . hir_attrs ( hir_id. owner ) . define_opaques else {
191
191
return ;
192
192
} ;
193
- for & define in defines {
193
+ for & ( span , define) in defines {
194
194
trace ! ( ?define) ;
195
195
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 ( ) ;
197
197
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
+ }
198
201
self . mode = mode;
199
202
}
200
203
// Allow using `#[define_opaques]` 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
-
3
1
#![ feature( type_alias_impl_trait) ]
4
2
5
3
type Thing = ( ) ;
6
4
7
5
#[ define_opaques( Thing ) ]
6
+ //~^ ERROR item does not contain any opaque types
8
7
fn 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:18
3
+ |
4
+ LL | #[define_opaques(Thing)]
5
+ | ^^^^^
6
+
7
+ error: aborting due to 1 previous error
8
+
You can’t perform that action at this time.
0 commit comments