]> git.lizzy.rs Git - rust.git/commitdiff
Make is_freeze and is_copy_modulo_regions take TyCtxtAt
authorRalf Jung <post@ralfj.de>
Sun, 21 Jun 2020 09:20:48 +0000 (11:20 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 21 Jun 2020 09:47:19 +0000 (11:47 +0200)
23 files changed:
src/librustc_codegen_ssa/traits/type_.rs
src/librustc_lint/builtin.rs
src/librustc_middle/ty/layout.rs
src/librustc_middle/ty/util.rs
src/librustc_mir/dataflow/impls/borrowed_locals.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/intern.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/check_consts/qualifs.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/validate.rs
src/librustc_mir_build/build/expr/as_operand.rs
src/librustc_mir_build/hair/pattern/check_match.rs
src/librustc_passes/intrinsicck.rs
src/librustc_trait_selection/infer.rs
src/librustc_ty/needs_drop.rs
src/tools/clippy/clippy_lints/src/functions.rs
src/tools/clippy/clippy_lints/src/let_if_seq.rs
src/tools/clippy/clippy_lints/src/mut_key.rs
src/tools/clippy/clippy_lints/src/non_copy_const.rs
src/tools/clippy/clippy_lints/src/question_mark.rs
src/tools/clippy/clippy_lints/src/utils/mod.rs

index 703479b74bef8a9d9514a8e1c3fb4ddf24a46a6f..c55bf9858b972450c4cd607ee630221dacb23f38 100644 (file)
@@ -74,7 +74,7 @@ fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
     }
 
     fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
-        ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
+        ty.is_freeze(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
     }
 
     fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
index b7f728ec60cfdab9b0b8aa2641c3f24de4ae3d23..e746396e4c684d7e13afb04ef2ac0dd7e75169d1 100644 (file)
@@ -562,7 +562,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
             return;
         }
         let param_env = ty::ParamEnv::empty();
-        if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
+        if ty.is_copy_modulo_regions(cx.tcx.at(item.span), param_env) {
             return;
         }
         if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {
index 68af22569e35326256533736f0c09f1f08898c5e..e4cc96dd83bfbd751cd4b29b9e1b9bcd1e892b32 100644 (file)
@@ -2159,7 +2159,7 @@ fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<Poin
 
             ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
                 let tcx = cx.tcx();
-                let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
+                let is_freeze = ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env());
                 let kind = match mt {
                     hir::Mutability::Not => {
                         if is_freeze {
index 47110be53b2521ad09b296e7ecf5793122054996..67ad7ee708267968560c9b5b1b97106d5b041ff2 100644 (file)
@@ -681,11 +681,10 @@ pub fn numeric_min_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<
     /// winds up being reported as an error during NLL borrow check.
     pub fn is_copy_modulo_regions(
         &'tcx self,
-        tcx: TyCtxt<'tcx>,
+        tcx_at: TyCtxtAt<'tcx>,
         param_env: ty::ParamEnv<'tcx>,
-        span: Span,
     ) -> bool {
-        tcx.at(span).is_copy_raw(param_env.and(self))
+        tcx_at.is_copy_raw(param_env.and(self))
     }
 
     /// Checks whether values of this type `T` have a size known at
@@ -706,13 +705,8 @@ pub fn is_sized(&'tcx self, tcx_at: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx
     /// that the `Freeze` trait is not exposed to end users and is
     /// effectively an implementation detail.
     // FIXME: use `TyCtxtAt` instead of separate `Span`.
-    pub fn is_freeze(
-        &'tcx self,
-        tcx: TyCtxt<'tcx>,
-        param_env: ty::ParamEnv<'tcx>,
-        span: Span,
-    ) -> bool {
-        self.is_trivially_freeze() || tcx.at(span).is_freeze_raw(param_env.and(self))
+    pub fn is_freeze(&'tcx self, tcx_at: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
+        self.is_trivially_freeze() || tcx_at.is_freeze_raw(param_env.and(self))
     }
 
     /// Fast path helper for testing if a type is `Freeze`.
index 70c916a089270dd108cbddfb72dfad01e478a591..a3fc51cad656b0c9f2721f2d53b3b68d21dd527f 100644 (file)
@@ -233,7 +233,7 @@ impl MutBorrow<'mir, 'tcx> {
     ///
     /// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
     fn shared_borrow_allows_mutation(&self, place: Place<'tcx>) -> bool {
-        !place.ty(self.body, self.tcx).ty.is_freeze(self.tcx, self.param_env, DUMMY_SP)
+        !place.ty(self.body, self.tcx).ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env)
     }
 }
 
index 22f4691c22b3de81226fe406c8fafd6c427c04bd..91b1ec8b3a3ad2a645fd39ca1fbe69577b29e82d 100644 (file)
@@ -391,7 +391,7 @@ pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
 
     #[inline]
     pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
-        ty.is_freeze(*self.tcx, self.param_env, self.tcx.span)
+        ty.is_freeze(self.tcx, self.param_env)
     }
 
     pub fn load_mir(
index cab13d379a2ccead0845ab7735d5ae4aaedf30e9..dffbc969c21b8c645158e7ba7850e59d29df5bb6 100644 (file)
@@ -111,7 +111,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
     if let InternMode::Static(mutability) = mode {
         // For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
         // no interior mutability.
-        let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env, ecx.tcx.span));
+        let frozen = ty.map_or(true, |ty| ty.is_freeze(ecx.tcx, ecx.param_env));
         // For statics, allocation mutability is the combination of the place mutability and
         // the type mutability.
         // The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.
index 15a2e9130a37e91a240c2bbefa4657adac890288..8327affd982ed0f4578d41eded44cf05460e573b 100644 (file)
@@ -327,7 +327,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
     let param_env = tcx.param_env(def_id);
 
     let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
-    let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env, builder.span);
+    let is_copy = self_ty.is_copy_modulo_regions(tcx.at(builder.span), param_env);
 
     let dest = Place::return_place();
     let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
index 936c1a84e142eb9a595c042c016dfe695eac7303..e2893e81a2ce63dc8a0cebdce21ac276ce145957 100644 (file)
@@ -77,7 +77,7 @@ fn in_qualifs(qualifs: &ConstQualifs) -> bool {
     }
 
     fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
-        !ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP)
+        !ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)
     }
 
     fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
index 7dbb2ebad8b996b0c43b28978368fe60c1b93fa8..9898cde5207780ac582c5e7c899e402bd59968c9 100644 (file)
@@ -282,9 +282,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location:
                                 ),
                             };
                             if !elem_ty.is_copy_modulo_regions(
-                                self.tcx,
+                                self.tcx.at(self.source_info.span),
                                 self.param_env,
-                                self.source_info.span,
                             ) {
                                 self.require_unsafe(
                                     "assignment to non-`Copy` union field",
@@ -459,11 +458,11 @@ fn check_mut_borrowing_layout_constrained_field(
 
                             // Check `is_freeze` as late as possible to avoid cycle errors
                             // with opaque types.
-                            } else if !place.ty(self.body, self.tcx).ty.is_freeze(
-                                self.tcx,
-                                self.param_env,
-                                self.source_info.span,
-                            {
+                            } else if !place
+                                .ty(self.body, self.tcx)
+                                .ty
+                                .is_freeze(self.tcx.at(self.source_info.span), self.param_env)
+                            {
                                 (
                                     "borrow of layout constrained field with interior \
                                         mutability",
index 330f6c1640ff493ecd0b9ce443982a6ae22943f7..8bcbcd79ae60b798a49ed22bb6a2221b8599d08e 100644 (file)
@@ -341,7 +341,7 @@ fn validate_candidate(&self, candidate: Candidate) -> Result<(), Unpromotable> {
                                     Place::ty_from(place.local, proj_base, self.body, self.tcx)
                                         .projection_ty(self.tcx, elem)
                                         .ty;
-                                if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
+                                if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
                                     has_mut_interior = false;
                                     break;
                                 }
@@ -678,7 +678,7 @@ fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
                         let ty = Place::ty_from(place.local, proj_base, self.body, self.tcx)
                             .projection_ty(self.tcx, elem)
                             .ty;
-                        if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
+                        if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
                             has_mut_interior = false;
                             break;
                         }
index 625f40cd79206313d3f696abb9f494542abc5c79..953b335d9d798b5e4160689a180372b98c5a83d7 100644 (file)
@@ -90,7 +90,7 @@ fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
             let ty = place.ty(&self.body.local_decls, self.tcx).ty;
             let span = self.body.source_info(location).span;
 
-            if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
+            if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
                 self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
             }
         }
index 9a75f3afe8f082bccffe7e60cc0d895c4400f37d..5949fd1e22ce88dbc3effbb1487311d48e738e7f 100644 (file)
@@ -172,7 +172,7 @@ fn expr_as_call_operand(
 
             if !ty.is_sized(tcx.at(span), param_env) {
                 // !sized means !copy, so this is an unsized move
-                assert!(!ty.is_copy_modulo_regions(tcx, param_env, span));
+                assert!(!ty.is_copy_modulo_regions(tcx.at(span), param_env));
 
                 // As described above, detect the case where we are passing a value of unsized
                 // type, and that value is coming from the deref of a box.
index 4d97a19f4086bdff11222171efcc635fe3874f4d..6fc447a87f57a7892bfe694846bc568495941f89 100644 (file)
@@ -579,7 +579,7 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span>
 
 /// Check if a by-value binding is by-value. That is, check if the binding's type is not `Copy`.
 fn is_binding_by_move(cx: &MatchVisitor<'_, '_>, hir_id: HirId, span: Span) -> bool {
-    !cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx, cx.param_env, span)
+    !cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx.at(span), cx.param_env)
 }
 
 /// Check the legality of legality of by-move bindings.
index 88fb78f85e423add2e3303342314fcd09f6485f5..c8666ba1fd078d58676329565fc6a44f40c16a8f 100644 (file)
@@ -214,7 +214,7 @@ fn check_asm_operand_type(
 
         // Check that the type implements Copy. The only case where this can
         // possibly fail is for SIMD types which don't #[derive(Copy)].
-        if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
+        if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
             let msg = "arguments for inline assembly must be copyable";
             let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
             err.note(&format!("`{}` does not implement the Copy trait", ty));
index f244785b49d2fdf3dd5e4050543217b5549171e5..dc895ad34a93205017fdd623c22e083b606e9dfa 100644 (file)
@@ -44,7 +44,7 @@ fn type_is_copy_modulo_regions(
         let ty = self.resolve_vars_if_possible(&ty);
 
         if !(param_env, ty).needs_infer() {
-            return ty.is_copy_modulo_regions(self.tcx, param_env, span);
+            return ty.is_copy_modulo_regions(self.tcx.at(span), param_env);
         }
 
         let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);
index 439bec1702eaed10e2d4dc133a8d5f281246d7cf..7880c09c2ad81a04ad3284ab97fd1b2093a014c9 100644 (file)
@@ -91,7 +91,7 @@ fn next(&mut self) -> Option<NeedsDropResult<Ty<'tcx>>> {
 
             for component in components {
                 match component.kind {
-                    _ if component.is_copy_modulo_regions(tcx, self.param_env, DUMMY_SP) => (),
+                    _ if component.is_copy_modulo_regions(tcx.at(DUMMY_SP), self.param_env) => (),
 
                     ty::Closure(_, substs) => {
                         for upvar_ty in substs.as_closure().upvar_tys() {
index 991d129e8f0d612a7d7187abe0d007c5592502b3..1f9bd7a691b520bed9c788980974d3050d14e69d 100644 (file)
@@ -513,7 +513,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
         // primitive types are never mutable
         ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
         ty::Adt(ref adt, ref substs) => {
-            tys.insert(adt.did) && !ty.is_freeze(cx.tcx, cx.param_env, span)
+            tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
                 || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
                     && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
         },
index d7bf8a1476817c28892be2a3033f120fb2585301..e097f40f87e47c4b13084141de3e89b840b89232 100644 (file)
@@ -74,9 +74,8 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_
                     let span = stmt.span.to(if_.span);
 
                     let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze(
-                        cx.tcx,
+                        cx.tcx.at(span),
                         cx.param_env,
-                        span
                     );
                     if has_interior_mutability { return; }
 
index 0b9b7e1b8cc1b3e8e951d2f97dc43ff080390638..93569a04f7a3a23b151b70b28752f912d6cacf23 100644 (file)
@@ -118,7 +118,7 @@ fn is_mutable_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Spa
             size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_mutable_type(cx, inner_ty, span)
         },
         Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)),
-        Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx, cx.param_env, span),
+        Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(span), cx.param_env),
         _ => false,
     }
 }
index bb257e5a542d98632f9f25c31bac6342c72504b7..230dfd2ebf5661c3dd768225627bc5b4199fd93d 100644 (file)
@@ -110,7 +110,7 @@ fn lint(&self) -> (&'static Lint, &'static str, Span) {
 }
 
 fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: Source) {
-    if ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP) || is_copy(cx, ty) {
+    if ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env) || is_copy(cx, ty) {
         // An `UnsafeCell` is `!Copy`, and an `UnsafeCell` is also the only type which
         // is `!Freeze`, thus if our type is `Copy` we can be sure it must be `Freeze`
         // as well.
index 3591972fe082f7d0db4a12878a993059556509b8..d8a73f8054bcaa0dff4509fd060d686b24a89ee2 100644 (file)
@@ -137,7 +137,7 @@ fn check_if_let_some_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr
     fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
         let expr_ty = cx.tables.expr_ty(expression);
 
-        !expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span)
+        !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env)
     }
 
     fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
index 60ab19e71f5e4e15b8f9b45ae6cac3fc01f146a5..6d4c6c6ce1ceada7c78195219f454e35374ccc3f 100644 (file)
@@ -891,7 +891,7 @@ pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx
 }
 
 pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
-    ty.is_copy_modulo_regions(cx.tcx, cx.param_env, DUMMY_SP)
+    ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env)
 }
 
 /// Checks if an expression is constructing a tuple-like enum variant or struct