Skip to content

Conversation

@flip1995
Copy link
Member

r? @ghost

changelog: none

pitaj and others added 28 commits October 25, 2025 14:30
Constify trait aliases

Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively.

tracking issue rust-lang/rust#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time)

r? ``@compiler-errors`` ``@fee1-dead``
…,traviscross

Implement pin-project in pattern matching for `&pin mut|const T`

This PR implements part of rust-lang/rust#130494. It supports pin-project in pattern matching for `&pin mut|const T`.

~Pin-projection by field access (i.e. `&pin mut|const place.field`) is not fully supported yet since pinned-borrow is not ready (rust-lang/rust#135731).~

CC ``````@traviscross``````
Clippy subtree update

r? ``@Manishearth``

Cargo.lock update due to Clippy version bump
…r=estebank

fix: Only special case single line item attribute suggestions

`rustc` currently special cases suggestions to add [`#[derive(_)]\n` and other attributes](https://github.com/rust-lang/rust/blob/dc1feabef242259d61bd930713de3250577c1c71/compiler/rustc_errors/src/emitter.rs#L2288C36-L2288C72), to add more context to the suggestions.

> // The suggestion adds an entire line of code, ending on a newline, so we'll also
> // print the *following* line, to provide context of what we're advising people to
> // do. Otherwise you would only see contextless code that can be confused for
> // already existing code, despite the colors and UI elements.
> // We special case `#[derive(_)]\n` and other attribute suggestions, because those
> // are the ones where context is most useful.

This special case is a bit broad at the moment and applies to suggestions just to add an attribute, as well as suggestions that contain an attribute and other code, i.e.
```rust
#[derive(Clone)]
```
and
```rust
#[cfg(not(test))]
impl Default for NewWithCfg {
    fn default() -> Self {
        Self::new()
    }
}
```

In the latter case, adding a line for context after the suggestion doesn't provide much benefit. Example:
![temp](https://github.com/user-attachments/assets/6859b400-aa99-4c1b-9eb0-0cd67ae35bf9)

This PR makes it so that this special case only applies to suggestions that just add an attribute and nothing else. This will also make `rustc`'s output match `annotate-snippets`.
When mgca is enabled, const rhs's that are paths may have false
negatives with the lints in non_copy_const.rs. But these should probably
be using the trait solver anyway, and it only happens under mgca.
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
Add `overflow_checks` intrinsic

This adds an intrinsic which allows code in a pre-built library to inherit the overflow checks option from a crate depending on it. This enables code in the standard library to explicitly change behavior based on whether `overflow_checks` are enabled, regardless of the setting used when standard library was compiled.

This is very similar to the `ub_checks` intrinsic, and refactors the two to use a common mechanism.

The primary use case for this is to allow the new `RangeFrom` iterator to yield the maximum element before overflowing, as requested [here](rust-lang/rust#125687 (comment)). This PR includes a working `IterRangeFrom` implementation based on this new intrinsic that exhibits the desired behavior.

[Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Ability.20to.20select.20code.20based.20on.20.60overflow_checks.60.3F)
…=urgau

Add new `function_casts_as_integer` lint

The `function_casts_as_integer` lint detects cases where users cast a function pointer into an integer.

*warn-by-default*

### Example

```rust
fn foo() {}
let x = foo as usize;
```

```
warning: casting a function into an integer implicitly
  --> $DIR/function_casts_as_integer.rs:9:17
   |
LL |     let x = foo as usize;
   |                 ^^^^^^^^
   |
help: add `fn() as usize`
   |
LL |     let x = foo as fn() as usize;
   |                 +++++++
```

### Explanation

You should never cast a function directly into an integer but go through a cast as `fn` first to make it obvious what's going on. It also allows to prevent confusion with (associated) constants.

Related to rust-lang/rust#81686 and https://stackoverflow.com/questions/68701177/whats-the-meaning-of-casting-a-rust-enum-variant-to-a-numeric-data-type

r? ````@urgau````
Using the new `override_allocator_on_supported_platforms` feature in
`tikv-jemalloc-sys v0.6.1` we can avoid the manual statics.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 14, 2025
@flip1995 flip1995 enabled auto-merge November 14, 2025 23:38
@flip1995 flip1995 added this pull request to the merge queue Nov 14, 2025
@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Lintcheck changes for 72fc40c

Lint Added Removed Changed
clippy::absolute_paths 0 0 25
clippy::arbitrary_source_item_ordering 0 0 7
clippy::as_conversions 0 0 65
clippy::as_underscore 0 0 54
clippy::cast_sign_loss 0 0 5
clippy::derivable_impls 0 0 2
clippy::doc_lazy_continuation 0 0 2
clippy::doc_markdown 0 0 22
clippy::doc_overindented_list_items 0 0 1
clippy::exhaustive_structs 0 0 3
clippy::expect_used 0 0 1
clippy::expl_impl_clone_on_copy 0 0 181
clippy::if_not_else 0 0 2
clippy::implicit_return 0 0 33
clippy::min_ident_chars 0 0 38
clippy::missing_const_for_fn 0 0 1
clippy::missing_docs_in_private_items 0 0 11
clippy::missing_inline_in_public_items 0 0 89
clippy::missing_trait_methods 0 0 41212
clippy::multiple_inherent_impl 0 0 1
clippy::multiple_unsafe_ops_per_block 0 0 4
clippy::must_use_candidate 0 0 13
clippy::needless_borrow 0 0 4
clippy::non_ascii_literal 0 7 1
clippy::panic 0 0 2
clippy::panic_in_result_fn 0 0 1
clippy::question_mark_used 0 0 66
clippy::redundant_pub_crate 0 0 6
clippy::redundant_static_lifetimes 0 0 1
clippy::semicolon_if_nothing_returned 0 0 1
clippy::shadow_reuse 0 0 7
clippy::single_call_fn 0 0 4
clippy::std_instead_of_core 0 0 1
clippy::str_to_string 0 0 1
clippy::too_long_first_doc_paragraph 0 0 1
clippy::too_many_lines 0 0 6
clippy::undocumented_unsafe_blocks 0 0 10
clippy::uninlined_format_args 0 0 2
clippy::unnecessary_wraps 0 0 5
clippy::unreachable 0 0 1
clippy::unseparated_literal_suffix 0 0 1
clippy::use_self 0 0 5
clippy::useless_conversion 0 0 3
clippy::wildcard_enum_match_arm 0 0 1

This comment will be updated if you push new changes

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 14, 2025
@flip1995 flip1995 added this pull request to the merge queue Nov 14, 2025
@flip1995 flip1995 removed this pull request from the merge queue due to a manual request Nov 14, 2025
@flip1995 flip1995 enabled auto-merge November 14, 2025 23:58
@flip1995 flip1995 added this pull request to the merge queue Nov 15, 2025
Merged via the queue into rust-lang:master with commit 62589a2 Nov 15, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 15, 2025
@flip1995 flip1995 deleted the rustup branch November 15, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.