Skip to content

Is there a gentler way to land the assert_matches macro? #82913

Closed
@anp

Description

@anp

As a user I'm really excited for std::assert_matches!, but I'm a little worried about the level of breakage it introduces and I'm hoping to discuss possible paths forward.

The Fuchsia roll to update rustc is currently blocked by ambiguous macro resolution errors with code that glob-imports matches::assert_matches!. It seems that a locally defined glob import does not take precedence over macros defined in std.

This implies a workaround of changing all the glob imports to use matches::assert_matches, but this does not account for submodules which use super::*;. Unfortunately it seems that the test_case crate wraps the function body in a submodule and adds a use super::*to the new module.

What this means in practice is that every function using the test_case crate must have an explicit import added or have the macro referenced via a fully qualified name. AIUI this change counts as an acceptable breakage and so I'm still putting together a diff which will resolve all of our roll blockers.

What I'm wondering though is whether knowing about this source of breakage offers a path to a smoother release. If so, we could revert the change and prepare to roll it out more gently.

Two options that came up in private discussions:

  1. remove assert_matches from the prelude until the 2021 edition
  • this wouldn't make it immediately available but it would prevent the breakage
  1. make local glob imports take precedence over std/prelude macros
  • this would make it immediately available but may not be possible within language constraints

Any other suggestions for how to make this change less disruptive? cc @m-ou-se @tmandry @joshtriplett

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyT-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-releaseRelevant to the release subteam, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions