From c824399d74feee7f00e4b8d75f9dd85c633193f9 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 4 Jan 2024 13:08:38 -0800 Subject: [PATCH 01/13] Fix broken markdown in csky-unknown-linux-gnuabiv2.md --- .../rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md b/src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md index a54abcb606ea7..e72bfb8bae767 100644 --- a/src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md +++ b/src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md @@ -50,6 +50,7 @@ cc = "${TOOLCHAIN_PATH}/bin/csky-linux-gnuabiv2-gcc" [target.csky-unknown-linux-gnuabiv2hf] # ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN cc = "${TOOLCHAIN_PATH}/bin/csky-linux-gnuabiv2-gcc" +``` ### Build From 933e33496362e053a5cae5da76f151eb581936f1 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 24 Dec 2023 18:34:20 -0500 Subject: [PATCH 02/13] remove dead code in CGREP script --- src/etc/cat-and-grep.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/etc/cat-and-grep.sh b/src/etc/cat-and-grep.sh index 238f7f5b66027..68c6993ac15ef 100755 --- a/src/etc/cat-and-grep.sh +++ b/src/etc/cat-and-grep.sh @@ -33,7 +33,6 @@ while getopts ':vieh' OPTION; do case "$OPTION" in v) INVERT=1 - ERROR_MSG='should not be found' ;; i) GREPFLAGS="i$GREPFLAGS" From 19ca3079c2269ecb9bedc8033e66b1831dbafaf1 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 24 Dec 2023 18:34:31 -0500 Subject: [PATCH 03/13] give a better error for tuple structs in `derive(Diagnostic)` --- .../src/diagnostics/diagnostic_builder.rs | 5 +- .../rustc_macros/src/diagnostics/error.rs | 2 +- .../rustc_macros/src/diagnostics/utils.rs | 2 +- .../diagnostic-derive.stderr | 134 +++++++++--------- .../enforce_slug_naming.stderr | 2 +- .../subdiagnostic-derive.stderr | 134 +++++++++--------- 6 files changed, 141 insertions(+), 138 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 0b7ecff8148b3..019ba08ad4c0d 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -249,7 +249,10 @@ impl DiagnosticDeriveVariantBuilder { let mut field_binding = binding_info.binding.clone(); field_binding.set_span(field.ty.span()); - let ident = field.ident.as_ref().unwrap(); + let Some(ident) = field.ident.as_ref() else { + span_err(field.span().unwrap(), "tuple structs are not supported").emit(); + return TokenStream::new(); + }; let ident = format_ident!("{}", ident); // strip `r#` prefix, if present quote! { diff --git a/compiler/rustc_macros/src/diagnostics/error.rs b/compiler/rustc_macros/src/diagnostics/error.rs index 84b18a6202814..aba01340fd59b 100644 --- a/compiler/rustc_macros/src/diagnostics/error.rs +++ b/compiler/rustc_macros/src/diagnostics/error.rs @@ -55,7 +55,7 @@ fn path_to_string(path: &syn::Path) -> String { /// Returns an error diagnostic on span `span` with msg `msg`. #[must_use] pub(crate) fn span_err>(span: impl MultiSpan, msg: T) -> Diagnostic { - Diagnostic::spanned(span, Level::Error, msg) + Diagnostic::spanned(span, Level::Error, format!("derive(Diagnostic): {}", msg.into())) } /// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index 4684306e23592..3c59e610f66a1 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -242,7 +242,7 @@ impl SetOnce for SpannedOption { *self = Some((value, span)); } Some((_, prev_span)) => { - span_err(span, "specified multiple times") + span_err(span, "attribute specified multiple times") .span_note(*prev_span, "previously specified here") .emit(); } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index f376c034587fa..92cc71489364e 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -1,10 +1,10 @@ -error: unsupported type attribute for diagnostic derive enum +error: derive(Diagnostic): unsupported type attribute for diagnostic derive enum --> $DIR/diagnostic-derive.rs:43:1 | LL | #[diag(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:46:5 | LL | Foo, @@ -12,7 +12,7 @@ LL | Foo, | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:48:5 | LL | Bar, @@ -20,13 +20,13 @@ LL | Bar, | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: `#[nonsense(...)]` is not a valid attribute +error: derive(Diagnostic): `#[nonsense(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:59:1 | LL | #[nonsense(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:59:1 | LL | / #[nonsense(no_crate_example, code = "E0123")] @@ -38,7 +38,7 @@ LL | | struct InvalidStructAttr {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:66:1 | LL | / #[diag("E0123")] @@ -48,13 +48,13 @@ LL | | struct InvalidLitNestedAttr {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: diagnostic slug must be the first argument +error: derive(Diagnostic): diagnostic slug must be the first argument --> $DIR/diagnostic-derive.rs:76:16 | LL | #[diag(nonsense("foo"), code = "E0123", slug = "foo")] | ^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:76:1 | LL | / #[diag(nonsense("foo"), code = "E0123", slug = "foo")] @@ -65,7 +65,7 @@ LL | | struct InvalidNestedStructAttr1 {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: unknown argument +error: derive(Diagnostic): unknown argument --> $DIR/diagnostic-derive.rs:82:8 | LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] @@ -73,7 +73,7 @@ LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] | = note: only the `code` parameter is valid after the slug -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:82:1 | LL | / #[diag(nonsense = "...", code = "E0123", slug = "foo")] @@ -84,7 +84,7 @@ LL | | struct InvalidNestedStructAttr2 {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: unknown argument +error: derive(Diagnostic): unknown argument --> $DIR/diagnostic-derive.rs:88:8 | LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] @@ -92,7 +92,7 @@ LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] | = note: only the `code` parameter is valid after the slug -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:88:1 | LL | / #[diag(nonsense = 4, code = "E0123", slug = "foo")] @@ -103,7 +103,7 @@ LL | | struct InvalidNestedStructAttr3 {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: unknown argument +error: derive(Diagnostic): unknown argument --> $DIR/diagnostic-derive.rs:94:42 | LL | #[diag(no_crate_example, code = "E0123", slug = "foo")] @@ -111,13 +111,13 @@ LL | #[diag(no_crate_example, code = "E0123", slug = "foo")] | = note: only the `code` parameter is valid after the slug -error: `#[suggestion = ...]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion = ...]` is not a valid attribute --> $DIR/diagnostic-derive.rs:101:5 | LL | #[suggestion = "bar"] | ^^^^^^^^^^^^^^^^^^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:108:8 | LL | #[diag(no_crate_example, code = "E0456")] @@ -129,7 +129,7 @@ note: previously specified here LL | #[diag(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:108:26 | LL | #[diag(no_crate_example, code = "E0456")] @@ -141,7 +141,7 @@ note: previously specified here LL | #[diag(no_crate_example, code = "E0123")] | ^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:114:42 | LL | #[diag(no_crate_example, code = "E0456", code = "E0457")] @@ -153,13 +153,13 @@ note: previously specified here LL | #[diag(no_crate_example, code = "E0456", code = "E0457")] | ^^^^ -error: diagnostic slug must be the first argument +error: derive(Diagnostic): diagnostic slug must be the first argument --> $DIR/diagnostic-derive.rs:119:43 | LL | #[diag(no_crate_example, no_crate::example, code = "E0456")] | ^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:124:1 | LL | struct KindNotProvided {} @@ -167,7 +167,7 @@ LL | struct KindNotProvided {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:127:1 | LL | / #[diag(code = "E0456")] @@ -177,25 +177,25 @@ LL | | struct SlugNotProvided {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/diagnostic-derive.rs:138:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ -error: `#[nonsense]` is not a valid attribute +error: derive(Diagnostic): `#[nonsense]` is not a valid attribute --> $DIR/diagnostic-derive.rs:146:5 | LL | #[nonsense] | ^^^^^^^^^^^ -error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/diagnostic-derive.rs:163:5 | LL | #[label(no_crate_label)] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: `name` doesn't refer to a field on this type +error: derive(Diagnostic): `name` doesn't refer to a field on this type --> $DIR/diagnostic-derive.rs:171:46 | LL | #[suggestion(no_crate_suggestion, code = "{name}")] @@ -219,19 +219,19 @@ LL | #[derive(Diagnostic)] = note: if you intended to print `}`, you can escape it using `}}` = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/diagnostic-derive.rs:206:5 | LL | #[label(no_crate_label)] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: suggestion without `code = "..."` +error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:225:5 | LL | #[suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: invalid nested attribute +error: derive(Diagnostic): invalid nested attribute --> $DIR/diagnostic-derive.rs:233:18 | LL | #[suggestion(nonsense = "bar")] @@ -239,13 +239,13 @@ LL | #[suggestion(nonsense = "bar")] | = help: only `no_span`, `style`, `code` and `applicability` are valid nested attributes -error: suggestion without `code = "..."` +error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:233:5 | LL | #[suggestion(nonsense = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: invalid nested attribute +error: derive(Diagnostic): invalid nested attribute --> $DIR/diagnostic-derive.rs:242:18 | LL | #[suggestion(msg = "bar")] @@ -253,13 +253,13 @@ LL | #[suggestion(msg = "bar")] | = help: only `no_span`, `style`, `code` and `applicability` are valid nested attributes -error: suggestion without `code = "..."` +error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:242:5 | LL | #[suggestion(msg = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: wrong field type for suggestion +error: derive(Diagnostic): wrong field type for suggestion --> $DIR/diagnostic-derive.rs:265:5 | LL | / #[suggestion(no_crate_suggestion, code = "This is suggested code")] @@ -269,7 +269,7 @@ LL | | suggestion: Applicability, | = help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)` -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:281:24 | LL | suggestion: (Span, Span, Applicability), @@ -281,7 +281,7 @@ note: previously specified here LL | suggestion: (Span, Span, Applicability), | ^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:289:33 | LL | suggestion: (Applicability, Applicability, Span), @@ -293,13 +293,13 @@ note: previously specified here LL | suggestion: (Applicability, Applicability, Span), | ^^^^^^^^^^^^^ -error: `#[label = ...]` is not a valid attribute +error: derive(Diagnostic): `#[label = ...]` is not a valid attribute --> $DIR/diagnostic-derive.rs:296:5 | LL | #[label = "bar"] | ^^^^^^^^^^^^^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:447:5 | LL | #[suggestion(no_crate_suggestion, code = "...", applicability = "maybe-incorrect")] @@ -311,37 +311,37 @@ note: previously specified here LL | suggestion: (Span, Applicability), | ^^^^^^^^^^^^^ -error: invalid applicability +error: derive(Diagnostic): invalid applicability --> $DIR/diagnostic-derive.rs:455:69 | LL | #[suggestion(no_crate_suggestion, code = "...", applicability = "batman")] | ^^^^^^^^ -error: the `#[help(...)]` attribute can only be applied to fields of type `Span`, `MultiSpan`, `bool` or `()` +error: derive(Diagnostic): the `#[help(...)]` attribute can only be applied to fields of type `Span`, `MultiSpan`, `bool` or `()` --> $DIR/diagnostic-derive.rs:522:5 | LL | #[help(no_crate_help)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: a diagnostic slug must be the first argument to the attribute +error: derive(Diagnostic): a diagnostic slug must be the first argument to the attribute --> $DIR/diagnostic-derive.rs:531:32 | LL | #[label(no_crate_label, foo)] | ^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/diagnostic-derive.rs:539:29 | LL | #[label(no_crate_label, foo = "...")] | ^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/diagnostic-derive.rs:547:29 | LL | #[label(no_crate_label, foo("..."))] | ^^^ -error: `#[primary_span]` is not a valid attribute +error: derive(Diagnostic): `#[primary_span]` is not a valid attribute --> $DIR/diagnostic-derive.rs:559:5 | LL | #[primary_span] @@ -349,13 +349,13 @@ LL | #[primary_span] | = help: the `primary_span` field attribute is not valid for lint diagnostics -error: `#[error(...)]` is not a valid attribute +error: derive(Diagnostic): `#[error(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:579:1 | LL | #[error(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:579:1 | LL | / #[error(no_crate_example, code = "E0123")] @@ -367,13 +367,13 @@ LL | | struct ErrorAttribute {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: `#[warn_(...)]` is not a valid attribute +error: derive(Diagnostic): `#[warn_(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:586:1 | LL | #[warn_(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:586:1 | LL | / #[warn_(no_crate_example, code = "E0123")] @@ -385,13 +385,13 @@ LL | | struct WarnAttribute {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: `#[lint(...)]` is not a valid attribute +error: derive(Diagnostic): `#[lint(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:593:1 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:593:1 | LL | / #[lint(no_crate_example, code = "E0123")] @@ -403,13 +403,13 @@ LL | | struct LintAttributeOnSessionDiag {} | = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` -error: `#[lint(...)]` is not a valid attribute +error: derive(Diagnostic): `#[lint(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:600:1 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[lint(...)]` is not a valid attribute +error: derive(Diagnostic): `#[lint(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:600:1 | LL | #[lint(no_crate_example, code = "E0123")] @@ -417,7 +417,7 @@ LL | #[lint(no_crate_example, code = "E0123")] | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: diagnostic slug not specified +error: derive(Diagnostic): diagnostic slug not specified --> $DIR/diagnostic-derive.rs:600:1 | LL | / #[lint(no_crate_example, code = "E0123")] @@ -430,7 +430,7 @@ LL | | struct LintAttributeOnLintDiag {} | = help: specify the slug as the first argument to the attribute, such as `#[diag(compiletest_example)]` -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/diagnostic-derive.rs:610:53 | LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")] @@ -442,7 +442,7 @@ note: previously specified here LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")] | ^^^^ -error: wrong types for suggestion +error: derive(Diagnostic): wrong types for suggestion --> $DIR/diagnostic-derive.rs:619:24 | LL | suggestion: (Span, usize), @@ -450,7 +450,7 @@ LL | suggestion: (Span, usize), | = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` -error: wrong types for suggestion +error: derive(Diagnostic): wrong types for suggestion --> $DIR/diagnostic-derive.rs:627:17 | LL | suggestion: (Span,), @@ -458,13 +458,13 @@ LL | suggestion: (Span,), | = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` -error: suggestion without `code = "..."` +error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:634:5 | LL | #[suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[multipart_suggestion(...)]` is not a valid attribute +error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:641:1 | LL | #[multipart_suggestion(no_crate_suggestion)] @@ -472,7 +472,7 @@ LL | #[multipart_suggestion(no_crate_suggestion)] | = help: consider creating a `Subdiagnostic` instead -error: `#[multipart_suggestion(...)]` is not a valid attribute +error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:644:1 | LL | #[multipart_suggestion()] @@ -480,7 +480,7 @@ LL | #[multipart_suggestion()] | = help: consider creating a `Subdiagnostic` instead -error: `#[multipart_suggestion(...)]` is not a valid attribute +error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:648:5 | LL | #[multipart_suggestion(no_crate_suggestion)] @@ -488,7 +488,7 @@ LL | #[multipart_suggestion(no_crate_suggestion)] | = help: consider creating a `Subdiagnostic` instead -error: `#[suggestion(...)]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:656:1 | LL | #[suggestion(no_crate_suggestion, code = "...")] @@ -496,7 +496,7 @@ LL | #[suggestion(no_crate_suggestion, code = "...")] | = help: `#[label]` and `#[suggestion]` can only be applied to fields -error: `#[label]` is not a valid attribute +error: derive(Diagnostic): `#[label]` is not a valid attribute --> $DIR/diagnostic-derive.rs:665:1 | LL | #[label] @@ -504,31 +504,31 @@ LL | #[label] | = help: `#[label]` and `#[suggestion]` can only be applied to fields -error: `eager` is the only supported nested attribute for `subdiagnostic` +error: derive(Diagnostic): `eager` is the only supported nested attribute for `subdiagnostic` --> $DIR/diagnostic-derive.rs:699:7 | LL | #[subdiagnostic(bad)] | ^^^^^^^^^^^^^^^^^^ -error: `#[subdiagnostic = ...]` is not a valid attribute +error: derive(Diagnostic): `#[subdiagnostic = ...]` is not a valid attribute --> $DIR/diagnostic-derive.rs:707:5 | LL | #[subdiagnostic = "bad"] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: `eager` is the only supported nested attribute for `subdiagnostic` +error: derive(Diagnostic): `eager` is the only supported nested attribute for `subdiagnostic` --> $DIR/diagnostic-derive.rs:715:7 | LL | #[subdiagnostic(bad, bad)] | ^^^^^^^^^^^^^^^^^^^^^^^ -error: `eager` is the only supported nested attribute for `subdiagnostic` +error: derive(Diagnostic): `eager` is the only supported nested attribute for `subdiagnostic` --> $DIR/diagnostic-derive.rs:723:7 | LL | #[subdiagnostic("bad")] | ^^^^^^^^^^^^^^^^^^^^ -error: `#[subdiagnostic(...)]` is not a valid attribute +error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:731:5 | LL | #[subdiagnostic(eager)] @@ -536,19 +536,19 @@ LL | #[subdiagnostic(eager)] | = help: eager subdiagnostics are not supported on lints -error: expected at least one string literal for `code(...)` +error: derive(Diagnostic): expected at least one string literal for `code(...)` --> $DIR/diagnostic-derive.rs:789:23 | LL | #[suggestion(code())] | ^ -error: `code(...)` must contain only string literals +error: derive(Diagnostic): `code(...)` must contain only string literals --> $DIR/diagnostic-derive.rs:797:23 | LL | #[suggestion(code(foo))] | ^^^ -error: `#[suggestion(...)]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion(...)]` is not a valid attribute --> $DIR/diagnostic-derive.rs:821:5 | LL | #[suggestion(no_crate_suggestion, code = "")] diff --git a/tests/ui-fulldeps/session-diagnostic/enforce_slug_naming.stderr b/tests/ui-fulldeps/session-diagnostic/enforce_slug_naming.stderr index 4cdc24e6a6bc9..a0715c41599f3 100644 --- a/tests/ui-fulldeps/session-diagnostic/enforce_slug_naming.stderr +++ b/tests/ui-fulldeps/session-diagnostic/enforce_slug_naming.stderr @@ -1,4 +1,4 @@ -error: diagnostic slug and crate name do not match +error: derive(Diagnostic): diagnostic slug and crate name do not match --> $DIR/enforce_slug_naming.rs:22:8 | LL | #[diag(compiletest_example, code = "E0123")] diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr index 80bee3bd6e6c3..ffc3fcfa2425a 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr @@ -1,4 +1,4 @@ -error: label without `#[primary_span]` field +error: derive(Diagnostic): label without `#[primary_span]` field --> $DIR/subdiagnostic-derive.rs:51:1 | LL | / #[label(no_crate_example)] @@ -8,127 +8,127 @@ LL | | var: String, LL | | } | |_^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:58:1 | LL | #[label] | ^^^^^^^^ -error: `#[foo]` is not a valid attribute +error: derive(Diagnostic): `#[foo]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:67:1 | LL | #[foo] | ^^^^^^ -error: `#[label = ...]` is not a valid attribute +error: derive(Diagnostic): `#[label = ...]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:77:1 | LL | #[label = "..."] | ^^^^^^^^^^^^^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:86:9 | LL | #[label(bug = "...")] | ^^^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:86:1 | LL | #[label(bug = "...")] | ^^^^^^^^^^^^^^^^^^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:106:9 | LL | #[label(slug = 4)] | ^^^^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:106:1 | LL | #[label(slug = 4)] | ^^^^^^^^^^^^^^^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:116:9 | LL | #[label(slug("..."))] | ^^^^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:116:1 | LL | #[label(slug("..."))] | ^^^^^^^^^^^^^^^^^^^^^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:136:1 | LL | #[label()] | ^^^^^^^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:145:27 | LL | #[label(no_crate_example, code = "...")] | ^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:154:27 | LL | #[label(no_crate_example, applicability = "machine-applicable")] | ^^^^^^^^^^^^^ -error: unsupported type attribute for subdiagnostic enum +error: derive(Diagnostic): unsupported type attribute for subdiagnostic enum --> $DIR/subdiagnostic-derive.rs:163:1 | LL | #[foo] | ^^^^^^ -error: `#[bar]` is not a valid attribute +error: derive(Diagnostic): `#[bar]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:177:5 | LL | #[bar] | ^^^^^^ -error: `#[bar = ...]` is not a valid attribute +error: derive(Diagnostic): `#[bar = ...]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:189:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ -error: `#[bar = ...]` is not a valid attribute +error: derive(Diagnostic): `#[bar = ...]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:201:5 | LL | #[bar = 4] | ^^^^^^^^^^ -error: `#[bar(...)]` is not a valid attribute +error: derive(Diagnostic): `#[bar(...)]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:213:5 | LL | #[bar("...")] | ^^^^^^^^^^^^^ -error: only `no_span` is a valid nested attribute +error: derive(Diagnostic): only `no_span` is a valid nested attribute --> $DIR/subdiagnostic-derive.rs:225:13 | LL | #[label(code = "...")] | ^^^^ -error: diagnostic slug must be first argument of a `#[label(...)]` attribute +error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label(...)]` attribute --> $DIR/subdiagnostic-derive.rs:225:5 | LL | #[label(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^ -error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/subdiagnostic-derive.rs:254:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ -error: label without `#[primary_span]` field +error: derive(Diagnostic): label without `#[primary_span]` field --> $DIR/subdiagnostic-derive.rs:251:1 | LL | / #[label(no_crate_example)] @@ -140,13 +140,13 @@ LL | | span: String, LL | | } | |_^ -error: `#[applicability]` is only valid on suggestions +error: derive(Diagnostic): `#[applicability]` is only valid on suggestions --> $DIR/subdiagnostic-derive.rs:264:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ -error: `#[bar]` is not a valid attribute +error: derive(Diagnostic): `#[bar]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:274:5 | LL | #[bar] @@ -154,13 +154,13 @@ LL | #[bar] | = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes -error: `#[bar = ...]` is not a valid attribute +error: derive(Diagnostic): `#[bar = ...]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:285:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ -error: `#[bar(...)]` is not a valid attribute +error: derive(Diagnostic): `#[bar(...)]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:296:5 | LL | #[bar("...")] @@ -168,13 +168,13 @@ LL | #[bar("...")] | = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes -error: a diagnostic slug must be the first argument to the attribute +error: derive(Diagnostic): a diagnostic slug must be the first argument to the attribute --> $DIR/subdiagnostic-derive.rs:328:44 | LL | #[label(no_crate_example, no_crate::example)] | ^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/subdiagnostic-derive.rs:341:5 | LL | #[primary_span] @@ -186,13 +186,13 @@ note: previously specified here LL | #[primary_span] | ^^^^^^^^^^^^^^^ -error: subdiagnostic kind not specified +error: derive(Diagnostic): subdiagnostic kind not specified --> $DIR/subdiagnostic-derive.rs:347:8 | LL | struct AG { | ^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/subdiagnostic-derive.rs:384:46 | LL | #[suggestion(no_crate_example, code = "...", code = "...")] @@ -204,7 +204,7 @@ note: previously specified here LL | #[suggestion(no_crate_example, code = "...", code = "...")] | ^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/subdiagnostic-derive.rs:402:5 | LL | #[applicability] @@ -216,25 +216,25 @@ note: previously specified here LL | #[applicability] | ^^^^^^^^^^^^^^^^ -error: the `#[applicability]` attribute can only be applied to fields of type `Applicability` +error: derive(Diagnostic): the `#[applicability]` attribute can only be applied to fields of type `Applicability` --> $DIR/subdiagnostic-derive.rs:412:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ -error: suggestion without `code = "..."` +error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/subdiagnostic-derive.rs:425:1 | LL | #[suggestion(no_crate_example)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: invalid applicability +error: derive(Diagnostic): invalid applicability --> $DIR/subdiagnostic-derive.rs:435:62 | LL | #[suggestion(no_crate_example, code = "...", applicability = "foo")] | ^^^^^ -error: suggestion without `#[primary_span]` field +error: derive(Diagnostic): suggestion without `#[primary_span]` field --> $DIR/subdiagnostic-derive.rs:453:1 | LL | / #[suggestion(no_crate_example, code = "...")] @@ -244,25 +244,25 @@ LL | | var: String, LL | | } | |_^ -error: unsupported type attribute for subdiagnostic enum +error: derive(Diagnostic): unsupported type attribute for subdiagnostic enum --> $DIR/subdiagnostic-derive.rs:467:1 | LL | #[label] | ^^^^^^^^ -error: `var` doesn't refer to a field on this type +error: derive(Diagnostic): `var` doesn't refer to a field on this type --> $DIR/subdiagnostic-derive.rs:487:39 | LL | #[suggestion(no_crate_example, code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ -error: `var` doesn't refer to a field on this type +error: derive(Diagnostic): `var` doesn't refer to a field on this type --> $DIR/subdiagnostic-derive.rs:506:43 | LL | #[suggestion(no_crate_example, code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ -error: `#[suggestion_part]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion_part]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:529:5 | LL | #[suggestion_part] @@ -270,7 +270,7 @@ LL | #[suggestion_part] | = help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead -error: `#[suggestion_part(...)]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion_part(...)]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:532:5 | LL | #[suggestion_part(code = "...")] @@ -278,7 +278,7 @@ LL | #[suggestion_part(code = "...")] | = help: `#[suggestion_part(...)]` is only valid in multipart suggestions -error: suggestion without `#[primary_span]` field +error: derive(Diagnostic): suggestion without `#[primary_span]` field --> $DIR/subdiagnostic-derive.rs:526:1 | LL | / #[suggestion(no_crate_example, code = "...")] @@ -290,7 +290,7 @@ LL | | var: String, LL | | } | |_^ -error: invalid nested attribute +error: derive(Diagnostic): invalid nested attribute --> $DIR/subdiagnostic-derive.rs:541:42 | LL | #[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")] @@ -298,7 +298,7 @@ LL | #[multipart_suggestion(no_crate_example, code = "...", applicability = "mac | = help: only `no_span`, `style` and `applicability` are valid nested attributes -error: multipart suggestion without any `#[suggestion_part(...)]` fields +error: derive(Diagnostic): multipart suggestion without any `#[suggestion_part(...)]` fields --> $DIR/subdiagnostic-derive.rs:541:1 | LL | / #[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")] @@ -309,19 +309,19 @@ LL | | var: String, LL | | } | |_^ -error: `#[suggestion_part(...)]` attribute without `code = "..."` +error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` --> $DIR/subdiagnostic-derive.rs:551:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ -error: `#[suggestion_part(...)]` attribute without `code = "..."` +error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` --> $DIR/subdiagnostic-derive.rs:559:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ -error: `#[primary_span]` is not a valid attribute +error: derive(Diagnostic): `#[primary_span]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:568:5 | LL | #[primary_span] @@ -329,7 +329,7 @@ LL | #[primary_span] | = help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]` -error: multipart suggestion without any `#[suggestion_part(...)]` fields +error: derive(Diagnostic): multipart suggestion without any `#[suggestion_part(...)]` fields --> $DIR/subdiagnostic-derive.rs:565:1 | LL | / #[multipart_suggestion(no_crate_example)] @@ -341,37 +341,37 @@ LL | | span: Span, LL | | } | |_^ -error: `#[suggestion_part(...)]` attribute without `code = "..."` +error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` --> $DIR/subdiagnostic-derive.rs:576:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ -error: `#[suggestion_part(...)]` attribute without `code = "..."` +error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` --> $DIR/subdiagnostic-derive.rs:579:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ -error: `code` is the only valid nested attribute +error: derive(Diagnostic): `code` is the only valid nested attribute --> $DIR/subdiagnostic-derive.rs:582:23 | LL | #[suggestion_part(foo = "bar")] | ^^^ -error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/subdiagnostic-derive.rs:587:5 | LL | #[suggestion_part(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` +error: derive(Diagnostic): the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/subdiagnostic-derive.rs:590:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/subdiagnostic-derive.rs:598:37 | LL | #[suggestion_part(code = "...", code = ",,,")] @@ -383,37 +383,37 @@ note: previously specified here LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^ -error: `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."` +error: derive(Diagnostic): `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."` --> $DIR/subdiagnostic-derive.rs:627:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ -error: expected exactly one string literal for `code = ...` +error: derive(Diagnostic): expected exactly one string literal for `code = ...` --> $DIR/subdiagnostic-derive.rs:675:34 | LL | #[suggestion_part(code("foo"))] | ^ -error: expected exactly one string literal for `code = ...` +error: derive(Diagnostic): expected exactly one string literal for `code = ...` --> $DIR/subdiagnostic-derive.rs:686:41 | LL | #[suggestion_part(code("foo", "bar"))] | ^ -error: expected exactly one string literal for `code = ...` +error: derive(Diagnostic): expected exactly one string literal for `code = ...` --> $DIR/subdiagnostic-derive.rs:697:30 | LL | #[suggestion_part(code(3))] | ^ -error: expected exactly one string literal for `code = ...` +error: derive(Diagnostic): expected exactly one string literal for `code = ...` --> $DIR/subdiagnostic-derive.rs:708:29 | LL | #[suggestion_part(code())] | ^ -error: specified multiple times +error: derive(Diagnostic): attribute specified multiple times --> $DIR/subdiagnostic-derive.rs:763:1 | LL | #[suggestion(no_crate_example, code = "", style = "hidden", style = "normal")] @@ -425,7 +425,7 @@ note: previously specified here LL | #[suggestion(no_crate_example, code = "", style = "hidden", style = "normal")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[suggestion_hidden(...)]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion_hidden(...)]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:772:1 | LL | #[suggestion_hidden(no_crate_example, code = "")] @@ -433,7 +433,7 @@ LL | #[suggestion_hidden(no_crate_example, code = "")] | = help: Use `#[suggestion(..., style = "hidden")]` instead -error: `#[suggestion_hidden(...)]` is not a valid attribute +error: derive(Diagnostic): `#[suggestion_hidden(...)]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:780:1 | LL | #[suggestion_hidden(no_crate_example, code = "", style = "normal")] @@ -441,7 +441,7 @@ LL | #[suggestion_hidden(no_crate_example, code = "", style = "normal")] | = help: Use `#[suggestion(..., style = "hidden")]` instead -error: invalid suggestion style +error: derive(Diagnostic): invalid suggestion style --> $DIR/subdiagnostic-derive.rs:788:51 | LL | #[suggestion(no_crate_example, code = "", style = "foo")] @@ -449,25 +449,25 @@ LL | #[suggestion(no_crate_example, code = "", style = "foo")] | = help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only` -error: expected `= "xxx"` +error: derive(Diagnostic): expected `= "xxx"` --> $DIR/subdiagnostic-derive.rs:796:49 | LL | #[suggestion(no_crate_example, code = "", style = 42)] | ^ -error: a diagnostic slug must be the first argument to the attribute +error: derive(Diagnostic): a diagnostic slug must be the first argument to the attribute --> $DIR/subdiagnostic-derive.rs:804:48 | LL | #[suggestion(no_crate_example, code = "", style)] | ^ -error: expected `= "xxx"` +error: derive(Diagnostic): expected `= "xxx"` --> $DIR/subdiagnostic-derive.rs:812:48 | LL | #[suggestion(no_crate_example, code = "", style("foo"))] | ^ -error: `#[primary_span]` is not a valid attribute +error: derive(Diagnostic): `#[primary_span]` is not a valid attribute --> $DIR/subdiagnostic-derive.rs:825:5 | LL | #[primary_span] @@ -476,7 +476,7 @@ LL | #[primary_span] = note: there must be exactly one primary span = help: to create a suggestion with multiple spans, use `#[multipart_suggestion]` instead -error: suggestion without `#[primary_span]` field +error: derive(Diagnostic): suggestion without `#[primary_span]` field --> $DIR/subdiagnostic-derive.rs:822:1 | LL | / #[suggestion(no_crate_example, code = "")] From 56fc9c7c54f51181f0e6089ebb8a92dd155b7231 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 24 Dec 2023 18:38:00 -0500 Subject: [PATCH 04/13] show linker warnings even if it returns 0 --- compiler/rustc_codegen_ssa/messages.ftl | 2 ++ compiler/rustc_codegen_ssa/src/back/link.rs | 26 ++++++++++++++++++-- tests/run-make/linker-warning/Makefile | 17 +++++++++++++ tests/run-make/linker-warning/fake-linker.sh | 17 +++++++++++++ tests/run-make/linker-warning/main.rs | 1 + 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/run-make/linker-warning/Makefile create mode 100755 tests/run-make/linker-warning/fake-linker.sh create mode 100644 tests/run-make/linker-warning/main.rs diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 5881c6236ece6..f76a63c3897c7 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -160,6 +160,8 @@ codegen_ssa_linker_file_stem = couldn't extract file stem from specified linker codegen_ssa_linker_not_found = linker `{$linker_path}` not found .note = {$error} +codegen_ssa_linker_output = {$inner} + codegen_ssa_linker_unsupported_modifier = `as-needed` modifier not supported for current linker codegen_ssa_linking_failed = linking with `{$linker_path}` failed: {$exit_status} diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 959653c932653..48269a9265520 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -721,6 +721,14 @@ fn link_dwarf_object<'a>( } } +#[derive(Diagnostic)] +#[diag(codegen_ssa_linker_output)] +/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just +/// end up with inconsistent languages within the same diagnostic. +struct LinkerOutput { + inner: String, +} + /// Create a dynamic library or executable. /// /// This will invoke the system linker/cc to create the resulting file. This links to all upstream @@ -972,8 +980,22 @@ fn link_natively<'a>( sess.dcx().abort_if_errors(); } - info!("linker stderr:\n{}", escape_string(&prog.stderr)); - info!("linker stdout:\n{}", escape_string(&prog.stdout)); + + if !prog.stderr.is_empty() { + // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present. + let stderr = escape_string(&prog.stderr); + debug!("original stderr: {stderr}"); + let stderr = stderr + .strip_prefix("warning: ") + .unwrap_or(&stderr) + .replace(": warning: ", ": "); + sess.dcx().emit_warn(LinkerOutput { inner: format!("linker stderr: {stderr}") }); + } + if !prog.stdout.is_empty() && sess.opts.verbose { + sess.dcx().emit_warn(LinkerOutput { + inner: format!("linker stdout: {}", escape_string(&prog.stdout)), + }); + } } Err(e) => { let linker_not_found = e.kind() == io::ErrorKind::NotFound; diff --git a/tests/run-make/linker-warning/Makefile b/tests/run-make/linker-warning/Makefile new file mode 100644 index 0000000000000..8b9e98f4ec54e --- /dev/null +++ b/tests/run-make/linker-warning/Makefile @@ -0,0 +1,17 @@ +include ../tools.mk + +RUN_RUSTC := $(RUSTC_ORIGINAL) main.rs -o $(TMPDIR)/main -C linker=./fake-linker.sh + +all: + # Run rustc with our fake linker, and make sure it shows warnings + $(RUN_RUSTC) -C link-arg=run_make_warn 2>&1 | $(CGREP) "warning: linker stderr: bar" + + # Make sure it shows stdout, but only when --verbose is passed + $(RUN_RUSTC) -C link-arg=run_make_info --verbose 2>&1 | $(CGREP) "warning: linker stdout: foo" + $(RUN_RUSTC) -C link-arg=run_make_info 2>&1 | $(CGREP) -v "warning: linker stdout: foo" + + # Make sure we short-circuit this new path if the linker exits with an error (so the diagnostic is less verbose) + rm -f $(TMPDIR)/main + $(RUN_RUSTC) -C link-arg=run_make_error 2>&1 | $(CGREP) "note: error: baz" + ! [ -e $(TMPDIR)/main ] + diff --git a/tests/run-make/linker-warning/fake-linker.sh b/tests/run-make/linker-warning/fake-linker.sh new file mode 100755 index 0000000000000..ed4d472c3bfbd --- /dev/null +++ b/tests/run-make/linker-warning/fake-linker.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +code=0 +while ! [ $# = 0 ]; do + case "$1" in + run_make_info) echo "foo" + ;; + run_make_warn) echo "warning: bar" >&2 + ;; + run_make_error) echo "error: baz" >&2; code=1 + ;; + *) ;; # rustc passes lots of args we don't care about + esac + shift +done + +exit $code diff --git a/tests/run-make/linker-warning/main.rs b/tests/run-make/linker-warning/main.rs new file mode 100644 index 0000000000000..f328e4d9d04c3 --- /dev/null +++ b/tests/run-make/linker-warning/main.rs @@ -0,0 +1 @@ +fn main() {} From aac51d50fb3641f8679badfb60e58b55c980b859 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 24 Dec 2023 19:49:23 -0500 Subject: [PATCH 05/13] don't show the full linker args unless `--verbose` is passed the linker arguments can be *very* long, especially for crates with many dependencies. often they are not useful. omit them unless the user specifically requests them. --- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_codegen_ssa/src/errors.rs | 9 ++++++++- tests/run-make/link-args-order/Makefile | 4 ++-- tests/run-make/link-dedup/Makefile | 8 ++++---- tests/run-make/linker-warning/Makefile | 10 +++++++++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 48269a9265520..4b71ff39d9c25 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -934,12 +934,12 @@ fn link_natively<'a>( let mut output = prog.stderr.clone(); output.extend_from_slice(&prog.stdout); let escaped_output = escape_linker_output(&output, flavor); - // FIXME: Add UI tests for this error. let err = errors::LinkingFailed { linker_path: &linker_path, exit_status: prog.status, command: &cmd, escaped_output, + verbose: sess.opts.verbose, }; sess.dcx().emit_err(err); // If MSVC's `link.exe` was expected but the return code diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index f90e1906caf0a..ec1a26d069375 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -340,6 +340,7 @@ pub struct LinkingFailed<'a> { pub exit_status: ExitStatus, pub command: &'a Command, pub escaped_output: String, + pub verbose: bool, } impl IntoDiagnostic<'_, G> for LinkingFailed<'_> { @@ -350,7 +351,13 @@ impl IntoDiagnostic<'_, G> for LinkingFailed<'_> { let contains_undefined_ref = self.escaped_output.contains("undefined reference to"); - diag.note(format!("{:?}", self.command)).note(self.escaped_output); + if self.verbose { + diag.note(format!("{:?}", self.command)); + } else { + diag.note("use `--verbose` to show all linker arguments"); + } + + diag.note(self.escaped_output); // Trying to match an error from OS linkers // which by now we have no way to translate. diff --git a/tests/run-make/link-args-order/Makefile b/tests/run-make/link-args-order/Makefile index c562cc1b396fa..0896184f81ea5 100644 --- a/tests/run-make/link-args-order/Makefile +++ b/tests/run-make/link-args-order/Makefile @@ -6,5 +6,5 @@ RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args= RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f all: - $(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' - $(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' + $(RUSTC) $(RUSTC_FLAGS) empty.rs --print=link-args | $(CGREP) '"a" "b" "c" "d" "e" "f"' + $(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs --print=link-args | $(CGREP) '"a" "b" "c" "d" "e" "f"' diff --git a/tests/run-make/link-dedup/Makefile b/tests/run-make/link-dedup/Makefile index eff18ab48ab4f..ac07068c02a7f 100644 --- a/tests/run-make/link-dedup/Makefile +++ b/tests/run-make/link-dedup/Makefile @@ -6,7 +6,7 @@ all: $(RUSTC) depa.rs $(RUSTC) depb.rs $(RUSTC) depc.rs - $(RUSTC) empty.rs --cfg bar 2>&1 | $(CGREP) '"-ltesta" "-ltestb" "-ltesta"' - $(RUSTC) empty.rs 2>&1 | $(CGREP) '"-ltesta"' - $(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltestb"' - $(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltesta" "-ltesta" "-ltesta"' + $(RUSTC) empty.rs --cfg bar --print=link-args | $(CGREP) '"-ltesta" "-ltestb" "-ltesta"' + $(RUSTC) empty.rs --print=link-args | $(CGREP) '"-ltesta"' + $(RUSTC) empty.rs --print=link-args | $(CGREP) -v '"-ltestb"' + $(RUSTC) empty.rs --print=link-args | $(CGREP) -v '"-ltesta" "-ltesta" "-ltesta"' diff --git a/tests/run-make/linker-warning/Makefile b/tests/run-make/linker-warning/Makefile index 8b9e98f4ec54e..ecb36aee21440 100644 --- a/tests/run-make/linker-warning/Makefile +++ b/tests/run-make/linker-warning/Makefile @@ -2,7 +2,9 @@ include ../tools.mk RUN_RUSTC := $(RUSTC_ORIGINAL) main.rs -o $(TMPDIR)/main -C linker=./fake-linker.sh -all: +all: succeeds_with_warnings errors linker_args + +succeeds_with_warnings: # Run rustc with our fake linker, and make sure it shows warnings $(RUN_RUSTC) -C link-arg=run_make_warn 2>&1 | $(CGREP) "warning: linker stderr: bar" @@ -10,8 +12,14 @@ all: $(RUN_RUSTC) -C link-arg=run_make_info --verbose 2>&1 | $(CGREP) "warning: linker stdout: foo" $(RUN_RUSTC) -C link-arg=run_make_info 2>&1 | $(CGREP) -v "warning: linker stdout: foo" +errors: # Make sure we short-circuit this new path if the linker exits with an error (so the diagnostic is less verbose) rm -f $(TMPDIR)/main $(RUN_RUSTC) -C link-arg=run_make_error 2>&1 | $(CGREP) "note: error: baz" ! [ -e $(TMPDIR)/main ] +linker_args: + # Make sure we don't show the linker args unless `--verbose` is passed + $(RUN_RUSTC) --verbose -C link-arg=run_make_error 2>&1 | $(CGREP) -e "PATH=.*fake-linker.sh.*run_make_error" + $(RUN_RUSTC) -C link-arg=run_make_error 2>&1 | $(CGREP) -v -e "PATH=.*fake-linker.sh.*run_make_error" + From 56bc5525b301bcbde05f464493cdf368e9997104 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 21 Jan 2024 17:16:26 +0000 Subject: [PATCH 06/13] Bump `object` version --- Cargo.lock | 34 +++++++--------------------------- src/tools/tidy/src/deps.rs | 2 -- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef5811c6901d4..2f759bf85231e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -373,9 +373,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -2588,9 +2588,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "compiler_builtins", "crc32fast", @@ -4789,12 +4789,12 @@ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "ruzstd" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc" +checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d" dependencies = [ "byteorder", - "thiserror-core", + "derive_more", "twox-hash", ] @@ -5357,26 +5357,6 @@ dependencies = [ "thiserror-impl", ] -[[package]] -name = "thiserror-core" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497" -dependencies = [ - "thiserror-core-impl", -] - -[[package]] -name = "thiserror-core-impl" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "thiserror-impl" version = "1.0.47" diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index b03811e5efda5..b06c072a2b0fd 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -340,8 +340,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "termize", "thin-vec", "thiserror", - "thiserror-core", - "thiserror-core-impl", "thiserror-impl", "thorin-dwp", "thread_local", From b50b333a0f17fd674ae487f7bd2baf0395b2dd15 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 21 Jan 2024 17:17:34 +0000 Subject: [PATCH 07/13] Bump `uniq-langid` version --- Cargo.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f759bf85231e..a8543eceb22d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5729,9 +5729,9 @@ dependencies = [ [[package]] name = "unic-langid" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f" +checksum = "238722e6d794ed130f91f4ea33e01fcff4f188d92337a21297892521c72df516" dependencies = [ "unic-langid-impl", "unic-langid-macros", @@ -5739,18 +5739,18 @@ dependencies = [ [[package]] name = "unic-langid-impl" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff" +checksum = "4bd55a2063fdea4ef1f8633243a7b0524cbeef1905ae04c31a1c9b9775c55bc6" dependencies = [ "tinystr", ] [[package]] name = "unic-langid-macros" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe" +checksum = "5c854cefb82ff2816410ce606acbad1b3af065140907b29be9229040752b83ec" dependencies = [ "proc-macro-hack", "tinystr", @@ -5760,13 +5760,13 @@ dependencies = [ [[package]] name = "unic-langid-macros-impl" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8" +checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4" dependencies = [ "proc-macro-hack", "quote", - "syn 1.0.109", + "syn 2.0.32", "unic-langid-impl", ] From dbf55f611e7c49c920be41c99e190cffb74ac580 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Mon, 18 Dec 2023 21:43:02 +0100 Subject: [PATCH 08/13] Add the wasm32-wasi-preview2 target Signed-off-by: Ryan Levick --- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/targets/wasm32_wasi_preview2.rs | 64 +++++++++ library/std/src/os/mod.rs | 3 + library/std/src/os/wasi/mod.rs | 3 +- library/std/src/os/wasi_preview2/mod.rs | 5 + library/std/src/sys/pal/mod.rs | 3 + library/std/src/sys/pal/wasi/helpers.rs | 123 ++++++++++++++++ library/std/src/sys/pal/wasi/mod.rs | 132 ++---------------- library/std/src/sys/pal/wasi_preview2/mod.rs | 78 +++++++++++ src/bootstrap/src/core/build_steps/compile.rs | 7 +- src/bootstrap/src/lib.rs | 2 +- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../platform-support/wasm32-wasi-preview2.md | 30 ++++ tests/assembly/targets/targets-elf.rs | 3 + tests/ui/check-cfg/well-known-values.stderr | 2 +- 17 files changed, 331 insertions(+), 128 deletions(-) create mode 100644 compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs create mode 100644 library/std/src/os/wasi_preview2/mod.rs create mode 100644 library/std/src/sys/pal/wasi/helpers.rs create mode 100644 library/std/src/sys/pal/wasi_preview2/mod.rs create mode 100644 src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 90a38b26f73ca..1879b531130e4 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1793,6 +1793,7 @@ symbols! { warn, wasm_abi, wasm_import_module, + wasm_preview2, wasm_target_feature, while_let, windows, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 884bd23e8cce9..ead3be7fd529b 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1574,6 +1574,7 @@ supported_targets! { ("wasm32-unknown-emscripten", wasm32_unknown_emscripten), ("wasm32-unknown-unknown", wasm32_unknown_unknown), ("wasm32-wasi", wasm32_wasi), + ("wasm32-wasi-preview2", wasm32_wasi_preview2), ("wasm32-wasi-preview1-threads", wasm32_wasi_preview1_threads), ("wasm64-unknown-unknown", wasm64_unknown_unknown), diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs new file mode 100644 index 0000000000000..fc44e5d4cbce9 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs @@ -0,0 +1,64 @@ +//! The `wasm32-wasi-preview2` target is the next evolution of the +//! wasm32-wasi target. While the wasi specification is still under +//! active development, the {review 2 iteration is considered an "island +//! of stability" that should allow users to rely on it indefinitely. +//! +//! The `wasi` target is a proposal to define a standardized set of WebAssembly +//! component imports that allow it to interoperate with the host system in a +//! standardized way. This set of imports is intended to empower WebAssembly +//! binaries with host capabilities such as filesystem access, network access, etc. +//! +//! Wasi Preview 2 relies on the WebAssembly component model which is an extension of +//! the core WebAssembly specification which allows interoperability between WebAssembly +//! modules (known as "components") through high-level, shared-nothing APIs instead of the +//! low-level, shared-everything linear memory model of the core WebAssembly specification. +//! +//! You can see more about wasi at and the component model at +//! . + +use crate::spec::crt_objects; +use crate::spec::LinkSelfContainedDefault; +use crate::spec::{base, Target}; + +pub fn target() -> Target { + let mut options = base::wasm::options(); + + options.os = "wasi".into(); + options.env = "preview2".into(); + options.linker = Some("wasm-component-ld".into()); + + options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained(); + options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained(); + + // FIXME: Figure out cases in which WASM needs to link with a native toolchain. + options.link_self_contained = LinkSelfContainedDefault::True; + + // Right now this is a bit of a workaround but we're currently saying that + // the target by default has a static crt which we're taking as a signal + // for "use the bundled crt". If that's turned off then the system's crt + // will be used, but this means that default usage of this target doesn't + // need an external compiler but it's still interoperable with an external + // compiler if configured correctly. + options.crt_static_default = true; + options.crt_static_respected = true; + + // Allow `+crt-static` to create a "cdylib" output which is just a wasm file + // without a main function. + options.crt_static_allows_dylibs = true; + + // WASI's `sys::args::init` function ignores its arguments; instead, + // `args::args()` makes the WASI API calls itself. + options.main_needs_argc_argv = false; + + // And, WASI mangles the name of "main" to distinguish between different + // signatures. + options.entry_name = "__main_void".into(); + + Target { + llvm_target: "wasm32-unknown-unknown".into(), + pointer_width: 32, + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm32".into(), + options, + } +} diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 6e11b92b618a3..f03e079030503 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -85,6 +85,9 @@ pub mod linux; #[cfg(any(target_os = "wasi", doc))] pub mod wasi; +#[cfg(any(all(target_os = "wasi", target_env = "preview2"), doc))] +pub mod wasi_preview2; + // windows #[cfg(not(all( doc, diff --git a/library/std/src/os/wasi/mod.rs b/library/std/src/os/wasi/mod.rs index bbaf328f457e4..05c8d30073f42 100644 --- a/library/std/src/os/wasi/mod.rs +++ b/library/std/src/os/wasi/mod.rs @@ -28,7 +28,8 @@ //! [`OsStr`]: crate::ffi::OsStr //! [`OsString`]: crate::ffi::OsString -#![stable(feature = "rust1", since = "1.0.0")] +#![cfg_attr(not(target_env = "preview2"), stable(feature = "rust1", since = "1.0.0"))] +#![cfg_attr(target_env = "preview2", unstable(feature = "wasm_preview2", issue = "none"))] #![deny(unsafe_op_in_unsafe_fn)] #![doc(cfg(target_os = "wasi"))] diff --git a/library/std/src/os/wasi_preview2/mod.rs b/library/std/src/os/wasi_preview2/mod.rs new file mode 100644 index 0000000000000..1d44dd72814b8 --- /dev/null +++ b/library/std/src/os/wasi_preview2/mod.rs @@ -0,0 +1,5 @@ +//! Platform-specific extensions to `std` for Preview 2 of the WebAssembly System Interface (WASI). +//! +//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized. + +#![stable(feature = "raw_ext", since = "1.1.0")] diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs index 041b7c355822a..f927d88d46c34 100644 --- a/library/std/src/sys/pal/mod.rs +++ b/library/std/src/sys/pal/mod.rs @@ -40,6 +40,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "wasi")] { mod wasi; pub use self::wasi::*; + } else if #[cfg(all(target_os = "wasi", target_env = "preview2"))] { + mod wasi_preview2; + pub use self::wasi_preview2::*; } else if #[cfg(target_family = "wasm")] { mod wasm; pub use self::wasm::*; diff --git a/library/std/src/sys/pal/wasi/helpers.rs b/library/std/src/sys/pal/wasi/helpers.rs new file mode 100644 index 0000000000000..82149cef8fad1 --- /dev/null +++ b/library/std/src/sys/pal/wasi/helpers.rs @@ -0,0 +1,123 @@ +use crate::io as std_io; +use crate::mem; + +#[inline] +pub fn is_interrupted(errno: i32) -> bool { + errno == wasi::ERRNO_INTR.raw().into() +} + +pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { + use std_io::ErrorKind; + + let Ok(errno) = u16::try_from(errno) else { + return ErrorKind::Uncategorized; + }; + + macro_rules! match_errno { + ($($($errno:ident)|+ => $errkind:ident),*, _ => $wildcard:ident $(,)?) => { + match errno { + $(e if $(e == ::wasi::$errno.raw())||+ => ErrorKind::$errkind),*, + _ => ErrorKind::$wildcard, + } + }; + } + + match_errno! { + ERRNO_2BIG => ArgumentListTooLong, + ERRNO_ACCES => PermissionDenied, + ERRNO_ADDRINUSE => AddrInUse, + ERRNO_ADDRNOTAVAIL => AddrNotAvailable, + ERRNO_AFNOSUPPORT => Unsupported, + ERRNO_AGAIN => WouldBlock, + // ALREADY => "connection already in progress", + // BADF => "bad file descriptor", + // BADMSG => "bad message", + ERRNO_BUSY => ResourceBusy, + // CANCELED => "operation canceled", + // CHILD => "no child processes", + ERRNO_CONNABORTED => ConnectionAborted, + ERRNO_CONNREFUSED => ConnectionRefused, + ERRNO_CONNRESET => ConnectionReset, + ERRNO_DEADLK => Deadlock, + // DESTADDRREQ => "destination address required", + ERRNO_DOM => InvalidInput, + // DQUOT => /* reserved */, + ERRNO_EXIST => AlreadyExists, + // FAULT => "bad address", + ERRNO_FBIG => FileTooLarge, + ERRNO_HOSTUNREACH => HostUnreachable, + // IDRM => "identifier removed", + // ILSEQ => "illegal byte sequence", + // INPROGRESS => "operation in progress", + ERRNO_INTR => Interrupted, + ERRNO_INVAL => InvalidInput, + ERRNO_IO => Uncategorized, + // ISCONN => "socket is connected", + ERRNO_ISDIR => IsADirectory, + ERRNO_LOOP => FilesystemLoop, + // MFILE => "file descriptor value too large", + ERRNO_MLINK => TooManyLinks, + // MSGSIZE => "message too large", + // MULTIHOP => /* reserved */, + ERRNO_NAMETOOLONG => InvalidFilename, + ERRNO_NETDOWN => NetworkDown, + // NETRESET => "connection aborted by network", + ERRNO_NETUNREACH => NetworkUnreachable, + // NFILE => "too many files open in system", + // NOBUFS => "no buffer space available", + ERRNO_NODEV => NotFound, + ERRNO_NOENT => NotFound, + // NOEXEC => "executable file format error", + // NOLCK => "no locks available", + // NOLINK => /* reserved */, + ERRNO_NOMEM => OutOfMemory, + // NOMSG => "no message of the desired type", + // NOPROTOOPT => "protocol not available", + ERRNO_NOSPC => StorageFull, + ERRNO_NOSYS => Unsupported, + ERRNO_NOTCONN => NotConnected, + ERRNO_NOTDIR => NotADirectory, + ERRNO_NOTEMPTY => DirectoryNotEmpty, + // NOTRECOVERABLE => "state not recoverable", + // NOTSOCK => "not a socket", + ERRNO_NOTSUP => Unsupported, + // NOTTY => "inappropriate I/O control operation", + ERRNO_NXIO => NotFound, + // OVERFLOW => "value too large to be stored in data type", + // OWNERDEAD => "previous owner died", + ERRNO_PERM => PermissionDenied, + ERRNO_PIPE => BrokenPipe, + // PROTO => "protocol error", + ERRNO_PROTONOSUPPORT => Unsupported, + // PROTOTYPE => "protocol wrong type for socket", + // RANGE => "result too large", + ERRNO_ROFS => ReadOnlyFilesystem, + ERRNO_SPIPE => NotSeekable, + ERRNO_SRCH => NotFound, + // STALE => /* reserved */, + ERRNO_TIMEDOUT => TimedOut, + ERRNO_TXTBSY => ResourceBusy, + ERRNO_XDEV => CrossesDevices, + ERRNO_NOTCAPABLE => PermissionDenied, + _ => Uncategorized, + } +} + +pub fn abort_internal() -> ! { + unsafe { libc::abort() } +} + +pub fn hashmap_random_keys() -> (u64, u64) { + let mut ret = (0u64, 0u64); + unsafe { + let base = &mut ret as *mut (u64, u64) as *mut u8; + let len = mem::size_of_val(&ret); + wasi::random_get(base, len).expect("random_get failure"); + } + return ret; +} + +#[inline] +pub(crate) fn err2io(err: wasi::Errno) -> std_io::Error { + std_io::Error::from_raw_os_error(err.raw().into()) +} diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs index 4ffc8ecdd67ee..a4b55093bf47f 100644 --- a/library/std/src/sys/pal/wasi/mod.rs +++ b/library/std/src/sys/pal/wasi/mod.rs @@ -14,9 +14,6 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use crate::io as std_io; -use crate::mem; - #[path = "../unix/alloc.rs"] pub mod alloc; pub mod args; @@ -72,123 +69,12 @@ cfg_if::cfg_if! { mod common; pub use common::*; -#[inline] -pub fn is_interrupted(errno: i32) -> bool { - errno == wasi::ERRNO_INTR.raw().into() -} - -pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { - use std_io::ErrorKind; - - let Ok(errno) = u16::try_from(errno) else { - return ErrorKind::Uncategorized; - }; - - macro_rules! match_errno { - ($($($errno:ident)|+ => $errkind:ident),*, _ => $wildcard:ident $(,)?) => { - match errno { - $(e if $(e == ::wasi::$errno.raw())||+ => ErrorKind::$errkind),*, - _ => ErrorKind::$wildcard, - } - }; - } - - match_errno! { - ERRNO_2BIG => ArgumentListTooLong, - ERRNO_ACCES => PermissionDenied, - ERRNO_ADDRINUSE => AddrInUse, - ERRNO_ADDRNOTAVAIL => AddrNotAvailable, - ERRNO_AFNOSUPPORT => Unsupported, - ERRNO_AGAIN => WouldBlock, - // ALREADY => "connection already in progress", - // BADF => "bad file descriptor", - // BADMSG => "bad message", - ERRNO_BUSY => ResourceBusy, - // CANCELED => "operation canceled", - // CHILD => "no child processes", - ERRNO_CONNABORTED => ConnectionAborted, - ERRNO_CONNREFUSED => ConnectionRefused, - ERRNO_CONNRESET => ConnectionReset, - ERRNO_DEADLK => Deadlock, - // DESTADDRREQ => "destination address required", - ERRNO_DOM => InvalidInput, - // DQUOT => /* reserved */, - ERRNO_EXIST => AlreadyExists, - // FAULT => "bad address", - ERRNO_FBIG => FileTooLarge, - ERRNO_HOSTUNREACH => HostUnreachable, - // IDRM => "identifier removed", - // ILSEQ => "illegal byte sequence", - // INPROGRESS => "operation in progress", - ERRNO_INTR => Interrupted, - ERRNO_INVAL => InvalidInput, - ERRNO_IO => Uncategorized, - // ISCONN => "socket is connected", - ERRNO_ISDIR => IsADirectory, - ERRNO_LOOP => FilesystemLoop, - // MFILE => "file descriptor value too large", - ERRNO_MLINK => TooManyLinks, - // MSGSIZE => "message too large", - // MULTIHOP => /* reserved */, - ERRNO_NAMETOOLONG => InvalidFilename, - ERRNO_NETDOWN => NetworkDown, - // NETRESET => "connection aborted by network", - ERRNO_NETUNREACH => NetworkUnreachable, - // NFILE => "too many files open in system", - // NOBUFS => "no buffer space available", - ERRNO_NODEV => NotFound, - ERRNO_NOENT => NotFound, - // NOEXEC => "executable file format error", - // NOLCK => "no locks available", - // NOLINK => /* reserved */, - ERRNO_NOMEM => OutOfMemory, - // NOMSG => "no message of the desired type", - // NOPROTOOPT => "protocol not available", - ERRNO_NOSPC => StorageFull, - ERRNO_NOSYS => Unsupported, - ERRNO_NOTCONN => NotConnected, - ERRNO_NOTDIR => NotADirectory, - ERRNO_NOTEMPTY => DirectoryNotEmpty, - // NOTRECOVERABLE => "state not recoverable", - // NOTSOCK => "not a socket", - ERRNO_NOTSUP => Unsupported, - // NOTTY => "inappropriate I/O control operation", - ERRNO_NXIO => NotFound, - // OVERFLOW => "value too large to be stored in data type", - // OWNERDEAD => "previous owner died", - ERRNO_PERM => PermissionDenied, - ERRNO_PIPE => BrokenPipe, - // PROTO => "protocol error", - ERRNO_PROTONOSUPPORT => Unsupported, - // PROTOTYPE => "protocol wrong type for socket", - // RANGE => "result too large", - ERRNO_ROFS => ReadOnlyFilesystem, - ERRNO_SPIPE => NotSeekable, - ERRNO_SRCH => NotFound, - // STALE => /* reserved */, - ERRNO_TIMEDOUT => TimedOut, - ERRNO_TXTBSY => ResourceBusy, - ERRNO_XDEV => CrossesDevices, - ERRNO_NOTCAPABLE => PermissionDenied, - _ => Uncategorized, - } -} - -pub fn abort_internal() -> ! { - unsafe { libc::abort() } -} - -pub fn hashmap_random_keys() -> (u64, u64) { - let mut ret = (0u64, 0u64); - unsafe { - let base = &mut ret as *mut (u64, u64) as *mut u8; - let len = mem::size_of_val(&ret); - wasi::random_get(base, len).expect("random_get failure"); - } - return ret; -} - -#[inline] -fn err2io(err: wasi::Errno) -> std_io::Error { - std_io::Error::from_raw_os_error(err.raw().into()) -} +mod helpers; +// These exports are listed individually to work around Rust's glob import +// conflict rules. If we glob export `helpers` and `common` together, then +// the compiler complains about conflicts. +pub use helpers::abort_internal; +pub use helpers::decode_error_kind; +use helpers::err2io; +pub use helpers::hashmap_random_keys; +pub use helpers::is_interrupted; diff --git a/library/std/src/sys/pal/wasi_preview2/mod.rs b/library/std/src/sys/pal/wasi_preview2/mod.rs new file mode 100644 index 0000000000000..b61695015bbd9 --- /dev/null +++ b/library/std/src/sys/pal/wasi_preview2/mod.rs @@ -0,0 +1,78 @@ +//! System bindings for the wasi preview 2 target. +//! +//! This is the next evolution of the original wasi target, and is intended to +//! replace that target over time. +//! +//! To begin with, this target mirrors the wasi target 1 to 1, but over +//! time this will change significantly. + +#[path = "../unix/alloc.rs"] +pub mod alloc; +#[path = "../wasi/args.rs"] +pub mod args; +#[path = "../unix/cmath.rs"] +pub mod cmath; +#[path = "../wasi/env.rs"] +pub mod env; +#[path = "../wasi/fd.rs"] +pub mod fd; +#[path = "../wasi/fs.rs"] +pub mod fs; +#[allow(unused)] +#[path = "../wasm/atomics/futex.rs"] +pub mod futex; +#[path = "../wasi/io.rs"] +pub mod io; + +#[path = "../wasi/net.rs"] +pub mod net; +#[path = "../wasi/os.rs"] +pub mod os; +#[path = "../unix/os_str.rs"] +pub mod os_str; +#[path = "../unix/path.rs"] +pub mod path; +#[path = "../unsupported/pipe.rs"] +pub mod pipe; +#[path = "../unsupported/process.rs"] +pub mod process; +#[path = "../wasi/stdio.rs"] +pub mod stdio; +#[path = "../wasi/thread.rs"] +pub mod thread; +#[path = "../unsupported/thread_local_dtor.rs"] +pub mod thread_local_dtor; +#[path = "../unsupported/thread_local_key.rs"] +pub mod thread_local_key; +#[path = "../wasi/time.rs"] +pub mod time; + +cfg_if::cfg_if! { + if #[cfg(target_feature = "atomics")] { + compile_error!("The wasm32-wasi-preview2 target does not support atomics"); + } else { + #[path = "../unsupported/locks/mod.rs"] + pub mod locks; + #[path = "../unsupported/once.rs"] + pub mod once; + #[path = "../unsupported/thread_parking.rs"] + pub mod thread_parking; + } +} + +#[path = "../unsupported/common.rs"] +#[deny(unsafe_op_in_unsafe_fn)] +#[allow(unused)] +mod common; +pub use common::*; + +#[path = "../wasi/helpers.rs"] +mod helpers; +// These exports are listed individually to work around Rust's glob import +// conflict rules. If we glob export `helpers` and `common` together, then +// the compiler complains about conflicts. +pub use helpers::abort_internal; +pub use helpers::decode_error_kind; +use helpers::err2io; +pub use helpers::hashmap_random_keys; +pub use helpers::is_interrupted; diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index f954f01fe4eda..e06bc3fb09ac1 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -367,10 +367,13 @@ fn copy_self_contained_objects( let srcdir = builder .wasi_root(target) .unwrap_or_else(|| { - panic!("Target {:?} does not have a \"wasi-root\" key", target.triple) + panic!( + "Target {:?} does not have a \"wasi-root\" key in Config.toml", + target.triple + ) }) .join("lib") - .join(target.to_string().replace("-preview1", "")); + .join(target.to_string().replace("-preview1", "").replace("-preview2", "")); for &obj in &["libc.a", "crt1-command.o", "crt1-reactor.o"] { copy_and_stamp( builder, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 1336abf6c7aba..1726e7aacbcea 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -88,7 +88,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ (Some(Mode::Std), "no_sync", None), (Some(Mode::Std), "backtrace_in_libstd", None), /* Extra values not defined in the built-in targets yet, but used in std */ - (Some(Mode::Std), "target_env", Some(&["libnx"])), + (Some(Mode::Std), "target_env", Some(&["libnx", "preview2"])), // (Some(Mode::Std), "target_os", Some(&[])), // #[cfg(bootstrap)] zkvm (Some(Mode::Std), "target_os", Some(&["zkvm"])), diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 1998b008dc811..990998ea70431 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -59,6 +59,7 @@ - [*-unknown-openbsd](platform-support/openbsd.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) - [wasm32-wasi-preview1-threads](platform-support/wasm32-wasi-preview1-threads.md) + - [wasm32-wasi-preview2](platform-support/wasm32-wasi-preview2.md) - [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index f648a60b6c48d..fb751b7229eb4 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -360,6 +360,7 @@ target | std | host | notes `thumbv7a-pc-windows-msvc` | ? | | `thumbv7a-uwp-windows-msvc` | ✓ | | `thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL +[`wasm32-wasi-preview2`](platform-support/wasm32-wasi-preview2.md) | ✓ | | WebAssembly [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly `x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS diff --git a/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md b/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md new file mode 100644 index 0000000000000..837efd13d417e --- /dev/null +++ b/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md @@ -0,0 +1,30 @@ +# `wasm32-wasi-preview2` + +**Tier: 3** + +The `wasm32-wasi-preview2` target is a new and still (as of January 2024) an +experimental target. This target is an extension to `wasm32-wasi-preview1` target, +originally known as `wasm32-wasi`. It is the next evolution in the development of +wasi (the [WebAssembly System Interface](https://wasi.dev)) that uses the WebAssembly +[component model] to allow for a standardized set of syscalls that are intended to empower +WebAssembly binaries with native host capabilities. + +[component model]: https://github.com/WebAssembly/component-model + +## Target maintainers + +- Alex Crichton, https://github.com/alexcrichton +- Ryan Levick, https://github.com/rylev + +## Requirements + +This target is cross-compiled. The target supports `std` fully. + +## Platform requirements + +The WebAssembly runtime should support the wasi preview 2 API set. + +This target is not a stable target. This means that there are only a few engines +which implement wasi preview 2, for example: + +* Wasmtime - `-W component-model` diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 6eec05e85ac71..f6f2f5e88ffc3 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -534,6 +534,9 @@ // revisions: wasm64_unknown_unknown // [wasm64_unknown_unknown] compile-flags: --target wasm64-unknown-unknown // [wasm64_unknown_unknown] needs-llvm-components: webassembly +// revisions: wasm32_wasi_preview2 +// [wasm32_wasi_preview2] compile-flags: --target wasm32-wasi-preview2 +// [wasm32_wasi_preview2] needs-llvm-components: webassembly // revisions: x86_64_apple_darwin // [x86_64_apple_darwin] compile-flags: --target x86_64-apple-darwin // [x86_64_apple_darwin] needs-llvm-components: x86 diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 814d473619777..bb9804386ea88 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -125,7 +125,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_env = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_env` are: ``, `eabihf`, `gnu`, `gnueabihf`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `psx`, `relibc`, `sgx`, `uclibc` + = note: expected values for `target_env` are: ``, `eabihf`, `gnu`, `gnueabihf`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `preview2`, `psx`, `relibc`, `sgx`, `uclibc` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From 8c2ae804e386d0e8e49233d23ce35469316eea52 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 24 Jan 2024 20:37:31 +0000 Subject: [PATCH 09/13] Don't manually resolve async closures in rustc_resolve --- compiler/rustc_resolve/src/late.rs | 29 ------------------- .../async-closures/higher-ranked.rs | 12 ++++++++ .../async-closures/higher-ranked.stderr | 17 +++++++++++ 3 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 tests/ui/async-await/async-closures/higher-ranked.rs create mode 100644 tests/ui/async-await/async-closures/higher-ranked.stderr diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index abd724a6cc25c..18926463d6b04 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4424,35 +4424,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { ExprKind::Type(ref _type_expr, ref _ty) => { visit::walk_expr(self, expr); } - // `async |x| ...` gets desugared to `|x| async {...}`, so we need to - // resolve the arguments within the proper scopes so that usages of them inside the - // closure are detected as upvars rather than normal closure arg usages. - // - // Similarly, `gen |x| ...` gets desugared to `|x| gen {...}`, so we handle that too. - ExprKind::Closure(box ast::Closure { - coroutine_kind: Some(_), - ref fn_decl, - ref body, - .. - }) => { - self.with_rib(ValueNS, RibKind::Normal, |this| { - this.with_label_rib(RibKind::FnOrCoroutine, |this| { - // Resolve arguments: - this.resolve_params(&fn_decl.inputs); - // No need to resolve return type -- - // the outer closure return type is `FnRetTy::Default`. - - // Now resolve the inner closure - { - // No need to resolve arguments: the inner closure has none. - // Resolve the return type: - visit::walk_fn_ret_ty(this, &fn_decl.output); - // Resolve the body - this.visit_expr(body); - } - }) - }); - } // For closures, RibKind::FnOrCoroutine is added in visit_fn ExprKind::Closure(box ast::Closure { binder: ClosureBinder::For { ref generic_params, span }, diff --git a/tests/ui/async-await/async-closures/higher-ranked.rs b/tests/ui/async-await/async-closures/higher-ranked.rs new file mode 100644 index 0000000000000..f0bdcf691ae2f --- /dev/null +++ b/tests/ui/async-await/async-closures/higher-ranked.rs @@ -0,0 +1,12 @@ +// edition:2021 + +#![feature(async_closure)] + +fn main() { + let x = async move |x: &str| { + //~^ ERROR lifetime may not live long enough + // This error is proof that the `&str` type is higher-ranked. + // This won't work until async closures are fully impl'd. + println!("{x}"); + }; +} diff --git a/tests/ui/async-await/async-closures/higher-ranked.stderr b/tests/ui/async-await/async-closures/higher-ranked.stderr new file mode 100644 index 0000000000000..fb02a15b079d7 --- /dev/null +++ b/tests/ui/async-await/async-closures/higher-ranked.stderr @@ -0,0 +1,17 @@ +error: lifetime may not live long enough + --> $DIR/higher-ranked.rs:6:34 + | +LL | let x = async move |x: &str| { + | ____________________________-___-_^ + | | | | + | | | return type of closure `{async closure body@$DIR/higher-ranked.rs:6:34: 11:6}` contains a lifetime `'2` + | | let's call the lifetime of this reference `'1` +LL | | +LL | | // This error is proof that the `&str` type is higher-ranked. +LL | | // This won't work until async closures are fully impl'd. +LL | | println!("{x}"); +LL | | }; + | |_____^ returning this value requires that `'1` must outlive `'2` + +error: aborting due to 1 previous error + From 886108b9fe5b1e681f8bd8e34fdfab23cc74ef53 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 8 Jan 2024 21:48:22 +0100 Subject: [PATCH 10/13] Add feature gate --- compiler/rustc_feature/src/unstable.rs | 3 +++ compiler/rustc_span/src/symbol.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 6eed2178ead8d..e66a66e23dc4f 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -516,6 +516,9 @@ declare_features! ( (unstable, macro_metavar_expr, "1.61.0", Some(83527)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), + /// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are + /// unambiguously sound. + (incomplete, min_exhaustive_patterns, "CURRENT_RUSTC_VERSION", Some(119612)), /// A minimal, sound subset of specialization intended to be used by the /// standard library until the soundness issues with specialization /// are fixed. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 90a38b26f73ca..4456cd1e2f852 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1023,6 +1023,7 @@ symbols! { min_const_fn, min_const_generics, min_const_unsafe_fn, + min_exhaustive_patterns, min_specialization, min_type_alias_impl_trait, minnumf32, From 95a14d43d7aa4b37a8f45a0d97d109f91f9b079f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Jan 2024 19:22:44 +0100 Subject: [PATCH 11/13] Implement feature gate logic --- compiler/rustc_pattern_analysis/src/lib.rs | 1 + compiler/rustc_pattern_analysis/src/rustc.rs | 7 +- .../rustc_pattern_analysis/src/usefulness.rs | 26 +- .../empty-types.exhaustive_patterns.stderr | 100 +-- .../empty-types.min_exh_pats.stderr | 630 ++++++++++++++++++ .../usefulness/empty-types.normal.stderr | 98 +-- tests/ui/pattern/usefulness/empty-types.rs | 84 +-- 7 files changed, 797 insertions(+), 149 deletions(-) create mode 100644 tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 4fd01b5e638ce..9311f763f67bf 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -95,6 +95,7 @@ pub trait TypeCx: Sized + fmt::Debug { type PatData: Clone; fn is_exhaustive_patterns_feature_on(&self) -> bool; + fn is_min_exhaustive_patterns_feature_on(&self) -> bool; /// The number of fields for this constructor. fn ctor_arity(&self, ctor: &Constructor, ty: &Self::Ty) -> usize; diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index d8c3c010a2a93..1971a731d27c7 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -182,7 +182,9 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> { // `field.ty()` doesn't normalize after substituting. let ty = cx.tcx.normalize_erasing_regions(cx.param_env, ty); let is_visible = adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx); - let is_uninhabited = cx.tcx.features().exhaustive_patterns && cx.is_uninhabited(ty); + let is_uninhabited = (cx.tcx.features().exhaustive_patterns + || cx.tcx.features().min_exhaustive_patterns) + && cx.is_uninhabited(ty); if is_uninhabited && (!is_visible || is_non_exhaustive) { None @@ -960,6 +962,9 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> { fn is_exhaustive_patterns_feature_on(&self) -> bool { self.tcx.features().exhaustive_patterns } + fn is_min_exhaustive_patterns_feature_on(&self) -> bool { + self.tcx.features().min_exhaustive_patterns + } fn ctor_arity(&self, ctor: &crate::constructor::Constructor, ty: &Self::Ty) -> usize { self.ctor_arity(ctor, *ty) diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index d7852a2b2cbfc..c71f375ca905b 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -548,11 +548,12 @@ //! [`ValidityConstraint::specialize`]. //! //! Having said all that, in practice we don't fully follow what's been presented in this section. -//! Under `exhaustive_patterns`, we allow omitting empty arms even in `!known_valid` places, for -//! backwards-compatibility until we have a better alternative. Without `exhaustive_patterns`, we -//! mostly treat empty types as inhabited, except specifically a non-nested `!` or empty enum. In -//! this specific case we also allow the empty match regardless of place validity, for -//! backwards-compatibility. Hopefully we can eventually deprecate this. +//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or +//! `EmptyEnum`. First, on stable rust, we require `_` patterns for empty types in all cases apart +//! from the toplevel exception. The `exhaustive_patterns` and `min_exaustive_patterns` allow +//! omitting patterns in the cases described above. There's a final detail: in the toplevel +//! exception or with the `exhaustive_patterns` feature, we ignore place validity when checking +//! whether a pattern is required for exhaustiveness. I (Nadrieril) hope to deprecate this behavior. //! //! //! @@ -1440,10 +1441,17 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>( // We treat match scrutinees of type `!` or `EmptyEnum` differently. let is_toplevel_exception = is_top_level && matches!(ctors_for_ty, ConstructorSet::NoConstructors); - // Whether empty patterns can be omitted for exhaustiveness. - let can_omit_empty_arms = is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on(); - // Whether empty patterns are counted as useful or not. - let empty_arms_are_unreachable = place_validity.is_known_valid() && can_omit_empty_arms; + // Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if + // it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`). + let empty_arms_are_unreachable = place_validity.is_known_valid() + && (is_toplevel_exception + || mcx.tycx.is_exhaustive_patterns_feature_on() + || mcx.tycx.is_min_exhaustive_patterns_feature_on()); + // Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the + // toplevel exception and `exhaustive_patterns` cases for backwards compatibility. + let can_omit_empty_arms = empty_arms_are_unreachable + || is_toplevel_exception + || mcx.tycx.is_exhaustive_patterns_feature_on(); // Analyze the constructors present in this column. let ctors = matrix.heads().map(|p| p.ctor()); diff --git a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr index 367aba3bdd6e6..0c55164a780b5 100644 --- a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr @@ -1,23 +1,23 @@ error: unreachable pattern - --> $DIR/empty-types.rs:47:9 + --> $DIR/empty-types.rs:50:9 | LL | _ => {} | ^ | note: the lint level is defined here - --> $DIR/empty-types.rs:13:9 + --> $DIR/empty-types.rs:16:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:50:9 + --> $DIR/empty-types.rs:53:9 | LL | _x => {} | ^^ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:54:11 + --> $DIR/empty-types.rs:57:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -32,31 +32,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:69:9 + --> $DIR/empty-types.rs:72:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:76:9 + --> $DIR/empty-types.rs:79:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:79:9 + --> $DIR/empty-types.rs:82:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:83:9 + --> $DIR/empty-types.rs:86:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/empty-types.rs:87:11 + --> $DIR/empty-types.rs:90:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered @@ -75,19 +75,19 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:95:9 + --> $DIR/empty-types.rs:98:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:100:9 + --> $DIR/empty-types.rs:103:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:97:11 + --> $DIR/empty-types.rs:100:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -105,7 +105,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:104:9 + --> $DIR/empty-types.rs:107:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -119,121 +119,121 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:115:9 + --> $DIR/empty-types.rs:118:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:119:9 + --> $DIR/empty-types.rs:122:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:122:9 + --> $DIR/empty-types.rs:125:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:123:9 + --> $DIR/empty-types.rs:126:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:126:9 + --> $DIR/empty-types.rs:129:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:127:9 + --> $DIR/empty-types.rs:130:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:136:13 + --> $DIR/empty-types.rs:139:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:139:13 + --> $DIR/empty-types.rs:142:13 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:148:13 + --> $DIR/empty-types.rs:151:13 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:152:13 + --> $DIR/empty-types.rs:155:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:204:13 + --> $DIR/empty-types.rs:207:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:209:13 + --> $DIR/empty-types.rs:212:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:214:13 + --> $DIR/empty-types.rs:217:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:219:13 + --> $DIR/empty-types.rs:222:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:225:13 + --> $DIR/empty-types.rs:228:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:284:9 + --> $DIR/empty-types.rs:287:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:287:9 + --> $DIR/empty-types.rs:290:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:290:9 + --> $DIR/empty-types.rs:293:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:291:9 + --> $DIR/empty-types.rs:294:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:323:11 + --> $DIR/empty-types.rs:326:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -247,7 +247,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:334:11 + --> $DIR/empty-types.rs:337:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -260,7 +260,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:347:11 + --> $DIR/empty-types.rs:350:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -274,7 +274,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:353:11 + --> $DIR/empty-types.rs:356:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -288,25 +288,25 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:363:9 + --> $DIR/empty-types.rs:366:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:366:9 + --> $DIR/empty-types.rs:369:9 | LL | [_, _, _] => {} | ^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:369:9 + --> $DIR/empty-types.rs:372:9 | LL | [_, ..] => {} | ^^^^^^^ error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:383:11 + --> $DIR/empty-types.rs:386:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -320,13 +320,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:390:9 + --> $DIR/empty-types.rs:393:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:392:11 + --> $DIR/empty-types.rs:395:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -340,49 +340,49 @@ LL + [] => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:411:9 + --> $DIR/empty-types.rs:414:9 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:416:9 + --> $DIR/empty-types.rs:419:9 | LL | Some(_a) => {} | ^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:421:9 + --> $DIR/empty-types.rs:424:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:426:9 + --> $DIR/empty-types.rs:429:9 | LL | _a => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:598:9 + --> $DIR/empty-types.rs:601:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:601:9 + --> $DIR/empty-types.rs:604:9 | LL | _x => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:604:9 + --> $DIR/empty-types.rs:607:9 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:607:9 + --> $DIR/empty-types.rs:610:9 | LL | _x if false => {} | ^^ diff --git a/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr new file mode 100644 index 0000000000000..ed5d125e68404 --- /dev/null +++ b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr @@ -0,0 +1,630 @@ +warning: the feature `min_exhaustive_patterns` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/empty-types.rs:13:35 + | +LL | #![cfg_attr(min_exh_pats, feature(min_exhaustive_patterns))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #119612 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: unreachable pattern + --> $DIR/empty-types.rs:50:9 + | +LL | _ => {} + | ^ + | +note: the lint level is defined here + --> $DIR/empty-types.rs:16:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:53:9 + | +LL | _x => {} + | ^^ + +error[E0004]: non-exhaustive patterns: type `&!` is non-empty + --> $DIR/empty-types.rs:57:11 + | +LL | match ref_never {} + | ^^^^^^^^^ + | + = note: the matched value is of type `&!` + = note: references are always considered inhabited +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match ref_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:72:9 + | +LL | (_, _) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:79:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:82:9 + | +LL | (_, _) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:86:9 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: `Ok(_)` not covered + --> $DIR/empty-types.rs:90:11 + | +LL | match res_u32_never {} + | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered + | +note: `Result` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ match res_u32_never { +LL + Ok(_) => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:98:9 + | +LL | Err(_) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:103:9 + | +LL | Err(_) => {} + | ^^^^^^ + +error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered + --> $DIR/empty-types.rs:100:11 + | +LL | match res_u32_never { + | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered + | +note: `Result` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Err(_) => {}, +LL ~ Ok(1_u32..=u32::MAX) => todo!() + | + +error[E0005]: refutable pattern in local binding + --> $DIR/empty-types.rs:107:9 + | +LL | let Ok(_x) = res_u32_never.as_ref(); + | ^^^^^^ pattern `Err(_)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `Result<&u32, &!>` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; + | ++++++++++++++++ + +error[E0005]: refutable pattern in local binding + --> $DIR/empty-types.rs:111:9 + | +LL | let Ok(_x) = &res_u32_never; + | ^^^^^^ pattern `&Err(_)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `&Result` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Ok(_x) = &res_u32_never else { todo!() }; + | ++++++++++++++++ + +error: unreachable pattern + --> $DIR/empty-types.rs:118:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:122:9 + | +LL | Ok(_) => {} + | ^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:125:9 + | +LL | Ok(_) => {} + | ^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:126:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:129:9 + | +LL | Ok(_) => {} + | ^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:130:9 + | +LL | Err(_) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:139:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:142:13 + | +LL | _ if false => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:151:13 + | +LL | Some(_) => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:155:13 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> $DIR/empty-types.rs:164:15 + | +LL | match *ref_opt_void { + | ^^^^^^^^^^^^^ pattern `Some(_)` not covered + | +note: `Option` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(_) => todo!() + | + +error: unreachable pattern + --> $DIR/empty-types.rs:207:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:212:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:217:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:222:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:228:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:287:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:290:9 + | +LL | (_, _) => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:293:9 + | +LL | Ok(_) => {} + | ^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:294:9 + | +LL | Err(_) => {} + | ^^^^^^ + +error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty + --> $DIR/empty-types.rs:315:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `(u32, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty + --> $DIR/empty-types.rs:317:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `(!, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered + --> $DIR/empty-types.rs:319:11 + | +LL | match *x {} + | ^^ patterns `Ok(_)` and `Err(_)` not covered + | +note: `Result` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ match *x { +LL + Ok(_) | Err(_) => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty + --> $DIR/empty-types.rs:321:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `[!; 3]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty + --> $DIR/empty-types.rs:326:11 + | +LL | match slice_never {} + | ^^^^^^^^^^^ + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match slice_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered + --> $DIR/empty-types.rs:328:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ pattern `&[_, ..]` not covered + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ [] => {}, +LL + &[_, ..] => todo!() + | + +error[E0004]: non-exhaustive patterns: `&[]`, `&[_]` and `&[_, _]` not covered + --> $DIR/empty-types.rs:337:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _]` not covered + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ [_, _, _, ..] => {}, +LL + &[] | &[_] | &[_, _] => todo!() + | + +error[E0004]: non-exhaustive patterns: `&[]` and `&[_, ..]` not covered + --> $DIR/empty-types.rs:350:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ patterns `&[]` and `&[_, ..]` not covered + | + = note: the matched value is of type `&[!]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ &[..] if false => {}, +LL + &[] | &[_, ..] => todo!() + | + +error[E0004]: non-exhaustive patterns: type `[!]` is non-empty + --> $DIR/empty-types.rs:356:11 + | +LL | match *slice_never {} + | ^^^^^^^^^^^^ + | + = note: the matched value is of type `[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *slice_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:366:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:369:9 + | +LL | [_, _, _] => {} + | ^^^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:372:9 + | +LL | [_, ..] => {} + | ^^^^^^^ + +error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty + --> $DIR/empty-types.rs:386:11 + | +LL | match array_0_never {} + | ^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; 0]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match array_0_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:393:9 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-types.rs:395:11 + | +LL | match array_0_never { + | ^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; 0]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ [..] if false => {}, +LL + [] => todo!() + | + +error: unreachable pattern + --> $DIR/empty-types.rs:414:9 + | +LL | Some(_) => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:419:9 + | +LL | Some(_a) => {} + | ^^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:424:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:429:9 + | +LL | _a => {} + | ^^ + +error[E0004]: non-exhaustive patterns: `&Some(_)` not covered + --> $DIR/empty-types.rs:449:11 + | +LL | match ref_opt_never { + | ^^^^^^^^^^^^^ pattern `&Some(_)` not covered + | +note: `Option` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `&Option` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ &None => {}, +LL + &Some(_) => todo!() + | + +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> $DIR/empty-types.rs:490:11 + | +LL | match *ref_opt_never { + | ^^^^^^^^^^^^^^ pattern `Some(_)` not covered + | +note: `Option` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(_) => todo!() + | + +error[E0004]: non-exhaustive patterns: `Err(_)` not covered + --> $DIR/empty-types.rs:538:11 + | +LL | match *ref_res_never { + | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered + | +note: `Result` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Ok(_) => {}, +LL + Err(_) => todo!() + | + +error[E0004]: non-exhaustive patterns: `Err(_)` not covered + --> $DIR/empty-types.rs:549:11 + | +LL | match *ref_res_never { + | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered + | +note: `Result` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Ok(_a) => {}, +LL + Err(_) => todo!() + | + +error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty + --> $DIR/empty-types.rs:568:11 + | +LL | match *ref_tuple_half_never {} + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `(u32, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *ref_tuple_half_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:601:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:604:9 + | +LL | _x => {} + | ^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:607:9 + | +LL | _ if false => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:610:9 + | +LL | _x if false => {} + | ^^ + +error[E0004]: non-exhaustive patterns: `&_` not covered + --> $DIR/empty-types.rs:635:11 + | +LL | match ref_never { + | ^^^^^^^^^ pattern `&_` not covered + | + = note: the matched value is of type `&!` + = note: references are always considered inhabited + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ &_a if false => {}, +LL + &_ => todo!() + | + +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> $DIR/empty-types.rs:663:11 + | +LL | match *x { + | ^^ pattern `Some(_)` not covered + | +note: `Option>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(_) => todo!() + | + +error: aborting due to 63 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0004, E0005. +For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.normal.stderr b/tests/ui/pattern/usefulness/empty-types.normal.stderr index 133a95a821ba3..2fdb51677dac5 100644 --- a/tests/ui/pattern/usefulness/empty-types.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-types.normal.stderr @@ -1,23 +1,23 @@ error: unreachable pattern - --> $DIR/empty-types.rs:47:9 + --> $DIR/empty-types.rs:50:9 | LL | _ => {} | ^ | note: the lint level is defined here - --> $DIR/empty-types.rs:13:9 + --> $DIR/empty-types.rs:16:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:50:9 + --> $DIR/empty-types.rs:53:9 | LL | _x => {} | ^^ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:54:11 + --> $DIR/empty-types.rs:57:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -32,7 +32,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:66:11 + --> $DIR/empty-types.rs:69:11 | LL | match tuple_half_never {} | ^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:73:11 + --> $DIR/empty-types.rs:76:11 | LL | match tuple_never {} | ^^^^^^^^^^^ @@ -60,13 +60,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:83:9 + --> $DIR/empty-types.rs:86:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:87:11 + --> $DIR/empty-types.rs:90:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered @@ -88,7 +88,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:89:11 + --> $DIR/empty-types.rs:92:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -106,7 +106,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:97:11 + --> $DIR/empty-types.rs:100:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -124,7 +124,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:102:9 + --> $DIR/empty-types.rs:105:9 | LL | let Ok(_x) = res_u32_never; | ^^^^^^ pattern `Err(_)` not covered @@ -138,7 +138,7 @@ LL | let Ok(_x) = res_u32_never else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:104:9 + --> $DIR/empty-types.rs:107:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -152,7 +152,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:108:9 + --> $DIR/empty-types.rs:111:9 | LL | let Ok(_x) = &res_u32_never; | ^^^^^^ pattern `&Err(_)` not covered @@ -166,7 +166,7 @@ LL | let Ok(_x) = &res_u32_never else { todo!() }; | ++++++++++++++++ error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:112:11 + --> $DIR/empty-types.rs:115:11 | LL | match result_never {} | ^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered @@ -188,7 +188,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:117:11 + --> $DIR/empty-types.rs:120:11 | LL | match result_never { | ^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -205,19 +205,19 @@ LL | Ok(_) => {}, Err(_) => todo!() | +++++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:136:13 + --> $DIR/empty-types.rs:139:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:139:13 + --> $DIR/empty-types.rs:142:13 | LL | _ if false => {} | ^ error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:142:15 + --> $DIR/empty-types.rs:145:15 | LL | match opt_void { | ^^^^^^^^ pattern `Some(_)` not covered @@ -235,7 +235,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:161:15 + --> $DIR/empty-types.rs:164:15 | LL | match *ref_opt_void { | ^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -253,43 +253,43 @@ LL + Some(_) => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:204:13 + --> $DIR/empty-types.rs:207:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:209:13 + --> $DIR/empty-types.rs:212:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:214:13 + --> $DIR/empty-types.rs:217:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:219:13 + --> $DIR/empty-types.rs:222:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:225:13 + --> $DIR/empty-types.rs:228:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:284:9 + --> $DIR/empty-types.rs:287:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:312:11 + --> $DIR/empty-types.rs:315:11 | LL | match *x {} | ^^ @@ -303,7 +303,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:314:11 + --> $DIR/empty-types.rs:317:11 | LL | match *x {} | ^^ @@ -317,7 +317,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:316:11 + --> $DIR/empty-types.rs:319:11 | LL | match *x {} | ^^ patterns `Ok(_)` and `Err(_)` not covered @@ -339,7 +339,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:318:11 + --> $DIR/empty-types.rs:321:11 | LL | match *x {} | ^^ @@ -353,7 +353,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:323:11 + --> $DIR/empty-types.rs:326:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -367,7 +367,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered - --> $DIR/empty-types.rs:325:11 + --> $DIR/empty-types.rs:328:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[_, ..]` not covered @@ -380,7 +380,7 @@ LL + &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: `&[]`, `&[_]` and `&[_, _]` not covered - --> $DIR/empty-types.rs:334:11 + --> $DIR/empty-types.rs:337:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _]` not covered @@ -393,7 +393,7 @@ LL + &[] | &[_] | &[_, _] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` and `&[_, ..]` not covered - --> $DIR/empty-types.rs:347:11 + --> $DIR/empty-types.rs:350:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]` and `&[_, ..]` not covered @@ -407,7 +407,7 @@ LL + &[] | &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:353:11 + --> $DIR/empty-types.rs:356:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:360:11 + --> $DIR/empty-types.rs:363:11 | LL | match array_3_never {} | ^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:383:11 + --> $DIR/empty-types.rs:386:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -449,13 +449,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:390:9 + --> $DIR/empty-types.rs:393:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:392:11 + --> $DIR/empty-types.rs:395:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -469,7 +469,7 @@ LL + [] => todo!() | error[E0004]: non-exhaustive patterns: `&Some(_)` not covered - --> $DIR/empty-types.rs:446:11 + --> $DIR/empty-types.rs:449:11 | LL | match ref_opt_never { | ^^^^^^^^^^^^^ pattern `&Some(_)` not covered @@ -487,7 +487,7 @@ LL + &Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:487:11 + --> $DIR/empty-types.rs:490:11 | LL | match *ref_opt_never { | ^^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -505,7 +505,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:535:11 + --> $DIR/empty-types.rs:538:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -523,7 +523,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:546:11 + --> $DIR/empty-types.rs:549:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -541,7 +541,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:565:11 + --> $DIR/empty-types.rs:568:11 | LL | match *ref_tuple_half_never {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -555,31 +555,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:598:9 + --> $DIR/empty-types.rs:601:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:601:9 + --> $DIR/empty-types.rs:604:9 | LL | _x => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:604:9 + --> $DIR/empty-types.rs:607:9 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:607:9 + --> $DIR/empty-types.rs:610:9 | LL | _x if false => {} | ^^ error[E0004]: non-exhaustive patterns: `&_` not covered - --> $DIR/empty-types.rs:631:11 + --> $DIR/empty-types.rs:635:11 | LL | match ref_never { | ^^^^^^^^^ pattern `&_` not covered @@ -594,7 +594,7 @@ LL + &_ => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:659:11 + --> $DIR/empty-types.rs:663:11 | LL | match *x { | ^^ pattern `Some(_)` not covered diff --git a/tests/ui/pattern/usefulness/empty-types.rs b/tests/ui/pattern/usefulness/empty-types.rs index 1e1d23e446d4c..c66fd1edc19ec 100644 --- a/tests/ui/pattern/usefulness/empty-types.rs +++ b/tests/ui/pattern/usefulness/empty-types.rs @@ -1,4 +1,5 @@ -// revisions: normal exhaustive_patterns +// revisions: normal min_exh_pats exhaustive_patterns +// gate-test-min_exhaustive_patterns // // This tests correct handling of empty types in exhaustiveness checking. // @@ -9,6 +10,8 @@ // This feature is useful to avoid `!` falling back to `()` all the time. #![feature(never_type_fallback)] #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] +#![cfg_attr(min_exh_pats, feature(min_exhaustive_patterns))] +//[min_exh_pats]~^ WARN the feature `min_exhaustive_patterns` is incomplete #![allow(dead_code, unreachable_code)] #![deny(unreachable_patterns)] @@ -66,17 +69,17 @@ fn basic(x: NeverBundle) { match tuple_half_never {} //[normal]~^ ERROR non-empty match tuple_half_never { - (_, _) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let tuple_never: (!, !) = x.tuple_never; match tuple_never {} //[normal]~^ ERROR non-empty match tuple_never { - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match tuple_never { - (_, _) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match tuple_never.0 {} match tuple_never.0 { @@ -92,12 +95,12 @@ fn basic(x: NeverBundle) { } match res_u32_never { Ok(_) => {} - Err(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match res_u32_never { //~^ ERROR non-exhaustive Ok(0) => {} - Err(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let Ok(_x) = res_u32_never; //[normal]~^ ERROR refutable @@ -106,25 +109,25 @@ fn basic(x: NeverBundle) { // Non-obvious difference: here there's an implicit dereference in the patterns, which makes the // inner place !known_valid. `exhaustive_patterns` ignores this. let Ok(_x) = &res_u32_never; - //[normal]~^ ERROR refutable + //[normal,min_exh_pats]~^ ERROR refutable let result_never: Result = x.result_never; match result_never {} //[normal]~^ ERROR non-exhaustive match result_never { - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { //[normal]~^ ERROR non-exhaustive - Ok(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern - Err(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } } @@ -145,11 +148,11 @@ fn void_same_as_never(x: NeverBundle) { } match opt_void { None => {} - Some(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Some(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match opt_void { None => {} - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let ref_void: &Void = &x.void; @@ -159,7 +162,7 @@ fn void_same_as_never(x: NeverBundle) { } let ref_opt_void: &Option = &None; match *ref_opt_void { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_void { @@ -284,11 +287,11 @@ fn nested_validity_tracking(bundle: NeverBundle) { _ => {} //~ ERROR unreachable pattern } match tuple_never { - (_, _) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { - Ok(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern - Err(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern + Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } // These should be considered !known_valid and not warn unreachable. @@ -309,13 +312,13 @@ fn invalid_empty_match(bundle: NeverBundle) { match *x {} let x: &(u32, !) = &bundle.tuple_half_never; - match *x {} //[normal]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive let x: &(!, !) = &bundle.tuple_never; - match *x {} //[normal]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive let x: &Result = &bundle.result_never; - match *x {} //[normal]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive let x: &[!; 3] = &bundle.array_3_never; - match *x {} //[normal]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive } fn arrays_and_slices(x: NeverBundle) { @@ -323,7 +326,7 @@ fn arrays_and_slices(x: NeverBundle) { match slice_never {} //~^ ERROR non-empty match slice_never { - //[normal]~^ ERROR not covered + //[normal,min_exh_pats]~^ ERROR not covered [] => {} } match slice_never { @@ -332,7 +335,7 @@ fn arrays_and_slices(x: NeverBundle) { [_, _, ..] => {} } match slice_never { - //[normal]~^ ERROR `&[]`, `&[_]` and `&[_, _]` not covered + //[normal,min_exh_pats]~^ ERROR `&[]`, `&[_]` and `&[_, _]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered [_, _, _, ..] => {} } @@ -345,7 +348,7 @@ fn arrays_and_slices(x: NeverBundle) { _x => {} } match slice_never { - //[normal]~^ ERROR `&[]` and `&[_, ..]` not covered + //[normal,min_exh_pats]~^ ERROR `&[]` and `&[_, ..]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered &[..] if false => {} } @@ -360,13 +363,13 @@ fn arrays_and_slices(x: NeverBundle) { match array_3_never {} //[normal]~^ ERROR non-empty match array_3_never { - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match array_3_never { - [_, _, _] => {} //[exhaustive_patterns]~ ERROR unreachable pattern + [_, _, _] => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match array_3_never { - [_, ..] => {} //[exhaustive_patterns]~ ERROR unreachable pattern + [_, ..] => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let ref_array_3_never: &[!; 3] = &array_3_never; @@ -408,22 +411,22 @@ fn bindings(x: NeverBundle) { match opt_never { None => {} // !useful, !reachable - Some(_) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Some(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - Some(_a) => {} //[exhaustive_patterns]~ ERROR unreachable pattern + Some(_a) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - _ => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match opt_never { None => {} // !useful, !reachable - _a => {} //[exhaustive_patterns]~ ERROR unreachable pattern + _a => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } // The scrutinee is known_valid, but under the `&` isn't anymore. @@ -444,7 +447,7 @@ fn bindings(x: NeverBundle) { &_a => {} } match ref_opt_never { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive &None => {} } match ref_opt_never { @@ -485,7 +488,7 @@ fn bindings(x: NeverBundle) { ref _a => {} } match *ref_opt_never { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_never { @@ -533,7 +536,7 @@ fn bindings(x: NeverBundle) { let ref_res_never: &Result = &x.result_never; match *ref_res_never { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive // useful, reachable Ok(_) => {} } @@ -544,7 +547,7 @@ fn bindings(x: NeverBundle) { _ => {} } match *ref_res_never { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive // useful, !reachable Ok(_a) => {} } @@ -563,7 +566,7 @@ fn bindings(x: NeverBundle) { let ref_tuple_half_never: &(u32, !) = &x.tuple_half_never; match *ref_tuple_half_never {} - //[normal]~^ ERROR non-empty + //[normal,min_exh_pats]~^ ERROR non-empty match *ref_tuple_half_never { // useful, reachable (_, _) => {} @@ -614,6 +617,7 @@ fn guards_and_validity(x: NeverBundle) { // useful, reachable _ => {} } + // Now the madness commences. The guard caused a load of the value thus asserting validity. So // there's no invalid value for `_` to catch. So the second pattern is unreachable despite the // guard not being taken. @@ -629,7 +633,7 @@ fn guards_and_validity(x: NeverBundle) { _a if false => {} } match ref_never { - //[normal]~^ ERROR non-exhaustive + //[normal,min_exh_pats]~^ ERROR non-exhaustive // useful, !reachable &_a if false => {} } @@ -657,7 +661,7 @@ fn diagnostics_subtlety(x: NeverBundle) { // Regression test for diagnostics: don't report `Some(Ok(_))` and `Some(Err(_))`. let x: &Option> = &None; match *x { - //[normal]~^ ERROR `Some(_)` not covered + //[normal,min_exh_pats]~^ ERROR `Some(_)` not covered None => {} } } From 8866449c6672f3fc7887edb96616a46530e18947 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 19 Jan 2024 09:44:03 +0100 Subject: [PATCH 12/13] Split assembly tests for ELF and MachO On ELF, the text section is opened with ".text", on MachO with ".section __TEXT,__text". Previously, on ELF this test was actually matching a GNU note section, which is no longer emitted on Solaris starting with LLVM 18. Fixes https://github.com/rust-lang/rust/issues/120105. --- tests/assembly/targets/targets-elf.rs | 65 +------------------- tests/assembly/targets/targets-macho.rs | 81 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 64 deletions(-) create mode 100644 tests/assembly/targets/targets-macho.rs diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index f6f2f5e88ffc3..dee0fa9f4a410 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -1,29 +1,5 @@ // assembly-output: emit-asm // ignore-tidy-linelength -// revisions: aarch64_apple_darwin -// [aarch64_apple_darwin] compile-flags: --target aarch64-apple-darwin -// [aarch64_apple_darwin] needs-llvm-components: aarch64 -// revisions: aarch64_apple_ios -// [aarch64_apple_ios] compile-flags: --target aarch64-apple-ios -// [aarch64_apple_ios] needs-llvm-components: aarch64 -// revisions: aarch64_apple_ios_macabi -// [aarch64_apple_ios_macabi] compile-flags: --target aarch64-apple-ios-macabi -// [aarch64_apple_ios_macabi] needs-llvm-components: aarch64 -// revisions: aarch64_apple_ios_sim -// [aarch64_apple_ios_sim] compile-flags: --target aarch64-apple-ios-sim -// [aarch64_apple_ios_sim] needs-llvm-components: aarch64 -// revisions: aarch64_apple_tvos -// [aarch64_apple_tvos] compile-flags: --target aarch64-apple-tvos -// [aarch64_apple_tvos] needs-llvm-components: aarch64 -// revisions: aarch64_apple_tvos_sim -// [aarch64_apple_tvos_sim] compile-flags: --target aarch64-apple-tvos-sim -// [aarch64_apple_tvos_sim] needs-llvm-components: aarch64 -// revisions: aarch64_apple_watchos -// [aarch64_apple_watchos] compile-flags: --target aarch64-apple-watchos -// [aarch64_apple_watchos] needs-llvm-components: aarch64 -// revisions: aarch64_apple_watchos_sim -// [aarch64_apple_watchos_sim] compile-flags: --target aarch64-apple-watchos-sim -// [aarch64_apple_watchos_sim] needs-llvm-components: aarch64 // revisions: aarch64_be_unknown_linux_gnu // [aarch64_be_unknown_linux_gnu] compile-flags: --target aarch64_be-unknown-linux-gnu // [aarch64_be_unknown_linux_gnu] needs-llvm-components: aarch64 @@ -93,15 +69,6 @@ // revisions: aarch64_wrs_vxworks // [aarch64_wrs_vxworks] compile-flags: --target aarch64-wrs-vxworks // [aarch64_wrs_vxworks] needs-llvm-components: aarch64 -// revisions: arm64_32_apple_watchos -// [arm64_32_apple_watchos] compile-flags: --target arm64_32-apple-watchos -// [arm64_32_apple_watchos] needs-llvm-components: aarch64 -// revisions: arm64e_apple_darwin -// [arm64e_apple_darwin] compile-flags: --target arm64e-apple-darwin -// [arm64e_apple_darwin] needs-llvm-components: aarch64 -// revisions: arm64e_apple_ios -// [arm64e_apple_ios] compile-flags: --target arm64e-apple-ios -// [arm64e_apple_ios] needs-llvm-components: aarch64 // revisions: arm_linux_androideabi // [arm_linux_androideabi] compile-flags: --target arm-linux-androideabi // [arm_linux_androideabi] needs-llvm-components: arm @@ -201,18 +168,12 @@ // revisions: armv7a_none_eabihf // [armv7a_none_eabihf] compile-flags: --target armv7a-none-eabihf // [armv7a_none_eabihf] needs-llvm-components: arm -// revisions: armv7k_apple_watchos -// [armv7k_apple_watchos] compile-flags: --target armv7k-apple-watchos -// [armv7k_apple_watchos] needs-llvm-components: arm // revisions: armv7r_none_eabi // [armv7r_none_eabi] compile-flags: --target armv7r-none-eabi // [armv7r_none_eabi] needs-llvm-components: arm // revisions: armv7r_none_eabihf // [armv7r_none_eabihf] compile-flags: --target armv7r-none-eabihf // [armv7r_none_eabihf] needs-llvm-components: arm -// revisions: armv7s_apple_ios -// [armv7s_apple_ios] compile-flags: --target armv7s-apple-ios -// [armv7s_apple_ios] needs-llvm-components: arm // FIXME: disabled since it fails on CI saying the csky component is missing /* revisions: csky_unknown_linux_gnuabiv2 @@ -228,9 +189,6 @@ // revisions: hexagon_unknown_none_elf // [hexagon_unknown_none_elf] compile-flags: --target hexagon-unknown-none-elf // [hexagon_unknown_none_elf] needs-llvm-components: hexagon -// revisions: i386_apple_ios -// [i386_apple_ios] compile-flags: --target i386-apple-ios -// [i386_apple_ios] needs-llvm-components: x86 // revisions: i586_pc_nto_qnx700 // [i586_pc_nto_qnx700] compile-flags: --target i586-pc-nto-qnx700 // [i586_pc_nto_qnx700] needs-llvm-components: x86 @@ -243,9 +201,6 @@ // revisions: i586_unknown_netbsd // [i586_unknown_netbsd] compile-flags: --target i586-unknown-netbsd // [i586_unknown_netbsd] needs-llvm-components: x86 -// revisions: i686_apple_darwin -// [i686_apple_darwin] compile-flags: --target i686-apple-darwin -// [i686_apple_darwin] needs-llvm-components: x86 // revisions: i686_linux_android // [i686_linux_android] compile-flags: --target i686-linux-android // [i686_linux_android] needs-llvm-components: x86 @@ -537,21 +492,6 @@ // revisions: wasm32_wasi_preview2 // [wasm32_wasi_preview2] compile-flags: --target wasm32-wasi-preview2 // [wasm32_wasi_preview2] needs-llvm-components: webassembly -// revisions: x86_64_apple_darwin -// [x86_64_apple_darwin] compile-flags: --target x86_64-apple-darwin -// [x86_64_apple_darwin] needs-llvm-components: x86 -// revisions: x86_64_apple_ios -// [x86_64_apple_ios] compile-flags: --target x86_64-apple-ios -// [x86_64_apple_ios] needs-llvm-components: x86 -// revisions: x86_64_apple_ios_macabi -// [x86_64_apple_ios_macabi] compile-flags: --target x86_64-apple-ios-macabi -// [x86_64_apple_ios_macabi] needs-llvm-components: x86 -// revisions: x86_64_apple_tvos -// [x86_64_apple_tvos] compile-flags: --target x86_64-apple-tvos -// [x86_64_apple_tvos] needs-llvm-components: x86 -// revisions: x86_64_apple_watchos_sim -// [x86_64_apple_watchos_sim] compile-flags: --target x86_64-apple-watchos-sim -// [x86_64_apple_watchos_sim] needs-llvm-components: x86 // revisions: x86_64_fortanix_unknown_sgx // [x86_64_fortanix_unknown_sgx] compile-flags: --target x86_64-fortanix-unknown-sgx // [x86_64_fortanix_unknown_sgx] needs-llvm-components: x86 @@ -618,9 +558,6 @@ // revisions: x86_64_wrs_vxworks // [x86_64_wrs_vxworks] compile-flags: --target x86_64-wrs-vxworks // [x86_64_wrs_vxworks] needs-llvm-components: x86 -// revisions: x86_64h_apple_darwin -// [x86_64h_apple_darwin] compile-flags: --target x86_64h-apple-darwin -// [x86_64h_apple_darwin] needs-llvm-components: x86 // Sanity-check that each target can produce assembly code. @@ -636,4 +573,4 @@ pub fn test() -> u8 { 42 } -// CHECK: .section +// CHECK: .text diff --git a/tests/assembly/targets/targets-macho.rs b/tests/assembly/targets/targets-macho.rs new file mode 100644 index 0000000000000..ead9ccfc8e74e --- /dev/null +++ b/tests/assembly/targets/targets-macho.rs @@ -0,0 +1,81 @@ +// assembly-output: emit-asm +// ignore-tidy-linelength +// revisions: aarch64_apple_darwin +// [aarch64_apple_darwin] compile-flags: --target aarch64-apple-darwin +// [aarch64_apple_darwin] needs-llvm-components: aarch64 +// revisions: aarch64_apple_ios +// [aarch64_apple_ios] compile-flags: --target aarch64-apple-ios +// [aarch64_apple_ios] needs-llvm-components: aarch64 +// revisions: aarch64_apple_ios_macabi +// [aarch64_apple_ios_macabi] compile-flags: --target aarch64-apple-ios-macabi +// [aarch64_apple_ios_macabi] needs-llvm-components: aarch64 +// revisions: aarch64_apple_ios_sim +// [aarch64_apple_ios_sim] compile-flags: --target aarch64-apple-ios-sim +// [aarch64_apple_ios_sim] needs-llvm-components: aarch64 +// revisions: aarch64_apple_tvos +// [aarch64_apple_tvos] compile-flags: --target aarch64-apple-tvos +// [aarch64_apple_tvos] needs-llvm-components: aarch64 +// revisions: aarch64_apple_tvos_sim +// [aarch64_apple_tvos_sim] compile-flags: --target aarch64-apple-tvos-sim +// [aarch64_apple_tvos_sim] needs-llvm-components: aarch64 +// revisions: aarch64_apple_watchos +// [aarch64_apple_watchos] compile-flags: --target aarch64-apple-watchos +// [aarch64_apple_watchos] needs-llvm-components: aarch64 +// revisions: aarch64_apple_watchos_sim +// [aarch64_apple_watchos_sim] compile-flags: --target aarch64-apple-watchos-sim +// [aarch64_apple_watchos_sim] needs-llvm-components: aarch64 +// revisions: arm64_32_apple_watchos +// [arm64_32_apple_watchos] compile-flags: --target arm64_32-apple-watchos +// [arm64_32_apple_watchos] needs-llvm-components: aarch64 +// revisions: arm64e_apple_darwin +// [arm64e_apple_darwin] compile-flags: --target arm64e-apple-darwin +// [arm64e_apple_darwin] needs-llvm-components: aarch64 +// revisions: arm64e_apple_ios +// [arm64e_apple_ios] compile-flags: --target arm64e-apple-ios +// [arm64e_apple_ios] needs-llvm-components: aarch64 +// revisions: armv7k_apple_watchos +// [armv7k_apple_watchos] compile-flags: --target armv7k-apple-watchos +// [armv7k_apple_watchos] needs-llvm-components: arm +// revisions: armv7s_apple_ios +// [armv7s_apple_ios] compile-flags: --target armv7s-apple-ios +// [armv7s_apple_ios] needs-llvm-components: arm +// revisions: i386_apple_ios +// [i386_apple_ios] compile-flags: --target i386-apple-ios +// [i386_apple_ios] needs-llvm-components: x86 +// revisions: i686_apple_darwin +// [i686_apple_darwin] compile-flags: --target i686-apple-darwin +// [i686_apple_darwin] needs-llvm-components: x86 +// revisions: x86_64_apple_darwin +// [x86_64_apple_darwin] compile-flags: --target x86_64-apple-darwin +// [x86_64_apple_darwin] needs-llvm-components: x86 +// revisions: x86_64_apple_ios +// [x86_64_apple_ios] compile-flags: --target x86_64-apple-ios +// [x86_64_apple_ios] needs-llvm-components: x86 +// revisions: x86_64_apple_ios_macabi +// [x86_64_apple_ios_macabi] compile-flags: --target x86_64-apple-ios-macabi +// [x86_64_apple_ios_macabi] needs-llvm-components: x86 +// revisions: x86_64_apple_tvos +// [x86_64_apple_tvos] compile-flags: --target x86_64-apple-tvos +// [x86_64_apple_tvos] needs-llvm-components: x86 +// revisions: x86_64_apple_watchos_sim +// [x86_64_apple_watchos_sim] compile-flags: --target x86_64-apple-watchos-sim +// [x86_64_apple_watchos_sim] needs-llvm-components: x86 +// revisions: x86_64h_apple_darwin +// [x86_64h_apple_darwin] compile-flags: --target x86_64h-apple-darwin +// [x86_64h_apple_darwin] needs-llvm-components: x86 + +// Sanity-check that each target can produce assembly code. + +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] +#![crate_type = "lib"] + +#[lang = "sized"] +trait Sized {} + +pub fn test() -> u8 { + 42 +} + +// CHECK: .section __TEXT,__text From 27717dbd4d0df888e66661690199d5dd07078259 Mon Sep 17 00:00:00 2001 From: Andrew Zhogin Date: Mon, 22 Jan 2024 00:58:50 +0700 Subject: [PATCH 13/13] Builtin macros effectively have implicit #[collapse_debuginfo(yes)] attribute --- compiler/rustc_expand/src/base.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 29b70f33a6c7d..657e19277a7ed 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -796,9 +796,15 @@ impl SyntaxExtension { /// | external | no | if-ext | if-ext | yes | /// | yes | yes | yes | yes | yes | fn get_collapse_debuginfo(sess: &Session, attrs: &[ast::Attribute], is_local: bool) -> bool { - let collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo) + let mut collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo) .map(|v| Self::collapse_debuginfo_by_name(sess, v)) .unwrap_or(CollapseMacroDebuginfo::Unspecified); + if collapse_debuginfo_attr == CollapseMacroDebuginfo::Unspecified + && attr::contains_name(attrs, sym::rustc_builtin_macro) + { + collapse_debuginfo_attr = CollapseMacroDebuginfo::Yes; + } + let flag = sess.opts.unstable_opts.collapse_macro_debuginfo; let attr = collapse_debuginfo_attr; let ext = !is_local;