Commit graph

2870 commits

Author SHA1 Message Date
Matthias Krüger
67f77f5a55
Rollup merge of #100709 - JhonnyBillM:port-expected-used-symbol-diagnostic, r=compiler-errors
Migrate typeck's `used` expected symbol diagnostic to `SessionDiagnostic`

r? ``@davidtwco``
2022-08-20 07:09:02 +02:00
Dylan DPC
490d04bfbc
Rollup merge of #100598 - ouz-a:91633, r=compiler-errors
Don't fix builtin index when Where clause is found

Where clause shadows blanket impl for `Index` which causes normalization to not occur, which causes ICE to happen when we typeck.

r? `@compiler-errors`

Fixes #91633
2022-08-19 12:26:45 +05:30
Dylan DPC
078844283c
Rollup merge of #99576 - compiler-errors:foreign-fundamental-drop-is-bad, r=TaKO8Ki
Do not allow `Drop` impl on foreign fundamental types

`Drop` should not be implemented on `Pin<T>` even if `T` is local.

This does not trigger regular orphan rules is because `Pin` is `#[fundamental]`... but we don't allow specialized `Drop` impls anyways, so these rules are not sufficient to prevent this impl on stable. Let's just choose even stricter rules, since we shouldn't be implementing `Drop` on a foreign ADT ever.

Fixes #99575
2022-08-19 12:26:38 +05:30
Jhonny Bill Mena
af4f66ef93 ADD - ExpectedUsedSymbol diagnostic to port used() diagnostic 2022-08-18 08:18:26 -04:00
Matthias Krüger
3de034d401
Rollup merge of #100674 - PragmaTwice:mig-typeck-unused-crate-diag, r=davidtwco
Migrate lint reports in typeck::check_unused to LintDiagnostic

In this PR, I migrate two lint reports in `typeck::check_unused` by `LintDiagnostic`, all of which is about extern crates.

```@rustbot``` label +A-translation
r? rust-lang/diagnostics
2022-08-18 05:10:50 +02:00
Matthias Krüger
370bf1543d
Rollup merge of #97962 - eholk:drop-tracking-must-not-suspend, r=cjgillot
Make must_not_suspend lint see through references when drop tracking is enabled

See #97333.

With drop tracking enabled, sometimes values that were previously linted are now considered dropped and not linted. This change makes must_not_suspend traverse through references to still catch these values.

Unfortunately, this leads to duplicate warnings in some cases (e.g. [dedup.rs](9a74608543/src/test/ui/lint/must_not_suspend/dedup.rs (L4))), so we only use the new behavior when drop tracking is enabled.

cc ``@guswynn``
2022-08-18 05:10:41 +02:00
PragmaTwice
9efe979511 remove #[primary_span] 2022-08-17 22:08:06 +08:00
Twice
52418d661b
use suggestion_short in LintDiagnostic
Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
2022-08-17 20:45:18 +08:00
Matthias Krüger
6eed54a2c9
Rollup merge of #100652 - compiler-errors:no-defer-sized-checks, r=TaKO8Ki
Remove deferred sized checks (make them eager)

Improves diagnostics spans... this doesn't seem to be the case anymore:

```rust
// Some additional `Sized` obligations badly affect type inference.
// These obligations are added in a later stage of typeck.
pub(super) deferred_sized_obligations:
        RefCell<Vec<(Ty<'tcx>, Span, traits::ObligationCauseCode<'tcx>)>>,
```
2022-08-17 12:32:57 +02:00
PragmaTwice
98fb65eff9 Migrate lint reports in typeck::check_unused to LintDiagnostic 2022-08-17 17:47:44 +08:00
ouz-a
7b45718484 pass when where clause found 2022-08-17 12:25:52 +03:00
Michael Goulet
33212bf7f5 Remove deferred sized checks 2022-08-16 22:30:56 +00:00
bors
86c6ebee8f Auto merge of #100644 - TaKO8Ki:rollup-n0o6a1t, r=TaKO8Ki
Rollup of 4 pull requests

Successful merges:

 - #100243 (Remove opt_remap_env_constness from rustc_query_impl)
 - #100625 (Add `IpDisplayBuffer` helper struct.)
 - #100629 (Use `merged_ty` method instead of rewriting it every time)
 - #100630 (rustdoc JSON: Fix ICE with `pub extern crate self as <self_crate_name>`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-16 21:10:08 +00:00
Guillaume Gomez
1f7d1eae96 Use merged_ty method instead of rewriting it every time 2022-08-16 15:33:46 +02:00
Dylan DPC
cf5c7645ac
Rollup merge of #100609 - chenyukang:fix-100527, r=davidtwco
Extend invalid floating point literal suffix suggestion

Fixes #100527
2022-08-16 18:16:12 +05:30
yukang
89a51a1a48 use proper words in help message for floating point 2022-08-16 19:12:36 +08:00
Matthias Krüger
76dd1663d9
Rollup merge of #100590 - TaKO8Ki:suggest-adding-array-length, r=compiler-errors
Suggest adding an array length if possible

fixes #100448
2022-08-16 06:05:59 +02:00
Matthias Krüger
836f706d9a
Rollup merge of #100338 - lyming2007:issue-100285-fix, r=petrochenkov
when there are 3 or more return statements in the loop

emit the first 3 errors and duplicated diagnostic information
	modified:   compiler/rustc_typeck/src/check/coercion.rs
	new file:   src/test/ui/typeck/issue-100285.rs
	new file:   src/test/ui/typeck/issue-100285.stderr
2022-08-16 06:05:55 +02:00
yukang
84629a5ab1 Extend invalid floating point literal suffix suggestion 2022-08-16 10:50:04 +08:00
Michael Goulet
fd934c99bc Do not allow Drop impl on foreign fundamental types 2022-08-16 00:59:06 +00:00
Yiming Lei
0471e2780f when there are 3 or more return statements in the loop
emit the first 3 errors and duplicated diagnostic information
using take of iterator for the first third return
	modified:   compiler/rustc_typeck/src/check/coercion.rs
	new file:   src/test/ui/typeck/issue-100285.rs
	new file:   src/test/ui/typeck/issue-100285.stderr
2022-08-15 13:31:14 -07:00
Takayuki Maeda
12e609ba3c use span_suggestion instead of span_suggestion_verbose 2022-08-16 03:42:58 +09:00
bors
9b4ea391a1 Auto merge of #100569 - matthiaskrgr:rollup-9450lzs, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #100211 (Refuse to codegen an upstream static.)
 - #100277 (Simplify format_args builtin macro implementation.)
 - #100483 (Point to generic or arg if it's the self type of unsatisfied projection predicate)
 - #100506 (change `InlineAsmCtxt` to not talk about `FnCtxt`)
 - #100534 (Make code slightly more uniform)
 - #100566 (Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-15 15:25:31 +00:00
Takayuki Maeda
4d1b5f0d99 suggest adding an array length if possible 2022-08-16 00:16:14 +09:00
Matthias Krüger
a5cdb6566b
Rollup merge of #100506 - lcnr:fnctxt-yeet, r=compiler-errors
change `InlineAsmCtxt` to not talk about `FnCtxt`

wip for https://github.com/rust-lang/compiler-team/issues/529. this currently uses both the `FnCtxt` and is used by `check_mod_item_types`. This should be the only thing blocking that MCP afaict.

I am still unsure whether `rustc_hir_typeck` should depend on `rustc_hir_analysis` to use the `InlineAsmCtxt`. I think that's the best solution for now, so that's what I will go for

r? `@compiler-errors`
2022-08-15 10:28:12 +02:00
Matthias Krüger
ee63d09bd6
Rollup merge of #100483 - compiler-errors:point-to-projection-too, r=jyn514
Point to generic or arg if it's the self type of unsatisfied projection predicate

We do this for `TraitPredicate`s in `point_at_type_arg_instead_of_call_if_possible` and `point_at_arg_instead_of_call_if_possible`, so also do it for `ProjectionPredicate`.

Improves spans for a lot of unit tests.
2022-08-15 10:28:11 +02:00
bors
6ce76091c7 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
Michael Goulet
54edf1863e Also do it for generics 2022-08-14 20:22:10 +00:00
Michael Goulet
16b33cc1e3 Point to argument if it's self type of unsatisfied projection predicate 2022-08-14 20:22:10 +00:00
Michael Goulet
75dfe55a5d TypeError can be Copy 2022-08-14 19:58:46 +00:00
Dylan DPC
9de9786ef8
Rollup merge of #100487 - tmiasko:assert-safe, r=petrochenkov
`assert_{inhabited,zero_valid,uninit_valid}` intrinsics are safe

Those intrinsics either panic or do nothing. They are safe.
2022-08-14 17:09:17 +05:30
Dylan DPC
a9f3e0393a
Rollup merge of #99582 - compiler-errors:issue-99566, r=cjgillot
Delay a span bug if we see ty/const generic params during writeback

Fixes #99566
2022-08-14 17:09:12 +05:30
Michael Goulet
b3e76aa491
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
Argument type error improvements

Motivated by this interesting code snippet:

```rust
#[derive(Copy, Clone)]
struct Wrapper<T>(T);

fn foo(_: fn(i32), _: Wrapper<i32>) {}

fn f(_: u32) {}

fn main() {
    let w = Wrapper::<isize>(1isize);
    foo(f, w);
}
```

Which currently errors like:
```
error[E0308]: arguments to this function are incorrect
  --> src/main.rs:10:5
   |
10 |     foo(f, w);
   |     ^^^ -  - expected `i32`, found `isize`
   |         |
   |         expected `i32`, found `u32`
   |
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> src/main.rs:4:4
   |
4  | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------
```

Specifically, that double `expected .. found ..` which is very difficult to correlate to the types in the arguments. Also, the fact that "expected `i32`, found `isize`" and the other argument mismatch label don't even really explain what's going on here.

After this PR:
```
error[E0308]: arguments to this function are incorrect
  --> $DIR/two-mismatch-notes.rs:10:5
   |
LL |     foo(f, w);
   |     ^^^
   |
note: expected fn pointer, found fn item
  --> $DIR/two-mismatch-notes.rs:10:9
   |
LL |     foo(f, w);
   |         ^
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
note: expected struct `Wrapper`, found a different struct `Wrapper`
  --> $DIR/two-mismatch-notes.rs:10:12
   |
LL |     foo(f, w);
   |            ^
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> $DIR/two-mismatch-notes.rs:4:4
   |
LL | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------

error: aborting due to previous error

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

Yeah, it's a bit verbose, but much clearer IMO.

---

Open to discussions about how this could be further improved. Motivated by `@jyn514's` [tweet](https://mobile.twitter.com/joshuayn514/status/1558042020601634816) here.
2022-08-13 21:06:53 -07:00
Michael Goulet
2af344595a
Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-label, r=estebank
Only point out a single function parameter if we have a single arg incompatibility

Fixes #99635
2022-08-13 21:06:46 -07:00
Michael Goulet
b0cd1e192c Label argument coercion errors 2022-08-13 18:24:36 +00:00
lcnr
1137fffe28 change InlineAsmCtxt to not talk about FnCtxt 2022-08-13 19:58:39 +02:00
Tomasz Miąsko
6b19a48e70 assert_{inhabited,zero_valid,uninit_valid} intrinsics are safe
Those intrinsics either panic or do nothing. They are safe.
2022-08-13 00:00:00 +00:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Michael Goulet
c6089189b3 Address nit 2022-08-12 15:35:27 +00:00
Michael Goulet
262644d94a And for closures 2022-08-12 15:18:40 +00:00
Michael Goulet
20121fa781 Point out a single arg if we have a single arg incompatibility 2022-08-12 15:18:39 +00:00
Dylan DPC
caac670a16
Rollup merge of #100247 - cjgillot:verify-dyn-trait-alias-defaults, r=lcnr
Generalize trait object generic param check to aliases.

The current algorithm only checks that `Self` does not appear in defaults for traits.  This is not sufficient for trait aliases.
This PR moves the check to trait object elaboration, which sees through trait aliases.

Fixes https://github.com/rust-lang/rust/issues/82927.
Fixes https://github.com/rust-lang/rust/issues/84789.
2022-08-12 20:39:12 +05:30
Eric Huss
1c70b8669a Fix diagnostic that was looking for a PatKind::Struct
Now that fields are first-class HIR nodes, they appear before the struct pat.
2022-08-11 21:48:39 -07:00
Eric Huss
7b36047239 Make Node::ExprField a child of Node::Expr.
This was incorrectly inserting the ExprField as a sibling of the struct
expression.

This required adjusting various parts which were looking at parent node
of a field expression to find the struct.
2022-08-11 21:48:39 -07:00
Eric Huss
b651c1cebe Check attributes on struct expression fields.
Attributes on struct expression fields were not being checked for
validity. This adds the fields as HIR nodes so that `CheckAttrVisitor`
can visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Eric Huss
1b464c73b7 Check attributes on pattern fields.
Attributes on pattern struct fields were not being checked for validity.
This adds the fields as HIR nodes so that the `CheckAttrVisitor` can
visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Dylan DPC
b5f5bdce87
Rollup merge of #100351 - compiler-errors:diagnostic-convention, r=fee1-dead
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed

This seems to be the established convention (02ff9e0) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2022-08-11 22:47:03 +05:30
Dylan DPC
dfddc2f918
Rollup merge of #92744 - lambinoo:I-91161-non-exhaustive-foreign-variants, r=scottmcm
Check if enum from foreign crate has any non exhaustive variants when attempting a cast

Fixes #91161

As stated in the issue, this will require a crater run as it might break other people's stuff.
2022-08-11 22:46:56 +05:30
Scott McMurray
dfb3713cdb Update error message to clarify that it's not the enum itself that's non_exhaustive 2022-08-10 10:02:03 -07:00
Lamb
a3b84ad197 Check if extern crate enum has non exhaustive variant when cast 2022-08-10 09:55:41 -07:00