Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5fbbf47
std: Use getexecpath() for current_exe() on OpenBSD
brad0 Oct 15, 2026
05a72d2
Rewrite `--print-config` integration tests
matthewhughes934 Oct 16, 2026
d7ecf4d
Update config discovery integration tests
matthewhughes934 Oct 17, 2026
a50d9a9
Allow `llm-assisted` label to be set by users without write access
jieyouxu Oct 22, 2026
fad0b13
Add test demonstrating current error leak formatting
jieyouxu Oct 16, 2026
b1c0b19
Properly reset error count for `cfg_if!`
jieyouxu Oct 16, 2026
44a8861
Merge pull request #7196 from matthewhughes934/integration-test-updates
jieyouxu Oct 22, 2026
28968c5
Merge pull request #7195 from jieyouxu/jieyouxu/cfg-if
jieyouxu Oct 22, 2026
ba09f12
Integration tests: also capture exit code
matthewhughes934 Oct 19, 2026
0772c1d
Merge pull request #7207 from jieyouxu/jieyouxu/triagebot-label
ytmimi Oct 22, 2026
4689345
test: rename multi-file `cfg_select!` tests subfolder
jieyouxu Oct 23, 2026
49c47fc
test: group `cfg_select!` related tests under subfolder
jieyouxu Oct 23, 2026
04d74ce
test: add regression test for miri between-block comment
jieyouxu Oct 23, 2026
44541eb
fix(cfg_select): don't use concise format when in-between comments exist
jieyouxu Oct 23, 2026
018f54c
fix(cfg_select): don't lose comments/attrs between `=>` and arm expr
jieyouxu Oct 23, 2026
0aff56c
fix(cfg_select): don't lose comments between predicate and `=>`
jieyouxu Oct 23, 2026
0dd546a
fix(cfg_select): don't lose comment between body and trailing comma
jieyouxu Oct 23, 2026
9ab72ab
Merge pull request #7211 from jieyouxu/jieyouxu/cfg-select-comments
jieyouxu Oct 24, 2026
a5198eb
test(cfg_select): snapshot current `control_brace_style` behavior
jieyouxu Oct 24, 2026
19cdcb6
refactor: exhaustively match on `token::LitKind`
ytmimi Oct 26, 2026
e5ad9ad
fix(cfg_select): respect `control_brace_style` config
jieyouxu Oct 24, 2026
3d87f59
test(cfg_select): add coverage for `control_brace_style` with comment…
jieyouxu Oct 25, 2026
67bfa44
test(cfg_select): add coverage for long comment before arrow
jieyouxu Oct 25, 2026
fe7d957
Merge pull request #7214 from jieyouxu/jieyouxu/cfg-select-control-br…
jieyouxu Oct 27, 2026
ecc66a8
ci: Disable credential persistence
hashcatHitman Oct 23, 2026
a754ca9
ci: Expand `github.event.inputs.commit_hash` in `env`
hashcatHitman Oct 23, 2026
2c9df22
ci: Expand `github.event.inputs.rustfmt_configs` in `env`
hashcatHitman Oct 23, 2026
ad47c3e
ci: Expand `github.event.inputs.clone_url` in `env`
hashcatHitman Oct 23, 2026
e2e3160
ci: Expand `github.event.inputs.branch_name` in `env`
hashcatHitman Oct 23, 2026
ce40bba
ci: Expand `github.event.inputs.language_edition` in `env`
hashcatHitman Oct 23, 2026
52d6915
ci: Expand `github.event.inputs.style_edition` in `env`
hashcatHitman Oct 23, 2026
9cda3d3
ci: Expand `github.event.release.tag_name` in `env`
hashcatHitman Oct 23, 2026
a16fdd3
ci: Prefer shell expansion over template expansion
hashcatHitman Oct 23, 2026
e6c6acb
ci: Expand `matrix.target` in `env`
hashcatHitman Oct 23, 2026
c136f96
ci: Expand `matrix.os` in `env`
hashcatHitman Oct 23, 2026
c47f1f6
ci: Expand `matrix.build` in `env`
hashcatHitman Oct 23, 2026
905157b
ci: Expand `matrix.integration` in `env`
hashcatHitman Oct 23, 2026
6c0248d
ci: Expand `matrix.package` in `env`
hashcatHitman Oct 23, 2026
febf7c1
ci: Expand `toJson(needs)` in `env`
hashcatHitman Oct 23, 2026
17a6414
ci: Disable all permissions by default
hashcatHitman Oct 24, 2026
1dde57f
ci: Grant minimum required permissions
hashcatHitman Oct 24, 2026
865b76d
Merge pull request #7216 from ytmimi/refactor_rewrite_literal
ytmimi Oct 27, 2026
f39d517
Integration test: assert on exit codes
matthewhughes934 Oct 19, 2026
302895a
Error on `--print-config minimal` with no output path
matthewhughes934 Oct 19, 2026
a7e179a
Remove test that writes within the repo
matthewhughes934 Oct 20, 2026
72ea442
Merge pull request #7208 from matthewhughes934/more-integration-tests
matthewhughes934 Oct 27, 2026
09026e0
avoid building a region map when erasing bound regions
TaKO8Ki Oct 29, 2026
12839e8
Merge pull request #7212 from hashcatHitman/zizmor
ytmimi Oct 30, 2026
b7e097e
Revert "Use saturating arithmetics for `adjust_max_width`"
jieyouxu Nov 2, 2026
bfd66ed
Revert "Fixes adjustment of max_width within macros"
jieyouxu Nov 2, 2026
380fd0d
Reuse CanonicalVarKinds if no new variables were added
Randl Nov 2, 2026
3db5134
Merge pull request #7222 from jieyouxu/jieyouxu/revert-macro-fmt
jieyouxu Nov 2, 2026
107a661
Prepare for merging from rust-lang/rust
jieyouxu Nov 2, 2026
977efa3
Merge ref '3e92e1a2d20b' (nightly-2026-11-02) from rust-lang/rust
jieyouxu Nov 2, 2026
bec2190
inline and cold attributes on async fn and async closures affect the …
xacrimon Sep 26, 2026
1c517b2
Don't keep #[rustc_force_inline] on async/gen fn constructors
xacrimon Nov 2, 2026
2caedab
Adapt async fn inline attrs to #[inline(always)] + #[target_feature] …
xacrimon Nov 2, 2026
0e44319
chore: prepare changelog for v1.12.0
jieyouxu Nov 2, 2026
3512466
chore: remove changelog entry that's intended to be reverted in beta
jieyouxu Nov 2, 2026
f237e20
chore: bump rustfmt version to v1.12.0
jieyouxu Nov 2, 2026
003a893
ci: remove no longer used `upload-assets` workflow
jieyouxu Nov 2, 2026
fb78ede
Merge pull request #7229 from jieyouxu/jieyouxu/remove-upload-assets
ytmimi Nov 2, 2026
9b1ceff
Reenable the cg_gcc tests that were disabled by accident
antoyo Nov 2, 2026
86fd101
rename sizedness_fast_path to implicit_fast_path
jdonszelmann Nov 2, 2026
1b8ce17
refactor implicit bounds addition
jdonszelmann Nov 2, 2026
7eb4e44
Implement AIX TLS destructor guard in std and update dynamic-loading-…
xingxue-ibm Oct 30, 2026
f0767bb
add is_implicit_trait to tcx
jdonszelmann Nov 2, 2026
aff3637
Don't use `llvm_type` as the type of `static`s.
beetrees Nov 2, 2026
79520af
Avoid oscillating line wrapping due to symbol indices
aytey Sep 10, 2026
0f763a0
Merge pull request #7226 from jieyouxu/subtree-pull-20261102
ytmimi Nov 3, 2026
fd17c29
Merge pull request #7227 from jieyouxu/jieyouxu/release/1.12.0
ytmimi Nov 3, 2026
be89a22
Replace `builtin # field_of` with `k#field_of`
fmease Sep 3, 2026
f2f5592
Replace `builtin # deref` with `k#deref`
fmease Sep 3, 2026
c9e0b0a
Replace `builtin # offset_of` with `k#offset_of`
fmease Sep 3, 2026
be1070c
Replace `builtin # type_ascribe` with `k#type_ascribe`
fmease Sep 3, 2026
ee888ba
Replace `builtin # {,un}wrap_binder` with `k#{,un}wrap_binder`
fmease Sep 3, 2026
2a9fdf5
Rename feature `builtin_syntax` to `internal_syntax`
fmease Sep 3, 2026
a72068e
Fix rigidity assertion ICE
lsunsi Nov 3, 2026
bb2e461
chore: bump rustfmt version to v1.12.0 in the r-l/r workspace
ytmimi Nov 3, 2026
e083b8b
offload: pass the linked device image to the host pass
sgasho Oct 24, 2026
b76246d
offload: make the device build work without `--emit=llvm-bc`/`llvm-ir`
sgasho Oct 25, 2026
c6749d8
offload: build bin crates as cdylib on the device side
sgasho Oct 29, 2026
dedfa67
Make `ExpectedLint` more general
JonathanBrouwer Oct 26, 2026
58c0988
Use `ExpectedLint` in more places
JonathanBrouwer Oct 27, 2026
cdc3205
Make diagnostic title consistent with other attributes
JonathanBrouwer Nov 3, 2026
b4c0d81
Rollup merge of #165378 - ytmimi:rustfmt-v1.12.0, r=jieyouxu
JonathanBrouwer Nov 3, 2026
45d60e4
Rollup merge of #149245 - xacrimon:acrimon/async-fn-inline-attr, r=sa…
JonathanBrouwer Nov 3, 2026
c77bb2a
Rollup merge of #164304 - Randl:perf-reuse, r=ShoyuVanilla
JonathanBrouwer Nov 3, 2026
a9a6e57
Rollup merge of #165109 - TaKO8Ki:avoid-erased-region-map, r=lcnr
JonathanBrouwer Nov 3, 2026
7a44046
Rollup merge of #163393 - brad0:std_src_sys_paths_unix, r=JohnTitor
JonathanBrouwer Nov 3, 2026
1efb937
Rollup merge of #164896 - sgasho:offload-cleanup-2, r=ZuseZ4
JonathanBrouwer Nov 3, 2026
a14f96d
Rollup merge of #165358 - antoyo:fix/reenable-cg_gcc-tests, r=Guillau…
JonathanBrouwer Nov 3, 2026
819c6ae
Rollup merge of #165371 - beetrees:global-llvm-type, r=folkertdev
JonathanBrouwer Nov 3, 2026
c2da812
Rollup merge of #162232 - fmease:yeet-builtin-hash, r=JohnTitor
JonathanBrouwer Nov 3, 2026
a541a8d
Rollup merge of #162608 - aytey:unpretty-hygiene-test-churn, r=fmease
JonathanBrouwer Nov 3, 2026
a0f4157
Rollup merge of #165029 - JonathanBrouwer:expected-lint, r=fmease
JonathanBrouwer Nov 3, 2026
8a216f1
Rollup merge of #165203 - xingxue-ibm:aix-disable-test-dynamic-loadin…
JonathanBrouwer Nov 3, 2026
1ec7d92
Rollup merge of #165230 - lsunsi:issue158773, r=adwinwhite
JonathanBrouwer Nov 3, 2026
a2a35e3
Rollup merge of #165374 - jdonszelmann:move-trait-splitouts, r=ShoyuV…
JonathanBrouwer Nov 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5177,7 +5177,7 @@ dependencies = [

[[package]]
name = "rustfmt-nightly"
version = "1.11.0"
version = "1.12.0"
dependencies = [
"annotate-snippets 0.12.16",
"anyhow",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ pub enum ExprKind {
Lit(token::Lit),
/// A cast (e.g., `foo as f64`).
Cast(Box<Expr>, Box<Ty>),
/// A type ascription (e.g., `builtin # type_ascribe(42, usize)`).
/// A type ascription (e.g., `k#type_ascribe(42, usize)`).
///
/// Usually not written directly in user code but
/// indirectly via the macro `type_ascribe!(...)`.
Expand Down Expand Up @@ -1871,7 +1871,7 @@ pub enum ExprKind {
/// Output of the `asm!()` macro.
InlineAsm(Box<InlineAsm>),

/// An `offset_of` expression (e.g., `builtin # offset_of(Struct, field)`).
/// An `offset_of` expression (e.g., `k#offset_of(Struct, field)`).
///
/// Usually not written directly in user code but
/// indirectly via the macro `core::mem::offset_of!(...)`.
Expand Down Expand Up @@ -2570,7 +2570,7 @@ pub enum TyKind {
/// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZero<u32>`,
/// just as part of the type system.
Pat(Box<Ty>, Box<TyPat>),
/// A `field_of` expression (e.g., `builtin # field_of(Struct, field)`).
/// A `field_of` expression (e.g., `k#field_of(Struct, field)`).
///
/// Usually not written directly in user code but indirectly via the macro
/// `core::field::field_of!(...)`.
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, kind: IdentKind) -> bool {
// WARNING: Take care when modifying this function! It will change the stable(!) set of
// tokens that are allowed to match an `expr` nonterminal which is user observable.

// NOTE: We don't care about forced keywords that are gated behind `internal_syntax`.

let ident_token = Token::new(Ident(name, kind), span);

// FIXME: Remove `box` from this list given we officially no longer support box expressions
Expand Down Expand Up @@ -350,6 +352,8 @@ fn ident_can_begin_type(name: Symbol, span: Span, kind: IdentKind) -> bool {
// WARNING: Take care when modifying this function! It will change the stable(!) set of
// tokens that are allowed to match an `ty` nonterminal which is user observable.

// NOTE: We don't care about forced keywords that are gated behind `internal_syntax`.

let ident_token = Token::new(Ident(name, kind), span);

!ident_token.is_reserved_ident()
Expand Down Expand Up @@ -936,6 +940,10 @@ impl Token {
self.non_raw_ident().is_some_and(|id| id.name == kw)
}

pub fn is_forced_keyword(&self, kw: Symbol) -> bool {
self.ident().is_some_and(|(id, kind)| kind == IdentKind::ForcedKeyword && id.name == kw)
}

/// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
/// token is an identifier equal to `kw` ignoring the case.
pub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {

// tidy-alphabetical-start
gate_all!(async_for_loop, "`for await` loops are experimental");
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
gate_all!(const_block_items, "const block items are experimental");
gate_all!(const_closures, "const closures are experimental");
gate_all!(const_trait_impl, "const trait impls are experimental");
Expand All @@ -452,6 +451,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(global_registration, "global registration is experimental");
gate_all!(guard_patterns, "guard patterns are experimental", "consider using match arm guards");
gate_all!(impl_restriction, "`impl` restrictions are experimental");
gate_all!(internal_syntax, "this syntax is internal");
gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental");
gate_all!(move_expr, "`move(expr)` syntax is experimental");
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ impl<'a> State<'a> {
self.print_ty_pat(pat);
}
ast::TyKind::FieldOf(ty, variant, field) => {
self.word("builtin # field_of");
self.word("k#field_of");
self.popen();
let ib = self.ibox(0);
self.print_type(ty);
Expand Down Expand Up @@ -2012,6 +2012,11 @@ impl<'a> State<'a> {
self.pclose();
}
PatKind::Deref(inner) => {
// FIXME(deref_patterns, internal_syntax, forced_keywords, clippy):
// This should render `k#deref(...)` but unfortunately Clippy uses `pat_to_string`
// for the suggestions of its lint `unnested_or_patterns`. Smh fix Clippy to not
// rely on AST pretty printing `deref!(…)` for `Deref` patterns and please don't
// think about adding a flag to AST pretty to control the output.
self.word("deref!");
self.popen();
self.print_pat(inner);
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl<'a> State<'a> {
self.print_type(ty);
}
ast::ExprKind::Type(expr, ty) => {
self.word("builtin # type_ascribe");
self.word("k#type_ascribe");
self.popen();
let ib = self.ibox(0);
self.print_expr(expr, FixupContext::default());
Expand Down Expand Up @@ -777,12 +777,12 @@ impl<'a> State<'a> {
self.print_expr(result, fixup.rightmost_subexpression());
}
ast::ExprKind::InlineAsm(a) => {
// FIXME: Print `builtin # asm` once macro `asm` uses `builtin_syntax`.
// FIXME: Print `k#asm` once macro `asm` uses `internal_syntax`.
self.word(format!("{}!", a.asm_macro.macro_name()));
self.print_inline_asm(a);
}
ast::ExprKind::FormatArgs(fmt) => {
// FIXME: Print `builtin # format_args` once macro `format_args` uses `builtin_syntax`.
// FIXME: Print `k#format_args` once macro `format_args` uses `internal_syntax`.
self.word("format_args!");
self.popen();
let ib = self.ibox(0);
Expand All @@ -795,7 +795,7 @@ impl<'a> State<'a> {
self.pclose();
}
ast::ExprKind::OffsetOf(container, fields) => {
self.word("builtin # offset_of");
self.word("k#offset_of");
self.popen();
let ib = self.ibox(0);
self.print_type(container);
Expand Down Expand Up @@ -855,10 +855,9 @@ impl<'a> State<'a> {
self.print_block_with_attrs(blk, attrs, cb, ib)
}
ast::ExprKind::UnsafeBinderCast(kind, expr, ty) => {
self.word("builtin # ");
match kind {
ast::UnsafeBinderCastKind::Wrap => self.word("wrap_binder"),
ast::UnsafeBinderCastKind::Unwrap => self.word("unwrap_binder"),
ast::UnsafeBinderCastKind::Wrap => self.word("k#wrap_binder"),
ast::UnsafeBinderCastKind::Unwrap => self.word("k#unwrap_binder"),
}
self.popen();
let ib = self.ibox(0);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'a> State<'a> {
self.bclose(item.span, empty, cb);
}
ast::ItemKind::GlobalAsm(asm) => {
// FIXME: Print `builtin # global_asm` once macro `global_asm` uses `builtin_syntax`.
// FIXME: Print `k#global_asm` once macro `global_asm` uses `internal_syntax`.
let (cb, ib) = self.head(visibility_qualified(&item.vis, "global_asm!"));
self.print_inline_asm(asm);
self.word(";");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_ir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ language_item_table! {
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
AlignOf, sym::mem_align_const, align_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);
SizeOf, sym::mem_size_const, size_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0);
OffsetOf, sym::offset_of, offset_of, Target::Fn, GenericRequirement::Exact(1);
OffsetOf, kw::OffsetOf, offset_of, Target::Fn, GenericRequirement::Exact(1);
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);
Expand Down Expand Up @@ -239,7 +239,7 @@ language_item_table! {
Complex, sym::complex, complex, Target::Struct, GenericRequirement::Exact(1);
PpcF128, sym::ppcf128, ppcf128, Target::Struct, GenericRequirement::None;

Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);
Deref, kw::Deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0);
DerefTarget, sym::deref_target, deref_target, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None;
Expand Down
23 changes: 14 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use thin_vec::ThinVec;

use crate::attributes::{AcceptMapping, AttributeParser, AttributeStability};
use crate::context::{AcceptContext, ExpectStringLiteral, FinalizeContext};
use crate::diagnostics::{MalformedLintAttributeInput, MalformedLintAttributeInputHelp};
use crate::parser::{ArgParser, MetaItemOrLitParser};
use crate::target_checking::AllowedTargets;
use crate::target_checking::Policy::{Allow, Warn};
Expand Down Expand Up @@ -36,9 +37,11 @@ impl LintParser {
let p = parsers.last()?.meta_item()?;
let nv = p.args().as_name_value()?;
if !p.path().word_is(sym::reason) {
cx.emit_err(diagnostics::MalformedAttribute {
// FIXME: We should recommend `reason` here
cx.emit_err(MalformedLintAttributeInput {
span: p.span(),
kind: diagnostics::MalformedAttributeKind::BadAttributeArgument(p.span()),
help: MalformedLintAttributeInputHelp::Other { kind: kind.sym() },
kind: kind.sym(),
});
} else {
parsers = &parsers[..(parsers.len() - 1)];
Expand Down Expand Up @@ -78,26 +81,28 @@ impl LintParser {
nv.expect_string_literal(cx);
}
ArgParser::NameValue(_) | ArgParser::List(_) => {
cx.emit_err(diagnostics::MalformedAttribute {
cx.emit_err(MalformedLintAttributeInput {
span: p.span(),
kind: diagnostics::MalformedAttributeKind::BadAttributeArgument(
item.span(),
),
help: MalformedLintAttributeInputHelp::Other {
kind: kind.sym(),
},
kind: kind.sym(),
});
}
}
}
MetaItemOrLitParser::Lit(lit) => {
cx.emit_err(diagnostics::BadAttributeLit {
cx.emit_err(MalformedLintAttributeInput {
span: item.span(),
help: if lit.kind.is_str() {
diagnostics::BadAttributeLitHelp::StrLit {
MalformedLintAttributeInputHelp::StrLit {
sym: lit.symbol,
kind: kind.sym(),
}
} else {
diagnostics::BadAttributeLitHelp::Other { kind: kind.sym() }
MalformedLintAttributeInputHelp::Other { kind: kind.sym() }
},
kind: kind.sym(),
});
}
}
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2196,24 +2196,23 @@ pub(crate) struct MalformedAttribute {

#[derive(Subdiagnostic)]
pub(crate) enum MalformedAttributeKind {
#[label("bad attribute argument")]
BadAttributeArgument(#[primary_span] Span),
#[label("reason in lint attribute must come last")]
ReasonMustComeLast(#[primary_span] Span),
}

#[derive(Diagnostic)]
#[diag("expected a lint, found literal")]
pub(crate) struct BadAttributeLit {
#[diag("malformed `{$kind}` attribute input")]
pub(crate) struct MalformedLintAttributeInput {
#[primary_span]
#[label("not the name of a lint")]
pub span: Span,
pub kind: Symbol,
#[subdiagnostic]
pub help: BadAttributeLitHelp,
pub help: MalformedLintAttributeInputHelp,
}

#[derive(Subdiagnostic)]
pub(crate) enum BadAttributeLitHelp {
pub(crate) enum MalformedLintAttributeInputHelp {
#[help("try using `#[{$kind}({$sym})]`")]
StrLit { sym: Symbol, kind: Symbol },
#[help("for example, write `#[{$kind}(dead_code)]` for `dead_code`")]
Expand Down
43 changes: 23 additions & 20 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,17 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
None
};

fn handle_offload<'ll>(cx: &SimpleCx<'ll>, old_fn: &'ll llvm::Value) {
// Wraps `old_fn` into a new kernel that takes the implicit `dyn_ptr` as its first argument.
// Returns the new function, or `None` if nothing was wrapped
fn handle_offload<'ll>(
cx: &SimpleCx<'ll>,
old_fn: &'ll llvm::Value,
) -> Option<&'ll llvm::Value> {
let old_fn_ty = cx.get_type_of_global(old_fn);
let old_param_types = cx.func_params_types(old_fn_ty);
let old_param_count = old_param_types.len();
if old_param_count == 0 {
return;
}

let first_param = llvm::get_param(old_fn, 0);
let c_name = llvm::get_value_name(first_param);
let first_arg_name = str::from_utf8(&c_name).unwrap();
// We might call llvm_optimize (and thus this code) multiple times on the same IR,
// but we shouldn't add this helper ptr multiple times.
// FIXME(offload): This could break if the user calls his first argument `dyn_ptr`.
if first_arg_name == "dyn_ptr" {
return;
return None;
}

// Create the new parameter list, with ptr as the first argument
Expand Down Expand Up @@ -747,6 +742,7 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
}
// Now we can re-use the old name, without name collision.
llvm::set_value_name(new_fn, &name);
Some(new_fn)
}

if cgcx.target_is_like_gpu
Expand All @@ -755,10 +751,13 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
let cx = SimpleCx::new(llmod, llcx, cgcx.pointer_size);
for func in cx.get_functions() {
let offload_kernel = "offload-kernel";
if attributes::has_string_attr(func, offload_kernel) {
handle_offload(&cx, func);
if !attributes::has_string_attr(func, offload_kernel) {
continue;
}
match handle_offload(&cx, func) {
Some(new_fn) => attributes::remove_string_attr_from_llfn(new_fn, offload_kernel),
None => attributes::remove_string_attr_from_llfn(func, offload_kernel),
}
attributes::remove_string_attr_from_llfn(func, offload_kernel);
}
}

Expand Down Expand Up @@ -822,8 +821,9 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
};

// This assumes that we previously compiled our kernels for a gpu target, which created a
// `<crate>.bc` artifact. The user is supposed to provide us with a path to this artifact, we
// don't need any other artifacts from the previous run.
// `<crate>.ptx` (NVPTX) or `<crate>.elf` (AMDGPU) artifact.
// The user is supposed to provide us with a path to this artifact,
// we don't need any other artifacts from the previous run.
if !cgcx.target_is_like_gpu && is_final_stage {
if let Some(device_path) = config
.offload
Expand All @@ -833,15 +833,18 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
let device_pathbuf = PathBuf::from(device_path);
if device_pathbuf.is_relative() {
dcx.emit_err(crate::diagnostics::OffloadWithoutAbsPath);
} else if device_pathbuf.extension().and_then(|e| e.to_str()) != Some("bc") {
} else if !matches!(
device_pathbuf.extension().and_then(|e| e.to_str()),
Some("ptx" | "elf")
) {
dcx.emit_err(crate::diagnostics::OffloadWrongFileName);
} else if !device_pathbuf.exists() {
dcx.emit_err(crate::diagnostics::OffloadNonexistingPath);
}
let device_bitcode_c = path_to_c_string(device_pathbuf.as_path());
let device_image_c = path_to_c_string(device_pathbuf.as_path());
let ok = unsafe {
llvm::RustOffloadWrapper::get_instance()
.llvm_rust_offload_wrap_images(llmod, device_bitcode_c.as_c_str())
.llvm_rust_offload_wrap_images(llmod, device_image_c.as_c_str())
};
if !ok {
dcx.emit_err(crate::diagnostics::OffloadWrapImagesFailed);
Expand Down
Loading
Loading