Commit Graph

519 Commits

Author SHA1 Message Date
Matthias Krüger
77152955b8
Rollup merge of #127106 - spastorino:improve-unsafe-extern-blocks-diagnostics, r=compiler-errors
Improve unsafe extern blocks diagnostics

Closes #126327

For this code:

```rust
extern {
    pub fn foo();
    pub safe fn bar();
}
```

We get ...

```
error: items in unadorned `extern` blocks cannot have safety qualifiers
 --> test.rs:3:5
  |
3 |     pub safe fn bar();
  |     ^^^^^^^^^^^^^^^^^^
  |
help: add unsafe to this `extern` block
  |
1 | unsafe extern {
  | ++++++

error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental
 --> test.rs:3:9
  |
3 |     pub safe fn bar();
  |         ^^^^
  |
  = note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
  = help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
```

And then making the extern block unsafe, we get ...

```
error: extern block cannot be declared unsafe
 --> test.rs:1:1
  |
1 | unsafe extern {
  | ^^^^^^
  |
  = note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
  = help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable

error: items in unadorned `extern` blocks cannot have safety qualifiers
 --> test.rs:3:5
  |
3 |     pub safe fn bar();
  |     ^^^^^^^^^^^^^^^^^^

error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental
 --> test.rs:3:9
  |
3 |     pub safe fn bar();
  |         ^^^^
  |
  = note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
  = help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
```

r? ``@compiler-errors``
2024-06-29 22:10:57 +02:00
Santiago Pastorino
15d5dac32e
Avoid suggesting to add unsafe when the extern block is already unsafe 2024-06-29 14:40:32 -03:00
Santiago Pastorino
a62cbda57e
Add feature diagnostic for unsafe_extern_blocks 2024-06-28 23:13:33 -03:00
Matthias Krüger
26df3146ab
Rollup merge of #124091 - jieyouxu:ast-validation-top-level-docs, r=wesleywiser
Update AST validation module docs

Drive-by doc update for AST validation pass:

- Syntax extensions are replaced by proc macros.
- Add rationale for why AST validation pass need to be run
  post-expansion and why the pass is needed in the first place.

This was discussed during this week's [rustc-dev-guide reading club](https://rust-lang.zulipchat.com/#narrow/stream/196385-t-compiler.2Fwg-rustc-dev-guide), and the rationale was explained by cc ``````@bjorn3.``````
2024-06-28 22:04:15 +02:00
Matthias Krüger
b2720867f1
Rollup merge of #126973 - chenyukang:yukang-fix-126756-unsafe-suggestion-error, r=spastorino
Fix bad replacement for unsafe extern block suggestion

Fixes #126756

r? ``@spastorino``

link #123743
2024-06-26 07:50:21 +02:00
yukang
0addda6578 Fix bad replacement for unsafe extern block suggestion 2024-06-26 08:50:50 +08:00
carbotaniuman
a23917cfd0 Add hard error and migration lint for unsafe attrs 2024-06-23 19:02:14 -05:00
Jubilee Young
43a6b018a2 compiler: Mention C-unwind in C-variadic error 2024-06-22 23:30:31 -07:00
Jubilee Young
26dccadb47 Allow "C-unwind" fn to have C variadics 2024-06-22 15:14:14 -07:00
Santiago Pastorino
22831ed117
Do not allow safe usafe on static and fn items 2024-06-21 09:12:13 -03:00
Matthias Krüger
f577d808b7
Rollup merge of #126767 - compiler-errors:static-foreign-item, r=spastorino
`StaticForeignItem` and `StaticItem` are the same

The struct `StaticItem` and `StaticForeignItem` are the same, so remove `StaticForeignItem`. Having them be separate is unique to `static` items -- unlike `ForeignItemKind::{Fn,TyAlias}`, which use the normal AST item.

r? ``@spastorino`` or ``@oli-obk``
2024-06-21 09:12:37 +02:00
Michael Goulet
3e59f0c3c5 StaticForeignItem and StaticItem are the same 2024-06-20 19:51:09 -04:00
Michael Goulet
108b3f214a Properly gate safe keyword in pre-expansion 2024-06-20 14:14:49 -04:00
Oli Scherer
7ba82d61eb Use a dedicated type instead of a reference for the diagnostic context
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18 15:42:11 +00:00
Michael Goulet
2e03130e11 Detect duplicates 2024-06-17 22:35:25 -04:00
Michael Goulet
f66558d2bf Add tests for illegal use bound syntax 2024-06-17 22:35:25 -04:00
Michael Goulet
b1efe1ab5d Rework precise capturing syntax 2024-06-17 22:35:25 -04:00
Nicholas Nethercote
75b164d836 Use tidy to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.

For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
  `allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
  sometimes the order is alphabetical, and sometimes there is no
  particular order.
- Sometimes the attributes of a particular kind aren't even grouped
  all together, e.g. there might be a `feature`, then an `allow`, then
  another `feature`.

This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.

Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
  because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
  ignored in `rustfmt.toml`).
2024-06-12 15:49:10 +10:00
carbotaniuman
67f5dd1ef1 Parse unsafe attributes 2024-06-06 20:26:27 -05:00
Santiago Pastorino
1afc7d716c
Make MISSING_UNSAFE_ON_EXTERN lint emit future compat info with suggestion to prepend unsafe 2024-06-05 09:36:01 -03:00
Santiago Pastorino
0380321e78
Add unsafe_extern_blocks feature flag 2024-06-05 09:35:57 -03:00
Santiago Pastorino
b4cbdb7246
Fail when using safe/unsafe items inside unadorned extern blocks 2024-06-04 14:19:43 -03:00
Santiago Pastorino
2a377122dd
Handle safety keyword for extern block inner items 2024-06-04 14:19:42 -03:00
Santiago Pastorino
bbddc9b58f
Allow using unsafe on functions inside extern blocks 2024-06-04 14:19:42 -03:00
Santiago Pastorino
3ba8de0b60
Make extern blocks without unsafe warn in edition 2024 2024-06-04 14:19:42 -03:00
Santiago Pastorino
6d670b74e5
Allow unsafe extern on all editions 2024-06-04 14:19:42 -03:00
Matthias Krüger
379233242b
Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, r=compiler-errors
Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup

Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology.

Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense.

---

Old terminology (HIR, rustdoc):

```
`TypeBinding`: (associated) type binding
├── `Constraint`: associated type bound
└── `Equality`: (associated) equality constraint (?)
    ├── `Ty`: (associated) type binding
    └── `Const`: associated const equality (constraint)
```

Old terminology (AST, abbrev.):

```
`AssocConstraint`
├── `Bound`
└── `Equality`
    ├── `Ty`
    └── `Const`
```

New terminology (AST, HIR, rustdoc):

```
`AssocItemConstraint`: associated item constraint
├── `Bound`: associated type bound
└── `Equality`: associated item equality constraint OR associated item binding (for short)
    ├── `Ty`: associated type equality constraint OR associated type binding (for short)
    └── `Const`: associated const equality constraint OR associated const binding (for short)
```

r? compiler-errors
2024-05-31 08:50:22 +02:00
León Orell Valerian Liehr
34c56c45cf
Rename HIR TypeBinding to AssocItemConstraint and related cleanup 2024-05-30 22:52:33 +02:00
Jubilee
866630d004
Rollup merge of #124048 - veera-sivarajan:bugfix-123773-c23-variadics, r=compiler-errors
Support C23's Variadics Without a Named Parameter

Fixes #123773

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

This will not break any existing code as mentioned in the proposal
document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
2024-05-26 15:28:26 -07:00
Xiretza
98dd6c7e8f Rename buffer_lint_with_diagnostic to buffer_lint 2024-05-21 20:16:39 +00:00
Xiretza
8004e6a379 Make early lints translatable 2024-05-21 20:16:39 +00:00
Xiretza
c227f35a9c Generate lint diagnostic message from BuiltinLintDiag
Translation of the lint message happens when the actual diagnostic is
created, not when the lint is buffered. Generating the message from
BuiltinLintDiag ensures that all required data to construct the message
is preserved in the LintBuffer, eventually allowing the messages to be
moved to fluent.

Remove the `msg` field from BufferedEarlyLint, it is either generated
from the data in the BuiltinLintDiag or stored inside
BuiltinLintDiag::Normal.
2024-05-21 20:16:39 +00:00
Matthias Krüger
a79737c3f0
Rollup merge of #125314 - jdonszelmann:global-registration-feature-gate, r=pnkfelix
Add an experimental feature gate for global registration

See #125119 for the tracking issue.
2024-05-20 18:13:49 +02:00
Santiago Pastorino
6b46a919e1
Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
jdonszelmann
42119ff45c
create a feature gate 2024-05-14 16:11:26 +02:00
Ross Smyth
6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
León Orell Valerian Liehr
2a1d748254
Replace item names containing an error code with something more meaningful
or inline such functions if useless.
2024-04-30 22:27:19 +02:00
Santiago Pastorino
f06e0f7837
Add StaticForeignItem and use it on ForeignItemKind 2024-04-29 13:15:51 -03:00
Vadim Petrochenkov
5be9fdd636 ast: Generalize item kind visiting
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25 22:49:58 +03:00
Gary Guo
94c1920497 Stabilise inline_const 2024-04-24 13:12:25 +01:00
Xiretza
5646b65cf5 Pass translation closure to add_to_diag_with() as reference 2024-04-21 07:45:03 +00:00
许杰友 Jieyou Xu (Joe)
0e3521605d ast_passes/validation: update attribute macro example 2024-04-17 19:38:29 +00:00
许杰友 Jieyou Xu (Joe)
356027b709 ast_passes/validation: update module docs
- Syntax extensions are replaced by proc macros.
- Add rationale for why AST validation pass need to be run
  post-expansion and why the pass is needed in the first place.
2024-04-17 19:23:34 +00:00
Jules Bertholet
2a4624ddd1
Rename BindingAnnotation to BindingMode 2024-04-17 09:34:39 -04:00
Veera
f005b451c2 Support C23's Variadics Without a Named Parameter
This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
2024-04-16 18:53:05 -04:00
Michael Goulet
a076eae0d2 Parsing , pre-lowering support for precise captures 2024-04-15 16:45:01 -04:00
Matthias Krüger
15a8b490ea
Rollup merge of #123841 - Kohei316:remove_qualifier_sugg, r=wesleywiser
Improve diagnostic by suggesting to remove visibility qualifier

Resolves #123529
This PR improve diagnostic by suggesting to remove visibility qualifier.
2024-04-12 17:41:35 +02:00
morine0122
ac1bee6493 Improve diagnostic by suggesting to remove visibility qualifier 2024-04-12 12:59:40 +09:00
Michael Goulet
3253c021cb Add a helper for extending a span to include any trailing whitespace 2024-04-09 14:06:09 -04:00
Oli Scherer
c340e67dec Add pattern types to parser 2024-04-08 11:57:17 +00:00