about summary refs log tree commit diff
path: root/tests/ui/suggestions
AgeCommit message (Collapse)AuthorLines
2023-12-12Rollup merge of #117914 - estebank:issue-85843, r=wesleywiserMatthias Krüger-17/+103
On borrow return type, suggest borrowing from arg or owned return type When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix #85843.
2023-12-12Rollup merge of #118756 - jyn514:colors, r=estebankMatthias Krüger-65/+0
use bold magenta instead of bold white for highlighting according to a poll of gay people in my phone, purple is the most popular color to use for highlighting | color | percentage | | ---------- | ---------- | | bold white | 6% | | blue | 14% | | cyan | 26% | | purple | 37% | | magenta | 17% | unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason. until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it. instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty. before: ![image](https://github.com/rust-lang/rust/assets/23638587/9a89eee2-8b89-422e-8554-812827bb2a23) after: ![image](https://github.com/rust-lang/rust/assets/23638587/5bf3a917-8a20-4afd-af3e-f9491d0d57f5) other colors for comparison: blue: ![image](https://github.com/rust-lang/rust/assets/23638587/6f199c7b-d598-4009-8ffc-6b7b1d0d1f8c) cyan: ![image](https://github.com/rust-lang/rust/assets/23638587/a77e4fe3-563e-4aa5-ae92-745bb67287d1) purple: ![image](https://github.com/rust-lang/rust/assets/23638587/ffe603fb-d811-4106-95a9-4dd4c955924c) magenta without bolding: ![image](https://github.com/rust-lang/rust/assets/23638587/cf927e5f-8b25-4dc2-b8e7-32905a11a459) r? ``@estebank``
2023-12-11Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, ↵bors-4/+0
r=compiler-errors Restore `const PartialEq` And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now. r? `@compiler-errors`
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-6/+2
remove redundant imports detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR. r? `@petrochenkov`
2023-12-10fix testsDeadbeef-4/+0
2023-12-10remove redundant importssurechen-6/+2
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Rollup merge of #118775 - Young-Flash:fix, r=compiler-errorsGuillaume Gomez-3/+69
chore: add test case for type with generic follow up https://github.com/rust-lang/rust/pull/118502
2023-12-09chore: add test case for type with genericYoung-Flash-3/+69
2023-12-08Rollup merge of #118730 - jyn514:cmp_refs, r=estebank,compiler-errorsMatthias Krüger-12/+12
recurse into refs when comparing tys for diagnostics before: ![image](https://github.com/rust-lang/rust/assets/23638587/bf6abd62-c7f3-4c09-a47e-31b6e129de19) after: ![image](https://github.com/rust-lang/rust/assets/23638587/b704d728-ddba-4204-aebe-c07dcbbcb55c) this diff from the test suite is also quite nice imo: ```diff `@@` -4,8 +4,8 `@@` error[E0308]: mismatched types LL | debug_assert_eq!(iter.next(), Some(value)); | ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>` | - = note: expected enum `Option<<I as Iterator>::Item>` - found enum `Option<&<I as Iterator>::Item>` + = note: expected enum `Option<_>` + found enum `Option<&_>` ```
2023-12-08Rollup merge of #118502 - Young-Flash:fix, r=compiler-errorsMatthias Krüger-0/+73
fix: correct the arg for 'suggest to use associated function syntax' diagnostic close https://github.com/rust-lang/rust/issues/118469
2023-12-08use magenta instead of bold for highlightingjyn-65/+0
according to a poll of gay people in my phone, purple is the most popular color to use for highlighting | color | percentage | | ---------- | ---------- | | bold white | 6% | | blue | 14% | | cyan | 26% | | purple | 37% | | magenta | 17% | unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason. until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it. instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.
2023-12-07recurse into refs when comparing tys for diagnosticsjyn-12/+12
2023-12-04Mark more tests as `run-rustfix`Esteban Küber-2/+41
2023-12-04Suggest cloning and point out obligation errors on move errorEsteban Küber-0/+9
When encountering a move error, look for implementations of `Clone` for the moved type. If there is one, check if all its obligations are met. If they are, we suggest cloning without caveats. If they aren't, we suggest cloning while mentioning the unmet obligations, potentially suggesting `#[derive(Clone)]` when appropriate. ``` error[E0507]: cannot move out of a shared reference --> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28 | LL | let mut copy: Vec<U> = map.clone().into_values().collect(); | ^^^^^^^^^^^ ------------- value moved due to this method call | | | move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait | note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied | LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect(); | ++++++++++++++++++++++++++++++++++++++++++++ + help: consider annotating `Hash128_1` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | pub struct Hash128_1; | ``` Fix #109429.
2023-12-04Tweak `.clone()` suggestion to work in more casesEsteban Küber-4/+4
When going through auto-deref, the `<T as Clone>` impl sometimes needs to be specified for rustc to actually clone the value and not the reference. ``` error[E0507]: cannot move out of dereference of `S` --> $DIR/needs-clone-through-deref.rs:15:18 | LL | for _ in self.clone().into_iter() {} | ^^^^^^^^^^^^ ----------- value moved due to this method call | | | move occurs because value has type `Vec<usize>`, which does not implement the `Copy` trait | note: `into_iter` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL help: you can `clone` the value and consume it, but this might not be your desired behavior | LL | for _ in <Vec<usize> as Clone>::clone(&self.clone()).into_iter() {} | ++++++++++++++++++++++++++++++ + ``` CC #109429.
2023-12-02Auto merge of #118077 - calebzulawski:sync-portable-simd-2023-11-19, ↵bors-1/+1
r=workingjubilee Portable SIMD subtree update Syncs nightly to the latest changes from rust-lang/portable-simd r? `@rust-lang/libs`
2023-12-01rustc_hir_typeck: Fix ICE when probing for non-ASCII function alternativeMartin Nordholts-1/+10
2023-12-01fix: correct the arg for 'suggest to use associated function syntax' diagnosticYoung-Flash-0/+73
2023-11-29On Fn arg mismatch for a fn path, suggest a closureEsteban Küber-0/+8
When encountering a fn call that has a path to another fn being passed in, where an `Fn` impl is expected, and the arguments differ, suggest wrapping the argument with a closure with the appropriate arguments.
2023-11-27Rollup merge of #118381 - Enselic:edit-dist-len, r=WaffleLapkinMichael Goulet-0/+13
rustc_span: Use correct edit distance start length for suggestions Otherwise the suggestions can be off-base for non-ASCII identifiers. For example suggesting that `Ok` is a name similar to `读文`. Closes https://github.com/rust-lang/rust/issues/72553.
2023-11-27rustc_span: Use correct edit distance start length for suggestionsMartin Nordholts-0/+13
Otherwise the suggestions can be off-base for non-ASCII identifiers. For example suggesting that `Ok` is a name similar to `读文`.
2023-11-27Change help message to make some sense in broader contextHirochika Matsumoto-2/+2
2023-11-27Address review feedbacksHirochika Matsumoto-7/+1
Also addressed merge conflicts upon rebasing.
2023-11-27Make tidy test happyHirochika Matsumoto-1/+1
2023-11-27Detect Python-like slicing and suggest how to fixHirochika Matsumoto-0/+26
Fix #108215
2023-11-26Update std::simd usage and test outputsCaleb Zulawski-1/+1
2023-11-24Show number in error message even for one errorNilstrieb-148/+148
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24Auto merge of #117934 - Young-Flash:dev, r=petrochenkovbors-4/+50
feat: make `let_binding_suggestion` more reasonable This is my first PR for rustc, which trying to fix https://github.com/rust-lang/rust/issues/117894, I am not familiar with some internal api so maybe some modification here isn't the way to go, appreciated for any review suggestion.
2023-11-23feat: make let_binding_suggestion more reasonableYoung-Flash-4/+50
2023-11-20Do not consider traits as ownable in suggestionEsteban Küber-5/+0
2023-11-20Account for '_ in lifetime suggestionEsteban Küber-0/+20
2023-11-20Suggest 'a when trait object assoc type has '_Esteban Küber-0/+16
2023-11-20Tweak wordingEsteban Küber-5/+5
2023-11-20Account for impl Trait in lifetime suggestionEsteban Küber-12/+12
When encountering ```rust fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ } ``` Suggest ```rust fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ } ```
2023-11-20On borrow return type, suggest borrowing from arg or owned return typeEsteban Küber-17/+72
When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix #85843.
2023-11-19When encountering struct fn call literal with private fields, suggest all ↵Esteban Küber-3/+3
builders When encountering code like `Box(42)`, suggest `Box::new(42)` and *all* other associated functions that return `-> Box<T>`.
2023-11-19Rollup merge of #117110 - estebank:deref-field-suggestion, r=b-naberTakayuki Maeda-9/+123
Suggest field typo through derefs Take into account implicit dereferences when suggesting fields. ``` error[E0609]: no field `longname` on type `Arc<S>` --> $DIR/suggest-field-through-deref.rs:10:15 | LL | let _ = x.longname; | ^^^^^^^^ help: a field with a similar name exists: `long_name` ``` CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-18tweak logic of "unknown field" labelEsteban Küber-1/+6
2023-11-16recover primary span labelEsteban Küber-17/+18
2023-11-16Suggest `unwrap()` on field not found for `Result`/`Option`Esteban Küber-3/+73
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field that's being accessed, suggest calling `.unwrap()` to get to the field.
2023-11-16Suggest field typo through derefsEsteban Küber-11/+49
Take into account implicit dereferences when suggesting fields. ``` error[E0609]: no field `longname` on type `Arc<S>` --> $DIR/suggest-field-through-deref.rs:10:15 | LL | let _ = x.longname; | ^^^^^^^^ help: a field with a similar name exists: `long_name` ``` CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-16When using existing fn as module, don't claim it doesn't existEsteban Küber-3/+3
Tweak wording of module not found in resolve, when the name exists but belongs to a non-`mod` item. Fix #81232.
2023-11-14Rollup merge of #116244 - estebank:issue-73497, r=b-naberMatthias Krüger-0/+37
Apply structured suggestion that allows test to work since 1.64 Close #73497.
2023-11-14Auto merge of #117856 - estebank:issue-66023, r=compiler-errorsbors-0/+2
Always point at index span on index obligation failure Use more targetted span for index obligation failures by rewriting the obligation cause span. CC #66023
2023-11-13Rollup merge of #117695 - ↵Matthias Krüger-0/+22
3tilley:prioritise-unwrap-expect-over-last-method-call, r=compiler-errors Reorder checks to make sure potential missing expect on Option/Result… … runs before removing last method call Fixes #117669
2023-11-13review comments: more targeted span setting approachEsteban Küber-0/+2
2023-11-11Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnaybors-1/+1
Add `std::hash::{DefaultHasher, RandomState}` exports (needs FCP) This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`. <details><summary>The below no longer applies, but is kept for clarity.</summary> This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API. I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier. I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred. </details>
2023-11-10Recurse over the method chain and maintain a stack to peek at previous ↵Swapna Iyer-1/+4
receiver to align spans
2023-11-08Reorder type mismatch suggestionsMax Tilley-0/+22
Suggestions are reordered to to make sure potential missing expect on Option/Result runs before the suggestion to remove the last method call
2023-11-07Apply structured suggestion that allows test to work since 1.64Esteban Küber-0/+37
Close #73497.