Yes, you can use auto-tags for this:
auto trait NotReference {}
impl<'a, T> !NotReference for &'a T {}
impl<'a, T> !NotReference for &'a mut T {}
fn no_references<T: NotReference>(_: T) {}
fn main() {
no_references(42); // OK
no_references(&42); // the trait bound `&{integer}: NotReference` is not satisfied
no_references("hello"); // the trait bound `&str: NotReference` is not satisfied
no_references(vec![1, 2, 3]); // OK
let x = vec![1, 2, 3];
no_references(x.iter()); // the trait bound `&{integer}: NotReference` is not satisfied in `std::slice::Iter<'_, {integer}>`
}
Please note that this also excludes:
- tagged with a
'statichello call - , ,
iter()
.
, 'static:
fn foo<T: 'static>(x: T) -> T {}