From 1c30c9e92bdae1814dbae9367f214b4819cdd0de Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 26 May 2020 14:26:11 -0400 Subject: Don't bail out of trait selection when predicate references an error Fixes #72590 With PR #70551, observing a `ty::Error` guarantees that compilation is going to fail. Therefore, there are no soundness impliciations to continuing on when we encounter a `ty::Error` - we can only affect whether or not additional error messags are emitted. By not bailing out, we avoid incorrectly determining that types are `!Sized` when a type error is present, which allows us to avoid emitting additional spurious error messages. The original comment mentioned this code being shared by coherence - howver, this change resulted in no diagnostic changes in any of the existing tests. --- .../ui/async-await/issue-72590-type-error-sized.rs | 22 +++++++++++++++++ .../issue-72590-type-error-sized.stderr | 28 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/ui/async-await/issue-72590-type-error-sized.rs create mode 100644 src/test/ui/async-await/issue-72590-type-error-sized.stderr (limited to 'src/test') diff --git a/src/test/ui/async-await/issue-72590-type-error-sized.rs b/src/test/ui/async-await/issue-72590-type-error-sized.rs new file mode 100644 index 00000000000..00e098d43e0 --- /dev/null +++ b/src/test/ui/async-await/issue-72590-type-error-sized.rs @@ -0,0 +1,22 @@ +// Regression test for issue #72590 +// Tests that we don't emit a spurious "size cannot be statically determined" error +// edition:2018 + +struct Foo { + foo: Nonexistent, //~ ERROR cannot find + other: str +} + +struct Bar { + test: Missing //~ ERROR cannot find +} + +impl Foo { + async fn frob(self) {} //~ ERROR the size +} + +impl Bar { + async fn myfn(self) {} +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-72590-type-error-sized.stderr b/src/test/ui/async-await/issue-72590-type-error-sized.stderr new file mode 100644 index 00000000000..603895b598c --- /dev/null +++ b/src/test/ui/async-await/issue-72590-type-error-sized.stderr @@ -0,0 +1,28 @@ +error[E0412]: cannot find type `Nonexistent` in this scope + --> $DIR/issue-72590-type-error-sized.rs:6:10 + | +LL | foo: Nonexistent, + | ^^^^^^^^^^^ not found in this scope + +error[E0412]: cannot find type `Missing` in this scope + --> $DIR/issue-72590-type-error-sized.rs:11:11 + | +LL | test: Missing + | ^^^^^^^ not found in this scope + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/issue-72590-type-error-sized.rs:15:19 + | +LL | async fn frob(self) {} + | ^^^^ doesn't have a size known at compile-time + | + = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `str` + = note: to learn more, visit + = note: required because it appears within the type `Foo` + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0412. +For more information about an error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From ce81d15289867f7ec0bba959712d100d3ff6a653 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Thu, 28 May 2020 14:40:07 -0700 Subject: Add test to make sure -Wunused-crate-dependencies works with tests Make sure code in `#[test]` blocks counts as a use of a crate. --- src/test/ui/unused-crate-deps/test-use-ok.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/ui/unused-crate-deps/test-use-ok.rs (limited to 'src/test') diff --git a/src/test/ui/unused-crate-deps/test-use-ok.rs b/src/test/ui/unused-crate-deps/test-use-ok.rs new file mode 100644 index 00000000000..66d6440c9cb --- /dev/null +++ b/src/test/ui/unused-crate-deps/test-use-ok.rs @@ -0,0 +1,15 @@ +// Test-only use OK + +// edition:2018 +// check-pass +// aux-crate:bar=bar.rs +// compile-flags:--test + +#![deny(unused_crate_dependencies)] + +fn main() {} + +#[test] +fn test_bar() { + assert_eq!(bar::BAR, "bar"); +} -- cgit 1.4.1-3-g733a5 From 02cc593af04a4f8c338baa1f51c9a4c9c005d729 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Fri, 29 May 2020 00:00:00 +0000 Subject: Remove unused mut from long-linker-command-lines test --- src/test/run-make-fulldeps/long-linker-command-lines/foo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/run-make-fulldeps/long-linker-command-lines/foo.rs b/src/test/run-make-fulldeps/long-linker-command-lines/foo.rs index 96fb16b1fcc..f313798de21 100644 --- a/src/test/run-make-fulldeps/long-linker-command-lines/foo.rs +++ b/src/test/run-make-fulldeps/long-linker-command-lines/foo.rs @@ -90,7 +90,7 @@ fn main() { } let linker_args = read_linker_args(&ok); - for mut arg in linker_args.split('S') { + for arg in linker_args.split('S') { expected_libs.remove(arg); } -- cgit 1.4.1-3-g733a5 From 4d4facbe4f0290c511c21167e48074786ad75efd Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 29 May 2020 00:19:08 -0400 Subject: Revert "Add test for macro_rules! invoking a proc-macro with capture groups" This reverts commit 30c00fd26a24f349df64a7c0f5c3490e9f624322. --- src/test/ui/proc-macro/macro-rules-capture.rs | 18 ------------------ src/test/ui/proc-macro/macro-rules-capture.stderr | 12 ------------ 2 files changed, 30 deletions(-) delete mode 100644 src/test/ui/proc-macro/macro-rules-capture.rs delete mode 100644 src/test/ui/proc-macro/macro-rules-capture.stderr (limited to 'src/test') diff --git a/src/test/ui/proc-macro/macro-rules-capture.rs b/src/test/ui/proc-macro/macro-rules-capture.rs deleted file mode 100644 index 37436567d70..00000000000 --- a/src/test/ui/proc-macro/macro-rules-capture.rs +++ /dev/null @@ -1,18 +0,0 @@ -// aux-build: test-macros.rs - -extern crate test_macros; -use test_macros::recollect_attr; - -macro_rules! reemit { - ($name:ident => $($token:expr)*) => { - - #[recollect_attr] - pub fn $name() { - $($token)*; - } - } -} - -reemit! { foo => 45u32.into() } //~ ERROR type annotations - -fn main() {} diff --git a/src/test/ui/proc-macro/macro-rules-capture.stderr b/src/test/ui/proc-macro/macro-rules-capture.stderr deleted file mode 100644 index 6d512846ff7..00000000000 --- a/src/test/ui/proc-macro/macro-rules-capture.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/macro-rules-capture.rs:16:24 - | -LL | reemit! { foo => 45u32.into() } - | ------^^^^-- - | | | - | | cannot infer type for type parameter `T` declared on the trait `Into` - | this method call resolves to `T` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0282`. -- cgit 1.4.1-3-g733a5 From 27ed143ba9bb96e907f56c9f294c904a2cb26123 Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Fri, 29 May 2020 16:03:46 -0400 Subject: fix diagnostics for `@ ..` binding pattern in tuples and tuple structs fix comment add newline for tidy fmt error... edit suggestion message change the suggestion message to better handle cases with binding modes Apply suggestions from estebank code review Co-authored-by: Esteban Kuber edits to address source review Apply suggestions from estebank code review #2 Co-authored-by: Esteban Kuber update test files --- src/librustc_ast_lowering/pat.rs | 33 ++++++++++++++++++++++++++++++--- src/test/ui/issues/issue-72574-1.rs | 8 ++++++++ src/test/ui/issues/issue-72574-1.stderr | 14 ++++++++++++++ src/test/ui/issues/issue-72574-2.rs | 10 ++++++++++ src/test/ui/issues/issue-72574-2.stderr | 14 ++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/issues/issue-72574-1.rs create mode 100644 src/test/ui/issues/issue-72574-1.stderr create mode 100644 src/test/ui/issues/issue-72574-2.rs create mode 100644 src/test/ui/issues/issue-72574-2.stderr (limited to 'src/test') diff --git a/src/librustc_ast_lowering/pat.rs b/src/librustc_ast_lowering/pat.rs index 496e401d061..55c1f802663 100644 --- a/src/librustc_ast_lowering/pat.rs +++ b/src/librustc_ast_lowering/pat.rs @@ -3,6 +3,7 @@ use super::{ImplTraitContext, LoweringContext, ParamMode}; use rustc_ast::ast::*; use rustc_ast::ptr::P; use rustc_data_structures::stack::ensure_sufficient_stack; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_span::symbol::Ident; @@ -102,10 +103,36 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Note that unlike for slice patterns, // where `xs @ ..` is a legal sub-slice pattern, // it is not a legal sub-tuple pattern. - if pat.is_rest() { - rest = Some((idx, pat.span)); - break; + match pat.kind { + // Found a sub-tuple rest pattern + PatKind::Rest => { + rest = Some((idx, pat.span)); + break; + } + // Found a sub-tuple pattern `$binding_mode $ident @ ..`. + // This is not allowed as a sub-tuple pattern + PatKind::Ident(ref _bm, ident, Some(ref sub)) if sub.is_rest() => { + rest = Some((idx, pat.span)); + let sp = pat.span; + self.diagnostic() + .struct_span_err( + sp, + &format!("`{} @` is not allowed in a {}", ident.name, ctx), + ) + .span_label(sp, "this is only allowed in slice patterns") + .help("remove this and bind each tuple field independently") + .span_suggestion_verbose( + sp, + &format!("if you don't need to use the contents of {}, discard the tuple's remaining fields", ident), + "..".to_string(), + Applicability::MaybeIncorrect, + ) + .emit(); + break; + } + _ => {} } + // It was not a sub-tuple pattern so lower it normally. elems.push(self.lower_pat(pat)); } diff --git a/src/test/ui/issues/issue-72574-1.rs b/src/test/ui/issues/issue-72574-1.rs new file mode 100644 index 00000000000..efbb0bfb150 --- /dev/null +++ b/src/test/ui/issues/issue-72574-1.rs @@ -0,0 +1,8 @@ +fn main() { + let x = (1, 2, 3); + match x { + (_a, _x @ ..) => {} + _ => {} + } +} +//~^^^^ ERROR `_x @` is not allowed in a tuple diff --git a/src/test/ui/issues/issue-72574-1.stderr b/src/test/ui/issues/issue-72574-1.stderr new file mode 100644 index 00000000000..329f7d008d4 --- /dev/null +++ b/src/test/ui/issues/issue-72574-1.stderr @@ -0,0 +1,14 @@ +error: `_x @` is not allowed in a tuple + --> $DIR/issue-72574-1.rs:4:14 + | +LL | (_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 | (_a, ..) => {} + | ^^ + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-72574-2.rs b/src/test/ui/issues/issue-72574-2.rs new file mode 100644 index 00000000000..0c8f6fcc508 --- /dev/null +++ b/src/test/ui/issues/issue-72574-2.rs @@ -0,0 +1,10 @@ +struct Binder(i32, i32, i32); + +fn main() { + let x = Binder(1, 2, 3); + match x { + Binder(_a, _x @ ..) => {} + _ => {} + } +} +//~^^^^ ERROR `_x @` is not allowed in a tuple struct diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr new file mode 100644 index 00000000000..6faa57bcca6 --- /dev/null +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -0,0 +1,14 @@ +error: `_x @` is not allowed in a tuple struct + --> $DIR/issue-72574-2.rs:6:20 + | +LL | Binder(_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 | Binder(_a, ..) => {} + | ^^ + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5