Skip to content

Commit a8f7ec2

Browse files
authored
Rollup merge of #106499 - lyming2007:issue-105946-fix, r=estebank
fix [type error] for error E0029 and E0277 check explicitly for the type references error if ty.references_error() is true change the error to be err.delay_as_bug() and prevent the error E0029 and E0277 from emitting out this fix #105946
2 parents 4b094c5 + 10dbcf0 commit a8f7ec2

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+3
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
553553
(lhs, Some((true, rhs_ty, rhs_sp))) => one_side_err(rhs_sp, rhs_ty, lhs),
554554
_ => span_bug!(span, "Impossible, verified above."),
555555
}
556+
if (lhs, rhs).references_error() {
557+
err.downgrade_to_delayed_bug();
558+
}
556559
if self.tcx.sess.teach(&err.get_code().unwrap()) {
557560
err.note(
558561
"In a match expression, only numbers and characters can be matched \

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
14071407

14081408
self.note_obligation_cause(&mut err, &obligation);
14091409
self.point_at_returns_when_relevant(&mut err, &obligation);
1410-
14111410
err.emit();
14121411
}
14131412
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub trait TypeErrCtxtExt<'tcx> {
248248

249249
fn point_at_returns_when_relevant(
250250
&self,
251-
err: &mut Diagnostic,
251+
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
252252
obligation: &PredicateObligation<'tcx>,
253253
);
254254

@@ -1685,7 +1685,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16851685

16861686
fn point_at_returns_when_relevant(
16871687
&self,
1688-
err: &mut Diagnostic,
1688+
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
16891689
obligation: &PredicateObligation<'tcx>,
16901690
) {
16911691
match obligation.cause.code().peel_derives() {
@@ -1707,7 +1707,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
17071707
for expr in &visitor.returns {
17081708
if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) {
17091709
let ty = self.resolve_vars_if_possible(returned_ty);
1710-
err.span_label(expr.span, &format!("this returned value is of type `{}`", ty));
1710+
if ty.references_error() {
1711+
// don't print out the [type error] here
1712+
err.delay_as_bug();
1713+
} else {
1714+
err.span_label(
1715+
expr.span,
1716+
&format!("this returned value is of type `{}`", ty),
1717+
);
1718+
}
17111719
}
17121720
}
17131721
}

src/test/ui/typeck/issue-105946.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn digit() -> str {
2+
return {};
3+
//~^ ERROR: mismatched types [E0308]
4+
}
5+
fn main() {
6+
let [_y..] = [box 1, box 2];
7+
//~^ ERROR: cannot find value `_y` in this scope [E0425]
8+
//~| ERROR: `X..` patterns in slices are experimental [E0658]
9+
//~| ERROR: box expression syntax is experimental; you can call `Box::new` instead [E0658]
10+
//~| ERROR: box expression syntax is experimental; you can call `Box::new` instead [E0658]
11+
//~| ERROR: pattern requires 1 element but array has 2 [E0527]
12+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error[E0425]: cannot find value `_y` in this scope
2+
--> $DIR/issue-105946.rs:6:10
3+
|
4+
LL | let [_y..] = [box 1, box 2];
5+
| ^^ not found in this scope
6+
7+
error[E0658]: `X..` patterns in slices are experimental
8+
--> $DIR/issue-105946.rs:6:10
9+
|
10+
LL | let [_y..] = [box 1, box 2];
11+
| ^^^^
12+
|
13+
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
14+
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
15+
16+
error[E0658]: box expression syntax is experimental; you can call `Box::new` instead
17+
--> $DIR/issue-105946.rs:6:19
18+
|
19+
LL | let [_y..] = [box 1, box 2];
20+
| ^^^^^
21+
|
22+
= note: see issue #49733 <https://github.com/rust-lang/rust/issues/49733> for more information
23+
= help: add `#![feature(box_syntax)]` to the crate attributes to enable
24+
25+
error[E0658]: box expression syntax is experimental; you can call `Box::new` instead
26+
--> $DIR/issue-105946.rs:6:26
27+
|
28+
LL | let [_y..] = [box 1, box 2];
29+
| ^^^^^
30+
|
31+
= note: see issue #49733 <https://github.com/rust-lang/rust/issues/49733> for more information
32+
= help: add `#![feature(box_syntax)]` to the crate attributes to enable
33+
34+
error[E0308]: mismatched types
35+
--> $DIR/issue-105946.rs:2:10
36+
|
37+
LL | return {};
38+
| ^^ expected `str`, found `()`
39+
40+
error[E0527]: pattern requires 1 element but array has 2
41+
--> $DIR/issue-105946.rs:6:9
42+
|
43+
LL | let [_y..] = [box 1, box 2];
44+
| ^^^^^^ expected 2 elements
45+
46+
error: aborting due to 6 previous errors
47+
48+
Some errors have detailed explanations: E0308, E0425, E0527, E0658.
49+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)