Commit Graph

1608 Commits

Author SHA1 Message Date
Maybe Waffle
fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
Guillaume Gomez
de074242eb
Rollup merge of #111450 - compiler-errors:opaque-ty-key, r=oli-obk
Use `OpaqueTypeKey` in query response

Makes it a bit clearer that at least one of the types being returned from a canonical query is an opaque.
2023-05-20 15:37:23 +02:00
lcnr
3e4ed61c09 do not overwrite obligations 2023-05-18 15:00:30 +02:00
Nilstrieb
3e34be004e
Rollup merge of #111602 - tmiasko:erroneous-constant-used, r=oli-obk
Suppress "erroneous constant used" for constants tainted by errors

When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.

Fixes #110891.
2023-05-16 11:39:39 +02:00
Michael Goulet
a2678e15e5 Replace RelationDir with Variance 2023-05-15 17:00:16 +00:00
Michael Goulet
41501c7449 Rename super_relate_* to structurally_relate_* 2023-05-15 16:40:42 +00:00
Michael Goulet
6d0b6c0d2c Tweaks and a test 2023-05-15 16:40:42 +00:00
Michael Goulet
4ce2123ecc yeet ConstInferUnifier 2023-05-15 16:40:42 +00:00
Michael Goulet
c270b0a8a8 Simplify delegate 2023-05-15 16:40:42 +00:00
Michael Goulet
338e7642fb Combine TypeGeneralizer and Generalizer 2023-05-15 16:40:42 +00:00
bors
8d18c32b61 Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwU
Rename const error methods for consistency

renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods.

r? `@BoxyUwU`
2023-05-15 01:03:29 +00:00
Tomasz Miąsko
67f455afe1 Suppress "erroneous constant used" for constants tainted by errors
When constant evaluation fails because its MIR is tainted by errors,
suppress note indicating that erroneous constant was used, since those
errors have to be fixed regardless of the constant being used or not.
2023-05-15 00:00:00 +00:00
Michael Goulet
8e163f9dce Rename const error methods for consistency 2023-05-14 20:32:51 +00:00
Dylan DPC
6cb13585d0
Rollup merge of #110454 - oli-obk:limited_impl_trait_in_assoc_type, r=compiler-errors
Require impl Trait in associated types to appear in method signatures

This implements the limited version of TAIT that was proposed in https://github.com/rust-lang/rust/issues/107645#issuecomment-1477899536

Similar to `impl Trait` in return types, `impl Trait` in associated types may only be used within the impl block which it is a part of. To make everything simpler and forward compatible to getting desugared to a plain type alias impl trait in the future, we're requiring that any associated functions or constants that want to register hidden types must be using the associated type in their signature (type of the constant or argument/return type of the associated method. Where bounds mentioning the associated type are ignored).

We have preexisting tests checking that this works transitively across multiple associated types in situations like

```rust
impl Foo for Bar {
    type A = impl Trait;
    type B = impl Iterator<Item = Self::A>;
    fn foo() -> Self::B { ...... }
}
```
2023-05-13 11:05:32 +05:30
bors
077fc26f0a Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwco
Uplift `clippy::{drop,forget}_{ref,copy}` lints

This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints.

Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.

## `drop_ref` and `forget_ref`

The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value.

### Example

```rust
let mut lock_guard = mutex.lock();
std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
// still locked
operation_that_requires_mutex_to_be_unlocked();
```

### Explanation

Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended.

## `drop_copy` and `forget_copy`

The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait.

### Example

```rust
let x: i32 = 42; // i32 implements Copy
std::mem::forget(x) // A copy of x is passed to the function, leaving the
                    // original unaffected
```

### Explanation

Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation.

-----

Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-12 12:04:32 +00:00
Oli Scherer
4e92f761fe Use the opaque_types_defined_by query to cheaply check for whether a hidden type may be registered for an opaque type 2023-05-12 10:26:50 +00:00
Oli Scherer
f08b517597 Require impl Trait in associated types to appear in method signatures 2023-05-12 10:24:03 +00:00
Michael Goulet
6f27876f62 Use OpaqueTypeKey in query response 2023-05-10 23:41:06 +00:00
Urgau
d36e390d81 Remove and fix useless drop of reference 2023-05-10 19:36:01 +02:00
Kyle Matsuda
26dc139b37 add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_const 2023-05-09 16:22:50 -06:00
Michael Goulet
29ac429c9b
Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errors
Introduce `AliasKind::Inherent` for inherent associated types

Allows us to check (possibly generic) inherent associated types for well-formedness.
Type inference now also works properly.

Follow-up to #105961. Supersedes #108430.
Fixes #106722.
Fixes #108957.
Fixes #109768.
Fixes #109789.
Fixes #109790.

~Not to be merged before #108860 (`AliasKind::Weak`).~

CC `@jackh726`
r? `@compiler-errors`

`@rustbot` label T-types F-inherent_associated_types
2023-05-08 09:30:21 -07:00
bors
ea0c22ea4f Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum
enable `rust_2018_idioms` lint group for doctests

With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests.

Resolves #106086
Resolves #99144

Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-08 04:50:28 +00:00
bors
0dddad0dc5 Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillot
Support return-type bounds on associated methods from supertraits

Support `T: Trait<method(): Bound>` when `method` comes from a supertrait, aligning it with the behavior of associated type bounds (both equality and trait bounds).

The only wrinkle is that I have to extend `super_predicates_that_define_assoc_type` to look for *all* items, not just `AssocKind::Ty`. This will also be needed to support `feature(associated_const_equality)` as well, which is subtly broken when it comes to supertraits, though this PR does not fix those yet. There's a slight chance there's a perf regression here, in which case I guess I could split it out into a separate query.
2023-05-07 11:18:22 +00:00
ozkanonur
4e7c14fe9f enable rust_2018_idioms for doctests
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07 00:12:29 +03:00
Matthias Krüger
bcc9aa01b5
Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnr
Use fulfillment to check `Drop` impl compatibility

Use an `ObligationCtxt` to ensure that a `Drop` impl does not have stricter requirements than the ADT that it's implemented for, rather than using a `SimpleEqRelation` to (more or less) syntactically equate predicates on an ADT with predicates on an impl.

r? types

### Some background

The old code reads:

```rust
// An earlier version of this code attempted to do this checking
// via the traits::fulfill machinery. However, it ran into trouble
// since the fulfill machinery merely turns outlives-predicates
// 'a:'b and T:'b into region inference constraints. It is simpler
// just to look for all the predicates directly.
```

I'm not sure what this means, but perhaps in the 8 years since that this comment was written (cc #23638) it's gotten easier to process region constraints after doing fulfillment? I don't know how this logic differs from anything we do in the `compare_impl_item` module. Ironically, later on it says:

```rust
// However, it may be more efficient in the future to batch
// the analysis together via the fulfill (see comment above regarding
// the usage of the fulfill machinery), rather than the
// repeated `.iter().any(..)` calls.
```

Also:
* Removes `SimpleEqRelation` which was far too syntactical in its relation.
* Fixes #110557
2023-05-06 13:30:03 +02:00
lcnr
6691c4cdad forbid escaping bound vars in combine
removes the `CollectAllMismatches` in favor of a slightly
more manual approach.
2023-05-05 13:51:19 +02:00
Yuki Okushi
f5c50e3350
Rollup merge of #111132 - lcnr:nll-generalize, r=b-naber
cleanup nll generalizer

followup to #108861
2023-05-05 12:46:27 +09:00
Michael Goulet
964fb67a5f Use fulfillment to check Drop impl compatibility 2023-05-04 18:05:58 +00:00
León Orell Valerian Liehr
e8139dfd5a
IAT: Introduce AliasKind::Inherent 2023-05-04 16:59:10 +02:00
bors
6f8c0557e0 Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new`

First step in implementing https://github.com/rust-lang/compiler-team/issues/616
r? `@lcnr`
2023-05-04 05:54:09 +00:00
Michael Goulet
fef2f5b815 Rename things to reflect that they're not item specific 2023-05-03 20:13:32 +00:00
lcnr
0c5fe37786 remove inside_canonicalization_ctxt flag
we never reach the code checking for this flag while the
flag is enabled, so it does not change the behavior
of the code.
2023-05-03 21:03:19 +02:00
Dylan DPC
80df4ab403
Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obk
Implement negative bounds for internal testing purposes

Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature.

Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-04 00:17:23 +05:30
lcnr
6bb1f792db cleanup nll generalizer 2023-05-03 15:47:36 +02:00
Nicholas Nethercote
6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
Michael Goulet
03469c3f2e Make negative trait bounds work with the old trait solver 2023-05-02 22:36:25 +00:00
Matthias Krüger
57e9a4be48
Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr
More `Typefoldable`/`TypeVisitable` cleanups

r? ``@lcnr``
2023-04-27 21:34:14 +02:00
Boxy
f04b8fe0af rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
Nicholas Nethercote
671de6d62a Remove unused TypeFoldable/TypeVisitable impls. 2023-04-26 15:19:50 +10:00
Matthias Krüger
297b222066
Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, r=compiler-errors
Switch to `EarlyBinder` for `explicit_item_bounds`

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`.

r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 😃)
2023-04-25 21:06:32 +02:00
Maybe Waffle
46b01abbcd Replace tcx.mk_trait_ref with ty::TraitRef::new 2023-04-25 16:12:44 +00:00
Matthias Krüger
5f33a8c026
Rollup merge of #110563 - bryangarza:refactor-trait-selection-error-reporting, r=compiler-errors
Break up long function in trait selection error reporting + clean up nearby code

- Move blocks of code into their own functions
- Replace a few function argument types with their type aliases
- Create "AppendConstMessage" enum to replace a nested `Option`.
2023-04-25 06:46:48 +02:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
bors
4396ceca05 Auto merge of #109753 - compiler-errors:replenish-region-constraints, r=aliemjay
Clone region var origins instead of taking them in borrowck

Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls `InferCtxt::evaluate_obligation`.

This also removes a handful of unnecessary `tcx.infer_ctxt().build()` calls that are only there to mitigate this same exact issue, but with the old solver.

Fixes compiler-errors/next-solver-hir-issues#12.

----

This implements `@aliemjay's` solution where we just don't *take* the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.
2023-04-22 15:15:51 +00:00
Bryan Garza
d0d40d2a40 Break up long function in trait selection error reporting
- Move blocks of code into their own functions
- Replace a few function argument types with their type aliases
2023-04-21 09:04:02 -07:00
Michael Goulet
964600b38e Clone region var origins instead of taking in borrowck 2023-04-21 00:31:43 +00:00
Kyle Matsuda
f3b279fcc5 add EarlyBinder to output of explicit_item_bounds; replace bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query 2023-04-20 12:36:50 -06:00
Camille GILLOT
b275d2c30b Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
bors
23a76a8ab5 Auto merge of #110527 - nnethercote:lazy-graph, r=lqd
In `LexicalResolver`, don't construct graph unless necessary.

A small but easy perf win.

r? `@jackh726`
2023-04-20 06:14:55 +00:00
bors
7fde08365c Auto merge of #110399 - cjgillot:infer-variance, r=aliemjay
Account for opaque variance in outlives

Fixes https://github.com/rust-lang/rust/issues/108591
Fixes https://github.com/rust-lang/rust/issues/108592
cc `@aliemjay`
2023-04-20 04:08:03 +00:00