mirror of
https://github.com/rust-lang/rust.git
synced 2026-02-15 07:44:23 +00:00
If a type is incomplete, for example if generic parameters are not available yet, although they are not escaping, its layout may not be computable. Calling `TyCtxt::layout_of()` would create a delayed bug in the compiler.
105 lines
2.4 KiB
Rust
105 lines
2.4 KiB
Rust
#![warn(clippy::zero_sized_map_values)]
|
|
use std::collections::HashMap;
|
|
|
|
const CONST_OK: Option<HashMap<String, usize>> = None;
|
|
const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
|
|
//~^ zero_sized_map_values
|
|
|
|
static STATIC_OK: Option<HashMap<String, usize>> = None;
|
|
static STATIC_NOT_OK: Option<HashMap<String, ()>> = None;
|
|
//~^ zero_sized_map_values
|
|
|
|
type OkMap = HashMap<String, usize>;
|
|
type NotOkMap = HashMap<String, ()>;
|
|
//~^ zero_sized_map_values
|
|
|
|
enum TestEnum {
|
|
Ok(HashMap<String, usize>),
|
|
NotOk(HashMap<String, ()>),
|
|
//~^ zero_sized_map_values
|
|
}
|
|
|
|
struct Test {
|
|
ok: HashMap<String, usize>,
|
|
not_ok: HashMap<String, ()>,
|
|
//~^ zero_sized_map_values
|
|
also_not_ok: Vec<HashMap<usize, ()>>,
|
|
//~^ zero_sized_map_values
|
|
}
|
|
|
|
trait TestTrait {
|
|
type Output;
|
|
|
|
fn produce_output() -> Self::Output;
|
|
|
|
fn weird_map(&self, map: HashMap<usize, ()>);
|
|
//~^ zero_sized_map_values
|
|
}
|
|
|
|
impl Test {
|
|
fn ok(&self) -> HashMap<String, usize> {
|
|
todo!()
|
|
}
|
|
|
|
fn not_ok(&self) -> HashMap<String, ()> {
|
|
//~^ zero_sized_map_values
|
|
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl TestTrait for Test {
|
|
type Output = HashMap<String, ()>;
|
|
|
|
fn produce_output() -> Self::Output {
|
|
todo!();
|
|
}
|
|
|
|
fn weird_map(&self, map: HashMap<usize, ()>) {
|
|
todo!();
|
|
}
|
|
}
|
|
|
|
fn test(map: HashMap<String, ()>, key: &str) -> HashMap<String, ()> {
|
|
//~^ zero_sized_map_values
|
|
//~| zero_sized_map_values
|
|
|
|
todo!();
|
|
}
|
|
|
|
fn test2(map: HashMap<String, usize>, key: &str) -> HashMap<String, usize> {
|
|
todo!();
|
|
}
|
|
|
|
fn issue14822() {
|
|
trait Trait {
|
|
type T;
|
|
}
|
|
struct S<T: Trait>(T::T);
|
|
|
|
// The `delay_bug` happens when evaluating the pointer metadata of `S<T>` which depends on
|
|
// whether `T::T` is `Sized`. Since the type alias doesn't have a trait bound of `T: Trait`
|
|
// evaluating `T::T: Sized` ultimately fails with `NoSolution`.
|
|
type A<T> = HashMap<u32, *const S<T>>;
|
|
type B<T> = HashMap<u32, S<T>>;
|
|
|
|
enum E {}
|
|
impl Trait for E {
|
|
type T = ();
|
|
}
|
|
type C = HashMap<u32, *const S<E>>;
|
|
type D = HashMap<u32, S<E>>;
|
|
//~^ zero_sized_map_values
|
|
}
|
|
|
|
fn main() {
|
|
let _: HashMap<String, ()> = HashMap::new();
|
|
//~^ zero_sized_map_values
|
|
//~| zero_sized_map_values
|
|
|
|
let _: HashMap<String, usize> = HashMap::new();
|
|
|
|
let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
|
|
//~^ zero_sized_map_values
|
|
}
|