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

View File

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

View File

@ -553,7 +553,7 @@ pub enum OpKind {
/// DEPRECATED. Use [`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,
/// Memory operand.
///

View File

@ -1190,25 +1190,25 @@ pub enum Register {
TMM6 = 247,
TMM7 = 248,
/// 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,
/// 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,
/// 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,
/// 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,
/// 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,
/// 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,
/// 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,
}
#[rustfmt::skip]