about summary refs log tree commit diff
path: root/tests/ui/return
AgeCommit message (Collapse)AuthorLines
2025-09-29Make replacement suggestion `_` in type verboseEsteban Küber-16/+28
``` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/in-signature.rs:6:21 | LL | fn arr_fn() -> [u8; _] { | ^ not allowed in type signatures | help: replace with the correct return type | LL - fn arr_fn() -> [u8; _] { LL + fn arr_fn() -> [u8; 3] { | ```
2025-07-24Rehome tests/ui/issues/ tests [1/?]Oneirical-0/+10
2025-05-09Merge typeck loop with static/const item eval loopOli Scherer-6/+6
2025-04-03compiletest: Require `//~` annotations even if `error-pattern` is specifiedVadim Petrochenkov-4/+2
2025-03-06Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillotMichael Goulet-5/+0
Remove `MaybeForgetReturn` suggestion #115196 implemented a suggestion to add a missing `return` when there is an ambiguity error, when that ambiguity error could be constrained by the return type of the function. I initially reviewed it and thought it could be useful; however, looking back at that code now, I feel like it's a bit too much of a hack to be worth keeping around in typeck, especially given how rare it's expected to fire in practice. This is especially true because it depends on `StashKey::MaybeForgetReturn`, which is only stashed when we have *Sized* obligation ambiguity errors. Let's remove it for now. I'd like to note that it's basically impossible to get this suggestion to apply in its current state except for what I'd consider somewhat artificial examples, involving no generic trait bounds. For example, it's not triggered for: ```rust struct W<T>(T); fn bar<T: Default>() -> W<T> { todo!() } fn foo() -> W<i32> { if true { bar(); } W(0) } ``` Nor is it triggered for: ``` fn foo() -> i32 { if true { Default::default(); } 0 } ``` It's basically only triggered iff there's only one ambiguity error on the type, which is `Sized`. Generally, suggesting something that affects control flow is a pretty dramatic suggestion; therefore, both the accuracy and precision of this diagnostic should be pretty high. One other, somewhat unrelated observation is that this might be using stashed diagnostics incorrectly (or at least unnecessarily). Stashed diagnostics are used when error detection is fragmented over several major stages of the compiler, like a parse or resolver error which later can be recovered in typeck. However, this one is a bit different since it is fully handled within typeck -- perhaps that suggests that if this were to be reimplemented, it wouldn't need to be so complicated of an implementation.
2025-02-22Remove MaybeForgetReturn suggestionMichael Goulet-5/+0
2025-02-20Tweak E0277 when predicate comes indirectly from `?`Esteban Küber-6/+0
When a `?` operation requires an `Into` conversion with additional bounds (like having a concrete error but wanting to convert to a trait object), we handle it speficically and provide the same kind of information we give other `?` related errors. ``` error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not satisfied --> $DIR/bad-question-mark-on-trait-object.rs:5:13 | LL | fn foo() -> Result<(), Box<dyn std::error::Error>> { | -------------------------------------- required `E: std::error::Error` because of this LL | Ok(bar()?) | ^ the trait `std::error::Error` is not implemented for `E` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required for `Box<dyn std::error::Error>` to implement `From<E>` ``` Avoid talking about `FromResidual` when other more relevant information is being given, particularly from `rust_on_unimplemented`.
2024-12-12Filter empty lines, comments and delimiters from previous to last multiline ↵Esteban Küber-3/+0
span rendering
2024-12-12Tweak multispan renderingEsteban Küber-19/+6
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments.
2024-11-26tests: remove `//@ pretty-expanded` usages许杰友 Jieyou Xu (Joe)-1/+0
Done with ```bash sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs ``` and ``` sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs ```
2024-08-25Fixing span manipulation and indentation of the suggestion introduced by #126187surechen-27/+12
According to comments: https://github.com/rust-lang/rust/pull/128084#issuecomment-2295254576 https://github.com/rust-lang/rust/pull/126187/files#r1634897691
2024-07-23Suggest adding Result return type for associated method in E0277.surechen-2/+75
For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For #125997
2024-06-30Use full expr span for return suggestion on type error/ambiguityMichael Goulet-15/+54
2024-06-29Rollup merge of #127110 - surechen:fix_125488_06, r=compiler-errorsMatthias Krüger-0/+105
Fix a error suggestion for E0121 when using placeholder _ as return types on function signature. Recommit after refactoring based on comment: https://github.com/rust-lang/rust/pull/126017#issuecomment-2189149361 But when changing return type's lifetime to `ReError` will affect the subsequent borrow check process and cause test11 in typeck_type_placeholder_item.rs to lost E0515 message. ```rust fn test11(x: &usize) -> &_ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types &x //~ ERROR cannot return reference to function parameter(this E0515 msg will disappear) } ``` fixes #125488 r? ``@pnkfelix``
2024-06-29Fix a error suggestion for E0121 when using placeholder _ as return types on ↵surechen-0/+105
function signature. Recommit after refactoring based on comment: https://github.com/rust-lang/rust/pull/126017#issuecomment-2189149361 But when changing return type's lifetime to `ReError` will affect the subsequent borrow check process and cause test11 in typeck_type_placeholder_item.rs to lost E0515 message. ```rust fn test11(x: &usize) -> &_ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types &x //~ ERROR cannot return reference to function parameter(this E0515 msg will disappear) } ```
2024-06-18tests: update tests for more conservative return ty mismatch note许杰友 Jieyou Xu (Joe)-5/+27
2024-06-12For E0277 suggest adding `Result` return type for function which using ↵surechen-0/+162
QuesionMark `?` in the body.
2024-05-23Don't skip inner const when looking for body for suggestionMichael Goulet-0/+26
2024-05-20Move 100 entries from tests/ui into subdirsJubilee Young-0/+60
- Move super-fast-paren-parsing test into ui/parser - Move stmt_expr_attrs test into ui/feature-gates - Move macro tests into ui/macros - Move global_asm tests into ui/asm - Move env tests into ui/process - Move xcrate tests into ui/cross-crate - Move unop tests into ui/unop - Move backtrace tests into ui/backtrace - Move check-static tests into ui/statics - Move expr tests into ui/expr - Move optimization fuel tests into ui/fuel - Move ffi attribute tests into ui/ffi-attrs - Move suggestion tests into ui/suggestions - Move main tests into ui/fn-main - Move lint tests into ui/lint - Move repr tests into ui/repr - Move intrinsics tests into ui/intrinsics - Move tool lint tests into ui/tool-attributes - Move return tests into ui/return - Move pattern tests into ui/patttern - Move range tests into ui/range - Move foreign-fn tests into ui/foreign - Move orphan-check tests into ui/coherence - Move inference tests into ui/inference - Reduce ROOT_ENTRY_LIMIT
2024-05-16feat: add unit testcardigan1008-0/+17
2024-04-14Fix 1-tuple value suggestionMichael Goulet-2/+2
2024-04-14Suggest value on bare returnMichael Goulet-0/+22
2024-03-16Note that type param is chosen by caller when suggesting return impl Trait许杰友 Jieyou Xu (Joe)-0/+63
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-3/+3
2023-11-24Show number in error message even for one errorNilstrieb-5/+5
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-10-18Tweak wording of type errors involving type paramsEsteban Küber-6/+6
Fix #78206.
2023-10-04Point to where missing return type should goMichael Goulet-2/+2
2023-08-10Bugfix: 'can_have_side_effects()' would return 'false' for ↵Morten Lohne-0/+59
struct/enum/array/tuple literals unless *all* sub-expressions had side effects. This would easily allow side effects to slip through, and also wrongly label empty literals as having side effects. Add some tests for the last point
2023-06-26`hir`: Add `Become` expression kindMaybe Waffle-10/+10
2023-01-30Modify primary span label for E0308Esteban Küber-3/+3
The previous output was unintuitive to users.
2023-01-11Move /src/test to /testsAlbert Larsan-0/+593