Skip to content

Contradictory E0423 (constructor not visible due to private fields) when attributes are not in scope #66853

Closed
@boxofrox

Description

@boxofrox

Example at https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0a4268fac37b445aada5d32934c465ae.

I'm upgrading a 2015 project to 2018 and ran into a wall of errors. I started with the E0423 (as seen in the example), but couldn't figure out why Rust thought this struct had private fields.

error[E0423]: expected function, found struct `Sequence`
 --> src/main.rs:7:19
  |
7 |     let payload = Sequence(data.iter());
  |                   ^^^^^^^^ constructor is not visible here due to private fields
help: possible better candidates are found in other modules, you can import them into scope
  |
1 | use ring::io::der::Tag::Sequence;
  |
1 | use serde_yaml::Value::Sequence;
  |
1 | use weedle::term::Sequence;
  |
1 | use weedle::types::NonAnyType::Sequence;
#[derive(Serialize)]
#[serde(bound(serialize = "T : Clone + Iterator, T::Item : Serialize"))]
pub struct Sequence<T>(#[serde(serialize_with = "serialize_iter")] pub T);

pub T is pub. Since I was getting nowhere with that error, I moved on to the missing serde imports, which fixed the E0423 error.

I'm reporting this, because the error is unexpected to a perpetual newbie such as myself. If Rust cannot make sense of the attributes, I would expect Rust to ignore them as if they weren't there, and recognize the pub T, so the E0423 wasn't erroneously reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions