summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
2022-03-30Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakisbors-7/+7
Lazy type-alias-impl-trait take two ### user visible change 1: RPIT inference from recursive call sites Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned. ```rust fn bar(b: bool) -> impl std::fmt::Debug { if b { return 42 } let x: u32 = bar(false); // this errors on stable 99 } ``` The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type. ### user visible change 2: divergence between RPIT and TAIT in return statements Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So ```rust #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![42]; } std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![42] } std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended) } ``` But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same: ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![]; } let mut x = foo(false); x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator vec![] } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![]; } let mut x = bar(false); x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator vec![] } ``` ### user visible change 3: TAIT does not merge types across branches In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile. ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { vec![42_i32] } else { std::iter::empty().collect() //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } ``` It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this). ### PR formalities previous attempt: #92007 This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893 fixes #93411 fixes #88236 fixes #89312 fixes #87340 fixes #86800 fixes #86719 fixes #84073 fixes #83919 fixes #82139 fixes #77987 fixes #74282 fixes #67830 fixes #62742 fixes #54895
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-7/+7
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-27resolve: Simplify some diagnostic code to avoid an ICEVadim Petrochenkov-2/+24
2022-03-24Properly track `ImplObligation`sEsteban Kuber-1/+7
Instead of probing for all possible impls that could have caused an `ImplObligation`, keep track of its `DefId` and obligation spans for accurate error reporting. Follow up to #89580. Addresses #89418. Remove some unnecessary clones. Tweak output for auto trait impl obligations.
2022-03-15Auto merge of #92285 - compiler-errors:dyn-proj-bounds, r=nikomatsakisbors-11/+85
check ~Projection~ all supertrait bounds when confirming dyn candidate I'm pretty sure Projection is the only other PredicateKind that we care about enforcing here. Fixes #80800
2022-03-14check all dyn obligations, actuallyMichael Goulet-11/+35
2022-03-14check Projection supertrait bounds when confirming dyn candidateMichael Goulet-0/+50
2022-03-03add tests for metadata for unsized generics and opaquesMichael Goulet-0/+62
2022-03-03opaque types may also be sizedMichael Goulet-3/+20
2022-03-03type parameters have unit metadata if they are sizedMichael Goulet-0/+12
2022-02-24better ObligationCause for normalization errors in can_type_implement_copyMichael Goulet-0/+39
2022-02-14Auto merge of #93652 - spastorino:fix-negative-overlap-check-regions, ↵bors-4/+6
r=nikomatsakis Fix negative overlap check regions r? `@nikomatsakis`
2022-02-14Properly check regions on negative overlap checkSantiago Pastorino-4/+6
2022-02-14further update `fuzzy_match_tys`lcnr-4/+5
2022-02-14fuzzify `fuzzy_match_tys`lcnr-0/+6
2022-02-14Make `find_similar_impl_candidates` a little fuzzier.Ben Reeves-0/+2
2022-02-11Rollup merge of #93909 - saschanaz:patch-2, r=petrochenkovMatthias Krüger-8/+8
Fix typo: explicitely -> explicitly
2022-02-11Fix typo: explicitely->explicitlyKagami Sascha Rosylight-8/+8
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-3/+3
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-07Print opaque types from type aliases via their pathOli Scherer-3/+3
2022-02-01Auto merge of #93386 - ↵bors-1/+27
WaffleLapkin:rustc_must_implement_one_of_check_target, r=nagisa Check that `#[rustc_must_implement_one_of]` is applied to a trait `#[rustc_must_implement_one_of]` only makes sense when applied to a trait, so it's sensible to emit an error otherwise.
2022-01-28Add test for old ICE in #91594Ben Reeves-0/+34
2022-01-27Check that `#[rustc_must_implement_one_of]` is applied to a traitMaybe Waffle-1/+27
2022-01-17Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, ↵Matthias Krüger-0/+256
r=Aaron1011 Implement `#[rustc_must_implement_one_of]` attribute This PR adds a new attribute — `#[rustc_must_implement_one_of]` that allows changing the "minimal complete definition" of a trait. It's similar to GHC's minimal `{-# MINIMAL #-}` pragma, though `#[rustc_must_implement_one_of]` is weaker atm. Such attribute was long wanted. It can be, for example, used in `Read` trait to make transitions to recently added `read_buf` easier: ```rust #[rustc_must_implement_one_of(read, read_buf)] pub trait Read { fn read(&mut self, buf: &mut [u8]) -> Result<usize> { let mut buf = ReadBuf::new(buf); self.read_buf(&mut buf)?; Ok(buf.filled_len()) } fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { default_read_buf(|b| self.read(b), buf) } } impl Read for Ty0 {} //^ This will fail to compile even though all `Read` methods have default implementations // Both of these will compile just fine impl Read for Ty1 { fn read(&mut self, buf: &mut [u8]) -> Result<usize> { /* ... */ } } impl Read for Ty2 { fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { /* ... */ } } ``` For now, this is implemented as an internal attribute to start experimenting on the design of this feature. In the future we may want to extend it: - Allow arbitrary requirements like `a | (b & c)` - Allow multiple requirements like - ```rust #[rustc_must_implement_one_of(a, b)] #[rustc_must_implement_one_of(c, d)] ``` - Make it appear in rustdoc documentation - Change the syntax? - Etc Eventually, we should make an RFC and make this (or rather similar) attribute public. --- I'm fairly new to compiler development and not at all sure if the implementation makes sense, but at least it passes tests :)
2022-01-14Do not use `HashSet` for `#[rustc_must_implement_one_of]`Maybe Waffle-3/+3
2022-01-14Check for duplicate arguments in `#[rustc_must_implement_one_of]`Maybe Waffle-0/+53
2022-01-11Add a test for ungated `#[rustc_must_implement_one_of]`Maybe Waffle-0/+24
This test checks that `#[rustc_must_implement_one_of]` is gated behind `#![feature(rustc_attrs)]`.
2022-01-10Rollup merge of #92248 - compiler-errors:normalize-type-for-pointee, r=jackh726Matthias Krüger-0/+22
Normalize struct tail type when checking Pointee trait Let's go ahead and implement the FIXMEs by properly normalizing the struct-tail type when satisfying a Pointee obligation. This should fix the ICE when we try to calculate a layout depending on `<Ty as Pointee>::Metadata` later. Fixes #92128 Fixes #92577 Additionally, mark the obligation as ambiguous if there are any infer types in that struct-tail type. This has the effect of causing `<_ as Pointee>::Metadata` to be properly replaced with an infer variable ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/traits/project.rs#L813)) and registered as an obligation... this turns out to be very important in unifying function parameters with formals that are assoc types. Fixes #91446
2022-01-09Apply suggestions from code reviewWaffle Maybe-17/+17
Use "(associated) function" terminology instead of "method". Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-01-09Move `#[rustc_must_implement_one_of]` tests to fix tidy checkMaybe Waffle-0/+179
2021-12-29Add UI test for #92292Wang Ruochen-0/+32
Closes #92292
2021-12-24Normalize struct tail type when checking Pointee traitMichael Goulet-0/+22
2021-12-20Auto merge of #92041 - Aaron1011:remove-speculative-evaluation, r=jackh726bors-0/+34
Remove 'speculative evaluation' of predicates Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-18Rollup merge of #89090 - cjgillot:bare-dyn, r=jackh726Matthias Krüger-1/+6
Lint bare traits in AstConv. Removing the lint from lowering allows to: - make lowering querification easier; - have the lint implementation in only one place. r? `@estebank`
2021-12-17Remove 'speculative evaluation' of predicatesAaron Hill-0/+34
Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-13Fix HashStable implementation on InferTyMichael Goulet-0/+17
2021-12-11Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obkbors-10/+23
Tweak assoc type obligation spans * Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors r? `@oli-obk` This is a(n uncontroversial) subset of #85799.
2021-12-11Tweak assoc type obligation spansEsteban Kuber-10/+23
* Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors
2021-12-10Tweak wordingEsteban Kuber-7/+7
2021-12-10Use a more accurate `Span` for `'static` obligation from return typeEsteban Kuber-8/+8
2021-12-10Point at return type when it introduces `'static` obligationEsteban Kuber-0/+32
2021-12-10Clean up visual output logicEsteban Kuber-9/+9
2021-12-10Point at capture points for non-`'static` reference crossing a `yield` pointEsteban Kuber-2/+64
``` error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/issue-72312.rs:10:24 | LL | pub async fn start(&self) { | ^^^^^ this data with an anonymous lifetime `'_`... ... LL | require_static(async move { | -------------- ...is required to live as long as `'static` here... LL | &self; | ----- ...and is captured here | note: `'static` lifetime requirement introduced by this trait bound --> $DIR/issue-72312.rs:2:22 | LL | fn require_static<T: 'static>(val: T) -> T { | ^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0759`. ``` Fix #72312.
2021-12-04Use multipart suggestions.Camille GILLOT-1/+6
2021-12-03Add test case that evals to `EvaluatedToOkModuloRegions`Wesley Wiser-1/+32
2021-12-03Add test with `#[rustc_evaluate_where_clauses]`Wesley Wiser-0/+150
As suggested via reviewer feedback.
2021-11-28Fix incorrect usage of `EvaluatedToOk` when evaluating `TypeOutlives`Aaron Hill-0/+77
A global predicate is not guarnatenteed to outlive all regions. If the predicate involves late-bound regions, then it may fail to outlive other regions (e.g. `for<'b> &'b bool: 'static` does not hold) We now only produce `EvaluatedToOk` when a global predicate has no late-bound regions - in that case, the ony region that can be present in the type is 'static
2021-11-20Align multiline messages to their label (add left margin)Esteban Kuber-148/+148
2021-11-20Do not mention associated items when they introduce an obligationEsteban Kuber-93/+0
2021-11-20Point at source of trait bound obligations in more placesEsteban Kuber-21/+73
Be more thorough in using `ItemObligation` and `BindingObligation` when evaluating obligations so that we can point at trait bounds that introduced unfulfilled obligations. We no longer incorrectly point at unrelated trait bounds (`substs-ppaux.verbose.stderr`). In particular, we now point at trait bounds on method calls. We no longer point at "obvious" obligation sources (we no longer have a note pointing at `Trait` saying "required by a bound in `Trait`", like in `associated-types-no-suitable-supertrait*`). Address part of #89418.