about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2023-11-08Rollup merge of #113925 - clubby789:const-ctor-repeat, r=estebankMatthias Krüger-9/+20
Improve diagnostic for const ctors in array repeat expressions Fixes #113912
2023-11-06Don't instantiate the binder twice when assembling object candidateMichael Goulet-17/+7
2023-11-06Only check predicates for late-bound non-lifetime vars in object candidate ↵Michael Goulet-1/+4
assembly
2023-11-06Auto merge of #117585 - dnbln:feat/move-kw-span, r=cjgillotbors-1/+1
Add the `Span` of the `move` keyword to the HIR. This is required to implement a lint like the one described here: https://github.com/rust-lang/rust-clippy/issues/11721
2023-11-04Rollup merge of #117583 - compiler-errors:placeholderconst-lifetime, r=cjgillotMatthias Krüger-5/+5
Remove `'tcx` lifetime on `PlaceholderConst` The `'tcx` lifetime is not needed for anything, so this is a continuation of #117139.
2023-11-04Fix remaining uses of `CaptureBy::Value`Dinu Blanovschi-1/+1
2023-11-04No lifetime on PlaceholderConstMichael Goulet-5/+5
2023-11-03Auto merge of #117507 - nnethercote:rustc_span, r=Nilstriebbors-4/+3
`rustc_span` cleanups Just some things I found while looking over this crate. r? `@oli-obk`
2023-11-03Auto merge of #116439 - compiler-errors:on-unimplemented, r=davidtwcobors-0/+14
Pretty print `Fn` traits in `rustc_on_unimplemented` I don't think that users really ever should need to think about `Fn*` traits' tupled args for a simple trait error. r? diagnostics
2023-11-02Auto merge of #117134 - lcnr:dropck_outlives-coroutine, r=compiler-errorsbors-13/+22
dropck_outlives check whether generator witness needs_drop see https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/.23116242.3A.20Code.20no.20longer.20compiles.20after.20-Zdrop-tracking-mir.20.E2.80.A6/near/398311627 for an explanation. Fixes #116242 (or well, the repro by `@jamuraa` in https://github.com/rust-lang/rust/issues/116242#issuecomment-1739802047). I did not add a regression test as it depends on other crates. We do have 1 test going from fail to pass, showing the intended behavior. r? types
2023-11-02Pretty print Fn traits in rustc_on_unimplementedMichael Goulet-0/+14
2023-11-02only erase param env regions where neededlcnr-1/+1
2023-11-02dropck_outlives check generator witness needs_droplcnr-13/+22
2023-11-02Rollup merge of #117394 - lcnr:proof-tree-cache4, r=compiler-errorsMatthias Krüger-99/+96
use global cache when computing proof trees we're writing the solver while relying on the existence of the global cache to avoid exponential blowup. By disabling the global cache when building proof trees, it is easy to get hangs, e.g. when computing intercrate ambiguity causes. Removes the unstable `-Zdump_solver_proof_tree_use_cache` option, as we now always return a full proof tree. r? `@compiler-errors`
2023-11-02use global cache when computing proof treeslcnr-99/+96
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-4/+3
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-31Auto merge of #117419 - compiler-errors:gen, r=oli-obkbors-23/+24
Some more coroutine renamings a few places where `gen_` names leaked through but should be coroutine. r? oli-obk
2023-10-30Some more coroutine renamingsMichael Goulet-23/+24
2023-10-30Auto merge of #116405 - estebank:issue-103155, r=davidtwcobors-2/+2
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-30Detect object safety errors when assoc type is missingEsteban Küber-2/+2
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-30Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgrbors-7/+4
Rollup of 7 pull requests Successful merges: - #116862 (Detect when trait is implemented for type and suggest importing it) - #117389 (Some diagnostics improvements of `gen` blocks) - #117396 (Don't treat closures/coroutine types as part of the public API) - #117398 (Correctly handle nested or-patterns in exhaustiveness) - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it) - #117411 (Improve some diagnostics around `?Trait` bounds) - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-30Don't super-fold types when we hit the recursion limitMichael Goulet-7/+4
2023-10-30Rollup merge of #117068 - nnethercote:clean-up-Cargo-toml, r=wesleywiserGuillaume Gomez-7/+7
Clean up `compiler/rustc*/Cargo.toml` Mostly by sorting dependencies, plus some other minor things. r? ``@wesleywiser``
2023-10-30Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, ↵León Orell Valerian Liehr-22/+24
r=compiler-errors Allows `#[diagnostic::on_unimplemented]` attributes to have multiple notes This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests. r? `@compiler-errors` I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-7/+7
- Sort dependencies and features sections. - Add `tidy` markers to the sorted sections so they stay sorted. - Remove empty `[lib`] sections. - Remove "See more keys..." comments. Excluded files: - rustc_codegen_{cranelift,gcc}, because they're external. - rustc_lexer, because it has external use. - stable_mir, because it has external use.
2023-10-29Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errorsbors-8/+208
Implement `gen` blocks in the 2024 edition Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122 `gen` block tracking issue https://github.com/rust-lang/rust/issues/117078 This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically. An example usage of `gen` blocks is ```rust fn foo() -> impl Iterator<Item = i32> { gen { yield 42; for i in 5..18 { if i.is_even() { continue } yield i * 2; } } } ``` The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-28Rollup merge of #116945 - estebank:sealed-trait-impls, r=petrochenkovJubilee-2/+28
When encountering sealed traits, point types that implement it ``` error[E0277]: the trait bound `S: d::Hidden` is not satisfied --> $DIR/sealed-trait-local.rs:53:20 | LL | impl c::Sealed for S {} | ^ the trait `d::Hidden` is not implemented for `S` | note: required by a bound in `c::Sealed` --> $DIR/sealed-trait-local.rs:17:23 | LL | pub trait Sealed: self::d::Hidden { | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - c::X - c::Y ``` The last `help` is new.
2023-10-28Rollup merge of #116739 - Milo123459:milo/short-paths, r=estebankJubilee-5/+11
Make `E0277` use short paths Fixes #116616
2023-10-27Update type_err_ctxt_ext.rsMilo-2/+2
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2023-10-27When encountering sealed traits, point types that implement itEsteban Küber-2/+28
``` error[E0277]: the trait bound `S: d::Hidden` is not satisfied --> $DIR/sealed-trait-local.rs:53:20 | LL | impl c::Sealed for S {} | ^ the trait `d::Hidden` is not implemented for `S` | note: required by a bound in `c::Sealed` --> $DIR/sealed-trait-local.rs:17:23 | LL | pub trait Sealed: self::d::Hidden { | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - c::X - c::Y ``` The last `help` is new.
2023-10-27Make `gen` blocks implement the `Iterator` traitOli Scherer-7/+189
2023-10-27Allows `#[diagnostic::on_unimplemented]` attributes to have multipleGeorg Semmler-22/+24
notes This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests.
2023-10-27Rollup merge of #117241 - compiler-errors:auto-trait-leak-cycle, r=oli-obkMatthias Krüger-0/+7
Stash and cancel cycle errors for auto trait leakage in opaques We don't need to emit a traditional cycle error when we have a selection error that explains what's going on but in more detail. We may want to augment this error to actually point out the cycle, now that the cycle error is not being emitted. We could do that by storing the set of opaques that was in the `CyclePlaceholder` that gets returned from `type_of_opaque`. r? `@oli-obk` cc `@estebank` #117235
2023-10-27Auto merge of #113183 - estebank:redundant-sized-errors, r=davidtwcobors-6/+39
Only emit one error per unsized binding, instead of one per usage Fix #56607.
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/+52
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