作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Self::It-6ren">
use std::iter::Iterator;
trait ListTerm<'a> {
type Iter: Iterator<Item = &'a u32>;
fn iter(&'a self) -> Self::Iter;
}
enum TermValue<'a, LT>
where
LT: ListTerm<'a> + Sized + 'a,
{
Str(LT),
}
error[E0392]: parameter `'a` is never used
--> src/main.rs:8:16
|
8 | enum TermValue<'a, LT>
| ^^ unused type parameter
|
= help: consider removing `'a` or using a marker such as `std::marker::PhantomData`
'a
显然正在使用。这是一个错误,还是参数枚举还没有真正完成?
rustc --explain E0392
推荐使用
PhantomData<&'a _>
,但我认为在我的用例中没有任何机会这样做。
最佳答案
'a
clearly is being used.
struct
的主体中的某处使用。或
enum
.约束不计算在内。
enum TermValue<LT>
where
for<'a> LT: 'a + ListTerm<'a> + Sized,
{
Str(LT),
}
PhantomData
表示您希望一个类型表现得好像它使用参数一样:
use std::marker::PhantomData;
struct Thing<'a> {
// Causes the type to function *as though* it has a `&'a ()` field,
// despite not *actually* having one.
_marker: PhantomData<&'a ()>,
}
PhantomData
在
enum
;将其放入其中一种变体中:
enum TermValue<'a, LT>
where
LT: 'a + ListTerm<'a> + Sized,
{
Str(LT, PhantomData<&'a ()>),
}
关于rust - "parameter ` 'a` 从未使用 "error when ' a 用于类型参数绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64847153/
我是一名优秀的程序员,十分优秀!