@@ -23,14 +23,12 @@ use polonius_engine::Atom;
23
23
use rustc_data_structures:: fx:: FxHashSet ;
24
24
use rustc_data_structures:: graph:: dominators:: Dominators ;
25
25
use rustc_data_structures:: graph:: { self , GraphSuccessors } ;
26
- use rustc_data_structures:: sync:: Lrc ;
27
26
use rustc_index:: bit_set:: BitMatrix ;
28
27
use rustc_index:: vec:: { Idx , IndexVec } ;
29
28
use rustc_macros:: HashStable ;
30
29
use rustc_serialize:: { Decodable , Encodable } ;
31
30
use rustc_span:: symbol:: Symbol ;
32
31
use rustc_span:: { Span , DUMMY_SP } ;
33
- use smallvec:: SmallVec ;
34
32
use std:: borrow:: Cow ;
35
33
use std:: fmt:: { self , Debug , Display , Formatter , Write } ;
36
34
use std:: ops:: Index ;
@@ -39,13 +37,15 @@ use std::{iter, mem, option, u32};
39
37
pub use syntax:: ast:: Mutability ;
40
38
use syntax:: ast:: Name ;
41
39
42
- pub use crate :: mir:: cache:: { BodyAndCache , ReadOnlyBodyAndCache } ;
43
- pub use crate :: mir:: interpret:: AssertMessage ;
40
+ pub use self :: cache:: { BodyAndCache , ReadOnlyBodyAndCache } ;
41
+ pub use self :: interpret:: AssertMessage ;
42
+ pub use self :: query:: * ;
44
43
pub use crate :: read_only;
45
44
46
45
mod cache;
47
46
pub mod interpret;
48
47
pub mod mono;
48
+ mod query;
49
49
pub mod tcx;
50
50
pub mod traversal;
51
51
pub mod visit;
@@ -2648,221 +2648,6 @@ impl Location {
2648
2648
}
2649
2649
}
2650
2650
2651
- #[ derive( Copy , Clone , PartialEq , RustcEncodable , RustcDecodable , HashStable ) ]
2652
- pub enum UnsafetyViolationKind {
2653
- General ,
2654
- /// Permitted both in `const fn`s and regular `fn`s.
2655
- GeneralAndConstFn ,
2656
- BorrowPacked ( hir:: HirId ) ,
2657
- }
2658
-
2659
- #[ derive( Copy , Clone , PartialEq , RustcEncodable , RustcDecodable , HashStable ) ]
2660
- pub struct UnsafetyViolation {
2661
- pub source_info : SourceInfo ,
2662
- pub description : Symbol ,
2663
- pub details : Symbol ,
2664
- pub kind : UnsafetyViolationKind ,
2665
- }
2666
-
2667
- #[ derive( Clone , RustcEncodable , RustcDecodable , HashStable ) ]
2668
- pub struct UnsafetyCheckResult {
2669
- /// Violations that are propagated *upwards* from this function.
2670
- pub violations : Lrc < [ UnsafetyViolation ] > ,
2671
- /// `unsafe` blocks in this function, along with whether they are used. This is
2672
- /// used for the "unused_unsafe" lint.
2673
- pub unsafe_blocks : Lrc < [ ( hir:: HirId , bool ) ] > ,
2674
- }
2675
-
2676
- rustc_index:: newtype_index! {
2677
- pub struct GeneratorSavedLocal {
2678
- derive [ HashStable ]
2679
- DEBUG_FORMAT = "_{}" ,
2680
- }
2681
- }
2682
-
2683
- /// The layout of generator state.
2684
- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable , TypeFoldable ) ]
2685
- pub struct GeneratorLayout < ' tcx > {
2686
- /// The type of every local stored inside the generator.
2687
- pub field_tys : IndexVec < GeneratorSavedLocal , Ty < ' tcx > > ,
2688
-
2689
- /// Which of the above fields are in each variant. Note that one field may
2690
- /// be stored in multiple variants.
2691
- pub variant_fields : IndexVec < VariantIdx , IndexVec < Field , GeneratorSavedLocal > > ,
2692
-
2693
- /// Which saved locals are storage-live at the same time. Locals that do not
2694
- /// have conflicts with each other are allowed to overlap in the computed
2695
- /// layout.
2696
- pub storage_conflicts : BitMatrix < GeneratorSavedLocal , GeneratorSavedLocal > ,
2697
- }
2698
-
2699
- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2700
- pub struct BorrowCheckResult < ' tcx > {
2701
- pub closure_requirements : Option < ClosureRegionRequirements < ' tcx > > ,
2702
- pub used_mut_upvars : SmallVec < [ Field ; 8 ] > ,
2703
- }
2704
-
2705
- /// The result of the `mir_const_qualif` query.
2706
- ///
2707
- /// Each field corresponds to an implementer of the `Qualif` trait in
2708
- /// `librustc_mir/transform/check_consts/qualifs.rs`. See that file for more information on each
2709
- /// `Qualif`.
2710
- #[ derive( Clone , Copy , Debug , Default , RustcEncodable , RustcDecodable , HashStable ) ]
2711
- pub struct ConstQualifs {
2712
- pub has_mut_interior : bool ,
2713
- pub needs_drop : bool ,
2714
- }
2715
-
2716
- /// After we borrow check a closure, we are left with various
2717
- /// requirements that we have inferred between the free regions that
2718
- /// appear in the closure's signature or on its field types. These
2719
- /// requirements are then verified and proved by the closure's
2720
- /// creating function. This struct encodes those requirements.
2721
- ///
2722
- /// The requirements are listed as being between various
2723
- /// `RegionVid`. The 0th region refers to `'static`; subsequent region
2724
- /// vids refer to the free regions that appear in the closure (or
2725
- /// generator's) type, in order of appearance. (This numbering is
2726
- /// actually defined by the `UniversalRegions` struct in the NLL
2727
- /// region checker. See for example
2728
- /// `UniversalRegions::closure_mapping`.) Note that we treat the free
2729
- /// regions in the closure's type "as if" they were erased, so their
2730
- /// precise identity is not important, only their position.
2731
- ///
2732
- /// Example: If type check produces a closure with the closure substs:
2733
- ///
2734
- /// ```text
2735
- /// ClosureSubsts = [
2736
- /// i8, // the "closure kind"
2737
- /// for<'x> fn(&'a &'x u32) -> &'x u32, // the "closure signature"
2738
- /// &'a String, // some upvar
2739
- /// ]
2740
- /// ```
2741
- ///
2742
- /// here, there is one unique free region (`'a`) but it appears
2743
- /// twice. We would "renumber" each occurrence to a unique vid, as follows:
2744
- ///
2745
- /// ```text
2746
- /// ClosureSubsts = [
2747
- /// i8, // the "closure kind"
2748
- /// for<'x> fn(&'1 &'x u32) -> &'x u32, // the "closure signature"
2749
- /// &'2 String, // some upvar
2750
- /// ]
2751
- /// ```
2752
- ///
2753
- /// Now the code might impose a requirement like `'1: '2`. When an
2754
- /// instance of the closure is created, the corresponding free regions
2755
- /// can be extracted from its type and constrained to have the given
2756
- /// outlives relationship.
2757
- ///
2758
- /// In some cases, we have to record outlives requirements between
2759
- /// types and regions as well. In that case, if those types include
2760
- /// any regions, those regions are recorded as `ReClosureBound`
2761
- /// instances assigned one of these same indices. Those regions will
2762
- /// be substituted away by the creator. We use `ReClosureBound` in
2763
- /// that case because the regions must be allocated in the global
2764
- /// `TyCtxt`, and hence we cannot use `ReVar` (which is what we use
2765
- /// internally within the rest of the NLL code).
2766
- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2767
- pub struct ClosureRegionRequirements < ' tcx > {
2768
- /// The number of external regions defined on the closure. In our
2769
- /// example above, it would be 3 -- one for `'static`, then `'1`
2770
- /// and `'2`. This is just used for a sanity check later on, to
2771
- /// make sure that the number of regions we see at the callsite
2772
- /// matches.
2773
- pub num_external_vids : usize ,
2774
-
2775
- /// Requirements between the various free regions defined in
2776
- /// indices.
2777
- pub outlives_requirements : Vec < ClosureOutlivesRequirement < ' tcx > > ,
2778
- }
2779
-
2780
- /// Indicates an outlives-constraint between a type or between two
2781
- /// free regions declared on the closure.
2782
- #[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2783
- pub struct ClosureOutlivesRequirement < ' tcx > {
2784
- // This region or type ...
2785
- pub subject : ClosureOutlivesSubject < ' tcx > ,
2786
-
2787
- // ... must outlive this one.
2788
- pub outlived_free_region : ty:: RegionVid ,
2789
-
2790
- // If not, report an error here ...
2791
- pub blame_span : Span ,
2792
-
2793
- // ... due to this reason.
2794
- pub category : ConstraintCategory ,
2795
- }
2796
-
2797
- /// Outlives-constraints can be categorized to determine whether and why they
2798
- /// are interesting (for error reporting). Order of variants indicates sort
2799
- /// order of the category, thereby influencing diagnostic output.
2800
- ///
2801
- /// See also [rustc_mir::borrow_check::nll::constraints].
2802
- #[ derive(
2803
- Copy ,
2804
- Clone ,
2805
- Debug ,
2806
- Eq ,
2807
- PartialEq ,
2808
- PartialOrd ,
2809
- Ord ,
2810
- Hash ,
2811
- RustcEncodable ,
2812
- RustcDecodable ,
2813
- HashStable
2814
- ) ]
2815
- pub enum ConstraintCategory {
2816
- Return ,
2817
- Yield ,
2818
- UseAsConst ,
2819
- UseAsStatic ,
2820
- TypeAnnotation ,
2821
- Cast ,
2822
-
2823
- /// A constraint that came from checking the body of a closure.
2824
- ///
2825
- /// We try to get the category that the closure used when reporting this.
2826
- ClosureBounds ,
2827
- CallArgument ,
2828
- CopyBound ,
2829
- SizedBound ,
2830
- Assignment ,
2831
- OpaqueType ,
2832
-
2833
- /// A "boring" constraint (caused by the given location) is one that
2834
- /// the user probably doesn't want to see described in diagnostics,
2835
- /// because it is kind of an artifact of the type system setup.
2836
- /// Example: `x = Foo { field: y }` technically creates
2837
- /// intermediate regions representing the "type of `Foo { field: y
2838
- /// }`", and data flows from `y` into those variables, but they
2839
- /// are not very interesting. The assignment into `x` on the other
2840
- /// hand might be.
2841
- Boring ,
2842
- // Boring and applicable everywhere.
2843
- BoringNoLocation ,
2844
-
2845
- /// A constraint that doesn't correspond to anything the user sees.
2846
- Internal ,
2847
- }
2848
-
2849
- /// The subject of a `ClosureOutlivesRequirement` -- that is, the thing
2850
- /// that must outlive some region.
2851
- #[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable , HashStable ) ]
2852
- pub enum ClosureOutlivesSubject < ' tcx > {
2853
- /// Subject is a type, typically a type parameter, but could also
2854
- /// be a projection. Indicates a requirement like `T: 'a` being
2855
- /// passed to the caller, where the type here is `T`.
2856
- ///
2857
- /// The type here is guaranteed not to contain any free regions at
2858
- /// present.
2859
- Ty ( Ty < ' tcx > ) ,
2860
-
2861
- /// Subject is a free region from the closure. Indicates a requirement
2862
- /// like `'a: 'b` being passed to the caller; the region here is `'a`.
2863
- Region ( ty:: RegionVid ) ,
2864
- }
2865
-
2866
2651
/*
2867
2652
* `TypeFoldable` implementations for MIR types
2868
2653
*/
0 commit comments