Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
e79fef4
Fix incorrect Self path expand for inline_call
A4-Tacks Jan 1, 2026
f091a8a
Fix complete semicolon in array expression
A4-Tacks Jan 4, 2026
d6362e6
document guidelines for which shims have a place in Miri
RalfJung Dec 17, 2025
0e6d603
migrate introduce_named_lifetime to SyntaxEditor
Shourya742 Jan 22, 2026
ed44659
Prepare for merging from rust-lang/rust
Jan 25, 2026
3d87f9c
Merge ref '5a07626f4b88' from rust-lang/rust
Jan 25, 2026
a109785
Merge pull request #4832 from rust-lang/rustup-2026-01-25
RalfJung Jan 25, 2026
be79f47
Merge pull request #4767 from RalfJung/shim-scope
RalfJung Jan 25, 2026
20c31e0
Prepare for merging from rust-lang/rust
Jan 26, 2026
58f38eb
Merge ref '873d4682c7d2' from rust-lang/rust
Jan 26, 2026
5f2d232
Merge pull request #4834 from rust-lang/rustup-2026-01-26
RalfJung Jan 26, 2026
db8f276
Prepare for merging from rust-lang/rust
Jan 28, 2026
db1d1ab
Merge ref 'e96bb7e44fbc' from rust-lang/rust
Jan 28, 2026
7129412
add a bug to the trophy shelf
joboet Jan 28, 2026
9fc9950
Merge pull request #4836 from joboet/vecdeque-trophy
RalfJung Jan 28, 2026
f67f5d9
bless android tests
RalfJung Jan 28, 2026
8513474
Merge pull request #4835 from rust-lang/rustup-2026-01-28
RalfJung Jan 28, 2026
ce7c03d
Prepare for merging from rust-lang/rust
Jan 30, 2026
f15548f
Merge ref '35a31ba76397' from rust-lang/rust
Jan 30, 2026
ca86fb5
Merge pull request #4837 from rust-lang/rustup-2026-01-30
oli-obk Jan 30, 2026
455172f
trophy case: oneshot data race
RalfJung Jan 31, 2026
c18e790
Merge pull request #4838 from RalfJung/oneshot-trophy
RalfJung Jan 31, 2026
1af1222
Prepare for merging from rust-lang/rust
RalfJung Feb 1, 2026
0f4176d
Merge ref '878374e07f3b' from rust-lang/rust
RalfJung Feb 1, 2026
070102b
fix building sysroot for JSON targets
RalfJung Feb 1, 2026
62d5181
Merge pull request #4839 from RalfJung/rustup
RalfJung Feb 1, 2026
c89a88e
do not run miri for the dependency build
RalfJung Feb 2, 2026
1044241
do not forward run flags to dependency build
RalfJung Feb 2, 2026
ab29d82
When autoimporting a segment followed by other segments, only conside…
ChayimFriedman2 Feb 3, 2026
3eabab2
chore: configure capstone for x86 and clean up arm64 stub
hsqStephenZhang Feb 2, 2026
d17eefa
Merge pull request #4842 from RalfJung/miri-run
RalfJung Feb 3, 2026
dcb608d
re-balance CI
RalfJung Feb 3, 2026
477f93e
Merge pull request #4843 from hsqStephenZhang/fix/capstone_features
RalfJung Feb 3, 2026
fd1b7c1
Merge pull request #4844 from RalfJung/ci
RalfJung Feb 3, 2026
2159eaf
Add a validity testcase for uninhabited variants
meithecatte Jan 4, 2026
510af14
Bump bytes from 1.10.1 to 1.11.1 in /tests/deps
dependabot[bot] Feb 3, 2026
35f6c75
Merge pull request #4845 from rust-lang/dependabot/cargo/tests/deps/b…
RalfJung Feb 3, 2026
9a84e66
fix: Fix loses associated bounds for replace_derive_with_manual_impl
A4-Tacks Feb 4, 2026
a3d848b
Prepare for merging from rust-lang/rust
Feb 4, 2026
99f8340
Merge ref '1d05e3c131d7' from rust-lang/rust
Feb 4, 2026
1f73d3f
Merge pull request #4846 from rust-lang/rustup-2026-02-04
RalfJung Feb 4, 2026
aace5bb
Merge pull request #4805 from meithecatte/uninhabited-enum-validity
RalfJung Feb 4, 2026
5009ac3
Bump git2 from 0.20.2 to 0.20.4
dependabot[bot] Feb 4, 2026
bd0d19f
Merge pull request #4848 from rust-lang/dependabot/cargo/git2-0.20.4
RalfJung Feb 4, 2026
4b68f80
feat: Improve hover too long parameter list
A4-Tacks Feb 5, 2026
94fa522
Prepare for merging from rust-lang/rust
RalfJung Feb 5, 2026
edc1ad4
Merge ref '9f4b56a5aed8' from rust-lang/rust
RalfJung Feb 5, 2026
40857fc
chore: fix typos suggested by typos-cli
hsqStephenZhang Feb 5, 2026
ba33e03
pass -Zunstable-options to tests
RalfJung Feb 5, 2026
4d946a9
Merge pull request #4849 from RalfJung/rustup
RalfJung Feb 5, 2026
2a6b9e6
inline the binding
tshepang Feb 3, 2026
193bc70
missing word
tshepang Feb 3, 2026
85f4694
Prepare for merging from rust-lang/rust
Feb 6, 2026
13ebd31
Merge ref 'f889772d6500' from rust-lang/rust
Feb 6, 2026
b1e0336
Merge pull request #4852 from rust-lang/rustup-2026-02-06
oli-obk Feb 6, 2026
5b68138
add trailing commas
tshepang Feb 3, 2026
6bb8cc6
obsolete comment
tshepang Feb 3, 2026
638d23c
E0570: improve text
tshepang Feb 5, 2026
84741ed
add reading pauses in doc comment
tshepang Feb 5, 2026
3be2843
make docs render better by separating intro from rest of paragraph
tshepang Feb 6, 2026
f605c0a
self_param and impl_ implementation in syntax_factory
Shourya742 Feb 8, 2026
fa31e17
migrate generate_getter_or_setter to syntaxeditor api
Shourya742 Feb 8, 2026
59111f7
Add `expression_types()`, `pattern_types()`, `binding_types()` to `De…
regexident Feb 4, 2026
ae24fda
fix: Fix `set_top_subtree_delimiter_span` using wrong index for close…
Veykril Feb 9, 2026
c4eaf24
Merge pull request #21608 from Veykril/push-kknkruwvyltp
Veykril Feb 9, 2026
23f6d74
Merge pull request #21606 from Shourya742/2026-02-09-migrate-getters-…
ShoyuVanilla Feb 9, 2026
7d521a2
Merge pull request #21574 from ChayimFriedman2/autoimport-after
ShoyuVanilla Feb 9, 2026
e7855f5
internal: Run clippy as a separate CI step
Wilfred Feb 3, 2026
6494dab
fix: Sync `allow_normalize` to rustc
ShoyuVanilla Feb 9, 2026
a3b7fa9
Merge pull request #21584 from regexident/def-with-body-types
ChayimFriedman2 Feb 9, 2026
5a721a1
Improve variable name
A4-Tacks Feb 9, 2026
68f2f3c
Merge pull request #21611 from ShoyuVanilla/issue-21605
ChayimFriedman2 Feb 9, 2026
c53e819
Merge pull request #21583 from A4-Tacks/derive-manual-assoc-bounds
ShoyuVanilla Feb 10, 2026
78c8ab3
migrate destructure tuple binding to new syntaxEditor
Shourya742 Feb 11, 2026
9c7cc62
make generate_unique_lifetime_param_name return Option<SmolStr>
Shourya742 Feb 10, 2026
751508a
Merge pull request #21507 from Shourya742/2026-01-17-migrate-named-li…
ShoyuVanilla Feb 11, 2026
49228dc
Merge pull request #21618 from Shourya742/2026-02-10-migrate-destruct…
ShoyuVanilla Feb 11, 2026
eb05ff6
Merge pull request #21581 from Wilfred/clippy_in_ci
Veykril Feb 11, 2026
fcb8812
align_strange_enum_discriminant_offset: fix accidentally unused variable
RalfJung Feb 11, 2026
ecc243b
remove an unused allow(unused)
RalfJung Feb 11, 2026
940ebda
Merge pull request #4854 from RalfJung/test-unused
RalfJung Feb 11, 2026
7077797
Parse and lower final for methods
mu001999 Jan 28, 2026
460cda8
Validate final usages in AST
mu001999 Jan 28, 2026
3572d48
Validate no override impl definitions
mu001999 Jan 28, 2026
f0e1c8f
Fix rustfmt
mu001999 Jan 28, 2026
f0a019b
Render final associated functions correctly in rustdoc
mu001999 Jan 28, 2026
2e0ff1f
Fix clippy ast utils
mu001999 Jan 28, 2026
8c77b6c
Exclude final methods from dyn-compat check and vtable
mu001999 Jan 29, 2026
11ce0a5
pin nightly for miri workflow
Shourya742 Feb 12, 2026
d32a473
Merge pull request #21628 from Shourya742/2026-02-12-pin-nightly-for-…
ChayimFriedman2 Feb 12, 2026
8b27b45
Revert "feat: Implement fine grained client side request cancellation…
ChayimFriedman2 Feb 12, 2026
87feb37
migrate covert_tuple_return_type to struct to syntax editor
Shourya742 Feb 11, 2026
9c468be
move to edit::AstNodeEdit from edit_in_place::Indent
Shourya742 Feb 12, 2026
c991d07
Merge pull request #21627 from rust-lang/revert-21380-push-nolvxuourwru
ChayimFriedman2 Feb 12, 2026
5bbd3e6
Merge pull request #21619 from Shourya742/2026-02-10-migrate-convert-…
ShoyuVanilla Feb 12, 2026
860469f
Merge pull request #21591 from A4-Tacks/hover-fmt-long-param
ChayimFriedman2 Feb 12, 2026
88d951e
Merge pull request #21402 from A4-Tacks/no-semicolon-array
ChayimFriedman2 Feb 12, 2026
15e661c
Merge pull request #21381 from A4-Tacks/inline-call-generic-args
ChayimFriedman2 Feb 12, 2026
61df37f
Don't assume `extern fn`s parameters are patterns
ChayimFriedman2 Feb 12, 2026
b214aac
Merge pull request #21632 from ChayimFriedman2/extern-fn-pat
ShoyuVanilla Feb 12, 2026
4fc780d
Do not resolve proc macros in value ns (as functions), only in macro …
ChayimFriedman2 Feb 12, 2026
b76642d
Cleanup unnecessary code
ChayimFriedman2 Feb 12, 2026
1911d67
Prepare for merging from rust-lang/rust
Feb 13, 2026
dce9791
Merge ref '47611e16044c' from rust-lang/rust
Feb 13, 2026
3a202c4
remove edit_in_place from replace_let_with_if_let assist with edit::A…
Shourya742 Feb 13, 2026
28bf2db
remove edit_in_place from move_const_to_impl assist with edit::AstNod…
Shourya742 Feb 13, 2026
6221b39
remove edit_in_place from bind_unused_param assist with edit::AstNode…
Shourya742 Feb 13, 2026
5de304e
remove edit_in_place from generate_mut_trait_impl assist with edit::A…
Shourya742 Feb 13, 2026
34eee0c
remove edit_in_place from generate_getter_or_setter assist with edit:…
Shourya742 Feb 13, 2026
96d6a3e
remove edit_in_place from convert_let_else_to_match assist with edit:…
Shourya742 Feb 13, 2026
8841267
Merge pull request #4856 from rust-lang/rustup-2026-02-13
RalfJung Feb 13, 2026
c8e284b
remove edit_in_place from replace_if_let_with_match assist with edit:…
Shourya742 Feb 13, 2026
140a039
remove edit_in_place from generate_trait_from_impl assist with edit::…
Shourya742 Feb 13, 2026
85e0c32
remove edit_in_place from convert_bool_to_enum assist with edit::AstN…
Shourya742 Feb 13, 2026
c6b1f8a
remove edit_in_place from generate_new assist with edit::AstNodeEdit
Shourya742 Feb 13, 2026
6040177
Merge pull request #21636 from Shourya742/2026-02-13-remove-edit-in-p…
ShoyuVanilla Feb 13, 2026
f931a79
Merge pull request #21633 from ChayimFriedman2/proc-macro-is-not-fn
ShoyuVanilla Feb 13, 2026
b132beb
internal: Use rayon for proc-macro loading
Veykril Feb 7, 2026
4b5b181
Merge pull request #21609 from Veykril/push-qknzslvkmtyt
Veykril Feb 13, 2026
c2c7d5d
build(deps): bump qs from 6.14.1 to 6.14.2 in /editors/code
dependabot[bot] Feb 13, 2026
da9ff14
Remove incorrect warning log
Veykril Feb 13, 2026
ca35562
Merge pull request #21640 from Veykril/push-rutrqvxousks
Veykril Feb 13, 2026
7ce9839
migrate generate_impl to use AstNodeEdit
Shourya742 Feb 13, 2026
a9cc42e
Revert "fix: Stale diagnostics with rust-project.json and rustc JSON"
Veykril Feb 13, 2026
81b7275
Merge pull request #21644 from Veykril/push-zrzoswxlqlqq
Veykril Feb 13, 2026
deaae49
Merge pull request #21639 from rust-lang/dependabot/npm_and_yarn/edit…
Veykril Feb 14, 2026
4247967
simplify wildcard datastructure
royAmmerschuber Feb 5, 2026
c78baeb
Merge pull request #4851 from royAmmerschuber/feature/simplyfy-exposing
RalfJung Feb 14, 2026
9216678
feat: vtbl1_u8 intrinsic on aarch64
hsqStephenZhang Feb 4, 2026
5932915
minor tweaks
RalfJung Feb 14, 2026
3d2786f
Merge pull request #4847 from hsqStephenZhang/feat/aarch64_intrinsics
RalfJung Feb 14, 2026
0b1003c
Merge pull request #4850 from hsqStephenZhang/chore/typos
saethlin Feb 14, 2026
d15d714
fix smol_str compilation error
alexanderkjall Feb 14, 2026
6464188
fix: handle `ref mut` bindings in `contains_explicit_ref_binding`
Albab-Hasan Feb 14, 2026
1c21e60
made -> marked
saethlin Feb 14, 2026
e542472
Merge pull request #4858 from saethlin/typos-redux
saethlin Feb 15, 2026
d888b1c
Prepare for merging from rust-lang/rust
Feb 15, 2026
0f86403
Merge ref '7bee525095c0' from rust-lang/rust
Feb 15, 2026
8d3b9f4
gate borsh tests on std also, as they depend on both
alexanderkjall Feb 15, 2026
721edae
Merge pull request #21647 from Albab-Hasan/fix/contains-explicit-ref-…
ChayimFriedman2 Feb 15, 2026
7733f65
fix: use `ExprIsRead::Yes` for rhs of ordinary assignments
Albab-Hasan Feb 15, 2026
b55673b
Avoid ICE in From/TryFrom diagnostic under -Znext-solver
THARUN-BART Feb 15, 2026
40a3ca1
fix: remove unused source span
Embers-of-the-Fire Feb 15, 2026
5ad533b
Merge pull request #21649 from Albab-Hasan/fix/assignment-rhs-never-c…
ChayimFriedman2 Feb 15, 2026
a8bbacd
fix: remove unused import
Embers-of-the-Fire Feb 15, 2026
d13828b
fix: re-format the changes
Embers-of-the-Fire Feb 15, 2026
23a3e64
Merge pull request #21648 from alexanderkjall/borsh-error-compilation…
ChayimFriedman2 Feb 15, 2026
7027931
fmt
Feb 15, 2026
1f39d1f
Merge pull request #4859 from rust-lang/rustup-2026-02-15
RalfJung Feb 15, 2026
2ef5156
Prepare for merging from rust-lang/rust
invalid-email-address Feb 16, 2026
1fb6fc1
Merge ref '139651428df8' from rust-lang/rust
invalid-email-address Feb 16, 2026
0f5c221
Regression test for "unstable" traits in force-unstable builds
Zalathar Feb 16, 2026
125e69e
Suppress unstable-trait notes under `-Zforce-unstable-if-unmarked`
Zalathar Feb 16, 2026
72c7d86
Remove `rustc_query_system` README file.
nnethercote Feb 13, 2026
71c9411
Merge pull request #21653 from rust-lang/rustc-pull
lnicola Feb 16, 2026
8d56cfe
Move `QuerySideEffect`.
nnethercote Feb 13, 2026
6a3a3d4
try to make cargo-miri work with bootstrap cargo
RalfJung Feb 16, 2026
e52ed9c
Merge pull request #21643 from Shourya742/2026-02-13-migrate-generate…
lnicola Feb 16, 2026
74dd36a
Remove `DEP_KIND_DEBUG`.
nnethercote Feb 16, 2026
47ed452
Remove `DEP_NODE_DEBUG`.
nnethercote Feb 16, 2026
e9288e7
Remove last remnants of `rustc_query_system`.
nnethercote Feb 13, 2026
7e14260
`probe_op` silence ambiguity errors if tainted
lcnr Feb 16, 2026
8081e86
Port #![default_lib_allocator] to the new attribute parser
Ozzy1423 Feb 16, 2026
67799c9
core: Implement feature `float_exact_integer_constants`
okaneco Feb 12, 2026
7be024f
[cg_clif]: Fix codegen of f128 to i128 casts
okaneco Feb 12, 2026
476a630
Rollup merge of #152700 - RalfJung:miri, r=RalfJung
Zalathar Feb 17, 2026
118df88
Rollup merge of #152715 - lnicola:sync-from-ra, r=lnicola
Zalathar Feb 17, 2026
1367126
Rollup merge of #151783 - mu001999-contrib:impl/final-method, r=fee1-…
Zalathar Feb 17, 2026
331a785
Rollup merge of #152512 - okaneco:exact_integer, r=tgross35
Zalathar Feb 17, 2026
572b53f
Rollup merge of #152661 - BartSimpson001:fix-next-solver-from-ice, r=…
Zalathar Feb 17, 2026
e28a33a
Rollup merge of #152703 - nnethercote:rm-rustc_query_system, r=Zalathar
Zalathar Feb 17, 2026
910d4f4
Rollup merge of #152206 - tshepang:misc, r=davidtwco
Zalathar Feb 17, 2026
7ab22cd
Rollup merge of #152664 - Embers-of-the-Fire:fix-152601, r=GuillaumeG…
Zalathar Feb 17, 2026
dc77672
Rollup merge of #152698 - Zalathar:zforce, r=jieyouxu
Zalathar Feb 17, 2026
dd27f85
Rollup merge of #152727 - lcnr:method-ambig-err-taint, r=jackh726
Zalathar Feb 17, 2026
f769905
Rollup merge of #152728 - Ozzy1423:default-lib, r=JonathanBrouwer
Zalathar Feb 17, 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
19 changes: 0 additions & 19 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,6 @@ dependencies = [
"rustc_macros",
"rustc_metadata",
"rustc_middle",
"rustc_query_system",
"rustc_sanitizers",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4243,7 +4242,6 @@ dependencies = [
"rustc_index",
"rustc_lint_defs",
"rustc_macros",
"rustc_query_system",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4507,23 +4505,6 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_query_system"
version = "0.0.0"
dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_hir",
"rustc_macros",
"rustc_serialize",
"rustc_session",
"rustc_span",
"smallvec",
]

[[package]]
name = "rustc_resolve"
version = "0.0.0"
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3131,8 +3131,16 @@ pub enum Const {
/// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532).
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
pub enum Defaultness {
/// Item is unmarked. Implicitly determined based off of position.
/// For impls, this is `final`; for traits, this is `default`.
///
/// If you're expanding an item in a built-in macro or parsing an item
/// by hand, you probably want to use this.
Implicit,
/// `default`
Default(Span),
Final,
/// `final`; per RFC 3678, only trait items may be *explicitly* marked final.
Final(Span),
}

#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)]
Expand Down Expand Up @@ -4140,7 +4148,7 @@ impl AssocItemKind {
| Self::Fn(box Fn { defaultness, .. })
| Self::Type(box TyAlias { defaultness, .. }) => defaultness,
Self::MacCall(..) | Self::Delegation(..) | Self::DelegationMac(..) => {
Defaultness::Final
Defaultness::Implicit
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
let trait_item_def_id = hir_id.expect_owner();

let (ident, generics, kind, has_default) = match &i.kind {
let (ident, generics, kind, has_value) = match &i.kind {
AssocItemKind::Const(box ConstItem {
ident,
generics,
Expand Down Expand Up @@ -1088,13 +1088,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
};

let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value, || {
hir::Defaultness::Default { has_value }
});

let item = hir::TraitItem {
owner_id: trait_item_def_id,
ident: self.lower_ident(ident),
generics,
kind,
span: self.lower_span(i.span),
defaultness: hir::Defaultness::Default { has_value: has_default },
defaultness,
has_delayed_lints: !self.delayed_lints.is_empty(),
};
self.arena.alloc(item)
Expand Down Expand Up @@ -1122,7 +1126,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
// to not cause an assertion failure inside the `lower_defaultness` function.
let has_val = true;
let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
let (defaultness, defaultness_span) =
self.lower_defaultness(defaultness, has_val, || hir::Defaultness::Final);
let modifiers = TraitBoundModifiers {
constness: BoundConstness::Never,
asyncness: BoundAsyncness::Normal,
Expand Down Expand Up @@ -1151,7 +1156,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> &'hir hir::ImplItem<'hir> {
// Since `default impl` is not yet implemented, this is always true in impls.
let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
let (defaultness, _) =
self.lower_defaultness(i.kind.defaultness(), has_value, || hir::Defaultness::Final);
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
let attrs = self.lower_attrs(
hir_id,
Expand Down Expand Up @@ -1304,15 +1310,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
&self,
d: Defaultness,
has_value: bool,
implicit: impl FnOnce() -> hir::Defaultness,
) -> (hir::Defaultness, Option<Span>) {
match d {
Defaultness::Implicit => (implicit(), None),
Defaultness::Default(sp) => {
(hir::Defaultness::Default { has_value }, Some(self.lower_span(sp)))
}
Defaultness::Final => {
assert!(has_value);
(hir::Defaultness::Final, None)
}
Defaultness::Final(sp) => (hir::Defaultness::Final, Some(self.lower_span(sp))),
}
}

Expand Down
78 changes: 66 additions & 12 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ impl TraitOrImpl {
}
}

enum AllowDefault {
Yes,
No,
}

impl AllowDefault {
fn when(b: bool) -> Self {
if b { Self::Yes } else { Self::No }
}
}

enum AllowFinal {
Yes,
No,
}

impl AllowFinal {
fn when(b: bool) -> Self {
if b { Self::Yes } else { Self::No }
}
}

struct AstValidator<'a> {
sess: &'a Session,
features: &'a Features,
Expand Down Expand Up @@ -563,10 +585,32 @@ impl<'a> AstValidator<'a> {
}
}

fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
if let Defaultness::Default(def_span) = defaultness {
let span = self.sess.source_map().guess_head_span(span);
self.dcx().emit_err(errors::ForbiddenDefault { span, def_span });
fn check_defaultness(
&self,
span: Span,
defaultness: Defaultness,
allow_default: AllowDefault,
allow_final: AllowFinal,
) {
match defaultness {
Defaultness::Default(def_span) if matches!(allow_default, AllowDefault::No) => {
let span = self.sess.source_map().guess_head_span(span);
self.dcx().emit_err(errors::ForbiddenDefault { span, def_span });
}
Defaultness::Final(def_span) if matches!(allow_final, AllowFinal::No) => {
let span = self.sess.source_map().guess_head_span(span);
self.dcx().emit_err(errors::ForbiddenFinal { span, def_span });
}
_ => (),
}
}

fn check_final_has_body(&self, item: &Item<AssocItemKind>, defaultness: Defaultness) {
if let AssocItemKind::Fn(box Fn { body: None, .. }) = &item.kind
&& let Defaultness::Final(def_span) = defaultness
{
let span = self.sess.source_map().guess_head_span(item.span);
self.dcx().emit_err(errors::ForbiddenFinalWithoutBody { span, def_span });
}
}

Expand Down Expand Up @@ -1190,7 +1234,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
},
) => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.check_defaultness(item.span, *defaultness);
self.check_defaultness(item.span, *defaultness, AllowDefault::No, AllowFinal::No);

for EiiImpl { eii_macro_path, .. } in eii_impls {
self.visit_path(eii_macro_path);
Expand Down Expand Up @@ -1360,7 +1404,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
});
}
ItemKind::Const(box ConstItem { defaultness, ident, rhs_kind, .. }) => {
self.check_defaultness(item.span, *defaultness);
self.check_defaultness(item.span, *defaultness, AllowDefault::No, AllowFinal::No);
if !rhs_kind.has_expr() {
self.dcx().emit_err(errors::ConstWithoutBody {
span: item.span,
Expand Down Expand Up @@ -1398,7 +1442,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ItemKind::TyAlias(
ty_alias @ box TyAlias { defaultness, bounds, after_where_clause, ty, .. },
) => {
self.check_defaultness(item.span, *defaultness);
self.check_defaultness(item.span, *defaultness, AllowDefault::No, AllowFinal::No);
if ty.is_none() {
self.dcx().emit_err(errors::TyAliasWithoutBody {
span: item.span,
Expand Down Expand Up @@ -1428,7 +1472,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
match &fi.kind {
ForeignItemKind::Fn(box Fn { defaultness, ident, sig, body, .. }) => {
self.check_defaultness(fi.span, *defaultness);
self.check_defaultness(fi.span, *defaultness, AllowDefault::No, AllowFinal::No);
self.check_foreign_fn_bodyless(*ident, body.as_deref());
self.check_foreign_fn_headerless(sig.header);
self.check_foreign_item_ascii_only(*ident);
Expand All @@ -1448,7 +1492,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ty,
..
}) => {
self.check_defaultness(fi.span, *defaultness);
self.check_defaultness(fi.span, *defaultness, AllowDefault::No, AllowFinal::No);
self.check_foreign_kind_bodyless(*ident, "type", ty.as_ref().map(|b| b.span));
self.check_type_no_bounds(bounds, "`extern` blocks");
self.check_foreign_ty_genericless(generics, after_where_clause);
Expand Down Expand Up @@ -1707,9 +1751,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.check_nomangle_item_asciionly(ident, item.span);
}

if ctxt == AssocCtxt::Trait || self.outer_trait_or_trait_impl.is_none() {
self.check_defaultness(item.span, item.kind.defaultness());
}
let defaultness = item.kind.defaultness();
self.check_defaultness(
item.span,
defaultness,
// `default` is allowed on all associated items in impls.
AllowDefault::when(matches!(ctxt, AssocCtxt::Impl { .. })),
// `final` is allowed on all associated *functions* in traits.
AllowFinal::when(
ctxt == AssocCtxt::Trait && matches!(item.kind, AssocItemKind::Fn(..)),
),
);

self.check_final_has_body(item, defaultness);

if let AssocCtxt::Impl { .. } = ctxt {
match &item.kind {
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ pub(crate) struct ForbiddenDefault {
pub def_span: Span,
}

#[derive(Diagnostic)]
#[diag("`final` is only allowed on associated functions in traits")]
pub(crate) struct ForbiddenFinal {
#[primary_span]
pub span: Span,
#[label("`final` because of this")]
pub def_span: Span,
}

#[derive(Diagnostic)]
#[diag("`final` is only allowed on associated functions if they have a body")]
pub(crate) struct ForbiddenFinalWithoutBody {
#[primary_span]
pub span: Span,
#[label("`final` because of this")]
pub def_span: Span,
}

#[derive(Diagnostic)]
#[diag("associated constant in `impl` without body")]
pub(crate) struct AssocConstWithoutBody {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(frontmatter, "frontmatters are experimental");
gate_all!(coroutines, "coroutine syntax is experimental");
gate_all!(const_block_items, "const block items are experimental");
gate_all!(final_associated_functions, "`final` on trait functions is experimental");

if !visitor.features.never_patterns() {
if let Some(spans) = spans.get(&sym::never_patterns) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> State<'a> {
expr.as_deref(),
vis,
*safety,
ast::Defaultness::Final,
ast::Defaultness::Implicit,
define_opaque.as_deref(),
),
ast::ForeignItemKind::TyAlias(box ast::TyAlias {
Expand Down Expand Up @@ -201,7 +201,7 @@ impl<'a> State<'a> {
body.as_deref(),
&item.vis,
ast::Safety::Default,
ast::Defaultness::Final,
ast::Defaultness::Implicit,
define_opaque.as_deref(),
);
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNoImplicitBoundsParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitBounds;
}

pub(crate) struct DefaultLibAllocatorParser;

impl<S: Stage> NoArgsAttributeParser<S> for DefaultLibAllocatorParser {
const PATH: &[Symbol] = &[sym::default_lib_allocator];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::DefaultLibAllocator;
}
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ attribute_parsers!(
Single<WithoutArgs<ConstContinueParser>>,
Single<WithoutArgs<ConstStabilityIndirectParser>>,
Single<WithoutArgs<CoroutineParser>>,
Single<WithoutArgs<DefaultLibAllocatorParser>>,
Single<WithoutArgs<DenyExplicitImplParser>>,
Single<WithoutArgs<DynIncompatibleTraitParser>>,
Single<WithoutArgs<EiiForeignItemParser>>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span

let body = Some(cx.block_expr(call));
let kind = ItemKind::Fn(Box::new(Fn {
defaultness: ast::Defaultness::Final,
defaultness: ast::Defaultness::Implicit,
sig,
ident: Ident::from_str_and_span(&global_fn_name(ALLOC_ERROR_HANDLER), span),
generics: Generics::default(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ mod llvm_enzyme {

// The first element of it is the name of the function to be generated
let d_fn = Box::new(ast::Fn {
defaultness: ast::Defaultness::Final,
defaultness: ast::Defaultness::Implicit,
sig: d_sig,
ident: first_ident(&meta_item_vec[0]),
generics,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
of_trait: Some(Box::new(ast::TraitImplHeader {
safety: ast::Safety::Default,
polarity: ast::ImplPolarity::Positive,
defaultness: ast::Defaultness::Final,
defaultness: ast::Defaultness::Implicit,
trait_ref,
})),
constness: ast::Const::No,
Expand All @@ -159,7 +159,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
of_trait: Some(Box::new(ast::TraitImplHeader {
safety: ast::Safety::Default,
polarity: ast::ImplPolarity::Positive,
defaultness: ast::Defaultness::Final,
defaultness: ast::Defaultness::Implicit,
trait_ref,
})),
constness: ast::Const::No,
Expand Down
Loading
Loading