Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions compiler/rustc_error_codes/src/error_codes/E0071.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ form of initializer was used.
For example, the code above can be fixed to:

```
enum Foo {
FirstValue(i32)
}
type U32 = u32;
let t: U32 = 4;
```

fn main() {
let u = Foo::FirstValue(0i32);
or:

let t = 4;
}
```
struct U32 { value: u32 }
let t = U32 { value: 4 };
```
28 changes: 19 additions & 9 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

Some((variant, ty))
} else {
struct_span_err!(
self.tcx.sess,
path_span,
E0071,
"expected struct, variant or union type, found {}",
ty.sort_string(self.tcx)
)
.span_label(path_span, "not a struct")
.emit();
match ty.kind() {
ty::Error(_) => {
// E0071 might be caused by a spelling error, which will have
// already caused an error message and probably a suggestion
// elsewhere. Refrain from emitting more unhelpful errors here
// (issue #88844).
}
_ => {
struct_span_err!(
self.tcx.sess,
path_span,
E0071,
"expected struct, variant or union type, found {}",
ty.sort_string(self.tcx)
)
.span_label(path_span, "not a struct")
.emit();
}
}
None
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/typeck/issue-88844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for #88844.

struct Struct { value: i32 }
//~^ NOTE: similarly named struct `Struct` defined here

impl Stuct {
//~^ ERROR: cannot find type `Stuct` in this scope [E0412]
//~| HELP: a struct with a similar name exists
fn new() -> Self {
Self { value: 42 }
}
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/typeck/issue-88844.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0412]: cannot find type `Stuct` in this scope
--> $DIR/issue-88844.rs:6:6
|
LL | struct Struct { value: i32 }
| ------------- similarly named struct `Struct` defined here
...
LL | impl Stuct {
| ^^^^^ help: a struct with a similar name exists: `Struct`

error: aborting due to previous error

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