From 40916ef88f7809c5e8956a3917e00681ad25c30b Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Sat, 31 Dec 2022 00:56:43 +0100 Subject: [PATCH 01/16] Add notes and examples about non-intuitive `PathBuf::set_extension` behavior Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension. --- library/std/src/path.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 9d63281627d66..c89097e078307 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1411,7 +1411,8 @@ impl PathBuf { self.push(file_name); } - /// Updates [`self.extension`] to `extension`. + /// Updates [`self.extension`] to `Some(extension)` or to `None` if + /// `extension` is empty. /// /// Returns `false` and does nothing if [`self.file_name`] is [`None`], /// returns `true` and updates the extension otherwise. @@ -1419,6 +1420,20 @@ impl PathBuf { /// If [`self.extension`] is [`None`], the extension is added; otherwise /// it is replaced. /// + /// If `extension` is the empty string, [`self.extension`] will be [`None`] + /// afterwards, not `Some("")`. + /// + /// # Caveats + /// + /// The new `extension` may contain dots and will be used in its entirety, + /// but only the part after the final dot will be reflected in + /// [`self.extension`]. + /// + /// If the file stem contains internal dots and `extension` is empty, part + /// of the old file stem will be considered the new [`self.extension`]. + /// + /// See the examples below. + /// /// [`self.file_name`]: Path::file_name /// [`self.extension`]: Path::extension /// @@ -1432,8 +1447,20 @@ impl PathBuf { /// p.set_extension("force"); /// assert_eq!(Path::new("/feel/the.force"), p.as_path()); /// - /// p.set_extension("dark_side"); - /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path()); + /// p.set_extension("dark.side"); + /// assert_eq!(Path::new("/feel/the.dark.side"), p.as_path()); + /// + /// p.set_extension("cookie"); + /// assert_eq!(Path::new("/feel/the.dark.cookie"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the.dark"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the"), p.as_path()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn set_extension>(&mut self, extension: S) -> bool { From b7b252a4f43b9ba8ca46a8d8443f2022259ec6e6 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Sun, 1 Jan 2023 18:11:53 +0000 Subject: [PATCH 02/16] clean: Always store enum disriminant. --- src/librustdoc/clean/mod.rs | 42 +++++++++++++++--------- src/librustdoc/clean/types.rs | 24 +++++++++----- src/librustdoc/fold.rs | 26 ++++++++------- src/librustdoc/html/render/print_item.rs | 37 +++++++++++---------- src/librustdoc/json/conversions.rs | 9 +++-- src/librustdoc/passes/stripper.rs | 5 ++- src/librustdoc/visit.rs | 8 ++--- 7 files changed, 92 insertions(+), 59 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 8f4099653562e..b89b74a7f5fd3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1949,20 +1949,28 @@ pub(crate) fn clean_field_with_def_id( } pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item { + let discriminant = match variant.discr { + ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }), + ty::VariantDiscr::Relative(_) => None, + }; + let kind = match variant.ctor_kind() { - Some(CtorKind::Const) => Variant::CLike(match variant.discr { - ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }), - ty::VariantDiscr::Relative(_) => None, - }), - Some(CtorKind::Fn) => Variant::Tuple( + Some(CtorKind::Const) => VariantKind::CLike, + Some(CtorKind::Fn) => VariantKind::Tuple( variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(), ), - None => Variant::Struct(VariantStruct { + None => VariantKind::Struct(VariantStruct { ctor_kind: None, fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(), }), }; - Item::from_def_id_and_parts(variant.def_id, Some(variant.name), VariantItem(kind), cx) + + Item::from_def_id_and_parts( + variant.def_id, + Some(variant.name), + VariantItem(Variant { kind, discriminant }), + cx, + ) } fn clean_variant_data<'tcx>( @@ -1970,19 +1978,23 @@ fn clean_variant_data<'tcx>( disr_expr: &Option, cx: &mut DocContext<'tcx>, ) -> Variant { - match variant { - hir::VariantData::Struct(..) => Variant::Struct(VariantStruct { + let discriminant = disr_expr.map(|disr| Discriminant { + expr: Some(disr.body), + value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(), + }); + + let kind = match variant { + hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct { ctor_kind: None, fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(), }), hir::VariantData::Tuple(..) => { - Variant::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect()) + VariantKind::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect()) } - hir::VariantData::Unit(..) => Variant::CLike(disr_expr.map(|disr| Discriminant { - expr: Some(disr.body), - value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(), - })), - } + hir::VariantData::Unit(..) => VariantKind::CLike, + }; + + Variant { discriminant, kind } } fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 62217df8de79c..77ec024262123 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -807,8 +807,11 @@ impl ItemKind { match self { StructItem(s) => s.fields.iter(), UnionItem(u) => u.fields.iter(), - VariantItem(Variant::Struct(v)) => v.fields.iter(), - VariantItem(Variant::Tuple(v)) => v.iter(), + VariantItem(v) => match &v.kind { + VariantKind::CLike => [].iter(), + VariantKind::Tuple(t) => t.iter(), + VariantKind::Struct(s) => s.fields.iter(), + }, EnumItem(e) => e.variants.iter(), TraitItem(t) => t.items.iter(), ImplItem(i) => i.items.iter(), @@ -824,7 +827,6 @@ impl ItemKind { | TyMethodItem(_) | MethodItem(_, _) | StructFieldItem(_) - | VariantItem(_) | ForeignFunctionItem(_) | ForeignStaticItem(_) | ForeignTypeItem @@ -2136,17 +2138,23 @@ impl Enum { } #[derive(Clone, Debug)] -pub(crate) enum Variant { - CLike(Option), +pub(crate) struct Variant { + pub kind: VariantKind, + pub discriminant: Option, +} + +#[derive(Clone, Debug)] +pub(crate) enum VariantKind { + CLike, Tuple(Vec), Struct(VariantStruct), } impl Variant { pub(crate) fn has_stripped_entries(&self) -> Option { - match *self { - Self::Struct(ref struct_) => Some(struct_.has_stripped_entries()), - Self::CLike(..) | Self::Tuple(_) => None, + match &self.kind { + VariantKind::Struct(struct_) => Some(struct_.has_stripped_entries()), + VariantKind::CLike | VariantKind::Tuple(_) => None, } } } diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index c6f1f9de51a49..656aeefb01a4a 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -37,17 +37,21 @@ pub(crate) trait DocFolder: Sized { i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect(); ImplItem(i) } - VariantItem(i) => match i { - Variant::Struct(mut j) => { - j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); - VariantItem(Variant::Struct(j)) - } - Variant::Tuple(fields) => { - let fields = fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); - VariantItem(Variant::Tuple(fields)) - } - Variant::CLike(disr) => VariantItem(Variant::CLike(disr)), - }, + VariantItem(Variant { kind, discriminant }) => { + let kind = match kind { + VariantKind::Struct(mut j) => { + j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); + VariantKind::Struct(j) + } + VariantKind::Tuple(fields) => { + let fields = fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); + VariantKind::Tuple(fields) + } + VariantKind::CLike => VariantKind::CLike, + }; + + VariantItem(Variant { kind, discriminant }) + } ExternCrateItem { src: _ } | ImportItem(_) | FunctionItem(_) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index a7b57c373e3be..40dfb06975067 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1220,15 +1220,15 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: w.write_str(" "); let name = v.name.unwrap(); match *v.kind { - clean::VariantItem(ref var) => match var { - // FIXME(#101337): Show discriminant - clean::Variant::CLike(..) => write!(w, "{}", name), - clean::Variant::Tuple(ref s) => { + // FIXME(#101337): Show discriminant + clean::VariantItem(ref var) => match var.kind { + clean::VariantKind::CLike => write!(w, "{}", name), + clean::VariantKind::Tuple(ref s) => { write!(w, "{}(", name); print_tuple_struct_fields(w, cx, s); w.write_str(")"); } - clean::Variant::Struct(ref s) => { + clean::VariantKind::Struct(ref s) => { render_struct( w, v, @@ -1286,25 +1286,28 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: " rightside", ); write!(w, "

{name}", name = variant.name.unwrap()); - if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind { + + let clean::VariantItem(variant_data) = &*variant.kind else { unreachable!() }; + + if let clean::VariantKind::Tuple(ref s) = variant_data.kind { w.write_str("("); print_tuple_struct_fields(w, cx, s); w.write_str(")"); } w.write_str("

"); - use crate::clean::Variant; - - let heading_and_fields = match &*variant.kind { - clean::VariantItem(Variant::Struct(s)) => Some(("Fields", &s.fields)), - // Documentation on tuple variant fields is rare, so to reduce noise we only emit - // the section if at least one field is documented. - clean::VariantItem(Variant::Tuple(fields)) - if fields.iter().any(|f| f.doc_value().is_some()) => - { - Some(("Tuple Fields", fields)) + let heading_and_fields = match &variant_data.kind { + clean::VariantKind::Struct(s) => Some(("Fields", &s.fields)), + clean::VariantKind::Tuple(fields) => { + // Documentation on tuple variant fields is rare, so to reduce noise we only emit + // the section if at least one field is documented. + if fields.iter().any(|f| f.doc_value().is_some()) { + Some(("Tuple Fields", fields)) + } else { + None + } } - _ => None, + clean::VariantKind::CLike => None, }; if let Some((heading, fields)) = heading_and_fields { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index d7184053c87a4..ee491ce961a04 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -646,9 +646,12 @@ impl FromWithTcx for Enum { impl FromWithTcx for Variant { fn from_tcx(variant: clean::Variant, tcx: TyCtxt<'_>) -> Self { - use clean::Variant::*; - match variant { - CLike(disr) => Variant::Plain(disr.map(|disr| disr.into_tcx(tcx))), + use clean::VariantKind::*; + + let discriminant = variant.discriminant.map(|d| d.into_tcx(tcx)); + + match variant.kind { + CLike => Variant::Plain(discriminant), Tuple(fields) => Variant::Tuple(ids_keeping_stripped(fields, tcx)), Struct(s) => Variant::Struct { fields_stripped: s.has_stripped_entries(), diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 995fb5dcc1c86..bf111133b9f7f 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -132,7 +132,10 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { // implementations of traits are always public. clean::ImplItem(ref imp) if imp.trait_.is_some() => true, // Variant fields have inherited visibility - clean::VariantItem(clean::Variant::Struct(..) | clean::Variant::Tuple(..)) => true, + clean::VariantItem(clean::Variant { + kind: clean::VariantKind::Struct(..) | clean::VariantKind::Tuple(..), + .. + }) => true, _ => false, }; diff --git a/src/librustdoc/visit.rs b/src/librustdoc/visit.rs index d29ceead4f3a5..390b943612195 100644 --- a/src/librustdoc/visit.rs +++ b/src/librustdoc/visit.rs @@ -17,10 +17,10 @@ pub(crate) trait DocVisitor: Sized { EnumItem(i) => i.variants.iter().for_each(|x| self.visit_item(x)), TraitItem(i) => i.items.iter().for_each(|x| self.visit_item(x)), ImplItem(i) => i.items.iter().for_each(|x| self.visit_item(x)), - VariantItem(i) => match i { - Variant::Struct(j) => j.fields.iter().for_each(|x| self.visit_item(x)), - Variant::Tuple(fields) => fields.iter().for_each(|x| self.visit_item(x)), - Variant::CLike(_) => {} + VariantItem(i) => match &i.kind { + VariantKind::Struct(j) => j.fields.iter().for_each(|x| self.visit_item(x)), + VariantKind::Tuple(fields) => fields.iter().for_each(|x| self.visit_item(x)), + VariantKind::CLike => {} }, ExternCrateItem { src: _ } | ImportItem(_) From cca5d219e6801ebc2a62b455a12c657098a8af2d Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Sun, 1 Jan 2023 18:53:50 +0000 Subject: [PATCH 03/16] Rustdoc-Json: Report discriminant on all kinds of enum variant. Closes #106299 --- src/librustdoc/json/conversions.rs | 12 ++-- src/rustdoc-json-types/lib.rs | 17 +++-- .../rustdoc-json/enums/discriminant/basic.rs | 12 ++-- .../rustdoc-json/enums/discriminant/expr.rs | 36 +++++----- .../rustdoc-json/enums/discriminant/limits.rs | 32 ++++----- .../discriminant/num_underscore_and_suffix.rs | 16 ++--- .../only_some_have_discriminant.rs | 8 +-- .../rustdoc-json/enums/discriminant/struct.rs | 15 ++++ .../rustdoc-json/enums/discriminant/tuple.rs | 15 ++++ src/test/rustdoc-json/enums/field_hidden.rs | 4 +- src/test/rustdoc-json/enums/kind.rs | 17 ++--- .../rustdoc-json/enums/struct_field_hidden.rs | 9 ++- .../rustdoc-json/enums/tuple_fields_hidden.rs | 69 ++++++++----------- src/test/rustdoc-json/enums/variant_struct.rs | 9 ++- .../enums/variant_tuple_struct.rs | 4 +- src/tools/jsondoclint/src/validator.rs | 36 +++++----- 16 files changed, 167 insertions(+), 144 deletions(-) create mode 100644 src/test/rustdoc-json/enums/discriminant/struct.rs create mode 100644 src/test/rustdoc-json/enums/discriminant/tuple.rs diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index ee491ce961a04..84af194904d1b 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -650,14 +650,16 @@ impl FromWithTcx for Variant { let discriminant = variant.discriminant.map(|d| d.into_tcx(tcx)); - match variant.kind { - CLike => Variant::Plain(discriminant), - Tuple(fields) => Variant::Tuple(ids_keeping_stripped(fields, tcx)), - Struct(s) => Variant::Struct { + let kind = match variant.kind { + CLike => VariantKind::Plain, + Tuple(fields) => VariantKind::Tuple(ids_keeping_stripped(fields, tcx)), + Struct(s) => VariantKind::Struct { fields_stripped: s.has_stripped_entries(), fields: ids(s.fields, tcx), }, - } + }; + + Variant { kind, discriminant } } } diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 1ee96b8231cd1..387d5787dfcb2 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 23; +pub const FORMAT_VERSION: u32 = 24; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -333,11 +333,18 @@ pub struct Enum { pub impls: Vec, } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct Variant { + /// Whether the variant is plain, a tuple-like, or struct-like. Contains the fields. + pub kind: VariantKind, + /// The discriminant, if explicitly specified. + pub discriminant: Option, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] -#[serde(tag = "variant_kind", content = "variant_inner")] -pub enum Variant { - /// A variant with no parentheses, and possible discriminant. +pub enum VariantKind { + /// A variant with no parentheses /// /// ```rust /// enum Demo { @@ -345,7 +352,7 @@ pub enum Variant { /// PlainWithDiscriminant = 1, /// } /// ``` - Plain(Option), + Plain, /// A variant with unnamed fields. /// /// Unlike most of json, `#[doc(hidden)]` fields will be given as `None` diff --git a/src/test/rustdoc-json/enums/discriminant/basic.rs b/src/test/rustdoc-json/enums/discriminant/basic.rs index 8c221615aa753..06906df3b2c64 100644 --- a/src/test/rustdoc-json/enums/discriminant/basic.rs +++ b/src/test/rustdoc-json/enums/discriminant/basic.rs @@ -1,12 +1,12 @@ #[repr(i8)] pub enum Ordering { - // @is "$.index[*][?(@.name=='Less')].inner.variant_inner.expr" '"-1"' - // @is "$.index[*][?(@.name=='Less')].inner.variant_inner.value" '"-1"' + // @is "$.index[*][?(@.name=='Less')].inner.discriminant.expr" '"-1"' + // @is "$.index[*][?(@.name=='Less')].inner.discriminant.value" '"-1"' Less = -1, - // @is "$.index[*][?(@.name=='Equal')].inner.variant_inner.expr" '"0"' - // @is "$.index[*][?(@.name=='Equal')].inner.variant_inner.value" '"0"' + // @is "$.index[*][?(@.name=='Equal')].inner.discriminant.expr" '"0"' + // @is "$.index[*][?(@.name=='Equal')].inner.discriminant.value" '"0"' Equal = 0, - // @is "$.index[*][?(@.name=='Greater')].inner.variant_inner.expr" '"1"' - // @is "$.index[*][?(@.name=='Greater')].inner.variant_inner.value" '"1"' + // @is "$.index[*][?(@.name=='Greater')].inner.discriminant.expr" '"1"' + // @is "$.index[*][?(@.name=='Greater')].inner.discriminant.value" '"1"' Greater = 1, } diff --git a/src/test/rustdoc-json/enums/discriminant/expr.rs b/src/test/rustdoc-json/enums/discriminant/expr.rs index 235b0b47381fc..e639965e79b42 100644 --- a/src/test/rustdoc-json/enums/discriminant/expr.rs +++ b/src/test/rustdoc-json/enums/discriminant/expr.rs @@ -1,30 +1,30 @@ pub enum Foo { - // @is "$.index[*][?(@.name=='Addition')].inner.variant_inner.value" '"0"' - // @is "$.index[*][?(@.name=='Addition')].inner.variant_inner.expr" '"{ _ }"' + // @is "$.index[*][?(@.name=='Addition')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='Addition')].inner.discriminant.expr" '"{ _ }"' Addition = 0 + 0, - // @is "$.index[*][?(@.name=='Bin')].inner.variant_inner.value" '"1"' - // @is "$.index[*][?(@.name=='Bin')].inner.variant_inner.expr" '"0b1"' + // @is "$.index[*][?(@.name=='Bin')].inner.discriminant.value" '"1"' + // @is "$.index[*][?(@.name=='Bin')].inner.discriminant.expr" '"0b1"' Bin = 0b1, - // @is "$.index[*][?(@.name=='Oct')].inner.variant_inner.value" '"2"' - // @is "$.index[*][?(@.name=='Oct')].inner.variant_inner.expr" '"0o2"' + // @is "$.index[*][?(@.name=='Oct')].inner.discriminant.value" '"2"' + // @is "$.index[*][?(@.name=='Oct')].inner.discriminant.expr" '"0o2"' Oct = 0o2, - // @is "$.index[*][?(@.name=='PubConst')].inner.variant_inner.value" '"3"' - // @is "$.index[*][?(@.name=='PubConst')].inner.variant_inner.expr" '"THREE"' + // @is "$.index[*][?(@.name=='PubConst')].inner.discriminant.value" '"3"' + // @is "$.index[*][?(@.name=='PubConst')].inner.discriminant.expr" '"THREE"' PubConst = THREE, - // @is "$.index[*][?(@.name=='Hex')].inner.variant_inner.value" '"4"' - // @is "$.index[*][?(@.name=='Hex')].inner.variant_inner.expr" '"0x4"' + // @is "$.index[*][?(@.name=='Hex')].inner.discriminant.value" '"4"' + // @is "$.index[*][?(@.name=='Hex')].inner.discriminant.expr" '"0x4"' Hex = 0x4, - // @is "$.index[*][?(@.name=='Cast')].inner.variant_inner.value" '"5"' - // @is "$.index[*][?(@.name=='Cast')].inner.variant_inner.expr" '"{ _ }"' + // @is "$.index[*][?(@.name=='Cast')].inner.discriminant.value" '"5"' + // @is "$.index[*][?(@.name=='Cast')].inner.discriminant.expr" '"{ _ }"' Cast = 5 as isize, - // @is "$.index[*][?(@.name=='PubCall')].inner.variant_inner.value" '"6"' - // @is "$.index[*][?(@.name=='PubCall')].inner.variant_inner.expr" '"{ _ }"' + // @is "$.index[*][?(@.name=='PubCall')].inner.discriminant.value" '"6"' + // @is "$.index[*][?(@.name=='PubCall')].inner.discriminant.expr" '"{ _ }"' PubCall = six(), - // @is "$.index[*][?(@.name=='PrivCall')].inner.variant_inner.value" '"7"' - // @is "$.index[*][?(@.name=='PrivCall')].inner.variant_inner.expr" '"{ _ }"' + // @is "$.index[*][?(@.name=='PrivCall')].inner.discriminant.value" '"7"' + // @is "$.index[*][?(@.name=='PrivCall')].inner.discriminant.expr" '"{ _ }"' PrivCall = seven(), - // @is "$.index[*][?(@.name=='PrivConst')].inner.variant_inner.value" '"8"' - // @is "$.index[*][?(@.name=='PrivConst')].inner.variant_inner.expr" '"EIGHT"' + // @is "$.index[*][?(@.name=='PrivConst')].inner.discriminant.value" '"8"' + // @is "$.index[*][?(@.name=='PrivConst')].inner.discriminant.expr" '"EIGHT"' PrivConst = EIGHT, } diff --git a/src/test/rustdoc-json/enums/discriminant/limits.rs b/src/test/rustdoc-json/enums/discriminant/limits.rs index 8df73d78d237f..e56d5594f2fc9 100644 --- a/src/test/rustdoc-json/enums/discriminant/limits.rs +++ b/src/test/rustdoc-json/enums/discriminant/limits.rs @@ -4,40 +4,40 @@ #[repr(u64)] pub enum U64 { - // @is "$.index[*][?(@.name=='U64Min')].inner.variant_inner.value" '"0"' - // @is "$.index[*][?(@.name=='U64Min')].inner.variant_inner.expr" '"u64::MIN"' + // @is "$.index[*][?(@.name=='U64Min')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='U64Min')].inner.discriminant.expr" '"u64::MIN"' U64Min = u64::MIN, - // @is "$.index[*][?(@.name=='U64Max')].inner.variant_inner.value" '"18446744073709551615"' - // @is "$.index[*][?(@.name=='U64Max')].inner.variant_inner.expr" '"u64::MAX"' + // @is "$.index[*][?(@.name=='U64Max')].inner.discriminant.value" '"18446744073709551615"' + // @is "$.index[*][?(@.name=='U64Max')].inner.discriminant.expr" '"u64::MAX"' U64Max = u64::MAX, } #[repr(i64)] pub enum I64 { - // @is "$.index[*][?(@.name=='I64Min')].inner.variant_inner.value" '"-9223372036854775808"' - // @is "$.index[*][?(@.name=='I64Min')].inner.variant_inner.expr" '"i64::MIN"' + // @is "$.index[*][?(@.name=='I64Min')].inner.discriminant.value" '"-9223372036854775808"' + // @is "$.index[*][?(@.name=='I64Min')].inner.discriminant.expr" '"i64::MIN"' I64Min = i64::MIN, - // @is "$.index[*][?(@.name=='I64Max')].inner.variant_inner.value" '"9223372036854775807"' - // @is "$.index[*][?(@.name=='I64Max')].inner.variant_inner.expr" '"i64::MAX"' + // @is "$.index[*][?(@.name=='I64Max')].inner.discriminant.value" '"9223372036854775807"' + // @is "$.index[*][?(@.name=='I64Max')].inner.discriminant.expr" '"i64::MAX"' I64Max = i64::MAX, } #[repr(u128)] pub enum U128 { - // @is "$.index[*][?(@.name=='U128Min')].inner.variant_inner.value" '"0"' - // @is "$.index[*][?(@.name=='U128Min')].inner.variant_inner.expr" '"u128::MIN"' + // @is "$.index[*][?(@.name=='U128Min')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='U128Min')].inner.discriminant.expr" '"u128::MIN"' U128Min = u128::MIN, - // @is "$.index[*][?(@.name=='U128Max')].inner.variant_inner.value" '"340282366920938463463374607431768211455"' - // @is "$.index[*][?(@.name=='U128Max')].inner.variant_inner.expr" '"u128::MAX"' + // @is "$.index[*][?(@.name=='U128Max')].inner.discriminant.value" '"340282366920938463463374607431768211455"' + // @is "$.index[*][?(@.name=='U128Max')].inner.discriminant.expr" '"u128::MAX"' U128Max = u128::MAX, } #[repr(i128)] pub enum I128 { - // @is "$.index[*][?(@.name=='I128Min')].inner.variant_inner.value" '"-170141183460469231731687303715884105728"' - // @is "$.index[*][?(@.name=='I128Min')].inner.variant_inner.expr" '"i128::MIN"' + // @is "$.index[*][?(@.name=='I128Min')].inner.discriminant.value" '"-170141183460469231731687303715884105728"' + // @is "$.index[*][?(@.name=='I128Min')].inner.discriminant.expr" '"i128::MIN"' I128Min = i128::MIN, - // @is "$.index[*][?(@.name=='I128Max')].inner.variant_inner.value" '"170141183460469231731687303715884105727"' - // @is "$.index[*][?(@.name=='I128Max')].inner.variant_inner.expr" '"i128::MAX"' + // @is "$.index[*][?(@.name=='I128Max')].inner.discriminant.value" '"170141183460469231731687303715884105727"' + // @is "$.index[*][?(@.name=='I128Max')].inner.discriminant.expr" '"i128::MAX"' I128Max = i128::MAX, } diff --git a/src/test/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs b/src/test/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs index 3417baa0760e1..6889b305ffb41 100644 --- a/src/test/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs +++ b/src/test/rustdoc-json/enums/discriminant/num_underscore_and_suffix.rs @@ -1,15 +1,15 @@ #[repr(u32)] pub enum Foo { - // @is "$.index[*][?(@.name=='Basic')].inner.variant_inner.value" '"0"' - // @is "$.index[*][?(@.name=='Basic')].inner.variant_inner.expr" '"0"' + // @is "$.index[*][?(@.name=='Basic')].inner.discriminant.value" '"0"' + // @is "$.index[*][?(@.name=='Basic')].inner.discriminant.expr" '"0"' Basic = 0, - // @is "$.index[*][?(@.name=='Suffix')].inner.variant_inner.value" '"10"' - // @is "$.index[*][?(@.name=='Suffix')].inner.variant_inner.expr" '"10u32"' + // @is "$.index[*][?(@.name=='Suffix')].inner.discriminant.value" '"10"' + // @is "$.index[*][?(@.name=='Suffix')].inner.discriminant.expr" '"10u32"' Suffix = 10u32, - // @is "$.index[*][?(@.name=='Underscore')].inner.variant_inner.value" '"100"' - // @is "$.index[*][?(@.name=='Underscore')].inner.variant_inner.expr" '"1_0_0"' + // @is "$.index[*][?(@.name=='Underscore')].inner.discriminant.value" '"100"' + // @is "$.index[*][?(@.name=='Underscore')].inner.discriminant.expr" '"1_0_0"' Underscore = 1_0_0, - // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.variant_inner.value" '"1000"' - // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.variant_inner.expr" '"1_0_0_0u32"' + // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.discriminant.value" '"1000"' + // @is "$.index[*][?(@.name=='SuffixUnderscore')].inner.discriminant.expr" '"1_0_0_0u32"' SuffixUnderscore = 1_0_0_0u32, } diff --git a/src/test/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs b/src/test/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs index 6af944a2219ef..6a4f54de61745 100644 --- a/src/test/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs +++ b/src/test/rustdoc-json/enums/discriminant/only_some_have_discriminant.rs @@ -1,10 +1,10 @@ pub enum Foo { - // @is "$.index[*][?(@.name=='Has')].inner.variant_inner" '{"expr":"0", "value":"0"}' + // @is "$.index[*][?(@.name=='Has')].inner.discriminant" '{"expr":"0", "value":"0"}' Has = 0, - // @is "$.index[*][?(@.name=='Doesnt')].inner.variant_inner" null + // @is "$.index[*][?(@.name=='Doesnt')].inner.discriminant" null Doesnt, - // @is "$.index[*][?(@.name=='AlsoDoesnt')].inner.variant_inner" null + // @is "$.index[*][?(@.name=='AlsoDoesnt')].inner.discriminant" null AlsoDoesnt, - // @is "$.index[*][?(@.name=='AlsoHas')].inner.variant_inner" '{"expr":"44", "value":"44"}' + // @is "$.index[*][?(@.name=='AlsoHas')].inner.discriminant" '{"expr":"44", "value":"44"}' AlsoHas = 44, } diff --git a/src/test/rustdoc-json/enums/discriminant/struct.rs b/src/test/rustdoc-json/enums/discriminant/struct.rs new file mode 100644 index 0000000000000..e91a632a3b38e --- /dev/null +++ b/src/test/rustdoc-json/enums/discriminant/struct.rs @@ -0,0 +1,15 @@ +// ignore-tidy-linelength + +#[repr(i32)] +// @is "$.index[*][?(@.name=='Foo')].attrs" '["#[repr(i32)]"]' +pub enum Foo { + // @is "$.index[*][?(@.name=='Struct')].inner.discriminant" null + // @count "$.index[*][?(@.name=='Struct')].inner.kind.struct.fields[*]" 0 + Struct {}, + // @is "$.index[*][?(@.name=='StructWithDiscr')].inner.discriminant" '{"expr": "42", "value": "42"}' + // @count "$.index[*][?(@.name=='StructWithDiscr')].inner.kind.struct.fields[*]" 1 + StructWithDiscr { x: i32 } = 42, + // @is "$.index[*][?(@.name=='StructWithHexDiscr')].inner.discriminant" '{"expr": "0x42", "value": "66"}' + // @count "$.index[*][?(@.name=='StructWithHexDiscr')].inner.kind.struct.fields[*]" 2 + StructWithHexDiscr { x: i32, y: bool } = 0x42, +} diff --git a/src/test/rustdoc-json/enums/discriminant/tuple.rs b/src/test/rustdoc-json/enums/discriminant/tuple.rs new file mode 100644 index 0000000000000..b94d5739eabcb --- /dev/null +++ b/src/test/rustdoc-json/enums/discriminant/tuple.rs @@ -0,0 +1,15 @@ +// ignore-tidy-linelength + +#[repr(u32)] +// @is "$.index[*][?(@.name=='Foo')].attrs" '["#[repr(u32)]"]' +pub enum Foo { + // @is "$.index[*][?(@.name=='Tuple')].inner.discriminant" null + // @count "$.index[*][?(@.name=='Tuple')].inner.kind.tuple[*]" 0 + Tuple(), + // @is "$.index[*][?(@.name=='TupleWithDiscr')].inner.discriminant" '{"expr": "1", "value": "1"}' + // @count "$.index[*][?(@.name=='TupleWithDiscr')].inner.kind.tuple[*]" 1 + TupleWithDiscr(i32) = 1, + // @is "$.index[*][?(@.name=='TupleWithBinDiscr')].inner.discriminant" '{"expr": "0b10", "value": "2"}' + // @count "$.index[*][?(@.name=='TupleWithBinDiscr')].inner.kind.tuple[*]" 2 + TupleWithBinDiscr(i32, i32) = 0b10, +} diff --git a/src/test/rustdoc-json/enums/field_hidden.rs b/src/test/rustdoc-json/enums/field_hidden.rs index e6310cc3b997c..78a05431472cb 100644 --- a/src/test/rustdoc-json/enums/field_hidden.rs +++ b/src/test/rustdoc-json/enums/field_hidden.rs @@ -5,8 +5,8 @@ // @has "$.index[*][?(@.name=='ParseError')]" // @has "$.index[*][?(@.name=='UnexpectedEndTag')]" -// @is "$.index[*][?(@.name=='UnexpectedEndTag')].inner.variant_kind" '"tuple"' -// @is "$.index[*][?(@.name=='UnexpectedEndTag')].inner.variant_inner" [null] +// @is "$.index[*][?(@.name=='UnexpectedEndTag')].inner.kind.tuple" [null] +// @is "$.index[*][?(@.name=='UnexpectedEndTag')].inner.discriminant" null pub enum ParseError { UnexpectedEndTag(#[doc(hidden)] u32), diff --git a/src/test/rustdoc-json/enums/kind.rs b/src/test/rustdoc-json/enums/kind.rs index e9ea3ae23c226..1787a859c8b37 100644 --- a/src/test/rustdoc-json/enums/kind.rs +++ b/src/test/rustdoc-json/enums/kind.rs @@ -5,27 +5,22 @@ pub enum Foo { // @set Unit = "$.index[*][?(@.name=='Unit')].id" - // @is "$.index[*][?(@.name=='Unit')].inner.variant_kind" '"plain"' - // @is "$.index[*][?(@.name=='Unit')].inner.variant_inner" null + // @is "$.index[*][?(@.name=='Unit')].inner.kind" '"plain"' Unit, // @set Named = "$.index[*][?(@.name=='Named')].id" - // @is "$.index[*][?(@.name=='Named')].inner.variant_kind" '"struct"' - // @is "$.index[*][?(@.name=='Named')].inner.variant_inner" '{"fields": [], "fields_stripped": false}' + // @is "$.index[*][?(@.name=='Named')].inner.kind.struct" '{"fields": [], "fields_stripped": false}' Named {}, // @set Tuple = "$.index[*][?(@.name=='Tuple')].id" - // @is "$.index[*][?(@.name=='Tuple')].inner.variant_kind" '"tuple"' - // @is "$.index[*][?(@.name=='Tuple')].inner.variant_inner" [] + // @is "$.index[*][?(@.name=='Tuple')].inner.kind.tuple" [] Tuple(), // @set NamedField = "$.index[*][?(@.name=='NamedField')].id" // @set x = "$.index[*][?(@.name=='x' && @.kind=='struct_field')].id" - // @is "$.index[*][?(@.name=='NamedField')].inner.variant_kind" '"struct"' - // @is "$.index[*][?(@.name=='NamedField')].inner.variant_inner.fields[*]" $x - // @is "$.index[*][?(@.name=='NamedField')].inner.variant_inner.fields_stripped" false + // @is "$.index[*][?(@.name=='NamedField')].inner.kind.struct.fields[*]" $x + // @is "$.index[*][?(@.name=='NamedField')].inner.kind.struct.fields_stripped" false NamedField { x: i32 }, // @set TupleField = "$.index[*][?(@.name=='TupleField')].id" - // @is "$.index[*][?(@.name=='TupleField')].inner.variant_kind" '"tuple"' // @set tup_field = "$.index[*][?(@.name=='0' && @.kind=='struct_field')].id" - // @is "$.index[*][?(@.name=='TupleField')].inner.variant_inner[*]" $tup_field + // @is "$.index[*][?(@.name=='TupleField')].inner.kind.tuple[*]" $tup_field TupleField(i32), } diff --git a/src/test/rustdoc-json/enums/struct_field_hidden.rs b/src/test/rustdoc-json/enums/struct_field_hidden.rs index f612a34a49277..de939cde2e7b3 100644 --- a/src/test/rustdoc-json/enums/struct_field_hidden.rs +++ b/src/test/rustdoc-json/enums/struct_field_hidden.rs @@ -9,9 +9,8 @@ pub enum Foo { // @set y = "$.index[*][?(@.name=='y')].id" y: i32, }, - // @is "$.index[*][?(@.name=='Variant')].inner.variant_kind" '"struct"' - // @is "$.index[*][?(@.name=='Variant')].inner.variant_inner.fields_stripped" true - // @is "$.index[*][?(@.name=='Variant')].inner.variant_inner.fields[0]" $b - // @is "$.index[*][?(@.name=='Variant')].inner.variant_inner.fields[1]" $y - // @count "$.index[*][?(@.name=='Variant')].inner.variant_inner.fields[*]" 2 + // @is "$.index[*][?(@.name=='Variant')].inner.kind.struct.fields_stripped" true + // @is "$.index[*][?(@.name=='Variant')].inner.kind.struct.fields[0]" $b + // @is "$.index[*][?(@.name=='Variant')].inner.kind.struct.fields[1]" $y + // @count "$.index[*][?(@.name=='Variant')].inner.kind.struct.fields[*]" 2 } diff --git a/src/test/rustdoc-json/enums/tuple_fields_hidden.rs b/src/test/rustdoc-json/enums/tuple_fields_hidden.rs index f546eaa0d172d..70bfbb81826be 100644 --- a/src/test/rustdoc-json/enums/tuple_fields_hidden.rs +++ b/src/test/rustdoc-json/enums/tuple_fields_hidden.rs @@ -14,61 +14,50 @@ // @set 3.3.1 = "$.index[*][?(@.docs=='3.3.1')].id" pub enum EnumWithStrippedTupleVariants { - // @is "$.index[*][?(@.name=='None')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='None')].inner.variant_inner[*]" 0 + // @count "$.index[*][?(@.name=='None')].inner.kind.tuple[*]" 0 None(), - // @is "$.index[*][?(@.name=='One')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='One')].inner.variant_inner[*]" 1 - // @is "$.index[*][?(@.name=='One')].inner.variant_inner[0]" $1.1.0 + // @count "$.index[*][?(@.name=='One')].inner.kind.tuple[*]" 1 + // @is "$.index[*][?(@.name=='One')].inner.kind.tuple[0]" $1.1.0 One(/** 1.1.0*/ bool), - // @is "$.index[*][?(@.name=='OneHidden')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='OneHidden')].inner.variant_inner[*]" 1 - // @is "$.index[*][?(@.name=='OneHidden')].inner.variant_inner[0]" null + // @count "$.index[*][?(@.name=='OneHidden')].inner.kind.tuple[*]" 1 + // @is "$.index[*][?(@.name=='OneHidden')].inner.kind.tuple[0]" null OneHidden(#[doc(hidden)] bool), - // @is "$.index[*][?(@.name=='Two')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='Two')].inner.variant_inner[*]" 2 - // @is "$.index[*][?(@.name=='Two')].inner.variant_inner[0]" $2.1.0 - // @is "$.index[*][?(@.name=='Two')].inner.variant_inner[1]" $2.1.1 + // @count "$.index[*][?(@.name=='Two')].inner.kind.tuple[*]" 2 + // @is "$.index[*][?(@.name=='Two')].inner.kind.tuple[0]" $2.1.0 + // @is "$.index[*][?(@.name=='Two')].inner.kind.tuple[1]" $2.1.1 Two(/** 2.1.0*/ bool, /** 2.1.1*/ bool), - // @is "$.index[*][?(@.name=='TwoLeftHidden')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='TwoLeftHidden')].inner.variant_inner[*]" 2 - // @is "$.index[*][?(@.name=='TwoLeftHidden')].inner.variant_inner[0]" null - // @is "$.index[*][?(@.name=='TwoLeftHidden')].inner.variant_inner[1]" $2.2.1 + // @count "$.index[*][?(@.name=='TwoLeftHidden')].inner.kind.tuple[*]" 2 + // @is "$.index[*][?(@.name=='TwoLeftHidden')].inner.kind.tuple[0]" null + // @is "$.index[*][?(@.name=='TwoLeftHidden')].inner.kind.tuple[1]" $2.2.1 TwoLeftHidden(#[doc(hidden)] bool, /** 2.2.1*/ bool), - // @is "$.index[*][?(@.name=='TwoRightHidden')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='TwoRightHidden')].inner.variant_inner[*]" 2 - // @is "$.index[*][?(@.name=='TwoRightHidden')].inner.variant_inner[0]" $2.3.0 - // @is "$.index[*][?(@.name=='TwoRightHidden')].inner.variant_inner[1]" null + // @count "$.index[*][?(@.name=='TwoRightHidden')].inner.kind.tuple[*]" 2 + // @is "$.index[*][?(@.name=='TwoRightHidden')].inner.kind.tuple[0]" $2.3.0 + // @is "$.index[*][?(@.name=='TwoRightHidden')].inner.kind.tuple[1]" null TwoRightHidden(/** 2.3.0*/ bool, #[doc(hidden)] bool), - // @is "$.index[*][?(@.name=='TwoBothHidden')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='TwoBothHidden')].inner.variant_inner[*]" 2 - // @is "$.index[*][?(@.name=='TwoBothHidden')].inner.variant_inner[0]" null - // @is "$.index[*][?(@.name=='TwoBothHidden')].inner.variant_inner[1]" null + // @count "$.index[*][?(@.name=='TwoBothHidden')].inner.kind.tuple[*]" 2 + // @is "$.index[*][?(@.name=='TwoBothHidden')].inner.kind.tuple[0]" null + // @is "$.index[*][?(@.name=='TwoBothHidden')].inner.kind.tuple[1]" null TwoBothHidden(#[doc(hidden)] bool, #[doc(hidden)] bool), - // @is "$.index[*][?(@.name=='Three1')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='Three1')].inner.variant_inner[*]" 3 - // @is "$.index[*][?(@.name=='Three1')].inner.variant_inner[0]" null - // @is "$.index[*][?(@.name=='Three1')].inner.variant_inner[1]" $3.1.1 - // @is "$.index[*][?(@.name=='Three1')].inner.variant_inner[2]" $3.1.2 + // @count "$.index[*][?(@.name=='Three1')].inner.kind.tuple[*]" 3 + // @is "$.index[*][?(@.name=='Three1')].inner.kind.tuple[0]" null + // @is "$.index[*][?(@.name=='Three1')].inner.kind.tuple[1]" $3.1.1 + // @is "$.index[*][?(@.name=='Three1')].inner.kind.tuple[2]" $3.1.2 Three1(#[doc(hidden)] bool, /** 3.1.1*/ bool, /** 3.1.2*/ bool), - // @is "$.index[*][?(@.name=='Three2')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='Three2')].inner.variant_inner[*]" 3 - // @is "$.index[*][?(@.name=='Three2')].inner.variant_inner[0]" $3.2.0 - // @is "$.index[*][?(@.name=='Three2')].inner.variant_inner[1]" null - // @is "$.index[*][?(@.name=='Three2')].inner.variant_inner[2]" $3.2.2 + // @count "$.index[*][?(@.name=='Three2')].inner.kind.tuple[*]" 3 + // @is "$.index[*][?(@.name=='Three2')].inner.kind.tuple[0]" $3.2.0 + // @is "$.index[*][?(@.name=='Three2')].inner.kind.tuple[1]" null + // @is "$.index[*][?(@.name=='Three2')].inner.kind.tuple[2]" $3.2.2 Three2(/** 3.2.0*/ bool, #[doc(hidden)] bool, /** 3.2.2*/ bool), - // @is "$.index[*][?(@.name=='Three3')].inner.variant_kind" '"tuple"' - // @count "$.index[*][?(@.name=='Three3')].inner.variant_inner[*]" 3 - // @is "$.index[*][?(@.name=='Three3')].inner.variant_inner[0]" $3.3.0 - // @is "$.index[*][?(@.name=='Three3')].inner.variant_inner[1]" $3.3.1 - // @is "$.index[*][?(@.name=='Three3')].inner.variant_inner[2]" null + // @count "$.index[*][?(@.name=='Three3')].inner.kind.tuple[*]" 3 + // @is "$.index[*][?(@.name=='Three3')].inner.kind.tuple[0]" $3.3.0 + // @is "$.index[*][?(@.name=='Three3')].inner.kind.tuple[1]" $3.3.1 + // @is "$.index[*][?(@.name=='Three3')].inner.kind.tuple[2]" null Three3(/** 3.3.0*/ bool, /** 3.3.1*/ bool, #[doc(hidden)] bool), } - // @is "$.index[*][?(@.docs=='1.1.0')].name" '"0"' // @is "$.index[*][?(@.docs=='2.1.0')].name" '"0"' // @is "$.index[*][?(@.docs=='2.1.1')].name" '"1"' diff --git a/src/test/rustdoc-json/enums/variant_struct.rs b/src/test/rustdoc-json/enums/variant_struct.rs index 23b854d8d1721..bc870c502a011 100644 --- a/src/test/rustdoc-json/enums/variant_struct.rs +++ b/src/test/rustdoc-json/enums/variant_struct.rs @@ -1,11 +1,10 @@ // @is "$.index[*][?(@.name=='EnumStruct')].visibility" \"public\" // @is "$.index[*][?(@.name=='EnumStruct')].kind" \"enum\" pub enum EnumStruct { - // @is "$.index[*][?(@.name=='VariantS')].inner.variant_kind" \"struct\" // @is "$.index[*][?(@.name=='x')].kind" \"struct_field\" + // @set x = "$.index[*][?(@.name=='x')].id" // @is "$.index[*][?(@.name=='y')].kind" \"struct_field\" - VariantS { - x: u32, - y: String, - }, + // @set y = "$.index[*][?(@.name=='y')].id" + // @ismany "$.index[*][?(@.name=='VariantS')].inner.kind.struct.fields[*]" $x $y + VariantS { x: u32, y: String }, } diff --git a/src/test/rustdoc-json/enums/variant_tuple_struct.rs b/src/test/rustdoc-json/enums/variant_tuple_struct.rs index b71ec47a804ad..d1207bbfb18da 100644 --- a/src/test/rustdoc-json/enums/variant_tuple_struct.rs +++ b/src/test/rustdoc-json/enums/variant_tuple_struct.rs @@ -1,8 +1,10 @@ // @is "$.index[*][?(@.name=='EnumTupleStruct')].visibility" \"public\" // @is "$.index[*][?(@.name=='EnumTupleStruct')].kind" \"enum\" pub enum EnumTupleStruct { - // @is "$.index[*][?(@.name=='VariantA')].inner.variant_kind" \"tuple\" // @is "$.index[*][?(@.name=='0')].kind" \"struct_field\" + // @set f0 = "$.index[*][?(@.name=='0')].id" // @is "$.index[*][?(@.name=='1')].kind" \"struct_field\" + // @set f1 = "$.index[*][?(@.name=='1')].id" + // @ismany "$.index[*][?(@.name=='VariantA')].inner.kind.tuple[*]" $f0 $f1 VariantA(u32, String), } diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index e15f5fe3ccc96..291d02d67bd62 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -5,7 +5,7 @@ use rustdoc_json_types::{ Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs, GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Module, OpaqueTy, Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding, - TypeBindingKind, Typedef, Union, Variant, WherePredicate, + TypeBindingKind, Typedef, Union, Variant, VariantKind, WherePredicate, }; use crate::{item_kind::Kind, Error, ErrorKind}; @@ -140,24 +140,24 @@ impl<'a> Validator<'a> { } fn check_variant(&mut self, x: &'a Variant, id: &'a Id) { - match x { - Variant::Plain(discr) => { - if let Some(discr) = discr { - if let (Err(_), Err(_)) = - (discr.value.parse::(), discr.value.parse::()) - { - self.fail( - id, - ErrorKind::Custom(format!( - "Failed to parse discriminant value `{}`", - discr.value - )), - ); - } - } + let Variant { kind, discriminant } = x; + + if let Some(discr) = discriminant { + if let (Err(_), Err(_)) = (discr.value.parse::(), discr.value.parse::()) { + self.fail( + id, + ErrorKind::Custom(format!( + "Failed to parse discriminant value `{}`", + discr.value + )), + ); } - Variant::Tuple(tys) => tys.iter().flatten().for_each(|t| self.add_field_id(t)), - Variant::Struct { fields, fields_stripped: _ } => { + } + + match kind { + VariantKind::Plain => {} + VariantKind::Tuple(tys) => tys.iter().flatten().for_each(|t| self.add_field_id(t)), + VariantKind::Struct { fields, fields_stripped: _ } => { fields.iter().for_each(|f| self.add_field_id(f)) } } From beefcf88544b7f4d1b5e9ae77f93566303d34326 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 31 Dec 2022 01:02:10 +0000 Subject: [PATCH 04/16] Cleanup `mingw-tidy` docker job - Avoid `/checkout/src/ci/run.sh: line 187: [: =: unary operator expected`: https://github.com/rust-lang/rust/actions/runs/3809902408/jobs/6481611301#step:26:1701 - Avoid running `x check` in the tidy test, to get faster feedback. It's already run on the normal `mingw-check` job. --- src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile | 1 - src/ci/run.sh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile b/src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile index c340294fc7375..dc0e591cad6f6 100644 --- a/src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile +++ b/src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile @@ -32,5 +32,4 @@ RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-require COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/ COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/ -ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1 ENV SCRIPT python3 ../x.py test --stage 0 src/tools/tidy tidyselftest diff --git a/src/ci/run.sh b/src/ci/run.sh index b64300277508d..0db9c993eecb4 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -184,11 +184,11 @@ if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then $SRC/configure --set rust.parallel-compiler # Save the build metrics before we wipe the directory - if [ $HAS_METRICS = 1 ]; then + if [ "$HAS_METRICS" = 1 ]; then mv build/metrics.json . fi rm -rf build - if [ $HAS_METRICS = 1 ]; then + if [ "$HAS_METRICS" = 1 ]; then mkdir build mv metrics.json build fi From 3919b71b4879396791ba3d54c6e77e780a9fe9c6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 11:47:36 +0100 Subject: [PATCH 05/16] Fix rustdoc ICE on bad typedef with mismatching types --- src/librustdoc/clean/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 8f4099653562e..3253c3ae87c72 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1853,7 +1853,7 @@ pub(crate) fn clean_middle_ty<'tcx>( ty::Placeholder(..) => panic!("Placeholder"), ty::GeneratorWitness(..) => panic!("GeneratorWitness"), ty::Infer(..) => panic!("Infer"), - ty::Error(_) => panic!("Error"), + ty::Error(_) => rustc_errors::FatalError.raise(), } } From e8853563df4d9b736fa063d5669c7295c3c27d36 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 11:47:56 +0100 Subject: [PATCH 06/16] Add regression test for #106226 --- src/test/rustdoc-ui/issue-106226.rs | 3 +++ src/test/rustdoc-ui/issue-106226.stderr | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-106226.rs create mode 100644 src/test/rustdoc-ui/issue-106226.stderr diff --git a/src/test/rustdoc-ui/issue-106226.rs b/src/test/rustdoc-ui/issue-106226.rs new file mode 100644 index 0000000000000..71b497a9adc73 --- /dev/null +++ b/src/test/rustdoc-ui/issue-106226.rs @@ -0,0 +1,3 @@ +// This is a regression test for . +type F = [_; ()]; +//~^ ERROR diff --git a/src/test/rustdoc-ui/issue-106226.stderr b/src/test/rustdoc-ui/issue-106226.stderr new file mode 100644 index 0000000000000..2beffbc125bd4 --- /dev/null +++ b/src/test/rustdoc-ui/issue-106226.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/issue-106226.rs:2:14 + | +LL | type F = [_; ()]; + | ^^ expected `usize`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From ed3c3d3ddd9c505b446c2f2bdf245e97683bb4cf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 14:29:02 +0100 Subject: [PATCH 07/16] Add regression test for #105334 --- src/test/rustdoc-ui/issue-105334.rs | 2 ++ src/test/rustdoc-ui/issue-105334.stderr | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-105334.rs create mode 100644 src/test/rustdoc-ui/issue-105334.stderr diff --git a/src/test/rustdoc-ui/issue-105334.rs b/src/test/rustdoc-ui/issue-105334.rs new file mode 100644 index 0000000000000..ee1adc6a02914 --- /dev/null +++ b/src/test/rustdoc-ui/issue-105334.rs @@ -0,0 +1,2 @@ +impl Vec< br##"*.."## > {} +//~^ ERROR diff --git a/src/test/rustdoc-ui/issue-105334.stderr b/src/test/rustdoc-ui/issue-105334.stderr new file mode 100644 index 0000000000000..e163bb4db9ee6 --- /dev/null +++ b/src/test/rustdoc-ui/issue-105334.stderr @@ -0,0 +1,9 @@ +error[E0747]: constant provided when a type was expected + --> $DIR/issue-105334.rs:1:11 + | +LL | impl Vec< br##"*.."## > {} + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0747`. From 1a9432255eac349e4349f323123f3b49234d4f6b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 14:29:22 +0100 Subject: [PATCH 08/16] Add regression test for #105737 --- src/test/rustdoc-ui/issue-105737.rs | 4 ++++ src/test/rustdoc-ui/issue-105737.stderr | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-105737.rs create mode 100644 src/test/rustdoc-ui/issue-105737.stderr diff --git a/src/test/rustdoc-ui/issue-105737.rs b/src/test/rustdoc-ui/issue-105737.rs new file mode 100644 index 0000000000000..154f069d8ffac --- /dev/null +++ b/src/test/rustdoc-ui/issue-105737.rs @@ -0,0 +1,4 @@ +impl Vec {} +//~^ ERROR + +pub fn lol() {} diff --git a/src/test/rustdoc-ui/issue-105737.stderr b/src/test/rustdoc-ui/issue-105737.stderr new file mode 100644 index 0000000000000..2dd9beb17da9b --- /dev/null +++ b/src/test/rustdoc-ui/issue-105737.stderr @@ -0,0 +1,12 @@ +error[E0747]: constant provided when a type was expected + --> $DIR/issue-105737.rs:1:10 + | +LL | impl Vec {} + | ^^^ + | + = help: `lol` is a function item, not a type + = help: function item types cannot be named directly + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0747`. From a167435b76c1070fa0290e27f7756c9bb5b6548b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 14:29:38 +0100 Subject: [PATCH 09/16] Add regression test for #105742 --- src/test/rustdoc-ui/issue-105742.rs | 40 +++ src/test/rustdoc-ui/issue-105742.stderr | 385 ++++++++++++++++++++++++ 2 files changed, 425 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-105742.rs create mode 100644 src/test/rustdoc-ui/issue-105742.stderr diff --git a/src/test/rustdoc-ui/issue-105742.rs b/src/test/rustdoc-ui/issue-105742.rs new file mode 100644 index 0000000000000..cb1de7433cfaa --- /dev/null +++ b/src/test/rustdoc-ui/issue-105742.rs @@ -0,0 +1,40 @@ +// compile-flags: -Znormalize-docs + +use std::ops::Index; + +pub fn next<'a, T>(s: &'a mut dyn SVec) { +//~^ ERROR +//~^^ ERROR +//~^^^ ERROR + let _ = s; +} + +pub trait SVec: Index< + ::Item, +//~^ ERROR +//~^^ ERROR +//~^^^ ERROR +//~^^^^ ERROR + Output = ::Item, +//~^ ERROR +//~^^ ERROR +//~^^^ ERROR +//~^^^^ ERROR + Output = ::Item> as SVec>::Item, +//~^ ERROR +//~^^ ERROR +//~^^^ ERROR +//~^^^^ ERROR +//~^^^^^ ERROR +//~^^^^^^ ERROR +//~^^^^^^^ ERROR +//~^^^^^^^^ ERROR +> { + type Item<'a, T>; + + fn len(&self) -> ::Item; + //~^ ERROR + //~^^ ERROR + //~^^^ ERROR + //~^^^^ ERROR +} diff --git a/src/test/rustdoc-ui/issue-105742.stderr b/src/test/rustdoc-ui/issue-105742.stderr new file mode 100644 index 0000000000000..cc101b7ff3757 --- /dev/null +++ b/src/test/rustdoc-ui/issue-105742.stderr @@ -0,0 +1,385 @@ +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:13:21 + | +LL | ::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | ::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:13:21 + | +LL | ::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | ::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:18:37 + | +LL | Output = ::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:18:37 + | +LL | Output = ::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:30 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item<'a>> as SVec>::Item, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:30 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item> as SVec>::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:46 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item> as SVec>::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:46 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item> as SVec>::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:5:40 + | +LL | pub fn next<'a, T>(s: &'a mut dyn SVec) { + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | pub fn next<'a, T>(s: &'a mut dyn SVec = T, Output = T>) { + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:5:40 + | +LL | pub fn next<'a, T>(s: &'a mut dyn SVec) { + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | pub fn next<'a, T>(s: &'a mut dyn SVec = T, Output = T>) { + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:13:21 + | +LL | ::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | ::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:13:21 + | +LL | ::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | ::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:18:37 + | +LL | Output = ::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:18:37 + | +LL | Output = ::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:30 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item<'a>> as SVec>::Item, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:30 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item> as SVec>::Item, + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:46 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | Output = ::Item> as SVec>::Item<'a>, + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:23:46 + | +LL | Output = ::Item> as SVec>::Item, + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | Output = ::Item> as SVec>::Item, + | ~~~~~~~ + +error[E0038]: the trait `SVec` cannot be made into an object + --> $DIR/issue-105742.rs:5:31 + | +LL | pub fn next<'a, T>(s: &'a mut dyn SVec) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SVec` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-105742.rs:12:17 + | +LL | pub trait SVec: Index< + | ____________----__^ + | | | + | | this trait cannot be made into an object... +LL | | ::Item, +LL | | +LL | | +... | +LL | |/ Output = ::Item, +LL | || +LL | || +LL | || +LL | || +LL | || Output = ::Item> as SVec>::Item, + | ||_________________________________________________^ ...because it uses `Self` as a type parameter +... | +LL | | +LL | | > { + | |__^ ...because it uses `Self` as a type parameter + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:35:38 + | +LL | fn len(&self) -> ::Item; + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | fn len(&self) -> ::Item<'_>; + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:35:38 + | +LL | fn len(&self) -> ::Item; + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | fn len(&self) -> ::Item; + | ~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:35:38 + | +LL | fn len(&self) -> ::Item; + | ^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ -- +help: add missing lifetime argument + | +LL | fn len(&self) -> ::Item<'_>; + | ~~~~~~~~ + +error[E0107]: missing generics for associated type `SVec::Item` + --> $DIR/issue-105742.rs:35:38 + | +LL | fn len(&self) -> ::Item; + | ^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-105742.rs:33:10 + | +LL | type Item<'a, T>; + | ^^^^ - +help: add missing generic argument + | +LL | fn len(&self) -> ::Item; + | ~~~~~~~ + +error: aborting due to 23 previous errors + +Some errors have detailed explanations: E0038, E0107. +For more information about an error, try `rustc --explain E0038`. From c1567730c0ea07e41fcabd14332ad701857d9f93 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Jan 2023 14:29:56 +0100 Subject: [PATCH 10/16] Add regression test for #96287 --- src/test/rustdoc-ui/issue-96287.rs | 17 +++++++++++++++++ src/test/rustdoc-ui/issue-96287.stderr | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-96287.rs create mode 100644 src/test/rustdoc-ui/issue-96287.stderr diff --git a/src/test/rustdoc-ui/issue-96287.rs b/src/test/rustdoc-ui/issue-96287.rs new file mode 100644 index 0000000000000..8d8b4456e6335 --- /dev/null +++ b/src/test/rustdoc-ui/issue-96287.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +pub trait TraitWithAssoc { + type Assoc; +} + +pub type Foo = impl Trait; +//~^ ERROR +//~^^ ERROR + +pub trait Trait {} + +impl Trait for () {} + +pub fn foo_desugared(_: T) -> Foo { + () +} diff --git a/src/test/rustdoc-ui/issue-96287.stderr b/src/test/rustdoc-ui/issue-96287.stderr new file mode 100644 index 0000000000000..0236b9fe64775 --- /dev/null +++ b/src/test/rustdoc-ui/issue-96287.stderr @@ -0,0 +1,15 @@ +error[E0220]: associated type `Assoc` not found for `V` + --> $DIR/issue-96287.rs:7:33 + | +LL | pub type Foo = impl Trait; + | ^^^^^ there is a similarly named associated type `Assoc` in the trait `TraitWithAssoc` + +error[E0220]: associated type `Assoc` not found for `V` + --> $DIR/issue-96287.rs:7:33 + | +LL | pub type Foo = impl Trait; + | ^^^^^ there is a similarly named associated type `Assoc` in the trait `TraitWithAssoc` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0220`. From 693399f7c2cbd93abc6c780874d36efd949cc958 Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Mon, 2 Jan 2023 12:00:31 -0500 Subject: [PATCH 11/16] Update books --- src/doc/book | 2 +- src/doc/nomicon | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index a60f4316ec923..2bd5d42c99563 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit a60f4316ec923a5ac2ed6a2eba6960edb832d855 +Subproject commit 2bd5d42c9956369132228da6409f0e68da56c51a diff --git a/src/doc/nomicon b/src/doc/nomicon index dd37e21ccee43..8ca261268068d 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit dd37e21ccee43918ed18a71581bb2af537ffe4fc +Subproject commit 8ca261268068d80c0969260fff15199bad87b587 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 995df09b65c58..8888f9428fe9a 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 995df09b65c582eb6290ab7ea5d9485983eb4c37 +Subproject commit 8888f9428fe9a48f31de6bd2cef9b9bf80791edc diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index 8b42eb5f57d3d..b3e2a6e6c8a3a 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit 8b42eb5f57d3d8ed2257a22d0e850d9db52afed3 +Subproject commit b3e2a6e6c8a3aae5b5d950c63046f23bae07096d From fd59b628ea4d89099ae8ecfce01f271b2a1d9bf5 Mon Sep 17 00:00:00 2001 From: James Higgins Date: Tue, 12 Apr 2022 13:54:36 -0300 Subject: [PATCH 12/16] Add PhantomData marker to Context to make Context !Send and !Sync --- library/core/src/task/wake.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 1b7578376b42b..a4425fd234a4e 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -181,6 +181,9 @@ pub struct Context<'a> { // are contravariant while return-position lifetimes are // covariant). _marker: PhantomData &'a ()>, + // Ensure `Context` is `!Send` and `!Sync` in order to allow + // for future `!Send` and / or `!Sync` fields. + _marker2: PhantomData<*mut ()>, } impl<'a> Context<'a> { @@ -190,7 +193,7 @@ impl<'a> Context<'a> { #[must_use] #[inline] pub const fn from_waker(waker: &'a Waker) -> Self { - Context { waker, _marker: PhantomData } + Context { waker, _marker: PhantomData, _marker2: PhantomData } } /// Returns a reference to the [`Waker`] for the current task. From 257e766c0c17c1a3561a509c931cf89bce27dcf5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 2 Jan 2023 10:31:50 -0800 Subject: [PATCH 13/16] Remove test of static Context Context is no longer Sync so this doesn't work. error[E0277]: `*mut ()` cannot be shared between threads safely --> library/core/tests/task.rs:24:21 | 24 | static CONTEXT: Context<'static> = Context::from_waker(&WAKER); | ^^^^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely | = help: within `Context<'static>`, the trait `Sync` is not implemented for `*mut ()` = note: required because it appears within the type `PhantomData<*mut ()>` = note: required because it appears within the type `Context<'static>` = note: shared static variables must have a type that implements `Sync` --- library/core/tests/task.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/library/core/tests/task.rs b/library/core/tests/task.rs index 56be30e928245..163b34c964852 100644 --- a/library/core/tests/task.rs +++ b/library/core/tests/task.rs @@ -1,4 +1,4 @@ -use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; +use core::task::{Poll, RawWaker, RawWakerVTable, Waker}; #[test] fn poll_const() { @@ -21,9 +21,5 @@ fn waker_const() { static WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) }; - static CONTEXT: Context<'static> = Context::from_waker(&WAKER); - - static WAKER_REF: &'static Waker = CONTEXT.waker(); - - WAKER_REF.wake_by_ref(); + WAKER.wake_by_ref(); } From e1787f557223245375571550000eb6441de17b6e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 11 Dec 2022 12:10:55 +0100 Subject: [PATCH 14/16] Reduce HIR debug output HIR debug output is currently very verbose, especially when used with the alternate (`#`) flag. This commit reduces the amount of noisy newlines by forcing a few small key types to stay on one line, which makes the output easier to read and scroll by. ``` $ rustc +after hello_world.rs -Zunpretty=hir-tree | wc -l 582 $ rustc +before hello_world.rs -Zunpretty=hir-tree | wc -l 932 ``` --- .../rustc_data_structures/src/sorted_map.rs | 9 +++++++- compiler/rustc_hir/src/hir.rs | 16 +++++++++++++- compiler/rustc_hir/src/hir_id.rs | 21 ++++++++++++++++--- src/test/ui/thir-tree.stdout | 7 +------ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 05f059c89d5cd..c63caa06818f2 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -1,6 +1,7 @@ use crate::stable_hasher::{HashStable, StableHasher, StableOrd}; use std::borrow::Borrow; use std::cmp::Ordering; +use std::fmt::Debug; use std::mem; use std::ops::{Bound, Index, IndexMut, RangeBounds}; @@ -16,7 +17,7 @@ pub use index_map::SortedIndexMultiMap; /// stores data in a more compact way. It also supports accessing contiguous /// ranges of elements as a slice, and slices of already sorted elements can be /// inserted efficiently. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] pub struct SortedMap { data: Vec<(K, V)>, } @@ -314,5 +315,11 @@ impl + StableOrd, V: HashStable, CTX> HashStable fo } } +impl Debug for SortedMap { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_map().entries(self.data.iter().map(|(a, b)| (a, b))).finish() + } +} + #[cfg(test)] mod tests; diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index e923ec26a488f..034f06bb889b6 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -854,7 +854,11 @@ impl fmt::Debug for OwnerNodes<'_> { &self .nodes .iter_enumerated() - .map(|(id, parented_node)| (id, parented_node.as_ref().map(|node| node.parent))) + .map(|(id, parented_node)| { + let parented_node = parented_node.as_ref().map(|node| node.parent); + + debug_fn(move |f| write!(f, "({id:?}, {parented_node:?})")) + }) .collect::>(), ) .field("bodies", &self.bodies) @@ -3615,3 +3619,13 @@ mod size_asserts { static_assert_size!(TyKind<'_>, 32); // tidy-alphabetical-end } + +fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { + struct DebugFn(F); + impl) -> fmt::Result> fmt::Debug for DebugFn { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + (self.0)(fmt) + } + } + DebugFn(f) +} diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index 03bcaa6946825..5d05adfb55654 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -1,14 +1,21 @@ use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; use rustc_span::{def_id::DefPathHash, HashStableContext}; -use std::fmt; +use std::fmt::{self, Debug}; -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Encodable, Decodable)] pub struct OwnerId { pub def_id: LocalDefId, } +impl Debug for OwnerId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: DefId(0:1 ~ aa[7697]::{use#0}) + Debug::fmt(&self.def_id, f) + } +} + impl From for HirId { fn from(owner: OwnerId) -> HirId { HirId { owner, local_id: ItemLocalId::from_u32(0) } @@ -60,7 +67,7 @@ impl ToStableHashKey for OwnerId { /// the `local_id` part of the `HirId` changing, which is a very useful property in /// incremental compilation where we have to persist things through changes to /// the code base. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Encodable, Decodable, HashStable_Generic)] #[rustc_pass_by_value] pub struct HirId { @@ -68,6 +75,14 @@ pub struct HirId { pub local_id: ItemLocalId, } +impl Debug for HirId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10) + // Don't use debug_tuple to always keep this on one line. + write!(f, "HirId({:?}.{:?})", self.owner, self.local_id) + } +} + impl HirId { /// Signal local id which should never be used. pub const INVALID: HirId = diff --git a/src/test/ui/thir-tree.stdout b/src/test/ui/thir-tree.stdout index 7fb90581f8a8f..4b6915f771526 100644 --- a/src/test/ui/thir-tree.stdout +++ b/src/test/ui/thir-tree.stdout @@ -32,12 +32,7 @@ Thir { kind: Scope { region_scope: Node(2), lint_level: Explicit( - HirId { - owner: OwnerId { - def_id: DefId(0:3 ~ thir_tree[8f1d]::main), - }, - local_id: 2, - }, + HirId(DefId(0:3 ~ thir_tree[8f1d]::main).2), ), value: e0, }, From 3c7c694e734b6bcc41663eaf230a7f26c19de0f4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 2 Jan 2023 14:25:24 -0800 Subject: [PATCH 15/16] Document rustc_ast::Extern variants --- compiler/rustc_ast/src/ast.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 4ad9981991d30..9f38deacca416 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2705,8 +2705,19 @@ impl Item { /// `extern` qualifier on a function item or function type. #[derive(Clone, Copy, Encodable, Decodable, Debug)] pub enum Extern { + /// No explicit extern keyword was used + /// + /// E.g. `fn foo() {}` None, + /// An explicit extern keyword was used, but with implicit ABI + /// + /// E.g. `extern fn foo() {}` + /// + /// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`) Implicit(Span), + /// An explicit extern keyword was used with an explicit ABI + /// + /// E.g. `extern "C" fn foo() {}` Explicit(StrLit, Span), } From 157211ff2f0a8f45c6000c46a545412a0fb9eed4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 2 Jan 2023 14:26:43 -0800 Subject: [PATCH 16/16] Document rustc_ast::FnHeader fields --- compiler/rustc_ast/src/ast.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 9f38deacca416..37dfa46f696ea 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2736,9 +2736,13 @@ impl Extern { /// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`). #[derive(Clone, Copy, Encodable, Decodable, Debug)] pub struct FnHeader { + /// The `unsafe` keyword, if any pub unsafety: Unsafe, + /// The `async` keyword, if any pub asyncness: Async, + /// The `const` keyword, if any pub constness: Const, + /// The `extern` keyword and corresponding ABI string, if any pub ext: Extern, }