Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TAIT regression on nightly-2024-03-12 #122388

Closed
xxchan opened this issue Mar 12, 2024 · 2 comments
Closed

TAIT regression on nightly-2024-03-12 #122388

xxchan opened this issue Mar 12, 2024 · 2 comments
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@xxchan
Copy link
Contributor

xxchan commented Mar 12, 2024

regression in #121796 cc @oli-obk

I tried this code.

error[E0792]: non-defining opaque type use in defining scope
  --> src/main.rs:37:38
   |
37 |     pub fn test_int_counter_vec() -> Self {
   |                                      ^^^^ argument `prometheus::core::AtomicU64` is not a generic parameter
   |
note: for this opaque type
  --> src/main.rs:25:43
   |
25 | pub type VecBuilderOfCounter<P: Atomic> = impl MetricVecBuilder<M = GenericCounter<P>>;
   |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[package]
name = "tmp"
version = "0.1.0"
edition = "2021"

[dependencies]
prometheus = { version = "0.13" }
#![feature(type_alias_impl_trait)]

use prometheus::{
    core::{
        Atomic, AtomicU64, Collector, Desc, GenericCounter, GenericCounterVec, MetricVec,
        MetricVecBuilder,
    },
    proto::MetricFamily,
};

#[derive(Clone)]
pub struct LabelGuardedMetricVec<T: MetricVecBuilder, const N: usize> {
    inner: MetricVec<T>,
}

impl<T: MetricVecBuilder, const N: usize> Collector for LabelGuardedMetricVec<T, N> {
    fn desc(&self) -> Vec<&Desc> {
        self.inner.desc()
    }

    fn collect(&self) -> Vec<MetricFamily> {
        todo!()
    }
}
pub type VecBuilderOfCounter<P: Atomic> = impl MetricVecBuilder<M = GenericCounter<P>>;

pub type LabelGuardedIntCounterVec<const N: usize> =
    LabelGuardedMetricVec<VecBuilderOfCounter<AtomicU64>, N>;

impl<T: MetricVecBuilder, const N: usize> LabelGuardedMetricVec<T, N> {
    pub fn new(inner: MetricVec<T>, labels: &[&'static str; N]) -> Self {
        Self { inner }
    }
}

impl<const N: usize> LabelGuardedIntCounterVec<N> {
    pub fn test_int_counter_vec() -> Self {
        let label = &gen_test_label::<N>();
        let inner =
            prometheus::IntCounterVec::new(prometheus::opts!("test", "test"), label).unwrap();
        let inner = __extract_counter_builder(inner);
        let label_guarded = LabelGuardedIntCounterVec::new(inner, label);
        label_guarded
    }
}

fn gen_test_label<const N: usize>() -> [&'static str; N] {
    const TEST_LABELS: [&str; 5] = ["test1", "test2", "test3", "test4", "test5"];
    (0..N)
        .map(|i| TEST_LABELS[i])
        .collect::<Vec<_>>()
        .try_into()
        .unwrap()
}

pub fn __extract_counter_builder<P: Atomic>(
    vec: GenericCounterVec<P>,
) -> MetricVec<VecBuilderOfCounter<P>> {
    vec
}
@xxchan xxchan added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Mar 12, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 12, 2024
@oli-obk oli-obk added requires-nightly This issue requires a nightly compiler in some way. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` and removed regression-untriaged Untriaged performance or correctness regression. labels Mar 12, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Mar 12, 2024

This is expected breakage. I forgot the PR would already cause most of the breakage we wanted to do. For now you need to move your type alias into a submodule, but the next step is that we provide a #[defines(VecBuilderOfCounter)] attribute that you can add to the functions that should actually be defining

@xxchan
Copy link
Contributor Author

xxchan commented Mar 12, 2024

Thanks for the explanation!

@xxchan xxchan closed this as completed Mar 12, 2024
@jieyouxu jieyouxu removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants