File tree 3 files changed +39
-0
lines changed
src/tools/rust-analyzer/crates
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ use crate::{
45
45
db:: { HirDatabase , InternedClosure } ,
46
46
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
47
47
generics:: generics,
48
+ infer:: normalize,
48
49
layout:: Layout ,
49
50
lt_from_placeholder_idx,
50
51
mapping:: from_chalk,
@@ -657,6 +658,7 @@ fn render_const_scalar(
657
658
// infrastructure and have it here as a field on `f`.
658
659
let trait_env =
659
660
TraitEnvironment :: empty ( * f. db . crate_graph ( ) . crates_in_topological_order ( ) . last ( ) . unwrap ( ) ) ;
661
+ let ty = normalize ( f. db , trait_env. clone ( ) , ty. clone ( ) ) ;
660
662
match ty. kind ( Interner ) {
661
663
TyKind :: Scalar ( s) => match s {
662
664
Scalar :: Bool => write ! ( f, "{}" , b[ 0 ] != 0 ) ,
Original file line number Diff line number Diff line change @@ -435,6 +435,9 @@ pub fn layout_of_ty_query(
435
435
TyKind :: Error => return Err ( LayoutError :: HasErrorType ) ,
436
436
TyKind :: AssociatedType ( id, subst) => {
437
437
// Try again with `TyKind::Alias` to normalize the associated type.
438
+ // Usually we should not try to normalize `TyKind::AssociatedType`, but layout calculation is used
439
+ // in monomorphized MIR where this is okay. If outside monomorphization, this will lead to cycle,
440
+ // which we will recover from with an error.
438
441
let ty = TyKind :: Alias ( chalk_ir:: AliasTy :: Projection ( ProjectionTy {
439
442
associated_ty_id : * id,
440
443
substitution : subst. clone ( ) ,
Original file line number Diff line number Diff line change @@ -10947,3 +10947,37 @@ pub struct ManuallyDrop$0<T: ?Sized> {
10947
10947
"# ] ] ,
10948
10948
) ;
10949
10949
}
10950
+
10951
+ #[ test]
10952
+ fn projection_const ( ) {
10953
+ check (
10954
+ r#"
10955
+ pub trait PublicFlags {
10956
+ type Internal;
10957
+ }
10958
+
10959
+ pub struct NoteDialects(<NoteDialects as PublicFlags>::Internal);
10960
+
10961
+ impl NoteDialects {
10962
+ pub const CLAP$0: Self = Self(InternalBitFlags);
10963
+ }
10964
+
10965
+ pub struct InternalBitFlags;
10966
+
10967
+ impl PublicFlags for NoteDialects {
10968
+ type Internal = InternalBitFlags;
10969
+ }
10970
+ "# ,
10971
+ expect ! [ [ r#"
10972
+ *CLAP*
10973
+
10974
+ ```rust
10975
+ ra_test_fixture::NoteDialects
10976
+ ```
10977
+
10978
+ ```rust
10979
+ pub const CLAP: Self = NoteDialects(InternalBitFlags)
10980
+ ```
10981
+ "# ] ] ,
10982
+ ) ;
10983
+ }
You can’t perform that action at this time.
0 commit comments