Commit Graph

175 Commits

Author SHA1 Message Date
Nicholas Nethercote
3c4f1d85af Rename {create,emit}_warning as {create,emit}_warn.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
Nicholas Nethercote
589591efde Use chaining in DiagnosticBuilder construction.
To avoid the use of a mutable local variable, and because it reads more
nicely.
2024-01-08 15:43:07 +11:00
Nicholas Nethercote
505c1371d0 Rename some Diagnostic setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be
considered setters. Four of them have a `set_` prefix. This doesn't seem
necessary for a type that implements the builder pattern. This commit
removes the `set_` prefixes on those four methods.
2024-01-03 19:40:20 +11:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Nicholas Nethercote
d51db05d7e Remove ParseSess methods that duplicate DiagCtxt methods.
Also add missing `#[track_caller]` attributes to `DiagCtxt` methods as
necessary to keep tests working.
2023-12-24 07:59:21 +11:00
Nicholas Nethercote
e7724a2e31 Add level arg to into_diagnostic.
And make all hand-written `IntoDiagnostic` impls generic, by using
`DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
`dcx.struct_err(...)`.

This means the `create_*` functions are the source of the error level.
This change will let us remove `struct_diagnostic`.

Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
it's necessary to pass diagnostics tests now that it's used in
`into_diagnostic` functions.
2023-12-19 09:19:25 +11:00
Nicholas Nethercote
f422dca3ae Rename many DiagCtxt arguments. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
09af8a667c Rename Session::span_diagnostic as Session::dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Nicholas Nethercote
a179a53565 Use Session::diagnostic in more places. 2023-12-02 09:01:35 +11:00
Nicholas Nethercote
5d1d384443 Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
León Orell Valerian Liehr
16c164fea3
Detect and reject malformed repr(Rust) hints 2023-11-27 12:29:21 +01:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
bors
22b27120b9 Auto merge of #117377 - dtolnay:deprecatedsince, r=cjgillot
Store #[deprecated] attribute's `since` value in parsed form

This PR implements the first followup bullet listed in https://github.com/rust-lang/rust/pull/117148#issue-1960240108.

We centralize error handling to the attribute parsing code in `compiler/rustc_attr/src/builtin.rs`, and thereby remove some awkward error codepaths from later phases of compilation that had to make sense of these #\[deprecated\] attributes, namely `compiler/rustc_passes/src/stability.rs` and `compiler/rustc_middle/src/middle/stability.rs`.
2023-10-31 10:42:24 +00:00
David Tolnay
8b8906b264
Add method for checking if deprecation is a rustc version 2023-10-30 17:13:38 -07:00
David Tolnay
dccf10e989
Descriptive variant name deprecation versions outside the standard library 2023-10-30 17:13:26 -07:00
David Tolnay
e8868af75b
Represent absence of 'since' attribute as a variant of DeprecatedSince 2023-10-30 16:46:02 -07:00
David Tolnay
c52367276d
Preserve deprecation attribute even if 'since' version is missing 2023-10-30 15:48:46 -07:00
David Tolnay
b106167673
Add a DeprecatedSince::Err variant for versions that fail to parse 2023-10-30 15:41:18 -07:00
David Tolnay
1e10fe9eb6
Move deprecation_in_effect to inherent method on Deprecation 2023-10-30 09:02:32 -07:00
David Tolnay
2fe7d17bd9
Store version of deprecated attribute in structured form 2023-10-29 22:42:32 -07:00
David Tolnay
1e5b2da94b
Rename Since -> StableSince in preparation for a DeprecatedSince 2023-10-29 21:39:57 -07:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
David Tolnay
b7debe34e6
Parse rustc version at compile time 2023-10-26 18:55:05 -07:00
David Tolnay
ac4fa3f245
Pre-intern a symbol for env!("CFG_RELEASE") 2023-10-26 02:02:22 -07:00
David Tolnay
1a9ea1f1a5
Expose a non-Symbol way to access current rustc version string 2023-10-24 18:11:20 -07:00
David Tolnay
51f7fbab92
CFG_RELEASE is mandatory, no need for option_env
The same file already contains another env!("CFG_RELEASE") on line 632,
so it's impossible for this crate to compile without CFG_RELEASE set.
2023-10-24 18:04:47 -07:00
David Tolnay
6933a671d3
Handle structured stable attribute 'since' version in rustdoc 2023-10-24 17:34:59 -07:00
David Tolnay
ddcb1833ff
Keep track of #[stable] attribute even if version cannot be parsed 2023-10-24 15:50:23 -07:00
David Tolnay
f2ae7b55ae
Store 'since' attribute as parsed Version 2023-10-24 15:50:23 -07:00
David Tolnay
82ed3f5e8b
Validate since value in stable attribute 2023-10-23 13:04:35 -07:00
David Tolnay
9853f6132f
Validate #[stable(feature = "…")] identifier 2023-10-23 13:02:18 -07:00
David Tolnay
28785291f9
Eliminate redundant .parse_sess in rustc_attr::builtin errors 2023-10-22 12:40:00 -07:00
David Tolnay
f5429a0186
Eliminate rustc_attr::builtin::handle_errors 2023-10-22 12:36:35 -07:00
Michael Howell
2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
bors
a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Urgau
dcfc484b09 check-cfg: mention the unexpected name and value in the primary message 2023-10-12 18:39:04 +02:00
Nicholas Nethercote
e49a1470ba Factor out insert_or_error.
It appears identically as a closure in two functions.

Also change its return type from `bool` to `Option<()>` so it can be
used with `?`.
2023-10-06 14:57:09 +11:00
Jubilee
ea3454eabb
Rollup merge of #116223 - catandcoder:master, r=cjgillot
Fix misuses of a vs an

Fixes the misuse of "a" vs "an", according to English grammatical
expectations and using https://www.a-or-an.com/
2023-10-05 00:56:29 -07:00
Nicholas Nethercote
0ece171c2f Remove E0551.
Because it's the same as E0539.

Fixes #51489.
2023-10-04 18:12:20 +11:00
Nicholas Nethercote
81136cb391 Sort compiler/rustc_attr/Cargo.toml dependencies.
It's easier to read in sorted order.
2023-10-04 17:23:04 +11:00
cui fliter
f44d116e1f Fix misuses of a vs an
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-04 08:01:11 +08:00
bors
4354192429 Auto merge of #114201 - Centri3:explicit-repr-rust, r=WaffleLapkin
Allow explicit `#[repr(Rust)]`

This is identical to no `repr()` at all. For `Rust, packed` and `Rust, align(x)`, it should be the same as no `Rust` at all (as, afaik, `#[repr(align(16))]` uses the Rust ABI.)

The main use case for this is being able to explicitly say "I want to use the Rust ABI" in very very rare circumstances where the first obvious choice would be the C ABI yet is undesirable, which is already possible with functions as `extern "Rust"`. This would be useful for silencing https://github.com/rust-lang/rust-clippy/pull/11253. It's also more consistent with `extern`.

The lack of this also tripped me up a bit when I was new to Rust, as I expected this to be possible.
2023-08-25 00:02:54 +00:00
Vadim Petrochenkov
7353c96be8 rustc: Move features from Session to GlobalCtxt
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
Taras Tsugrii
9563eec9a8 [rustc_attr][nit] Replace filter + is_some with map_or.
It's slightly shorter and better communicates the intent.
2023-08-01 12:39:32 -07:00
Catherine Flores
f42d361a22 Allow explicit #[repr(Rust)] 2023-07-29 06:58:29 +00:00