Commit Graph

1540 Commits

Author SHA1 Message Date
Jonathan Brouwer
03c3d00ee3 Make inputs to ParenthesizedArgs a ThinVec<Param> in the compiler 2026-08-11 20:47:40 +02:00
Jonathan Brouwer
34df6a0ab8 Rollup merge of #160216 - khyperia:gca-path-cleanup, r=BoxyUwU,bit-aloo
clean up handling of paths in mgca

related tracking issue: https://github.com/rust-lang/rust/issues/132980

Handling of ambiguous type-or-constant argument paths was really wonky and distinct from the regular `can_lower_expr_to_const_arg_direct` lowering paths. Clean that up and unify it, as discussed here https://github.com/rust-lang/rust/pull/158479#discussion_r3544664708

Also, do a bunch of other little cleanups at the same time while I'm here:

- add support for parens to the inside of direct_const_arg! and macroless_generic_const_args (idk why this wasn't a thing before)
- add constant and lifetime ribs when resolving TyKind::DirectConstArg - note the TyKind, not ExprKind (~~I am unsure if/how this changes behavior~~ added a test, `direct-const-arg-correct-rib.rs`) - this was discussed here https://github.com/rust-lang/rust/pull/158617#issuecomment-4932249112
- minor debug logging change
- various minor code shuffles/cleanups
- add test for `direct_const_arg!(_)` inferring to a type - this test should have been added in https://github.com/rust-lang/rust/pull/159058 which added this behavior (well, changed the behavior from an ICE to inferring to a type)
- add a test asserting the current behavior of parens/braces/underscores on stable - one or two of these cases already have tests elsewhere, but it's nice to assert the whole set, and also assert the whole set in the same place so it's easily visible to be able to give me confidence the whole set actually is tested (both positives and negatives are important here)
- add a test similar to the previous one, but with mgca enabled, asserting all combinations now compile successfully

r? @BoxyUwU
2026-08-10 13:45:40 +02:00
Chris Denton
4641990929 Remove ensure_sufficient_stack 2026-08-09 19:58:29 +00:00
Jonathan Brouwer
7636221f4d Rollup merge of #160453 - Kobzol:include-blob-opt, r=the8472
Add fast path to `escape_string_symbol`

Discussed in https://github.com/rust-lang/rust/pull/159916. So far used the manual escaping variant.

CC @matthieu-m

r? the8472
2026-08-04 14:41:29 +02:00
Jakub Beránek
96057625c5 Add fast path to escape_string_symbol
Co-Authored-By: Matthieu M <matthieum.147192@gmail.com>
2026-08-03 19:12:41 +02:00
bjorn3
1a3d919258 Deny multiple EII impls on a single item
This allows implementing EIIs that don't have a default impl without the
involvement of symbol aliases by simply changing the mangled symbol name
of the implementation, which would make them trivially compatible with
all backends and targets. This change will be left to a followup PR.
2026-08-03 11:04:23 +02:00
khyperia
2f54b38220 clean up handling of paths in mgca 2026-08-01 12:37:11 +02:00
Jacob Pratt
10184a4249 Rollup merge of #159907 - mejrs:fix_globby, r=TaKO8Ki
Fix `hidden_glob_reexports` in `rustc_ast`

See https://github.com/rust-lang/rust/issues/159901 for why the downstream changes are necessary
2026-07-31 22:25:17 -04:00
mejrs
ed76f84cc8 remove hidden_glob_reexports 2026-07-31 14:14:45 +02:00
albab-hasan
7f51ec6773 don't fire unused_mut on &pin mut self
`SelfKind::Pinned` in `Param::from_self` was setting the binding mutability
to `mutbl`, so `&pin mut self` produced a mutable binding and triggered
`unused_mut` spuriously. the `mut` qualifies the pin reference, not the
binding -- same as `SelfKind::Region` which uses `Mutability::Not`.

fixes https://github.com/rust-lang/rust/issues/142077
2026-07-31 10:47:16 +06:00
teor
cb797b89ce Rename splat attribute to rustc_splat 2026-07-30 10:58:18 +10:00
Jonathan Brouwer
db1e471176 Rollup merge of #159936 - mejrs:ast_docs, r=chenyukang
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in https://github.com/rust-lang/rust/pull/159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
2026-07-26 15:47:29 +02:00
Jacob Pratt
ff96314929 Rollup merge of #159780 - folkertdev:extern-custom-check-fn-ptrs, r=WaffleLapkin
check `extern "custom"` function pointers

tracking issue: https://github.com/rust-lang/rust/issues/140829
related RFC: https://github.com/rust-lang/rfcs/pull/3980

Best reviewed commit-by-commit.

This PR makes 3 changes

- extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`.
- remove the ability for `extern "custom"` to return `!`
- improve the suggestion when `safe` is used in a function pointer type
2026-07-26 00:21:47 -04:00
Jacob Pratt
3fc9b07570 Rollup merge of #158709 - notriddle:html-lint-interleaving, r=camelid,GuillaumeGomez
rustdoc: warn on improperly interleaved HTML/MD

Enhances the `rustdoc::invalid_html_tags` lint to warn in cases where pulldown-cmark will produce invalid HTML because the Markdown and HTML are improperly nested.

As an extreme example, this code does not do what it looks like it does, and it doesn't produce a warning under current nightly, either:

```markdown
Figure 1: an X
<svg viewBox="0 0 10 10">
<path
    d="M0 10L10 0M10 10L0 0"
    stroke="black"
>
</svg>
```

This pull request makes it warn:

```text
error: unopened HTML tag `svg`
  --> $DIR/invalid-html-tags.rs:285:5
   |
LL | /// <svg viewBox="0 0 10 10">
   |     ---- does not match this unclosed tag
...
LL | /// >
   |     - because the Markdown paragraph is interrupted by this block quote
LL | /// </svg>
   |     ^^^^^^ this unopened tag
```

See also: https://talk.commonmark.org/t/thoughts-on-changing-supported-html-syntax-to-include-the-dangling-closing-angle-bracket/3827
2026-07-26 00:21:40 -04:00
mejrs
b81e756441 Minor doc comment formatting 2026-07-26 01:36:15 +02:00
mejrs
e24189e460 Update SyntheticAttr docs 2026-07-26 00:54:44 +02:00
mejrs
7697f3d6bb Fix obsolete P reference 2026-07-26 00:37:24 +02:00
Folkert de Vries
152ac5846a run ABI checks on function pointer types
and update the tests as needed.
2026-07-24 20:53:37 +02:00
Folkert de Vries
f7a98cbff1 add FnPtrTy::header 2026-07-24 20:49:45 +02:00
Folkert de Vries
180f48d2cb add BorrowedFnSig to prevent a clone down the road 2026-07-24 20:49:43 +02:00
Folkert de Vries
2dc6470711 add FnHeader::span 2026-07-24 20:47:21 +02:00
Michael Howell
ef33862446 rustdoc: helper method for generating doc comments 2026-07-23 23:12:05 -07:00
Jacob Pratt
7a2710b9d4 Rollup merge of #159722 - GuillaumeGomez:cfg_attr-doc_cfg, r=petrochenkov,mejrs,Urgau
[rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes https://github.com/rust-lang/rust/issues/103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc https://github.com/rust-lang/rust/issues/43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
2026-07-24 01:59:21 -04:00
panstromek
283ec3aa54 Make FieldDef smaller 2026-07-23 14:43:52 +02:00
Guillaume Gomez
0eb2348e8b Keep cfg predicate in CfgAttrTrace so it can be used by rustdoc 2026-07-22 23:50:54 +02:00
Jonathan Brouwer
2118316ebc Rollup merge of #159596 - khyperia:type-const-rhs-expr, r=BoxyUwU
unify the AST repr of type const and const RHS

related to min_generic_const_args, tracking issue here: https://github.com/rust-lang/rust/issues/132980

Previously, we were parsing/lowering the RHS of type consts differently than regular consts. We no longer need to do so, yippee! This deletes the anon const from the RHS of type consts. This removes the fake defid for the rhs of type consts, FYI.

r? @BoxyUwU
2026-07-22 18:02:19 +02:00
khyperia
e895ed8c90 unify the AST repr of type const and const RHS 2026-07-22 09:22:45 +02:00
bors
b803f36e07 Auto merge of #159609 - nikic:opt-escape, r=folkertdev
Optimize escape_string_symbol()

Going through escape_default() + to_string(), which involves going through formatting machinery and a flat_map of a complex iterator, ends up being quite slow. Directly pushing to a string, even with a naive implementation, is significantly faster.

This shows up in the include-blob benchmark, which mostly exercises this one function.
2026-07-22 06:22:21 +00:00
Jonathan Brouwer
ef3632338e Rollup merge of #159636 - nnethercote:some-comments, r=petrochenkov
Improve some comments (and an error message)

Details in individual commits.

r? @petrochenkov
2026-07-21 12:24:58 +02:00
Jonathan Brouwer
82d262fcc4 Rollup merge of #159590 - oli-obk:unsafe_attrs_old, r=petrochenkov
Remove some dead code

Leftover from a previous revision of `#[unsafe(no_mangle)]`. All call sites disallowed it anyway, and the real handling is in the parser.
2026-07-21 12:24:57 +02:00
Oli Scherer
4e2ebd6235 Remove some dead code 2026-07-21 11:34:36 +02:00
Nicholas Nethercote
8fa2ebfea5 Add a doc comment to Attribute::span
There's a lot going on and it's not obvious.
2026-07-21 16:16:05 +10:00
Jacob Pratt
d2f94b7374 Rollup merge of #159601 - nnethercote:privatize-TokenTreeCursor, r=Kobzol
Make `TokenTreeCursor` private

And also the fields of `TokenCursor`.

It's good hygiene in general, and will allow larger changes to `TokenCursor` down the road (e.g. hopefully avoiding the flattening of token trees to a linear token stream).

r? @Kobzol
2026-07-20 23:38:07 -04:00
Nicholas Nethercote
73de522410 Make TokenStream's internals private 2026-07-21 06:55:14 +10:00
Nicholas Nethercote
3f2624ea64 Make TokenTreeCursor private
And also the fields of `TokenCursor`.

It's good hygiene in general, and will allow larger changes to
`TokenCursor` down the road (e.g. hopefully avoiding the flattening of
token trees to a linear token stream).
2026-07-21 06:55:08 +10:00
Jonathan Brouwer
c905c76604 Rollup merge of #159603 - nnethercote:clarify-push_stream, r=Kobzol
Clarify `push_stream`/`push_tree`

More `TokenStream` cleanups. Details in individual commits.

r? @Kobzol
2026-07-20 18:06:17 +02:00
Jonathan Brouwer
3a0eece000 Rollup merge of #159585 - nnethercote:minor-TokenStream-improvements, r=Kobzol
Minor `TokenStream` improvements

I found these while attempting to improve the `TokenStream` representation in rust-lang/rust#159048.

r? @Kobzol
2026-07-20 18:06:13 +02:00
Nikita Popov
bfe8ccb68d Optimize escape_string_symbol() 2026-07-20 17:10:14 +02:00
Nicholas Nethercote
693756d643 Rename push_tree/push_stream
To clarify that they are for specific uses, and not intended as general
`TokenStream` builders.
2026-07-20 21:42:26 +10:00
Nicholas Nethercote
ea7bee7515 Change AttrItem::span from a method to a field
Currently the method computes the span from the path's span and the
args' span. That used to be fine but then `unsafe(..)`/`safe(..)` were
added without it being changed. So it doesn't account for those optional
keywords and parentheses. The only way to handle those reliably is with
a dedicated span for the entire `AttrItem`.

Consequences:
- `NormalAttr` grows from 72 bytes to 80. (It's the only AST node that
  contains an `AttrItem`.) Not ideal, but non-doc-comment attributes
  aren't that common (not compared to expressions, for example). Also,
  `NormalAttr` is always boxed and jemalloc will round up 72 byte
  allocations to 80 bytes anyway.
- In `lint-unsafe-code.rs` various spans now point to `unsafe(foo)`
  rather than just `foo`. (It makes sense to include the `unsafe` keyword
  in the complaint about unsafety.)
2026-07-20 15:10:16 +10:00
Nicholas Nethercote
88e8a9bcb6 Improve StableHash impl for TokenStream
It currently doesn't include the length. It should. This change makes it
more like other `StableHash` impls for vec-like types.
2026-07-20 14:05:15 +10:00
Nicholas Nethercote
3052ff8e4d Adjust signature of TokenStream::try_glue_to_last
A slice is more general.

Also remove the tail end of a comment that is inaccurate (this function
doesn't have a variable named `stream`, but one of its callers does).
2026-07-20 14:04:45 +10:00
Nicholas Nethercote
a6058f45c6 Remove unused TokenStream::chunks 2026-07-20 13:56:02 +10:00
Nicholas Nethercote
fa56a01dad Address review comments. 2026-07-17 08:59:25 +10:00
Nicholas Nethercote
17d526f1be Replace "early parsed" terminology
AST attributes use "early parsed"/"parsed" terminology to refer to the
`CfgTrace` and `CfgAttrTrace` attributes. I think this terminology is
meant to echo the terminology used for HIR attributes, i.e.
`hir::Attribute::{Parsed,Unparsed}`, probably because
`hir::Attribute::Parsed` is used for attributes that aren't stored in a
token-based form.

But this naming is misleading. "Early parsed" attributes aren't parsed
at all because they are inserted by the compiler and cannot be written
in source code. There are also two comments that claim that these
attributes are kept in parsed form "so they don't have to be reparsed
every time they're used, for performance", which is simply incorrect.

This commit renames these as "synthetic" attributes, which better
reflects their nature. The commit also fixes the incorrect comments.

Note that `is_parsed_attribute` is unchanged, because it refers to the
HIR attribute meaning. (And the removal of the synthetic attributes from
it in the previous commit is now more obviously correct.)
2026-07-17 08:59:25 +10:00
Nicholas Nethercote
1a8ecb0b5b Remove sym::cfg_trace and sym::cfg_attr_trace
This commit pushes further than the previous one, relying more heavily
on looking directly at `AttrKind::Parsed` to handle various cases.

Note that the removed clippy code was actually dead.
2026-07-17 08:59:25 +10:00
Nicholas Nethercote
b357c7c0ff Remove AttrItemKind
`AttrItem` currently contains an `AttrItemKind` which is either `Parsed`
or `Unparsed`. In the `Parsed` case the surrounding `AttrItem` is
basically fake, with a meaningless `unsafety` field, a synthetic
(non-ident) symbol, and an empty `tokens`.

This commit moves `Parsed` up one level to become a new variant of
`AttrKind`. It no longer needs to pretend to be an `AttrKind::Normal`,
and makes a number of things simpler:
- No `unparsed_ref` calls needed.
- Replaces the `attr_into_trace` and `Attribute::replace_args` mess with
  the much simpler `convert_normal_to_parsed`.

The commit converts a numberof non-exhaustive `AttrKind` matches (those
that don't involve matching a single attribute) to exhaustive, for
future-proofing. It uses `unreachable!` on all the `AttrKind::Parsed`
cases that aren't hit by the full test suite.
2026-07-17 08:59:24 +10:00
Nicholas Nethercote
d0042c3c7c Expand some comments about cfg_trace/cfg_attr_trace
To explain some things that weren't obvious to me.
2026-07-17 08:55:42 +10:00
Nicholas Nethercote
e8c660bad1 Remove unused unwrap_normal_item methods. 2026-07-17 08:55:42 +10:00
bors
470556c8c1 Auto merge of #158720 - nnethercote:Expr64, r=folkertdev
Shrink `ast::Expr64`



From 72 bytes to 64 bytes, by boxing `ForLoop`, which is the biggest
variant.

There are now 11 `ExprKind` variants that are 31 bytes, so future
improvements here will be very difficult.
2026-07-15 03:22:38 +00:00