diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index e47b415d39d10..a8d6cd32641da 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -454,9 +454,11 @@ impl FromWithTcx for GenericParamDefKind { use clean::GenericParamDefKind::*; match kind { Lifetime(param) => GenericParamDefKind::Lifetime { + variance: param.variance.map(|var| var.into_tcx(tcx)), outlives: param.outlives.into_iter().map(convert_lifetime).collect(), }, Type(param) => GenericParamDefKind::Type { + variance: param.variance.map(|var| var.into_tcx(tcx)), bounds: param.bounds.into_tcx(tcx), default: param.default.map(|ty| ty.into_tcx(tcx)), synthetic: param.synthetic, @@ -468,6 +470,17 @@ impl FromWithTcx for GenericParamDefKind { } } +impl FromWithTcx for Variance { + fn from_tcx(variance: ty::Variance, _tcx: TyCtxt<'_>) -> Self { + match variance { + ty::Variance::Covariant => Self::Covariant, + ty::Variance::Invariant => Self::Invariant, + ty::Variance::Contravariant => Self::Contravariant, + ty::Variance::Bivariant => Self::Bivariant, + } + } +} + impl FromWithTcx for WherePredicate { fn from_tcx(predicate: clean::WherePredicate, tcx: TyCtxt<'_>) -> Self { use clean::WherePredicate::*; diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 164f88faa314a..e9c69fdc3d602 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -443,9 +443,11 @@ pub struct GenericParamDef { #[serde(rename_all = "snake_case")] pub enum GenericParamDefKind { Lifetime { + variance: Option, outlives: Vec, }, Type { + variance: Option, bounds: Vec, default: Option, /// This is normally `false`, which means that this generic parameter is @@ -480,6 +482,16 @@ pub enum GenericParamDefKind { }, } +// FIXME(fmease): docs +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Variance { + Covariant, + Invariant, + Contravariant, + Bivariant, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum WherePredicate { diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 592e97310a4f4..a21cee0595394 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -324,8 +324,13 @@ impl<'a> Validator<'a> { fn check_generic_param_def(&mut self, gpd: &'a GenericParamDef) { match &gpd.kind { - rustdoc_json_types::GenericParamDefKind::Lifetime { outlives: _ } => {} - rustdoc_json_types::GenericParamDefKind::Type { bounds, default, synthetic: _ } => { + rustdoc_json_types::GenericParamDefKind::Lifetime { variance: _, outlives: _ } => {} + rustdoc_json_types::GenericParamDefKind::Type { + variance: _, + bounds, + default, + synthetic: _, + } => { bounds.iter().for_each(|b| self.check_generic_bound(b)); if let Some(ty) = default { self.check_type(ty);