Skip to content

tuple structs with all-public fields can not be instantiated if one of the fields has an external attribute #66555

@DarkKirb

Description

@DarkKirb

In current nightly (2019-11-18 and also 2019-11-16) and stable (1.39.0), tuple structs can not be instantiated from an outside module directly if

  • all of the members are public
  • at least one of the struct members has an attribute (like #[serde(rename = "some_name")])

Example code that is broken:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7108f99f96b03247b7d44bdf47091a1a

In the same module the code works:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a896f6f28a050228c4e91d9e3bcc5557

Same with normal structs:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=2083f2cae68b7378652bd239bb122d20

The broken code works in 1.38.0:

https://godbolt.org/z/_8KX6P

Meta

One of the affected installations:

rustc 1.41.0-nightly (5c5b8afd8 2019-11-16)
binary: rustc
commit-hash: 5c5b8afd80e6fa1d24632153cb2257c686041d41
commit-date: 2019-11-16
host: x86_64-apple-darwin
release: 1.41.0-nightly
LLVM version: 9.0

Activity

added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
A-visibilityArea: Visibility / privacy
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 19, 2019
Erk-

Erk- commented on Nov 19, 2019

@Erk-
Contributor

It seems to only happen with external attributes. Attributes like #[deprecated] and similar does not show this bug.

changed the title [-]tuple structs with all-public fields can not be instantiated if one of the fields has an attribute[/-] [+]tuple structs with all-public fields can not be instantiated if one of the fields has an external attribute[/+] on Nov 19, 2019
petrochenkov

petrochenkov commented on Nov 19, 2019

@petrochenkov
Contributor

Minimized:

mod m {
    pub struct S(#[rustfmt::skip] pub u8);
}

fn main() {
    m::S(0);
}
petrochenkov

petrochenkov commented on Nov 20, 2019

@petrochenkov
Contributor

Similarly to #66487, this issue was introduced by #63468 and recently unmasked for derive helper attributes by #64694.

self-assigned this
on Nov 20, 2019
pnkfelix

pnkfelix commented on Nov 21, 2019

@pnkfelix
Member

Based on @petrochenkov 's assertion that this was introduced by PR #63468, marking this as a stable-to-stable regression.

pnkfelix

pnkfelix commented on Nov 22, 2019

@pnkfelix
Member

Marking P-high, mostly because of the risk that a crate might rely on being able to use struct literal expressions in other modules, and then a later version of that crate wants to put an attribute on of the fields of the struct literal.

petrochenkov

petrochenkov commented on Nov 23, 2019

@petrochenkov
Contributor

Fixed in #66669.

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

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @pnkfelix@jonas-schievink@Erk-@petrochenkov@DarkKirb

    Issue actions

      tuple structs with all-public fields can not be instantiated if one of the fields has an external attribute · Issue #66555 · rust-lang/rust