From ea13023b367d56ac3a8fcb72c9bbe636cf9ae1e7 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 14 Jan 2023 11:44:25 +0000 Subject: Allocate one less vec in `parser/expr.rs` --- compiler/rustc_parse/src/parser/expr.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index dd2b03988c3..9995b214861 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1471,9 +1471,8 @@ impl<'a> Parser<'a> { } else if self.eat(&token::Comma) { // Vector with two or more elements. let sep = SeqSep::trailing_allowed(token::Comma); - let (remaining_exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?; - let mut exprs = vec![first_expr]; - exprs.extend(remaining_exprs); + let (mut exprs, _) = self.parse_seq_to_end(close, sep, |p| p.parse_expr())?; + exprs.insert(0, first_expr); ExprKind::Array(exprs) } else { // Vector with one element -- cgit 1.4.1-3-g733a5 From 6821adb65145463ffe51e044cbe37ea823059222 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 13 Jan 2023 01:27:58 +0100 Subject: Deprioritize fulfillment errors that come from expansions. --- .../src/traits/error_reporting/mod.rs | 8 +++++--- .../inference/cannot-infer-partial-try-return.stderr | 2 -- tests/ui/inference/question-mark-type-infer.stderr | 9 +++++++-- tests/ui/issues/issue-69455.stderr | 18 ++++++++++-------- .../cannot_infer_local_or_vec_in_tuples.stderr | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0c7ffb056cc..c75842d18c6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -453,9 +453,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - for (error, suppressed) in iter::zip(errors, is_suppressed) { - if !suppressed { - self.report_fulfillment_error(error, body_id); + for from_expansion in [false, true] { + for (error, suppressed) in iter::zip(errors, &is_suppressed) { + if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion { + self.report_fulfillment_error(error, body_id); + } } } diff --git a/tests/ui/inference/cannot-infer-partial-try-return.stderr b/tests/ui/inference/cannot-infer-partial-try-return.stderr index 2a56aaa44fe..888c321bc47 100644 --- a/tests/ui/inference/cannot-infer-partial-try-return.stderr +++ b/tests/ui/inference/cannot-infer-partial-try-return.stderr @@ -1,8 +1,6 @@ error[E0282]: type annotations needed --> $DIR/cannot-infer-partial-try-return.rs:20:9 | -LL | infallible()?; - | ------------- type must be known at this point LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | diff --git a/tests/ui/inference/question-mark-type-infer.stderr b/tests/ui/inference/question-mark-type-infer.stderr index 9b822714f82..a9cb7e5257c 100644 --- a/tests/ui/inference/question-mark-type-infer.stderr +++ b/tests/ui/inference/question-mark-type-infer.stderr @@ -1,8 +1,13 @@ error[E0282]: type annotations needed - --> $DIR/question-mark-type-infer.rs:10:30 + --> $DIR/question-mark-type-infer.rs:10:21 | LL | l.iter().map(f).collect()? - | ^ cannot infer type + | ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect` + | +help: consider specifying the generic argument + | +LL | l.iter().map(f).collect::>()? + | ++++++++++ error: aborting due to previous error diff --git a/tests/ui/issues/issue-69455.stderr b/tests/ui/issues/issue-69455.stderr index 9d11cf19ea7..fc343bb54aa 100644 --- a/tests/ui/issues/issue-69455.stderr +++ b/tests/ui/issues/issue-69455.stderr @@ -1,14 +1,16 @@ -error[E0282]: type annotations needed - --> $DIR/issue-69455.rs:29:20 +error[E0284]: type annotations needed + --> $DIR/issue-69455.rs:29:41 | LL | println!("{}", 23u64.test(xs.iter().sum())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `new_display` + | ---- ^^^ cannot infer type of the type parameter `S` declared on the associated function `sum` + | | + | type must be known at this point | - = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: cannot satisfy `>::Output == _` help: consider specifying the generic argument | -LL | println!("{}", 23u64.test(xs.iter().sum())::); - | +++++ +LL | println!("{}", 23u64.test(xs.iter().sum::())); + | +++++ error[E0283]: type annotations needed --> $DIR/issue-69455.rs:29:41 @@ -33,5 +35,5 @@ LL | println!("{}", 23u64.test(xs.iter().sum::())); error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0283. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0283, E0284. +For more information about an error, try `rustc --explain E0283`. diff --git a/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr index be60cda68b9..e544b369515 100644 --- a/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr +++ b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `(Vec,)` --> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9 | LL | let (x, ) = (vec![], ); - | ^^^^^ + | ^^^^^ ---------- type must be known at this point | help: consider giving this pattern a type, where the type for type parameter `T` is specified | -- cgit 1.4.1-3-g733a5 From 4f64de83bc5731946c9acdd4f572e24bfbaef4b9 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 7 Jan 2023 15:41:32 +0000 Subject: Fix `unused_braces` on generic const expr macro call --- compiler/rustc_lint/src/unused.rs | 1 + tests/ui/const-generics/unused_braces.fixed | 7 +++++++ tests/ui/const-generics/unused_braces.rs | 7 +++++++ tests/ui/const-generics/unused_braces.stderr | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index ac2b32b44e6..f2ee9ab1a19 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1105,6 +1105,7 @@ impl UnusedDelimLint for UnusedBraces { || matches!(expr.kind, ast::ExprKind::Lit(_))) && !cx.sess().source_map().is_multiline(value.span) && value.attrs.is_empty() + && !expr.span.from_expansion() && !value.span.from_expansion() && !inner.span.from_expansion() { diff --git a/tests/ui/const-generics/unused_braces.fixed b/tests/ui/const-generics/unused_braces.fixed index d080c210e6b..4c1926387b9 100644 --- a/tests/ui/const-generics/unused_braces.fixed +++ b/tests/ui/const-generics/unused_braces.fixed @@ -2,10 +2,17 @@ // run-rustfix #![warn(unused_braces)] +macro_rules! make_1 { + () => { + 1 + } +} + struct A; fn main() { let _: A<7>; // ok let _: A<7>; //~ WARN unnecessary braces let _: A<{ 3 + 5 }>; // ok + let _: A<{make_1!()}>; // ok } diff --git a/tests/ui/const-generics/unused_braces.rs b/tests/ui/const-generics/unused_braces.rs index 47f0f8c1c96..e9f15b40180 100644 --- a/tests/ui/const-generics/unused_braces.rs +++ b/tests/ui/const-generics/unused_braces.rs @@ -2,10 +2,17 @@ // run-rustfix #![warn(unused_braces)] +macro_rules! make_1 { + () => { + 1 + } +} + struct A; fn main() { let _: A<7>; // ok let _: A<{ 7 }>; //~ WARN unnecessary braces let _: A<{ 3 + 5 }>; // ok + let _: A<{make_1!()}>; // ok } diff --git a/tests/ui/const-generics/unused_braces.stderr b/tests/ui/const-generics/unused_braces.stderr index 553a3a0f88e..2c8031c4300 100644 --- a/tests/ui/const-generics/unused_braces.stderr +++ b/tests/ui/const-generics/unused_braces.stderr @@ -1,5 +1,5 @@ warning: unnecessary braces around const expression - --> $DIR/unused_braces.rs:9:14 + --> $DIR/unused_braces.rs:15:14 | LL | let _: A<{ 7 }>; | ^^ ^^ -- cgit 1.4.1-3-g733a5