about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs2
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs2
-rw-r--r--compiler/rustc_hir/src/hir.rs2
-rw-r--r--compiler/rustc_ty_utils/src/opaque_types.rs7
4 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index 302936ad1a1..f0b5f99cc9f 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -1696,7 +1696,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
                 );
                 return None;
             };
-            Some(did)
+            Some((self.lower_span(path.span), did))
         });
         let define_opaque = self.arena.alloc_from_iter(define_opaque);
         self.define_opaque = Some(define_opaque);
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index e42a4b460fe..e5569458dbd 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
     /// Bodies inside the owner being lowered.
     bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
     /// `#[define_opaque]` attributes
-    define_opaque: Option<&'hir [LocalDefId]>,
+    define_opaque: Option<&'hir [(Span, LocalDefId)]>,
     /// Attributes inside the owner being lowered.
     attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
     /// Collect items that were created by lowering the current owner.
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 1c54b99b12f..53f0194091c 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -1308,7 +1308,7 @@ impl Attribute {
 pub struct AttributeMap<'tcx> {
     pub map: SortedMap<ItemLocalId, &'tcx [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.
     pub opt_hash: Option<Fingerprint>,
 }
diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs
index 2d590dfdd14..a107925fb18 100644
--- a/compiler/rustc_ty_utils/src/opaque_types.rs
+++ b/compiler/rustc_ty_utils/src/opaque_types.rs
@@ -190,11 +190,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
         let Some(defines) = self.tcx.hir_attrs(hir_id.owner).define_opaque else {
             return;
         };
-        for &define in defines {
+        for &(span, define) in defines {
             trace!(?define);
             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);
+            if n == self.opaques.len() {
+                self.tcx.dcx().span_err(span, "item does not contain any opaque types");
+            }
             self.mode = mode;
         }
         // Allow using `#[define_opaque]` on assoc methods and type aliases to override the default collection mode in