Commit graph

137 commits

Author SHA1 Message Date
Lukas Markeffsky e330fe9c21 don't skip coercions for types with errors 2024-02-10 23:13:47 +01:00
Ralf Jung 4e77e368eb unstably allow constants to refer to statics and read from immutable statics 2024-02-10 16:12:55 +01:00
Oli Scherer eab2adb660 Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
bors 870a01a30e Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebank
Stop bailing out from compilation just because there were incoherent traits

fixes #120343

but also has a lot of "type annotations needed" fallout. Some are fixed in the second commit.
2024-02-08 05:01:09 +00:00
Matthias Krüger 3c52832375
Rollup merge of #119939 - clubby789:static-const-generic-note, r=compiler-errors
Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items

Fixes #109596
Fixes #119936
2024-02-06 22:45:39 +01:00
Oli Scherer 83738a9b1c Stop bailing out from compilation just because there were incoherent traits 2024-02-05 10:17:31 +00:00
Matthias Krüger 7fa99bfb71
Rollup merge of #120556 - fmease:improve-unused-generic-param-diags, r=oli-obk
Improve the diagnostics for unused generic parameters

* Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases
* Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense
* Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable
  * Still keep the error codes distinct (for now)
  * Naturally leads to better diagnostics for E0091

r? ```@oli-obk``` (to ballast your review load :P) or compiler
2024-02-04 19:42:12 +01:00
León Orell Valerian Liehr 02320b502d
Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
Esteban Küber 6efddac288 Provide more context on derived obligation error primary label
Expand the primary span of E0277 when the immediate unmet bound is not what the user wrote:

```
error[E0277]: the trait bound `i32: Bar` is not satisfied
 --> f100.rs:6:6
  |
6 |     <i32 as Foo>::foo();
  |      ^^^ the trait `Bar` is not implemented for `i32`, which is required by `i32: Foo`
  |
help: this trait has no implementations, consider adding one
 --> f100.rs:2:1
  |
2 | trait Bar {}
  | ^^^^^^^^^
note: required for `i32` to implement `Foo`
 --> f100.rs:3:14
  |
3 | impl<T: Bar> Foo for T {}
  |         ---  ^^^     ^
  |         |
  |         unsatisfied trait bound introduced here
```

Fix #40120.
2024-01-30 21:28:18 +00:00
Esteban Küber a9841936fe Deduplicate more sized errors on call exprs
Change the implicit `Sized` `Obligation` `Span` for call expressions to
include the whole expression. This aids the existing deduplication
machinery to reduce the number of errors caused by a single unsized
expression.
2024-01-24 02:53:15 +00:00
clubby789 2cfc81766c Special case 'generic param from outer item' message for Self 2024-01-14 12:31:34 +00:00
George-lewis d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Oli Scherer 55cab535e7 Taint more aggressively in astconv 2024-01-11 09:03:26 +00:00
bors 94807670a6 Auto merge of #117449 - oli-obk:query_merge_immobile_game, r=matthewjasper
Avoid silencing relevant follow-up errors

r? `@matthewjasper`

This PR only adds new errors to tests that are already failing and fixes one ICE.

Several tests were changed to not emit new errors. I believe all of them were faulty tests, and not explicitly testing for the code that had new errors.
2024-01-09 22:50:49 +00:00
Oli Scherer 0978f6e010 Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
Obei Sideg a8aa6878f6 Update test for E0796 and static_mut_ref lint 2024-01-07 17:29:25 +03:00
Matthew Jasper 26f48b4cba Stabilize THIR unsafeck 2024-01-05 10:00:59 +00:00
Matthew Jasper 982b49494e Remove revisions for THIR unsafeck
This is to make the diff when stabilizing it easier to review.
2024-01-05 09:30:27 +00:00
Martin Nordholts 741884dab2 rustc_lint: Prevent multiple 'incompatible with previous forbid' lints 2023-12-28 19:46:40 +01:00
Veera 286f2d819e Update existing tests 2023-12-20 22:53:56 -05:00
Michael Goulet ad00641b74 Collect lang items from AST 2023-12-15 16:12:27 +00:00
lcnr 11d16c4082 update use of feature flags 2023-12-14 15:22:37 +01:00
Eric Huss f481596ee4 Remove edition umbrella features. 2023-12-10 13:03:28 -08:00
León Orell Valerian Liehr 55559d93e7
Resolve assoc item bindings by namespace
If a const is expected, resolve a const.
If a type is expected, resolve a type.
Don't try to resolve a type first falling back to consts.
2023-12-07 22:33:56 +01:00
Michael Goulet b97ff8eb16 Add print_trait_sugared 2023-12-05 17:15:46 +00:00
zetanumbers f7617c1cd4 Enable link-arg link kind inside of #[link] attribute
- Implement link-arg as an attribute
- Apply suggestions from review
  - Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
- Add unstable book entry
2023-11-30 08:26:13 -08:00
bors 37b2813a7b Auto merge of #118138 - Nilstrieb:one-previous-error, r=WaffleLapkin
Fixes error count display is different when there's only one error left

Supersedes #114759

### What did I do?

I did the small change in `rustc_errors` by hand. Then I did the other changes in `/compiler` by hand, those were just find replace on `*.rs` in the workspace. The changes in run-make are find replace for `run-make` in the workspace.

All other changes are blessed using `x test TEST --bless`. I blessed the tests that were blessed in #114759.

### how to review this nightmare

ping bors with an `r+`. You should check that my logic is sound and maybe quickly scroll through the diff, but fully verifying it seems fairly hard to impossible. I did my best to do this correctly.

Thank you `@adrianEffe` for bringing this up and your initial implementation.

cc `@flip1995,` you said you want to do a subtree sync asap
cc `@RalfJung` maybe you want to do a quick subtree sync afterwards as well for Miri

r? `@WaffleLapkin`
2023-11-24 21:40:54 +00:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
lcnr d51ef5c1af fix intercrate ambiguity causes 2023-11-23 12:25:41 +00:00
Esteban Küber 4f7dddd4a1 recover primary span label 2023-11-16 17:00:23 +00:00
Esteban Küber 8bd8f3b090 Suggest unwrap() on field not found for Result/Option
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field
that's being accessed, suggest calling `.unwrap()` to get to the field.
2023-11-16 17:00:23 +00:00
Esteban Küber dfa75391f8 Suggest field typo through derefs
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-16 17:00:23 +00:00
Takayuki Maeda 9b9ea77641
Rollup merge of #117343 - Nadrieril:cleanup_check_match, r=davidtwco
Cleanup `rustc_mir_build/../check_match.rs`

The file had become pretty unwieldy, with a fair amount of duplication. As a bonus, I discovered that we weren't running some pattern checks in if-let chains.

I recommend looking commit-by-commit. The last commit is a whim, I think it makes more sense that way but I don't hold this opinion strongly.
2023-11-04 12:44:44 +09:00
Nicholas Nethercote 5c462a32bd Remove support for compiler plugins.
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
2023-11-04 08:50:46 +11:00
Nadrieril 746197c08a Tweak spans for "adt defined here" note 2023-11-03 18:26:16 +01:00
Esteban Küber 17a6ae2df3 Detect object safety errors when assoc type is missing
When an associated type with GATs isn't specified in a `dyn Trait`, emit
an object safety error instead of only complaining about the missing
associated type, as it will lead the user down a path of three different
errors before letting them know that what they were trying to do is
impossible to begin with.

Fix #103155.
2023-10-30 22:12:07 +00:00
Camille GILLOT ec28dc7aa7 Use PlaceMention for match scrutinees. 2023-10-24 15:30:17 +00:00
Matthias Krüger 31865b7bfb
Rollup merge of #116992 - estebank:issue-69492, r=oli-obk
Mention the syntax for `use` on `mod foo;` if `foo` doesn't exist

Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`.

Fix #69492.
2023-10-21 21:23:01 +02:00
Esteban Küber 2cca435717 Mention the syntax for use on mod foo; if foo doesn't exist
Newcomers might get confused that `mod` is the only way of defining
scopes, and that it can be used as if it were `use`.

Fix #69492.
2023-10-21 15:56:01 +00:00
Oli Scherer 60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Esteban Küber 890e92feed Unify suggestion wording 2023-10-17 17:33:55 +00:00
Ralf Jung b1ebf002c3 don't UB on dangling ptr deref, instead check inbounds on projections 2023-10-15 18:12:46 +02:00
bors 71704c4f84 Auto merge of #116623 - Nadrieril:validate-range-endpoints, r=oli-obk
Fix overflow checking in range patterns

When a range pattern contains an overflowing literal, if we're not careful we might not notice the overflow and use the wrapped value. This makes for confusing error messages because linting against overflowing literals is only done in a later pass. So when a range is invalid we check for overflows to provide a better error.

This check didn't use to handle negative types; this PR fixes that. First commit adds tests, second cleans up without changing behavior, third does the fix.

EDIT: while I was at it, I fixed a small annoyance about the span of the overflow lint on negated literals.

Fixes https://github.com/rust-lang/rust/issues/94239
2023-10-11 10:07:19 +00:00
Nadrieril 1baf8bf54d Fix range overflow checking 2023-10-11 04:55:55 +02:00
bors 59edd67056 Auto merge of #116497 - compiler-errors:impl-span, r=cjgillot
Extend `impl`'s `def_span` to include its where clauses

Typically, we highlight the def-span of an impl in a diagnostic due to either:
1. coherence error
2. trait evaluation cycle
3. invalid implementation of built-in trait

I find that an impl's where clauses are very often required to understanding why these errors come about, which is unfortunate since where clauses may be located on different lines and don't show up in the error. This PR expands the def-span of impls to include these where clauses.

r? cjgillot since you've touched this code a while back to make some spans shorter, but you can also reassign to wg-diagnostics or compiler if you're busy or have no strong opinions.
2023-10-09 21:03:41 +00:00
Michael Goulet 592163fb71 Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
Ali MJ Al-Nasrawy a8830631b9 remove trailing dots 2023-10-08 10:06:17 +00:00
Ali MJ Al-Nasrawy 996ffcb718 always show and explain sub region 2023-10-08 09:59:51 +00:00
Ali MJ Al-Nasrawy 5be0b2283a improve the suggestion of generic_bound_failure 2023-10-08 09:56:57 +00:00
bors 94bc9c737e Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply

- When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s).
```
error[E0283]: type annotations needed
  --> $DIR/multiple-impl-apply.rs:34:9
   |
LL |     let y = x.into();
   |         ^     ---- type must be known at this point
   |
note: multiple `impl`s satisfying `_: From<Baz>` found
  --> $DIR/multiple-impl-apply.rs:14:1
   |
LL | impl From<Baz> for Bar {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl From<Baz> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^
   = note: required for `Baz` to implement `Into<_>`
help: consider giving `y` an explicit type
   |
LL |     let y: /* Type */ = x.into();
   |          ++++++++++++
```

- Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user.

- Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases.
```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/cross-return-site-inference.rs:38:16
   |
LL |     return Err(From::from("foo"));
   |                ^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     return Err(</* self type */ as From>::from("foo"));
   |                +++++++++++++++++++     +
```

Fix #88284.
2023-10-06 18:44:32 +00:00