1
Fork 0

Rollup merge of #69452 - Centril:typeck-pat, r=estebank

typeck: use `Pattern` obligation cause more for better diagnostics

r? @estebank
This commit is contained in:
Mazdak Farrokhzad 2020-02-28 17:17:28 +01:00 committed by GitHub
commit a245221497
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 284 additions and 102 deletions

View file

@ -153,17 +153,13 @@ pub struct Map<'hir> {
hir_to_node_id: FxHashMap<HirId, NodeId>, hir_to_node_id: FxHashMap<HirId, NodeId>,
} }
struct ParentHirIterator<'map, 'hir> { /// An iterator that walks up the ancestor tree of a given `HirId`.
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
pub struct ParentHirIterator<'map, 'hir> {
current_id: HirId, current_id: HirId,
map: &'map Map<'hir>, map: &'map Map<'hir>,
} }
impl<'map, 'hir> ParentHirIterator<'map, 'hir> {
fn new(current_id: HirId, map: &'map Map<'hir>) -> Self {
Self { current_id, map }
}
}
impl<'hir> Iterator for ParentHirIterator<'_, 'hir> { impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
type Item = (HirId, Node<'hir>); type Item = (HirId, Node<'hir>);
@ -618,6 +614,12 @@ impl<'hir> Map<'hir> {
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id) self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
} }
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> {
ParentHirIterator { current_id, map: self }
}
/// Checks if the node is an argument. An argument is a local variable whose /// Checks if the node is an argument. An argument is a local variable whose
/// immediate parent is an item or a closure. /// immediate parent is an item or a closure.
pub fn is_argument(&self, id: HirId) -> bool { pub fn is_argument(&self, id: HirId) -> bool {
@ -684,7 +686,7 @@ impl<'hir> Map<'hir> {
/// } /// }
/// ``` /// ```
pub fn get_return_block(&self, id: HirId) -> Option<HirId> { pub fn get_return_block(&self, id: HirId) -> Option<HirId> {
let mut iter = ParentHirIterator::new(id, &self).peekable(); let mut iter = self.parent_iter(id).peekable();
let mut ignore_tail = false; let mut ignore_tail = false;
if let Some(entry) = self.find_entry(id) { if let Some(entry) = self.find_entry(id) {
if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = entry.node { if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = entry.node {
@ -731,7 +733,7 @@ impl<'hir> Map<'hir> {
/// in the HIR which is recorded by the map and is an item, either an item /// in the HIR which is recorded by the map and is an item, either an item
/// in a module, trait, or impl. /// in a module, trait, or impl.
pub fn get_parent_item(&self, hir_id: HirId) -> HirId { pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) { for (hir_id, node) in self.parent_iter(hir_id) {
match node { match node {
Node::Crate Node::Crate
| Node::Item(_) | Node::Item(_)
@ -753,7 +755,7 @@ impl<'hir> Map<'hir> {
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no /// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map. /// module parent is in this map.
pub fn get_module_parent_node(&self, hir_id: HirId) -> HirId { pub fn get_module_parent_node(&self, hir_id: HirId) -> HirId {
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) { for (hir_id, node) in self.parent_iter(hir_id) {
if let Node::Item(&Item { kind: ItemKind::Mod(_), .. }) = node { if let Node::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
return hir_id; return hir_id;
} }
@ -767,7 +769,7 @@ impl<'hir> Map<'hir> {
/// Used by error reporting when there's a type error in a match arm caused by the `match` /// Used by error reporting when there's a type error in a match arm caused by the `match`
/// expression needing to be unit. /// expression needing to be unit.
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> { pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
for (_, node) in ParentHirIterator::new(hir_id, &self) { for (_, node) in self.parent_iter(hir_id) {
match node { match node {
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => { Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
break; break;
@ -788,7 +790,7 @@ impl<'hir> Map<'hir> {
/// Returns the nearest enclosing scope. A scope is roughly an item or block. /// Returns the nearest enclosing scope. A scope is roughly an item or block.
pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> { pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> {
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) { for (hir_id, node) in self.parent_iter(hir_id) {
if match node { if match node {
Node::Item(i) => match i.kind { Node::Item(i) => match i.kind {
ItemKind::Fn(..) ItemKind::Fn(..)

View file

@ -43,7 +43,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>, expected: Ty<'tcx>,
actual: Ty<'tcx>, actual: Ty<'tcx>,
) -> Option<DiagnosticBuilder<'tcx>> { ) -> Option<DiagnosticBuilder<'tcx>> {
let cause = &self.misc(sp); self.demand_suptype_with_origin(&self.misc(sp), expected, actual)
}
pub fn demand_suptype_with_origin(
&self,
cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
) -> Option<DiagnosticBuilder<'tcx>> {
match self.at(cause, self.param_env).sup(expected, actual) { match self.at(cause, self.param_env).sup(expected, actual) {
Ok(InferOk { obligations, value: () }) => { Ok(InferOk { obligations, value: () }) => {
self.register_predicates(obligations); self.register_predicates(obligations);

View file

@ -9,9 +9,9 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{HirId, Pat, PatKind}; use rustc_hir::{HirId, Pat, PatKind};
use rustc_infer::infer; use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Pattern; use rustc_infer::traits::{ObligationCause, Pattern};
use rustc_span::hygiene::DesugaringKind; use rustc_span::hygiene::DesugaringKind;
use rustc_span::Span; use rustc_span::source_map::{Span, Spanned};
use syntax::ast; use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name; use syntax::util::lev_distance::find_best_match_for_name;
@ -66,6 +66,11 @@ struct TopInfo<'tcx> {
} }
impl<'tcx> FnCtxt<'_, 'tcx> { impl<'tcx> FnCtxt<'_, 'tcx> {
fn pattern_cause(&self, ti: TopInfo<'tcx>, cause_span: Span) -> ObligationCause<'tcx> {
let code = Pattern { span: ti.span, root_ty: ti.expected, origin_expr: ti.origin_expr };
self.cause(cause_span, code)
}
fn demand_eqtype_pat_diag( fn demand_eqtype_pat_diag(
&self, &self,
cause_span: Span, cause_span: Span,
@ -73,9 +78,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
actual: Ty<'tcx>, actual: Ty<'tcx>,
ti: TopInfo<'tcx>, ti: TopInfo<'tcx>,
) -> Option<DiagnosticBuilder<'tcx>> { ) -> Option<DiagnosticBuilder<'tcx>> {
let code = Pattern { span: ti.span, root_ty: ti.expected, origin_expr: ti.origin_expr }; self.demand_eqtype_with_origin(&self.pattern_cause(ti, cause_span), expected, actual)
let cause = self.cause(cause_span, code);
self.demand_eqtype_with_origin(&cause, expected, actual)
} }
fn demand_eqtype_pat( fn demand_eqtype_pat(
@ -152,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, def_bm, ti) self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, def_bm, ti)
} }
PatKind::Path(ref qpath) => { PatKind::Path(ref qpath) => {
self.check_pat_path(pat, path_res.unwrap(), qpath, expected) self.check_pat_path(pat, path_res.unwrap(), qpath, expected, ti)
} }
PatKind::Struct(ref qpath, fields, etc) => { PatKind::Struct(ref qpath, fields, etc) => {
self.check_pat_struct(pat, qpath, fields, etc, expected, def_bm, ti) self.check_pat_struct(pat, qpath, fields, etc, expected, def_bm, ti)
@ -361,16 +364,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Byte string patterns behave the same way as array patterns // Byte string patterns behave the same way as array patterns
// They can denote both statically and dynamically-sized byte arrays. // They can denote both statically and dynamically-sized byte arrays.
let mut pat_ty = ty; let mut pat_ty = ty;
if let hir::ExprKind::Lit(ref lt) = lt.kind { if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(_), .. }) = lt.kind {
if let ast::LitKind::ByteStr(_) = lt.node { let expected = self.structurally_resolved_type(span, expected);
let expected_ty = self.structurally_resolved_type(span, expected); if let ty::Ref(_, ty::TyS { kind: ty::Slice(_), .. }, _) = expected.kind {
if let ty::Ref(_, r_ty, _) = expected_ty.kind { let tcx = self.tcx;
if let ty::Slice(_) = r_ty.kind { pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
let tcx = self.tcx;
pat_ty =
tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
}
}
} }
} }
@ -384,7 +382,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// &'static str <: expected // &'static str <: expected
// //
// then that's equivalent to there existing a LUB. // then that's equivalent to there existing a LUB.
if let Some(mut err) = self.demand_suptype_diag(span, expected, pat_ty) { let cause = self.pattern_cause(ti, span);
if let Some(mut err) = self.demand_suptype_with_origin(&cause, expected, pat_ty) {
err.emit_unless( err.emit_unless(
ti.span ti.span
.filter(|&s| { .filter(|&s| {
@ -543,8 +542,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If there are multiple arms, make sure they all agree on // If there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be. // what the type of the binding `x` ought to be.
if var_id != pat.hir_id { if var_id != pat.hir_id {
let vt = self.local_ty(pat.span, var_id).decl_ty; self.check_binding_alt_eq_ty(pat.span, var_id, local_ty, ti);
self.demand_eqtype_pat(pat.span, vt, local_ty, ti);
} }
if let Some(p) = sub { if let Some(p) = sub {
@ -554,6 +552,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
local_ty local_ty
} }
fn check_binding_alt_eq_ty(&self, span: Span, var_id: HirId, ty: Ty<'tcx>, ti: TopInfo<'tcx>) {
let var_ty = self.local_ty(span, var_id).decl_ty;
if let Some(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) {
let hir = self.tcx.hir();
let var_ty = self.resolve_vars_with_obligations(var_ty);
let msg = format!("first introduced with type `{}` here", var_ty);
err.span_label(hir.span(var_id), msg);
let in_arm = hir.parent_iter(var_id).any(|(_, n)| matches!(n, hir::Node::Arm(..)));
let pre = if in_arm { "in the same arm, " } else { "" };
err.note(&format!("{}a binding must have the same type in all alternatives", pre));
err.emit();
}
}
fn borrow_pat_suggestion( fn borrow_pat_suggestion(
&self, &self,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
@ -659,6 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]), path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]),
qpath: &hir::QPath<'_>, qpath: &hir::QPath<'_>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
ti: TopInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
@ -684,7 +697,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Type-check the path. // Type-check the path.
let pat_ty = self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id).0; let pat_ty = self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id).0;
self.demand_suptype(pat.span, expected, pat_ty); if let Some(mut err) =
self.demand_suptype_with_origin(&self.pattern_cause(ti, pat.span), expected, pat_ty)
{
err.emit();
}
pat_ty pat_ty
} }
@ -901,7 +918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
let element_tys = tcx.mk_substs(element_tys_iter); let element_tys = tcx.mk_substs(element_tys_iter);
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys)); let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
if let Some(mut err) = self.demand_eqtype_diag(span, expected, pat_ty) { if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
err.emit(); err.emit();
// Walk subpatterns with an expected type of `err` in this case to silence // Walk subpatterns with an expected type of `err` in this case to silence
// further errors being emitted when using the bindings. #50333 // further errors being emitted when using the bindings. #50333
@ -1205,7 +1222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
let rptr_ty = self.new_ref_ty(pat.span, mutbl, inner_ty); let rptr_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
debug!("check_pat_ref: demanding {:?} = {:?}", expected, rptr_ty); debug!("check_pat_ref: demanding {:?} = {:?}", expected, rptr_ty);
let err = self.demand_eqtype_diag(pat.span, expected, rptr_ty); let err = self.demand_eqtype_pat_diag(pat.span, expected, rptr_ty, ti);
// Look for a case like `fn foo(&foo: u32)` and suggest // Look for a case like `fn foo(&foo: u32)` and suggest
// `fn foo(foo: &u32)` // `fn foo(foo: &u32)`

View file

@ -20,7 +20,7 @@ error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:32:10 --> $DIR/destructure-trait-ref.rs:32:10
| |
LL | let &&x = &1isize as &dyn T; LL | let &&x = &1isize as &dyn T;
| ^^ | ^^ ----------------- this expression has type `&dyn T`
| | | |
| expected trait object `dyn T`, found reference | expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x` | help: you can probably remove the explicit borrow: `x`
@ -32,7 +32,7 @@ error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:36:11 --> $DIR/destructure-trait-ref.rs:36:11
| |
LL | let &&&x = &(&1isize as &dyn T); LL | let &&&x = &(&1isize as &dyn T);
| ^^ | ^^ -------------------- this expression has type `&&dyn T`
| | | |
| expected trait object `dyn T`, found reference | expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x` | help: you can probably remove the explicit borrow: `x`

View file

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/elide-errors-on-mismatched-tuple.rs:14:9 --> $DIR/elide-errors-on-mismatched-tuple.rs:14:9
| |
LL | let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three LL | let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three
| ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements | ^^^^^^^^^ -------------------- this expression has type `(A, A)`
| |
| expected a tuple with 2 elements, found one with 3 elements
| |
= note: expected tuple `(A, A)` = note: expected tuple `(A, A)`
found tuple `(_, _, _)` found tuple `(_, _, _)`

View file

@ -12,6 +12,9 @@ LL | Some(k) => match k {
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-12552.rs:9:5 --> $DIR/issue-12552.rs:9:5
| |
LL | match t {
| - this expression has type `std::result::Result<_, {integer}>`
...
LL | None => () LL | None => ()
| ^^^^ expected enum `std::result::Result`, found enum `std::option::Option` | ^^^^ expected enum `std::result::Result`, found enum `std::option::Option`
| |

View file

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-37026.rs:6:9 --> $DIR/issue-37026.rs:6:9
| |
LL | let empty_struct::XEmpty2 = (); LL | let empty_struct::XEmpty2 = ();
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty2` | ^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()`
| |
| expected `()`, found struct `empty_struct::XEmpty2`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-37026.rs:7:9 --> $DIR/issue-37026.rs:7:9

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-5100.rs:8:9 --> $DIR/issue-5100.rs:8:9
| |
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | A::B => (), LL | A::B => (),
| ^^^^ expected tuple, found enum `A` | ^^^^ expected tuple, found enum `A`
| |
@ -10,6 +12,8 @@ LL | A::B => (),
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-5100.rs:17:9 --> $DIR/issue-5100.rs:17:9
| |
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | (true, false, false) => () LL | (true, false, false) => ()
| ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements | ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
| |
@ -19,6 +23,8 @@ LL | (true, false, false) => ()
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-5100.rs:25:9 --> $DIR/issue-5100.rs:25:9
| |
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | (true, false, false) => () LL | (true, false, false) => ()
| ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements | ^^^^^^^^^^^^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
| |
@ -39,6 +45,8 @@ LL | box (true, false) => ()
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-5100.rs:40:9 --> $DIR/issue-5100.rs:40:9
| |
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | &(true, false) => () LL | &(true, false) => ()
| ^^^^^^^^^^^^^^ expected tuple, found reference | ^^^^^^^^^^^^^^ expected tuple, found reference
| |

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-7867.rs:7:9 --> $DIR/issue-7867.rs:7:9
| |
LL | match (true, false) {
| ------------- this expression has type `(bool, bool)`
LL | A::B => (), LL | A::B => (),
| ^^^^ expected tuple, found enum `A` | ^^^^ expected tuple, found enum `A`
| |

View file

@ -1,6 +1,9 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/match-ill-type2.rs:4:9 --> $DIR/match-ill-type2.rs:4:9
| |
LL | match 1i32 {
| ---- this expression has type `i32`
LL | 1i32 => 1,
LL | 2u32 => 1, LL | 2u32 => 1,
| ^^^^ expected `i32`, found `u32` | ^^^^ expected `i32`, found `u32`

View file

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/match-tag-nullary.rs:4:40 --> $DIR/match-tag-nullary.rs:4:40
| |
LL | fn main() { let x: A = A::A; match x { B::B => { } } } LL | fn main() { let x: A = A::A; match x { B::B => { } } }
| ^^^^ expected enum `A`, found enum `B` | - ^^^^ expected enum `A`, found enum `B`
| |
| this expression has type `A`
error: aborting due to previous error error: aborting due to previous error

View file

@ -12,7 +12,11 @@ error[E0308]: mismatched types
LL | match x { LL | match x {
| - this expression has type `({integer}, {integer})` | - this expression has type `({integer}, {integer})`
LL | (0, ref y) | (y, 0) => {} LL | (0, ref y) | (y, 0) => {}
| ^ expected `&{integer}`, found integer | ----- ^ expected `&{integer}`, found integer
| |
| first introduced with type `&{integer}` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -3,7 +3,8 @@ error[E0308]: mismatched types
| |
LL | fn foo(&foo: Foo) { LL | fn foo(&foo: Foo) {
| ^^^^------ | ^^^^------
| | | | |
| | expected due to this
| expected struct `Foo`, found reference | expected struct `Foo`, found reference
| help: did you mean `foo`: `&Foo` | help: did you mean `foo`: `&Foo`
| |
@ -14,7 +15,7 @@ error[E0308]: mismatched types
--> $DIR/issue-38371.rs:18:9 --> $DIR/issue-38371.rs:18:9
| |
LL | fn agh(&&bar: &u32) { LL | fn agh(&&bar: &u32) {
| ^^^^ | ^^^^ ---- expected due to this
| | | |
| expected `u32`, found reference | expected `u32`, found reference
| help: you can probably remove the explicit borrow: `bar` | help: you can probably remove the explicit borrow: `bar`
@ -26,7 +27,9 @@ error[E0308]: mismatched types
--> $DIR/issue-38371.rs:21:8 --> $DIR/issue-38371.rs:21:8
| |
LL | fn bgh(&&bar: u32) { LL | fn bgh(&&bar: u32) {
| ^^^^^ expected `u32`, found reference | ^^^^^ --- expected due to this
| |
| expected `u32`, found reference
| |
= note: expected type `u32` = note: expected type `u32`
found reference `&_` found reference `&_`

View file

@ -3,6 +3,9 @@ error[E0308]: mismatched types
| |
LL | let &_ LL | let &_
| ^^ types differ in mutability | ^^ types differ in mutability
...
LL | = foo;
| --- this expression has type `&mut {integer}`
| |
= note: expected mutable reference `&mut {integer}` = note: expected mutable reference `&mut {integer}`
found reference `&_` found reference `&_`
@ -12,6 +15,9 @@ error[E0308]: mismatched types
| |
LL | let &mut _ LL | let &mut _
| ^^^^^^ types differ in mutability | ^^^^^^ types differ in mutability
...
LL | = bar;
| --- this expression has type `&{integer}`
| |
= note: expected reference `&{integer}` = note: expected reference `&{integer}`
found mutable reference `&mut _` found mutable reference `&mut _`

View file

@ -86,12 +86,14 @@ error[E0308]: mismatched types
--> $DIR/already-bound-name.rs:32:31 --> $DIR/already-bound-name.rs:32:31
| |
LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1)); LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
| ^ ------- this expression has type `E<E<{integer}>>` | - ^ ------- this expression has type `E<E<{integer}>>`
| | | | |
| expected integer, found enum `E` | | expected integer, found enum `E`
| first introduced with type `{integer}` here
| |
= note: expected type `{integer}` = note: expected type `{integer}`
found type `E<{integer}>` found type `E<{integer}>`
= note: a binding must have the same type in all alternatives
error: aborting due to 15 previous errors error: aborting due to 15 previous errors

View file

@ -52,23 +52,27 @@ error[E0308]: mismatched types
--> $DIR/inconsistent-modes.rs:11:25 --> $DIR/inconsistent-modes.rs:11:25
| |
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0); LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
| ^^^^^^^^^ -------------------- expected due to this | ----- ^^^^^^^^^ -------------------- expected due to this
| | | | |
| types differ in mutability | | types differ in mutability
| first introduced with type `&&u8` here
| |
= note: expected type `&&u8` = note: expected type `&&u8`
found type `&mut &mut u8` found type `&mut &mut u8`
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/inconsistent-modes.rs:14:31 --> $DIR/inconsistent-modes.rs:14:31
| |
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0)); LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
| ^^^^^^^^^ ----------- this expression has type `std::result::Result<({integer}, &{integer}), (_, _)>` | ----- ^^^^^^^^^ ----------- this expression has type `std::result::Result<({integer}, &{integer}), (_, _)>`
| | | | |
| types differ in mutability | | types differ in mutability
| first introduced with type `&{integer}` here
| |
= note: expected type `&{integer}` = note: expected type `&{integer}`
found type `&mut _` found type `&mut _`
= note: a binding must have the same type in all alternatives
error: aborting due to 9 previous errors error: aborting due to 9 previous errors

View file

@ -4,7 +4,11 @@ error[E0308]: mismatched types
LL | match Blah::A(1, 1, 2) { LL | match Blah::A(1, 1, 2) {
| ---------------- this expression has type `main::Blah` | ---------------- this expression has type `main::Blah`
LL | Blah::A(_, x, y) | Blah::B(x, y) => {} LL | Blah::A(_, x, y) | Blah::B(x, y) => {}
| ^ expected `usize`, found `isize` | - ^ expected `usize`, found `isize`
| |
| first introduced with type `usize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:17:44 --> $DIR/or-patterns-binding-type-mismatch.rs:17:44
@ -12,7 +16,11 @@ error[E0308]: mismatched types
LL | match Some(Blah::A(1, 1, 2)) { LL | match Some(Blah::A(1, 1, 2)) {
| ---------------------- this expression has type `std::option::Option<main::Blah>` | ---------------------- this expression has type `std::option::Option<main::Blah>`
LL | Some(Blah::A(_, x, y) | Blah::B(x, y)) => {} LL | Some(Blah::A(_, x, y) | Blah::B(x, y)) => {}
| ^ expected `usize`, found `isize` | - ^ expected `usize`, found `isize`
| |
| first introduced with type `usize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:21:19 --> $DIR/or-patterns-binding-type-mismatch.rs:21:19
@ -20,7 +28,11 @@ error[E0308]: mismatched types
LL | match (0u8, 1u16) { LL | match (0u8, 1u16) {
| ----------- this expression has type `(u8, u16)` | ----------- this expression has type `(u8, u16)`
LL | (x, y) | (y, x) => {} LL | (x, y) | (y, x) => {}
| ^ expected `u16`, found `u8` | - ^ expected `u16`, found `u8`
| |
| first introduced with type `u16` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:21:22 --> $DIR/or-patterns-binding-type-mismatch.rs:21:22
@ -28,7 +40,11 @@ error[E0308]: mismatched types
LL | match (0u8, 1u16) { LL | match (0u8, 1u16) {
| ----------- this expression has type `(u8, u16)` | ----------- this expression has type `(u8, u16)`
LL | (x, y) | (y, x) => {} LL | (x, y) | (y, x) => {}
| ^ expected `u8`, found `u16` | - ^ expected `u8`, found `u16`
| |
| first introduced with type `u8` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:26:41 --> $DIR/or-patterns-binding-type-mismatch.rs:26:41
@ -36,7 +52,11 @@ error[E0308]: mismatched types
LL | match Some((0u8, Some((1u16, 2u32)))) { LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {} LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u16`, found `u8` | - ^ expected `u16`, found `u8`
| |
| first introduced with type `u16` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:26:50 --> $DIR/or-patterns-binding-type-mismatch.rs:26:50
@ -44,7 +64,11 @@ error[E0308]: mismatched types
LL | match Some((0u8, Some((1u16, 2u32)))) { LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {} LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u8`, found `u16` | - ^ expected `u8`, found `u16`
| |
| first introduced with type `u8` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:26:59 --> $DIR/or-patterns-binding-type-mismatch.rs:26:59
@ -52,7 +76,11 @@ error[E0308]: mismatched types
LL | match Some((0u8, Some((1u16, 2u32)))) { LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {} LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u32`, found `u16` | - ^ expected `u32`, found `u16`
| |
| first introduced with type `u32` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:26:62 --> $DIR/or-patterns-binding-type-mismatch.rs:26:62
@ -60,123 +88,169 @@ error[E0308]: mismatched types
LL | match Some((0u8, Some((1u16, 2u32)))) { LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {} LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u8`, found `u32` | - first introduced with type `u8` here ^ expected `u8`, found `u32`
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:34:42 --> $DIR/or-patterns-binding-type-mismatch.rs:34:42
| |
LL | if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) { LL | if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
| ^ ---------------- this expression has type `main::Blah` | - ^ ---------------- this expression has type `main::Blah`
| | | | |
| expected `usize`, found `isize` | | expected `usize`, found `isize`
| first introduced with type `usize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:38:47 --> $DIR/or-patterns-binding-type-mismatch.rs:38:47
| |
LL | if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) { LL | if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
| ^ ---------------------- this expression has type `std::option::Option<main::Blah>` | - ^ ---------------------- this expression has type `std::option::Option<main::Blah>`
| | | | |
| expected `usize`, found `isize` | | expected `usize`, found `isize`
| first introduced with type `usize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:42:22 --> $DIR/or-patterns-binding-type-mismatch.rs:42:22
| |
LL | if let (x, y) | (y, x) = (0u8, 1u16) { LL | if let (x, y) | (y, x) = (0u8, 1u16) {
| ^ ----------- this expression has type `(u8, u16)` | - ^ ----------- this expression has type `(u8, u16)`
| | | | |
| expected `u16`, found `u8` | | expected `u16`, found `u8`
| first introduced with type `u16` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:42:25 --> $DIR/or-patterns-binding-type-mismatch.rs:42:25
| |
LL | if let (x, y) | (y, x) = (0u8, 1u16) { LL | if let (x, y) | (y, x) = (0u8, 1u16) {
| ^ ----------- this expression has type `(u8, u16)` | - ^ ----------- this expression has type `(u8, u16)`
| | | | |
| expected `u8`, found `u16` | | expected `u8`, found `u16`
| first introduced with type `u8` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:47:44 --> $DIR/or-patterns-binding-type-mismatch.rs:47:44
| |
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u16`, found `u8` | - ^ expected `u16`, found `u8`
| |
| first introduced with type `u16` here
... ...
LL | = Some((0u8, Some((1u16, 2u32)))) LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:47:53 --> $DIR/or-patterns-binding-type-mismatch.rs:47:53
| |
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u8`, found `u16` | - ^ expected `u8`, found `u16`
| |
| first introduced with type `u8` here
... ...
LL | = Some((0u8, Some((1u16, 2u32)))) LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:47:62 --> $DIR/or-patterns-binding-type-mismatch.rs:47:62
| |
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u32`, found `u16` | - ^ expected `u32`, found `u16`
| |
| first introduced with type `u32` here
... ...
LL | = Some((0u8, Some((1u16, 2u32)))) LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:47:65 --> $DIR/or-patterns-binding-type-mismatch.rs:47:65
| |
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u8`, found `u32` | - first introduced with type `u8` here ^ expected `u8`, found `u32`
... ...
LL | = Some((0u8, Some((1u16, 2u32)))) LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>` | ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:55:39 --> $DIR/or-patterns-binding-type-mismatch.rs:55:39
| |
LL | let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2); LL | let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2);
| ^ ---------------- this expression has type `main::Blah` | - ^ ---------------- this expression has type `main::Blah`
| | | | |
| expected `usize`, found `isize` | | expected `usize`, found `isize`
| first introduced with type `usize` here
|
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:58:19 --> $DIR/or-patterns-binding-type-mismatch.rs:58:19
| |
LL | let (x, y) | (y, x) = (0u8, 1u16); LL | let (x, y) | (y, x) = (0u8, 1u16);
| ^ ----------- this expression has type `(u8, u16)` | - ^ ----------- this expression has type `(u8, u16)`
| | | | |
| expected `u16`, found `u8` | | expected `u16`, found `u8`
| first introduced with type `u16` here
|
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:58:22 --> $DIR/or-patterns-binding-type-mismatch.rs:58:22
| |
LL | let (x, y) | (y, x) = (0u8, 1u16); LL | let (x, y) | (y, x) = (0u8, 1u16);
| ^ ----------- this expression has type `(u8, u16)` | - ^ ----------- this expression has type `(u8, u16)`
| | | | |
| expected `u8`, found `u16` | | expected `u8`, found `u16`
| first introduced with type `u8` here
|
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:62:42 --> $DIR/or-patterns-binding-type-mismatch.rs:62:42
| |
LL | fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {} LL | fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
| ^ ---- expected due to this | - ^ ---- expected due to this
| | | | |
| expected `usize`, found `isize` | | expected `usize`, found `isize`
| first introduced with type `usize` here
|
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:65:22 --> $DIR/or-patterns-binding-type-mismatch.rs:65:22
| |
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {} LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
| ^ --------- expected due to this | - ^ --------- expected due to this
| | | | |
| expected `u16`, found `u8` | | expected `u16`, found `u8`
| first introduced with type `u16` here
|
= note: a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/or-patterns-binding-type-mismatch.rs:65:25 --> $DIR/or-patterns-binding-type-mismatch.rs:65:25
| |
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {} LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
| ^ --------- expected due to this | - ^ --------- expected due to this
| | | | |
| expected `u8`, found `u16` | | expected `u8`, found `u16`
| first introduced with type `u8` here
|
= note: a binding must have the same type in all alternatives
error: aborting due to 22 previous errors error: aborting due to 22 previous errors

View file

@ -12,6 +12,8 @@ LL | (..) => {}
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/pat-tuple-bad-type.rs:10:9 --> $DIR/pat-tuple-bad-type.rs:10:9
| |
LL | match 0u8 {
| --- this expression has type `u8`
LL | (..) => {} LL | (..) => {}
| ^^^^ expected `u8`, found `()` | ^^^^ expected `u8`, found `()`

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:5:9 --> $DIR/pat-tuple-overfield.rs:5:9
| |
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {} LL | (1, 2, 3, 4) => {}
| ^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements | ^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
| |
@ -10,6 +12,9 @@ LL | (1, 2, 3, 4) => {}
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:6:9 --> $DIR/pat-tuple-overfield.rs:6:9
| |
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {}
LL | (1, 2, .., 3, 4) => {} LL | (1, 2, .., 3, 4) => {}
| ^^^^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements | ^^^^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
| |

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/pattern-ident-path-generics.rs:3:9 --> $DIR/pattern-ident-path-generics.rs:3:9
| |
LL | match Some("foo") {
| ----------- this expression has type `std::option::Option<&str>`
LL | None::<isize> => {} LL | None::<isize> => {}
| ^^^^^^^^^^^^^ expected `&str`, found `isize` | ^^^^^^^^^^^^^ expected `&str`, found `isize`
| |

View file

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/name-clash-nullary.rs:2:7 --> $DIR/name-clash-nullary.rs:2:7
| |
LL | let None: isize = 42; LL | let None: isize = 42;
| ^^^^ expected `isize`, found enum `std::option::Option` | ^^^^ ----- expected due to this
| |
| expected `isize`, found enum `std::option::Option`
| |
= note: expected type `isize` = note: expected type `isize`
found enum `std::option::Option<_>` found enum `std::option::Option<_>`

View file

@ -26,7 +26,11 @@ error[E0308]: mismatched types
LL | match x { LL | match x {
| - this expression has type `Opts` | - this expression has type `Opts`
LL | Opts::A(ref i) | Opts::B(i) => {} LL | Opts::A(ref i) | Opts::B(i) => {}
| ^ expected `&isize`, found `isize` | ----- ^ expected `&isize`, found `isize`
| |
| first introduced with type `&isize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/resolve-inconsistent-binding-mode.rs:16:32 --> $DIR/resolve-inconsistent-binding-mode.rs:16:32
@ -34,7 +38,11 @@ error[E0308]: mismatched types
LL | match x { LL | match x {
| - this expression has type `Opts` | - this expression has type `Opts`
LL | Opts::A(ref i) | Opts::B(i) => {} LL | Opts::A(ref i) | Opts::B(i) => {}
| ^ expected `&isize`, found `isize` | ----- ^ expected `&isize`, found `isize`
| |
| first introduced with type `&isize` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/resolve-inconsistent-binding-mode.rs:25:36 --> $DIR/resolve-inconsistent-binding-mode.rs:25:36
@ -42,10 +50,13 @@ error[E0308]: mismatched types
LL | match x { LL | match x {
| - this expression has type `Opts` | - this expression has type `Opts`
LL | Opts::A(ref mut i) | Opts::B(ref i) => {} LL | Opts::A(ref mut i) | Opts::B(ref i) => {}
| ^^^^^ types differ in mutability | --------- ^^^^^ types differ in mutability
| |
| first introduced with type `&mut isize` here
| |
= note: expected type `&mut isize` = note: expected type `&mut isize`
found type `&isize` found type `&isize`
= note: in the same arm, a binding must have the same type in all alternatives
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -89,7 +89,11 @@ error[E0308]: mismatched types
LL | match x { LL | match x {
| - this expression has type `(E, E)` | - this expression has type `(E, E)`
LL | (A, B) | (ref B, c) | (c, A) => () LL | (A, B) | (ref B, c) | (c, A) => ()
| ^^^^^ expected enum `E`, found `&E` | - ^^^^^ expected enum `E`, found `&E`
| |
| first introduced with type `E` here
|
= note: in the same arm, a binding must have the same type in all alternatives
error: aborting due to 9 previous errors error: aborting due to 9 previous errors

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/const.rs:14:9 --> $DIR/const.rs:14:9
| |
LL | match &f {
| -- this expression has type `&Foo`
LL | FOO => {}, LL | FOO => {},
| ^^^ expected `&Foo`, found struct `Foo` | ^^^ expected `&Foo`, found struct `Foo`

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/lit.rs:7:13 --> $DIR/lit.rs:7:13
| |
LL | match &s {
| -- this expression has type `&&str`
LL | "abc" => true, LL | "abc" => true,
| ^^^^^ expected `&str`, found `str` | ^^^^^ expected `&str`, found `str`
| |
@ -10,6 +12,8 @@ LL | "abc" => true,
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/lit.rs:16:9 --> $DIR/lit.rs:16:9
| |
LL | match &s {
| -- this expression has type `&&[u8]`
LL | b"abc" => true, LL | b"abc" => true,
| ^^^^^^ expected `&[u8]`, found array `[u8; 3]` | ^^^^^^ expected `&[u8]`, found array `[u8; 3]`
| |

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/slightly-nice-generic-literal-messages.rs:7:9 --> $DIR/slightly-nice-generic-literal-messages.rs:7:9
| |
LL | match Foo(1.1, marker::PhantomData) {
| ----------------------------- this expression has type `Foo<{float}, _>`
LL | 1 => {} LL | 1 => {}
| ^ expected struct `Foo`, found integer | ^ expected struct `Foo`, found integer
| |

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:4:10 --> $DIR/match-ergonomics.rs:4:10
| |
LL | match &x[..] {
| ------ this expression has type `&[i32]`
LL | [&v] => {}, LL | [&v] => {},
| ^^ | ^^
| | | |
@ -25,6 +27,8 @@ LL | [v] => {},
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:29:9 --> $DIR/match-ergonomics.rs:29:9
| |
LL | match y {
| - this expression has type `i32`
LL | &v => {}, LL | &v => {},
| ^^ | ^^
| | | |
@ -38,7 +42,7 @@ error[E0308]: mismatched types
--> $DIR/match-ergonomics.rs:40:13 --> $DIR/match-ergonomics.rs:40:13
| |
LL | if let [&v] = &x[..] {} LL | if let [&v] = &x[..] {}
| ^^ | ^^ ------ this expression has type `&[i32]`
| | | |
| expected `i32`, found reference | expected `i32`, found reference
| help: you can probably remove the explicit borrow: `v` | help: you can probably remove the explicit borrow: `v`

View file

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/suppressed-error.rs:2:9 --> $DIR/suppressed-error.rs:2:9
| |
LL | let (x, y) = (); LL | let (x, y) = ();
| ^^^^^^ expected `()`, found tuple | ^^^^^^ -- this expression has type `()`
| |
| expected `()`, found tuple
| |
= note: expected unit type `()` = note: expected unit type `()`
found tuple `(_, _)` found tuple `(_, _)`