From 50840ee851c7059e6261b2d961d5386e6763e963 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 9 Jul 2019 13:49:20 +0200 Subject: [PATCH 01/26] Delay bug; this sidesteps ICE'ing when compiler is just doing error-recovery. --- .../infer/lexical_region_resolve/mod.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index d06c4434b3aaf..4bfe953e45c0b 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -764,16 +764,17 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } } - span_bug!( + // Errors in earlier passes can yield error variables without + // resolution errors here; delay ICE in favor of those errors. + self.tcx().sess.delay_span_bug( self.var_infos[node_idx].origin.span(), - "collect_error_for_expanding_node() could not find \ - error for var {:?} in universe {:?}, lower_bounds={:#?}, \ - upper_bounds={:#?}", - node_idx, - node_universe, - lower_bounds, - upper_bounds - ); + &format!("collect_error_for_expanding_node() could not find \ + error for var {:?} in universe {:?}, lower_bounds={:#?}, \ + upper_bounds={:#?}", + node_idx, + node_universe, + lower_bounds, + upper_bounds)); } fn collect_concrete_regions( From 837fe7bbe354557c9323b1b9d288584fa077f950 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 9 Jul 2019 13:57:22 +0200 Subject: [PATCH 02/26] Regression test. --- src/test/ui/hrtb/issue-62203-hrtb-ice.rs | 50 ++++++++++++++++++++ src/test/ui/hrtb/issue-62203-hrtb-ice.stderr | 22 +++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/test/ui/hrtb/issue-62203-hrtb-ice.rs create mode 100644 src/test/ui/hrtb/issue-62203-hrtb-ice.stderr diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.rs b/src/test/ui/hrtb/issue-62203-hrtb-ice.rs new file mode 100644 index 0000000000000..454d7e5e9cdea --- /dev/null +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.rs @@ -0,0 +1,50 @@ +trait T0<'a, A> { + type O; +} + +struct L { + f: T, +} + +// explicitly named variants of what one would normally denote by the +// unit type `()`. Why do this? So that we can differentiate them in +// the diagnostic output. +struct Unit1; +struct Unit2; +struct Unit3; +struct Unit4; + +impl<'a, A, T> T0<'a, A> for L +where + T: FnMut(A) -> Unit3, +{ + type O = T::Output; +} + +trait T1: for<'r> Ty<'r> { + fn m<'a, B: Ty<'a>, F>(&self, f: F) -> Unit1 + where + F: for<'r> T0<'r, (>::V,), O = >::V>, + { + unimplemented!(); + } +} + +trait Ty<'a> { + type V; +} + +fn main() { + let v = Unit2.m( + //~^ ERROR type mismatch + //~| ERROR type mismatch + L { + f : |x| { drop(x); Unit4 } + }); +} + +impl<'a> Ty<'a> for Unit2 { + type V = &'a u8; +} + +impl T1 for Unit2 {} diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr new file mode 100644 index 0000000000000..c2d0e0c2a26bc --- /dev/null +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -0,0 +1,22 @@ +error[E0271]: type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` + --> $DIR/issue-62203-hrtb-ice.rs:38:19 + | +LL | let v = Unit2.m( + | ^ expected struct `Unit4`, found associated type + | + = note: expected type `Unit4` + found type `<_ as Ty<'_>>::V` + +error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as std::ops::FnOnce<((&u8,),)>>::Output == Unit3` + --> $DIR/issue-62203-hrtb-ice.rs:38:19 + | +LL | let v = Unit2.m( + | ^ expected struct `Unit4`, found struct `Unit3` + | + = note: expected type `Unit4` + found type `Unit3` + = note: required because of the requirements on the impl of `for<'r> T0<'r, (>::V,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0271`. From d73c23d114d109d7c48c9447f53bcba533effa16 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 13 Jul 2019 15:16:05 +0200 Subject: [PATCH 03/26] explain how to search without owned data --- src/libcore/slice/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 363ae08827558..c3eb2ec9dc251 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1263,6 +1263,14 @@ impl [T] { /// assert!(v.contains(&30)); /// assert!(!v.contains(&50)); /// ``` + /// + /// If you only have a borrowed `T`, use `any`: + /// + /// ``` + /// let v = [String::from("hello"), String::from("world")]; + /// assert!(v.iter().any(|e| e == "hello")); + /// assert!(!v.iter().any(|e| e == "hi")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains(&self, x: &T) -> bool where T: PartialEq From 3f77f2cd5bedf364d4226df139e7369761bd41a2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 14 Jul 2019 10:03:04 +0200 Subject: [PATCH 04/26] better comments --- src/libcore/slice/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c3eb2ec9dc251..edd00a9fa8561 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1264,11 +1264,12 @@ impl [T] { /// assert!(!v.contains(&50)); /// ``` /// - /// If you only have a borrowed `T`, use `any`: + /// If you do not have an `&T`, but just an `&U` such that `T: Borrow` + /// (e.g. `String: Borrow`), you can use `iter().any`: /// /// ``` - /// let v = [String::from("hello"), String::from("world")]; - /// assert!(v.iter().any(|e| e == "hello")); + /// let v = [String::from("hello"), String::from("world")]; // slice of `String` + /// assert!(v.iter().any(|e| e == "hello")); // search with `&str` /// assert!(!v.iter().any(|e| e == "hi")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] From 589f6a7dc66d88739485a1f9044ab29c166420a0 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Thu, 18 Jul 2019 14:52:30 +0530 Subject: [PATCH 05/26] tries to refactor InterpError in mir --- src/librustc/mir/interpret/error.rs | 43 +++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index c8f42b1c604a5..d5caa3c8ce442 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -247,6 +247,7 @@ pub enum InterpError<'tcx, O> { DanglingPointerDeref, DoubleFree, InvalidMemoryAccess, + FunctionPointerTyMismatch(FnSig<'tcx>, FnSig<'tcx>), InvalidFunctionPointer, InvalidBool, InvalidDiscriminant(ScalarMaybeUndef), @@ -266,11 +267,13 @@ pub enum InterpError<'tcx, O> { Unimplemented(String), DerefFunctionPointer, ExecuteMemory, + // asd BoundsCheck { len: O, index: O }, Overflow(mir::BinOp), OverflowNeg, DivisionByZero, RemainderByZero, + // asd Intrinsic(String), InvalidChar(u128), StackFrameLimitReached, @@ -281,6 +284,29 @@ pub enum InterpError<'tcx, O> { required: Align, has: Align, }, + MemoryLockViolation { + ptr: Pointer, + len: u64, + frame: usize, + access: AccessKind, + lock: Lock, + }, + MemoryAcquireConflict { + ptr: Pointer, + len: u64, + kind: AccessKind, + lock: Lock, + }, + InvalidMemoryLockRelease { + ptr: Pointer, + len: u64, + frame: usize, + lock: Lock, + }, + DeallocatedLockedMemory { + ptr: Pointer, + lock: Lock, + }, ValidationFailure(String), CalledClosureAsFunction, VtableForArgumentlessMethod, @@ -298,12 +324,7 @@ pub enum InterpError<'tcx, O> { HeapAllocZeroBytes, HeapAllocNonPowerOfTwoAlignment(u64), Unreachable, - Panic { - msg: Symbol, - line: u32, - col: u32, - file: Symbol, - }, + Panic(EvalErrorPanic<'tcx, O>), ReadFromReturnPointer, PathNotFound(Vec), UnimplementedTraitSelection, @@ -319,6 +340,16 @@ pub enum InterpError<'tcx, O> { InfiniteLoop, } +#[derive(Clone, RustcEncodable, RustcDecodable)] +pub enum EvalErrorPanic<'tcx, O> { + Panic, + BoundsCheck { len: O, index: O }, + Overflow(mir::BinOp), + OverflowNeg, + DivisionByZero, + RemainderByZero, +} + pub type InterpResult<'tcx, T = ()> = Result>; impl<'tcx, O> InterpError<'tcx, O> { From 469b7a916164d48a78d4bd8a10257bfe3b4a1dbe Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Thu, 18 Jul 2019 18:41:59 +0300 Subject: [PATCH 06/26] rustc_typeck: improve diagnostics for _ const/static declarations --- src/librustc_typeck/check/mod.rs | 31 ++++++----- src/librustc_typeck/collect.rs | 53 ++++++++++++++++--- .../typeck_type_placeholder_item.stderr | 20 +++++-- 3 files changed, 80 insertions(+), 24 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index bde6db78aef32..21cd4b694ae4c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -759,40 +759,40 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option { fn primary_body_of( tcx: TyCtxt<'_>, id: hir::HirId, -) -> Option<(hir::BodyId, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> { +) -> Option<(hir::BodyId, Option<&hir::Ty>, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> { match tcx.hir().get(id) { Node::Item(item) => { match item.node { - hir::ItemKind::Const(_, body) | - hir::ItemKind::Static(_, _, body) => - Some((body, None, None)), + hir::ItemKind::Const(ref ty, body) | + hir::ItemKind::Static(ref ty, _, body) => + Some((body, Some(ty), None, None)), hir::ItemKind::Fn(ref decl, ref header, .., body) => - Some((body, Some(header), Some(decl))), + Some((body, None, Some(header), Some(decl))), _ => None, } } Node::TraitItem(item) => { match item.node { - hir::TraitItemKind::Const(_, Some(body)) => - Some((body, None, None)), + hir::TraitItemKind::Const(ref ty, Some(body)) => + Some((body, Some(ty), None, None)), hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => - Some((body, Some(&sig.header), Some(&sig.decl))), + Some((body, None, Some(&sig.header), Some(&sig.decl))), _ => None, } } Node::ImplItem(item) => { match item.node { - hir::ImplItemKind::Const(_, body) => - Some((body, None, None)), + hir::ImplItemKind::Const(ref ty, body) => + Some((body, Some(ty), None, None)), hir::ImplItemKind::Method(ref sig, body) => - Some((body, Some(&sig.header), Some(&sig.decl))), + Some((body, None, Some(&sig.header), Some(&sig.decl))), _ => None, } } - Node::AnonConst(constant) => Some((constant.body, None, None)), + Node::AnonConst(constant) => Some((constant.body, None, None, None)), _ => None, } } @@ -825,7 +825,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> { let span = tcx.hir().span(id); // Figure out what primary body this item has. - let (body_id, fn_header, fn_decl) = primary_body_of(tcx, id) + let (body_id, body_ty, fn_header, fn_decl) = primary_body_of(tcx, id) .unwrap_or_else(|| { span_bug!(span, "can't type-check body of {:?}", def_id); }); @@ -856,7 +856,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> { fcx } else { let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); - let expected_type = tcx.type_of(def_id); + let expected_type = body_ty.and_then(|ty| match ty.node { + hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)), + _ => None + }).unwrap_or_else(|| tcx.type_of(def_id)); let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type); fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a5457c45d378c..053ef1f8f8297 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1135,6 +1135,26 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { checked_type_of(tcx, def_id, true).unwrap() } +fn infer_placeholder_type( + tcx: TyCtxt<'_>, + def_id: DefId, + body_id: hir::BodyId, + span: Span, +) -> Ty<'_> { + let ty = tcx.typeck_tables_of(def_id).node_type(body_id.hir_id); + let mut diag = bad_placeholder_type(tcx, span); + if ty != tcx.types.err { + diag.span_suggestion( + span, + "replace `_` with the correct type", + ty.to_string(), + Applicability::MaybeIncorrect, + ); + } + diag.emit(); + ty +} + /// Same as [`type_of`] but returns [`Option`] instead of failing. /// /// If you want to fail anyway, you can set the `fail` parameter to true, but in this case, @@ -1160,7 +1180,16 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option icx.to_ty(ty), + TraitItemKind::Const(ref ty, body_id) => { + body_id.and_then(|body_id| { + if let hir::TyKind::Infer = ty.node { + Some(infer_placeholder_type(tcx, def_id, body_id, ty.span)) + } else { + None + } + }).unwrap_or_else(|| icx.to_ty(ty)) + }, + TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty), TraitItemKind::Type(_, None) => { if !fail { return None; @@ -1174,7 +1203,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option icx.to_ty(ty), + ImplItemKind::Const(ref ty, body_id) => { + if let hir::TyKind::Infer = ty.node { + infer_placeholder_type(tcx, def_id, body_id, ty.span) + } else { + icx.to_ty(ty) + } + }, ImplItemKind::Existential(_) => { if tcx .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) @@ -1199,10 +1234,16 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option { match item.node { - ItemKind::Static(ref t, ..) - | ItemKind::Const(ref t, _) - | ItemKind::Ty(ref t, _) - | ItemKind::Impl(.., ref t, _) => icx.to_ty(t), + ItemKind::Static(ref ty, .., body_id) + | ItemKind::Const(ref ty, body_id) => { + if let hir::TyKind::Infer = ty.node { + infer_placeholder_type(tcx, def_id, body_id, ty.span) + } else { + icx.to_ty(ty) + } + }, + ItemKind::Ty(ref ty, _) + | ItemKind::Impl(.., ref ty, _) => icx.to_ty(ty), ItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.stderr b/src/test/ui/typeck/typeck_type_placeholder_item.stderr index ddaa5de4d3e27..2b4d9966c3d0b 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item.stderr +++ b/src/test/ui/typeck/typeck_type_placeholder_item.stderr @@ -23,13 +23,19 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa --> $DIR/typeck_type_placeholder_item.rs:11:15 | LL | static TEST3: _ = "test"; - | ^ not allowed in type signatures + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `&'static str` error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:14:15 | LL | static TEST4: _ = 145; - | ^ not allowed in type signatures + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `i32` error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:17:16 @@ -122,13 +128,19 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa --> $DIR/typeck_type_placeholder_item.rs:64:22 | LL | static FN_TEST3: _ = "test"; - | ^ not allowed in type signatures + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `&'static str` error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:67:22 | LL | static FN_TEST4: _ = 145; - | ^ not allowed in type signatures + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `i32` error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:70:23 From c6735a624b45f8170299c0539856c7d3b5f29422 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Fri, 19 Jul 2019 19:09:59 +0300 Subject: [PATCH 07/26] fixup! rustc_typeck: improve diagnostics for _ const/static declarations --- .../typeck_type_placeholder_item_help.rs | 18 +++++++++ .../typeck_type_placeholder_item_help.stderr | 38 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/test/ui/typeck/typeck_type_placeholder_item_help.rs b/src/test/ui/typeck/typeck_type_placeholder_item_help.rs index 5f4cb4c1316d5..905fc35350ed0 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item_help.rs +++ b/src/test/ui/typeck/typeck_type_placeholder_item_help.rs @@ -4,6 +4,24 @@ fn test1() -> _ { Some(42) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +const TEST2: _ = 42u32; +//~^ ERROR the type placeholder `_` is not allowed within types on item signatures + +const TEST3: _ = Some(42); +//~^ ERROR the type placeholder `_` is not allowed within types on item signatures + +trait Test4 { + const TEST4: _ = 42; + //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +} + +struct Test5; + +impl Test5 { + const TEST5: _ = 13; + //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +} + pub fn main() { let _: Option = test1(); let _: f64 = test1(); diff --git a/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr b/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr index 7fb5549825cc5..c5b9566290c11 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr +++ b/src/test/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -7,6 +7,42 @@ LL | fn test1() -> _ { Some(42) } | not allowed in type signatures | help: replace `_` with the correct return type: `std::option::Option` -error: aborting due to previous error +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item_help.rs:7:14 + | +LL | const TEST2: _ = 42u32; + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `u32` + +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item_help.rs:10:14 + | +LL | const TEST3: _ = Some(42); + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `std::option::Option` + +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item_help.rs:14:18 + | +LL | const TEST4: _ = 42; + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `i32` + +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item_help.rs:21:18 + | +LL | const TEST5: _ = 13; + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `i32` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0121`. From 10d415938ed8d87aa5cda7ef23680a16bcad288b Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 20 Jul 2019 01:29:47 +0800 Subject: [PATCH 08/26] Revert "Disable stack probing for gnux32." This reverts commit 42d652ecd6709b756d95fc42615b166aacd2ea07. --- src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs b/src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs index 73151b194de42..0b2d7aacc4ddf 100644 --- a/src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs +++ b/src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs @@ -5,8 +5,7 @@ pub fn target() -> TargetResult { base.cpu = "x86-64".to_string(); base.max_atomic_width = Some(64); base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-mx32".to_string()); - // BUG: temporarily workaround #59674 - base.stack_probes = false; + base.stack_probes = true; base.has_elf_tls = false; // BUG(GabrielMajeri): disabling the PLT on x86_64 Linux with x32 ABI // breaks code gen. See LLVM bug 36743 From f5b285906e45d0fd031a1433cdb7ab3c7be92650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 17 Jul 2019 11:40:36 -0700 Subject: [PATCH 09/26] Handle more cases of typos misinterpreted as type ascription --- src/libsyntax/parse/diagnostics.rs | 91 ++++++++++--------- src/libsyntax/parse/parser.rs | 45 +++++---- src/libsyntax_ext/format.rs | 5 +- .../ui/codemap_tests/bad-format-args.stderr | 4 +- src/test/ui/issues/issue-22644.stderr | 11 +-- src/test/ui/issues/issue-34255-1.stderr | 11 +-- src/test/ui/issues/issue-39616.stderr | 2 +- src/test/ui/issues/issue-44406.stderr | 5 +- .../ui/lifetime_starts_expressions.stderr | 11 +-- src/test/ui/macros/missing-comma.stderr | 2 +- src/test/ui/parser/issue-33262.stderr | 2 +- .../macro/trait-object-macro-matcher.stderr | 2 +- src/test/ui/parser/recover-enum2.stderr | 2 +- .../ui/parser/recover-from-bad-variant.stderr | 11 +-- .../parser/removed-syntax-mut-vec-ty.stderr | 2 +- .../ui/parser/removed-syntax-record.stderr | 2 +- .../trait-object-lifetime-parens.stderr | 2 +- .../type-ascription-instead-of-method.stderr | 7 +- .../type-ascription-instead-of-variant.stderr | 7 +- src/test/ui/type/ascription/issue-34255-1.rs | 15 +++ .../ui/type/ascription/issue-34255-1.stderr | 30 ++++++ src/test/ui/type/ascription/issue-47666.rs | 5 + .../ui/type/ascription/issue-47666.stderr | 13 +++ src/test/ui/type/ascription/issue-54516.rs | 6 ++ .../ui/type/ascription/issue-54516.stderr | 13 +++ src/test/ui/type/ascription/issue-60933.rs | 4 + .../ui/type/ascription/issue-60933.stderr | 13 +++ ...e-ascription-instead-of-initializer.stderr | 2 +- ...ascription-instead-of-statement-end.stderr | 16 ++-- 29 files changed, 227 insertions(+), 114 deletions(-) create mode 100644 src/test/ui/type/ascription/issue-34255-1.rs create mode 100644 src/test/ui/type/ascription/issue-34255-1.stderr create mode 100644 src/test/ui/type/ascription/issue-47666.rs create mode 100644 src/test/ui/type/ascription/issue-47666.stderr create mode 100644 src/test/ui/type/ascription/issue-54516.rs create mode 100644 src/test/ui/type/ascription/issue-54516.stderr create mode 100644 src/test/ui/type/ascription/issue-60933.rs create mode 100644 src/test/ui/type/ascription/issue-60933.stderr diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index 0e88a0ee28937..190672acfcf77 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -2,6 +2,7 @@ use crate::ast::{ self, Arg, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, VariantData, }; +use crate::feature_gate::{feature_err, UnstableFeatures}; use crate::parse::{SeqSep, PResult, Parser, ParseSess}; use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, TokenExpectType}; use crate::parse::token::{self, TokenKind}; @@ -365,9 +366,53 @@ impl<'a> Parser<'a> { err.span_label(self.token.span, "unexpected token"); } } + self.maybe_annotate_with_ascription(&mut err, false); Err(err) } + pub fn maybe_annotate_with_ascription( + &self, + err: &mut DiagnosticBuilder<'_>, + maybe_expected_semicolon: bool, + ) { + if let Some((sp, likely_path)) = self.last_type_ascription { + let cm = self.sess.source_map(); + let next_pos = cm.lookup_char_pos(self.token.span.lo()); + let op_pos = cm.lookup_char_pos(sp.hi()); + + if likely_path { + err.span_suggestion( + sp, + "maybe write a path separator here", + "::".to_string(), + match self.sess.unstable_features { + UnstableFeatures::Disallow => Applicability::MachineApplicable, + _ => Applicability::MaybeIncorrect, + }, + ); + } else if op_pos.line != next_pos.line && maybe_expected_semicolon { + err.span_suggestion( + sp, + "try using a semicolon", + ";".to_string(), + Applicability::MaybeIncorrect, + ); + } else if let UnstableFeatures::Disallow = self.sess.unstable_features { + err.span_label(sp, "tried to parse a type due to this"); + } else { + err.span_label(sp, "tried to parse a type due to this type ascription"); + } + if let UnstableFeatures::Disallow = self.sess.unstable_features { + // Give extra information about type ascription only if it's a nightly compiler. + } else { + err.note("`#![feature(type_ascription)]` lets you annotate an expression with a \ + type: `: `"); + err.note("for more information, see \ + https://github.com/rust-lang/rust/issues/23416"); + } + } + } + /// Eats and discards tokens until one of `kets` is encountered. Respects token trees, /// passes through any errors encountered. Used for error recovery. crate fn eat_to_tokens(&mut self, kets: &[&TokenKind]) { @@ -556,7 +601,7 @@ impl<'a> Parser<'a> { .collect::>(); if !discriminant_spans.is_empty() && has_fields { - let mut err = crate::feature_gate::feature_err( + let mut err = feature_err( sess, sym::arbitrary_enum_discriminant, discriminant_spans.clone(), @@ -887,47 +932,9 @@ impl<'a> Parser<'a> { self.look_ahead(2, |t| t.is_ident()) || self.look_ahead(1, |t| t == &token::Colon) && // `foo:bar:baz` self.look_ahead(2, |t| t.is_ident()) || - self.look_ahead(1, |t| t == &token::ModSep) && // `foo:bar::baz` - self.look_ahead(2, |t| t.is_ident()) - } - - crate fn bad_type_ascription( - &self, - err: &mut DiagnosticBuilder<'a>, - lhs_span: Span, - cur_op_span: Span, - next_sp: Span, - maybe_path: bool, - ) { - err.span_label(self.token.span, "expecting a type here because of type ascription"); - let cm = self.sess.source_map(); - let next_pos = cm.lookup_char_pos(next_sp.lo()); - let op_pos = cm.lookup_char_pos(cur_op_span.hi()); - if op_pos.line != next_pos.line { - err.span_suggestion( - cur_op_span, - "try using a semicolon", - ";".to_string(), - Applicability::MaybeIncorrect, - ); - } else { - if maybe_path { - err.span_suggestion( - cur_op_span, - "maybe you meant to write a path separator here", - "::".to_string(), - Applicability::MaybeIncorrect, - ); - } else { - err.note("`#![feature(type_ascription)]` lets you annotate an \ - expression with a type: `: `") - .span_note( - lhs_span, - "this expression expects an ascribed type after the colon", - ) - .help("this might be indicative of a syntax error elsewhere"); - } - } + self.look_ahead(1, |t| t == &token::ModSep) && + (self.look_ahead(2, |t| t.is_ident()) || // `foo:bar::baz` + self.look_ahead(2, |t| t == &token::Lt)) // `foo:bar::` } crate fn recover_seq_parse_error( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1d4d02c732582..41cfb5bece3b8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -239,6 +239,7 @@ pub struct Parser<'a> { /// error. crate unclosed_delims: Vec, crate last_unexpected_token_span: Option, + crate last_type_ascription: Option<(Span, bool /* likely path typo */)>, /// If present, this `Parser` is not parsing Rust code but rather a macro call. crate subparser_name: Option<&'static str>, } @@ -502,6 +503,7 @@ impl<'a> Parser<'a> { max_angle_bracket_count: 0, unclosed_delims: Vec::new(), last_unexpected_token_span: None, + last_type_ascription: None, subparser_name, }; @@ -1422,7 +1424,10 @@ impl<'a> Parser<'a> { } } else { let msg = format!("expected type, found {}", self.this_token_descr()); - return Err(self.fatal(&msg)); + let mut err = self.fatal(&msg); + err.span_label(self.token.span, "expected type"); + self.maybe_annotate_with_ascription(&mut err, true); + return Err(err); }; let span = lo.to(self.prev_span); @@ -2823,10 +2828,11 @@ impl<'a> Parser<'a> { } /// Parses an associative expression with operators of at least `min_prec` precedence. - fn parse_assoc_expr_with(&mut self, - min_prec: usize, - lhs: LhsExpr) - -> PResult<'a, P> { + fn parse_assoc_expr_with( + &mut self, + min_prec: usize, + lhs: LhsExpr, + ) -> PResult<'a, P> { let mut lhs = if let LhsExpr::AlreadyParsed(expr) = lhs { expr } else { @@ -2840,9 +2846,13 @@ impl<'a> Parser<'a> { self.parse_prefix_expr(attrs)? } }; + let last_type_ascription_set = self.last_type_ascription.is_some(); match (self.expr_is_complete(&lhs), AssocOp::from_token(&self.token)) { (true, None) => { + if last_type_ascription_set { + self.last_type_ascription = None; + } // Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071 return Ok(lhs); } @@ -2857,12 +2867,18 @@ impl<'a> Parser<'a> { // If the next token is a keyword, then the tokens above *are* unambiguously incorrect: // `if x { a } else { b } && if y { c } else { d }` if !self.look_ahead(1, |t| t.is_reserved_ident()) => { + if last_type_ascription_set { + self.last_type_ascription = None; + } // These cases are ambiguous and can't be identified in the parser alone let sp = self.sess.source_map().start_point(self.token.span); self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span); return Ok(lhs); } (true, Some(ref op)) if !op.can_continue_expr_unambiguously() => { + if last_type_ascription_set { + self.last_type_ascription = None; + } return Ok(lhs); } (true, Some(_)) => { @@ -2921,21 +2937,9 @@ impl<'a> Parser<'a> { continue } else if op == AssocOp::Colon { let maybe_path = self.could_ascription_be_path(&lhs.node); - let next_sp = self.token.span; + self.last_type_ascription = Some((self.prev_span, maybe_path)); - lhs = match self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type) { - Ok(lhs) => lhs, - Err(mut err) => { - self.bad_type_ascription( - &mut err, - lhs_span, - cur_op_span, - next_sp, - maybe_path, - ); - return Err(err); - } - }; + lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?; continue } else if op == AssocOp::DotDot || op == AssocOp::DotDotEq { // If we didn’t have to handle `x..`/`x..=`, it would be pretty easy to @@ -3020,6 +3024,9 @@ impl<'a> Parser<'a> { if let Fixity::None = fixity { break } } + if last_type_ascription_set { + self.last_type_ascription = None; + } Ok(lhs) } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index c3dbd48cc6e4e..b9e83de43bb0c 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -141,7 +141,10 @@ fn parse_args<'a>( while p.token != token::Eof { if !p.eat(&token::Comma) { - return Err(ecx.struct_span_err(p.token.span, "expected token: `,`")); + let mut err = ecx.struct_span_err(p.token.span, "expected token: `,`"); + err.span_label(p.token.span, "expected `,`"); + p.maybe_annotate_with_ascription(&mut err, false); + return Err(err); } if p.token == token::Eof { break; diff --git a/src/test/ui/codemap_tests/bad-format-args.stderr b/src/test/ui/codemap_tests/bad-format-args.stderr index c424eb08a7a98..5b01314d8ad4f 100644 --- a/src/test/ui/codemap_tests/bad-format-args.stderr +++ b/src/test/ui/codemap_tests/bad-format-args.stderr @@ -10,13 +10,13 @@ error: expected token: `,` --> $DIR/bad-format-args.rs:3:16 | LL | format!("" 1); - | ^ + | ^ expected `,` error: expected token: `,` --> $DIR/bad-format-args.rs:4:19 | LL | format!("", 1 1); - | ^ + | ^ expected `,` error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-22644.stderr b/src/test/ui/issues/issue-22644.stderr index 4f0dc0a488765..0fe167963c3f4 100644 --- a/src/test/ui/issues/issue-22644.stderr +++ b/src/test/ui/issues/issue-22644.stderr @@ -87,15 +87,12 @@ error: expected type, found `4` --> $DIR/issue-22644.rs:34:28 | LL | println!("{}", a: &mut 4); - | ^ expecting a type here because of type ascription + | - ^ expected type + | | + | tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` -note: this expression expects an ascribed type after the colon - --> $DIR/issue-22644.rs:34:20 - | -LL | println!("{}", a: &mut 4); - | ^ - = help: this might be indicative of a syntax error elsewhere + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to 9 previous errors diff --git a/src/test/ui/issues/issue-34255-1.stderr b/src/test/ui/issues/issue-34255-1.stderr index 0218a7abeaa4c..acb093b51428b 100644 --- a/src/test/ui/issues/issue-34255-1.stderr +++ b/src/test/ui/issues/issue-34255-1.stderr @@ -2,15 +2,12 @@ error: expected type, found `42` --> $DIR/issue-34255-1.rs:8:24 | LL | Test::Drill(field: 42); - | ^^ expecting a type here because of type ascription + | - ^^ expected type + | | + | tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` -note: this expression expects an ascribed type after the colon - --> $DIR/issue-34255-1.rs:8:17 - | -LL | Test::Drill(field: 42); - | ^^^^^ - = help: this might be indicative of a syntax error elsewhere + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to previous error diff --git a/src/test/ui/issues/issue-39616.stderr b/src/test/ui/issues/issue-39616.stderr index e24ffcdb0d990..75eb55fa50bb3 100644 --- a/src/test/ui/issues/issue-39616.stderr +++ b/src/test/ui/issues/issue-39616.stderr @@ -2,7 +2,7 @@ error: expected type, found `0` --> $DIR/issue-39616.rs:1:12 | LL | fn foo(a: [0; 1]) {} - | ^ + | ^ expected type error: expected one of `)`, `,`, `->`, `where`, or `{`, found `]` --> $DIR/issue-39616.rs:1:16 diff --git a/src/test/ui/issues/issue-44406.stderr b/src/test/ui/issues/issue-44406.stderr index 14b3b8cc5c85d..108542c9b6f13 100644 --- a/src/test/ui/issues/issue-44406.stderr +++ b/src/test/ui/issues/issue-44406.stderr @@ -15,7 +15,10 @@ LL | bar(baz: $rest) | - help: try using a semicolon: `;` ... LL | foo!(true); - | ^^^^ expecting a type here because of type ascription + | ^^^^ expected type + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to 2 previous errors diff --git a/src/test/ui/lifetime_starts_expressions.stderr b/src/test/ui/lifetime_starts_expressions.stderr index 84e4c87ebc4da..bacba10b55fba 100644 --- a/src/test/ui/lifetime_starts_expressions.stderr +++ b/src/test/ui/lifetime_starts_expressions.stderr @@ -12,15 +12,12 @@ error: expected type, found keyword `loop` --> $DIR/lifetime_starts_expressions.rs:6:26 | LL | loop { break 'label: loop { break 'label 42; }; } - | ^^^^ expecting a type here because of type ascription + | - ^^^^ expected type + | | + | tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` -note: this expression expects an ascribed type after the colon - --> $DIR/lifetime_starts_expressions.rs:6:12 - | -LL | loop { break 'label: loop { break 'label 42; }; } - | ^^^^^^^^^^^^ - = help: this might be indicative of a syntax error elsewhere + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to 2 previous errors diff --git a/src/test/ui/macros/missing-comma.stderr b/src/test/ui/macros/missing-comma.stderr index d5b6d86b20ff1..f96848f8239f7 100644 --- a/src/test/ui/macros/missing-comma.stderr +++ b/src/test/ui/macros/missing-comma.stderr @@ -2,7 +2,7 @@ error: expected token: `,` --> $DIR/missing-comma.rs:19:19 | LL | println!("{}" a); - | ^ + | ^ expected `,` error: no rules expected the token `b` --> $DIR/missing-comma.rs:21:12 diff --git a/src/test/ui/parser/issue-33262.stderr b/src/test/ui/parser/issue-33262.stderr index c2491df903b76..2aff328393538 100644 --- a/src/test/ui/parser/issue-33262.stderr +++ b/src/test/ui/parser/issue-33262.stderr @@ -2,7 +2,7 @@ error: expected type, found `{` --> $DIR/issue-33262.rs:4:22 | LL | for i in 0..a as { } - | ^ + | ^ expected type error: aborting due to previous error diff --git a/src/test/ui/parser/macro/trait-object-macro-matcher.stderr b/src/test/ui/parser/macro/trait-object-macro-matcher.stderr index 19c5c82f82cd2..f02f60e4bfb1d 100644 --- a/src/test/ui/parser/macro/trait-object-macro-matcher.stderr +++ b/src/test/ui/parser/macro/trait-object-macro-matcher.stderr @@ -2,7 +2,7 @@ error: expected type, found `'static` --> $DIR/trait-object-macro-matcher.rs:9:8 | LL | m!('static); - | ^^^^^^^ + | ^^^^^^^ expected type error: aborting due to previous error diff --git a/src/test/ui/parser/recover-enum2.stderr b/src/test/ui/parser/recover-enum2.stderr index 9ed2e6f5eb6c4..2311887a6fb36 100644 --- a/src/test/ui/parser/recover-enum2.stderr +++ b/src/test/ui/parser/recover-enum2.stderr @@ -2,7 +2,7 @@ error: expected type, found `{` --> $DIR/recover-enum2.rs:6:18 | LL | abc: {}, - | ^ + | ^ expected type error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `{` --> $DIR/recover-enum2.rs:25:22 diff --git a/src/test/ui/parser/recover-from-bad-variant.stderr b/src/test/ui/parser/recover-from-bad-variant.stderr index d525bd3f4c6e5..b46d3ca9c233c 100644 --- a/src/test/ui/parser/recover-from-bad-variant.stderr +++ b/src/test/ui/parser/recover-from-bad-variant.stderr @@ -2,15 +2,12 @@ error: expected type, found `3` --> $DIR/recover-from-bad-variant.rs:7:26 | LL | let x = Enum::Foo(a: 3, b: 4); - | ^ expecting a type here because of type ascription + | - ^ expected type + | | + | tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` -note: this expression expects an ascribed type after the colon - --> $DIR/recover-from-bad-variant.rs:7:23 - | -LL | let x = Enum::Foo(a: 3, b: 4); - | ^ - = help: this might be indicative of a syntax error elsewhere + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error[E0532]: expected tuple struct/variant, found struct variant `Enum::Foo` --> $DIR/recover-from-bad-variant.rs:10:9 diff --git a/src/test/ui/parser/removed-syntax-mut-vec-ty.stderr b/src/test/ui/parser/removed-syntax-mut-vec-ty.stderr index a759716b5a963..02b518e251678 100644 --- a/src/test/ui/parser/removed-syntax-mut-vec-ty.stderr +++ b/src/test/ui/parser/removed-syntax-mut-vec-ty.stderr @@ -2,7 +2,7 @@ error: expected type, found keyword `mut` --> $DIR/removed-syntax-mut-vec-ty.rs:1:11 | LL | type v = [mut isize]; - | ^^^ + | ^^^ expected type error: aborting due to previous error diff --git a/src/test/ui/parser/removed-syntax-record.stderr b/src/test/ui/parser/removed-syntax-record.stderr index 730d5e2712b96..0a1655840b550 100644 --- a/src/test/ui/parser/removed-syntax-record.stderr +++ b/src/test/ui/parser/removed-syntax-record.stderr @@ -2,7 +2,7 @@ error: expected type, found `{` --> $DIR/removed-syntax-record.rs:1:10 | LL | type t = { f: () }; - | ^ + | ^ expected type error: aborting due to previous error diff --git a/src/test/ui/parser/trait-object-lifetime-parens.stderr b/src/test/ui/parser/trait-object-lifetime-parens.stderr index a31b7aea8fee6..7ffc26e9edead 100644 --- a/src/test/ui/parser/trait-object-lifetime-parens.stderr +++ b/src/test/ui/parser/trait-object-lifetime-parens.stderr @@ -29,7 +29,7 @@ error: expected type, found `'a` --> $DIR/trait-object-lifetime-parens.rs:9:17 | LL | let _: Box<('a) + Trait>; - | - ^^ + | - ^^ expected type | | | while parsing the type for `_` diff --git a/src/test/ui/suggestions/type-ascription-instead-of-method.stderr b/src/test/ui/suggestions/type-ascription-instead-of-method.stderr index 15ec087b1cc01..4a8d2f57d89d3 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-method.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-method.stderr @@ -2,9 +2,12 @@ error: expected type, found `"foo"` --> $DIR/type-ascription-instead-of-method.rs:2:13 | LL | Box:new("foo".to_string()) - | - ^^^^^ expecting a type here because of type ascription + | - ^^^^^ expected type | | - | help: maybe you meant to write a path separator here: `::` + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to previous error diff --git a/src/test/ui/suggestions/type-ascription-instead-of-variant.stderr b/src/test/ui/suggestions/type-ascription-instead-of-variant.stderr index 5719a667a8415..7e9a31c06c8b2 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-variant.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-variant.stderr @@ -2,9 +2,12 @@ error: expected type, found `""` --> $DIR/type-ascription-instead-of-variant.rs:2:25 | LL | let _ = Option:Some(""); - | - ^^ expecting a type here because of type ascription + | - ^^ expected type | | - | help: maybe you meant to write a path separator here: `::` + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to previous error diff --git a/src/test/ui/type/ascription/issue-34255-1.rs b/src/test/ui/type/ascription/issue-34255-1.rs new file mode 100644 index 0000000000000..c11a248d3c7d1 --- /dev/null +++ b/src/test/ui/type/ascription/issue-34255-1.rs @@ -0,0 +1,15 @@ +struct Reactor { + input_cells: Vec, +} + +impl Reactor { + pub fn new() -> Self { + input_cells: Vec::new() + //~^ ERROR cannot find value `input_cells` in this scope + //~| ERROR parenthesized type parameters may only be used with a `Fn` trait + //~| ERROR wrong number of type arguments: expected 1, found 0 + //~| WARNING this was previously accepted by the compiler but is being phased out + } +} + +// This case isn't currently being handled gracefully, including for completeness. diff --git a/src/test/ui/type/ascription/issue-34255-1.stderr b/src/test/ui/type/ascription/issue-34255-1.stderr new file mode 100644 index 0000000000000..531455b82b424 --- /dev/null +++ b/src/test/ui/type/ascription/issue-34255-1.stderr @@ -0,0 +1,30 @@ +error[E0425]: cannot find value `input_cells` in this scope + --> $DIR/issue-34255-1.rs:7:9 + | +LL | input_cells: Vec::new() + | ^^^^^^^^^^^ a field by this name exists in `Self` + +error: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-34255-1.rs:7:30 + | +LL | input_cells: Vec::new() + | ^^ + | + = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #42238 + +error[E0601]: `main` function not found in crate `issue_34255_1` + | + = note: consider adding a `main` function to `$DIR/issue-34255-1.rs` + +error[E0107]: wrong number of type arguments: expected 1, found 0 + --> $DIR/issue-34255-1.rs:7:22 + | +LL | input_cells: Vec::new() + | ^^^^^^^^^^ expected 1 type argument + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0107, E0425, E0601. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/type/ascription/issue-47666.rs b/src/test/ui/type/ascription/issue-47666.rs new file mode 100644 index 0000000000000..ceb1dd89daea9 --- /dev/null +++ b/src/test/ui/type/ascription/issue-47666.rs @@ -0,0 +1,5 @@ +fn main() { + let _ = Option:Some(vec![0, 1]); //~ ERROR expected type, found +} + +// This case isn't currently being handled gracefully due to the macro invocation. diff --git a/src/test/ui/type/ascription/issue-47666.stderr b/src/test/ui/type/ascription/issue-47666.stderr new file mode 100644 index 0000000000000..7aa899f795c7d --- /dev/null +++ b/src/test/ui/type/ascription/issue-47666.stderr @@ -0,0 +1,13 @@ +error: expected type, found reserved keyword `box` + --> $DIR/issue-47666.rs:2:25 + | +LL | let _ = Option:Some(vec![0, 1]); + | ^^^^^^^^^^ + | | + | expected type + | in this macro invocation + | + = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/src/test/ui/type/ascription/issue-54516.rs b/src/test/ui/type/ascription/issue-54516.rs new file mode 100644 index 0000000000000..6d65760e299b5 --- /dev/null +++ b/src/test/ui/type/ascription/issue-54516.rs @@ -0,0 +1,6 @@ +use std::collections::BTreeMap; + +fn main() { + println!("{}", std::mem:size_of::>()); + //~^ ERROR expected token: `,` +} diff --git a/src/test/ui/type/ascription/issue-54516.stderr b/src/test/ui/type/ascription/issue-54516.stderr new file mode 100644 index 0000000000000..a846f3bc320e6 --- /dev/null +++ b/src/test/ui/type/ascription/issue-54516.stderr @@ -0,0 +1,13 @@ +error: expected token: `,` + --> $DIR/issue-54516.rs:4:58 + | +LL | println!("{}", std::mem:size_of::>()); + | - ^ expected `,` + | | + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: aborting due to previous error + diff --git a/src/test/ui/type/ascription/issue-60933.rs b/src/test/ui/type/ascription/issue-60933.rs new file mode 100644 index 0000000000000..8fb06c887bd3e --- /dev/null +++ b/src/test/ui/type/ascription/issue-60933.rs @@ -0,0 +1,4 @@ +fn main() { + let u: usize = std::mem:size_of::(); + //~^ ERROR expected one of +} diff --git a/src/test/ui/type/ascription/issue-60933.stderr b/src/test/ui/type/ascription/issue-60933.stderr new file mode 100644 index 0000000000000..c2fc7bbcfc865 --- /dev/null +++ b/src/test/ui/type/ascription/issue-60933.stderr @@ -0,0 +1,13 @@ +error: expected one of `!`, `::`, or `;`, found `(` + --> $DIR/issue-60933.rs:2:43 + | +LL | let u: usize = std::mem:size_of::(); + | - ^ expected one of `!`, `::`, or `;` here + | | + | help: maybe write a path separator here: `::` + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: aborting due to previous error + diff --git a/src/test/ui/type/type-ascription-instead-of-initializer.stderr b/src/test/ui/type/type-ascription-instead-of-initializer.stderr index a22d25697d8bd..3fe676de59dab 100644 --- a/src/test/ui/type/type-ascription-instead-of-initializer.stderr +++ b/src/test/ui/type/type-ascription-instead-of-initializer.stderr @@ -2,7 +2,7 @@ error: expected type, found `10` --> $DIR/type-ascription-instead-of-initializer.rs:2:31 | LL | let x: Vec::with_capacity(10, 20); - | -- ^^ + | -- ^^ expected type | || | |help: use `=` if you meant to assign | while parsing the type for `x` diff --git a/src/test/ui/type/type-ascription-instead-of-statement-end.stderr b/src/test/ui/type/type-ascription-instead-of-statement-end.stderr index 1f8989db81412..8fbcb3969a79a 100644 --- a/src/test/ui/type/type-ascription-instead-of-statement-end.stderr +++ b/src/test/ui/type/type-ascription-instead-of-statement-end.stderr @@ -4,21 +4,21 @@ error: expected type, found `0` LL | println!("test"): | - help: try using a semicolon: `;` LL | 0; - | ^ expecting a type here because of type ascription + | ^ expected type + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: expected type, found `0` --> $DIR/type-ascription-instead-of-statement-end.rs:9:23 | LL | println!("test"): 0; - | ^ expecting a type here because of type ascription + | - ^ expected type + | | + | tried to parse a type due to this type ascription | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` -note: this expression expects an ascribed type after the colon - --> $DIR/type-ascription-instead-of-statement-end.rs:9:5 - | -LL | println!("test"): 0; - | ^^^^^^^^^^^^^^^^ - = help: this might be indicative of a syntax error elsewhere + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 error: aborting due to 2 previous errors From 9dbe2e77b34f5321976ee3b26ca008ad8d574faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 19 Jul 2019 10:59:02 -0700 Subject: [PATCH 10/26] review comments --- src/libsyntax/parse/diagnostics.rs | 14 +++++++------- src/libsyntax/parse/parser.rs | 12 +++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index 190672acfcf77..f4fc87506f357 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -327,8 +327,8 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw::Return) || self.token.is_keyword(kw::While) ); - let cm = self.sess.source_map(); - match (cm.lookup_line(self.token.span.lo()), cm.lookup_line(sp.lo())) { + let sm = self.sess.source_map(); + match (sm.lookup_line(self.token.span.lo()), sm.lookup_line(sp.lo())) { (Ok(ref a), Ok(ref b)) if a.line != b.line && is_semi_suggestable => { // The spans are in different lines, expected `;` and found `let` or `return`. // High likelihood that it is only a missing `;`. @@ -376,9 +376,9 @@ impl<'a> Parser<'a> { maybe_expected_semicolon: bool, ) { if let Some((sp, likely_path)) = self.last_type_ascription { - let cm = self.sess.source_map(); - let next_pos = cm.lookup_char_pos(self.token.span.lo()); - let op_pos = cm.lookup_char_pos(sp.hi()); + let sm = self.sess.source_map(); + let next_pos = sm.lookup_char_pos(self.token.span.lo()); + let op_pos = sm.lookup_char_pos(sp.hi()); if likely_path { err.span_suggestion( @@ -814,8 +814,8 @@ impl<'a> Parser<'a> { return Ok(recovered); } } - let cm = self.sess.source_map(); - match (cm.lookup_line(prev_sp.lo()), cm.lookup_line(sp.lo())) { + let sm = self.sess.source_map(); + match (sm.lookup_line(prev_sp.lo()), sm.lookup_line(sp.lo())) { (Ok(ref a), Ok(ref b)) if a.line == b.line => { // When the spans are in the same line, it means that the only content // between them is whitespace, point only at the found token. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 41cfb5bece3b8..da38869463737 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2850,9 +2850,7 @@ impl<'a> Parser<'a> { match (self.expr_is_complete(&lhs), AssocOp::from_token(&self.token)) { (true, None) => { - if last_type_ascription_set { - self.last_type_ascription = None; - } + self.last_type_ascription = None; // Semi-statement forms are odd. See https://github.com/rust-lang/rust/issues/29071 return Ok(lhs); } @@ -2867,18 +2865,14 @@ impl<'a> Parser<'a> { // If the next token is a keyword, then the tokens above *are* unambiguously incorrect: // `if x { a } else { b } && if y { c } else { d }` if !self.look_ahead(1, |t| t.is_reserved_ident()) => { - if last_type_ascription_set { - self.last_type_ascription = None; - } + self.last_type_ascription = None; // These cases are ambiguous and can't be identified in the parser alone let sp = self.sess.source_map().start_point(self.token.span); self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span); return Ok(lhs); } (true, Some(ref op)) if !op.can_continue_expr_unambiguously() => { - if last_type_ascription_set { - self.last_type_ascription = None; - } + self.last_type_ascription = None; return Ok(lhs); } (true, Some(_)) => { From b3618648f2d762c94bfbeee096562a799af38fe7 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Fri, 19 Jul 2019 21:59:54 +0300 Subject: [PATCH 11/26] fixup! rustc_typeck: improve diagnostics for _ const/static declarations --- src/test/ui/error-codes/E0121.stderr | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/ui/error-codes/E0121.stderr b/src/test/ui/error-codes/E0121.stderr index 1a16aab6a41d1..1def7029e6ed2 100644 --- a/src/test/ui/error-codes/E0121.stderr +++ b/src/test/ui/error-codes/E0121.stderr @@ -11,7 +11,10 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa --> $DIR/E0121.rs:3:13 | LL | static BAR: _ = "test"; - | ^ not allowed in type signatures + | ^ + | | + | not allowed in type signatures + | help: replace `_` with the correct return type: `&'static str` error: aborting due to 2 previous errors From c6e027de52be7acd006e874500ac6a2095f888be Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Fri, 19 Jul 2019 23:20:51 +0300 Subject: [PATCH 12/26] fixup! rustc_typeck: improve diagnostics for _ const/static declarations --- src/test/ui/error-codes/E0121.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/error-codes/E0121.stderr b/src/test/ui/error-codes/E0121.stderr index 1def7029e6ed2..beb8941320bc2 100644 --- a/src/test/ui/error-codes/E0121.stderr +++ b/src/test/ui/error-codes/E0121.stderr @@ -14,7 +14,7 @@ LL | static BAR: _ = "test"; | ^ | | | not allowed in type signatures - | help: replace `_` with the correct return type: `&'static str` + | help: replace `_` with the correct type: `&'static str` error: aborting due to 2 previous errors From 2641beddc4a08351dc101365b3f80f92092866f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 19 Jul 2019 19:25:03 -0700 Subject: [PATCH 13/26] Tweak span for variant not found error --- src/librustc_typeck/astconv.rs | 5 ++++- src/test/ui/suggestions/suggest-variants.stderr | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d314228a232c9..5799e58a727a8 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1650,7 +1650,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { Applicability::MaybeIncorrect, ); } else { - err.span_label(span, format!("variant not found in `{}`", qself_ty)); + err.span_label( + assoc_ident.span, + format!("variant not found in `{}`", qself_ty), + ); } if let Some(sp) = tcx.hir().span_if_local(adt_def.did) { diff --git a/src/test/ui/suggestions/suggest-variants.stderr b/src/test/ui/suggestions/suggest-variants.stderr index ef0ba70c34066..b4338e2055431 100644 --- a/src/test/ui/suggestions/suggest-variants.stderr +++ b/src/test/ui/suggestions/suggest-variants.stderr @@ -23,9 +23,7 @@ LL | enum Shape { | ---------- variant `Rombus` not found here ... LL | println!("My shape is {:?}", Shape::Rombus{ size: 5}); - | -------^^^^^^ - | | - | variant not found in `Shape` + | ^^^^^^ variant not found in `Shape` error[E0599]: no variant or associated item named `Squareee` found for type `Shape` in the current scope --> $DIR/suggest-variants.rs:15:12 From fd352b02e17d78f03345ebc3ffabe02b0cb04fd1 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Sat, 20 Jul 2019 11:48:16 +0530 Subject: [PATCH 14/26] alters the panic variant of InterpError --- src/librustc/mir/interpret/error.rs | 59 +++++++++--------------- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc_mir/interpret/intrinsics.rs | 6 +-- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index d5caa3c8ce442..9e216a14874c4 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -228,6 +228,24 @@ impl<'tcx> From> for InterpErrorInfo<'tcx> { pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>; +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +pub enum EvalErrorPanic { + Panic { + msg: Symbol, + line: u32, + col: u32, + file: Symbol, + }, + BoundsCheck { + len: O, + index: O, + }, + Overflow(mir::BinOp), + OverflowNeg, + DivisionByZero, + RemainderByZero, +} + #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum InterpError<'tcx, O> { /// This variant is used by machines to signal their own errors that do not @@ -247,7 +265,6 @@ pub enum InterpError<'tcx, O> { DanglingPointerDeref, DoubleFree, InvalidMemoryAccess, - FunctionPointerTyMismatch(FnSig<'tcx>, FnSig<'tcx>), InvalidFunctionPointer, InvalidBool, InvalidDiscriminant(ScalarMaybeUndef), @@ -267,13 +284,11 @@ pub enum InterpError<'tcx, O> { Unimplemented(String), DerefFunctionPointer, ExecuteMemory, - // asd BoundsCheck { len: O, index: O }, Overflow(mir::BinOp), OverflowNeg, DivisionByZero, RemainderByZero, - // asd Intrinsic(String), InvalidChar(u128), StackFrameLimitReached, @@ -284,29 +299,6 @@ pub enum InterpError<'tcx, O> { required: Align, has: Align, }, - MemoryLockViolation { - ptr: Pointer, - len: u64, - frame: usize, - access: AccessKind, - lock: Lock, - }, - MemoryAcquireConflict { - ptr: Pointer, - len: u64, - kind: AccessKind, - lock: Lock, - }, - InvalidMemoryLockRelease { - ptr: Pointer, - len: u64, - frame: usize, - lock: Lock, - }, - DeallocatedLockedMemory { - ptr: Pointer, - lock: Lock, - }, ValidationFailure(String), CalledClosureAsFunction, VtableForArgumentlessMethod, @@ -324,7 +316,7 @@ pub enum InterpError<'tcx, O> { HeapAllocZeroBytes, HeapAllocNonPowerOfTwoAlignment(u64), Unreachable, - Panic(EvalErrorPanic<'tcx, O>), + Panic(EvalErrorPanic), ReadFromReturnPointer, PathNotFound(Vec), UnimplementedTraitSelection, @@ -340,15 +332,6 @@ pub enum InterpError<'tcx, O> { InfiniteLoop, } -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub enum EvalErrorPanic<'tcx, O> { - Panic, - BoundsCheck { len: O, index: O }, - Overflow(mir::BinOp), - OverflowNeg, - DivisionByZero, - RemainderByZero, -} pub type InterpResult<'tcx, T = ()> = Result>; @@ -549,8 +532,8 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { write!(f, "incorrect alloc info: expected size {} and align {}, \ got size {} and align {}", size.bytes(), align.bytes(), size2.bytes(), align2.bytes()), - Panic { ref msg, line, col, ref file } => - write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col), + Panic { .. } => + write!(f, "the evaluated program panicked"), InvalidDiscriminant(val) => write!(f, "encountered invalid enum discriminant {}", val), Exit(code) => diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 1b294250aa3dc..01bc27d55e580 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -12,7 +12,7 @@ mod pointer; pub use self::error::{ InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error, - FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, + FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, EvalErrorPanic }; pub use self::value::{Scalar, ScalarMaybeUndef, RawConst, ConstValue}; diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index cf36c10a614e5..5b80d0e251e4b 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -7,7 +7,7 @@ use rustc::ty; use rustc::ty::layout::{LayoutOf, Primitive, Size}; use rustc::mir::BinOp; use rustc::mir::interpret::{ - InterpResult, InterpError, Scalar, + InterpResult, InterpError, Scalar, EvalErrorPanic, }; use super::{ @@ -261,7 +261,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic { msg, file, line, col }.into()); + return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); } else if Some(def_id) == self.tcx.lang_items().begin_panic_fn() { assert!(args.len() == 2); // &'static str, &(&'static str, u32, u32) @@ -279,7 +279,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic { msg, file, line, col }.into()); + return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); } else { return Ok(false); } From 18dceabc9546050a2c30c525f58aaf9cbc582a6b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 21 Jul 2019 14:18:20 +0900 Subject: [PATCH 15/26] Add tests for issue-58887 --- src/test/ui/issues/issue-58887.rs | 21 ++++++++++++++++ src/test/ui/issues/issue-58887.stderr | 35 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/test/ui/issues/issue-58887.rs create mode 100644 src/test/ui/issues/issue-58887.stderr diff --git a/src/test/ui/issues/issue-58887.rs b/src/test/ui/issues/issue-58887.rs new file mode 100644 index 0000000000000..ca2374af7bdc1 --- /dev/null +++ b/src/test/ui/issues/issue-58887.rs @@ -0,0 +1,21 @@ +#![feature(existential_type)] + +trait UnwrapItemsExt { + type II; + fn unwrap_items(self) -> Self::II; +} + +impl UnwrapItemsExt for I +where + I: Iterator>, + E: std::fmt::Debug, +{ + existential type II: Iterator; + //~^ ERROR: could not find defining uses + + fn unwrap_items(self) -> Self::II { + //~^ ERROR: type parameter `T` is part of concrete type + //~| ERROR: type parameter `E` is part of concrete type + self.map(|x| x.unwrap()) + } +} diff --git a/src/test/ui/issues/issue-58887.stderr b/src/test/ui/issues/issue-58887.stderr new file mode 100644 index 0000000000000..8cb25d84f54ad --- /dev/null +++ b/src/test/ui/issues/issue-58887.stderr @@ -0,0 +1,35 @@ +error[E0601]: `main` function not found in crate `issue_58887` + | + = note: consider adding a `main` function to `$DIR/issue-58887.rs` + +error: type parameter `T` is part of concrete type but not used in parameter list for existential type + --> $DIR/issue-58887.rs:16:39 + | +LL | fn unwrap_items(self) -> Self::II { + | _______________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: type parameter `E` is part of concrete type but not used in parameter list for existential type + --> $DIR/issue-58887.rs:16:39 + | +LL | fn unwrap_items(self) -> Self::II { + | _______________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: could not find defining uses + --> $DIR/issue-58887.rs:13:5 + | +LL | existential type II: Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0601`. From e63fe150bfbce632dd7ff0a656a4180557128e4f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 21 Jul 2019 16:46:11 +0300 Subject: [PATCH 16/26] move unescape module to rustc_lexer --- src/librustc_lexer/src/lib.rs | 1 + .../parse => librustc_lexer/src}/unescape.rs | 22 +++++++++---------- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/literal.rs | 6 ++--- src/libsyntax/parse/mod.rs | 1 - .../parse/unescape_error_reporting.rs | 3 +-- 6 files changed, 17 insertions(+), 18 deletions(-) rename src/{libsyntax/parse => librustc_lexer/src}/unescape.rs (97%) diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index a21190ec33244..12e095b8bd595 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -4,6 +4,7 @@ #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor; +pub mod unescape; use crate::cursor::{Cursor, EOF_CHAR}; diff --git a/src/libsyntax/parse/unescape.rs b/src/librustc_lexer/src/unescape.rs similarity index 97% rename from src/libsyntax/parse/unescape.rs rename to src/librustc_lexer/src/unescape.rs index 87cc9c1c9e323..70085df9948eb 100644 --- a/src/libsyntax/parse/unescape.rs +++ b/src/librustc_lexer/src/unescape.rs @@ -5,7 +5,7 @@ use std::str::Chars; use std::ops::Range; #[derive(Debug, PartialEq, Eq)] -pub(crate) enum EscapeError { +pub enum EscapeError { ZeroChars, MoreThanOneChar, @@ -35,7 +35,7 @@ pub(crate) enum EscapeError { /// Takes a contents of a char literal (without quotes), and returns an /// unescaped char or an error -pub(crate) fn unescape_char(literal_text: &str) -> Result { +pub fn unescape_char(literal_text: &str) -> Result { let mut chars = literal_text.chars(); unescape_char_or_byte(&mut chars, Mode::Char) .map_err(|err| (literal_text.len() - chars.as_str().len(), err)) @@ -43,14 +43,14 @@ pub(crate) fn unescape_char(literal_text: &str) -> Result(literal_text: &str, callback: &mut F) +pub fn unescape_str(literal_text: &str, callback: &mut F) where F: FnMut(Range, Result), { unescape_str_or_byte_str(literal_text, Mode::Str, callback) } -pub(crate) fn unescape_byte(literal_text: &str) -> Result { +pub fn unescape_byte(literal_text: &str) -> Result { let mut chars = literal_text.chars(); unescape_char_or_byte(&mut chars, Mode::Byte) .map(byte_from_char) @@ -59,7 +59,7 @@ pub(crate) fn unescape_byte(literal_text: &str) -> Result(literal_text: &str, callback: &mut F) +pub fn unescape_byte_str(literal_text: &str, callback: &mut F) where F: FnMut(Range, Result), { @@ -72,7 +72,7 @@ where /// sequence of characters or errors. /// NOTE: Raw strings do not perform any explicit character escaping, here we /// only translate CRLF to LF and produce errors on bare CR. -pub(crate) fn unescape_raw_str(literal_text: &str, callback: &mut F) +pub fn unescape_raw_str(literal_text: &str, callback: &mut F) where F: FnMut(Range, Result), { @@ -83,7 +83,7 @@ where /// sequence of characters or errors. /// NOTE: Raw strings do not perform any explicit character escaping, here we /// only translate CRLF to LF and produce errors on bare CR. -pub(crate) fn unescape_raw_byte_str(literal_text: &str, callback: &mut F) +pub fn unescape_raw_byte_str(literal_text: &str, callback: &mut F) where F: FnMut(Range, Result), { @@ -93,7 +93,7 @@ where } #[derive(Debug, Clone, Copy)] -pub(crate) enum Mode { +pub enum Mode { Char, Str, Byte, @@ -101,18 +101,18 @@ pub(crate) enum Mode { } impl Mode { - fn in_single_quotes(self) -> bool { + pub fn in_single_quotes(self) -> bool { match self { Mode::Char | Mode::Byte => true, Mode::Str | Mode::ByteStr => false, } } - pub(crate) fn in_double_quotes(self) -> bool { + pub fn in_double_quotes(self) -> bool { !self.in_single_quotes() } - pub(crate) fn is_bytes(self) -> bool { + pub fn is_bytes(self) -> bool { match self { Mode::Byte | Mode::ByteStr => true, Mode::Char | Mode::Str => false, diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 317c49c7d3543..ebb027378229a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1,12 +1,12 @@ use crate::parse::ParseSess; use crate::parse::token::{self, Token, TokenKind}; use crate::symbol::{sym, Symbol}; -use crate::parse::unescape; use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char}; use errors::{FatalError, Diagnostic, DiagnosticBuilder}; use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION}; use rustc_lexer::Base; +use rustc_lexer::unescape; use std::borrow::Cow; use std::char; diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index 683d164156540..6409acba573ad 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -4,9 +4,6 @@ use crate::ast::{self, Lit, LitKind}; use crate::parse::parser::Parser; use crate::parse::PResult; use crate::parse::token::{self, Token, TokenKind}; -use crate::parse::unescape::{unescape_char, unescape_byte}; -use crate::parse::unescape::{unescape_str, unescape_byte_str}; -use crate::parse::unescape::{unescape_raw_str, unescape_raw_byte_str}; use crate::print::pprust; use crate::symbol::{kw, sym, Symbol}; use crate::tokenstream::{TokenStream, TokenTree}; @@ -15,6 +12,9 @@ use errors::{Applicability, Handler}; use log::debug; use rustc_data_structures::sync::Lrc; use syntax_pos::Span; +use rustc_lexer::unescape::{unescape_char, unescape_byte}; +use rustc_lexer::unescape::{unescape_str, unescape_byte_str}; +use rustc_lexer::unescape::{unescape_raw_str, unescape_raw_byte_str}; use std::ascii; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 4c4551b1757ac..225065c1cf11f 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -32,7 +32,6 @@ pub mod token; crate mod classify; crate mod diagnostics; crate mod literal; -crate mod unescape; crate mod unescape_error_reporting; /// Info about a parsing session. diff --git a/src/libsyntax/parse/unescape_error_reporting.rs b/src/libsyntax/parse/unescape_error_reporting.rs index 71b41161ad8c6..bc3ee8620e068 100644 --- a/src/libsyntax/parse/unescape_error_reporting.rs +++ b/src/libsyntax/parse/unescape_error_reporting.rs @@ -3,12 +3,11 @@ use std::ops::Range; use std::iter::once; +use rustc_lexer::unescape::{EscapeError, Mode}; use syntax_pos::{Span, BytePos}; use crate::errors::{Handler, Applicability}; -use super::unescape::{EscapeError, Mode}; - pub(crate) fn emit_unescape_error( handler: &Handler, // interior part of the literal, without quotes From e75ae15fb912afe56f07425abbba9e3412d0c01d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 22 Jul 2019 07:12:31 +0900 Subject: [PATCH 17/26] Move into existential-type dir --- .../issue-58887.rs | 10 +++--- .../ui/existential-type/issue-58887.stderr | 30 ++++++++++++++++ src/test/ui/issues/issue-58887.stderr | 35 ------------------- 3 files changed, 36 insertions(+), 39 deletions(-) rename src/test/ui/{issues => existential-type}/issue-58887.rs (69%) create mode 100644 src/test/ui/existential-type/issue-58887.stderr delete mode 100644 src/test/ui/issues/issue-58887.stderr diff --git a/src/test/ui/issues/issue-58887.rs b/src/test/ui/existential-type/issue-58887.rs similarity index 69% rename from src/test/ui/issues/issue-58887.rs rename to src/test/ui/existential-type/issue-58887.rs index ca2374af7bdc1..f038648ec2149 100644 --- a/src/test/ui/issues/issue-58887.rs +++ b/src/test/ui/existential-type/issue-58887.rs @@ -1,8 +1,8 @@ #![feature(existential_type)] trait UnwrapItemsExt { - type II; - fn unwrap_items(self) -> Self::II; + type Iter; + fn unwrap_items(self) -> Self::Iter; } impl UnwrapItemsExt for I @@ -10,12 +10,14 @@ where I: Iterator>, E: std::fmt::Debug, { - existential type II: Iterator; + existential type Iter: Iterator; //~^ ERROR: could not find defining uses - fn unwrap_items(self) -> Self::II { + fn unwrap_items(self) -> Self::Iter { //~^ ERROR: type parameter `T` is part of concrete type //~| ERROR: type parameter `E` is part of concrete type self.map(|x| x.unwrap()) } } + +fn main() {} diff --git a/src/test/ui/existential-type/issue-58887.stderr b/src/test/ui/existential-type/issue-58887.stderr new file mode 100644 index 0000000000000..800f4b7e059fb --- /dev/null +++ b/src/test/ui/existential-type/issue-58887.stderr @@ -0,0 +1,30 @@ +error: type parameter `T` is part of concrete type but not used in parameter list for existential type + --> $DIR/issue-58887.rs:16:41 + | +LL | fn unwrap_items(self) -> Self::Iter { + | _________________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: type parameter `E` is part of concrete type but not used in parameter list for existential type + --> $DIR/issue-58887.rs:16:41 + | +LL | fn unwrap_items(self) -> Self::Iter { + | _________________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: could not find defining uses + --> $DIR/issue-58887.rs:13:5 + | +LL | existential type Iter: Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/issues/issue-58887.stderr b/src/test/ui/issues/issue-58887.stderr deleted file mode 100644 index 8cb25d84f54ad..0000000000000 --- a/src/test/ui/issues/issue-58887.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0601]: `main` function not found in crate `issue_58887` - | - = note: consider adding a `main` function to `$DIR/issue-58887.rs` - -error: type parameter `T` is part of concrete type but not used in parameter list for existential type - --> $DIR/issue-58887.rs:16:39 - | -LL | fn unwrap_items(self) -> Self::II { - | _______________________________________^ -LL | | -LL | | -LL | | self.map(|x| x.unwrap()) -LL | | } - | |_____^ - -error: type parameter `E` is part of concrete type but not used in parameter list for existential type - --> $DIR/issue-58887.rs:16:39 - | -LL | fn unwrap_items(self) -> Self::II { - | _______________________________________^ -LL | | -LL | | -LL | | self.map(|x| x.unwrap()) -LL | | } - | |_____^ - -error: could not find defining uses - --> $DIR/issue-58887.rs:13:5 - | -LL | existential type II: Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0601`. From 795d96d87b5ed28e090a7d9ad883b08eb926607b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 21 Jul 2019 22:38:30 +0200 Subject: [PATCH 18/26] Place::as_place_ref is now Place::as_ref --- src/librustc/mir/mod.rs | 2 +- src/librustc_codegen_ssa/mir/analyze.rs | 2 +- src/librustc_codegen_ssa/mir/block.rs | 8 +-- src/librustc_codegen_ssa/mir/operand.rs | 2 +- src/librustc_codegen_ssa/mir/rvalue.rs | 6 +-- src/librustc_codegen_ssa/mir/statement.rs | 6 +-- .../borrow_check/conflict_errors.rs | 54 +++++++++---------- .../borrow_check/error_reporting.rs | 4 +- src/librustc_mir/borrow_check/mod.rs | 18 +++---- src/librustc_mir/borrow_check/move_errors.rs | 24 ++++----- .../borrow_check/mutability_errors.rs | 8 +-- .../borrow_check/nll/explain_borrow/mod.rs | 4 +- src/librustc_mir/borrow_check/path_utils.rs | 2 +- .../borrow_check/places_conflict.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 2 +- .../dataflow/drop_flag_effects.rs | 2 +- src/librustc_mir/dataflow/impls/mod.rs | 6 +-- .../dataflow/move_paths/builder.rs | 10 ++-- src/librustc_mir/transform/add_retag.rs | 2 +- src/librustc_mir/transform/elaborate_drops.rs | 12 ++--- src/librustc_mir/transform/qualify_consts.rs | 6 +-- src/librustc_mir/transform/rustc_peek.rs | 4 +- 22 files changed, 93 insertions(+), 93 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index d8b641fbe31f4..75f03949d995b 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1931,7 +1931,7 @@ impl<'tcx> Place<'tcx> { iterate_over2(place_base, place_projection, &Projections::Empty, op) } - pub fn as_place_ref(&self) -> PlaceRef<'_, 'tcx> { + pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> { PlaceRef { base: &self.base, projection: &self.projection, diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 09c346117f9d9..907689541f978 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -238,7 +238,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> context: PlaceContext, location: Location) { debug!("visit_place(place={:?}, context={:?})", place, context); - self.process_place(&place.as_place_ref(), context, location); + self.process_place(&place.as_ref(), context, location); } fn visit_local(&mut self, diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index d4b434ffe809c..54afefd1a64e2 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { PassMode::Direct(_) | PassMode::Pair(..) => { let op = - self.codegen_consume(&mut bx, &mir::Place::RETURN_PLACE.as_place_ref()); + self.codegen_consume(&mut bx, &mir::Place::RETURN_PLACE.as_ref()); if let Ref(llval, _, align) = op.val { bx.load(llval, align) } else { @@ -314,7 +314,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return } - let place = self.codegen_place(&mut bx, &location.as_place_ref()); + let place = self.codegen_place(&mut bx, &location.as_ref()); let (args1, args2); let mut args = if let Some(llextra) = place.llextra { args2 = [place.llval, llextra]; @@ -1171,7 +1171,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place), LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"), LocalRef::Operand(None) => { - let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_place_ref())); + let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_ref())); assert!(!dst_layout.ty.has_erasable_regions()); let place = PlaceRef::alloca(bx, dst_layout, "transmute_temp"); place.storage_live(bx); @@ -1186,7 +1186,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } } else { - let dst = self.codegen_place(bx, &dst.as_place_ref()); + let dst = self.codegen_place(bx, &dst.as_ref()); self.codegen_transmute_into(bx, src, dst); } } diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index 0f6a95c1968b8..302dcfcc682a3 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -462,7 +462,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { match *operand { mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => { - self.codegen_consume(bx, &place.as_place_ref()) + self.codegen_consume(bx, &place.as_ref()) } mir::Operand::Constant(ref constant) => { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index cfb7db7365802..202cf147f1fcb 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -355,7 +355,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::Rvalue::Ref(_, bk, ref place) => { - let cg_place = self.codegen_place(&mut bx, &place.as_place_ref()); + let cg_place = self.codegen_place(&mut bx, &place.as_ref()); let ty = cg_place.layout.ty; @@ -446,7 +446,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Discriminant(ref place) => { let discr_ty = rvalue.ty(&*self.mir, bx.tcx()); - let discr = self.codegen_place(&mut bx, &place.as_place_ref()) + let discr = self.codegen_place(&mut bx, &place.as_ref()) .codegen_get_discr(&mut bx, discr_ty); (bx, OperandRef { val: OperandValue::Immediate(discr), @@ -527,7 +527,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } // use common size calculation for non zero-sized types - let cg_value = self.codegen_place(bx, &place.as_place_ref()); + let cg_value = self.codegen_place(bx, &place.as_ref()); cg_value.len(bx.cx()) } diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs index 499cda1cf8449..3717be4b41753 100644 --- a/src/librustc_codegen_ssa/mir/statement.rs +++ b/src/librustc_codegen_ssa/mir/statement.rs @@ -46,12 +46,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } } else { - let cg_dest = self.codegen_place(&mut bx, &place.as_place_ref()); + let cg_dest = self.codegen_place(&mut bx, &place.as_ref()); self.codegen_rvalue(bx, cg_dest, rvalue) } } mir::StatementKind::SetDiscriminant{ref place, variant_index} => { - self.codegen_place(&mut bx, &place.as_place_ref()) + self.codegen_place(&mut bx, &place.as_ref()) .codegen_set_discr(&mut bx, variant_index); bx } @@ -73,7 +73,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::StatementKind::InlineAsm(ref asm) => { let outputs = asm.outputs.iter().map(|output| { - self.codegen_place(&mut bx, &output.as_place_ref()) + self.codegen_place(&mut bx, &output.as_ref()) }).collect(); let input_vals = asm.inputs.iter() diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 95fc22dc5eb76..5d0e490ebea5a 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -139,14 +139,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let is_partial_move = move_site_vec.iter().any(|move_site| { let move_out = self.move_data.moves[(*move_site).moi]; let moved_place = &self.move_data.move_paths[move_out.path].place; - used_place != moved_place.as_place_ref() - && used_place.is_prefix_of(moved_place.as_place_ref()) + used_place != moved_place.as_ref() + && used_place.is_prefix_of(moved_place.as_ref()) }); for move_site in &move_site_vec { let move_out = self.move_data.moves[(*move_site).moi]; let moved_place = &self.move_data.move_paths[move_out.path].place; - let move_spans = self.move_spans(moved_place.as_place_ref(), move_out.source); + let move_spans = self.move_spans(moved_place.as_ref(), move_out.source); let move_span = move_spans.args_or_use(); let move_msg = if move_spans.for_closure() { @@ -223,7 +223,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let ty = place.ty(self.body, self.infcx.tcx).ty; let opt_name = - self.describe_place_with_options(place.as_place_ref(), IncludingDowncast(true)); + self.describe_place_with_options(place.as_ref(), IncludingDowncast(true)); let note_msg = match opt_name { Some(ref name) => format!("`{}`", name), None => "value".to_owned(), @@ -275,11 +275,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "report_move_out_while_borrowed: location={:?} place={:?} span={:?} borrow={:?}", location, place, span, borrow ); - let value_msg = match self.describe_place(place.as_place_ref()) { + let value_msg = match self.describe_place(place.as_ref()) { Some(name) => format!("`{}`", name), None => "value".to_owned(), }; - let borrow_msg = match self.describe_place(borrow.borrowed_place.as_place_ref()) { + let borrow_msg = match self.describe_place(borrow.borrowed_place.as_ref()) { Some(name) => format!("`{}`", name), None => "value".to_owned(), }; @@ -287,12 +287,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let borrow_spans = self.retrieve_borrow_spans(borrow); let borrow_span = borrow_spans.args_or_use(); - let move_spans = self.move_spans(place.as_place_ref(), location); + let move_spans = self.move_spans(place.as_ref(), location); let span = move_spans.args_or_use(); let mut err = self.cannot_move_when_borrowed( span, - &self.describe_place(place.as_place_ref()).unwrap_or_else(|| "_".to_owned()), + &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()), ); err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg)); err.span_label(span, format!("move out of {} occurs here", value_msg)); @@ -326,21 +326,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // Conflicting borrows are reported separately, so only check for move // captures. - let use_spans = self.move_spans(place.as_place_ref(), location); + let use_spans = self.move_spans(place.as_ref(), location); let span = use_spans.var_or_use(); let mut err = self.cannot_use_when_mutably_borrowed( span, - &self.describe_place(place.as_place_ref()).unwrap_or_else(|| "_".to_owned()), + &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()), borrow_span, - &self.describe_place(borrow.borrowed_place.as_place_ref()) + &self.describe_place(borrow.borrowed_place.as_ref()) .unwrap_or_else(|| "_".to_owned()), ); borrow_spans.var_span_label(&mut err, { let place = &borrow.borrowed_place; let desc_place = - self.describe_place(place.as_place_ref()).unwrap_or_else(|| "_".to_owned()); + self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()); format!("borrow occurs due to use of `{}`{}", desc_place, borrow_spans.describe()) }); @@ -517,7 +517,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } else { let borrow_place = &issued_borrow.borrowed_place; - let borrow_place_desc = self.describe_place(borrow_place.as_place_ref()) + let borrow_place_desc = self.describe_place(borrow_place.as_ref()) .unwrap_or_else(|| "_".to_owned()); issued_spans.var_span_label( &mut err, @@ -650,8 +650,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { return Some(( describe_base_place, - describe_place(first_borrowed_place.as_place_ref()), - describe_place(second_borrowed_place.as_place_ref()), + describe_place(first_borrowed_place.as_ref()), + describe_place(second_borrowed_place.as_ref()), union_ty.to_string(), )); } @@ -666,7 +666,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // If we didn't find a field access into a union, or both places match, then // only return the description of the first place. ( - describe_place(first_borrowed_place.as_place_ref()), + describe_place(first_borrowed_place.as_ref()), "".to_string(), "".to_string(), "".to_string(), @@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); let drop_span = place_span.1; - let root_place = self.prefixes(borrow.borrowed_place.as_place_ref(), PrefixSet::All) + let root_place = self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All) .last() .unwrap(); @@ -730,13 +730,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }, borrow_span)); if let StorageDeadOrDrop::Destructor(dropped_ty) = - self.classify_drop_access_kind(borrow.borrowed_place.as_place_ref()) + self.classify_drop_access_kind(borrow.borrowed_place.as_ref()) { // If a borrow of path `B` conflicts with drop of `D` (and // we're not in the uninteresting case where `B` is a // prefix of `D`), then report this as a more interesting // destructor conflict. - if !borrow.borrowed_place.as_place_ref().is_prefix_of(place_span.0.as_place_ref()) { + if !borrow.borrowed_place.as_ref().is_prefix_of(place_span.0.as_ref()) { self.report_borrow_conflicts_with_destructor( location, borrow, place_span, kind, dropped_ty, ); @@ -744,7 +744,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - let place_desc = self.describe_place(borrow.borrowed_place.as_place_ref()); + let place_desc = self.describe_place(borrow.borrowed_place.as_ref()); let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0)); let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place); @@ -951,12 +951,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.cannot_borrow_across_destructor(borrow_span); - let what_was_dropped = match self.describe_place(place.as_place_ref()) { + let what_was_dropped = match self.describe_place(place.as_ref()) { Some(name) => format!("`{}`", name.as_str()), None => String::from("temporary value"), }; - let label = match self.describe_place(borrow.borrowed_place.as_place_ref()) { + let label = match self.describe_place(borrow.borrowed_place.as_ref()) { Some(borrowed) => format!( "here, drop of {D} needs exclusive access to `{B}`, \ because the type `{T}` implements the `Drop` trait", @@ -1127,7 +1127,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { format!("`{}` is borrowed here", place_desc), ) } else { - let root_place = self.prefixes(borrow.borrowed_place.as_place_ref(), + let root_place = self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All) .last() .unwrap(); @@ -1390,7 +1390,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.cannot_mutate_in_match_guard( span, loan_span, - &self.describe_place(place.as_place_ref()).unwrap_or_else(|| "_".to_owned()), + &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()), "assign", ); loan_spans.var_span_label( @@ -1406,7 +1406,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.cannot_assign_to_borrowed( span, loan_span, - &self.describe_place(place.as_place_ref()).unwrap_or_else(|| "_".to_owned()), + &self.describe_place(place.as_ref()).unwrap_or_else(|| "_".to_owned()), ); loan_spans.var_span_label( @@ -1466,8 +1466,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { is_user_variable: None, .. }) - | None => (self.describe_place(place.as_place_ref()), assigned_span), - Some(decl) => (self.describe_place(err_place.as_place_ref()), decl.source_info.span), + | None => (self.describe_place(place.as_ref()), assigned_span), + Some(decl) => (self.describe_place(err_place.as_ref()), decl.source_info.span), }; let mut err = self.cannot_reassign_immutable( diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 156897aedb70a..a05c77aad6700 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -855,7 +855,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { def_id, is_generator, places ); if let Some((args_span, var_span)) = self.closure_span( - *def_id, Place::from(target).as_place_ref(), places + *def_id, Place::from(target).as_ref(), places ) { return ClosureUse { is_generator, @@ -895,7 +895,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { for (upvar, place) in self.infcx.tcx.upvars(def_id)?.values().zip(places) { match place { Operand::Copy(place) | - Operand::Move(place) if target_place == place.as_place_ref() => { + Operand::Move(place) if target_place == place.as_ref() => { debug!("closure_span: found captured local {:?}", place); return Some((*args_span, upvar.span)); }, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index cfc7e77f4e5a8..5ec1e514100de 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -560,7 +560,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Use, - (place.as_place_ref(), span), + (place.as_ref(), span), flow_state, ); } @@ -591,7 +591,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Use, - (output.as_place_ref(), o.span), + (output.as_ref(), o.span), flow_state, ); } else { @@ -1154,7 +1154,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Update, - (place_span.0.as_place_ref(), place_span.1), + (place_span.0.as_ref(), place_span.1), flow_state, ); } @@ -1232,7 +1232,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_if_path_or_subpath_is_moved( location, action, - (place.as_place_ref(), span), + (place.as_ref(), span), flow_state, ); } @@ -1260,7 +1260,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Use, - (place.as_place_ref(), span), + (place.as_ref(), span), flow_state, ); } @@ -1309,7 +1309,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn propagate_closure_used_mut_upvar(&mut self, operand: &Operand<'tcx>) { let propagate_closure_used_mut_place = |this: &mut Self, place: &Place<'tcx>| { if place.projection.is_some() { - if let Some(field) = this.is_upvar_field_projection(place.as_place_ref()) { + if let Some(field) = this.is_upvar_field_projection(place.as_ref()) { this.used_mut_upvars.push(field); } } else if let PlaceBase::Local(local) = place.base { @@ -1401,7 +1401,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Use, - (place.as_place_ref(), span), + (place.as_ref(), span), flow_state, ); } @@ -1419,7 +1419,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_if_path_or_subpath_is_moved( location, InitializationRequiringAction::Use, - (place.as_place_ref(), span), + (place.as_ref(), span), flow_state, ); } @@ -1437,7 +1437,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ) { debug!("check_for_invalidation_at_exit({:?})", borrow); let place = &borrow.borrowed_place; - let root_place = self.prefixes(place.as_place_ref(), PrefixSet::All).last().unwrap(); + let root_place = self.prefixes(place.as_ref(), PrefixSet::All).last().unwrap(); // FIXME(nll-rfc#40): do more precise destructor tracking here. For now // we just know that all locals are dropped at function exit (otherwise diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 38653dc0e5e9b..738a091b0dd76 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -131,7 +131,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } - let move_spans = self.move_spans(original_path.as_place_ref(), location); + let move_spans = self.move_spans(original_path.as_ref(), location); grouped_errors.push(GroupedMoveError::OtherIllegalMove { use_spans: move_spans, original_path, @@ -160,7 +160,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let from_simple_let = match_place.is_none(); let match_place = match_place.as_ref().unwrap_or(move_from); - match self.move_data.rev_lookup.find(match_place.as_place_ref()) { + match self.move_data.rev_lookup.find(match_place.as_ref()) { // Error with the match place LookupResult::Parent(_) => { for ge in &mut *grouped_errors { @@ -192,7 +192,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } // Error with the pattern LookupResult::Exact(_) => { - let mpi = match self.move_data.rev_lookup.find(move_from.as_place_ref()) { + let mpi = match self.move_data.rev_lookup.find(move_from.as_ref()) { LookupResult::Parent(Some(mpi)) => mpi, // move_from should be a projection from match_place. _ => unreachable!("Probably not unreachable..."), @@ -242,7 +242,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { }; debug!("report: original_path={:?} span={:?}, kind={:?} \ original_path.is_upvar_field_projection={:?}", original_path, span, kind, - self.is_upvar_field_projection(original_path.as_place_ref())); + self.is_upvar_field_projection(original_path.as_ref())); ( match kind { IllegalMoveOriginKind::Static => { @@ -277,7 +277,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { span: Span ) -> DiagnosticBuilder<'a> { let description = if place.projection.is_none() { - format!("static item `{}`", self.describe_place(place.as_place_ref()).unwrap()) + format!("static item `{}`", self.describe_place(place.as_ref()).unwrap()) } else { let mut base_static = &place.projection; while let Some(box Projection { base: Some(ref proj), .. }) = base_static { @@ -290,7 +290,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { format!( "`{:?}` as `{:?}` is a static item", - self.describe_place(place.as_place_ref()).unwrap(), + self.describe_place(place.as_ref()).unwrap(), self.describe_place(base_static).unwrap(), ) }; @@ -308,7 +308,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // borrow to provide feedback about why this // was a move rather than a copy. let ty = deref_target_place.ty(self.body, self.infcx.tcx).ty; - let upvar_field = self.prefixes(move_place.as_place_ref(), PrefixSet::All) + let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All) .find_map(|p| self.is_upvar_field_projection(p)); let deref_base = match deref_target_place.projection { @@ -363,10 +363,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let upvar_name = upvar.name; let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id); - let place_name = self.describe_place(move_place.as_place_ref()).unwrap(); + let place_name = self.describe_place(move_place.as_ref()).unwrap(); let place_description = if self - .is_upvar_field_projection(move_place.as_place_ref()) + .is_upvar_field_projection(move_place.as_ref()) .is_some() { format!("`{}`, a {}", place_name, capture_description) @@ -393,7 +393,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { _ => { let source = self.borrowed_content_source(deref_base); match ( - self.describe_place(move_place.as_place_ref()), + self.describe_place(move_place.as_ref()), source.describe_for_named_place(), ) { (Some(place_desc), Some(source_desc)) => { @@ -455,7 +455,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if binds_to.is_empty() { let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; - let place_desc = match self.describe_place(move_from.as_place_ref()) { + let place_desc = match self.describe_place(move_from.as_ref()) { Some(desc) => format!("`{}`", desc), None => format!("value"), }; @@ -483,7 +483,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => { let span = use_spans.var_or_use(); let place_ty = original_path.ty(self.body, self.infcx.tcx).ty; - let place_desc = match self.describe_place(original_path.as_place_ref()) { + let place_desc = match self.describe_place(original_path.as_ref()) { Some(desc) => format!("`{}`", desc), None => format!("value"), }; diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index c424c06c41add..937c6383be341 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let item_msg; let reason; let mut opt_source = None; - let access_place_desc = self.describe_place(access_place.as_place_ref()); + let access_place_desc = self.describe_place(access_place.as_ref()); debug!("report_mutability_error: access_place_desc={:?}", access_place_desc); match the_place_err { @@ -77,7 +77,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { )); item_msg = format!("`{}`", access_place_desc.unwrap()); - if self.is_upvar_field_projection(access_place.as_place_ref()).is_some() { + if self.is_upvar_field_projection(access_place.as_ref()).is_some() { reason = ", as it is not declared as mutable".to_string(); } else { let name = self.upvars[upvar_index.index()].name; @@ -109,7 +109,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { )); reason = - if self.is_upvar_field_projection(access_place.as_place_ref()).is_some() { + if self.is_upvar_field_projection(access_place.as_ref()).is_some() { ", as it is a captured variable in a `Fn` closure".to_string() } else { ", as `Fn` closures cannot mutate their captured variables".to_string() @@ -244,7 +244,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { format!( "mutable borrow occurs due to use of `{}` in closure", // always Some() if the message is printed. - self.describe_place(access_place.as_place_ref()).unwrap_or_default(), + self.describe_place(access_place.as_ref()).unwrap_or_default(), ) ); borrow_span diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index abb84c59d9b9e..aba3ef1cbbfc9 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -252,7 +252,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some(Cause::LiveVar(local, location)) => { let span = body.source_info(location).span; let spans = self - .move_spans(Place::from(local).as_place_ref(), location) + .move_spans(Place::from(local).as_ref(), location) .or_else(|| self.borrow_spans(span, location)); let borrow_location = location; @@ -305,7 +305,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); if let Some(region_name) = region_name { let opt_place_desc = - self.describe_place(borrow.borrowed_place.as_place_ref()); + self.describe_place(borrow.borrowed_place.as_ref()); BorrowExplanation::MustBeValidFor { category, from_closure, diff --git a/src/librustc_mir/borrow_check/path_utils.rs b/src/librustc_mir/borrow_check/path_utils.rs index 75065816df050..da3f165482655 100644 --- a/src/librustc_mir/borrow_check/path_utils.rs +++ b/src/librustc_mir/borrow_check/path_utils.rs @@ -50,7 +50,7 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>( body, &borrowed.borrowed_place, borrowed.kind, - place.as_place_ref(), + place.as_ref(), access, places_conflict::PlaceConflictBias::Overlap, ) { diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index 348214f97f256..b2a03147ecf80 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -36,7 +36,7 @@ crate fn places_conflict<'tcx>( body, borrow_place, BorrowKind::Mut { allow_two_phase_borrow: true }, - access_place.as_place_ref(), + access_place.as_ref(), AccessDepth::Deep, bias, ) diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index b58cef9cce1e7..d72b0addae915 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -1304,7 +1304,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { prefix_cursor = base; } - all_fake_borrows.push(place.as_place_ref()); + all_fake_borrows.push(place.as_ref()); } // Deduplicate and ensure a deterministic order. diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index b6dd544d39561..c071b3101fce3 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -171,7 +171,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>( let move_data = &ctxt.move_data; for arg in body.args_iter() { let place = mir::Place::from(arg); - let lookup_result = move_data.rev_lookup.find(place.as_place_ref()); + let lookup_result = move_data.rev_lookup.find(place.as_ref()); on_lookup_result_bits(tcx, body, move_data, lookup_result, |mpi| callback(mpi, DropFlagState::Present)); diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index ade732bbb7597..69bbe08792140 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -309,7 +309,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for MaybeInitializedPlaces<'a, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 1 (initialized). on_lookup_result_bits(self.tcx, self.body, self.move_data(), - self.move_data().rev_lookup.find(dest_place.as_place_ref()), + self.move_data().rev_lookup.find(dest_place.as_ref()), |mpi| { in_out.insert(mpi); }); } } @@ -367,7 +367,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 0 (initialized). on_lookup_result_bits(self.tcx, self.body, self.move_data(), - self.move_data().rev_lookup.find(dest_place.as_place_ref()), + self.move_data().rev_lookup.find(dest_place.as_ref()), |mpi| { in_out.remove(mpi); }); } } @@ -423,7 +423,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 1 (initialized). on_lookup_result_bits(self.tcx, self.body, self.move_data(), - self.move_data().rev_lookup.find(dest_place.as_place_ref()), + self.move_data().rev_lookup.find(dest_place.as_ref()), |mpi| { in_out.insert(mpi); }); } } diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 436ac30ffb42e..366b96b53b423 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -274,9 +274,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { // move-path for the interior so it will be separate from // the exterior. self.create_move_path(&place.clone().deref()); - self.gather_init(place.as_place_ref(), InitKind::Shallow); + self.gather_init(place.as_ref(), InitKind::Shallow); } else { - self.gather_init(place.as_place_ref(), InitKind::Deep); + self.gather_init(place.as_ref(), InitKind::Deep); } self.gather_rvalue(rval); } @@ -286,7 +286,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { StatementKind::InlineAsm(ref asm) => { for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) { if !kind.is_indirect { - self.gather_init(output.as_place_ref(), InitKind::Deep); + self.gather_init(output.as_ref(), InitKind::Deep); } } for (_, input) in asm.inputs.iter() { @@ -376,7 +376,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { TerminatorKind::DropAndReplace { ref location, ref value, .. } => { self.create_move_path(location); self.gather_operand(value); - self.gather_init(location.as_place_ref(), InitKind::Deep); + self.gather_init(location.as_ref(), InitKind::Deep); } TerminatorKind::Call { ref func, @@ -391,7 +391,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { } if let Some((ref destination, _bb)) = *destination { self.create_move_path(destination); - self.gather_init(destination.as_place_ref(), InitKind::NonPanicPathOnly); + self.gather_init(destination.as_ref(), InitKind::NonPanicPathOnly); } } } diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index 887f93c647878..d573423906c2a 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -79,7 +79,7 @@ impl MirPass for AddRetag { let needs_retag = |place: &Place<'tcx>| { // FIXME: Instead of giving up for unstable places, we should introduce // a temporary and retag on that. - is_stable(place.as_place_ref()) + is_stable(place.as_ref()) && may_have_reference(place.ty(&*local_decls, tcx).ty, tcx) }; diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 0748321f60593..0a021d9b8fa06 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -105,7 +105,7 @@ fn find_dead_unwinds<'tcx>( init_data.apply_location(tcx, body, env, loc); } - let path = match env.move_data.rev_lookup.find(location.as_place_ref()) { + let path = match env.move_data.rev_lookup.find(location.as_ref()) { LookupResult::Exact(e) => e, LookupResult::Parent(..) => { debug!("find_dead_unwinds: has parent; skipping"); @@ -360,7 +360,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { statement_index: data.statements.len() }); - let path = self.move_data().rev_lookup.find(location.as_place_ref()); + let path = self.move_data().rev_lookup.find(location.as_ref()); debug!("collect_drop_flags: {:?}, place {:?} ({:?})", bb, location, path); @@ -399,7 +399,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { match terminator.kind { TerminatorKind::Drop { ref location, target, unwind } => { let init_data = self.initialization_data_at(loc); - match self.move_data().rev_lookup.find(location.as_place_ref()) { + match self.move_data().rev_lookup.find(location.as_ref()) { LookupResult::Exact(path) => { elaborate_drop( &mut Elaborator { @@ -488,7 +488,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { is_cleanup: false, }); - match self.move_data().rev_lookup.find(location.as_place_ref()) { + match self.move_data().rev_lookup.find(location.as_ref()) { LookupResult::Exact(path) => { debug!("elaborate_drop_and_replace({:?}) - tracked {:?}", terminator, path); let init_data = self.initialization_data_at(loc); @@ -558,7 +558,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { assert!(!self.patch.is_patched(bb)); let loc = Location { block: tgt, statement_index: 0 }; - let path = self.move_data().rev_lookup.find(place.as_place_ref()); + let path = self.move_data().rev_lookup.find(place.as_ref()); on_lookup_result_bits( self.tcx, self.body, self.move_data(), path, |child| self.set_drop_flag(loc, child, DropFlagState::Present) @@ -632,7 +632,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { assert!(!self.patch.is_patched(bb)); let loc = Location { block: bb, statement_index: data.statements.len() }; - let path = self.move_data().rev_lookup.find(place.as_place_ref()); + let path = self.move_data().rev_lookup.find(place.as_ref()); on_lookup_result_bits( self.tcx, self.body, self.move_data(), path, |child| self.set_drop_flag(loc, child, DropFlagState::Present) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 739e2172b03bc..ffeaf4e19c22a 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -243,7 +243,7 @@ trait Qualif { fn in_operand(cx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>) -> bool { match *operand { Operand::Copy(ref place) | - Operand::Move(ref place) => Self::in_place(cx, place.as_place_ref()), + Operand::Move(ref place) => Self::in_place(cx, place.as_ref()), Operand::Constant(ref constant) => { if let ConstValue::Unevaluated(def_id, _) = constant.literal.val { @@ -272,7 +272,7 @@ trait Qualif { Rvalue::NullaryOp(..) => false, Rvalue::Discriminant(ref place) | - Rvalue::Len(ref place) => Self::in_place(cx, place.as_place_ref()), + Rvalue::Len(ref place) => Self::in_place(cx, place.as_ref()), Rvalue::Use(ref operand) | Rvalue::Repeat(ref operand, _) | @@ -298,7 +298,7 @@ trait Qualif { } } - Self::in_place(cx, place.as_place_ref()) + Self::in_place(cx, place.as_ref()) } Rvalue::Aggregate(_, ref operands) => { diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 1fd865c42fcdb..7fe8480c819e6 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -168,7 +168,7 @@ fn each_block<'tcx, O>( if place == peek_arg_place { if let mir::Rvalue::Ref(_, mir::BorrowKind::Shared, ref peeking_at_place) = **rvalue { // Okay, our search is over. - match move_data.rev_lookup.find(peeking_at_place.as_place_ref()) { + match move_data.rev_lookup.find(peeking_at_place.as_ref()) { LookupResult::Exact(peek_mpi) => { let bit_state = on_entry.contains(peek_mpi); debug!("rustc_peek({:?} = &{:?}) bit_state: {}", @@ -192,7 +192,7 @@ fn each_block<'tcx, O>( } } - let lhs_mpi = move_data.rev_lookup.find(place.as_place_ref()); + let lhs_mpi = move_data.rev_lookup.find(place.as_ref()); debug!("rustc_peek: computing effect on place: {:?} ({:?}) in stmt: {:?}", place, lhs_mpi, stmt); From 27b703dd409c875853394f9c7f8400cd34390088 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 22 Jul 2019 12:09:34 +0300 Subject: [PATCH 19/26] add rustc_private as a proper language feature gate At the moment, `rustc_private` as a (library) feature exists by accident: `char::is_xid_start`, `char::is_xid_continue` methods in libcore define it. --- src/libcore/char/methods.rs | 19 ++++++++++++------- src/libfmt_macros/lib.rs | 1 + src/librustc_lexer/src/lib.rs | 1 - src/librustdoc/lib.rs | 1 + src/libsyntax/feature_gate.rs | 3 +++ src/libsyntax_ext/lib.rs | 1 + src/test/ui/feature-gate/rustc-private.rs | 5 +++++ src/test/ui/feature-gate/rustc-private.stderr | 12 ++++++++++++ 8 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/feature-gate/rustc-private.rs create mode 100644 src/test/ui/feature-gate/rustc-private.stderr diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index e843303380ad0..99f88591eea3e 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -553,10 +553,12 @@ impl char { /// 'XID_Start' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to `ID_Start` but modified for closure under `NFKx`. - #[unstable(feature = "rustc_private", - reason = "mainly needed for compiler internals", - issue = "27812")] - #[inline] + #[cfg_attr(bootstrap, + unstable(feature = "rustc_private", + reason = "mainly needed for compiler internals", + issue = "27812"))] + #[cfg_attr(not(bootstrap), + unstable(feature = "unicode_internals", issue = "0"))] pub fn is_xid_start(self) -> bool { derived_property::XID_Start(self) } @@ -567,9 +569,12 @@ impl char { /// 'XID_Continue' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. - #[unstable(feature = "rustc_private", - reason = "mainly needed for compiler internals", - issue = "27812")] + #[cfg_attr(bootstrap, + unstable(feature = "rustc_private", + reason = "mainly needed for compiler internals", + issue = "27812"))] + #[cfg_attr(not(bootstrap), + unstable(feature = "unicode_internals", issue = "0"))] #[inline] pub fn is_xid_continue(self) -> bool { derived_property::XID_Continue(self) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 39f130b82ed83..f1c2b1fb87133 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -13,6 +13,7 @@ #![feature(nll)] #![feature(rustc_private)] +#![feature(unicode_internals)] pub use Piece::*; pub use Position::*; diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index a21190ec33244..2d10ac8b0241a 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -1,6 +1,5 @@ // We want to be able to build this crate with a stable compiler, so feature // flags should optional. -#![cfg_attr(not(feature = "unicode-xid"), feature(rustc_private))] #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 58777130b7f29..3627ce6a5aa50 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -21,6 +21,7 @@ #![feature(inner_deref)] #![feature(never_type)] #![feature(mem_take)] +#![feature(unicode_internals)] #![recursion_limit="256"] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6a3f58ec89e19..43f0eaae7c97e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -126,6 +126,9 @@ declare_features! ( // no-tracking-issue-start + // Allows using compiler's own crates. + (active, rustc_private, "1.0.0", Some(27812), None), + // Allows using the `rust-intrinsic`'s "ABI". (active, intrinsics, "1.0.0", None, None), diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index da0f8ca6da090..7de90278ed732 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -12,6 +12,7 @@ #![feature(decl_macro)] #![feature(nll)] #![feature(rustc_diagnostic_macros)] +#![feature(unicode_internals)] #![recursion_limit="256"] diff --git a/src/test/ui/feature-gate/rustc-private.rs b/src/test/ui/feature-gate/rustc-private.rs new file mode 100644 index 0000000000000..7b8944bb0a0b8 --- /dev/null +++ b/src/test/ui/feature-gate/rustc-private.rs @@ -0,0 +1,5 @@ +// gate-test-rustc_private + +extern crate libc; //~ ERROR use of unstable library feature 'rustc_private' + +fn main() {} diff --git a/src/test/ui/feature-gate/rustc-private.stderr b/src/test/ui/feature-gate/rustc-private.stderr new file mode 100644 index 0000000000000..be320718145e0 --- /dev/null +++ b/src/test/ui/feature-gate/rustc-private.stderr @@ -0,0 +1,12 @@ +error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? + --> $DIR/rustc-private.rs:3:1 + | +LL | extern crate libc; + | ^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/27812 + = help: add `#![feature(rustc_private)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From 1a7127bbc469ba10c11d9d2d0b10669aff38b90c Mon Sep 17 00:00:00 2001 From: Samy Kacimi Date: Mon, 22 Jul 2019 22:52:13 +0200 Subject: [PATCH 20/26] normalize use of backticks in compiler messages for librustc_allocator https://github.com/rust-lang/rust/issues/60532 --- src/librustc_allocator/expand.rs | 4 ++-- src/test/ui/allocator/two-allocators.rs | 2 +- src/test/ui/allocator/two-allocators.stderr | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 87373364c4d9e..af63fffc0f9b4 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -79,7 +79,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> { if self.found { self.handler - .span_err(item.span, "cannot define more than one #[global_allocator]"); + .span_err(item.span, "cannot define more than one `#[global_allocator]`"); return smallvec![item]; } self.found = true; @@ -280,7 +280,7 @@ impl AllocFnFactory<'_> { AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(Vec::new())), expr), AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { - panic!("can't convert AllocatorTy to an output") + panic!("can't convert `AllocatorTy` to an output") } } } diff --git a/src/test/ui/allocator/two-allocators.rs b/src/test/ui/allocator/two-allocators.rs index 10fb03c39302b..0f81fc41823ba 100644 --- a/src/test/ui/allocator/two-allocators.rs +++ b/src/test/ui/allocator/two-allocators.rs @@ -4,6 +4,6 @@ use std::alloc::System; static A: System = System; #[global_allocator] static B: System = System; -//~^ ERROR: cannot define more than one #[global_allocator] +//~^ ERROR: cannot define more than one `#[global_allocator]` fn main() {} diff --git a/src/test/ui/allocator/two-allocators.stderr b/src/test/ui/allocator/two-allocators.stderr index da247f6c316c3..6b0c2b2a25d38 100644 --- a/src/test/ui/allocator/two-allocators.stderr +++ b/src/test/ui/allocator/two-allocators.stderr @@ -1,4 +1,4 @@ -error: cannot define more than one #[global_allocator] +error: cannot define more than one `#[global_allocator]` --> $DIR/two-allocators.rs:6:1 | LL | static B: System = System; From 4e02a1f7c51fe8e5270453ca02f65debf07169da Mon Sep 17 00:00:00 2001 From: Alex Touchet Date: Mon, 22 Jul 2019 16:16:59 -0700 Subject: [PATCH 21/26] Change "OSX" to "macOS" --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d4bde44ff9d3c..40df6a4737871 100644 --- a/README.md +++ b/README.md @@ -200,11 +200,11 @@ fetch snapshots, and an OS that can execute the available snapshot binaries. Snapshot binaries are currently built and tested on several platforms: -| Platform / Architecture | x86 | x86_64 | -|--------------------------|-----|--------| -| Windows (7, 8, 10, ...) | ✓ | ✓ | -| Linux (2.6.18 or later) | ✓ | ✓ | -| OSX (10.7 Lion or later) | ✓ | ✓ | +| Platform / Architecture | x86 | x86_64 | +|----------------------------|-----|--------| +| Windows (7, 8, 10, ...) | ✓ | ✓ | +| Linux (2.6.18 or later) | ✓ | ✓ | +| macOS (10.7 Lion or later) | ✓ | ✓ | You may find that other platforms work, but these are our officially supported build environments that are most likely to work. From 1ed375c68970f2c16500738249b10b46d3d3ec37 Mon Sep 17 00:00:00 2001 From: git-iso <46284404+git-iso@users.noreply.github.com> Date: Mon, 22 Jul 2019 23:30:21 -0400 Subject: [PATCH 22/26] Update stage0.txt Grammar. --- src/stage0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stage0.txt b/src/stage0.txt index 9b70a40458287..d548f6c06f406 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -25,7 +25,7 @@ cargo: beta # # This means that there's a small window of time (a few days) where artifacts # are downloaded from dev-static.rust-lang.org instead of static.rust-lang.org. -# In order to ease this transition we have an extra key is in this configuration +# In order to ease this transition we have an extra key which is in the configuration # file below. When uncommented this will instruct the bootstrap.py script to # download from dev-static.rust-lang.org. # From 7e612c19bee19b41796e8a4f4fe8a41714d7b3c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jul 2019 10:38:18 +0300 Subject: [PATCH 23/26] Update src/librustc_lexer/src/lib.rs Co-Authored-By: Ralf Jung --- src/librustc_lexer/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index 2d10ac8b0241a..244e837364adb 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -1,5 +1,5 @@ // We want to be able to build this crate with a stable compiler, so feature -// flags should optional. +// flags should be optional. #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor; From 90426ed6427f7a7a79eb47f60615d5a62ab1869f Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Sat, 20 Jul 2019 18:57:46 +0530 Subject: [PATCH 24/26] moving some variants from InterpError to EvalErrorPanic --- src/librustc/mir/interpret/error.rs | 53 ++++++++++--------- src/librustc/mir/interpret/pointer.rs | 6 +-- src/librustc/mir/mod.rs | 10 ++-- src/librustc/mir/visit.rs | 3 +- src/librustc_codegen_ssa/mir/block.rs | 6 +-- src/librustc_mir/borrow_check/mod.rs | 4 +- .../borrow_check/nll/invalidation.rs | 4 +- .../borrow_check/nll/type_check/mod.rs | 4 +- src/librustc_mir/build/expr/as_place.rs | 6 +-- src/librustc_mir/build/expr/as_rvalue.rs | 10 ++-- src/librustc_mir/interpret/operator.rs | 10 ++-- src/librustc_mir/interpret/place.rs | 4 +- src/librustc_mir/interpret/terminator.rs | 18 ++++--- src/librustc_mir/transform/const_prop.rs | 28 +++++----- 14 files changed, 88 insertions(+), 78 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 9e216a14874c4..41ec2029c816e 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -284,11 +284,6 @@ pub enum InterpError<'tcx, O> { Unimplemented(String), DerefFunctionPointer, ExecuteMemory, - BoundsCheck { len: O, index: O }, - Overflow(mir::BinOp), - OverflowNeg, - DivisionByZero, - RemainderByZero, Intrinsic(String), InvalidChar(u128), StackFrameLimitReached, @@ -332,7 +327,6 @@ pub enum InterpError<'tcx, O> { InfiniteLoop, } - pub type InterpResult<'tcx, T = ()> = Result>; impl<'tcx, O> InterpError<'tcx, O> { @@ -383,8 +377,6 @@ impl<'tcx, O> InterpError<'tcx, O> { "tried to dereference a function pointer", ExecuteMemory => "tried to treat a memory pointer as a function pointer", - BoundsCheck{..} => - "array index out of bounds", Intrinsic(..) => "intrinsic failed", NoMirFor(..) => @@ -436,8 +428,32 @@ impl<'tcx, O> InterpError<'tcx, O> { two", Unreachable => "entered unreachable code", - Panic { .. } => + Panic(EvalErrorPanic::Panic{..}) => "the evaluated program panicked", + Panic(EvalErrorPanic::BoundsCheck{..}) => + "array index out of bounds", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Add)) => + "attempt to add with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Sub)) => + "attempt to subtract with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Mul)) => + "attempt to multiply with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Div)) => + "attempt to divide with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Rem)) => + "attempt to calculate the remainder with overflow", + Panic(EvalErrorPanic::OverflowNeg) => + "attempt to negate with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Shr)) => + "attempt to shift right with overflow", + Panic(EvalErrorPanic::Overflow(mir::BinOp::Shl)) => + "attempt to shift left with overflow", + Panic(EvalErrorPanic::Overflow(op)) => + bug!("{:?} cannot overflow", op), + Panic(EvalErrorPanic::DivisionByZero) => + "attempt to divide by zero", + Panic(EvalErrorPanic::RemainderByZero) => + "attempt to calculate the remainder with a divisor of zero", ReadFromReturnPointer => "tried to read from the return pointer", PathNotFound(_) => @@ -450,17 +466,6 @@ impl<'tcx, O> InterpError<'tcx, O> { "encountered overly generic constant", ReferencedConstant => "referenced constant has errors", - Overflow(mir::BinOp::Add) => "attempt to add with overflow", - Overflow(mir::BinOp::Sub) => "attempt to subtract with overflow", - Overflow(mir::BinOp::Mul) => "attempt to multiply with overflow", - Overflow(mir::BinOp::Div) => "attempt to divide with overflow", - Overflow(mir::BinOp::Rem) => "attempt to calculate the remainder with overflow", - OverflowNeg => "attempt to negate with overflow", - Overflow(mir::BinOp::Shr) => "attempt to shift right with overflow", - Overflow(mir::BinOp::Shl) => "attempt to shift left with overflow", - Overflow(op) => bug!("{:?} cannot overflow", op), - DivisionByZero => "attempt to divide by zero", - RemainderByZero => "attempt to calculate the remainder with a divisor of zero", GeneratorResumedAfterReturn => "generator resumed after completion", GeneratorResumedAfterPanic => "generator resumed after panicking", InfiniteLoop => @@ -507,8 +512,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { callee_ty, caller_ty), FunctionArgCountMismatch => write!(f, "tried to call a function with incorrect number of arguments"), - BoundsCheck { ref len, ref index } => - write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index), ReallocatedWrongMemoryKind(ref old, ref new) => write!(f, "tried to reallocate memory from {} to {}", old, new), DeallocatedWrongMemoryKind(ref old, ref new) => @@ -532,8 +535,10 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { write!(f, "incorrect alloc info: expected size {} and align {}, \ got size {} and align {}", size.bytes(), align.bytes(), size2.bytes(), align2.bytes()), - Panic { .. } => - write!(f, "the evaluated program panicked"), + Panic(EvalErrorPanic::Panic { ref msg, line, col, ref file }) => + write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col), + Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => + write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index), InvalidDiscriminant(val) => write!(f, "encountered invalid enum discriminant {}", val), Exit(code) => diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index a17bc1f67283d..814cd90343c8b 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -5,7 +5,7 @@ use crate::ty::layout::{self, HasDataLayout, Size}; use rustc_macros::HashStable; use super::{ - AllocId, InterpResult, + AllocId, InterpResult, EvalErrorPanic }; /// Used by `check_in_alloc` to indicate context of check @@ -76,13 +76,13 @@ pub trait PointerArithmetic: layout::HasDataLayout { #[inline] fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_offset(val, i); - if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) } + if over { err!(Panic(EvalErrorPanic::Overflow(mir::BinOp::Add))) } else { Ok(res) } } #[inline] fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_signed_offset(val, i128::from(i)); - if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) } + if over { err!(Panic(EvalErrorPanic::Overflow(mir::BinOp::Add))) } else { Ok(res) } } } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 783964c701ad5..ca1111d7fbf04 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -7,7 +7,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; use crate::hir::{self, InlineAsm as HirInlineAsm}; -use crate::mir::interpret::{ConstValue, InterpError, Scalar}; +use crate::mir::interpret::{ConstValue, EvalErrorPanic, InterpError::Panic, Scalar}; use crate::mir::visit::MirVisitable; use crate::rustc_serialize as serialize; use crate::ty::adjustment::PointerCast; @@ -3087,11 +3087,11 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } } Assert { ref cond, expected, ref msg, target, cleanup } => { - let msg = if let InterpError::BoundsCheck { ref len, ref index } = *msg { - InterpError::BoundsCheck { + let msg = if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { + Panic(EvalErrorPanic::BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder), - } + }) } else { msg.clone() }; @@ -3132,7 +3132,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } Assert { ref cond, ref msg, .. } => { if cond.visit_with(visitor) { - if let InterpError::BoundsCheck { ref len, ref index } = *msg { + if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { len.visit_with(visitor) || index.visit_with(visitor) } else { false diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index babce812d4a39..54f987e2cf034 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -514,7 +514,8 @@ macro_rules! make_mir_visitor { msg: & $($mutability)? AssertMessage<'tcx>, location: Location) { use crate::mir::interpret::InterpError::*; - if let BoundsCheck { len, index } = msg { + use crate::mir::interpret::EvalErrorPanic::BoundsCheck; + if let Panic(BoundsCheck { len, index }) = msg { self.visit_operand(len, location); self.visit_operand(index, location); } diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 941166ccfab09..beb6b9421ce33 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -2,7 +2,7 @@ use rustc::middle::lang_items; use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt}; use rustc::mir::{self, Place, PlaceBase, Static, StaticKind}; -use rustc::mir::interpret::InterpError; +use rustc::mir::interpret::{InterpError, EvalErrorPanic}; use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; use rustc_target::spec::abi::Abi; use crate::base; @@ -368,7 +368,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // checked operation, just a comparison with the minimum // value, so we have to check for the assert message. if !bx.check_overflow() { - if let mir::interpret::InterpError::OverflowNeg = *msg { + if let InterpError::Panic(EvalErrorPanic::OverflowNeg) = *msg { const_cond = Some(expected); } } @@ -403,7 +403,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Put together the arguments to the panic entry point. let (lang_item, args) = match *msg { - InterpError::BoundsCheck { ref len, ref index } => { + InterpError::Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { let len = self.codegen_operand(&mut bx, len).immediate(); let index = self.codegen_operand(&mut bx, index).immediate(); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 5851cd8178878..86f2c07e6b94f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -734,8 +734,8 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx cleanup: _, } => { self.consume_operand(loc, (cond, span), flow_state); - use rustc::mir::interpret::InterpError::BoundsCheck; - if let BoundsCheck { ref len, ref index } = *msg { + use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic}; + if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { self.consume_operand(loc, (len, span), flow_state); self.consume_operand(loc, (index, span), flow_state); } diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index c7b4a40305259..51a00d2f0eb64 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -207,8 +207,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { cleanup: _, } => { self.consume_operand(location, cond); - use rustc::mir::interpret::InterpError::BoundsCheck; - if let BoundsCheck { ref len, ref index } = *msg { + use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic::BoundsCheck}; + if let Panic(BoundsCheck { ref len, ref index }) = *msg { self.consume_operand(location, len); self.consume_operand(location, index); } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index cdbbe1d02bd92..79020fdb4a5f3 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -28,7 +28,7 @@ use rustc::infer::canonical::QueryRegionConstraints; use rustc::infer::outlives::env::RegionBoundPairs; use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc::mir::interpret::{InterpError::BoundsCheck, ConstValue}; +use rustc::mir::interpret::{InterpError::Panic, ConstValue, EvalErrorPanic}; use rustc::mir::tcx::PlaceTy; use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext}; use rustc::mir::*; @@ -1589,7 +1589,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } - if let BoundsCheck { ref len, ref index } = *msg { + if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { if len.ty(body, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 82accb47437c6..f342761e25de0 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -4,7 +4,7 @@ use crate::build::expr::category::Category; use crate::build::ForGuard::{OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; -use rustc::mir::interpret::InterpError::BoundsCheck; +use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic::BoundsCheck}; use rustc::mir::*; use rustc::ty::{CanonicalUserTypeAnnotation, Variance}; @@ -105,10 +105,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ), ); - let msg = BoundsCheck { + let msg = Panic(BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(idx)), - }; + }); let success = this.assert(block, Operand::Move(lt), true, msg, expr_span); success.and(slice.index(idx)) } diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 56c518a6d57a8..10bf48a85d098 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -7,7 +7,7 @@ use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; use rustc::middle::region; -use rustc::mir::interpret::InterpError; +use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic}; use rustc::mir::*; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use syntax_pos::Span; @@ -101,7 +101,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, Operand::Move(is_min), false, - InterpError::OverflowNeg, + Panic(EvalErrorPanic::OverflowNeg), expr_span, ); } @@ -401,7 +401,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let val = result_value.clone().field(val_fld, ty); let of = result_value.field(of_fld, bool_ty); - let err = InterpError::Overflow(op); + let err = Panic(EvalErrorPanic::Overflow(op)); block = self.assert(block, Operand::Move(of), false, err, span); @@ -412,9 +412,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // and 2. there are two possible failure cases, divide-by-zero and overflow. let (zero_err, overflow_err) = if op == BinOp::Div { - (InterpError::DivisionByZero, InterpError::Overflow(op)) + (Panic(EvalErrorPanic::DivisionByZero), Panic(EvalErrorPanic::Overflow(op))) } else { - (InterpError::RemainderByZero, InterpError::Overflow(op)) + (Panic(EvalErrorPanic::RemainderByZero), Panic(EvalErrorPanic::Overflow(op))) }; // Check for / 0 diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 20180c9cba542..0932b468a502a 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -2,7 +2,7 @@ use rustc::mir; use rustc::ty::{self, layout::TyLayout}; use syntax::ast::FloatTy; use rustc_apfloat::Float; -use rustc::mir::interpret::{InterpResult, Scalar}; +use rustc::mir::interpret::{InterpResult, EvalErrorPanic, Scalar}; use super::{InterpCx, PlaceTy, Immediate, Machine, ImmTy}; @@ -173,8 +173,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return Ok((Scalar::from_bool(op(&l, &r)), false)); } let op: Option (i128, bool)> = match bin_op { - Div if r == 0 => return err!(DivisionByZero), - Rem if r == 0 => return err!(RemainderByZero), + Div if r == 0 => return err!(Panic(EvalErrorPanic::DivisionByZero)), + Rem if r == 0 => return err!(Panic(EvalErrorPanic::RemainderByZero)), Div => Some(i128::overflowing_div), Rem => Some(i128::overflowing_rem), Add => Some(i128::overflowing_add), @@ -231,8 +231,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Add => u128::overflowing_add, Sub => u128::overflowing_sub, Mul => u128::overflowing_mul, - Div if r == 0 => return err!(DivisionByZero), - Rem if r == 0 => return err!(RemainderByZero), + Div if r == 0 => return err!(Panic(EvalErrorPanic::DivisionByZero)), + Rem if r == 0 => return err!(Panic(EvalErrorPanic::RemainderByZero)), Div => u128::overflowing_div, Rem => u128::overflowing_rem, _ => bug!(), diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 68382071b4a67..9887095882faf 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -13,7 +13,7 @@ use rustc::ty::TypeFoldable; use super::{ GlobalId, AllocId, Allocation, Scalar, InterpResult, Pointer, PointerArithmetic, - InterpCx, Machine, AllocMap, AllocationExtra, + InterpCx, Machine, AllocMap, AllocationExtra, EvalErrorPanic, RawConst, Immediate, ImmTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind, LocalValue }; @@ -356,7 +356,7 @@ where // This can be violated because this runs during promotion on code where the // type system has not yet ensured that such things don't happen. debug!("tried to access element {} of array/slice with length {}", field, len); - return err!(BoundsCheck { len, index: field }); + return err!(Panic(EvalErrorPanic::BoundsCheck { len, index: field })); } stride * field } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 75690b4d361c6..ae1d8efa75349 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -7,7 +7,7 @@ use syntax::source_map::Span; use rustc_target::spec::abi::Abi; use super::{ - InterpResult, PointerArithmetic, InterpError, Scalar, + InterpResult, PointerArithmetic, InterpError, Scalar, EvalErrorPanic, InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal, }; @@ -137,19 +137,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Compute error message use rustc::mir::interpret::InterpError::*; return match *msg { - BoundsCheck { ref len, ref index } => { + Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { let len = self.read_immediate(self.eval_operand(len, None)?) .expect("can't eval len").to_scalar()? .to_bits(self.memory().pointer_size())? as u64; let index = self.read_immediate(self.eval_operand(index, None)?) .expect("can't eval index").to_scalar()? .to_bits(self.memory().pointer_size())? as u64; - err!(BoundsCheck { len, index }) + err!(Panic(EvalErrorPanic::BoundsCheck { len, index })) } - Overflow(op) => Err(Overflow(op).into()), - OverflowNeg => Err(OverflowNeg.into()), - DivisionByZero => Err(DivisionByZero.into()), - RemainderByZero => Err(RemainderByZero.into()), + Panic(EvalErrorPanic::Overflow(op)) => + Err(Panic(EvalErrorPanic::Overflow(op)).into()), + Panic(EvalErrorPanic::OverflowNeg) => + Err(Panic(EvalErrorPanic::OverflowNeg).into()), + Panic(EvalErrorPanic::DivisionByZero) => + Err(Panic(EvalErrorPanic::DivisionByZero).into()), + Panic(EvalErrorPanic::RemainderByZero) => + Err(Panic(EvalErrorPanic::RemainderByZero).into()), GeneratorResumedAfterReturn | GeneratorResumedAfterPanic => unimplemented!(), _ => bug!(), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 29480f88fcedc..9d9e47ecaf4e1 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -13,7 +13,7 @@ use rustc::mir::{ use rustc::mir::visit::{ Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext, }; -use rustc::mir::interpret::{InterpError, Scalar, GlobalId, InterpResult}; +use rustc::mir::interpret::{InterpError::Panic, Scalar, GlobalId, InterpResult, EvalErrorPanic}; use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; use syntax_pos::{Span, DUMMY_SP}; use rustc::ty::subst::InternalSubsts; @@ -339,12 +339,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // FIXME: implement => {}, - | Panic { .. } - | BoundsCheck{..} - | Overflow(_) - | OverflowNeg - | DivisionByZero - | RemainderByZero + | Panic(EvalErrorPanic::Panic { .. }) + | Panic(EvalErrorPanic::BoundsCheck{..}) + | Panic(EvalErrorPanic::Overflow(_)) + | Panic(EvalErrorPanic::OverflowNeg) + | Panic(EvalErrorPanic::DivisionByZero) + | Panic(EvalErrorPanic::RemainderByZero) => { diagnostic.report_as_lint( self.ecx.tcx, @@ -522,7 +522,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // Need to do overflow check here: For actual CTFE, MIR // generation emits code that does this before calling the op. if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) { - return err!(OverflowNeg); + return err!(Panic(EvalErrorPanic::OverflowNeg)); } } UnOp::Not => { @@ -600,7 +600,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) } else { if overflow { - let err = InterpError::Overflow(op).into(); + let err = Panic(EvalErrorPanic::Overflow(op)).into(); let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); return None; } @@ -839,11 +839,11 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { .expect("some part of a failing const eval must be local"); use rustc::mir::interpret::InterpError::*; let msg = match msg { - Overflow(_) | - OverflowNeg | - DivisionByZero | - RemainderByZero => msg.description().to_owned(), - BoundsCheck { ref len, ref index } => { + Panic(EvalErrorPanic::Overflow(_)) | + Panic(EvalErrorPanic::OverflowNeg) | + Panic(EvalErrorPanic::DivisionByZero) | + Panic(EvalErrorPanic::RemainderByZero) => msg.description().to_owned(), + Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { let len = self .eval_operand(len, source_info) .expect("len must be const"); From 3730ed9e5b50148d8fb83c4814a19a76ff30de38 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Tue, 23 Jul 2019 16:42:46 +0530 Subject: [PATCH 25/26] renames EvalErrorPanic to PanicMessage --- src/librustc/mir/interpret/error.rs | 34 +++++++++---------- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc/mir/interpret/pointer.rs | 6 ++-- src/librustc/mir/mod.rs | 8 ++--- src/librustc/mir/visit.rs | 2 +- src/librustc_codegen_ssa/mir/block.rs | 6 ++-- src/librustc_mir/borrow_check/mod.rs | 4 +-- .../borrow_check/nll/invalidation.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 4 +-- src/librustc_mir/build/expr/as_place.rs | 2 +- src/librustc_mir/build/expr/as_rvalue.rs | 10 +++--- src/librustc_mir/interpret/intrinsics.rs | 6 ++-- src/librustc_mir/interpret/operator.rs | 10 +++--- src/librustc_mir/interpret/place.rs | 4 +-- src/librustc_mir/interpret/terminator.rs | 22 ++++++------ src/librustc_mir/transform/const_prop.rs | 23 +++++-------- 16 files changed, 70 insertions(+), 75 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 41ec2029c816e..6ab07c9679e7a 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -229,7 +229,7 @@ impl<'tcx> From> for InterpErrorInfo<'tcx> { pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>; #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] -pub enum EvalErrorPanic { +pub enum PanicMessage { Panic { msg: Symbol, line: u32, @@ -311,7 +311,7 @@ pub enum InterpError<'tcx, O> { HeapAllocZeroBytes, HeapAllocNonPowerOfTwoAlignment(u64), Unreachable, - Panic(EvalErrorPanic), + Panic(PanicMessage), ReadFromReturnPointer, PathNotFound(Vec), UnimplementedTraitSelection, @@ -428,31 +428,31 @@ impl<'tcx, O> InterpError<'tcx, O> { two", Unreachable => "entered unreachable code", - Panic(EvalErrorPanic::Panic{..}) => + Panic(PanicMessage::Panic{..}) => "the evaluated program panicked", - Panic(EvalErrorPanic::BoundsCheck{..}) => + Panic(PanicMessage::BoundsCheck{..}) => "array index out of bounds", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Add)) => + Panic(PanicMessage::Overflow(mir::BinOp::Add)) => "attempt to add with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Sub)) => + Panic(PanicMessage::Overflow(mir::BinOp::Sub)) => "attempt to subtract with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Mul)) => + Panic(PanicMessage::Overflow(mir::BinOp::Mul)) => "attempt to multiply with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Div)) => + Panic(PanicMessage::Overflow(mir::BinOp::Div)) => "attempt to divide with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Rem)) => + Panic(PanicMessage::Overflow(mir::BinOp::Rem)) => "attempt to calculate the remainder with overflow", - Panic(EvalErrorPanic::OverflowNeg) => + Panic(PanicMessage::OverflowNeg) => "attempt to negate with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Shr)) => + Panic(PanicMessage::Overflow(mir::BinOp::Shr)) => "attempt to shift right with overflow", - Panic(EvalErrorPanic::Overflow(mir::BinOp::Shl)) => + Panic(PanicMessage::Overflow(mir::BinOp::Shl)) => "attempt to shift left with overflow", - Panic(EvalErrorPanic::Overflow(op)) => + Panic(PanicMessage::Overflow(op)) => bug!("{:?} cannot overflow", op), - Panic(EvalErrorPanic::DivisionByZero) => + Panic(PanicMessage::DivisionByZero) => "attempt to divide by zero", - Panic(EvalErrorPanic::RemainderByZero) => + Panic(PanicMessage::RemainderByZero) => "attempt to calculate the remainder with a divisor of zero", ReadFromReturnPointer => "tried to read from the return pointer", @@ -535,9 +535,9 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { write!(f, "incorrect alloc info: expected size {} and align {}, \ got size {} and align {}", size.bytes(), align.bytes(), size2.bytes(), align2.bytes()), - Panic(EvalErrorPanic::Panic { ref msg, line, col, ref file }) => + Panic(PanicMessage::Panic { ref msg, line, col, ref file }) => write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col), - Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => + Panic(PanicMessage::BoundsCheck { ref len, ref index }) => write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index), InvalidDiscriminant(val) => write!(f, "encountered invalid enum discriminant {}", val), diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 01bc27d55e580..5bec64d39fa62 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -12,7 +12,7 @@ mod pointer; pub use self::error::{ InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error, - FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, EvalErrorPanic + FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicMessage }; pub use self::value::{Scalar, ScalarMaybeUndef, RawConst, ConstValue}; diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index 814cd90343c8b..0e3b8459115e3 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -5,7 +5,7 @@ use crate::ty::layout::{self, HasDataLayout, Size}; use rustc_macros::HashStable; use super::{ - AllocId, InterpResult, EvalErrorPanic + AllocId, InterpResult, PanicMessage }; /// Used by `check_in_alloc` to indicate context of check @@ -76,13 +76,13 @@ pub trait PointerArithmetic: layout::HasDataLayout { #[inline] fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_offset(val, i); - if over { err!(Panic(EvalErrorPanic::Overflow(mir::BinOp::Add))) } else { Ok(res) } + if over { err!(Panic(PanicMessage::Overflow(mir::BinOp::Add))) } else { Ok(res) } } #[inline] fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_signed_offset(val, i128::from(i)); - if over { err!(Panic(EvalErrorPanic::Overflow(mir::BinOp::Add))) } else { Ok(res) } + if over { err!(Panic(PanicMessage::Overflow(mir::BinOp::Add))) } else { Ok(res) } } } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index ca1111d7fbf04..a2f6299450437 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -7,7 +7,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; use crate::hir::{self, InlineAsm as HirInlineAsm}; -use crate::mir::interpret::{ConstValue, EvalErrorPanic, InterpError::Panic, Scalar}; +use crate::mir::interpret::{ConstValue, PanicMessage, InterpError::Panic, Scalar}; use crate::mir::visit::MirVisitable; use crate::rustc_serialize as serialize; use crate::ty::adjustment::PointerCast; @@ -3087,8 +3087,8 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } } Assert { ref cond, expected, ref msg, target, cleanup } => { - let msg = if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { - Panic(EvalErrorPanic::BoundsCheck { + let msg = if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg { + Panic(PanicMessage::BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder), }) @@ -3132,7 +3132,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } Assert { ref cond, ref msg, .. } => { if cond.visit_with(visitor) { - if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { + if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg { len.visit_with(visitor) || index.visit_with(visitor) } else { false diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 54f987e2cf034..4b194c99a8ebf 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -514,7 +514,7 @@ macro_rules! make_mir_visitor { msg: & $($mutability)? AssertMessage<'tcx>, location: Location) { use crate::mir::interpret::InterpError::*; - use crate::mir::interpret::EvalErrorPanic::BoundsCheck; + use crate::mir::interpret::PanicMessage::BoundsCheck; if let Panic(BoundsCheck { len, index }) = msg { self.visit_operand(len, location); self.visit_operand(index, location); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index beb6b9421ce33..f6bc1b53ba5fd 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -2,7 +2,7 @@ use rustc::middle::lang_items; use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt}; use rustc::mir::{self, Place, PlaceBase, Static, StaticKind}; -use rustc::mir::interpret::{InterpError, EvalErrorPanic}; +use rustc::mir::interpret::{InterpError, PanicMessage}; use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; use rustc_target::spec::abi::Abi; use crate::base; @@ -368,7 +368,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // checked operation, just a comparison with the minimum // value, so we have to check for the assert message. if !bx.check_overflow() { - if let InterpError::Panic(EvalErrorPanic::OverflowNeg) = *msg { + if let InterpError::Panic(PanicMessage::OverflowNeg) = *msg { const_cond = Some(expected); } } @@ -403,7 +403,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Put together the arguments to the panic entry point. let (lang_item, args) = match *msg { - InterpError::Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { + InterpError::Panic(PanicMessage::BoundsCheck { ref len, ref index }) => { let len = self.codegen_operand(&mut bx, len).immediate(); let index = self.codegen_operand(&mut bx, index).immediate(); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 86f2c07e6b94f..09eb42ac0001d 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -734,8 +734,8 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx cleanup: _, } => { self.consume_operand(loc, (cond, span), flow_state); - use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic}; - if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { + use rustc::mir::interpret::{InterpError::Panic, PanicMessage}; + if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg { self.consume_operand(loc, (len, span), flow_state); self.consume_operand(loc, (index, span), flow_state); } diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index 51a00d2f0eb64..90df0c91c7235 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -207,7 +207,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { cleanup: _, } => { self.consume_operand(location, cond); - use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic::BoundsCheck}; + use rustc::mir::interpret::{InterpError::Panic, PanicMessage::BoundsCheck}; if let Panic(BoundsCheck { ref len, ref index }) = *msg { self.consume_operand(location, len); self.consume_operand(location, index); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 79020fdb4a5f3..8ff63e41700c8 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -28,7 +28,7 @@ use rustc::infer::canonical::QueryRegionConstraints; use rustc::infer::outlives::env::RegionBoundPairs; use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc::mir::interpret::{InterpError::Panic, ConstValue, EvalErrorPanic}; +use rustc::mir::interpret::{InterpError::Panic, ConstValue, PanicMessage}; use rustc::mir::tcx::PlaceTy; use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext}; use rustc::mir::*; @@ -1589,7 +1589,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } - if let Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) = *msg { + if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg { if len.ty(body, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index f342761e25de0..61c57f792c3ba 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -4,7 +4,7 @@ use crate::build::expr::category::Category; use crate::build::ForGuard::{OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; -use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic::BoundsCheck}; +use rustc::mir::interpret::{InterpError::Panic, PanicMessage::BoundsCheck}; use rustc::mir::*; use rustc::ty::{CanonicalUserTypeAnnotation, Variance}; diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 10bf48a85d098..377674600331a 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -7,7 +7,7 @@ use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; use rustc::middle::region; -use rustc::mir::interpret::{InterpError::Panic, EvalErrorPanic}; +use rustc::mir::interpret::{InterpError::Panic, PanicMessage}; use rustc::mir::*; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use syntax_pos::Span; @@ -101,7 +101,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, Operand::Move(is_min), false, - Panic(EvalErrorPanic::OverflowNeg), + Panic(PanicMessage::OverflowNeg), expr_span, ); } @@ -401,7 +401,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let val = result_value.clone().field(val_fld, ty); let of = result_value.field(of_fld, bool_ty); - let err = Panic(EvalErrorPanic::Overflow(op)); + let err = Panic(PanicMessage::Overflow(op)); block = self.assert(block, Operand::Move(of), false, err, span); @@ -412,9 +412,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // and 2. there are two possible failure cases, divide-by-zero and overflow. let (zero_err, overflow_err) = if op == BinOp::Div { - (Panic(EvalErrorPanic::DivisionByZero), Panic(EvalErrorPanic::Overflow(op))) + (Panic(PanicMessage::DivisionByZero), Panic(PanicMessage::Overflow(op))) } else { - (Panic(EvalErrorPanic::RemainderByZero), Panic(EvalErrorPanic::Overflow(op))) + (Panic(PanicMessage::RemainderByZero), Panic(PanicMessage::Overflow(op))) }; // Check for / 0 diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 5b80d0e251e4b..6623661f938fe 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -7,7 +7,7 @@ use rustc::ty; use rustc::ty::layout::{LayoutOf, Primitive, Size}; use rustc::mir::BinOp; use rustc::mir::interpret::{ - InterpResult, InterpError, Scalar, EvalErrorPanic, + InterpResult, InterpError, Scalar, PanicMessage, }; use super::{ @@ -261,7 +261,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); + return Err(InterpError::Panic(PanicMessage::Panic { msg, file, line, col }).into()); } else if Some(def_id) == self.tcx.lang_items().begin_panic_fn() { assert!(args.len() == 2); // &'static str, &(&'static str, u32, u32) @@ -279,7 +279,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); + return Err(InterpError::Panic(PanicMessage::Panic { msg, file, line, col }).into()); } else { return Ok(false); } diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 0932b468a502a..b4edee72a4d19 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -2,7 +2,7 @@ use rustc::mir; use rustc::ty::{self, layout::TyLayout}; use syntax::ast::FloatTy; use rustc_apfloat::Float; -use rustc::mir::interpret::{InterpResult, EvalErrorPanic, Scalar}; +use rustc::mir::interpret::{InterpResult, PanicMessage, Scalar}; use super::{InterpCx, PlaceTy, Immediate, Machine, ImmTy}; @@ -173,8 +173,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return Ok((Scalar::from_bool(op(&l, &r)), false)); } let op: Option (i128, bool)> = match bin_op { - Div if r == 0 => return err!(Panic(EvalErrorPanic::DivisionByZero)), - Rem if r == 0 => return err!(Panic(EvalErrorPanic::RemainderByZero)), + Div if r == 0 => return err!(Panic(PanicMessage::DivisionByZero)), + Rem if r == 0 => return err!(Panic(PanicMessage::RemainderByZero)), Div => Some(i128::overflowing_div), Rem => Some(i128::overflowing_rem), Add => Some(i128::overflowing_add), @@ -231,8 +231,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Add => u128::overflowing_add, Sub => u128::overflowing_sub, Mul => u128::overflowing_mul, - Div if r == 0 => return err!(Panic(EvalErrorPanic::DivisionByZero)), - Rem if r == 0 => return err!(Panic(EvalErrorPanic::RemainderByZero)), + Div if r == 0 => return err!(Panic(PanicMessage::DivisionByZero)), + Rem if r == 0 => return err!(Panic(PanicMessage::RemainderByZero)), Div => u128::overflowing_div, Rem => u128::overflowing_rem, _ => bug!(), diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 9887095882faf..8fe882934dfb5 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -13,7 +13,7 @@ use rustc::ty::TypeFoldable; use super::{ GlobalId, AllocId, Allocation, Scalar, InterpResult, Pointer, PointerArithmetic, - InterpCx, Machine, AllocMap, AllocationExtra, EvalErrorPanic, + InterpCx, Machine, AllocMap, AllocationExtra, PanicMessage, RawConst, Immediate, ImmTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind, LocalValue }; @@ -356,7 +356,7 @@ where // This can be violated because this runs during promotion on code where the // type system has not yet ensured that such things don't happen. debug!("tried to access element {} of array/slice with length {}", field, len); - return err!(Panic(EvalErrorPanic::BoundsCheck { len, index: field })); + return err!(Panic(PanicMessage::BoundsCheck { len, index: field })); } stride * field } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index ae1d8efa75349..a85b77c7b8143 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -7,7 +7,7 @@ use syntax::source_map::Span; use rustc_target::spec::abi::Abi; use super::{ - InterpResult, PointerArithmetic, InterpError, Scalar, EvalErrorPanic, + InterpResult, PointerArithmetic, InterpError, Scalar, PanicMessage, InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal, }; @@ -137,23 +137,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Compute error message use rustc::mir::interpret::InterpError::*; return match *msg { - Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { + Panic(PanicMessage::BoundsCheck { ref len, ref index }) => { let len = self.read_immediate(self.eval_operand(len, None)?) .expect("can't eval len").to_scalar()? .to_bits(self.memory().pointer_size())? as u64; let index = self.read_immediate(self.eval_operand(index, None)?) .expect("can't eval index").to_scalar()? .to_bits(self.memory().pointer_size())? as u64; - err!(Panic(EvalErrorPanic::BoundsCheck { len, index })) + err!(Panic(PanicMessage::BoundsCheck { len, index })) } - Panic(EvalErrorPanic::Overflow(op)) => - Err(Panic(EvalErrorPanic::Overflow(op)).into()), - Panic(EvalErrorPanic::OverflowNeg) => - Err(Panic(EvalErrorPanic::OverflowNeg).into()), - Panic(EvalErrorPanic::DivisionByZero) => - Err(Panic(EvalErrorPanic::DivisionByZero).into()), - Panic(EvalErrorPanic::RemainderByZero) => - Err(Panic(EvalErrorPanic::RemainderByZero).into()), + Panic(PanicMessage::Overflow(op)) => + Err(Panic(PanicMessage::Overflow(op)).into()), + Panic(PanicMessage::OverflowNeg) => + Err(Panic(PanicMessage::OverflowNeg).into()), + Panic(PanicMessage::DivisionByZero) => + Err(Panic(PanicMessage::DivisionByZero).into()), + Panic(PanicMessage::RemainderByZero) => + Err(Panic(PanicMessage::RemainderByZero).into()), GeneratorResumedAfterReturn | GeneratorResumedAfterPanic => unimplemented!(), _ => bug!(), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 9d9e47ecaf4e1..1c4cc02ce01cf 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -13,7 +13,7 @@ use rustc::mir::{ use rustc::mir::visit::{ Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext, }; -use rustc::mir::interpret::{InterpError::Panic, Scalar, GlobalId, InterpResult, EvalErrorPanic}; +use rustc::mir::interpret::{InterpError::Panic, Scalar, GlobalId, InterpResult, PanicMessage}; use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; use syntax_pos::{Span, DUMMY_SP}; use rustc::ty::subst::InternalSubsts; @@ -339,12 +339,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // FIXME: implement => {}, - | Panic(EvalErrorPanic::Panic { .. }) - | Panic(EvalErrorPanic::BoundsCheck{..}) - | Panic(EvalErrorPanic::Overflow(_)) - | Panic(EvalErrorPanic::OverflowNeg) - | Panic(EvalErrorPanic::DivisionByZero) - | Panic(EvalErrorPanic::RemainderByZero) + | Panic(_) => { diagnostic.report_as_lint( self.ecx.tcx, @@ -522,7 +517,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // Need to do overflow check here: For actual CTFE, MIR // generation emits code that does this before calling the op. if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) { - return err!(Panic(EvalErrorPanic::OverflowNeg)); + return err!(Panic(PanicMessage::OverflowNeg)); } } UnOp::Not => { @@ -600,7 +595,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) } else { if overflow { - let err = Panic(EvalErrorPanic::Overflow(op)).into(); + let err = Panic(PanicMessage::Overflow(op)).into(); let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); return None; } @@ -839,11 +834,11 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { .expect("some part of a failing const eval must be local"); use rustc::mir::interpret::InterpError::*; let msg = match msg { - Panic(EvalErrorPanic::Overflow(_)) | - Panic(EvalErrorPanic::OverflowNeg) | - Panic(EvalErrorPanic::DivisionByZero) | - Panic(EvalErrorPanic::RemainderByZero) => msg.description().to_owned(), - Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) => { + Panic(PanicMessage::Overflow(_)) | + Panic(PanicMessage::OverflowNeg) | + Panic(PanicMessage::DivisionByZero) | + Panic(PanicMessage::RemainderByZero) => msg.description().to_owned(), + Panic(PanicMessage::BoundsCheck { ref len, ref index }) => { let len = self .eval_operand(len, source_info) .expect("len must be const"); From f48ee09f040cecf5b11641f7548fcda34fb77ca9 Mon Sep 17 00:00:00 2001 From: git-iso <46284404+git-iso@users.noreply.github.com> Date: Tue, 23 Jul 2019 11:07:06 -0400 Subject: [PATCH 26/26] Update stage0.txt Fix columns. --- src/stage0.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stage0.txt b/src/stage0.txt index d548f6c06f406..14d65bef8f6dd 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -25,9 +25,9 @@ cargo: beta # # This means that there's a small window of time (a few days) where artifacts # are downloaded from dev-static.rust-lang.org instead of static.rust-lang.org. -# In order to ease this transition we have an extra key which is in the configuration -# file below. When uncommented this will instruct the bootstrap.py script to -# download from dev-static.rust-lang.org. +# In order to ease this transition we have an extra key which is in the +# configuration file below. When uncommented this will instruct the bootstrap.py +# script to download from dev-static.rust-lang.org. # # This key is typically commented out at all times. If you're looking at a # stable release tarball it should *definitely* be commented out. If you're