From 4b277c5f5b46c30ccc7e2b9a2300ce19d77bc646 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 30 Jul 2020 16:04:47 -0400 Subject: [PATCH 1/5] Revert "delay_span_bug instead of silent ignore" This reverts commit d01e1093baf4d5ebe08a067a2a8e720e7fa7eb22. --- src/librustc_resolve/late.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 9577a21c743c9..2d282c7464ead 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1415,22 +1415,16 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { match pat.kind { // In tuple struct patterns ignore the invalid `ident @ ...`. // It will be handled as an error by the AST lowering. - PatKind::Ident(bmode, ident, ref sub) => { - if is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some() { - self.r - .session - .delay_span_bug(ident.span, "ident in tuple pattern is invalid"); - } else { - // First try to resolve the identifier as some existing entity, - // then fall back to a fresh binding. - let has_sub = sub.is_some(); - let res = self - .try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub) - .unwrap_or_else(|| { - self.fresh_binding(ident, pat.id, pat_src, bindings) - }); - self.r.record_partial_res(pat.id, PartialRes::new(res)); - } + PatKind::Ident(bmode, ident, ref sub) + if !(is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some()) => + { + // First try to resolve the identifier as some existing entity, + // then fall back to a fresh binding. + let has_sub = sub.is_some(); + let res = self + .try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub) + .unwrap_or_else(|| self.fresh_binding(ident, pat.id, pat_src, bindings)); + self.r.record_partial_res(pat.id, PartialRes::new(res)); } PatKind::TupleStruct(ref path, ..) => { self.smart_resolve_path(pat.id, None, path, PathSource::TupleStruct); From a13f5b1492fe9860d20a075f08942d55e8ed417e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 30 Jul 2020 16:04:53 -0400 Subject: [PATCH 2/5] Revert "Fix an ICE on an invalid `binding @ ...` in a tuple struct pattern" This reverts commit 174b58287c66a6ad3eaa1897279d769611919960. --- src/librustc_resolve/late.rs | 8 +------- src/test/ui/issues/issue-74539.rs | 12 ------------ src/test/ui/issues/issue-74539.stderr | 21 --------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 src/test/ui/issues/issue-74539.rs delete mode 100644 src/test/ui/issues/issue-74539.stderr diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 2d282c7464ead..3b49b3b6ff7d2 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1407,17 +1407,11 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { pat_src: PatternSource, bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet); 1]>, ) { - let is_tuple_struct_pat = matches!(pat.kind, PatKind::TupleStruct(_, _)); - // Visit all direct subpatterns of this pattern. pat.walk(&mut |pat| { debug!("resolve_pattern pat={:?} node={:?}", pat, pat.kind); match pat.kind { - // In tuple struct patterns ignore the invalid `ident @ ...`. - // It will be handled as an error by the AST lowering. - PatKind::Ident(bmode, ident, ref sub) - if !(is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some()) => - { + PatKind::Ident(bmode, ident, ref sub) => { // First try to resolve the identifier as some existing entity, // then fall back to a fresh binding. let has_sub = sub.is_some(); diff --git a/src/test/ui/issues/issue-74539.rs b/src/test/ui/issues/issue-74539.rs deleted file mode 100644 index 75632d11c1df0..0000000000000 --- a/src/test/ui/issues/issue-74539.rs +++ /dev/null @@ -1,12 +0,0 @@ -enum E { - A(u8, u8), -} - -fn main() { - let e = E::A(2, 3); - match e { - E::A(x @ ..) => { //~ ERROR `x @` is not allowed in a tuple - x //~ ERROR cannot find value `x` in this scope - } - }; -} diff --git a/src/test/ui/issues/issue-74539.stderr b/src/test/ui/issues/issue-74539.stderr deleted file mode 100644 index 94526dcd7cb39..0000000000000 --- a/src/test/ui/issues/issue-74539.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0425]: cannot find value `x` in this scope - --> $DIR/issue-74539.rs:9:13 - | -LL | x - | ^ help: a local variable with a similar name exists: `e` - -error: `x @` is not allowed in a tuple struct - --> $DIR/issue-74539.rs:8:14 - | -LL | E::A(x @ ..) => { - | ^^^^^^ this is only allowed in slice patterns - | - = help: remove this and bind each tuple field independently -help: if you don't need to use the contents of x, discard the tuple's remaining fields - | -LL | E::A(..) => { - | ^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0425`. From 2098b6e98530fac543ea25f5c6a048b9cc14a159 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 30 Jul 2020 16:12:02 -0400 Subject: [PATCH 3/5] 1.45.2 release notes --- RELEASES.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 204741bec5a8f..8657cd2ab656a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,12 @@ +Version 1.45.2 (2020-08-03) +========================== + +* [Fix bindings in tuple struct patterns][74954] +* [Fix track_caller integration with trait objects][74784] + +[74954]: https://github.com/rust-lang/rust/issues/74954 +[74784]: https://github.com/rust-lang/rust/issues/74784 + Version 1.45.1 (2020-07-30) ========================== From c774981577f78f6422acd579ef865a3c06be5f25 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 30 Jul 2020 16:12:13 -0400 Subject: [PATCH 4/5] Add a test for pattern matching within a tuple --- src/test/ui/issues/issue-74954.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/test/ui/issues/issue-74954.rs diff --git a/src/test/ui/issues/issue-74954.rs b/src/test/ui/issues/issue-74954.rs new file mode 100644 index 0000000000000..269ec3c7abe93 --- /dev/null +++ b/src/test/ui/issues/issue-74954.rs @@ -0,0 +1,7 @@ +// check-pass + +fn main() { + if let Some([b'@', filename @ ..]) = Some(b"@abc123") { + println!("filename {:?}", filename); + } +} From fcd1712627e21618228057396d3b62e039c21544 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Sun, 26 Jul 2020 09:53:24 -0700 Subject: [PATCH 5/5] Fix #[track_caller] shims for trait objects. We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable. Closes #74764. --- src/librustc_middle/ty/instance.rs | 2 +- .../tracked-trait-obj.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 1ce079821a22e..b3083fa3b37c2 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -345,7 +345,7 @@ impl<'tcx> Instance<'tcx> { debug!(" => associated item with unsizeable self: Self"); Some(Instance { def: InstanceDef::VtableShim(def_id), substs }) } else { - Instance::resolve(tcx, param_env, def_id, substs).ok().flatten() + Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs) } } diff --git a/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs b/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs new file mode 100644 index 0000000000000..e41b1d2dd4830 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs @@ -0,0 +1,25 @@ +// run-pass + +#![feature(track_caller)] + +trait Tracked { + #[track_caller] + fn handle(&self) { + let location = std::panic::Location::caller(); + assert_eq!(location.file(), file!()); + // we only call this via trait object, so the def site should *always* be returned + assert_eq!(location.line(), line!() - 4); + assert_eq!(location.column(), 5); + } +} + +impl Tracked for () {} +impl Tracked for u8 {} + +fn main() { + let tracked: &dyn Tracked = &5u8; + tracked.handle(); + + const TRACKED: &dyn Tracked = &(); + TRACKED.handle(); +}