Commit graph

2567 commits

Author SHA1 Message Date
Wafarm
e513ce3fb4
Check identifiers defined in macros when suggesting identifiers hidden by hygiene 2025-12-04 14:58:46 +08:00
Matthias Krüger
02434fe718
Rollup merge of #148678 - xonx4l:EO412_replacement_with_EO425, r=Kivooeo
Merge E0412 into E0425

This PR merge E0412 into E0425  as both mean the same thing to users.

This fixes https://github.com/rust-lang/rust/issues/148558.
2025-12-02 22:02:30 +01:00
xonx4l
4b000cfacd Merge E0412 into E0425 2025-12-02 18:25:13 +00:00
bors
47cd7120d9 Auto merge of #147634 - fmease:mv-var-to-dyn-buf-lints-next, r=jdonszelmann
Move even more early buffered lints to dyn lint diagnostics

Follow-up to https://github.com/rust-lang/rust/pull/145881 and https://github.com/rust-lang/rust/pull/145747.

I originally wanted to migrate most if not the entire rest of the early buffered lints. However, when trying to migrate the buffered lints used by check-cfg I encountered a roadblock. Namely, it depends on `TyCtxt` (well, `Option<TyCtxt>`) which makes it quite hard to migrate (see also https://github.com/rust-lang/rust/pull/147634#issuecomment-3398174584, https://github.com/rust-lang/rust/pull/147634#issuecomment-3398207128 & rust-lang/rust#149215).

So for now, I won't migrate it (maybe rust-lang/rust#149215 will find a solution), nor will I migrate the rest since it's quite tedious to migrate these. I'll leave them for future me.
2025-12-02 07:33:36 +00:00
bors
1d60f9e070 Auto merge of #149515 - matthiaskrgr:rollup-djmciuc, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#149393 (expand valid edition range for use-path-segment-kw.rs)
 - rust-lang/rust#149427 (Make the capitalization explicit on keyword misspell error)
 - rust-lang/rust#149433 (Use a delayed bug for this layout ICE)
 - rust-lang/rust#149473 (Tidying up UI tests [7/N])
 - rust-lang/rust#149505 (Update the comment in the add_typo_suggestion function)
 - rust-lang/rust#149513 (`rust-analyzer` subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-01 20:29:33 +00:00
Matthias Krüger
453fca50ef
Rollup merge of #149505 - reddevilmidzy:fix, r=WaffleLapkin
Update the comment in the add_typo_suggestion function

This comment was added to 089810a1cb. However, the test for the comment was moved elsewhere in https://github.com/rust-lang/rust/pull/145897.
2025-12-01 18:35:12 +01:00
Matthias Krüger
e0091c5590
Rollup merge of #149496 - aerooneqq:ice-issue-148889, r=petrochenkov
Fix #148889: Add label rib when visiting delegation body

This PR relates to the delegation feature rust-lang/rust#118212, it fixes rust-lang/rust#148889 ICE.
r? `@petrochenkov`
2025-12-01 17:55:12 +01:00
León Orell Valerian Liehr
109e5e5999
Move early buffered lint ambigous-glob-imports to a dyn lint diagnostic 2025-12-01 16:31:53 +01:00
reddevilmidzy
31106eb752 Update the comment in the add_typo_suggestion function 2025-12-01 21:49:40 +09:00
aerooneqq
968376d507 Add label rib when visiting delegation body, add test 2025-12-01 12:38:12 +03:00
Matthias Krüger
97b5b9b817
Rollup merge of #148169 - fmease:rustdoc-bad-intra-bad-preprocess, r=lolbinarycat
Fix bad intra-doc-link preprocessing

How did rust-lang/rust#147981 happen?

1. We don't parse intra-doc links as Rust paths or qpaths. Instead they follow a very lenient bespoke grammar. We completely ignore Markdown links if they contain characters that don't match `/[a-zA-Z0-9_:<>, !*&;]/` (we don't even emit lint *broken-intra-doc-links* for these).
2. PR [#132748](https://github.com/rust-lang/rust/pull/132748) made rustdoc intepret more Markdown links as potential intra-doc links. Namely, if the link is surrounded by backticks (and some other conditions apply) then it doesn't matter if the (partially processed) link contains bad characters as defined above (cc `ignore_urllike && should_ignore_link(path_str)`).
3. However, rustdoc's `preprocess_link` must be kept in sync with a simplified counterpart in rustc. More specifically, whenever rustdoc's preprocessor returns a successful result then rustc's must yield the same result. Otherwise, rustc doesn't resolve the necessary links for rustdoc.
4. This uncovered a "dormant bug" / "mistake" in rustc's `preprocess_link`. Namely, when presented with a link like `struct@Type@suffix`, it didn't cut off the disambiguator if present (here: `struct@`). Instead it `rsplit('``@')``` which is incorrect if the "path" contains ```@``` itself (yielding `suffix` instead of `Type@suffix` here). Prior to PR [#132748](https://github.com/rust-lang/rust/pull/132748), a link like ``[`struct@Type@suffix`]`` was not considered a potential intra-doc link / worth querying rustc for. Now it is due to the backticks.
5. Finally, since rustc didn't record a resolution for `Type@suffix` (it only recorded `suffix` (to be `Res::Err`)), we triggered an assertion we have in place to catch cases like this.

Fixes rust-lang/rust#147981.

I didn't and still don't have the time to investigate if rust-lang/rust#132748 led to more rustc/rustdoc mismatches (after all, the PR made rustdoc's `preprocess_link` return `Some(Ok(_))` in more cases). I've at least added another much needed "warning banner" & made the existing one more flashy.

While this fixes a stable-to-beta regression, I don't think it's worth beta backporting, esp. since it's only P-medium and since the final 1.91 release steps commence today / the next days, so it would only be stressful to get it in on time. However, feel free to nominate.

<sub>(I've written such a verbose PR description since I tend to reread my old PR descriptions in the far future to fully freshen my memories when I have to work again in this area)</sub>

r? ``@lolbinarycat``
2025-11-30 18:44:22 +01:00
León Orell Valerian Liehr
3ad6359f54
Move more early buffered lints to dyn lint diagnostics (6/N) 2025-11-30 17:59:42 +01:00
León Orell Valerian Liehr
74d12e8598
Move more early buffered lints to dyn lint diagnostics (5/N) 2025-11-30 17:54:38 +01:00
León Orell Valerian Liehr
55d90c0653
Fix bad intra-doc-link preprocessing 2025-11-30 13:08:59 +01:00
Vadim Petrochenkov
c91b6ca58d resolve: Split resolve_ident_in_module_unadjusted into two parts - for non-glob and glob bindings.
In preparation for introducing `Scope::Module(Non)Globs` and `ScopeSet::Module`.
2025-11-29 17:23:53 +03:00
Vadim Petrochenkov
9761db07d9 resolve: Correctly mark break and continue for determinate errors
Existing but private bindings - break, everything else - continue.
2025-11-29 17:10:31 +03:00
Vadim Petrochenkov
674d287c38 resolve: Replace enum Weak with ops::ControlFlow 2025-11-29 17:05:37 +03:00
Vadim Petrochenkov
56e1e240e6 resolve: Remove some function parameters and return values that are no longer used 2025-11-29 16:47:27 +03:00
Vadim Petrochenkov
b7f6c9559c resolve: Move resolve_ident_in_module_unadjusted for real modules to a separate method 2025-11-29 16:47:27 +03:00
Vadim Petrochenkov
621d87099b resolve: Tweak top level logic and comments in resolve_ident_in_scope_set 2025-11-29 16:47:27 +03:00
Vadim Petrochenkov
47edfd386a resolve: Move ambiguity detection in resolve_ident_in_scope_set into a separate function 2025-11-29 16:47:27 +03:00
Vadim Petrochenkov
6ca6302533 resolve: Move one iteration of resolve_ident_in_scope_set into a separate function 2025-11-29 16:47:27 +03:00
Vadim Petrochenkov
97e6819e92 resolve: Use ControlFlow in fn visit_scopes callback 2025-11-29 16:47:26 +03:00
Jacob Pratt
888e5da41c
Rollup merge of #147362 - chenyukang:yukang-fix-bound-147356, r=fee1-dead
Avoid suggesting constrain the associated type with unknown type

Fixes rust-lang/rust#147356
2025-11-28 21:22:23 -05:00
Matthias Krüger
d67a12dfff
Rollup merge of #148256 - lcnr:orphan-check, r=spastorino,WaffleLapkin
remove support for `typeof`

see https://github.com/rust-lang/compiler-team/issues/940 closes https://github.com/rust-lang/rust/issues/148700

This also enables checks for invariants previously broken by `typeof` again.

r? types
2025-11-27 15:59:11 +01:00
Stuart Cook
e4cd17cd44
Rollup merge of #148641 - oli-obk:push-olzwqxsmnxmz, r=jackh726
Add a diagnostic attribute for special casing const bound errors for non-const impls

Somewhat of a follow-up to https://github.com/rust-lang/rust/pull/144194

My plan is to resolve

f4e19c6878/compiler/rustc_hir_typeck/src/callee.rs (L907-913)

but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
2025-11-27 12:36:48 +11:00
Oli Scherer
9218298caa Add a diagnostic attribute for special casing const bound errors for non-const impls 2025-11-26 07:40:47 +00:00
lcnr
feb13036ef remove support for type-of 2025-11-25 10:19:44 +01:00
yukang
76bd555913 Avoid suggesting constrain the associated type to a trait 2025-11-22 10:20:14 +08:00
James Barford-Evans
3d3394200a Use less brittle way for updating error message 2025-11-20 11:27:18 +00:00
James Barford-Evans
ed6a78ca86 Fix error message for calling a non-tuple struct 2025-11-19 15:50:40 +00:00
Theemathas Chirananthavat
cf47879b03 Remove unnecessary lifetime in with_generic_param_rib
Having the same lifetime in two covariant arguments doesn't do anything.

The lifetime was unnecessarilly added in faf0852fc1 (diff-3cff50afc88a11e641a6851dd19471a7e6470f05dd0cddaf2271e5cdd9936b73L2125)
2025-11-14 20:30:26 +07:00
Stuart Cook
ee40e0267c
Rollup merge of #148808 - nnethercote:resolve-cleanups, r=chenyukang,petrochenkov
Some resolve cleanups

Minor improvements I found while looking over this code.

r? ```````@petrochenkov```````
2025-11-14 13:14:00 +11:00
Nicholas Nethercote
8ece93912c Remove trace argument from resolve_macro_or_delegation_path.
It's `true` at all call sites.
2025-11-13 09:15:56 +11:00
Nicholas Nethercote
258a446c89 Simplify Resolver::resolve_macro_path.
There are only two call sites, and three of the arguments are identical
at both call sites. This commit removes those arguments and renames the
method accordingly.
2025-11-13 09:15:44 +11:00
Stuart Cook
60b2068eed
Rollup merge of #148770 - folkertdev:naked-c-variadic, r=workingjubilee
implement `feature(c_variadic_naked_functions)`

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

[#t-lang > C-variadic naked functions](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/C-variadic.20naked.20functions/with/554593886)

This feature allows naked c-variadic function definitions with any ABI that is supported for foreign c-variadic functions.

```rust
#![feature(c_variadic, c_variadic_naked_functions)]

#[unsafe(naked)]
unsafe extern "win64" fn variadic_win64(_: u32, _: ...) -> u32 {
    core::arch::naked_asm!(
        r#"
        push    rax
        mov     qword ptr [rsp + 40], r9
        mov     qword ptr [rsp + 24], rdx
        mov     qword ptr [rsp + 32], r8
        lea     rax, [rsp + 40]
        mov     qword ptr [rsp], rax
        lea     eax, [rdx + rcx]
        add     eax, r8d
        pop     rcx
        ret
    "#,
    )
}
```

r? ````@workingjubilee````
2025-11-12 12:26:40 +11:00
bors
2636cb4c13 Auto merge of #148818 - Zalathar:rollup-4vujcg0, r=Zalathar
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS)
 - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system)
 - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor)
 - rust-lang/rust#148771 (IAT: Reinstate early bailout)
 - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function)
 - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.)
 - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`)
 - rust-lang/rust#148783 (add test for assoc type norm wf check)
 - rust-lang/rust#148785 (Replace `master` branch references with `main`)
 - rust-lang/rust#148791 (fix "is_closure_like" doc comment)
 - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map)
 - rust-lang/rust#148805 (rustc-dev-guide subtree update)
 - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-11 13:30:50 +00:00
Stuart Cook
eb415e9a25
Rollup merge of #148506 - estebank:issue-41966, r=davidtwco
Special case detecting `'static` lifetime requirement coming from `-> Box<dyn Trait>`

```
error[E0310]: the parameter type `R` may not live long enough
  --> $DIR/implicit-static-lifetime-in-dyn-trait-return-type.rs:10:5
   |
LL | fn bb<R>(r: R) -> Box<dyn Foo> {
   |                       ------- this `dyn Trait` has an implicit `'static` lifetime bound
LL |     Box::new(Bar(r))
   |     ^^^^^^^^^^^^^^^^
   |     |
   |     the parameter type `R` must be valid for the static lifetime...
   |     ...so that the type `R` will meet its required lifetime bounds
   |
help: consider adding an explicit lifetime bound
   |
LL | fn bb<R: 'static>(r: R) -> Box<dyn Foo> {
   |        +++++++++
```

Partly address rust-lang/rust#41966 and rust-lang/rust#54753. rust-lang/rust#103849, which shows a case where there's an intermediary binding, is not addressed at all, as aren't cases *other* than `Box<dyn Trait>` return type.
2025-11-11 21:09:37 +11:00
Nicholas Nethercote
c6dbda8996 Document (and test) a problem with Clone/Copy deriving. 2025-11-11 11:35:10 +11:00
Folkert de Vries
568c6ed8c9
propagate function attributes in ast visitor 2025-11-09 14:35:11 +01:00
Stuart Cook
99af1bc1b9
Rollup merge of #148612 - chenyukang:yukang-fix-148580-macro-hygiene-diagnostic, r=JonathanBrouwer
Add note for identifier with attempted hygiene violation

Fixes rust-lang/rust#148580

I changed the original test to make sure we are pointing to the right scope.
2025-11-09 13:22:31 +11:00
bors
72b21e1a64 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
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.
2025-11-08 22:31:33 +00:00
Noah Lev
66267da3e9 Use "rhs" terminology instead of "body" 2025-11-08 13:50:48 -05:00
yukang
12cde3091a Add note for identifier with attempted hygiene violation 2025-11-07 08:27:23 +08:00
bjorn3
973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
bors
8e0b68e63c Auto merge of #148507 - Zalathar:rollup-vvz4knr, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#147355 (Add alignment parameter to `simd_masked_{load,store}`)
 - rust-lang/rust#147925 (Fix tests for big-endian)
 - rust-lang/rust#148341 (compiler: Fix a couple issues around cargo feature unification)
 - rust-lang/rust#148371 (Dogfood `trim_{suffix|prefix}` in compiler)
 - rust-lang/rust#148495 (Implement Path::is_empty)
 - rust-lang/rust#148502 (rustc-dev-guide subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-05 07:25:39 +00:00
Stuart Cook
21da1760da
Rollup merge of #148371 - yotamofek:pr/dogfood-trim-prefix-suffix, r=fee1-dead
Dogfood `trim_{suffix|prefix}` in compiler

cc rust-lang/rust#142312
2025-11-05 10:59:19 +11:00
Esteban Küber
a49d4d7713 Special case detecting 'static lifetime requirement coming from -> Box<dyn Trait>
```
error[E0310]: the parameter type `R` may not live long enough
  --> $DIR/implicit-static-lifetime-in-dyn-trait-return-type.rs:10:5
   |
LL | fn bb<R>(r: R) -> Box<dyn Foo> {
   |                       ------- this `dyn Trait` has an implicit `'static` lifetime bound
LL |     Box::new(Bar(r))
   |     ^^^^^^^^^^^^^^^^
   |     |
   |     the parameter type `R` must be valid for the static lifetime...
   |     ...so that the type `R` will meet its required lifetime bounds
   |
help: consider adding an explicit lifetime bound
   |
LL | fn bb<R: 'static>(r: R) -> Box<dyn Foo> {
   |        +++++++++
```
2025-11-04 22:33:13 +00:00
bors
6e41e61977 Auto merge of #145314 - estebank:issue-135589-all, r=Nadrieril
Tweak output of missing lifetime on associated type

Follow up to https://github.com/rust-lang/rust/pull/135602.

Previously we only showed the trait's assoc item if the trait was local, because we were looking for a small span only for the generics, which we don't have for foreign traits. We now use `def_span` for the item, so we at least provide some context, even if its span is too wide.

```
error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
   --> tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs:7:18
    |
7   |     type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
    |                  ^^^^ lifetimes do not match type in trait
    |
   ::: /home/gh-estebank/rust/library/core/src/iter/traits/collect.rs:292:5
    |
292 |     type IntoIter: Iterator<Item = Self::Item>;
    |     ------------------------------------------ lifetimes in impl do not match this type in trait
```

Given an associated item that needs a named lifetime, look at the enclosing `impl` item for one. If there is none, look at the self type and the implemented trait to see if either of those has an anonimous lifetime. If so, suggest adding a named lifetime.

```
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
   |
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
   |
help: add a lifetime to the impl block and use it in the self type and associated type
   |
LL ~ impl<'a> IntoIterator for &'a S {
LL ~     type Item = &'a T;
   |
```

Move the previous long message to a note and use a shorter primary message:

```
error: missing lifetime in associated type
  --> $DIR/missing-lifetime-in-assoc-type-1.rs:9:17
   |
LL | impl<'a> IntoIterator for &S {
   |     ---- there is a named lifetime specified on the impl block you could use
...
LL |     type Item = &T;
   |                 ^ this lifetime must come from the implemented type
   |
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
  --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider using the lifetime from the impl block
   |
LL |     type Item = &'a T;
   |                  ++
```

r? `@Nadrieril`
2025-11-04 21:37:44 +00:00
Esteban Küber
14646ec374 Add note to E0401 2025-11-03 16:24:36 +00:00