Commit graph

615 commits

Author SHA1 Message Date
Nicholas Nethercote
2fef0a30ae Replace infallible name_or_empty methods with fallible name methods.
I'm removing empty identifiers everywhere, because in practice they
always mean "no identifier" rather than "empty identifier". (An empty
identifier is impossible.) It's better to use `Option` to mean "no
identifier" because you then can't forget about the "no identifier"
possibility.

Some specifics:
- When testing an attribute for a single name, the commit uses the
  `has_name` method.
- When testing an attribute for multiple names, the commit uses the new
  `has_any_name` method.
- When using `match` on an attribute, the match arms now have `Some` on
  them.

In the tests, we now avoid printing empty identifiers by not printing
the identifier in the `error:` line at all, instead letting the carets
point out the problem.
2025-04-17 09:50:52 +10:00
Jacob Pratt
7f691d28f1
Rollup merge of #139001 - folkertdev:naked-function-rustic-abi, r=traviscross,compiler-errors
add `naked_functions_rustic_abi` feature gate

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

Because the details of the rust abi are unstable, and a naked function must match its stated ABI, this feature gate keeps naked functions with a rustic abi ("Rust", "rust-cold", "rust-call" and "rust-intrinsic") unstable.

r? ````@traviscross````
2025-04-13 17:37:52 -04:00
Folkert de Vries
8866af3884
Add naked_functions_rustic_abi feature gate 2025-04-07 21:42:12 +02:00
Oli Scherer
57c4ab7ff5 impl !PartialOrd for HirId 2025-04-03 09:22:21 +00:00
Oli Scherer
805f389da5 Remove LintExpectationId from Level variants 2025-04-03 09:22:21 +00:00
Ralf Jung
c961d123d2 add FCW to warn about wasm ABI transition 2025-03-25 08:22:35 +01:00
Nicholas Nethercote
ff0a5fe975 Remove #![warn(unreachable_pub)] from all compiler/ crates.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11 13:14:21 +11:00
许杰友 Jieyou Xu (Joe)
063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<https://github.com/rust-lang/rust/issues/138304>.

This reverts commit 48caf81484, reversing
changes made to c6662879b2.
2025-03-10 18:12:47 +08:00
Matthias Krüger
48caf81484
Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxu
Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? ``@jieyouxu``
2025-03-09 10:34:50 +01:00
Matthias Krüger
c6662879b2
Rollup merge of #138040 - thaliaarchi:use-prelude-size-of.compiler, r=compiler-errors
compiler: Use `size_of` from the prelude instead of imported

Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. Apply this change across the compiler.

These functions were added to all preludes in Rust 1.80.

r? ``@compiler-errors``
2025-03-09 10:34:49 +01:00
Matthias Krüger
5a46f82d7e
Rollup merge of #136968 - oli-obk:bye-bye, r=compiler-errors
Turn order dependent trait objects future incompat warning into a hard error

fixes #56484

r? ``@ghost``

will FCP when we have a crater result
2025-03-09 10:34:47 +01:00
Nicholas Nethercote
8a3e03392e Remove #![warn(unreachable_pub)] from all compiler/ crates.
(Except for `rustc_codegen_cranelift`.)

It's no longer necessary now that `unreachable_pub` is in the workspace
lints.
2025-03-08 08:41:43 +11:00
Nicholas Nethercote
beba32cebb Specify rust lints for compiler/ crates via Cargo.
By naming them in `[workspace.lints.rust]` in the top-level
`Cargo.toml`, and then making all `compiler/` crates inherit them with
`[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`,
because they're a bit different.)

The advantages of this over the current approach:
- It uses a standard Cargo feature, rather than special handling in
  bootstrap. So, easier to understand, and less likely to get
  accidentally broken in the future.
- It works for proc macro crates.

It's a shame it doesn't work for rustc-specific lints, as the comments
explain.
2025-03-08 08:41:09 +11:00
Thalia Archibald
38fad984c6 compiler: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-07 13:37:04 -08:00
许杰友 Jieyou Xu (Joe)
21b473334f
Rollup merge of #136764 - traviscross:TC/make-ptr_cast_add_auto_to_object-hard-error, r=oli-obk
Make `ptr_cast_add_auto_to_object` lint into hard error

In Rust 1.81, we added a FCW lint (including linting in dependencies) against pointer casts that add an auto trait to dyn bounds.  This was part of work making casts of pointers involving trait objects stricter, and was part of the work needed to restabilize trait upcasting.

We considered just making this a hard error, but opted against it at that time due to breakage found by crater.  This breakage was mostly due to the `anymap` crate which has been a persistent problem for us.

It's now a year later, and the fact that this is not yet a hard error is giving us pause about stabilizing arbitrary self types and `derive(CoercePointee)`.  So let's see about making a hard error of this.

r? ghost

cc ```@adetaylor``` ```@Darksonn``` ```@BoxyUwU``` ```@RalfJung``` ```@compiler-errors``` ```@oli-obk``` ```@WaffleLapkin```

Related:

- https://github.com/rust-lang/rust/pull/135881
- https://github.com/rust-lang/rust/issues/136702
- https://github.com/rust-lang/rust/pull/136776

Tracking:

- https://github.com/rust-lang/rust/issues/127323
- https://github.com/rust-lang/rust/issues/44874
- https://github.com/rust-lang/rust/issues/123430
2025-03-05 21:46:34 +08:00
Tamme Dittrich
9b78d48c11 After introducing the warning in 1.83, now also warn in deps
This was left to only warn in the current crate to give users
a chance to update their code. Now for 1.86 we also warn users
depending on those crates.
2025-03-03 08:52:06 +01:00
Jana Dönszelmann
7e0f5b5016
Introduce new-style attribute parsers for several attributes
note: compiler compiles but librustdoc and clippy don't
2025-02-24 14:31:17 +01:00
Travis Cross
ef337a6599 Make ptr_cast_add_auto_to_object lint into hard error
In Rust 1.81, we added a FCW lint (including linting in dependencies)
against pointer casts that add an auto trait to dyn bounds.  This was
part of work making casts of pointers involving trait objects stricter
which was needed to restabilize trait upcasting.

We considered just making this a hard error at the time, but opted
against it due to breakage found by crater.  This breakage was mostly
due to the `anymap` crate which has been a persistent problem for us.

It's now a year later, and the fact that this is not yet a hard error
is giving us pause about stabilizing arbitrary self types and
`derive(CoercePointee)`.  So let's now make a hard error of this.
2025-02-22 23:03:14 +00:00
Michael Goulet
3d5438accd Fix binding mode problems 2025-02-22 00:13:19 +00:00
Michael Goulet
7f6873f64c Fix builtin lints 2025-02-22 00:01:48 +00:00
Michael Goulet
76d341fa09 Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
Esteban Küber
835d434c79 Reword message 2025-02-20 17:55:31 +00:00
Oli Scherer
8f6b184946 Turn order dependent trait objects future incompat warning into a hard error 2025-02-20 13:39:39 +00:00
Esteban Küber
fe7ed278b7 Specify scope in out_of_scope_macro_calls lint
```
warning: cannot find macro `in_root` in the crate root
  --> $DIR/key-value-expansion-scope.rs:1:10
   |
LL | #![doc = in_root!()]
   |          ^^^^^^^ not found in the crate root
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
   = help: import `macro_rules` with `use` to make it callable above its definition
   = note: `#[warn(out_of_scope_macro_calls)]` on by default
```
2025-02-19 18:29:00 +00:00
Michael Goulet
72b4df3772 Implement lint for definition site item shadowing too 2025-02-13 05:45:53 +00:00
Michael Goulet
f8c51d3002 Implement shadowing lint 2025-02-13 05:45:53 +00:00
许杰友 Jieyou Xu (Joe)
def44600d1
Rollup merge of #135964 - ehuss:cenum_impl_drop_cast, r=Nadrieril
Make cenum_impl_drop_cast a hard error

This changes the `cenum_impl_drop_cast` lint to be a hard error. This lint has been deny-by-default and warning in dependencies since https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago.

Closes https://github.com/rust-lang/rust/issues/73333
2025-02-05 19:09:33 +08:00
Esteban Küber
8e9422f94e Make comma separated lists of anything easier to make for errors
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-31 20:36:44 +00:00
jyn
97311a8969 Downgrade linker-warnings to allow-by-default
This needs more time to bake before we turn it on. Turning it on early risks people silencing the warning indefinitely, before we have the chance to make it less noisy.
2025-01-26 22:57:20 -05:00
Jacob Pratt
dc202df0ed
Rollup merge of #133951 - bjorn3:wasm_c_abi_lint_hard_error, r=workingjubilee
Make the wasm_c_abi future compat warning a hard error

This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown.

The lint was made deny-by-default in https://github.com/rust-lang/rust/pull/129534 3 months ago. This still keeps the `-Zwasm-c-abi` flag set to `legacy` by default. It will be flipped in a future PR.

cc https://github.com/rust-lang/rust/issues/122532
2025-01-25 23:26:58 -05:00
Eric Huss
e0bbeb7a00 Make cenum_impl_drop_cast a hard error
This changes the `cenum_impl_drop_cast` lint to be a hard error. This
lint has been deny-by-default and warning in dependencies since
https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago.

Closes https://github.com/rust-lang/rust/issues/73333
2025-01-23 16:45:19 -08:00
bjorn3
4d1c16c09c Make the wasm_c_abi future compat warning a hard error
This is the next step in getting rid of the broken C abi for
wasm32-unknown-unknown.
2025-01-23 10:22:23 +00:00
jyn
537218afb2 make it possible to silence linker warnings with a crate-level attribute
this was slightly complicated because codegen_ssa doesn't have access to a tcx.
2025-01-20 16:46:00 -05:00
Jacob Pratt
285df03257
Rollup merge of #132397 - m-ou-se:warn-missing-abi, r=Nadrieril
Make missing_abi lint warn-by-default.

This makes the missing_abi lint warn-by-default, as suggested here: https://github.com/rust-lang/rfcs/pull/3722#issuecomment-2447719047

This needs a lang FCP.
2025-01-15 04:08:10 -05:00
Aditya-PS-05
7ece88a2d7 remove test_unstable_lint feature 2025-01-13 00:14:24 +05:30
Aditya-PS-05
562107760d Update unstable lint docs to include required feature attributes 2025-01-12 19:31:05 +05:30
Mara Bos
e7bd340ba4 Switch missing_abi lint to warn-by-default. 2025-01-07 15:48:19 +01:00
Kevin Reid
2a96478dd8 Mention unnameable_types in unreachable_pub documentation.
This link makes sense because someone who wishes to avoid unusable `pub`
is likely, but not guaranteed, to be interested in avoiding unnameable
types.

Also fixed some grammar problems I noticed in the area.

Fixes #116604.
2025-01-05 17:13:33 -08:00
Nicholas Nethercote
2620eb42d7 Re-export more rustc_span::symbol things from rustc_span.
`rustc_span::symbol` defines some things that are re-exported from
`rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some
closely related things such as `Ident` and `kw`. So you can do `use
rustc_span::{Symbol, sym}` but you have to do `use
rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good
reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`,
and changes many `rustc_span::symbol::` qualifiers in `compiler/` to
`rustc_span::`. This is a 200+ net line of code reduction, mostly
because many files with two `use rustc_span` items can be reduced to
one.
2024-12-18 13:38:53 +11:00
Eric Huss
3e80697972 Use links to edition guide for edition migrations 2024-12-15 20:28:16 -08:00
Jonathan Dönszelmann
d50c0a5480
Add hir::Attribute 2024-12-15 19:18:46 +01:00
Michael Goulet
db9e3681f9 Actually walk into lifetimes and attrs in EarlyContextAndPass 2024-12-07 02:08:40 +00:00
Guillaume Gomez
f79e09c562
Rollup merge of #133535 - RalfJung:forbidden_lint_groups-future-compat, r=davidtwco
show forbidden_lint_groups in future-compat reports

Part of https://github.com/rust-lang/rust/issues/81670. This has been a future-compat lint for a while, time to dial it up to show up in reports.
2024-12-02 23:08:53 +01:00
Ralf Jung
41c3b5c377 show forbidden_lint_groups in future-compat reports 2024-11-27 15:27:41 +01:00
Peter Jaszkowiak
44f4f67f46 fix confusing diagnostic for reserved ## 2024-11-25 22:29:14 -07:00
Ralf Jung
d7303194b9 show abi_unsupported_vector_types lint in future breakage reports 2024-11-23 09:15:25 +01:00
bors
3fee0f12e4 Auto merge of #131326 - dingxiangfei2009:issue-130836-attempt-2, r=nikomatsakis
Reduce false positives of tail-expr-drop-order from consumed values (attempt #2)

r? `@nikomatsakis`

Tracked by #123739.

Related to #129864 but not replacing, yet.

Related to #130836.

This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
2024-11-20 18:51:54 +00:00
Ding Xiang Fei
297b618944
reduce false positives of tail-expr-drop-order from consumed values
take 2

open up coroutines

tweak the wordings

the lint works up until 2021

We were missing one case, for ADTs, which was
causing `Result` to yield incorrect results.

only include field spans with significant types

deduplicate and eliminate field spans

switch to emit spans to impl Drops

Co-authored-by: Niko Matsakis <nikomat@amazon.com>

collect drops instead of taking liveness diff

apply some suggestions and add explantory notes

small fix on the cache

let the query recurse through coroutine

new suggestion format with extracted variable name

fine-tune the drop span and messages

bugfix on runtime borrows

tweak message wording

filter out ecosystem types earlier

apply suggestions

clippy

check lint level at session level

further restrict applicability of the lint

translate bid into nop for stable mir

detect cycle in type structure
2024-11-20 20:53:11 +08:00
Jacob Pratt
a175db1424
Rollup merge of #133108 - RalfJung:future-compat-needs-to-run, r=lcnr
lints_that_dont_need_to_run: never skip future-compat-reported lints

Follow-up to https://github.com/rust-lang/rust/pull/125116: future-compat lints show up with `--json=future-incompat` even if they are otherwise allowed in the crate. So let's ensure we do not skip those as part of the `lints_that_dont_need_to_run` logic.

I could not find a current future compat lint that is emitted by a lint pass, so there's no clear way to add a test for this.

Cc `@blyxyas` `@cjgillot`
2024-11-20 01:54:25 -05:00
Ralf Jung
df94818366 lints_that_dont_need_to_run: never skip future-compat-reported lints 2024-11-19 22:04:10 +01:00