diff options
| author | Michael Goulet <michael@errs.io> | 2023-08-08 19:59:44 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-08-28 01:05:34 +0000 |
| commit | 690bcc6619aad74d8c32a52c104d4f79fa2f6bf4 (patch) | |
| tree | 2cc33b5ea6ef3e824a0be2d37ff2f6bb05b87040 /compiler/rustc_hir_analysis/src/variance/test.rs | |
| parent | 32a9565223c05e6f7e60d783ad25e1864cd51d70 (diff) | |
| download | rust-690bcc6619aad74d8c32a52c104d4f79fa2f6bf4.tar.gz rust-690bcc6619aad74d8c32a52c104d4f79fa2f6bf4.zip | |
Test variances of opaque captures
Diffstat (limited to 'compiler/rustc_hir_analysis/src/variance/test.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/variance/test.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/variance/test.rs b/compiler/rustc_hir_analysis/src/variance/test.rs index d57d05d7605..d98dc0e6b83 100644 --- a/compiler/rustc_hir_analysis/src/variance/test.rs +++ b/compiler/rustc_hir_analysis/src/variance/test.rs @@ -1,9 +1,24 @@ +use rustc_hir::def::DefKind; +use rustc_hir::def_id::CRATE_DEF_ID; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::sym; use crate::errors; pub fn test_variance(tcx: TyCtxt<'_>) { + if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) { + for id in tcx.hir().items() { + if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) { + let variances_of = tcx.variances_of(id.owner_id); + + tcx.sess.emit_err(errors::VariancesOf { + span: tcx.def_span(id.owner_id), + variances_of: format!("{variances_of:?}"), + }); + } + } + } + // For unit testing: check for a special "rustc_variance" // attribute and report an error with various results if found. for id in tcx.hir().items() { |
