Commit Graph

35 Commits

Author SHA1 Message Date
Jubilee
bd2e7ee976
Rollup merge of #128721 - Brezak:pointee-in-strange-places, r=pnkfelix
Don't allow the `#[pointee]` attribute where it doesn't belong

Error if the `#[pointee]` attribute is applied to anything but generic type parameters.

Closes #128485
Related to #123430
2024-10-07 11:10:52 -07:00
Brezak
aa4f16a6e7
Check that #[pointee] is applied only to generic arguments 2024-10-06 23:56:27 +02:00
Folkert
aa5bbf05f4 implement naked_asm macro 2024-10-06 18:12:25 +02:00
Matthias Krüger
b6b8330b9d
Rollup merge of #128305 - folkertdev:asm-parser-unsupported-operand, r=Amanieu
improve error message when `global_asm!` uses `asm!` operands

follow-up to https://github.com/rust-lang/rust/pull/128207

what was

```
error: expected expression, found keyword `in`
 --> src/lib.rs:1:31
  |
1 | core::arch::global_asm!("{}", in(reg));
  |                               ^^ expected expression
```

becomes

```
error: the `in` operand cannot be used with `global_asm!`
  --> $DIR/parse-error.rs:150:19
   |
LL | global_asm!("{}", in(reg));
   |                   ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
```

the span of the error is just the keyword, which means that we can't create a machine-applicable suggestion here. The alternative would be to attempt to parse the full operand, but then if there are syntax errors in the operand those would  be presented to the user, even though the parser already knows that the output won't be valid. Also that would require more complexity in the parser.

So I think this is a nice improvement at very low cost.
2024-08-04 11:32:33 +02:00
carbotaniuman
49db8a5a99 Add toggle for parse_meta_item unsafe parsing
This makes it possible for the `unsafe(...)` syntax to only be
valid at the top level, and the `NestedMetaItem`s will automatically
reject `unsafe(...)`.
2024-07-30 18:28:43 -05:00
Folkert
571f7b6589
improve error message when global asm uses inline asm operands 2024-07-28 15:11:32 +02:00
Matthias Krüger
a13f40dae6
Rollup merge of #127853 - folkertdev:naked-function-error-messages, r=bjorn3
`#[naked]`: report incompatible attributes

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

this is a re-implementation of https://github.com/rust-lang/rust/pull/93809 by ``@bstrie`` which was closed 2 years ago due to inactivity.

This PR takes some of the final comments into account, specifically providing a little more context in error messages, and using an allow list to determine which attributes are compatible with `#[naked]`.

Notable attributes that are incompatible with `#[naked]` are:

  * `#[inline]`
  * `#[track_caller]`
  * ~~`#[target_feature]`~~ (this is now allowed, see PR discussion)
  * `#[test]`, `#[ignore]`, `#[should_panic]`

These attributes just directly conflict with what `#[naked]` should do.

Naked functions are still important for systems programming, embedded, and operating systems, so I'd like to move them forward.
2024-07-28 08:57:16 +02:00
Folkert
d3858f7465
improve error message when global_asm! uses asm! options 2024-07-25 22:33:52 +02:00
Folkert
4d082b77af
add error message when #[naked] is used with #[test] 2024-07-17 00:04:00 +02:00
he1pa
a82f70eeee Migrate some rustc_builtin_macros to SessionDiagnostic
Signed-off-by: he1pa <18012015693@163.com>
2024-06-25 18:04:21 +08:00
carbotaniuman
c4de986afa Disallow unsafe in derive 2024-06-06 20:26:27 -05:00
Xiretza
b7abf014ec Convert uses of BuiltinLintDiag::Normal to custom variants
This ensures all diagnostic messages are created at diagnostic emission
time, making them translatable.
2024-05-21 20:16:39 +00:00
Nicholas Nethercote
8dc84fa7d1 Move some functions from rustc_expand to rustc_builtin_macros.
These functions are only used in `rustc_builtin_macros`, so it makes
sense for them to live there. This allows them to be changed from `pub`
to `pub(crate)`.
2024-04-26 09:24:33 +10:00
beetrees
0bbaa2505b
Fix error message for env! when env var is not valid Unicode 2024-04-01 05:44:45 +01:00
Matthias Krüger
d774fbea7c
Rollup merge of #119365 - nbdd0121:asm-goto, r=Amanieu
Add asm goto support to `asm!`

Tracking issue: #119364

This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto).

Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary.

r? ``@Amanieu``
cc ``@ojeda``
2024-03-08 08:19:17 +01:00
r0cky
2064c19886 Remove unused fluent messages 2024-03-01 09:59:44 +08:00
Gary Guo
31f078ea99 Forbid asm unwind to work with labels 2024-02-24 18:50:09 +00:00
francorbacho
cbc6b65d9a Keep fluent slugs in alphabetical order 2023-10-05 16:17:32 +02:00
francorbacho
fcdd5c0b2d Plurals in format redundant arguments suggestion 2023-10-05 16:11:31 +02:00
francorbacho
04fc051a34 Use diagnostic impls and add suggestions in redundant format!() args 2023-10-05 16:09:57 +02:00
Lukas Markeffsky
d990eee0c8 add diagnostic for raw identifiers in format string 2023-09-06 18:55:45 +02:00
Camille GILLOT
2a0a1f918d Make test harness lint about unnnameable tests. 2023-08-03 13:07:30 +00:00
David Wood
75df62d4a2
builtin_macros: raw str in diagnostic output
If a raw string was used in the `env!` invocation, then it should also
be shown in the diagnostic messages as a raw string.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:12:52 +01:00
He1pa
453603a4b5 fix typo 2023-06-28 10:52:48 +08:00
He1pa
8af8a95a64 Migrate some rustc_builtin_macros to SessionDiagnostic 2023-06-25 01:32:30 +08:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
est31
5eb29c7f49 Migrate offset_of from a macro to builtin # syntax 2023-05-05 21:44:13 +02:00
clubby789
3738a18df7 Migrate builtin_macros::asm diagnostics to translatable diagnostics 2023-04-30 21:45:46 +01:00
clubby789
0138513635 Fix static string lints 2023-04-25 18:59:55 +01:00
Matthias Krüger
f54dbe6e31 Revert "Remove #[alloc_error_handler] from the compiler and library"
This reverts commit abc0660118.
2023-04-25 00:08:35 +02:00
bors
39cf520299 Auto merge of #109507 - Amanieu:panic-oom-payload, r=davidtwco
Report allocation errors as panics

OOM is now reported as a panic but with a custom payload type (`AllocErrorPanicPayload`) which holds the layout that was passed to `handle_alloc_error`.

This should be review one commit at a time:
- The first commit adds `AllocErrorPanicPayload` and changes allocation errors to always be reported as panics.
- The second commit removes `#[alloc_error_handler]` and the `alloc_error_hook` API.

ACP: https://github.com/rust-lang/libs-team/issues/192

Closes #51540
Closes #51245
2023-04-22 12:27:45 +00:00
DrMeepster
511e457c4b offset_of 2023-04-21 02:14:02 -07:00
Amanieu d'Antras
abc0660118 Remove #[alloc_error_handler] from the compiler and library 2023-04-16 08:35:50 -07:00
clubby789
64f7597776 Migrate most of rustc_builtin_macros to diagnostic impls
Co-authored-by: Joe ST <joe@fbstj.net>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-04-10 21:16:53 +01:00
est31
7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00