Skip to content

Commit 84843b7

Browse files
committed
Merge E0410 into E0408
1 parent cf8a1b0 commit 84843b7

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

src/librustc_resolve/diagnostics.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,11 @@ Example of erroneous code:
506506
```compile_fail
507507
match x {
508508
Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is
509-
// not bound in pattern #2
509+
// not bound in pattern #2
510510
_ => ()
511511
}
512512
```
513513
514-
515514
Here, `y` is bound to the contents of the `Some` and can be used within the
516515
block corresponding to the match arm. However, in case `x` is `None`, we have
517516
not specified what `y` is, and the block will use a nonexistent variable.
@@ -530,14 +529,15 @@ or, bind the variable to a field of the same type in all sub-patterns of the
530529
or pattern:
531530
532531
```
533-
let x = (0,2);
532+
let x = (0, 2);
534533
match x {
535534
(0, y) | (y, 0) => { /* use y */}
535+
_ => {}
536536
}
537537
```
538538
539539
In this example, if `x` matches the pattern `(0, _)`, the second field is set
540-
to `y`, and if it matches `(_, 0)`, the first field is set to `y`, so in all
540+
to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
541541
cases `y` is set to some value.
542542
"##,
543543

@@ -548,36 +548,35 @@ across patterns.
548548
Example of erroneous code:
549549
550550
```compile_fail
551-
let x = (0,2);
551+
let x = (0, 2);
552552
match x {
553553
(0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
554-
// different mode in pattern #2 than
555-
// in pattern #1
554+
// different mode in pattern #2
555+
// than in pattern #1
556556
_ => ()
557557
}
558558
```
559559
560-
561560
Here, `y` is bound by-value in one case and by-reference in the other.
562561
563562
To fix this error, just use the same mode in both cases.
564-
Generally using `ref` or `ref mut` where not already used will fix this.
563+
Generally using `ref` or `ref mut` where not already used will fix this:
565564
566-
```
567-
let x = (0,2);
565+
```ignore
566+
let x = (0, 2);
568567
match x {
569568
(0, ref y) | (ref y, 0) => { /* use y */}
570569
_ => ()
571570
}
572571
```
573572
574-
Alternatively, split the pattern
573+
Alternatively, split the pattern:
575574
576-
```compile_fail
577-
let x = (0,2);
575+
```
576+
let x = (0, 2);
578577
match x {
579-
(0, ref y) => { /* use y */}
580578
(y, 0) => { /* use y */ }
579+
(0, ref y) => { /* use y */}
581580
_ => ()
582581
}
583582
```

src/librustc_resolve/lib.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ enum ResolutionError<'a> {
126126
TypeNotMemberOfTrait(Name, &'a str),
127127
/// error E0438: const is not a member of trait
128128
ConstNotMemberOfTrait(Name, &'a str),
129-
/// error E0408: variable `{}` from pattern #1 is not bound in pattern
130-
VariableNotBoundInPattern(Name, usize),
129+
/// error E0408: variable `{}` from pattern #{} is not bound in pattern #{}
130+
VariableNotBoundInPattern(Name, usize, usize),
131131
/// error E0409: variable is bound with different mode in pattern #{} than in pattern #1
132132
VariableBoundWithDifferentMode(Name, usize),
133-
/// error E0410: variable from pattern is not bound in pattern #1
134-
VariableNotBoundInParentPattern(Name, usize),
135133
/// error E0411: use of `Self` outside of an impl or trait
136134
SelfUsedOutsideImplOrTrait,
137135
/// error E0412: use of undeclared
@@ -272,13 +270,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
272270
const_,
273271
trait_)
274272
}
275-
ResolutionError::VariableNotBoundInPattern(variable_name, pattern_number) => {
273+
ResolutionError::VariableNotBoundInPattern(variable_name, from, to) => {
276274
struct_span_err!(resolver.session,
277275
span,
278276
E0408,
279-
"variable `{}` from pattern #1 is not bound in pattern #{}",
277+
"variable `{}` from pattern #{} is not bound in pattern #{}",
280278
variable_name,
281-
pattern_number)
279+
from,
280+
to)
282281
}
283282
ResolutionError::VariableBoundWithDifferentMode(variable_name, pattern_number) => {
284283
struct_span_err!(resolver.session,
@@ -289,14 +288,6 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
289288
variable_name,
290289
pattern_number)
291290
}
292-
ResolutionError::VariableNotBoundInParentPattern(variable_name, pattern_number) => {
293-
struct_span_err!(resolver.session,
294-
span,
295-
E0410,
296-
"variable `{}` from pattern #{} is not bound in pattern #1",
297-
variable_name,
298-
pattern_number)
299-
}
300291
ResolutionError::SelfUsedOutsideImplOrTrait => {
301292
struct_span_err!(resolver.session,
302293
span,
@@ -2038,7 +2029,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20382029
None => {
20392030
resolve_error(self,
20402031
p.span,
2041-
ResolutionError::VariableNotBoundInPattern(key, i + 1));
2032+
ResolutionError::VariableNotBoundInPattern(key, 1, i + 1));
20422033
}
20432034
Some(binding_i) => {
20442035
if binding_0.binding_mode != binding_i.binding_mode {
@@ -2055,7 +2046,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20552046
if !map_0.contains_key(&key) {
20562047
resolve_error(self,
20572048
binding.span,
2058-
ResolutionError::VariableNotBoundInParentPattern(key, i + 1));
2049+
ResolutionError::VariableNotBoundInPattern(key, i + 1, 1));
20592050
}
20602051
}
20612052
}

0 commit comments

Comments
 (0)