Skip to content

Change the debug! macro ast expansion for temporaries

Closed

Description

Currently, expanding debug!("{}", foo) looks something like:

static PRECOMPILED_FORMAT_STRING = ...;
let foo_addr = &foo;
let arguments: &fmt::Arguments = unsafe { /* do things with foo_addr */ };
fmt::writeln(logger, arguments)

This is a problem with the new temporary rules because you can't debug!("{}", some_ref_cell.borrow().get()). This is because the borrow() ends after the enclosing statement which in this case is let foo_addr = &foo;

In order to allow debugging these values, we should change the ast expansion to:

static PRECOMPILED_FORMAT_STRING = ...;
match foo {
    ref foo_addr => {
        let arguments: &fmt::Arguments = unsafe { /* do things with foo_addr */ };
        fmt::writeln(logger, arguments)
    }
}

Note that with a match the enclosing statement encompasses the entire formatting call, so debugging foo.borrow().get() should be valid. One other portion of this bug would be ensuring that codegen doesn't suffer in terms of compile-time or size as a result of this change. It is currently unknown how much a match scope would affect codegen.

cc @nikomatsakis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions