Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1eaeaaf
Add FileCheck for array_index.rs, boolean_identities.rs and cast.rs
sfzhu93 Jan 8, 2024
e05c779
Add FileCheck for checked.rs and default_boxed_slice.rs.
sfzhu93 Jan 8, 2024
33e5d85
Add FileCheck for enum.rs
sfzhu93 Jan 8, 2024
24aefa0
Add FileCheck for if.rs, inherit_overflow.rs, issue_81605.rs
sfzhu93 Jan 9, 2024
9452d7e
Add FileCheck to 3 tests: large_array_index, mult_by_zero, and offset_of
sfzhu93 Jan 9, 2024
e9152e2
Add FileCheck to 3 tests: ref_without_sb, repeat, repr_transparent
sfzhu93 Jan 9, 2024
3ab1d5d
Add FileCheck to 3 tests: self_assign_add, self_assign, and sibling_ptr
sfzhu93 Jan 9, 2024
d765e3a
Add FileCheck to slice_len.rs
sfzhu93 Jan 9, 2024
732f6a1
Add FileCheck to struct.rs
sfzhu93 Jan 9, 2024
1adda9a
Add FileCheck to terminator.rs and tuple.rs
sfzhu93 Jan 9, 2024
7135168
Add FileCheck for enum.rs
sfzhu93 Jan 8, 2024
d63f10b
resolve code reviews
sfzhu93 Jan 12, 2024
1c886d7
resolve code reviews
sfzhu93 Jan 12, 2024
cd77d59
update enum.rs for code review
sfzhu93 Jan 13, 2024
5747ece
add FIXME for default_boxed_slice.rs
sfzhu93 Jan 15, 2024
edba949
update misuse of check-label
sfzhu93 Jan 20, 2024
7ad307d
finish a pattern in `enum.rs`
sfzhu93 Jan 20, 2024
65b1083
update enum.rs
sfzhu93 Jan 23, 2024
699b59c
update terminator.rs
sfzhu93 Jan 29, 2024
44d8ecb
Only suggest removal of `as_*` and `to_` conversion methods on E0308
estebank Jan 29, 2024
f9e2a6b
Make `Diagnostic::is_error` return false for `Level::FailureNote`.
nnethercote Jan 30, 2024
8b25343
Tighten the assertion in `downgrade_to_delayed_bug`.
nnethercote Jan 31, 2024
6a48407
Remove unnecessary setting of `suppressed_expected_diag`.
nnethercote Jan 31, 2024
b38c36b
Refactor `emit_diagnostic`.
nnethercote Jan 31, 2024
23510b2
Split `Level::DelayedBug` in two.
nnethercote Jan 31, 2024
c4c22b0
On E0277 be clearer about implicit `Sized` bounds on type params and …
estebank Jan 24, 2024
95d9009
Change incr comp test when adding explicit `Sized` bound
estebank Jan 25, 2024
8b0ab54
review comment: change wording
estebank Jan 30, 2024
4feec41
`#![feature(inline_const_pat)]` is no longer incomplete
matthewjasper Feb 1, 2024
0148da3
put pnkfelix (me) back on the review queue.
pnkfelix Feb 1, 2024
02320b5
Improve the diagnostics for unused generic parameters
fmease Feb 1, 2024
bedd81e
add test for try-block-in-match-arm
Fishrock123 Feb 1, 2024
2c0030f
Correctly check `never_type` feature gating
GuillaumeGomez Feb 1, 2024
0f21e45
Update `never_type` feature gate ui test
GuillaumeGomez Feb 1, 2024
0df6dfd
fix rebase
estebank Feb 1, 2024
dabde2d
Rollup merge of #119759 - sfzhu93:master, r=cjgillot
matthiaskrgr Feb 1, 2024
3bfa58a
Rollup merge of #120323 - estebank:issue-120178, r=fmease
matthiaskrgr Feb 1, 2024
7041892
Rollup merge of #120473 - estebank:issue-114329, r=TaKO8Ki
matthiaskrgr Feb 1, 2024
219b2da
Rollup merge of #120520 - nnethercote:rename-good-path, r=oli-obk
matthiaskrgr Feb 1, 2024
433b519
Rollup merge of #120540 - Fishrock123:test-try-block-in-match-arm, r=…
matthiaskrgr Feb 1, 2024
ccfbe47
Rollup merge of #120547 - matthewjasper:complete-inline-const-pat, r=…
matthiaskrgr Feb 1, 2024
e591ae7
Rollup merge of #120552 - GuillaumeGomez:never-type-feature-gate, r=c…
matthiaskrgr Feb 1, 2024
00e1441
Rollup merge of #120555 - pnkfelix:put-pnkfelix-back-on-review-queue,…
matthiaskrgr Feb 1, 2024
4b3423b
Rollup merge of #120556 - fmease:improve-unused-generic-param-diags, …
matthiaskrgr Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only suggest removal of as_* and to_ conversion methods on E0308
Instead of

```
error[E0308]: mismatched types
 --> tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.rs:9:5
  |
4 | fn get_name() -> String {
  |                  ------ expected `String` because of return type
...
9 |     your_name.trim() //~ ERROR E0308
  |     ^^^^^^^^^^^^^^^^ expected `String`, found `&str`
  |
help: try removing the method call
  |
9 -     your_name.trim()
9 +     your_name
```

output

```
error[E0308]: mismatched types
  --> $DIR/only-suggest-removal-of-conversion-method-calls.rs:9:5
   |
LL | fn get_name() -> String {
   |                  ------ expected `String` because of return type
...
LL |     your_name.trim()
   |     ^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
   |     |
   |     expected `String`, found `&str`
```

Fix #114329.
  • Loading branch information
estebank committed Jan 29, 2024
commit 44d8ecbfb85d1649a4267e33c847f79a125b99f9
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr.kind
&& let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr)
&& self.can_coerce(recv_ty, expected)
&& let name = method.name.as_str()
&& (name.starts_with("to_") || name.starts_with("as_") || name == "into")
{
let span = if let Some(recv_span) = recv_expr.span.find_ancestor_inside(expr.span) {
expr.span.with_lo(recv_span.hi())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-rustfix
use std::io::stdin;

fn get_name() -> String {
let mut your_name = String::new();
stdin()
.read_line(&mut your_name)
.expect("Failed to read the line for some reason");
your_name.trim().to_string() //~ ERROR E0308
}

fn main() {
println!("Hello, What is your name? ");
let your_name = get_name();
println!("Hello, {}", your_name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-rustfix
use std::io::stdin;

fn get_name() -> String {
let mut your_name = String::new();
stdin()
.read_line(&mut your_name)
.expect("Failed to read the line for some reason");
your_name.trim() //~ ERROR E0308
}

fn main() {
println!("Hello, What is your name? ");
let your_name = get_name();
println!("Hello, {}", your_name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/only-suggest-removal-of-conversion-method-calls.rs:9:5
|
LL | fn get_name() -> String {
| ------ expected `String` because of return type
...
LL | your_name.trim()
| ^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `&str`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.