mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-26 09:49:15 +00:00
Normalize projections in evaluated const display and layout calculation
This commit is contained in:
parent
bd0289e0e9
commit
1cd9e683e8
3 changed files with 39 additions and 0 deletions
|
|
@ -45,6 +45,7 @@ use crate::{
|
||||||
db::{HirDatabase, InternedClosure},
|
db::{HirDatabase, InternedClosure},
|
||||||
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
|
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
|
||||||
generics::generics,
|
generics::generics,
|
||||||
|
infer::normalize,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
lt_from_placeholder_idx,
|
lt_from_placeholder_idx,
|
||||||
mapping::from_chalk,
|
mapping::from_chalk,
|
||||||
|
|
@ -657,6 +658,7 @@ fn render_const_scalar(
|
||||||
// infrastructure and have it here as a field on `f`.
|
// infrastructure and have it here as a field on `f`.
|
||||||
let trait_env =
|
let trait_env =
|
||||||
TraitEnvironment::empty(*f.db.crate_graph().crates_in_topological_order().last().unwrap());
|
TraitEnvironment::empty(*f.db.crate_graph().crates_in_topological_order().last().unwrap());
|
||||||
|
let ty = normalize(f.db, trait_env.clone(), ty.clone());
|
||||||
match ty.kind(Interner) {
|
match ty.kind(Interner) {
|
||||||
TyKind::Scalar(s) => match s {
|
TyKind::Scalar(s) => match s {
|
||||||
Scalar::Bool => write!(f, "{}", b[0] != 0),
|
Scalar::Bool => write!(f, "{}", b[0] != 0),
|
||||||
|
|
|
||||||
|
|
@ -435,6 +435,9 @@ pub fn layout_of_ty_query(
|
||||||
TyKind::Error => return Err(LayoutError::HasErrorType),
|
TyKind::Error => return Err(LayoutError::HasErrorType),
|
||||||
TyKind::AssociatedType(id, subst) => {
|
TyKind::AssociatedType(id, subst) => {
|
||||||
// Try again with `TyKind::Alias` to normalize the associated type.
|
// Try again with `TyKind::Alias` to normalize the associated type.
|
||||||
|
// Usually we should not try to normalize `TyKind::AssociatedType`, but layout calculation is used
|
||||||
|
// in monomorphized MIR where this is okay. If outside monomorphization, this will lead to cycle,
|
||||||
|
// which we will recover from with an error.
|
||||||
let ty = TyKind::Alias(chalk_ir::AliasTy::Projection(ProjectionTy {
|
let ty = TyKind::Alias(chalk_ir::AliasTy::Projection(ProjectionTy {
|
||||||
associated_ty_id: *id,
|
associated_ty_id: *id,
|
||||||
substitution: subst.clone(),
|
substitution: subst.clone(),
|
||||||
|
|
|
||||||
|
|
@ -10947,3 +10947,37 @@ pub struct ManuallyDrop$0<T: ?Sized> {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn projection_const() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
pub trait PublicFlags {
|
||||||
|
type Internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NoteDialects(<NoteDialects as PublicFlags>::Internal);
|
||||||
|
|
||||||
|
impl NoteDialects {
|
||||||
|
pub const CLAP$0: Self = Self(InternalBitFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct InternalBitFlags;
|
||||||
|
|
||||||
|
impl PublicFlags for NoteDialects {
|
||||||
|
type Internal = InternalBitFlags;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*CLAP*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
ra_test_fixture::NoteDialects
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const CLAP: Self = NoteDialects(InternalBitFlags)
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue