Skip to content

Commit

Permalink
codegen/flags: Add missing display trait generation
Browse files Browse the repository at this point in the history
Analysis was copied from enums which adds an std::fmt when
generate_display_trait is true, but the codegen for it was missing.
Instead of removing the import, provide a simple Display trait that
forwards to bitflags' Debug implementation.
  • Loading branch information
MarijnS95 committed Dec 4, 2020
1 parent ef006ce commit 733768d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/codegen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ fn generate_flags(

writeln!(w)?;

if config.generate_display_trait {
// Generate Display trait implementation.
version_condition(w, env, flags.version, false, 0)?;
writeln!(
w,
"impl fmt::Display for {0} {{\n\
\tfn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {{\n\
\t\t<Self as fmt::Debug>::fmt(self, f)\n\
\t}}\n\
}}\n",
flags.name
)?;
}

version_condition(w, env, flags.version, false, 0)?;
writeln!(
w,
Expand Down

0 comments on commit 733768d

Please sign in to comment.