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
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.
`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
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
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
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
[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
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
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.
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.
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
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).
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.)
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).
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.)
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.
`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.
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.