Commit Graph

25342 Commits

Author SHA1 Message Date
James Farrell
c59b82353d Better diagnostics for dlltool errors.
When dlltool fails, show the full command that was executed. In
particular, llvm-dlltool is not very helpful, printing a generic usage
message rather than what actually went wrong, so stdout and stderr
aren't of much use when troubleshooting.
2023-07-17 20:20:01 +00:00
bors
4bd4e2ea82 Auto merge of #112386 - loongarch-rs:reloc-static, r=eholk
loongarch64-unknown-none*: Set default relocation model to static

This PR sets the default relocation model to `static` for `loongarch64-unknown-none*` targets. This change aims to streamline the development of the bare-metal project by removing the need for the executable program loader to implement relocation.
2023-06-13 09:13:03 +00:00
Matthias Krüger
b7706e891d
Rollup merge of #111885 - compiler-errors:rust-call-abi-sized, r=eholk
Don't ICE on unsized `extern "rust-call"` call

Conceptually builds on #111864, but doesn't depend on it.
2023-06-13 07:02:28 +02:00
Matthias Krüger
9cb785b9d3
Rollup merge of #112546 - lcnr:opaque-type-cleanup, r=compiler-errors
new solver: extend assert to other aliases
2023-06-12 17:44:39 +02:00
Matthias Krüger
8475a88d67
Rollup merge of #112416 - jieyouxu:issue-112363, r=wesleywiser
Fix debug ICE for extern type with where clauses

Fixes #112363.
2023-06-12 17:44:38 +02:00
Matthias Krüger
a5245b5894
Rollup merge of #112302 - jieyouxu:issue-85184, r=WaffleLapkin
Suggest using `ptr::null_mut` when user provided `ptr::null` to a function expecting `ptr::null_mut`

```
error[E0308]: mismatched types
  --> $DIR/ptr-null-mutability-suggestions.rs:9:24
   |
LL |     expecting_null_mut(ptr::null());
   |     ------------------ ^^^^^^^^^^^
   |     |                  |
   |     |                  types differ in mutability
   |     |                  help: consider using `core::ptr::null_mut` instead: `core::ptr::null_mut()`
   |     arguments to this function are incorrect
   |
   = note: expected raw pointer `*mut u8`
              found raw pointer `*const _`
note: function defined here
  --> $DIR/ptr-null-mutability-suggestions.rs:6:4
   |
LL | fn expecting_null_mut(_: *mut u8) {}
   |    ^^^^^^^^^^^^^^^^^^ ----------
```

Closes #85184.
2023-06-12 17:44:37 +02:00
lcnr
e74d1cd581 update comment 2023-06-12 12:47:09 +02:00
lcnr
f45502d20d extend assert 2023-06-12 11:58:40 +02:00
许杰友 Jieyou Xu (Joe)
72421bfb0c
Fix debug ICE for extern type with where clauses 2023-06-12 15:15:45 +08:00
bors
fd0a3313f7 Auto merge of #112261 - jieyouxu:c-like-ptr-arithmetics-diagnostics, r=WaffleLapkin
Add help for trying to do C-like pointer arithmetics

This PR adds help messages for these cases:

```rust
fn main() {
    let ptr1: *const u32 = std::ptr::null();
    let ptr2: *const u32 = std::ptr::null();
    let a = ptr1 + 5;
    let b = ptr1 - 5;
    let c = ptr2 - ptr1;
    let d = ptr1[5];
}
```

### Current Output

```
error[E0369]: cannot add `{integer}` to `*const u32`
 --> tests/ui/typeck/issue-112252-ptr-arithmetics-help.rs:4:18
  |
4 |     let a = ptr1 + 5; //~ ERROR cannot add
  |             ---- ^ - {integer}
  |             |
  |             *const u32

error[E0369]: cannot subtract `{integer}` from `*const u32`
 --> tests/ui/typeck/issue-112252-ptr-arithmetics-help.rs:5:18
  |
5 |     let b = ptr1 - 5; //~ ERROR cannot subtract
  |             ---- ^ - {integer}
  |             |
  |             *const u32

error[E0369]: cannot subtract `*const u32` from `*const u32`
 --> tests/ui/typeck/issue-112252-ptr-arithmetics-help.rs:6:18
  |
6 |     let c = ptr2 - ptr1; //~ ERROR cannot subtract
  |             ---- ^ ---- *const u32
  |             |
  |             *const u32

error[E0608]: cannot index into a value of type `*const u32`
 --> tests/ui/typeck/issue-112252-ptr-arithmetics-help.rs:7:13
  |
7 |     let d = ptr1[5]; //~ ERROR cannot index
  |             ^^^^^^^

error: aborting due to 4 previous errors
```

### Output After This PR

```
error[E0369]: cannot add `{integer}` to `*const u32`
  --> $DIR/issue-112252-ptr-arithmetics-help.rs:6:20
   |
LL |     let _a = _ptr1 + 5;
   |              ------^--
   |              |       |
   |              |       {integer}
   |              *const u32
   |              help: consider using `wrapping_add` or `add` for pointer + {integer}: `_ptr1.wrapping_add(5)`

error[E0369]: cannot subtract `{integer}` from `*const u32`
  --> $DIR/issue-112252-ptr-arithmetics-help.rs:7:20
   |
LL |     let _b = _ptr1 - 5;
   |              ------^--
   |              |       |
   |              |       {integer}
   |              *const u32
   |              help: consider using `offset` for pointer - {integer}: `unsafe { _ptr1.offset(-5) }`

error[E0369]: cannot subtract `*const u32` from `*const u32`
  --> $DIR/issue-112252-ptr-arithmetics-help.rs:8:20
   |
LL |     let _c = _ptr2 - _ptr1;
   |              ------^------
   |              |       |
   |              |       *const u32
   |              *const u32
   |              help: consider using `offset_from` for pointer - pointer if the pointers point to the same allocation: `_ptr2.offset_from(_ptr1)`

error[E0608]: cannot index into a value of type `*const u32`
  --> $DIR/issue-112252-ptr-arithmetics-help.rs:9:14
   |
LL |     let _d = _ptr1[5];
   |              ^^^^^^^^
   |
help: consider using `wrapping_add` or `add` for indexing into raw pointer
   |
LL |     let _d = _ptr1.wrapping_add(5);
   |              ~~~~~~~~~~~~~~~~~~~~~

error: aborting due to 4 previous errors
```

Closes #112252.
2023-06-12 07:15:19 +00:00
bors
77dba225c1 Auto merge of #111801 - Bryanskiy:lints1, r=petrochenkov
Private-in-public lints implementation

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
2023-06-11 22:18:23 +00:00
Bryanskiy
6d46382f6f Private-in-public lints implementation 2023-06-12 01:02:19 +03:00
Matthias Krüger
d9ae7180e4
Rollup merge of #112513 - compiler-errors:dont-compute-box-span-for-tait, r=cjgillot
Dont compute `opt_suggest_box_span` span for TAIT

Fixes #112434

Also a couple more commits on top, pruning some dead code and fixing another weird suggestion encountered in the above issue.
2023-06-11 18:38:28 +02:00
bors
34d64ab7a2 Auto merge of #112466 - lcnr:opaque-type-cleanup, r=compiler-errors
opaque type cleanup

the commits are pretty self-contained.

r? `@compiler-errors` cc `@oli-obk`
2023-06-11 03:42:14 +00:00
Michael Goulet
d80440263c Don't suggest boxing an empty if/else arm 2023-06-11 00:19:56 +00:00
Matthias Krüger
46b64aaef0
Rollup merge of #112498 - SamZhang3:rust-reference-link-update, r=Nilstrieb
Update links to Rust Reference in diagnostic

Instead of linking to the [old Rust Reference site](https://static.rust-lang.org/doc/master/reference.html#literals), which is severely outdated (Rust 1.17), link to the [current website](https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html) in diagnostic about incorrect literals.
2023-06-11 01:57:28 +02:00
Matthias Krüger
e9666d4d85
Rollup merge of #112493 - fmease:iat-select-complete-bound-var-erasure, r=compiler-errors
iat selection: normalize self ty & completely erase bound vars

Erase bound vars (most notably late-bound regions) irrespective of their binding level instead of just at the innermost one.
Fixes #111404.
2023-06-11 01:57:27 +02:00
Matthias Krüger
e19a509f8f
Rollup merge of #112475 - chenyukang:yukang-fix-112278, r=compiler-errors
Fix issue for module name when surround the struct literal with parentheses

Fixes #112278
2023-06-11 01:57:25 +02:00
Michael Goulet
5dfc17f045 prune some unused code 2023-06-10 23:36:55 +00:00
Michael Goulet
e49b4625df Don't compute opt_suggest_box_span for TAIT 2023-06-10 23:21:38 +00:00
León Orell Valerian Liehr
a995255cf5
iat selection: normalize self ty & completely erase bound vars 2023-06-11 00:19:47 +02:00
Hankai Zhang
6336da9a75 Use a better link 2023-06-10 14:46:11 -04:00
Hankai Zhang
e5fccf927d Update links to Rust Reference page on literals in diagnostic
Instead of linking to the old Rust Reference site on static.rust-lang.org,
link to the current website doc.rust-lang.org/stable/reference instead in
diagnostic about incorrect literals.
2023-06-10 12:34:16 -04:00
bors
ef8ee73fc4 Auto merge of #112494 - matthiaskrgr:rollup-xdf3om8, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #112297 (bootstrap: Disallow `--exclude test::std`)
 - #112298 (Update field-offset and enable unstable_offset_of)
 - #112335 (ci: Upgrade loongarch64-linux-gnu GCC to 13.1.0)
 - #112413 (Adjust span labels for `HIDDEN_GLOB_REEXPORTS`)
 - #112483 (Add deprecation warning to python versions <3.6 in x.py)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-10 15:49:43 +00:00
Matthias Krüger
312e676333
Rollup merge of #112413 - jieyouxu:fix-hidden-glob-reexports-span-order, r=petrochenkov
Adjust span labels for `HIDDEN_GLOB_REEXPORTS`

Addresses https://github.com/rust-lang/rust/pull/111378#issuecomment-1581226063.

### Before This PR

The possibility that the private item comes before the glob re-export was not account for, causing the span label messages to say "but private item here shadows it" before "the name `Foo` in the type namespace is supposed to be publicly re-exported here".

### After This PR

```rust
warning: private item shadows public glob re-export
  --> $DIR/hidden_glob_reexports.rs:9:5
   |
LL |     struct Foo;
   |     ^^^^^^^^^^^ the private item here shadows the name `Foo` in the type namespace
...
LL |     pub use self::inner::*;
   |             -------------- but it is supposed to be publicly re-exported here
   |
   = note: `#[warn(hidden_glob_reexports)]` on by default

warning: private item shadows public glob re-export
  --> $DIR/hidden_glob_reexports.rs:27:9
   |
LL |     pub use self::inner::*;
   |             -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here
LL |
LL |     use self::other::Foo;
   |         ^^^^^^^^^^^^^^^^ but the private item here shadows it
```
2023-06-10 15:24:44 +02:00
Matthias Krüger
e3656ff9fd
Rollup merge of #112298 - est31:update_field_offset, r=Mark-Simulacrum
Update field-offset and enable unstable_offset_of

This makes the compiler use the builtin `offset_of!()` macro, through the wrappers in memoffset and then in field-offset.

cc  #111839
2023-06-10 15:24:43 +02:00
bors
788c98df59 Auto merge of #111818 - Urgau:uplift_cmp_nan, r=cjgillot
Uplift `clippy::cmp_nan` lint

This PR aims at uplifting the `clippy::cmp_nan` lint into rustc.

## `invalid_nan_comparisons`

~~(deny-by-default)~~ (warn-by-default)

The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN` as one of the operand.

### Example

```rust,compile_fail
let a = 2.3f32;
if a == f32::NAN {}
```

### Explanation

NaN does not compare meaningfully to anything – not even itself – so those comparisons are always false.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler
2023-06-10 12:47:51 +00:00
Matthias Krüger
3189ce630d
Rollup merge of #112369 - nnethercote:more-cgu-cleanups, r=wesleywiser
More CGU cleanups

An assortment of improvements.

r? `@wesleywiser`
2023-06-10 11:20:09 +02:00
Matthias Krüger
2baebad063
Rollup merge of #110141 - petrochenkov:cratecfg2, r=WaffleLapkin
expand: Change how `#![cfg(FALSE)]` behaves on crate root

Previously it removed all other attributes from the crate root.
Now it removes only attributes below itself (during both regular expansion and pre-configuration).

So it becomes possible to configure some global crate properties even for fully unconfigured crates.

Fixes https://github.com/rust-lang/rust/issues/104633
Part of https://github.com/rust-lang/rust/issues/110082
2023-06-10 11:20:09 +02:00
Urgau
3e91349c42 Uplift improved version of clippy::cmp_nan to rustc 2023-06-10 11:12:55 +02:00
许杰友 Jieyou Xu (Joe)
80176a120e
Adjust span labels for HIDDEN_GLOB_REEXPORTS 2023-06-10 17:11:38 +08:00
bors
d0ee1908ed Auto merge of #112452 - MU001999:fix/issue-112439, r=petrochenkov
Make "consider importing" consistent for macros

Fixes #112439
2023-06-10 05:07:53 +00:00
yukang
f54e75730b remove unwrap 2023-06-10 10:34:19 +08:00
bors
29611778b7 Auto merge of #112426 - Bryanskiy:full_priv_ev, r=petrochenkov
increase the accuracy of effective visibilities calculation

Effective visibilities are calculated lazily due to performance restrictions.  Therefore

- crate should be walked at least 1 time in `compute_effective_visibilities` pass
- Impl's should always be in the effective visibilities table

to ensure that the table is filled in correctly.

r? `@petrochenkov`
2023-06-10 02:16:24 +00:00
yukang
e3071eaa60 reword the message to suggest surrounding with parentheses 2023-06-10 06:28:35 +08:00
yukang
3983881d4e take care module name for suggesting surround the struct literal in parentheses 2023-06-10 06:28:35 +08:00
Vadim Petrochenkov
46becfdf9c expand: Change how #![cfg(FALSE)] behaves on crate root
Previously it removed all other attributes from the crate root.
Now it removes only attributes below itself.

So it becomes possible to configure some global crate properties even for fully unconfigured crates.
2023-06-10 00:35:21 +03:00
bors
43062c43d2 Auto merge of #112216 - est31:offset_of_deep_tuple, r=petrochenkov
Support float-like tuple indices in offset_of!()

Supports invocations like `offset_of!((((), ()), ()), 0.0)`. This `0.0` gets tokenized as float literal, so it has to be broken up again.

The code that did the breaking up was returning a finished `Expr`, while we need a `Ident`, so this PR splits up the `parse_expr_tuple_field_access_float` function into:

* a function that breaks up the float literal (similar to `TokenKind::break_two_token_op`, but we do access the parser during this splitting operation, so we keep it as an inherent function on the parser)
* and a function that constructs an `Expr` from it

The former we can then re-use in `offset_of` parsing. The edge cases especially involving whitespaces are tricky so this adds a bunch of new tests as well.

fixes #112204
2023-06-09 18:53:58 +00:00
Mu001999
5bd8ba8493 Make "consider importing" consistent for macros 2023-06-10 00:06:34 +08:00
Urgau
3681285df7 Add diagnostic items for f32::NAN and f64::NAN 2023-06-09 17:46:33 +02:00
bors
397641f3bd Auto merge of #112465 - GuillaumeGomez:rollup-gyh5buc, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #112260 (Improve document of `unsafe_code` lint)
 - #112429 ([rustdoc] List matching impls on type aliases)
 - #112442 (Deduplicate identical region constraints in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-09 15:37:22 +00:00
lcnr
b62e20d2fd split opaque type handling in new solver
be more explicit in where we only add new hidden types
and where we also have to deal with item bounds.
2023-06-09 16:41:11 +02:00
Guillaume Gomez
4ef7257018
Rollup merge of #112442 - compiler-errors:next-solver-deduplicate-region-constraints, r=lcnr
Deduplicate identical region constraints in new solver

the new solver doesn't track whether we've already proven a goal like the fulfillment context's obligation forest does, so we may be instantiating a canonical response (and specifically, its nested region obligations) quite a few times.

This may lead to exponentially gathering up identical region constraints for things like auto traits, so let's deduplicate region constraints when in `compute_external_query_constraints`.

r? ``@lcnr``
2023-06-09 16:29:02 +02:00
Guillaume Gomez
a7f46af369
Rollup merge of #112260 - eval-exec:exec/fix-unsafe_code_lint, r=WaffleLapkin
Improve document of `unsafe_code` lint

This PR add another `unsafe_code` lint example, want to close #111967
2023-06-09 16:29:01 +02:00
lcnr
669d609dfd extract opaque type wf check into separate fn 2023-06-09 16:04:41 +02:00
lcnr
2278365889 recompute opaque type origin 2023-06-09 14:48:45 +02:00
bors
d7ad9d9797 Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errors
Uplift `clippy::undropped_manually_drops` lint

This PR aims at uplifting the `clippy::undropped_manually_drops` lint.

## `undropped_manually_drops`

(warn-by-default)

The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop.

### Example

```rust
struct S;
drop(std::mem::ManuallyDrop::new(S));
```

### Explanation

`ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either.

-----

Mostly followed the instructions for uplifting an clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-09 12:44:23 +00:00
Eval EXEC
30f84c4d17
Improve document of unsafe_code lint
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-09 20:41:18 +08:00
许杰友 Jieyou Xu (Joe)
432ce39c8b
Suggest using ptr::null_mut when user supplied ptr::null to a function expecting ptr::null_mut 2023-06-09 20:05:46 +08:00
bors
343ad6f059 Auto merge of #111626 - pjhades:output, r=b-naber
Write to stdout if `-` is given as output file

With this PR, if `-o -` or `--emit KIND=-` is provided, output will be written to stdout instead. Binary output (those of type `obj`, `llvm-bc`, `link` and `metadata`) being written this way will result in an error unless stdout is not a tty. Multiple output types going to stdout will trigger an error too, as they will all be mixded together.

This implements https://github.com/rust-lang/compiler-team/issues/431

The idea behind the changes is to introduce an `OutFileName` enum that represents the output - be it a real path or stdout - and to use this enum along the code paths that handle different output types.
2023-06-09 09:45:40 +00:00