@@ -22,7 +22,6 @@ use rustc_middle::ty::{
2222} ;
2323use rustc_span:: Span ;
2424use rustc_target:: abi:: { HasDataLayout , Size , TargetDataLayout } ;
25- use rustc_trait_selection:: traits;
2625
2726use crate :: const_prop:: CanConstProp ;
2827use crate :: const_prop:: ConstPropMachine ;
@@ -35,9 +34,9 @@ use crate::MirLint;
3534/// Severely regress performance.
3635const MAX_ALLOC_LIMIT : u64 = 1024 ;
3736
38- pub struct ConstProp ;
37+ pub struct ConstPropLint ;
3938
40- impl < ' tcx > MirLint < ' tcx > for ConstProp {
39+ impl < ' tcx > MirLint < ' tcx > for ConstPropLint {
4140 fn run_lint ( & self , tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) {
4241 if body. tainted_by_errors . is_some ( ) {
4342 return ;
@@ -49,61 +48,25 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
4948 }
5049
5150 let def_id = body. source . def_id ( ) . expect_local ( ) ;
52- let is_fn_like = tcx. def_kind ( def_id) . is_fn_like ( ) ;
53- let is_assoc_const = tcx. def_kind ( def_id) == DefKind :: AssocConst ;
51+ let def_kind = tcx. def_kind ( def_id) ;
52+ let is_fn_like = def_kind. is_fn_like ( ) ;
53+ let is_assoc_const = def_kind == DefKind :: AssocConst ;
5454
5555 // Only run const prop on functions, methods, closures and associated constants
5656 if !is_fn_like && !is_assoc_const {
5757 // skip anon_const/statics/consts because they'll be evaluated by miri anyway
58- trace ! ( "ConstProp skipped for {:?}" , def_id) ;
58+ trace ! ( "ConstPropLint skipped for {:?}" , def_id) ;
5959 return ;
6060 }
6161
62- let is_generator = tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) . is_generator ( ) ;
6362 // FIXME(welseywiser) const prop doesn't work on generators because of query cycles
6463 // computing their layout.
65- if is_generator {
66- trace ! ( "ConstProp skipped for generator {:?}" , def_id) ;
64+ if let DefKind :: Generator = def_kind {
65+ trace ! ( "ConstPropLint skipped for generator {:?}" , def_id) ;
6766 return ;
6867 }
6968
70- // Check if it's even possible to satisfy the 'where' clauses
71- // for this item.
72- // This branch will never be taken for any normal function.
73- // However, it's possible to `#!feature(trivial_bounds)]` to write
74- // a function with impossible to satisfy clauses, e.g.:
75- // `fn foo() where String: Copy {}`
76- //
77- // We don't usually need to worry about this kind of case,
78- // since we would get a compilation error if the user tried
79- // to call it. However, since we can do const propagation
80- // even without any calls to the function, we need to make
81- // sure that it even makes sense to try to evaluate the body.
82- // If there are unsatisfiable where clauses, then all bets are
83- // off, and we just give up.
84- //
85- // We manually filter the predicates, skipping anything that's not
86- // "global". We are in a potentially generic context
87- // (e.g. we are evaluating a function without substituting generic
88- // parameters, so this filtering serves two purposes:
89- //
90- // 1. We skip evaluating any predicates that we would
91- // never be able prove are unsatisfiable (e.g. `<T as Foo>`
92- // 2. We avoid trying to normalize predicates involving generic
93- // parameters (e.g. `<T as Foo>::MyItem`). This can confuse
94- // the normalization code (leading to cycle errors), since
95- // it's usually never invoked in this way.
96- let predicates = tcx
97- . predicates_of ( def_id. to_def_id ( ) )
98- . predicates
99- . iter ( )
100- . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
101- if traits:: impossible_predicates ( tcx, traits:: elaborate ( tcx, predicates) . collect ( ) ) {
102- trace ! ( "ConstProp skipped for {:?}: found unsatisfiable predicates" , def_id) ;
103- return ;
104- }
105-
106- trace ! ( "ConstProp starting for {:?}" , def_id) ;
69+ trace ! ( "ConstPropLint starting for {:?}" , def_id) ;
10770
10871 // FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
10972 // constants, instead of just checking for const-folding succeeding.
@@ -112,7 +75,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
11275 let mut linter = ConstPropagator :: new ( body, tcx) ;
11376 linter. visit_body ( body) ;
11477
115- trace ! ( "ConstProp done for {:?}" , def_id) ;
78+ trace ! ( "ConstPropLint done for {:?}" , def_id) ;
11679 }
11780}
11881
0 commit comments