fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
pat.walk(|p| {
if let PatKind::Binding(_, _, ident, None) = p.node {
- let bm = *cx.tables
- .pat_binding_modes()
- .get(p.hir_id)
- .expect("missing binding mode");
-
- if bm != ty::BindByValue(hir::MutImmutable) {
- // Nothing to check.
- return true;
- }
- let pat_ty = cx.tables.pat_ty(p);
- if let ty::TyAdt(edef, _) = pat_ty.sty {
- if edef.is_enum() && edef.variants.iter().any(|variant| {
- variant.name == ident.name && variant.ctor_kind == CtorKind::Const
- }) {
- let ty_path = cx.tcx.item_path_str(edef.did);
- let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
- "pattern binding `{}` is named the same as one \
- of the variants of the type `{}`",
- ident, ty_path);
- err.span_suggestion_with_applicability(
- p.span,
- "to match on the variant, qualify the path",
- format!("{}::{}", ty_path, ident),
- Applicability::MachineApplicable
- );
- err.emit();
+ if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
+ if bm != ty::BindByValue(hir::MutImmutable) {
+ // Nothing to check.
+ return true;
+ }
+ let pat_ty = cx.tables.pat_ty(p);
+ if let ty::TyAdt(edef, _) = pat_ty.sty {
+ if edef.is_enum() && edef.variants.iter().any(|variant| {
+ variant.name == ident.name && variant.ctor_kind == CtorKind::Const
+ }) {
+ let ty_path = cx.tcx.item_path_str(edef.did);
+ let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
+ "pattern binding `{}` is named the same as one \
+ of the variants of the type `{}`",
+ ident, ty_path);
+ err.span_suggestion_with_applicability(
+ p.span,
+ "to match on the variant, qualify the path",
+ format!("{}::{}", ty_path, ident),
+ Applicability::MachineApplicable
+ );
+ err.emit();
+ }
}
+ } else {
+ cx.tcx.sess.delay_span_bug(p.span, "missing binding mode");
}
}
true
// except according to those terms.
fn main() {
- |_: [_; return || {}] | {}
+ |_: [_; return || {}] | {};
//~^ ERROR return statement outside of function body
-}
-fn foo() {
[(); return || {}];
//~^ ERROR return statement outside of function body
-}
-fn bar() {
[(); return |ice| {}];
//~^ ERROR return statement outside of function body
+
+ [(); return while let Some(n) = Some(0) {}];
+ //~^ ERROR return statement outside of function body
}
error[E0572]: return statement outside of function body
--> $DIR/issue-51714.rs:12:14
|
-LL | |_: [_; return || {}] | {}
+LL | |_: [_; return || {}] | {};
| ^^^^^^^^^^^^
error[E0572]: return statement outside of function body
- --> $DIR/issue-51714.rs:17:10
+ --> $DIR/issue-51714.rs:15:10
|
LL | [(); return || {}];
| ^^^^^^^^^^^^
error[E0572]: return statement outside of function body
- --> $DIR/issue-51714.rs:22:10
+ --> $DIR/issue-51714.rs:18:10
|
LL | [(); return |ice| {}];
| ^^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error[E0572]: return statement outside of function body
+ --> $DIR/issue-51714.rs:21:10
+ |
+LL | [(); return while let Some(n) = Some(0) {}];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0572`.