about summary refs log tree commit diff
path: root/tests/ui/traits
AgeCommit message (Collapse)AuthorLines
2024-02-22Auto merge of #119989 - lcnr:sub_relations-bye-bye, r=compiler-errorsbors-5/+5
remove `sub_relations` from the `InferCtxt` While doing so, I tried to remove the `delay_span_bug` in `rematch_impl` again, which lead me to discover another `freshen` bug, fixing that one in the second commit. See commit descriptions for the reasoning behind each change. r? `@compiler-errors`
2024-02-22Deduplicate some logic and reword outputEsteban Küber-9/+9
2024-02-22Tweak wording of "implemented trait isn't imported" suggestionEsteban Küber-7/+7
2024-02-22Better account for associated const found for fn call exprEsteban Küber-8/+10
2024-02-22Make confusable suggestions `verbose`Esteban Küber-5/+25
2024-02-22Consider methods from traits when suggesting typosEsteban Küber-3/+33
Do not provide a structured suggestion when the arguments don't match. ``` error[E0599]: no method named `test_mut` found for struct `Vec<{integer}>` in the current scope --> $DIR/auto-ref-slice-plus-ref.rs:7:7 | LL | a.test_mut(); | ^^^^^^^^ | = help: items from traits can only be used if the trait is implemented and in scope note: `MyIter` defines an item `test_mut`, perhaps you need to implement it --> $DIR/auto-ref-slice-plus-ref.rs:14:1 | LL | trait MyIter { | ^^^^^^^^^^^^ help: there is a method `get_mut` with a similar name, but with different arguments --> $SRC_DIR/core/src/slice/mod.rs:LL:COL ``` Consider methods beyond inherent ones when suggesting typos. ``` error[E0599]: no method named `owned` found for reference `&dyn Foo` in the current scope --> $DIR/object-pointer-types.rs:11:7 | LL | fn owned(self: Box<Self>); | --------- the method might not be found because of this arbitrary self type ... LL | x.owned(); | ^^^^^ help: there is a method with a similar name: `to_owned` ``` Fix #101013.
2024-02-22change error messages to be incorrect, but more helpfullcnr-4/+4
2024-02-22Rollup merge of #120598 - compiler-errors:no-rigid-check, r=lcnrMatthias Krüger-15/+1
No need to `validate_alias_bound_self_from_param_env` in `assemble_alias_bound_candidates` We already fully normalize the self type before we reach `assemble_alias_bound_candidates`, so there's no reason to double check that a projection is truly rigid by checking param-env bounds. I think this is also blocked on us making sure to always normalize opaques: #120549. r? lcnr
2024-02-22do not use <: in subtyping overflow msglcnr-5/+5
2024-02-21Rollup merge of #121406 - compiler-errors:tests, r=NilstriebMatthias Krüger-0/+60
Add a couple tests Fixes #119857 Fixes #115497
2024-02-21Add a non-lifetime-binders testMichael Goulet-0/+60
2024-02-21Rollup merge of #121359 - lcnr:typesystem-cleanup, r=compiler-errorsLeón Orell Valerian Liehr-8/+8
miscellaneous type system improvements see review comments for rationale r? `@compiler-errors`
2024-02-20some type system cleanuplcnr-8/+8
2024-02-20Rollup merge of #121322 - compiler-errors:next-solver-fulfillment-ice, r=lcnrMatthias Krüger-0/+26
Don't ICE when hitting overflow limit in fulfillment loop in next solver As the title says, let's not ICE when hitting the overflow limit in fulfill. On the other hand, we don't want to treat these as true errors, since it means that whether something is considered a true error or an ambiguity is dependent on overflow handling in the solver, which seems not worth it. Now that we use the presence of true errors in fulfillment for implicit negative coherence, we especially don't want to tie together coherence and overflow. I guess I could also drain these errors out of fulfillment and put them into some `ambiguities` storage so we could return them in `select_all_or_error` without having to re-process them every time we call `select_where_possible`. Let me know if that's desired. r? lcnr
2024-02-20Rollup merge of #121241 - reitermarkus:generic-nonzero-traits, r=dtolnayNilstrieb-1/+0
Implement `NonZero` traits generically. Tracking issue: https://github.com/rust-lang/rust/issues/120257 r? ````@dtolnay````
2024-02-20Simply do not ICEMichael Goulet-0/+26
2024-02-19Auto merge of #121211 - lcnr:nll-relate-handle-infer, r=BoxyUwUbors-2/+2
deduplicate infer var instantiation Having 3 separate implementations of one of the most subtle parts of our type system is not a good strategy if we want to maintain a sound type system :sparkles: while working on this I already found some subtle bugs in the existing code, so that's awesome :tada: cc #121159 This was necessary as I am not confident in my nll changes in #119106, so I am first cleaning this up in a separate PR. r? `@BoxyUwU`
2024-02-17Implement `NonZero` traits generically.Markus Reiter-1/+0
2024-02-17move ty var instantiation into the generalize modulelcnr-2/+2
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-620/+620
2024-02-16Fix an ICE in the recursion lintOli Scherer-0/+70
2024-02-15Auto merge of #119338 - compiler-errors:upcast-plus-autos, r=lcnrbors-0/+14
Consider principal trait ref's auto-trait super-traits in dyn upcasting Given traits like: ```rust trait Subtrait: Supertrait + Send {} trait Supertrait {} ``` We should be able to upcast `dyn Subtrait` to `dyn Supertrait + Send`. This is not currently possible, because when upcasting, we look at the list of auto traits in the object type (`dyn Subtrait`, which has no auto traits in its bounds) and compare them to the target's auto traits (`dyn Supertrait + Send`, which has `Send` in its bound). Since the target has auto traits that are not present in the source, the upcasting fails. This is overly restrictive, since `dyn Subtrait` will always implement `Send` via its built-in object impl. I propose to loosen this restriction here. r? types --- ### ~~Aside: Fix this in astconv instead?~~ ### edit: This causes too many failures. See https://github.com/rust-lang/rust/pull/119825#issuecomment-1890847150 We may also fix this by by automatically elaborating all auto-trait supertraits during `AstConv::conv_object_ty_poly_trait_ref`. That is, we can make it so that `dyn Subtrait` is elaborated into the same type of `dyn Subtrait + Send`. I'm open to considering this solution instead, but it would break coherence in the following example: ```rust trait Foo: Send {} trait Bar {} impl Bar for dyn Foo {} impl Bar for dyn Foo + Send {} //~^ This would begin to be an overlapping impl. ```
2024-02-15Consider principal trait ref's auto-trait super-traits in dyn upcastingMichael Goulet-0/+14
2024-02-14Continue compilation even if inherent impl checks failOli Scherer-3/+39
2024-02-14Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errorsbors-14/+113
Continue compilation after check_mod_type_wf errors The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too. The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication. fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14Rollup merge of #120893 - c410-f3r:testsssssss, r=petrochenkovGuillaume Gomez-0/+34
Move some tests r? `@petrochenkov`
2024-02-14Continue compilation after check_mod_type_wf errorsOli Scherer-14/+113
2024-02-14Rollup merge of #121049 - estebank:issue-121009, r=fmeaseOli Scherer-5/+0
Do not point at `#[allow(_)]` as the reason for compat lint triggering Fix #121009.
2024-02-14Rollup merge of #120915 - OdenShirataki:master, r=fmeaseOli Scherer-4/+4
Fix suggestion span for `?Sized` when param type has default Fixes #120878 Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present r? `@fmease`
2024-02-14Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errorsOli Scherer-6/+6
Be less confident when `dyn` suggestion is not checked for object safety #120275 no longer checks bare traits for object safety when making a `dyn` suggestion on Rust < 2021. In this case, qualify the suggestion with a note that the trait must be object safe, to prevent user confusion as seen in #116434 r? ```@fmease```
2024-02-13Move testsCaio-0/+34
2024-02-13Do not point at `#[allow(_)]` as the reason for compat lint triggeringEsteban Küber-5/+0
Fix #121009.
2024-02-13use alias-relate to structurally normalize in the solverlcnr-23/+24
2024-02-12Fix suggestion span for ?SizedOdenShirataki-4/+4
when param type has default and type in trait is generic.
2024-02-09Be less confident when `dyn` suggestion is not checked for object safetytrevyn-6/+6
2024-02-10Rollup merge of #120629 - c410-f3r:testsssssss, r=petrochenkovMatthias Krüger-0/+81
Move some test files r? ``@petrochenkov``
2024-02-09Move some testsCaio-0/+81
2024-02-09Rollup merge of #120836 - lcnr:param-env-hide-impl, r=BoxyUwUMatthias Krüger-82/+316
hide impls if trait bound is proven from env AVERT YOUR EYES `@compiler-errors` fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/76 and https://github.com/rust-lang/trait-system-refactor-initiative/issues/12#issuecomment-1865234925 this is kinda ugly and I hate it, but I wasn't able to think of a cleaner approach for now. I am also unsure whether we have to refine this filtering later on, so by making the change pretty minimal it should be easier to improve going forward. r? `@BoxyUwU`
2024-02-09Rollup merge of #120354 - lukas-code:metadata-normalize, r=lcnrMatthias Krüger-0/+56
improve normalization of `Pointee::Metadata` This PR makes it so that `<Wrapper<Tail> as Pointee>::Metadata` is normalized to `<Tail as Pointee>::Metadata` if we don't know `Wrapper<Tail>: Sized`. With that, the trait solver can prove projection predicates like `<Wrapper<Tail> as Pointee>::Metadata == <Tail as Pointee>::Metadata`, which makes it possible to use the metadata APIs to cast between the tail and the wrapper: ```rust #![feature(ptr_metadata)] use std::ptr::{self, Pointee}; fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U where T: Pointee<Metadata = <U as Pointee>::Metadata>, { let (thin, meta) = ptr.to_raw_parts(); ptr::from_raw_parts(thin, meta) } struct Wrapper<T: ?Sized>(T); fn cast_to_wrapper<T: ?Sized>(ptr: *const T) -> *const Wrapper<T> { cast_same_meta(ptr) } ``` Previously, this failed to compile: ``` error[E0271]: type mismatch resolving `<Wrapper<T> as Pointee>::Metadata == <T as Pointee>::Metadata` --> src/lib.rs:16:5 | 15 | fn cast_to_wrapper<T: ?Sized>(ptr: *const T) -> *const Wrapper<T> { | - found this type parameter 16 | cast_same_meta(ptr) | ^^^^^^^^^^^^^^ expected `Wrapper<T>`, found type parameter `T` | = note: expected associated type `<Wrapper<T> as Pointee>::Metadata` found associated type `<T as Pointee>::Metadata` = note: an associated type was expected, but a different one was found ``` (Yes, you can already do this with `as` casts. But using functions is so much :sparkles: *safer* :sparkles:, because you can't change the metadata on accident.) --- This PR essentially changes the built-in impls of `Pointee` from this: ```rust // before impl Pointee for u8 { type Metadata = (); } impl Pointee for [u8] { type Metadata = usize; } // ... impl Pointee for Wrapper<u8> { type Metadata = (); } impl Pointee for Wrapper<[u8]> { type Metadata = usize; } // ... // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T: ?Sized> Pointee for Wrapper<T> where Wrapper<T>: Sized { type Metadata = (); } // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T /*: Sized */> Pointee for T { type Metadata = (); } ``` to this: ```rust // after impl Pointee for u8 { type Metadata = (); } impl Pointee for [u8] { type Metadata = usize; } // ... impl<T: ?Sized> Pointee for Wrapper<T> { // in the old solver this will instead project to the "deep" tail directly, // e.g. `Wrapper<Wrapper<T>>::Metadata = T::Metadata` type Metadata = <T as Pointee>::Metadata; } // ... // This impl is only selected if `T` is a type parameter or unnormalizable projection or opaque type. fallback impl<T /*: Sized */> Pointee for T { type Metadata = (); } ```
2024-02-09hide impls if trait bound is proven from envlcnr-82/+316
2024-02-08Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgrbors-0/+194
Rollup of 9 pull requests Successful merges: - #119592 (resolve: Unload speculatively resolved crates before freezing cstore) - #120103 (Make it so that async-fn-in-trait is compatible with a concrete future in implementation) - #120206 (hir: Make sure all `HirId`s have corresponding HIR `Node`s) - #120214 (match lowering: consistently lower bindings deepest-first) - #120688 (GVN: also turn moves into copies with projections) - #120702 (docs: also check the inline stmt during redundant link check) - #120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered") - #120734 (Add `SubdiagnosticMessageOp` as a trait alias.) - #120739 (improve pretty printing for associated items in trait objects) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-08Continue to borrowck even if there were previous errorsOli Scherer-3/+14
2024-02-08Rollup merge of #120739 - lukas-code:pp-dyn-assoc, r=compiler-errorsMatthias Krüger-0/+194
improve pretty printing for associated items in trait objects * Don't print a binder in front of associated items, because it's not valid syntax. * e.g. print `dyn for<'a> Trait<'a, Assoc = &'a u8>` instead of `dyn for<'a> Trait<'a, for<'a> Assoc = &'a u8>`. * Don't print associated items that are implied by a supertrait bound. * e.g. if we have `trait Sub: Super<Assoc = u8> {}`, then just print `dyn Sub` instead of `dyn Sub<Assoc = u8>`. I've added the test in the first commit, so you can see the diff of the compiler output in the second commit.
2024-02-08Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebankbors-15/+89
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-07address review comments and add more testsLukas Markeffsky-33/+72
2024-02-07improve pretty printing for trait objectsLukas Markeffsky-25/+25
2024-02-07add test for pretty printing trait objectsLukas Markeffsky-0/+155
2024-02-07Update testsr0cky-24/+177
2024-02-06Rollup merge of #120513 - compiler-errors:normalize-regions-for-nll, r=lcnrMatthias Krüger-3/+41
Normalize type outlives obligations in NLL for new solver Normalize the type outlives assumptions and obligations in MIR borrowck. This should fix any of the lazy-norm-related MIR borrowck problems. Also some cleanups from last PR: 1. Normalize obligations in a loop in lexical region resolution 2. Use `deeply_normalize_with_skipped_universes` in lexical resolution since we may have, e.g. `for<'a> Alias<'a>: 'b`. r? lcnr
2024-02-06Rollup merge of #120507 - estebank:issue-108428, r=davidtwcoMatthias Krüger-6/+16
Account for non-overlapping unmet trait bounds in suggestion When a method not found on a type parameter could have been provided by any of multiple traits, suggest each trait individually, instead of a single suggestion to restrict the type parameter with *all* of them. Before: ``` error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied --> $DIR/method-on-unbounded-type-param.rs:5:10 | LL | (&a).cmp(&b) | ^^^ method cannot be called on `&T` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `T: Ord` which is required by `&T: Ord` `&T: Iterator` which is required by `&mut &T: Iterator` `T: Iterator` which is required by `&mut T: Iterator` help: consider restricting the type parameters to satisfy the trait bounds | LL | fn g<T>(a: T, b: T) -> std::cmp::Ordering where T: Iterator, T: Ord { | +++++++++++++++++++++++++ ``` After: ``` error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied --> $DIR/method-on-unbounded-type-param.rs:5:10 | LL | (&a).cmp(&b) | ^^^ method cannot be called on `&T` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `T: Ord` which is required by `&T: Ord` `&T: Iterator` which is required by `&mut &T: Iterator` `T: Iterator` which is required by `&mut T: Iterator` = help: items from traits can only be used if the type parameter is bounded by the trait help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them: | LL | fn g<T: Ord>(a: T, b: T) -> std::cmp::Ordering { | +++++ LL | fn g<T: Iterator>(a: T, b: T) -> std::cmp::Ordering { | ++++++++++ ``` Fix #108428. Follow up to #120396, only last commit is relevant.