Skip to content

Commit a795419

Browse files
committed
Merge E0410 into E0408
1 parent cf8a1b0 commit a795419

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

src/librustc_resolve/diagnostics.rs

+12-14
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,14 @@ 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 */}
536535
}
537536
```
538537
539538
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
539+
to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
541540
cases `y` is set to some value.
542541
"##,
543542

@@ -548,36 +547,35 @@ across patterns.
548547
Example of erroneous code:
549548
550549
```compile_fail
551-
let x = (0,2);
550+
let x = (0, 2);
552551
match x {
553552
(0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
554-
// different mode in pattern #2 than
555-
// in pattern #1
553+
// different mode in pattern #2
554+
// than in pattern #1
556555
_ => ()
557556
}
558557
```
559558
560-
561559
Here, `y` is bound by-value in one case and by-reference in the other.
562560
563561
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.
562+
Generally using `ref` or `ref mut` where not already used will fix this:
565563
566564
```
567-
let x = (0,2);
565+
let x = (0, 2);
568566
match x {
569567
(0, ref y) | (ref y, 0) => { /* use y */}
570568
_ => ()
571569
}
572570
```
573571
574-
Alternatively, split the pattern
572+
Alternatively, split the pattern:
575573
576-
```compile_fail
577-
let x = (0,2);
574+
```
575+
let x = (0, 2);
578576
match x {
579-
(0, ref y) => { /* use y */}
580577
(y, 0) => { /* use y */ }
578+
(0, ref y) => { /* use y */}
581579
_ => ()
582580
}
583581
```

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)