about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2023-10-26Rollup merge of #117106 - estebank:issue-27300, r=petrochenkovMatthias Krüger-5/+48
When expecting closure argument but finding block provide suggestion Detect if there is a potential typo where the `{` meant to open the closure body was written before the body. ``` error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<usize>` --> $DIR/ruby_style_closure_successful_parse.rs:3:31 | LL | let p = Some(45).and_then({|x| | ______________________--------_^ | | | | | required by a bound introduced by this call LL | | 1 + 1; LL | | Some(x * 2) | | ----------- this tail expression is of type `Option<usize>` LL | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<usize>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<usize>` note: required by a bound in `Option::<T>::and_then` --> $SRC_DIR/core/src/option.rs:LL:COL help: you might have meant to open the closure body instead of placing a closure within a block | LL - let p = Some(45).and_then({|x| LL + let p = Some(45).and_then(|x| { | ``` Detect the potential typo where the closure header is missing. ``` error[E0277]: expected a `FnOnce<(&bool,)>` closure, found `bool` --> $DIR/block_instead_of_closure_in_arg.rs:3:23 | LL | Some(true).filter({ | _________________------_^ | | | | | required by a bound introduced by this call LL | |/ if number % 2 == 0 { LL | || number == 0 LL | || } else { LL | || number != 0 LL | || } | ||_________- this tail expression is of type `bool` LL | | }); | |______^ expected an `FnOnce<(&bool,)>` closure, found `bool` | = help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool` note: required by a bound in `Option::<T>::filter` --> $SRC_DIR/core/src/option.rs:LL:COL help: you might have meant to create the closure instead of a block | LL | Some(true).filter(|_| { | +++ ``` Partially address #27300. Fix #104690.
2023-10-26Stash and cancel cycle errors for auto trait leakage in opaquesMichael Goulet-0/+7
2023-10-26Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnrbors-126/+220
Rework negative coherence to properly consider impls that only partly overlap This PR implements a modified negative coherence that handles impls that only have partial overlap. It does this by: 1. taking both impl trait refs, instantiating them with infer vars 2. equating both trait refs 3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars 4. plugging all remaining infer vars with placeholder types these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs. We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them. This PR then additionally: * removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types. --- An example: Consider these two partially overlapping impls: ``` impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {} impl<F> PartialEq<F> for F where F: FnPtr {} ``` Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`. Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1]. Then we can take the param-env from the first impl, and try to prove the negated where clause of the second. We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap. [^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26Add hir::GeneratorKind::GenOli Scherer-1/+19
2023-10-25Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errorsMatthias Krüger-9/+9
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25Rollup merge of #117008 - compiler-errors:canonical, r=lcnrMatthias Krüger-1/+1
Uplift `Canonical` to `rustc_type_ir` I plan on moving the new trait solver's canonicalizer into either `rustc_type_ir` or a child crate. One dependency on this is lifting `Canonical<V>` to `rustc_type_ir` so we can actually name the canonicalized values. I may also later lift `CanonicalVarInfo` into the new trait solver. I can't really tell what other changes need to be done, but I'm just putting this up sooner than later since I'm almost certain it'll need to be done regardless of other design choices. There are a couple of warts introduced by this PR, since we no longer can define inherent `Canonical` impls in `rustc_middle` -- see the changes to: * `compiler/rustc_trait_selection/src/traits/query/normalize.rs` * `compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs` r? lcnr
2023-10-25Rollup merge of #116931 - ↵Matthias Krüger-10/+47
weiznich:improve_diagnostic_on_unimplemented_warnings, r=compiler-errors Improve the warning messages for the `#[diagnostic::on_unimplemented]` This commit improves warnings emitted for malformed on unimplemented attributes by: * Improving the span of the warnings * Adding a label message to them * Separating the messages for missing and unexpected options * Adding a help message that says which options are supported r? `@compiler-errors` I'm happy to work on further improvements, so feel free to make suggestions.
2023-10-25Rollup merge of #116401 - WaffleLapkin:vtablin''', r=oli-obkMatthias Krüger-37/+47
Return multiple object-safety violation errors and code improvements to the object-safety check See individual commits for more information. Split off of #114260, since it turned out that the main intent of that PR was wrong. r? oli-obk
2023-10-25make E0277 use short pathsMilo-5/+11
add note change wording short_ty_string on t
2023-10-25Return multiple object-safety violation errorsMaybe Waffle-35/+42
2023-10-25Don't allow dead codeMaybe Waffle-1/+0
2023-10-25Add a comment explaining some weird `is_vtable_safe_method` behaviorMaybe Waffle-0/+4
2023-10-25Refactor away the need for some `descr` methods.Oli Scherer-2/+2
Instead we use `Display` impls and their `alternate` render scheme to decide whether we want backticks or not.
2023-10-25Uplift Canonical to rustc_type_irMichael Goulet-1/+1
2023-10-25Rename `AsyncCoroutineKind` to `CoroutineSource`Oli Scherer-7/+7
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25Auto merge of #117076 - oli-obk:privacy_visitor_types, r=petrochenkovbors-3/+12
Refactor type visitor walking r? `@petrochenkov` pulling out the uncontroversial parts of https://github.com/rust-lang/rust/pull/113671
2023-10-24Get rid of 'tcx on ConstVid, EffectVidMichael Goulet-4/+5
2023-10-24Auto merge of #116435 - compiler-errors:re-erased, r=lcnrbors-2/+10
Handle `ReErased` in responses in new solver There are legitimate cases in the compiler where we return `ReErased` for lifetimes that are uncaptured in the hidden type of an opaque. For example, in the test committed below, we ignore ignore the bivariant lifetimes of an opaque when it's inferred as the hidden type of another opaque. This may result in a `type_of(Opaque)` call returning a type that references `ReErased`. Let's handle this gracefully in the new solver. Also added a `rustc_hidden_type_of_opaques` attr to print hidden types. This seems useful for opaques. r? lcnr
2023-10-23nitsMichael Goulet-83/+35
2023-10-23Consider regionsMichael Goulet-2/+9
2023-10-23Make things work by using the new solverMichael Goulet-3/+13
2023-10-23Rework negative coherenceMichael Goulet-39/+152
2023-10-23Remove FnPtr hack from trait_ref_is_knowableMichael Goulet-17/+21
2023-10-23pre-cleanupsMichael Goulet-24/+32
2023-10-23Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgrbors-24/+19
Rollup of 6 pull requests Successful merges: - #107159 (rand use getrandom for freebsd (available since 12.x)) - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`) - #117046 (return unfixed len if pat has reported error) - #117070 (rustdoc: wrap Type with Box instead of Generics) - #117074 (Remove smir from triage and add me to stablemir) - #117086 (Update .mailmap to promote my livename) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-23When expecting closure argument but finding block provide suggestionEsteban Küber-5/+48
Detect if there is a potential typo where the `{` meant to open the closure body was written before the body. ``` error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<usize>` --> $DIR/ruby_style_closure_successful_parse.rs:3:31 | LL | let p = Some(45).and_then({|x| | ______________________--------_^ | | | | | required by a bound introduced by this call LL | | 1 + 1; LL | | Some(x * 2) | | ----------- this tail expression is of type `Option<usize>` LL | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<usize>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<usize>` note: required by a bound in `Option::<T>::and_then` --> $SRC_DIR/core/src/option.rs:LL:COL help: you might have meant to open the closure body instead of placing a closure within a block | LL - let p = Some(45).and_then({|x| LL + let p = Some(45).and_then(|x| { | ``` Detect the potential typo where the closure header is missing. ``` error[E0277]: expected a `FnOnce<(&bool,)>` closure, found `bool` --> $DIR/block_instead_of_closure_in_arg.rs:3:23 | LL | Some(true).filter({ | _________________------_^ | | | | | required by a bound introduced by this call LL | |/ if number % 2 == 0 { LL | || number == 0 LL | || } else { LL | || number != 0 LL | || } | ||_________- this tail expression is of type `bool` LL | | }); | |______^ expected an `FnOnce<(&bool,)>` closure, found `bool` | = help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool` note: required by a bound in `Option::<T>::filter` --> $SRC_DIR/core/src/option.rs:LL:COL help: you might have meant to create the closure instead of a block | LL | Some(true).filter(|_| { | +++ ``` Partially address #27300.
2023-10-23Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obkMatthias Krüger-24/+19
Make `ty::print::Printer` take `&mut self` instead of `self` based on #116815 This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-23Handle ReErased in responses in new solverMichael Goulet-2/+10
2023-10-23Make ICE a bit more informativeOli Scherer-3/+12
2023-10-22use visibility to check unused imports and delete some stmtsbohan-7/+1
2023-10-21fix spans for removing `.await` on `for` expressionsLukas Markeffsky-1/+1
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-24/+19
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-21Rollup merge of #116911 - estebank:issue-85378, r=oli-obkMatthias Krüger-0/+23
Suggest relaxing implicit `type Assoc: Sized;` bound Fix #85378.
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-3/+3
2023-10-20s/generator/coroutine/Oli Scherer-179/+179
2023-10-20s/Generator/Coroutine/Oli Scherer-121/+121
2023-10-19Improve the warning messages for the `#[diagnostic::on_unimplemented]`Georg Semmler-10/+47
This commit improves warnings emitted for malformed on unimplemented attributes by: * Improving the span of the warnings * Adding a label message to them * Separating the messages for missing and unexpected options * Adding a help message that says which options are supported
2023-10-19Suggest relaxing implicit `type Assoc: Sized;` boundEsteban Küber-0/+23
Fix #85378.
2023-10-18Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errorsbors-13/+18
`TyCtxt::mk_alias_ty` -> `AliasTy::new`
2023-10-18AliasTy::new instead of tcx methodlcnr-13/+18
2023-10-18Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjaybors-42/+4
Rollup of 5 pull requests Successful merges: - #116812 (Disable missing_copy_implementations lint on non_exhaustive types) - #116856 (Disable effects in libcore again) - #116865 (Suggest constraining assoc types in more cases) - #116870 (Don't compare host param by name) - #116879 (revert #114586) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-18Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errorsbors-16/+4
Remove lots of generics from `ty::print` All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type. cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad r? oli-obk
2023-10-18revert rust-lang/rust#114586Ali MJ Al-Nasrawy-42/+4
2023-10-18Remove `#![feature(result_option_inspect)]` from the compilerSlanterns-1/+0
2023-10-17Rollup merge of #116717 - estebank:issue-9082, r=oli-obkMatthias Krüger-1/+126
Special case iterator chain checks for suggestion When encountering method call chains of `Iterator`, check for trailing `;` in the body of closures passed into `Iterator::map`, as well as calls to `<T as Clone>::clone` when `T` is a type param and `T: !Clone`. Fix #9082.
2023-10-17Remove `Print::Error`Nilstrieb-6/+2
All printing goes through `fmt::Error` now.
2023-10-17Remove `Print::Output`Nilstrieb-12/+4
Now that `Printer` doesn't have subprinters anymore, the output of a printing operation is always the same.
2023-10-17Auto merge of #116826 - nnethercote:fix-116780-116797, r=compiler-errorsbors-4/+4
Fix a performance regression in obligation deduplication. Commit 8378487 from #114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions. This commit moves the deduplication back to the old location. The good news is that #114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain. Fixes #116780, #116797. r? `@compiler-errors`
2023-10-17Fix a performance regression in obligation deduplication.Nicholas Nethercote-4/+4
Commit 8378487 from #114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions. This commit moves the deduplication back to the old location. The good news is that #114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain. Fixes #116780, #116797.
2023-10-16Rollup merge of #116805 - ↵Guillaume Gomez-4/+7
Nilstrieb:onunimplemented-std-core-alloc-whatever-who-cares, r=compiler-errors Make `rustc_onunimplemented` export path agnostic This makes it so that all the matchers that match against paths use the definition path instead of the export path. This removes all duplication around `std`/`alloc`/`core`. This is not necessarily optimal because we now depend on internal implementation details like `core::ops::control_flow::ControlFlow`, which is not very nice and probably not acceptable for a stable `on_unimplemented`. An alternative would be to just string-replace normalize away `alloc`/`core` to `std` as a special case, keeping the export paths but making it so that we're still fully standard library flavor agnostic. Looking at the diff, I'm starting to think that some simple string replacement would go a long way towards fixing the problem of duplication while keeping export paths... What do you prefer? Also `@weiznich` for your thoughts about the stable version. r? compiler-errors