Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually implement Debug for ImportKind. #100592

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::{mem, ptr};
type Res = def::Res<NodeId>;

/// Contains data for specific kinds of imports.
#[derive(Clone, Debug)]
#[derive(Clone)]
pub enum ImportKind<'a> {
Single {
/// `source` in `use prefix::source as target`.
Expand Down Expand Up @@ -62,6 +62,44 @@ pub enum ImportKind<'a> {
MacroUse,
}

/// Manually implement `Debug` for `ImportKind` because the `source/target_bindings`
/// contain `Cell`s which can introduce infinite loops while printing.
impl<'a> std::fmt::Debug for ImportKind<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use ImportKind::*;
match self {
Single {
ref source,
ref target,
ref type_ns_only,
ref nested,
ref additional_ids,
// Ignore the following to avoid an infinite loop while printing.
source_bindings: _,
target_bindings: _,
} => f
.debug_struct("Single")
.field("source", source)
.field("target", target)
.field("type_ns_only", type_ns_only)
.field("nested", nested)
.field("additional_ids", additional_ids)
cjgillot marked this conversation as resolved.
Show resolved Hide resolved
.finish(),
cjgillot marked this conversation as resolved.
Show resolved Hide resolved
Glob { ref is_prelude, ref max_vis } => f
.debug_struct("Glob")
.field("is_prelude", is_prelude)
.field("max_vis", max_vis)
.finish(),
ExternCrate { ref source, ref target } => f
.debug_struct("ExternCrate")
.field("source", source)
.field("target", target)
.finish(),
MacroUse => f.debug_struct("MacroUse").finish(),
}
}
}

/// One import.
#[derive(Debug, Clone)]
pub(crate) struct Import<'a> {
Expand Down