Since we gen the ser/de code, we don't need this old workaround anymore

This commit is contained in:
wtfsck 2021-07-18 15:03:14 +02:00
parent 000947c762
commit 8aa3fb4dda
4 changed files with 19 additions and 28 deletions

View File

@ -12,35 +12,29 @@ namespace Generator.Documentation.Rust {
public RustDeprecatedWriter(IdentifierConverter idConverter) => public RustDeprecatedWriter(IdentifierConverter idConverter) =>
this.idConverter = idConverter; this.idConverter = idConverter;
public override void WriteDeprecated(FileWriter writer, EnumValue value) => public override void WriteDeprecated(FileWriter writer, EnumValue value) {
WriteDeprecated(writer, value, null);
public void WriteDeprecated(FileWriter writer, EnumValue value, string? notDeprecFeature) {
if (value.DeprecatedInfo.IsDeprecated) { if (value.DeprecatedInfo.IsDeprecated) {
if (value.DeprecatedInfo.NewName is not null) { if (value.DeprecatedInfo.NewName is not null) {
var newValue = value.DeclaringType[value.DeprecatedInfo.NewName]; var newValue = value.DeclaringType[value.DeprecatedInfo.NewName];
WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, newValue.Name(idConverter), value.DeprecatedInfo.Description, notDeprecFeature); WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, newValue.Name(idConverter), value.DeprecatedInfo.Description);
} }
else else
WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, null, value.DeprecatedInfo.Description, notDeprecFeature); WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, null, value.DeprecatedInfo.Description);
} }
} }
public override void WriteDeprecated(FileWriter writer, Constant value) => public override void WriteDeprecated(FileWriter writer, Constant value) {
WriteDeprecated(writer, value, null);
public void WriteDeprecated(FileWriter writer, Constant value, string? notDeprecFeature) {
if (value.DeprecatedInfo.IsDeprecated) { if (value.DeprecatedInfo.IsDeprecated) {
if (value.DeprecatedInfo.NewName is not null) { if (value.DeprecatedInfo.NewName is not null) {
var newValue = value.DeclaringType[value.DeprecatedInfo.NewName]; var newValue = value.DeclaringType[value.DeprecatedInfo.NewName];
WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, newValue.Name(idConverter), value.DeprecatedInfo.Description, notDeprecFeature); WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, newValue.Name(idConverter), value.DeprecatedInfo.Description);
} }
else else
WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, null, value.DeprecatedInfo.Description, notDeprecFeature); WriteDeprecated(writer, value.DeprecatedInfo.VersionStr, null, value.DeprecatedInfo.Description);
} }
} }
static void WriteDeprecated(FileWriter writer, string version, string? newName, string? description, string? notDeprecFeature) { static void WriteDeprecated(FileWriter writer, string version, string? newName, string? description) {
string extra; string extra;
if (description is not null) if (description is not null)
extra = description; extra = description;
@ -48,11 +42,7 @@ namespace Generator.Documentation.Rust {
extra = $"Use {newName} instead"; extra = $"Use {newName} instead";
else else
extra = "Don't use it!"; extra = "Don't use it!";
var deprecatedAttr = $"deprecated(since = \"{version}\", note = \"{extra}\")"; writer.WriteLine($"#[deprecated(since = \"{version}\", note = \"{extra}\")]");
if (notDeprecFeature is not null)
writer.WriteLine($"#[cfg_attr(not(feature = \"{notDeprecFeature}\"), {deprecatedAttr})]");
else
writer.WriteLine($"#[{deprecatedAttr}]");
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Generator.Constants; using Generator.Constants;
using Generator.Constants.Rust; using Generator.Constants.Rust;
using Generator.Documentation;
using Generator.Documentation.Rust; using Generator.Documentation.Rust;
using Generator.IO; using Generator.IO;
@ -15,7 +16,7 @@ namespace Generator.Enums.Rust {
readonly IdentifierConverter idConverter; readonly IdentifierConverter idConverter;
readonly Dictionary<TypeId, PartialEnumFileInfo?> toPartialFileInfo; readonly Dictionary<TypeId, PartialEnumFileInfo?> toPartialFileInfo;
readonly RustDocCommentWriter docWriter; readonly RustDocCommentWriter docWriter;
readonly RustDeprecatedWriter deprecatedWriter; readonly DeprecatedWriter deprecatedWriter;
readonly RustConstantsWriter constantsWriter; readonly RustConstantsWriter constantsWriter;
sealed class PartialEnumFileInfo { sealed class PartialEnumFileInfo {
@ -190,7 +191,7 @@ namespace Generator.Enums.Rust {
uint expectedValue = 0; uint expectedValue = 0;
foreach (var value in enumValues) { foreach (var value in enumValues) {
docWriter.WriteSummary(writer, value.Documentation, enumType.RawName); docWriter.WriteSummary(writer, value.Documentation, enumType.RawName);
deprecatedWriter.WriteDeprecated(writer, value, "serde"); deprecatedWriter.WriteDeprecated(writer, value);
if (expectedValue != value.Value || enumType.IsPublic || isSerializePublic) if (expectedValue != value.Value || enumType.IsPublic || isSerializePublic)
writer.WriteLine($"{value.Name(idConverter)} = {value.Value},"); writer.WriteLine($"{value.Name(idConverter)} = {value.Value},");
else else

View File

@ -553,7 +553,7 @@ pub enum OpKind {
/// DEPRECATED. Use [`Memory`] /// DEPRECATED. Use [`Memory`]
/// ///
/// [`Memory`]: enum.OpKind.html#variant.Memory /// [`Memory`]: enum.OpKind.html#variant.Memory
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.11.0", note = "Don't use it!"))] #[deprecated(since = "1.11.0", note = "Don't use it!")]
Memory64 = 24, Memory64 = 24,
/// Memory operand. /// Memory operand.
/// ///

View File

@ -1190,25 +1190,25 @@ pub enum Register {
TMM6 = 247, TMM6 = 247,
TMM7 = 248, TMM7 = 248,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUse0 = 249, DontUse0 = 249,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFA = 250, DontUseFA = 250,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFB = 251, DontUseFB = 251,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFC = 252, DontUseFC = 252,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFD = 253, DontUseFD = 253,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFE = 254, DontUseFE = 254,
/// Don't use it! /// Don't use it!
#[cfg_attr(not(feature = "serde"), deprecated(since = "1.12.0", note = "Not part of the public API"))] #[deprecated(since = "1.12.0", note = "Not part of the public API")]
DontUseFF = 255, DontUseFF = 255,
} }
#[rustfmt::skip] #[rustfmt::skip]