Skip to content

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

Closed
@xxchan

Description

@xxchan

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions