mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 21:25:25 +00:00 
			
		
		
		
	Remove dead code and extend test coverage and diagnostics around it
We lost the following comment during refactorings: The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
This commit is contained in:
		
							parent
							
								
									b516b302ef
								
							
						
					
					
						commit
						31b88819c7
					
				
					 1 changed files with 3 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
use std::{cmp, ops::Bound};
 | 
			
		||||
 | 
			
		||||
use hir_def::{
 | 
			
		||||
    AdtId, VariantId,
 | 
			
		||||
    layout::{Integer, ReprOptions, TargetDataLayout},
 | 
			
		||||
    signatures::{StructFlags, VariantFields},
 | 
			
		||||
    AdtId, VariantId,
 | 
			
		||||
};
 | 
			
		||||
use intern::sym;
 | 
			
		||||
use rustc_index::IndexVec;
 | 
			
		||||
| 
						 | 
				
			
			@ -13,9 +13,9 @@ use smallvec::SmallVec;
 | 
			
		|||
use triomphe::Arc;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    Substitution, TraitEnvironment,
 | 
			
		||||
    db::HirDatabase,
 | 
			
		||||
    layout::{Layout, LayoutError, field_ty},
 | 
			
		||||
    layout::{field_ty, Layout, LayoutError},
 | 
			
		||||
    Substitution, TraitEnvironment,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
use super::LayoutCx;
 | 
			
		||||
| 
						 | 
				
			
			@ -85,16 +85,6 @@ pub fn layout_of_adt_query(
 | 
			
		|||
                let d = db.const_eval_discriminant(e.enum_variants(db).variants[id.0].0).ok()?;
 | 
			
		||||
                Some((id, d))
 | 
			
		||||
            }),
 | 
			
		||||
            // FIXME: The current code for niche-filling relies on variant indices
 | 
			
		||||
            // instead of actual discriminants, so enums with
 | 
			
		||||
            // explicit discriminants (RFC #2363) would misbehave and we should disable
 | 
			
		||||
            // niche optimization for them.
 | 
			
		||||
            // The code that do it in rustc:
 | 
			
		||||
            // repr.inhibit_enum_layout_opt() || def
 | 
			
		||||
            //     .variants()
 | 
			
		||||
            //     .iter_enumerated()
 | 
			
		||||
            //     .any(|(i, v)| v.discr != ty::VariantDiscr::Relative(i.as_u32()))
 | 
			
		||||
            repr.inhibit_enum_layout_opt(),
 | 
			
		||||
            !matches!(def, AdtId::EnumId(..))
 | 
			
		||||
                && variants
 | 
			
		||||
                    .iter()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue