Skip to content

Should we use an enum to encode fields? #75550

Closed
@tesuji

Description

@tesuji

rust/src/librustc_span/lib.rs

Lines 1079 to 1088 in 668a34e

pub struct SourceFile {
/// The name of the file that the source came from. Source that doesn't
/// originate from files has names between angle brackets by convention
/// (e.g., `<anon>`).
pub name: FileName,
/// `true` if the `name` field above has been modified by `--remap-path-prefix`.
pub name_was_remapped: bool,
/// The unmapped path of the file that the source came from.
/// Set to `None` if the `SourceFile` was imported from an external crate.
pub unmapped_path: Option<FileName>,

enum Name {
    /// The name of the file that the source came from. Source that doesn't 
    /// originate from files has names between angle brackets by convention 
    /// (e.g., `<anon>`). 
    Normal(FileName),
    /// FileName modified by `--remap-path-prefix`. 
    Remapped(FileName),
}

pub struct SourceFile { 
    pub name: Name,
    /// The unmapped path of the file that the source came from. 
    /// Set to `None` if the `SourceFile` was imported from an external crate. 
    pub unmapped_path: Option<FileName>, 
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions