Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeck: suggest use of match_default_bindings feature #45409

Merged
merged 1 commit into from Nov 2, 2017

Conversation

Projects
None yet
5 participants
@tamird
Copy link
Contributor

tamird commented Oct 20, 2017

Fixes #45383.
Updates #42640.

r? @nikomatsakis
cc @tschottdorf

This needs a UI test, but thought I'd get some early feedback.

@tamird tamird force-pushed the tamird:suggest-match-default-bindings branch 2 times, most recently from 264265f to bca2201 Oct 20, 2017

@tamird

This comment has been minimized.

Copy link
Contributor Author

tamird commented Oct 20, 2017

OK, this should be in a reasonable state now - I had to do some additional juggling to prevent halfway-massaging in the case of the feature not being enabled.

@tamird tamird force-pushed the tamird:suggest-match-default-bindings branch 3 times, most recently from a3dbc28 to 570f476 Oct 20, 2017

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

Looks great. I left one suggestion -- let me know what you think.

err.span_suggestion(pat.span, "consider using", format!("&{}", &snippet));
}
err.emit();
None

This comment has been minimized.

@nikomatsakis

nikomatsakis Oct 23, 2017

Contributor

Hmm, it seems like it may be better to just update expected and def_bm either way -- i.e., if the feature gate is not enabled, we type-check as if it were, but issue an error. It'd certainly be less complicated, but it would also suppress the "duplicate-ish" errors we see below (e.g., mismatched types).

This comment has been minimized.

@tamird

tamird Oct 26, 2017

Author Contributor

That's what I did initially. Added a commit that reverts to that so you can see the resulting UI test behaviour.

@@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let false = "foo"; //~ error: mismatched types
let false = "foo";

This comment has been minimized.

@nikomatsakis

nikomatsakis Oct 23, 2017

Contributor

let's change this test from "foo" to 22 -- I feel like the message about non-reference patterns isn't central to the test.

This comment has been minimized.

@tamird

tamird Oct 26, 2017

Author Contributor

Done.

@@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let Self = "foo"; //~ ERROR cannot find unit struct/variant or constant `Self` in this scope
let Self = "foo";

This comment has been minimized.

@nikomatsakis

nikomatsakis Oct 23, 2017

Contributor

let's change this test from "foo" to 22 -- I feel like the message about non-reference patterns isn't central to the test.

This comment has been minimized.

@tamird

tamird Oct 26, 2017

Author Contributor

Done.

@@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let super = "foo"; //~ ERROR failed to resolve. There are too many initial `super`s
let super = "foo";

This comment has been minimized.

@nikomatsakis

nikomatsakis Oct 23, 2017

Contributor

let's change this test from "foo" to 22 -- I feel like the message about non-reference patterns isn't central to the test.

This comment has been minimized.

@tamird

tamird Oct 26, 2017

Author Contributor

Done.

@@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let true = "foo"; //~ error: mismatched types
let true = "foo";

This comment has been minimized.

@nikomatsakis

nikomatsakis Oct 23, 2017

Contributor

let's change this test from "foo" to 22 -- I feel like the message about non-reference patterns isn't central to the test.

This comment has been minimized.

@tamird

tamird Oct 26, 2017

Author Contributor

Done.

@tamird tamird force-pushed the tamird:suggest-match-default-bindings branch from 570f476 to bd5a587 Oct 26, 2017

@tamird

This comment has been minimized.

Copy link
Contributor Author

tamird commented Oct 26, 2017

@kennytm should be waiting-on-review again.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 30, 2017

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 30, 2017

📌 Commit bd5a587 has been approved by nikomatsakis

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 30, 2017

@tamird sorry for the delay; I was at the Rust Belt Rust conference. Looks good, thanks!

@tamird

This comment has been minimized.

Copy link
Contributor Author

tamird commented Oct 30, 2017

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Oct 30, 2017

@bors r-

(Waiting on author to cleanup.)

@tamird tamird force-pushed the tamird:suggest-match-default-bindings branch from bd5a587 to 9844777 Oct 30, 2017

@tamird

This comment has been minimized.

Copy link
Contributor Author

tamird commented Oct 30, 2017

OK, should be good to go, unless y'all have tweaks for the message.

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Oct 31, 2017

@bors r=nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 31, 2017

📌 Commit 9844777 has been approved by nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 31, 2017

⌛️ Testing commit 9844777 with merge 772b3b7...

bors added a commit that referenced this pull request Oct 31, 2017

Auto merge of #45409 - tamird:suggest-match-default-bindings, r=nikom…
…atsakis

typeck: suggest use of match_default_bindings feature

Fixes #45383.
Updates #42640.

r? @nikomatsakis
cc @tschottdorf

This needs a UI test, but thought I'd get some early feedback.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 31, 2017

💔 Test failed - status-travis

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Oct 31, 2017

@bors retry #45230 LLDB segfault at check x86_64-apple-darwin

[01:34:24] ---- [debuginfo-lldb] debuginfo/associated-types.rs stdout ----
[01:34:24] 	NOTE: compiletest thinks it is using LLDB version 370
[01:34:24] 
[01:34:24] error: Error while running LLDB
[01:34:24] status: signal: 11
[01:34:24] command: "/usr/bin/python" "/Users/travis/build/rust-lang/rust/src/etc/lldb_batchmode.py" "/Users/travis/build/rust-lang/rust/build/x86_64-apple-darwin/test/debuginfo/associated-types.stage2-x86_64-apple-darwin" "/Users/travis/build/rust-lang/rust/build/x86_64-apple-darwin/test/debuginfo/associated-types.debugger.script"
[01:34:24] stdout:
[01:34:24] ------------------------------------------
[01:34:24] LLDB batch-mode script
[01:34:24] ----------------------
[01:34:24] Debugger commands script is '/Users/travis/build/rust-lang/rust/build/x86_64-apple-darwin/test/debuginfo/associated-types.debugger.script'.
[01:34:24] Target executable is '/Users/travis/build/rust-lang/rust/build/x86_64-apple-darwin/test/debuginfo/associated-types.stage2-x86_64-apple-darwin'.
[01:34:24] Current working directory is '/Users/travis/build/rust-lang/rust'
[01:34:24] Creating a target for '/Users/travis/build/rust-lang/rust/build/x86_64-apple-darwin/test/debuginfo/associated-types.stage2-x86_64-apple-darwin'
[01:34:24] settings set auto-confirm true
[01:34:24] 
[01:34:24] version
[01:34:24] lldb-370.0.42 Swift-3.1 
[01:34:24] command script import /Users/travis/build/rust-lang/rust/./src/etc/lldb_rust_formatters.py
[01:34:24] type summary add --no-value --python-function lldb_rust_formatters.print_val -x ".*" --category Rust
[01:34:24] type category enable Rust
[01:34:24] 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 110
[01:34:24] Breakpoint 1: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_struct<i32> + 4 at associated-types.rs:110, address = 0x0000000100000764 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 117
[01:34:24] Breakpoint 2: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_local<i32> + 74 at associated-types.rs:117, address = 0x00000001000007fa 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 121
[01:34:24] Breakpoint 3: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_arg<i32> + 12 at associated-types.rs:121, address = 0x000000010000084c 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 129
[01:34:24] Breakpoint 4: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_tuple<i32> + 4 at associated-types.rs:129, address = 0x00000001000008d4 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 136
[01:34:24] Breakpoint 5: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_enum<i32> + 102 at associated-types.rs:136, address = 0x0000000100000976 
[01:34:24] breakpoint set --file 'associated-types.rs' --line 139
[01:34:24] Breakpoint 6: where = associated-types.stage2-x86_64-apple-darwin`associated_types::assoc_enum<i32> + 143 at associated-types.rs:139, address = 0x000000010000099f 
[01:34:24] quit
[01:34:24] 
[01:34:24] 
[01:34:24] ------------------------------------------
[01:34:24] stderr:
[01:34:24] ------------------------------------------
[01:34:24] 
[01:34:24] ------------------------------------------
[01:34:24] 
[01:34:24] thread '[debuginfo-lldb] debuginfo/associated-types.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:2485:8
[01:34:24] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:34:24] 
[01:34:24] 
[01:34:24] failures:
[01:34:24]     [debuginfo-lldb] debuginfo/associated-types.rs
[01:34:24] 
[01:34:24] test result: �[31mFAILED�(B�[m. 97 passed; 1 failed; 10 ignored; 0 measured; 0 filtered out
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 31, 2017

⌛️ Testing commit 9844777 with merge a274ae0...

bors added a commit that referenced this pull request Oct 31, 2017

Auto merge of #45409 - tamird:suggest-match-default-bindings, r=nikom…
…atsakis

typeck: suggest use of match_default_bindings feature

Fixes #45383.
Updates #42640.

r? @nikomatsakis
cc @tschottdorf

This needs a UI test, but thought I'd get some early feedback.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 31, 2017

💔 Test failed - status-appveyor

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Oct 31, 2017

test [run-pass] run-pass\rustc-rust-log.rs has been running for over 60 seconds
fatal runtime error: allocator memory exhausted

Looks like this test generated so much log output that it caused compiletest, which was collecting output, to OOM.

Unsure if it's caused by this PR (in that maybe it increased the amount of logging?) but it also seems like we may just need to remove the test...

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Oct 31, 2017

check i686-pc-windows-msvc runs out of memory?

@bors retry

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Oct 31, 2017

@kennytm we may want to watch this test though, I suspect this won't be the first time we see this error. Also the test ran for at least a minute which is a bit much

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Oct 31, 2017

@alexcrichton Sorry did not see your reply when commenting. @bors r-

This test case has failed before, e.g. #44142 (comment) which was legit. Probably this diff caused a lot more logs to appear and failing the test case?

diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index ab8994bcae25..e25f7d796689 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -68,7 +69,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
             PatKind::Binding(..) |
             PatKind::Ref(..) => false,
         };
-        if is_non_ref_pat && tcx.sess.features.borrow().match_default_bindings {
+        if is_non_ref_pat {
             debug!("pattern is non reference pattern");
             let mut exp_ty = self.resolve_type_vars_with_obligations(&expected);
@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Nov 1, 2017

@kennytm I cannot imagine how this change would affect that particular test -- it compiles an empty file, so I don't think that this code will trigger at all.

I do think the test is useful, but I wonder if we should consider e.g. directing the log output into /dev/null or something so as not to overwhelm compile-test. This could be a compiletest flag, or perhaps we can modify the test to invoke rustc as a subprocess or something.

Regardless, I'm inclined to r+ again because I don't think the problem is related to this patch per se. But I'll try to run a local test to verify.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Nov 2, 2017

Before:

lunch-box. RUST_LOG=debug /usr/bin/time -o killme.master rustc rustc-rust-log.rs 2>&1 | wc -c
606664960
lunch-box. cat killme.master
17.36user 8.18system 0:25.55elapsed 99%CPU (0avgtext+0avgdata 107360maxresident)k
32inputs+8488outputs (4major+20279minor)pagefaults 0swaps

With this branch:

lunch-box. RUST_LOG=debug /usr/bin/time -o killme rustc rustc-rust-log.rs 2>&1 | wc -c
606664960
lunch-box. cat killme
22.50user 8.48system 0:31.05elapsed 99%CPU (0avgtext+0avgdata 108668maxresident)k
0inputs+8488outputs (0major+20557minor)pagefaults 0swaps

No real difference. This branch for some reason took an extra few seconds, but it's probably because I was compiling other working directories at the same time or something.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Nov 2, 2017

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 2, 2017

📌 Commit 9844777 has been approved by nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 2, 2017

⌛️ Testing commit 9844777 with merge e340996...

bors added a commit that referenced this pull request Nov 2, 2017

Auto merge of #45409 - tamird:suggest-match-default-bindings, r=nikom…
…atsakis

typeck: suggest use of match_default_bindings feature

Fixes #45383.
Updates #42640.

r? @nikomatsakis
cc @tschottdorf

This needs a UI test, but thought I'd get some early feedback.
@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Nov 2, 2017

AppVeyor passed 😕 I'm going to record that as a spurious error.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing e340996 to master...

@bors bors merged commit 9844777 into rust-lang:master Nov 2, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@tamird tamird deleted the tamird:suggest-match-default-bindings branch Nov 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.