Skip to content

rustc sometimes resolves an ambiguous generic parameter instead of erroring #91369

Open
@TheBlueMatt

Description

@TheBlueMatt

Apologies that I don't have a minimum reproduction but I've tried a few ways and thus far failed to reproduce outside of the original crate.

We recently had an error where we were deserializing a dummy object for backwards-compatibility, but the type being read was ambiguous, causing the code to behave unexpectedly. For some reason rustc concretized the object to an Option<()> (guessing based on {:?} output, as I can't tell why it was concretized) when it was ambiguous (we really wanted an Option<u64> but didn't specify it).

You can see the change which fixes it at lightningdevkit/rust-lightning#1195, which makes pretty clear that the object's type was, in fact, ambiguous (switching the changed declaration to None::<()> works just as well, while changing behavior). The read_tlv_fields macro isn't all that complicated - https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/util/ser_macros.rs#L332 - it basically just calls into decode_tlv_stream which is pretty straightforward - https://github.com/lightningdevkit/rust-lightning/blob/main/lightning/src/util/ser_macros.rs#L168.

I tried (and failed) to get a minimum reproduction which at least shows the high-level code structure at https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=c873827053afdaa20d333703d00fd16f (the actual relevant things are mostly in util::ser and util::ser_macros in the real code).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.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