From a63f5dce27cd5a315046ecebbafa8ee2fef10e12 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 22 Jan 2023 16:28:23 +0000 Subject: [PATCH 01/11] Remove confusing 'while checking' note from opaque future type mismatches --- .../src/infer/error_reporting/mod.rs | 62 +++++-------------- .../dont-suggest-missing-await.stderr | 5 -- tests/ui/async-await/generator-desc.stderr | 10 --- tests/ui/async-await/issue-61076.rs | 3 - tests/ui/async-await/issue-61076.stderr | 15 ++--- tests/ui/async-await/issue-98634.stderr | 15 ----- .../ui/async-await/issues/issue-102206.stderr | 5 -- .../suggest-missing-await-closure.stderr | 5 -- .../async-await/suggest-missing-await.stderr | 35 ----------- .../in-trait/method-signature-matches.stderr | 10 --- tests/ui/impl-trait/issue-102605.stderr | 5 -- tests/ui/impl-trait/issue-99914.stderr | 5 -- tests/ui/suggestions/if-then-neeing-semi.rs | 15 +---- .../ui/suggestions/if-then-neeing-semi.stderr | 28 ++------- tests/ui/suggestions/issue-81839.stderr | 5 -- .../match-prev-arm-needing-semi.rs | 15 +---- .../match-prev-arm-needing-semi.stderr | 28 ++------- .../type-alias-impl-trait/issue-98604.stderr | 5 -- 18 files changed, 35 insertions(+), 236 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 28fd03b878b2b..1e84940b01949 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -60,7 +60,7 @@ use crate::traits::{ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg}; -use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan}; +use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -1468,51 +1468,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (key, values) in types.iter() { let count = values.len(); let kind = key.descr(); - let mut returned_async_output_error = false; for &sp in values { - if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error { - if [sp] != err.span.primary_spans() { - let mut span: MultiSpan = sp.into(); - span.push_span_label( - sp, - format!( - "checked the `Output` of this `async fn`, {}{} {}{}", - if count > 1 { "one of the " } else { "" }, - target, - kind, - pluralize!(count), - ), - ); - err.span_note( - span, - "while checking the return type of the `async fn`", - ); - } else { - err.span_label( - sp, - format!( - "checked the `Output` of this `async fn`, {}{} {}{}", - if count > 1 { "one of the " } else { "" }, - target, - kind, - pluralize!(count), - ), - ); - err.note("while checking the return type of the `async fn`"); - } - returned_async_output_error = true; - } else { - err.span_label( - sp, - format!( - "{}{} {}{}", - if count == 1 { "the " } else { "one of the " }, - target, - kind, - pluralize!(count), - ), - ); - } + err.span_label( + sp, + format!( + "{}{} {}{}", + if count == 1 { "the " } else { "one of the " }, + target, + kind, + pluralize!(count), + ), + ); } } } @@ -1535,7 +1501,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // | // = note: expected unit type `()` // found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]` - if !self.ignore_span.overlaps(span) { + // + // Also ignore opaque `Future`s that come from async fns. + if !self.ignore_span.overlaps(span) + && !span.is_desugaring(DesugaringKind::Async) + { self.types.entry(kind).or_default().insert(span); } } diff --git a/tests/ui/async-await/dont-suggest-missing-await.stderr b/tests/ui/async-await/dont-suggest-missing-await.stderr index 627bf05bba2d9..8e2d42c8f138c 100644 --- a/tests/ui/async-await/dont-suggest-missing-await.stderr +++ b/tests/ui/async-await/dont-suggest-missing-await.stderr @@ -6,11 +6,6 @@ LL | take_u32(x) | | | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/dont-suggest-missing-await.rs:7:24 - | -LL | async fn make_u32() -> u32 { - | ^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `u32` found opaque type `impl Future` note: function defined here diff --git a/tests/ui/async-await/generator-desc.stderr b/tests/ui/async-await/generator-desc.stderr index 963c6ba57adf8..9fdb1ce47d7ba 100644 --- a/tests/ui/async-await/generator-desc.stderr +++ b/tests/ui/async-await/generator-desc.stderr @@ -21,16 +21,6 @@ LL | fun(one(), two()); | | | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/generator-desc.rs:5:16 - | -LL | async fn one() {} - | ^ checked the `Output` of this `async fn`, expected opaque type -note: while checking the return type of the `async fn` - --> $DIR/generator-desc.rs:6:16 - | -LL | async fn two() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:5:16>) found opaque type `impl Future` (opaque type at <$DIR/generator-desc.rs:6:16>) = help: consider `await`ing on both `Future`s diff --git a/tests/ui/async-await/issue-61076.rs b/tests/ui/async-await/issue-61076.rs index 750fad8393bbf..0cfb774756e66 100644 --- a/tests/ui/async-await/issue-61076.rs +++ b/tests/ui/async-await/issue-61076.rs @@ -54,9 +54,6 @@ async fn struct_() -> Struct { } async fn tuple() -> Tuple { - //~^ NOTE checked the `Output` of this `async fn`, expected opaque type - //~| NOTE while checking the return type of the `async fn` - //~| NOTE in this expansion of desugaring of `async` block or function Tuple(1i32) } diff --git a/tests/ui/async-await/issue-61076.stderr b/tests/ui/async-await/issue-61076.stderr index 33839ea59392d..28a1a14aa8b04 100644 --- a/tests/ui/async-await/issue-61076.stderr +++ b/tests/ui/async-await/issue-61076.stderr @@ -11,7 +11,7 @@ LL | foo().await?; | ++++++ error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/issue-61076.rs:65:5 + --> $DIR/issue-61076.rs:62:5 | LL | t?; | ^^ the `?` operator cannot be applied to type `T` @@ -23,7 +23,7 @@ LL | t.await?; | ++++++ error[E0609]: no field `0` on type `impl Future` - --> $DIR/issue-61076.rs:74:26 + --> $DIR/issue-61076.rs:71:26 | LL | let _: i32 = tuple().0; | ^ field not available in `impl Future`, but it is available in its `Output` @@ -34,7 +34,7 @@ LL | let _: i32 = tuple().await.0; | ++++++ error[E0609]: no field `a` on type `impl Future` - --> $DIR/issue-61076.rs:78:28 + --> $DIR/issue-61076.rs:75:28 | LL | let _: i32 = struct_().a; | ^ field not available in `impl Future`, but it is available in its `Output` @@ -45,7 +45,7 @@ LL | let _: i32 = struct_().await.a; | ++++++ error[E0599]: no method named `method` found for opaque type `impl Future` in the current scope - --> $DIR/issue-61076.rs:82:15 + --> $DIR/issue-61076.rs:79:15 | LL | struct_().method(); | ^^^^^^ method not found in `impl Future` @@ -56,7 +56,7 @@ LL | struct_().await.method(); | ++++++ error[E0308]: mismatched types - --> $DIR/issue-61076.rs:91:9 + --> $DIR/issue-61076.rs:88:9 | LL | match tuple() { | ------- this expression has type `impl Future` @@ -64,11 +64,6 @@ LL | LL | Tuple(_) => {} | ^^^^^^^^ expected opaque type, found struct `Tuple` | -note: while checking the return type of the `async fn` - --> $DIR/issue-61076.rs:56:21 - | -LL | async fn tuple() -> Tuple { - | ^^^^^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future` found struct `Tuple` help: consider `await`ing on the `Future` diff --git a/tests/ui/async-await/issue-98634.stderr b/tests/ui/async-await/issue-98634.stderr index 5160e48d88afd..63156140b409c 100644 --- a/tests/ui/async-await/issue-98634.stderr +++ b/tests/ui/async-await/issue-98634.stderr @@ -4,11 +4,6 @@ error[E0271]: expected `fn() -> impl Future {callback}` to be a fn LL | StructAsync { callback }.await; | ^^^^^^^^ expected struct `Pin`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/issue-98634.rs:24:21 - | -LL | async fn callback() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected struct `Pin + 'static)>>` found opaque type `impl Future` note: required by a bound in `StructAsync` @@ -23,11 +18,6 @@ error[E0271]: expected `fn() -> impl Future {callback}` to be a fn LL | StructAsync { callback }.await; | ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/issue-98634.rs:24:21 - | -LL | async fn callback() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected struct `Pin + 'static)>>` found opaque type `impl Future` note: required by a bound in `StructAsync` @@ -42,11 +32,6 @@ error[E0271]: expected `fn() -> impl Future {callback}` to be a fn LL | StructAsync { callback }.await; | ^^^^^^ expected struct `Pin`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/issue-98634.rs:24:21 - | -LL | async fn callback() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected struct `Pin + 'static)>>` found opaque type `impl Future` note: required by a bound in `StructAsync` diff --git a/tests/ui/async-await/issues/issue-102206.stderr b/tests/ui/async-await/issues/issue-102206.stderr index 2ab790ac761a0..2ec242c04a58f 100644 --- a/tests/ui/async-await/issues/issue-102206.stderr +++ b/tests/ui/async-await/issues/issue-102206.stderr @@ -8,11 +8,6 @@ LL | std::mem::size_of_val(foo()); | | help: consider borrowing here: `&foo()` | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/issue-102206.rs:3:16 - | -LL | async fn foo() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected reference `&_` found opaque type `impl Future` note: function defined here diff --git a/tests/ui/async-await/suggest-missing-await-closure.stderr b/tests/ui/async-await/suggest-missing-await-closure.stderr index a5958baffbaf7..e47325cb4aeae 100644 --- a/tests/ui/async-await/suggest-missing-await-closure.stderr +++ b/tests/ui/async-await/suggest-missing-await-closure.stderr @@ -6,11 +6,6 @@ LL | take_u32(x) | | | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await-closure.rs:8:24 - | -LL | async fn make_u32() -> u32 { - | ^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `u32` found opaque type `impl Future` note: function defined here diff --git a/tests/ui/async-await/suggest-missing-await.stderr b/tests/ui/async-await/suggest-missing-await.stderr index 1196601ace090..dfafc810997ec 100644 --- a/tests/ui/async-await/suggest-missing-await.stderr +++ b/tests/ui/async-await/suggest-missing-await.stderr @@ -6,11 +6,6 @@ LL | take_u32(x) | | | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:5:24 - | -LL | async fn make_u32() -> u32 { - | ^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `u32` found opaque type `impl Future` note: function defined here @@ -29,11 +24,6 @@ error[E0308]: mismatched types LL | dummy() | ^^^^^^^ expected `()`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:18:18 - | -LL | async fn dummy() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` help: consider `await`ing on the `Future` @@ -60,11 +50,6 @@ LL | | LL | | }; | |_____- `if` and `else` have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:18:18 - | -LL | async fn dummy() {} - | ^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future` found unit type `()` help: consider `await`ing on the `Future` @@ -87,11 +72,6 @@ LL | | LL | | }; | |_____- `match` arms have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:18:18 - | -LL | async fn dummy() {} - | ^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future` found unit type `()` help: consider `await`ing on the `Future` @@ -108,11 +88,6 @@ LL | let _x = match dummy() { LL | () => {} | ^^ expected opaque type, found `()` | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:18:18 - | -LL | async fn dummy() {} - | ^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future` found unit type `()` help: consider `await`ing on the `Future` @@ -129,11 +104,6 @@ LL | match dummy_result() { LL | Ok(_) => {} | ^^^^^ expected opaque type, found enum `Result` | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:57:28 - | -LL | async fn dummy_result() -> Result<(), ()> { - | ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future>` found enum `Result<_, _>` help: consider `await`ing on the `Future` @@ -150,11 +120,6 @@ LL | match dummy_result() { LL | Err(_) => {} | ^^^^^^ expected opaque type, found enum `Result` | -note: while checking the return type of the `async fn` - --> $DIR/suggest-missing-await.rs:57:28 - | -LL | async fn dummy_result() -> Result<(), ()> { - | ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type = note: expected opaque type `impl Future>` found enum `Result<_, _>` help: consider `await`ing on the `Future` diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.stderr index 4dfd772222e5d..3ec62020e6c89 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.stderr @@ -24,16 +24,6 @@ LL | async fn owo(_: u8) {} | expected `()`, found `u8` | help: change the parameter type to match the trait: `()` | -note: while checking the return type of the `async fn` - --> $DIR/method-signature-matches.rs:20:25 - | -LL | async fn owo(_: u8) {} - | ^ checked the `Output` of this `async fn`, expected opaque type -note: while checking the return type of the `async fn` - --> $DIR/method-signature-matches.rs:20:25 - | -LL | async fn owo(_: u8) {} - | ^ checked the `Output` of this `async fn`, found opaque type note: type in trait --> $DIR/method-signature-matches.rs:16:21 | diff --git a/tests/ui/impl-trait/issue-102605.stderr b/tests/ui/impl-trait/issue-102605.stderr index d4aba914908fd..c191ff57152fd 100644 --- a/tests/ui/impl-trait/issue-102605.stderr +++ b/tests/ui/impl-trait/issue-102605.stderr @@ -6,11 +6,6 @@ LL | convert_result(foo()) | | | arguments to this function are incorrect | -note: while checking the return type of the `async fn` - --> $DIR/issue-102605.rs:3:19 - | -LL | async fn foo() -> Result<(), String> { - | ^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected enum `Result<(), _>` found opaque type `impl Future>` note: function defined here diff --git a/tests/ui/impl-trait/issue-99914.stderr b/tests/ui/impl-trait/issue-99914.stderr index 074d5d58d9a30..db2a979cc50af 100644 --- a/tests/ui/impl-trait/issue-99914.stderr +++ b/tests/ui/impl-trait/issue-99914.stderr @@ -4,11 +4,6 @@ error[E0308]: mismatched types LL | t.and_then(|t| -> _ { bar(t) }); | ^^^^^^ expected enum `Result`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/issue-99914.rs:13:23 - | -LL | async fn bar(t: Okay) {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected enum `Result<_, Error>` found opaque type `impl Future` help: try wrapping the expression in `Ok` diff --git a/tests/ui/suggestions/if-then-neeing-semi.rs b/tests/ui/suggestions/if-then-neeing-semi.rs index b487f013d2706..7be4312bfbacb 100644 --- a/tests/ui/suggestions/if-then-neeing-semi.rs +++ b/tests/ui/suggestions/if-then-neeing-semi.rs @@ -15,18 +15,9 @@ fn extra_semicolon() { }; } -async fn async_dummy() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -//~| NOTE checked the `Output` of this `async fn`, expected opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -async fn async_dummy2() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function +async fn async_dummy() {} + +async fn async_dummy2() {} async fn async_extra_semicolon_same() { let _ = if true { diff --git a/tests/ui/suggestions/if-then-neeing-semi.stderr b/tests/ui/suggestions/if-then-neeing-semi.stderr index d7c5818abbd54..567deb405fccd 100644 --- a/tests/ui/suggestions/if-then-neeing-semi.stderr +++ b/tests/ui/suggestions/if-then-neeing-semi.stderr @@ -1,5 +1,5 @@ error[E0308]: `if` and `else` have incompatible types - --> $DIR/if-then-neeing-semi.rs:37:9 + --> $DIR/if-then-neeing-semi.rs:28:9 | LL | let _ = if true { | _____________- @@ -15,11 +15,6 @@ LL | | LL | | }; | |_____- `if` and `else` have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/if-then-neeing-semi.rs:18:24 - | -LL | async fn async_dummy() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` help: consider `await`ing on the `Future` @@ -33,7 +28,7 @@ LL + async_dummy() | error[E0308]: `if` and `else` have incompatible types - --> $DIR/if-then-neeing-semi.rs:50:9 + --> $DIR/if-then-neeing-semi.rs:41:9 | LL | let _ = if true { | _____________- @@ -49,11 +44,6 @@ LL | | LL | | }; | |_____- `if` and `else` have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/if-then-neeing-semi.rs:24:25 - | -LL | async fn async_dummy2() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` help: consider `await`ing on the `Future` @@ -69,7 +59,7 @@ LL ~ Box::new(async_dummy2()) | error[E0308]: `if` and `else` have incompatible types - --> $DIR/if-then-neeing-semi.rs:63:9 + --> $DIR/if-then-neeing-semi.rs:54:9 | LL | let _ = if true { | _____________- @@ -85,18 +75,8 @@ LL | | LL | | }; | |_____- `if` and `else` have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/if-then-neeing-semi.rs:18:24 - | -LL | async fn async_dummy() {} - | ^ checked the `Output` of this `async fn`, expected opaque type -note: while checking the return type of the `async fn` - --> $DIR/if-then-neeing-semi.rs:24:25 - | -LL | async fn async_dummy2() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected opaque type `impl Future` (opaque type at <$DIR/if-then-neeing-semi.rs:18:24>) - found opaque type `impl Future` (opaque type at <$DIR/if-then-neeing-semi.rs:24:25>) + found opaque type `impl Future` (opaque type at <$DIR/if-then-neeing-semi.rs:20:25>) = note: distinct uses of `impl Trait` result in different opaque types help: consider `await`ing on both `Future`s | diff --git a/tests/ui/suggestions/issue-81839.stderr b/tests/ui/suggestions/issue-81839.stderr index fae474cedb886..4af7cc9f8ec80 100644 --- a/tests/ui/suggestions/issue-81839.stderr +++ b/tests/ui/suggestions/issue-81839.stderr @@ -14,11 +14,6 @@ LL | | _ => cx.answer_str("hi"), LL | | } | |_____- `match` arms have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/auxiliary/issue-81839.rs:6:49 - | -LL | pub async fn answer_str(&self, _s: &str) -> Test { - | ^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` diff --git a/tests/ui/suggestions/match-prev-arm-needing-semi.rs b/tests/ui/suggestions/match-prev-arm-needing-semi.rs index 8c8abe047c2ab..3f863cb104e0b 100644 --- a/tests/ui/suggestions/match-prev-arm-needing-semi.rs +++ b/tests/ui/suggestions/match-prev-arm-needing-semi.rs @@ -13,18 +13,9 @@ fn extra_semicolon() { }; } -async fn async_dummy() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -//~| NOTE checked the `Output` of this `async fn`, expected opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -async fn async_dummy2() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE checked the `Output` of this `async fn`, found opaque type -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function -//~| NOTE while checking the return type of the `async fn` -//~| NOTE in this expansion of desugaring of `async` block or function +async fn async_dummy() {} + +async fn async_dummy2() {} async fn async_extra_semicolon_same() { let _ = match true { //~ NOTE `match` arms have incompatible types diff --git a/tests/ui/suggestions/match-prev-arm-needing-semi.stderr b/tests/ui/suggestions/match-prev-arm-needing-semi.stderr index 8d735b71f8278..df18c7b0b23cc 100644 --- a/tests/ui/suggestions/match-prev-arm-needing-semi.stderr +++ b/tests/ui/suggestions/match-prev-arm-needing-semi.stderr @@ -1,5 +1,5 @@ error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:35:18 + --> $DIR/match-prev-arm-needing-semi.rs:26:18 | LL | let _ = match true { | _____________- @@ -15,11 +15,6 @@ LL | | LL | | }; | |_____- `match` arms have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/match-prev-arm-needing-semi.rs:16:24 - | -LL | async fn async_dummy() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` help: consider `await`ing on the `Future` @@ -33,7 +28,7 @@ LL + async_dummy() | error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:48:18 + --> $DIR/match-prev-arm-needing-semi.rs:39:18 | LL | let _ = match true { | _____________- @@ -49,11 +44,6 @@ LL | | LL | | }; | |_____- `match` arms have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/match-prev-arm-needing-semi.rs:22:25 - | -LL | async fn async_dummy2() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected unit type `()` found opaque type `impl Future` help: consider `await`ing on the `Future` @@ -69,7 +59,7 @@ LL ~ false => Box::new(async_dummy2()), | error[E0308]: `match` arms have incompatible types - --> $DIR/match-prev-arm-needing-semi.rs:59:18 + --> $DIR/match-prev-arm-needing-semi.rs:50:18 | LL | let _ = match true { | _____________- @@ -83,18 +73,8 @@ LL | | LL | | }; | |_____- `match` arms have incompatible types | -note: while checking the return type of the `async fn` - --> $DIR/match-prev-arm-needing-semi.rs:16:24 - | -LL | async fn async_dummy() {} - | ^ checked the `Output` of this `async fn`, expected opaque type -note: while checking the return type of the `async fn` - --> $DIR/match-prev-arm-needing-semi.rs:22:25 - | -LL | async fn async_dummy2() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected opaque type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:16:24>) - found opaque type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:22:25>) + found opaque type `impl Future` (opaque type at <$DIR/match-prev-arm-needing-semi.rs:18:25>) = note: distinct uses of `impl Trait` result in different opaque types help: consider `await`ing on both `Future`s | diff --git a/tests/ui/type-alias-impl-trait/issue-98604.stderr b/tests/ui/type-alias-impl-trait/issue-98604.stderr index 92d01eb0d3d5e..570529322e60f 100644 --- a/tests/ui/type-alias-impl-trait/issue-98604.stderr +++ b/tests/ui/type-alias-impl-trait/issue-98604.stderr @@ -4,11 +4,6 @@ error[E0271]: expected `fn() -> impl Future {test}` to be a fn item LL | Box::new(test) as AsyncFnPtr; | ^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type | -note: while checking the return type of the `async fn` - --> $DIR/issue-98604.rs:5:17 - | -LL | async fn test() {} - | ^ checked the `Output` of this `async fn`, found opaque type = note: expected struct `Pin + 'static)>>` found opaque type `impl Future` = note: required for the cast from `fn() -> impl Future {test}` to the object type `dyn Fn() -> Pin + 'static)>>` From 5209d6f5fdac2054666a15c64f78450d6cb99717 Mon Sep 17 00:00:00 2001 From: imWildCat Date: Thu, 26 Jan 2023 23:29:08 -0800 Subject: [PATCH 02/11] Remove hardcoded clang target: ios13 or ios14 for Mac Catalyst [fixed] --- compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs | 4 ++-- compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs index 0009972cf4256..2b135b6703481 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs @@ -2,7 +2,7 @@ use super::apple_base::{opts, Arch}; use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions}; pub fn target() -> Target { - let llvm_target = "arm64-apple-ios14.0-macabi"; + let llvm_target = "arm64-apple-ios-macabi"; let arch = Arch::Arm64_macabi; let mut base = opts("ios", arch); @@ -22,7 +22,7 @@ pub fn target() -> Target { // These arguments are not actually invoked - they just have // to look right to pass App Store validation. bitcode_llvm_cmdline: "-triple\0\ - arm64-apple-ios14.0-macabi\0\ + arm64-apple-ios-macabi\0\ -emit-obj\0\ -disable-llvm-passes\0\ -Os\0" diff --git a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs index 0f3f851996377..5a3e2a79bb9cc 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs @@ -2,7 +2,7 @@ use super::apple_base::{opts, Arch}; use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { - let llvm_target = "x86_64-apple-ios13.0-macabi"; + let llvm_target = "x86_64-apple-ios-macabi"; let arch = Arch::X86_64_macabi; let mut base = opts("ios", arch); From 72419efa0dc968462e41a6a022464798f4e2ff33 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 15 Jan 2023 21:31:04 +0000 Subject: [PATCH 03/11] Recover _ as .. in field pattern --- compiler/rustc_parse/src/parser/pat.rs | 35 +++++++++++-------- ...ssue-46718-struct-pattern-dotdotdot.stderr | 7 +++- tests/ui/parser/issue-102806.stderr | 7 +++- tests/ui/parser/issues/issue-63135.stderr | 7 +++- ...uct-enum-ignoring-field-with-underscore.rs | 3 +- ...enum-ignoring-field-with-underscore.stderr | 23 ++++-------- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 912f7cc14f6cc..54624724fd4cb 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -1013,12 +1013,15 @@ impl<'a> Parser<'a> { } ate_comma = false; - if self.check(&token::DotDot) || self.token == token::DotDotDot { + if self.check(&token::DotDot) + || self.check_noexpect(&token::DotDotDot) + || self.check_keyword(kw::Underscore) + { etc = true; let mut etc_sp = self.token.span; - self.recover_one_fewer_dotdot(); - self.bump(); // `..` || `...` + self.recover_bad_dot_dot(); + self.bump(); // `..` || `...` || `_` if self.token == token::CloseDelim(Delimiter::Brace) { etc_span = Some(etc_sp); @@ -1111,21 +1114,25 @@ impl<'a> Parser<'a> { Ok((fields, etc)) } - /// Recover on `...` as if it were `..` to avoid further errors. + /// Recover on `...` or `_` as if it were `..` to avoid further errors. /// See issue #46718. - fn recover_one_fewer_dotdot(&self) { - if self.token != token::DotDotDot { + fn recover_bad_dot_dot(&self) { + if self.token == token::DotDot { return; } - self.struct_span_err(self.token.span, "expected field pattern, found `...`") - .span_suggestion( - self.token.span, - "to omit remaining fields, use one fewer `.`", - "..", - Applicability::MachineApplicable, - ) - .emit(); + let token_str = pprust::token_to_string(&self.token); + self.struct_span_err( + self.token.span, + format!("expected field pattern, found `{token_str}`"), + ) + .span_suggestion_verbose( + self.token.span, + "to omit remaining fields, use `..`", + "..", + Applicability::MachineApplicable, + ) + .emit(); } fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> { diff --git a/tests/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr b/tests/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr index bfe1ed32859b9..589b2c3784926 100644 --- a/tests/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr +++ b/tests/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr @@ -2,7 +2,12 @@ error: expected field pattern, found `...` --> $DIR/issue-46718-struct-pattern-dotdotdot.rs:11:55 | LL | PersonalityInventory { expressivity: exp, ... } => exp - | ^^^ help: to omit remaining fields, use one fewer `.`: `..` + | ^^^ + | +help: to omit remaining fields, use `..` + | +LL | PersonalityInventory { expressivity: exp, .. } => exp + | ~~ error: aborting due to previous error diff --git a/tests/ui/parser/issue-102806.stderr b/tests/ui/parser/issue-102806.stderr index 6872b8bc0afec..ba8174a823b2a 100644 --- a/tests/ui/parser/issue-102806.stderr +++ b/tests/ui/parser/issue-102806.stderr @@ -32,7 +32,12 @@ error: expected field pattern, found `...` --> $DIR/issue-102806.rs:21:22 | LL | let V3 { z: val, ... } = v; - | ^^^ help: to omit remaining fields, use one fewer `.`: `..` + | ^^^ + | +help: to omit remaining fields, use `..` + | +LL | let V3 { z: val, .. } = v; + | ~~ error[E0063]: missing fields `x` and `y` in initializer of `V3` --> $DIR/issue-102806.rs:17:13 diff --git a/tests/ui/parser/issues/issue-63135.stderr b/tests/ui/parser/issues/issue-63135.stderr index 80e9ac5bedf13..e0dc356d5467b 100644 --- a/tests/ui/parser/issues/issue-63135.stderr +++ b/tests/ui/parser/issues/issue-63135.stderr @@ -20,7 +20,12 @@ error: expected field pattern, found `...` --> $DIR/issue-63135.rs:3:8 | LL | fn i(n{...,f # - | ^^^ help: to omit remaining fields, use one fewer `.`: `..` + | ^^^ + | +help: to omit remaining fields, use `..` + | +LL | fn i(n{..,f # + | ~~ error: expected `}`, found `,` --> $DIR/issue-63135.rs:3:11 diff --git a/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.rs b/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.rs index c30b8a1e1f1a7..b569993c6143e 100644 --- a/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.rs +++ b/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.rs @@ -7,6 +7,5 @@ fn main() { let foo = Some(Foo::Other); if let Some(Foo::Bar {_}) = foo {} - //~^ ERROR expected identifier, found reserved identifier `_` - //~| ERROR pattern does not mention field `bar` [E0027] + //~^ ERROR expected field pattern, found `_` } diff --git a/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.stderr b/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.stderr index 16f751444a558..2f3a150e5cba9 100644 --- a/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.stderr +++ b/tests/ui/structs-enums/struct-enum-ignoring-field-with-underscore.stderr @@ -1,24 +1,13 @@ -error: expected identifier, found reserved identifier `_` +error: expected field pattern, found `_` --> $DIR/struct-enum-ignoring-field-with-underscore.rs:9:27 | LL | if let Some(Foo::Bar {_}) = foo {} - | ^ expected identifier, found reserved identifier - -error[E0027]: pattern does not mention field `bar` - --> $DIR/struct-enum-ignoring-field-with-underscore.rs:9:17 - | -LL | if let Some(Foo::Bar {_}) = foo {} - | ^^^^^^^^^^^^ missing field `bar` - | -help: include the missing field in the pattern + | ^ | -LL | if let Some(Foo::Bar {_, bar }) = foo {} - | ~~~~~~~ -help: if you don't care about this missing field, you can explicitly ignore it +help: to omit remaining fields, use `..` | -LL | if let Some(Foo::Bar {_, .. }) = foo {} - | ~~~~~~ +LL | if let Some(Foo::Bar {..}) = foo {} + | ~~ -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0027`. From f1cb13e7b58338f5255e854d50a69c35b980168c Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 30 Jan 2023 23:47:10 +0000 Subject: [PATCH 04/11] Improve diagnostic for missing space in range pattern --- .../rustc_error_messages/locales/en-US/parse.ftl | 5 +++-- compiler/rustc_parse/src/errors.rs | 9 +++------ compiler/rustc_parse/src/parser/expr.rs | 8 ++++++++ compiler/rustc_parse/src/parser/pat.rs | 6 +++--- ...half-open-range-pats-inclusive-match-arrow.rs | 5 +++-- ...-open-range-pats-inclusive-match-arrow.stderr | 16 ++++++---------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/parse.ftl b/compiler/rustc_error_messages/locales/en-US/parse.ftl index 1728ef70cba0a..ee2d56570d8fb 100644 --- a/compiler/rustc_error_messages/locales/en-US/parse.ftl +++ b/compiler/rustc_error_messages/locales/en-US/parse.ftl @@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range .suggestion_remove_eq = use `..=` instead .note = inclusive ranges end with a single equals sign (`..=`) -parse_inclusive_range_match_arrow = unexpected `=>` after open range - .suggestion_add_space = add a space between the pattern and `=>` +parse_inclusive_range_match_arrow = unexpected `>` after inclusive range + .label = this is parsed as an inclusive range `..=` + .suggestion = add a space between the pattern and `=>` parse_inclusive_range_no_end = inclusive range with no end .suggestion_open_range = use `..` instead diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 054b41b478d60..083d7b5ac7515 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -667,13 +667,10 @@ pub(crate) struct InclusiveRangeExtraEquals { #[diag(parse_inclusive_range_match_arrow)] pub(crate) struct InclusiveRangeMatchArrow { #[primary_span] + pub arrow: Span, + #[label] pub span: Span, - #[suggestion( - suggestion_add_space, - style = "verbose", - code = " ", - applicability = "machine-applicable" - )] + #[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")] pub after_pat: Span, } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 17d1e200b41aa..9eb551139492c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2707,6 +2707,14 @@ impl<'a> Parser<'a> { ); err.emit(); this.bump(); + } else if matches!( + (&this.prev_token.kind, &this.token.kind), + (token::DotDotEq, token::Gt) + ) { + // `error_inclusive_range_match_arrow` handles cases like `0..=> {}`, + // so we supress the error here + err.delay_as_bug(); + this.bump(); } else { return Err(err); } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 912f7cc14f6cc..42d662ab20a96 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -777,7 +777,7 @@ impl<'a> Parser<'a> { self.error_inclusive_range_with_extra_equals(span_with_eq); } token::Gt if no_space => { - self.error_inclusive_range_match_arrow(span); + self.error_inclusive_range_match_arrow(span, tok.span); } _ => self.error_inclusive_range_with_no_end(span), } @@ -787,9 +787,9 @@ impl<'a> Parser<'a> { self.sess.emit_err(InclusiveRangeExtraEquals { span }); } - fn error_inclusive_range_match_arrow(&self, span: Span) { + fn error_inclusive_range_match_arrow(&self, span: Span, arrow: Span) { let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi(); - self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat }); + self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow, after_pat }); } fn error_inclusive_range_with_no_end(&self, span: Span) { diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.rs b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.rs index 7ba2b6d857cd0..30173b1b4be03 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.rs +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.rs @@ -2,7 +2,8 @@ fn main() { let x = 42; match x { 0..=73 => {}, - 74..=> {}, //~ ERROR unexpected `=>` after open range - //~^ ERROR expected one of `=>`, `if`, or `|`, found `>` + 74..=> {}, + //~^ ERROR unexpected `>` after inclusive range + //~| NOTE this is parsed as an inclusive range `..=` } } diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.stderr b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.stderr index 9ba6d15113cd6..cb7f998df7a5b 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.stderr +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-match-arrow.stderr @@ -1,19 +1,15 @@ -error: unexpected `=>` after open range - --> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:11 +error: unexpected `>` after inclusive range + --> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:14 | LL | 74..=> {}, - | ^^^ + | ---^ + | | + | this is parsed as an inclusive range `..=` | help: add a space between the pattern and `=>` | LL | 74.. => {}, | + -error: expected one of `=>`, `if`, or `|`, found `>` - --> $DIR/half-open-range-pats-inclusive-match-arrow.rs:5:14 - | -LL | 74..=> {}, - | ^ expected one of `=>`, `if`, or `|` - -error: aborting due to 2 previous errors +error: aborting due to previous error From 75e87d1f81290052a07fe85e3809d48a46613fb1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 30 Jan 2023 16:29:52 +1100 Subject: [PATCH 05/11] Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`. If you do `derive(PartialEq)` on a packed struct, the output shown by `-Zunpretty=expanded` includes expressions like this: ``` { self.x } == { other.x } ``` This is invalid syntax. This doesn't break compilation, because the AST nodes are constructed within the compiler. But it does mean anyone using `-Zunpretty=expanded` output as a guide for hand-written impls could get a nasty surprise. This commit fixes things by instead using this form: ``` ({ self.x }) == ({ other.x }) ``` --- .../src/deriving/cmp/partial_eq.rs | 24 +++++++++++++++---- compiler/rustc_expand/src/build.rs | 4 ++++ tests/ui/deriving/deriving-all-codegen.stdout | 6 ++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs index 88d454fbc1123..bad47db0de1d4 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs @@ -29,16 +29,30 @@ pub fn expand_deriving_partial_eq( cx.span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`"); }; - // We received `&T` arguments. Convert them to `T` by - // stripping `&` or adding `*`. This isn't necessary for - // type checking, but it results in much better error - // messages if something goes wrong. + // We received arguments of type `&T`. Convert them to type `T` by stripping + // any leading `&` or adding `*`. This isn't necessary for type checking, but + // it results in better error messages if something goes wrong. + // + // Note: for arguments that look like `&{ x }`, which occur with packed + // structs, this would cause expressions like `{ self.x } == { other.x }`, + // which isn't valid Rust syntax. This wouldn't break compilation because these + // AST nodes are constructed within the compiler. But it would mean that code + // printed by `-Zunpretty=expanded` (or `cargo expand`) would have invalid + // syntax, which would be suboptimal. So we wrap these in parens, giving + // `({ self.x }) == ({ other.x })`, which is valid syntax. let convert = |expr: &P| { if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = &expr.kind { - inner.clone() + if let ExprKind::Block(..) = &inner.kind { + // `&{ x }` form: remove the `&`, add parens. + cx.expr_paren(field.span, inner.clone()) + } else { + // `&x` form: remove the `&`. + inner.clone() + } } else { + // No leading `&`: add a leading `*`. cx.expr_deref(field.span, expr.clone()) } }; diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 9b16e79d49a9e..6cd56852f9d68 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -272,6 +272,10 @@ impl<'a> ExtCtxt<'a> { self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e)) } + pub fn expr_paren(&self, sp: Span, e: P) -> P { + self.expr(sp, ast::ExprKind::Paren(e)) + } + pub fn expr_call( &self, span: Span, diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index b4874cef134f7..8e238a509d2fd 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -209,7 +209,7 @@ impl ::core::marker::StructuralPartialEq for PackedPoint { } impl ::core::cmp::PartialEq for PackedPoint { #[inline] fn eq(&self, other: &PackedPoint) -> bool { - { self.x } == { other.x } && { self.y } == { other.y } + ({ self.x }) == ({ other.x }) && ({ self.y }) == ({ other.y }) } } #[automatically_derived] @@ -718,8 +718,8 @@ impl) -> bool { - { self.0 } == { other.0 } && { self.1 } == { other.1 } && - { self.2 } == { other.2 } + ({ self.0 }) == ({ other.0 }) && ({ self.1 }) == ({ other.1 }) && + ({ self.2 }) == ({ other.2 }) } } #[automatically_derived] From b96c8992a521a502fe66f72e188cc64fa79b2179 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 1 Feb 2023 10:42:20 +0000 Subject: [PATCH 06/11] Rename `rust_2015` => `is_rust_2015` --- compiler/rustc_ast_pretty/src/pprust/state.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_parse/src/parser/ty.rs | 2 +- compiler/rustc_resolve/src/build_reduced_graph.rs | 6 +++--- compiler/rustc_resolve/src/diagnostics.rs | 8 +++++--- compiler/rustc_resolve/src/ident.rs | 5 +++-- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_resolve/src/late/diagnostics.rs | 2 +- compiler/rustc_session/src/session.rs | 4 ++-- compiler/rustc_span/src/edition.rs | 2 +- compiler/rustc_span/src/lib.rs | 4 ++-- 11 files changed, 21 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index fa8567eac6090..d7767efa9841b 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -131,7 +131,7 @@ pub fn print_crate<'a>( // Currently, in Rust 2018 we don't have `extern crate std;` at the crate // root, so this is not needed, and actually breaks things. - if edition.rust_2015() { + if edition.is_rust_2015() { // `#![no_std]` let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP); s.print_attribute(&fake_attr); diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 53680a82bdc2e..29e9769befb55 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2442,7 +2442,7 @@ impl<'a> Parser<'a> { /// We are parsing `async fn`. If we are on Rust 2015, emit an error. fn ban_async_in_2015(&self, span: Span) { - if span.rust_2015() { + if span.is_rust_2015() { let diag = self.diagnostic(); struct_span_err!(diag, span, E0670, "`async fn` is not permitted in Rust 2015") .span_label(span, "to use `async fn`, switch to Rust 2018 or later") diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 8b4f0ab8feb84..12abec0ff9deb 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -702,7 +702,7 @@ impl<'a> Parser<'a> { /// Is a `dyn B0 + ... + Bn` type allowed here? fn is_explicit_dyn_type(&mut self) -> bool { self.check_keyword(kw::Dyn) - && (!self.token.uninterpolated_span().rust_2015() + && (!self.token.uninterpolated_span().is_rust_2015() || self.look_ahead(1, |t| { (t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star)) && !can_continue_type_after_non_fn_ident(t) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 84421dc1f6225..2fb62ce53ba6e 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -265,7 +265,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let ident = path.segments.get(0).expect("empty path in visibility").ident; let crate_root = if ident.is_path_segment_keyword() { None - } else if ident.span.rust_2015() { + } else if ident.span.is_rust_2015() { Some(Segment::from_ident(Ident::new( kw::PathRoot, path.span.shrink_to_lo().with_ctxt(ident.span.ctxt()), @@ -435,10 +435,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // appears, so imports in braced groups can have roots prepended independently. let is_glob = matches!(use_tree.kind, ast::UseTreeKind::Glob); let crate_root = match prefix_iter.peek() { - Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.rust_2015() => { + Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.is_rust_2015() => { Some(seg.ident.span.ctxt()) } - None if is_glob && use_tree.span.rust_2015() => Some(use_tree.span.ctxt()), + None if is_glob && use_tree.span.is_rust_2015() => Some(use_tree.span.ctxt()), _ => None, } .map(|ctxt| { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 3bf041cebcb88..a08ae0f184bb2 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -462,7 +462,9 @@ impl<'a> Resolver<'a> { let first_name = match path.get(0) { // In the 2018 edition this lint is a hard error, so nothing to do - Some(seg) if seg.ident.span.rust_2015() && self.session.rust_2015() => seg.ident.name, + Some(seg) if seg.ident.span.is_rust_2015() && self.session.is_rust_2015() => { + seg.ident.name + } _ => return, }; @@ -1717,7 +1719,7 @@ impl<'a> Resolver<'a> { Applicability::MaybeIncorrect, )), ) - } else if self.session.rust_2015() { + } else if self.session.is_rust_2015() { ( format!("maybe a missing crate `{ident}`?"), Some(( @@ -1996,7 +1998,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { mut path: Vec, parent_scope: &ParentScope<'b>, ) -> Option<(Vec, Option)> { - if path[1].ident.span.rust_2015() { + if path[1].ident.span.is_rust_2015() { return None; } diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 1c985d43658ae..d03ccf256fad7 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -85,7 +85,7 @@ impl<'a> Resolver<'a> { // 4c. Standard library prelude (de-facto closed, controlled). // 6. Language prelude: builtin attributes (closed, controlled). - let rust_2015 = ctxt.edition().rust_2015(); + let rust_2015 = ctxt.edition().is_rust_2015(); let (ns, macro_kind, is_absolute_path) = match scope_set { ScopeSet::All(ns, _) => (ns, None, false), ScopeSet::AbsolutePath(ns) => (ns, None, true), @@ -1397,7 +1397,8 @@ impl<'a> Resolver<'a> { module = Some(ModuleOrUniformRoot::ExternPrelude); continue; } - if name == kw::PathRoot && ident.span.rust_2015() && self.session.rust_2018() { + if name == kw::PathRoot && ident.span.is_rust_2015() && self.session.rust_2018() + { // `::a::b` from 2015 macro on 2018 global edition module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude); continue; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 83932c089b311..3ca10ac50baa6 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2145,7 +2145,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { let segments = &use_tree.prefix.segments; if !segments.is_empty() { let ident = segments[0].ident; - if ident.is_path_segment_keyword() || ident.span.rust_2015() { + if ident.is_path_segment_keyword() || ident.span.is_rust_2015() { return; } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 37beff37c1fb9..cee0a7f3c203d 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1343,7 +1343,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { "!", Applicability::MaybeIncorrect, ); - if path_str == "try" && span.rust_2015() { + if path_str == "try" && span.is_rust_2015() { err.note("if you want the `try` keyword, you need Rust 2018 or later"); } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 3b2cd1864c518..6d3a19b981a83 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -919,8 +919,8 @@ impl Session { } /// Is this edition 2015? - pub fn rust_2015(&self) -> bool { - self.edition().rust_2015() + pub fn is_rust_2015(&self) -> bool { + self.edition().is_rust_2015() } /// Are we allowed to use features from the Rust 2018 edition? diff --git a/compiler/rustc_span/src/edition.rs b/compiler/rustc_span/src/edition.rs index e66ec07904341..f16db69aae232 100644 --- a/compiler/rustc_span/src/edition.rs +++ b/compiler/rustc_span/src/edition.rs @@ -77,7 +77,7 @@ impl Edition { } /// Is this edition 2015? - pub fn rust_2015(self) -> bool { + pub fn is_rust_2015(self) -> bool { self == Edition::Edition2015 } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 006102a5f2fcf..e095cf3fda20d 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -705,8 +705,8 @@ impl Span { } #[inline] - pub fn rust_2015(self) -> bool { - self.edition().rust_2015() + pub fn is_rust_2015(self) -> bool { + self.edition().is_rust_2015() } #[inline] From 7f8bf600179339f582e19bbe25d9aefda69cc869 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 1 Feb 2023 10:44:59 +0000 Subject: [PATCH 07/11] Use `rust_2018` instead of `!is_rust_2015` --- compiler/rustc_parse/src/parser/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 12abec0ff9deb..55b24ab9ad13e 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -702,7 +702,7 @@ impl<'a> Parser<'a> { /// Is a `dyn B0 + ... + Bn` type allowed here? fn is_explicit_dyn_type(&mut self) -> bool { self.check_keyword(kw::Dyn) - && (!self.token.uninterpolated_span().is_rust_2015() + && (self.token.uninterpolated_span().rust_2018() || self.look_ahead(1, |t| { (t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star)) && !can_continue_type_after_non_fn_ident(t) From 63f82db9584d72fa042641ed4ef970cfe701356d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 31 Jan 2023 21:23:23 +0100 Subject: [PATCH 08/11] Inline CSS background images directly into the CSS --- src/librustdoc/html/static/css/rustdoc.css | 17 +++++++++++++---- .../html/static/images/down-arrow.svg | 1 - .../html/static/images/toggle-minus.svg | 1 - .../html/static/images/toggle-plus.svg | 1 - src/librustdoc/html/static_files.rs | 3 --- 5 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 src/librustdoc/html/static/images/down-arrow.svg delete mode 100644 src/librustdoc/html/static/images/toggle-minus.svg delete mode 100644 src/librustdoc/html/static/images/toggle-plus.svg diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index c8ab3ef70d7b7..70c60aa25faa9 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -806,8 +806,11 @@ so that we can apply CSS-filters to change the arrow color in themes */ background-repeat: no-repeat; background-size: 20px; background-position: calc(100% - 2px) 56%; - /* image is black color */ - background-image: url("down-arrow-927217e04c7463ac.svg"); + /* down arrow (image is black color) */ + background-image: url('data:image/svg+xml, \ + '); /* changes the arrow image color */ filter: var(--crate-search-div-filter); } @@ -1440,7 +1443,10 @@ details.toggle > summary.hideme > span { } details.toggle > summary::before { - background: url("toggle-plus-1092eb4930d581b0.svg") no-repeat top left; + /* toggle plus */ + background: url('data:image/svg+xml,') no-repeat top left; content: ""; cursor: pointer; width: 16px; @@ -1518,7 +1524,10 @@ details.toggle[open] > summary.hideme > span { } details.toggle[open] > summary::before { - background: url("toggle-minus-31bbd6e4c77f5c96.svg") no-repeat top left; + /* toggle minus */ + background: url('data:image/svg+xml,') no-repeat top left; } details.toggle[open] > summary::after { diff --git a/src/librustdoc/html/static/images/down-arrow.svg b/src/librustdoc/html/static/images/down-arrow.svg deleted file mode 100644 index 5d76a64e92c70..0000000000000 --- a/src/librustdoc/html/static/images/down-arrow.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static/images/toggle-minus.svg b/src/librustdoc/html/static/images/toggle-minus.svg deleted file mode 100644 index 73154788a0e8e..0000000000000 --- a/src/librustdoc/html/static/images/toggle-minus.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static/images/toggle-plus.svg b/src/librustdoc/html/static/images/toggle-plus.svg deleted file mode 100644 index 08b17033e164b..0000000000000 --- a/src/librustdoc/html/static/images/toggle-plus.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index b48b82307ebc3..767b974cc9109 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -102,9 +102,6 @@ static_files! { scrape_examples_js => "static/js/scrape-examples.js", wheel_svg => "static/images/wheel.svg", clipboard_svg => "static/images/clipboard.svg", - down_arrow_svg => "static/images/down-arrow.svg", - toggle_minus_png => "static/images/toggle-minus.svg", - toggle_plus_png => "static/images/toggle-plus.svg", copyright => "static/COPYRIGHT.txt", license_apache => "static/LICENSE-APACHE.txt", license_mit => "static/LICENSE-MIT.txt", From fb3857808253c3513ffff1f2c2b033081ae24cf5 Mon Sep 17 00:00:00 2001 From: Joseph Ryan Date: Wed, 1 Feb 2023 13:35:36 -0800 Subject: [PATCH 09/11] Add proc-macro boilerplate to crt-static test --- tests/ui/proc-macro/crt-static.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ui/proc-macro/crt-static.rs b/tests/ui/proc-macro/crt-static.rs index 6103acb7b6bd9..020128fa21446 100644 --- a/tests/ui/proc-macro/crt-static.rs +++ b/tests/ui/proc-macro/crt-static.rs @@ -5,6 +5,9 @@ // ignore-wasm32 // ignore-sgx no support for proc-macro crate type // build-pass +// force-host +// no-prefer-dynamic + #![crate_type = "proc-macro"] // FIXME: This don't work when crate-type is specified by attribute From 619de1bdc6462faf0e05995fe7040416ecd1bc0a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 30 Jan 2023 18:08:50 +0000 Subject: [PATCH 10/11] Revert "Teach parser to understand fake anonymous enum syntax" and related commits Revert "review comment: Remove AST AnonTy" This reverts commit 020cca8d36cb678e3ddc2ead41364be314d19e93. Revert "Ensure macros are not affected" This reverts commit 12d18e403139eeeeb339e8611b2bed4910864edb. Revert "Emit fewer errors on patterns with possible type ascription" This reverts commit c847a01a3b1f620c4fdb98c75805033e768975d1. Revert "Teach parser to understand fake anonymous enum syntax" This reverts commit 2d824206655bfb26cb5eed43490ee396542b153e. --- compiler/rustc_ast/src/visit.rs | 4 +- .../rustc_parse/src/parser/diagnostics.rs | 52 +++--------- compiler/rustc_parse/src/parser/pat.rs | 3 +- compiler/rustc_parse/src/parser/ty.rs | 65 +-------------- tests/ui/parser/anon-enums.rs | 17 ---- tests/ui/parser/anon-enums.stderr | 68 ---------------- tests/ui/parser/fake-anon-enums-in-macros.rs | 20 ----- .../issues/issue-87086-colon-path-sep.rs | 1 + .../issues/issue-87086-colon-path-sep.stderr | 81 ++++++------------- 9 files changed, 46 insertions(+), 265 deletions(-) delete mode 100644 tests/ui/parser/anon-enums.rs delete mode 100644 tests/ui/parser/anon-enums.stderr delete mode 100644 tests/ui/parser/fake-anon-enums-in-macros.rs diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index e7b2e4b1cb4b0..bdb1879ec201d 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -403,8 +403,8 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref); visitor.visit_ty(&mutable_type.ty) } - TyKind::Tup(tys) => { - walk_list!(visitor, visit_ty, tys); + TyKind::Tup(tuple_element_types) => { + walk_list!(visitor, visit_ty, tuple_element_types); } TyKind::BareFn(function_declaration) => { walk_list!(visitor, visit_generic_param, &function_declaration.generic_params); diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f4c08031bcca0..6596a06afab65 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2394,7 +2394,7 @@ impl<'a> Parser<'a> { /// Some special error handling for the "top-level" patterns in a match arm, /// `for` loop, `let`, &c. (in contrast to subpatterns within such). - pub(crate) fn maybe_recover_colon_colon_in_pat_typo_or_anon_enum( + pub(crate) fn maybe_recover_colon_colon_in_pat_typo( &mut self, mut first_pat: P, expected: Expected, @@ -2405,41 +2405,26 @@ impl<'a> Parser<'a> { if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..)) || !self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident()) { - let mut snapshot_type = self.create_snapshot_for_diagnostic(); - snapshot_type.bump(); // `:` - match snapshot_type.parse_ty() { - Err(inner_err) => { - inner_err.cancel(); - } - Ok(ty) => { - let Err(mut err) = self.expected_one_of_not_found(&[], &[]) else { - return first_pat; - }; - err.span_label(ty.span, "specifying the type of a pattern isn't supported"); - self.restore_snapshot(snapshot_type); - let span = first_pat.span.to(ty.span); - first_pat = self.mk_pat(span, PatKind::Wild); - err.emit(); - } - } return first_pat; } // The pattern looks like it might be a path with a `::` -> `:` typo: // `match foo { bar:baz => {} }` - let colon_span = self.token.span; + let span = self.token.span; // We only emit "unexpected `:`" error here if we can successfully parse the // whole pattern correctly in that case. - let mut snapshot_pat = self.create_snapshot_for_diagnostic(); - let mut snapshot_type = self.create_snapshot_for_diagnostic(); + let snapshot = self.create_snapshot_for_diagnostic(); // Create error for "unexpected `:`". match self.expected_one_of_not_found(&[], &[]) { Err(mut err) => { - snapshot_pat.bump(); // Skip the `:`. - snapshot_type.bump(); // Skip the `:`. - match snapshot_pat.parse_pat_no_top_alt(expected) { + self.bump(); // Skip the `:`. + match self.parse_pat_no_top_alt(expected) { Err(inner_err) => { + // Carry on as if we had not done anything, callers will emit a + // reasonable error. inner_err.cancel(); + err.cancel(); + self.restore_snapshot(snapshot); } Ok(mut pat) => { // We've parsed the rest of the pattern. @@ -2503,8 +2488,8 @@ impl<'a> Parser<'a> { _ => {} } if show_sugg { - err.span_suggestion_verbose( - colon_span.until(self.look_ahead(1, |t| t.span)), + err.span_suggestion( + span, "maybe write a path separator here", "::", Applicability::MaybeIncorrect, @@ -2512,24 +2497,13 @@ impl<'a> Parser<'a> { } else { first_pat = self.mk_pat(new_span, PatKind::Wild); } - self.restore_snapshot(snapshot_pat); + err.emit(); } } - match snapshot_type.parse_ty() { - Err(inner_err) => { - inner_err.cancel(); - } - Ok(ty) => { - err.span_label(ty.span, "specifying the type of a pattern isn't supported"); - self.restore_snapshot(snapshot_type); - let new_span = first_pat.span.to(ty.span); - first_pat = self.mk_pat(new_span, PatKind::Wild); - } - } - err.emit(); } _ => { // Carry on as if we had not done anything. This should be unreachable. + self.restore_snapshot(snapshot); } }; first_pat diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 912f7cc14f6cc..0a13fd7fd4368 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -118,8 +118,7 @@ impl<'a> Parser<'a> { // Check if the user wrote `foo:bar` instead of `foo::bar`. if ra == RecoverColon::Yes { - first_pat = - self.maybe_recover_colon_colon_in_pat_typo_or_anon_enum(first_pat, expected); + first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, expected); } if let Some(leading_vert_span) = leading_vert_span { diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 8b4f0ab8feb84..d7cf7af82ceab 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -11,7 +11,6 @@ use rustc_ast::{ self as ast, BareFnTy, FnRetTy, GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef, TraitBoundModifier, TraitObjectSyntax, Ty, TyKind, }; -use rustc_ast_pretty::pprust; use rustc_errors::{pluralize, struct_span_err, Applicability, PResult}; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym, Ident}; @@ -44,24 +43,17 @@ pub(super) enum AllowPlus { No, } -#[derive(PartialEq, Clone, Copy)] +#[derive(PartialEq)] pub(super) enum RecoverQPath { Yes, No, } -#[derive(PartialEq, Clone, Copy)] pub(super) enum RecoverQuestionMark { Yes, No, } -#[derive(PartialEq, Clone, Copy)] -pub(super) enum RecoverAnonEnum { - Yes, - No, -} - /// Signals whether parsing a type should recover `->`. /// /// More specifically, when parsing a function like: @@ -94,7 +86,7 @@ impl RecoverReturnSign { } // Is `...` (`CVarArgs`) legal at this level of type parsing? -#[derive(PartialEq, Clone, Copy)] +#[derive(PartialEq)] enum AllowCVariadic { Yes, No, @@ -119,7 +111,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::No, ) } @@ -134,7 +125,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, Some(ty_params), RecoverQuestionMark::Yes, - RecoverAnonEnum::No, ) } @@ -149,7 +139,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::Yes, ) } @@ -167,7 +156,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::No, ) } @@ -181,7 +169,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, None, RecoverQuestionMark::No, - RecoverAnonEnum::No, ) } @@ -193,7 +180,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::Yes, None, RecoverQuestionMark::No, - RecoverAnonEnum::No, ) } @@ -206,7 +192,6 @@ impl<'a> Parser<'a> { RecoverReturnSign::OnlyFatArrow, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::No, ) } @@ -226,7 +211,6 @@ impl<'a> Parser<'a> { recover_return_sign, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::Yes, )?; FnRetTy::Ty(ty) } else if recover_return_sign.can_recover(&self.token.kind) { @@ -248,7 +232,6 @@ impl<'a> Parser<'a> { recover_return_sign, None, RecoverQuestionMark::Yes, - RecoverAnonEnum::Yes, )?; FnRetTy::Ty(ty) } else { @@ -264,7 +247,6 @@ impl<'a> Parser<'a> { recover_return_sign: RecoverReturnSign, ty_generics: Option<&Generics>, recover_question_mark: RecoverQuestionMark, - recover_anon_enum: RecoverAnonEnum, ) -> PResult<'a, P> { let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); @@ -348,50 +330,9 @@ impl<'a> Parser<'a> { AllowPlus::Yes => self.maybe_recover_from_bad_type_plus(&ty)?, AllowPlus::No => self.maybe_report_ambiguous_plus(impl_dyn_multi, &ty), } - if RecoverQuestionMark::Yes == recover_question_mark { + if let RecoverQuestionMark::Yes = recover_question_mark { ty = self.maybe_recover_from_question_mark(ty); } - if recover_anon_enum == RecoverAnonEnum::Yes - && self.check_noexpect(&token::BinOp(token::Or)) - && self.look_ahead(1, |t| t.can_begin_type()) - { - let mut pipes = vec![self.token.span]; - let mut types = vec![ty]; - loop { - if !self.eat(&token::BinOp(token::Or)) { - break; - } - pipes.push(self.prev_token.span); - types.push(self.parse_ty_common( - allow_plus, - allow_c_variadic, - recover_qpath, - recover_return_sign, - ty_generics, - recover_question_mark, - RecoverAnonEnum::No, - )?); - } - let mut err = self.struct_span_err(pipes, "anonymous enums are not supported"); - for ty in &types { - err.span_label(ty.span, ""); - } - err.help(&format!( - "create a named `enum` and use it here instead:\nenum Name {{\n{}\n}}", - types - .iter() - .enumerate() - .map(|(i, t)| format!( - " Variant{}({}),", - i + 1, // Lets not confuse people with zero-indexing :) - pprust::to_string(|s| s.print_type(&t)), - )) - .collect::>() - .join("\n"), - )); - err.emit(); - return Ok(self.mk_ty(lo.to(self.prev_token.span), TyKind::Err)); - } if allow_qpath_recovery { self.maybe_recover_from_bad_qpath(ty) } else { Ok(ty) } } diff --git a/tests/ui/parser/anon-enums.rs b/tests/ui/parser/anon-enums.rs deleted file mode 100644 index 56b8a3d43bedf..0000000000000 --- a/tests/ui/parser/anon-enums.rs +++ /dev/null @@ -1,17 +0,0 @@ -fn foo(x: bool | i32) -> i32 | f64 { -//~^ ERROR anonymous enums are not supported -//~| ERROR anonymous enums are not supported - match x { - x: i32 => x, //~ ERROR expected - true => 42., - false => 0.333, - } -} - -fn main() { - match foo(true) { - 42: i32 => (), //~ ERROR expected - _: f64 => (), //~ ERROR expected - x: i32 => (), //~ ERROR expected - } -} diff --git a/tests/ui/parser/anon-enums.stderr b/tests/ui/parser/anon-enums.stderr deleted file mode 100644 index 8415822566091..0000000000000 --- a/tests/ui/parser/anon-enums.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error: anonymous enums are not supported - --> $DIR/anon-enums.rs:1:16 - | -LL | fn foo(x: bool | i32) -> i32 | f64 { - | ---- ^ --- - | - = help: create a named `enum` and use it here instead: - enum Name { - Variant1(bool), - Variant2(i32), - } - -error: anonymous enums are not supported - --> $DIR/anon-enums.rs:1:30 - | -LL | fn foo(x: bool | i32) -> i32 | f64 { - | --- ^ --- - | - = help: create a named `enum` and use it here instead: - enum Name { - Variant1(i32), - Variant2(f64), - } - -error: expected one of `@` or `|`, found `:` - --> $DIR/anon-enums.rs:5:10 - | -LL | x: i32 => x, - | ^ --- specifying the type of a pattern isn't supported - | | - | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | x::i32 => x, - | ~~ - -error: expected one of `...`, `..=`, `..`, or `|`, found `:` - --> $DIR/anon-enums.rs:13:11 - | -LL | 42: i32 => (), - | ^ --- specifying the type of a pattern isn't supported - | | - | expected one of `...`, `..=`, `..`, or `|` - -error: expected `|`, found `:` - --> $DIR/anon-enums.rs:14:10 - | -LL | _: f64 => (), - | ^ --- specifying the type of a pattern isn't supported - | | - | expected `|` - -error: expected one of `@` or `|`, found `:` - --> $DIR/anon-enums.rs:15:10 - | -LL | x: i32 => (), - | ^ --- specifying the type of a pattern isn't supported - | | - | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | x::i32 => (), - | ~~ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/parser/fake-anon-enums-in-macros.rs b/tests/ui/parser/fake-anon-enums-in-macros.rs deleted file mode 100644 index 38fe8dee23829..0000000000000 --- a/tests/ui/parser/fake-anon-enums-in-macros.rs +++ /dev/null @@ -1,20 +0,0 @@ -// build-pass -macro_rules! check_ty { - ($Z:ty) => { compile_error!("triggered"); }; - ($X:ty | $Y:ty) => { $X }; -} - -macro_rules! check { - ($Z:ty) => { compile_error!("triggered"); }; - ($X:ty | $Y:ty) => { }; -} - -check! { i32 | u8 } - -fn foo(x: check_ty! { i32 | u8 }) -> check_ty! { i32 | u8 } { - x -} -fn main() { - let x: check_ty! { i32 | u8 } = 42; - let _: check_ty! { i32 | u8 } = foo(x); -} diff --git a/tests/ui/parser/issues/issue-87086-colon-path-sep.rs b/tests/ui/parser/issues/issue-87086-colon-path-sep.rs index e1ea38f2795df..0b7b67496d6f3 100644 --- a/tests/ui/parser/issues/issue-87086-colon-path-sep.rs +++ b/tests/ui/parser/issues/issue-87086-colon-path-sep.rs @@ -68,6 +68,7 @@ fn main() { Foo:Bar::Baz => {} //~^ ERROR: expected one of //~| HELP: maybe write a path separator here + //~| ERROR: failed to resolve: `Bar` is a variant, not a module } match myfoo { Foo::Bar => {} diff --git a/tests/ui/parser/issues/issue-87086-colon-path-sep.stderr b/tests/ui/parser/issues/issue-87086-colon-path-sep.stderr index 63b072ac4cdc6..2050a16beb349 100644 --- a/tests/ui/parser/issues/issue-87086-colon-path-sep.stderr +++ b/tests/ui/parser/issues/issue-87086-colon-path-sep.stderr @@ -2,118 +2,89 @@ error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:17:12 | LL | Foo:Bar => {} - | ^--- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | Foo::Bar => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `!`, `(`, `...`, `..=`, `..`, `::`, `{`, or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:23:17 | LL | qux::Foo:Bar => {} - | ^--- specifying the type of a pattern isn't supported + | ^ | | | expected one of 8 possible tokens - | -help: maybe write a path separator here - | -LL | qux::Foo::Bar => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:29:12 | LL | qux:Foo::Baz => {} - | ^-------- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | qux::Foo::Baz => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:35:12 | LL | qux: Foo::Baz if true => {} - | ^ -------- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | qux::Foo::Baz if true => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:40:15 | LL | if let Foo:Bar = f() { - | ^--- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | if let Foo::Bar = f() { - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:48:16 | LL | ref qux: Foo::Baz => {} - | ^ -------- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | ref qux::Foo::Baz => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:57:16 | LL | mut qux: Foo::Baz => {} - | ^ -------- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | mut qux::Foo::Baz => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` --> $DIR/issue-87086-colon-path-sep.rs:68:12 | LL | Foo:Bar::Baz => {} - | ^-------- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` - | -help: maybe write a path separator here - | -LL | Foo::Bar::Baz => {} - | ~~ + | help: maybe write a path separator here: `::` error: expected one of `@` or `|`, found `:` - --> $DIR/issue-87086-colon-path-sep.rs:74:12 + --> $DIR/issue-87086-colon-path-sep.rs:75:12 | LL | Foo:Bar => {} - | ^--- specifying the type of a pattern isn't supported + | ^ | | | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error[E0433]: failed to resolve: `Bar` is a variant, not a module + --> $DIR/issue-87086-colon-path-sep.rs:68:13 | -help: maybe write a path separator here - | -LL | Foo::Bar => {} - | ~~ +LL | Foo:Bar::Baz => {} + | ^^^ `Bar` is a variant, not a module -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors +For more information about this error, try `rustc --explain E0433`. From 250f530385322494add1d78bcb4b404054b9fe2a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 30 Jan 2023 18:39:33 +0000 Subject: [PATCH 11/11] Add a test --- tests/ui/parser/anon-enums-are-ambiguous.rs | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/ui/parser/anon-enums-are-ambiguous.rs diff --git a/tests/ui/parser/anon-enums-are-ambiguous.rs b/tests/ui/parser/anon-enums-are-ambiguous.rs new file mode 100644 index 0000000000000..b0173cf98e0a6 --- /dev/null +++ b/tests/ui/parser/anon-enums-are-ambiguous.rs @@ -0,0 +1,26 @@ +// check-pass + +macro_rules! test_expr { + ($expr:expr) => {}; +} + +macro_rules! test_ty { + ($a:ty | $b:ty) => {}; +} + +fn main() { + test_expr!(a as fn() -> B | C); + // Do not break the `|` operator. + + test_expr!(|_: fn() -> B| C | D); + // Do not break `-> Ret` in closure args. + + test_ty!(A | B); + // We can't support anon enums in arbitrary positions. + + test_ty!(fn() -> A | B); + // Don't break fn ptrs. + + test_ty!(impl Fn() -> A | B); + // Don't break parenthesized generics. +}