Skip to content

Commit 158ae9e

Browse files
committed
Auto merge of #151360 - JonathanBrouwer:rollup-UpAM1gc, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #151071 (Generate openmp metadata) - #151302 (add lint test) - #151338 (Factor out diagnostic slug checking from `DiagnosticDerive` ) - #151354 (ci: Move lockfile updates to a script) r? @ghost
2 parents 53b6f89 + 20262a2 commit 158ae9e

File tree

8 files changed

+113
-97
lines changed

8 files changed

+113
-97
lines changed

.github/workflows/dependencies.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,9 @@ jobs:
6262
rustup toolchain install --no-self-update --profile minimal $TOOLCHAIN
6363
rustup default $TOOLCHAIN
6464
65-
- name: cargo update compiler & tools
66-
# Remove first line that always just says "Updating crates.io index"
67-
run: |
68-
echo -e "\ncompiler & tools dependencies:" >> cargo_update.log
69-
cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
70-
- name: cargo update library
71-
run: |
72-
echo -e "\nlibrary dependencies:" >> cargo_update.log
73-
cargo update --manifest-path library/Cargo.toml 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
74-
- name: cargo update rustbook
75-
run: |
76-
echo -e "\nrustbook dependencies:" >> cargo_update.log
77-
cargo update --manifest-path src/tools/rustbook/Cargo.toml 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
65+
- name: cargo update
66+
run: ./src/tools/update-lockfile.sh
67+
7868
- name: upload Cargo.lock artifact for use in PR
7969
uses: actions/upload-artifact@v4
8070
with:

compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ impl<'ll> OffloadGlobals<'ll> {
5555
let init_ty = cx.type_func(&[], cx.type_void());
5656
let init_rtls = declare_offload_fn(cx, "__tgt_init_all_rtls", init_ty);
5757

58+
// We want LLVM's openmp-opt pass to pick up and optimize this module, since it covers both
59+
// openmp and offload optimizations.
60+
llvm::add_module_flag_u32(cx.llmod(), llvm::ModuleFlagMergeBehavior::Max, "openmp", 51);
61+
5862
OffloadGlobals {
5963
launcher_fn,
6064
launcher_ty,

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use std::cell::RefCell;
44

55
use proc_macro2::TokenStream;
66
use quote::quote;
7-
use syn::spanned::Spanned;
87
use synstructure::Structure;
98

109
use crate::diagnostics::diagnostic_builder::DiagnosticDeriveKind;
11-
use crate::diagnostics::error::{DiagnosticDeriveError, span_err};
12-
use crate::diagnostics::utils::SetOnce;
10+
use crate::diagnostics::error::DiagnosticDeriveError;
1311

1412
/// The central struct for constructing the `into_diag` method from an annotated struct.
1513
pub(crate) struct DiagnosticDerive<'a> {
@@ -29,36 +27,16 @@ impl<'a> DiagnosticDerive<'a> {
2927
let preamble = builder.preamble(variant);
3028
let body = builder.body(variant);
3129

32-
let init = match builder.slug.value_ref() {
33-
None => {
34-
span_err(builder.span, "diagnostic slug not specified")
35-
.help(
36-
"specify the slug as the first argument to the `#[diag(...)]` \
37-
attribute, such as `#[diag(hir_analysis_example_error)]`",
38-
)
39-
.emit();
40-
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
41-
}
42-
Some(slug)
43-
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) =
44-
Mismatch::check(slug) =>
45-
{
46-
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
47-
.note(format!("slug is `{slug_name}` but the crate name is `{crate_name}`"))
48-
.help(format!("expected a slug starting with `{slug_prefix}_...`"))
49-
.emit();
50-
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
51-
}
52-
Some(slug) => {
53-
slugs.borrow_mut().push(slug.clone());
54-
quote! {
55-
let mut diag = rustc_errors::Diag::new(
56-
dcx,
57-
level,
58-
crate::fluent_generated::#slug
59-
);
60-
}
61-
}
30+
let Some(slug) = builder.primary_message() else {
31+
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
32+
};
33+
slugs.borrow_mut().push(slug.clone());
34+
let init = quote! {
35+
let mut diag = rustc_errors::Diag::new(
36+
dcx,
37+
level,
38+
crate::fluent_generated::#slug
39+
);
6240
};
6341

6442
let formatting_init = &builder.formatting_init;
@@ -113,32 +91,12 @@ impl<'a> LintDiagnosticDerive<'a> {
11391
let preamble = builder.preamble(variant);
11492
let body = builder.body(variant);
11593

116-
let primary_message = match builder.slug.value_ref() {
117-
None => {
118-
span_err(builder.span, "diagnostic slug not specified")
119-
.help(
120-
"specify the slug as the first argument to the attribute, such as \
121-
`#[diag(compiletest_example)]`",
122-
)
123-
.emit();
124-
DiagnosticDeriveError::ErrorHandled.to_compile_error()
125-
}
126-
Some(slug)
127-
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) =
128-
Mismatch::check(slug) =>
129-
{
130-
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
131-
.note(format!("slug is `{slug_name}` but the crate name is `{crate_name}`"))
132-
.help(format!("expected a slug starting with `{slug_prefix}_...`"))
133-
.emit();
134-
DiagnosticDeriveError::ErrorHandled.to_compile_error()
135-
}
136-
Some(slug) => {
137-
slugs.borrow_mut().push(slug.clone());
138-
quote! {
139-
diag.primary_message(crate::fluent_generated::#slug);
140-
}
141-
}
94+
let Some(slug) = builder.primary_message() else {
95+
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
96+
};
97+
slugs.borrow_mut().push(slug.clone());
98+
let primary_message = quote! {
99+
diag.primary_message(crate::fluent_generated::#slug);
142100
};
143101

144102
let formatting_init = &builder.formatting_init;
@@ -172,30 +130,6 @@ impl<'a> LintDiagnosticDerive<'a> {
172130
}
173131
}
174132

175-
struct Mismatch {
176-
slug_name: String,
177-
crate_name: String,
178-
slug_prefix: String,
179-
}
180-
181-
impl Mismatch {
182-
/// Checks whether the slug starts with the crate name it's in.
183-
fn check(slug: &syn::Path) -> Option<Mismatch> {
184-
// If this is missing we're probably in a test, so bail.
185-
let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;
186-
187-
// If we're not in a "rustc_" crate, bail.
188-
let Some(("rustc", slug_prefix)) = crate_name.split_once('_') else { return None };
189-
190-
let slug_name = slug.segments.first()?.ident.to_string();
191-
if !slug_name.starts_with(slug_prefix) {
192-
Some(Mismatch { slug_name, slug_prefix: slug_prefix.to_string(), crate_name })
193-
} else {
194-
None
195-
}
196-
}
197-
}
198-
199133
/// Generates a `#[test]` that verifies that all referenced variables
200134
/// exist on this structure.
201135
fn generate_test(slug: &syn::Path, structure: &Structure<'_>) -> TokenStream {

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ impl DiagnosticDeriveKind {
110110
}
111111

112112
impl DiagnosticDeriveVariantBuilder {
113+
pub(crate) fn primary_message(&self) -> Option<&Path> {
114+
match self.slug.value_ref() {
115+
None => {
116+
span_err(self.span, "diagnostic slug not specified")
117+
.help(
118+
"specify the slug as the first argument to the `#[diag(...)]` \
119+
attribute, such as `#[diag(hir_analysis_example_error)]`",
120+
)
121+
.emit();
122+
None
123+
}
124+
Some(slug)
125+
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) =
126+
Mismatch::check(slug) =>
127+
{
128+
span_err(slug.span().unwrap(), "diagnostic slug and crate name do not match")
129+
.note(format!("slug is `{slug_name}` but the crate name is `{crate_name}`"))
130+
.help(format!("expected a slug starting with `{slug_prefix}_...`"))
131+
.emit();
132+
None
133+
}
134+
Some(slug) => Some(slug),
135+
}
136+
}
137+
113138
/// Generates calls to `code` and similar functions based on the attributes on the type or
114139
/// variant.
115140
pub(crate) fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
@@ -504,3 +529,27 @@ impl DiagnosticDeriveVariantBuilder {
504529
}
505530
}
506531
}
532+
533+
struct Mismatch {
534+
slug_name: String,
535+
crate_name: String,
536+
slug_prefix: String,
537+
}
538+
539+
impl Mismatch {
540+
/// Checks whether the slug starts with the crate name it's in.
541+
fn check(slug: &syn::Path) -> Option<Mismatch> {
542+
// If this is missing we're probably in a test, so bail.
543+
let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;
544+
545+
// If we're not in a "rustc_" crate, bail.
546+
let Some(("rustc", slug_prefix)) = crate_name.split_once('_') else { return None };
547+
548+
let slug_name = slug.segments.first()?.ident.to_string();
549+
if slug_name.starts_with(slug_prefix) {
550+
return None;
551+
}
552+
553+
Some(Mismatch { slug_name, slug_prefix: slug_prefix.to_string(), crate_name })
554+
}
555+
}

src/tools/update-lockfile.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# Updates the workspaces in `.`, `library` and `src/tools/rustbook`
4+
# Logs are written to `cargo_update.log`
5+
# Used as part of regular dependency bumps
6+
7+
set -euo pipefail
8+
9+
echo -e "\ncompiler & tools dependencies:" > cargo_update.log
10+
# Remove first line that always just says "Updating crates.io index"
11+
cargo update 2>&1 | sed '/crates.io index/d' | \
12+
tee -a cargo_update.log
13+
echo -e "\nlibrary dependencies:" >> cargo_update.log
14+
cargo update --manifest-path library/Cargo.toml 2>&1 | sed '/crates.io index/d' | \
15+
tee -a cargo_update.log
16+
echo -e "\nrustbook dependencies:" >> cargo_update.log
17+
cargo update --manifest-path src/tools/rustbook/Cargo.toml 2>&1 | sed '/crates.io index/d' | \
18+
tee -a cargo_update.log

tests/codegen-llvm/gpu_offload/gpu_host.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ pub fn _kernel_1(x: &mut [f32; 256]) {
104104
// CHECK-NEXT: call void @__tgt_unregister_lib(ptr nonnull %EmptyDesc)
105105
// CHECK-NEXT: ret void
106106
// CHECK-NEXT: }
107+
108+
// CHECK: !{i32 7, !"openmp", i32 51}

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ error: derive(Diagnostic): diagnostic slug not specified
384384
LL | #[lint(no_crate_example, code = E0123)]
385385
| ^
386386
|
387-
= help: specify the slug as the first argument to the attribute, such as `#[diag(compiletest_example)]`
387+
= help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
388388

389389
error: derive(Diagnostic): attribute specified multiple times
390390
--> $DIR/diagnostic-derive.rs:613:53
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/138069>
2+
// This test ensures that unused_assignments does not report assignments used in a match.
3+
//@ check-pass
4+
5+
fn pnk(x: usize) -> &'static str {
6+
let mut k1 = "k1";
7+
let mut h1 = "h1";
8+
match x & 3 {
9+
3 if { k1 = "unused?"; false } => (),
10+
_ if { h1 = k1; true } => (),
11+
_ => (),
12+
}
13+
h1
14+
}
15+
16+
#[deny(unused_assignments)]
17+
fn main() {
18+
pnk(3);
19+
}

0 commit comments

Comments
 (0)