From 7f19f1f91ba7d082b03f36716909eae39c24ddb3 Mon Sep 17 00:00:00 2001 From: Cengiz Can Date: Fri, 10 Mar 2017 02:51:47 +0300 Subject: fix #40294 obligation cause.body_id is not always a NodeExpr --- src/librustc/traits/error_reporting.rs | 21 +++++++++++++-------- src/test/ui/codemap_tests/issue-38812-2.rs | 13 ------------- src/test/ui/codemap_tests/issue-38812-2.stderr | 12 ------------ src/test/ui/codemap_tests/issue-38812.rs | 13 ------------- src/test/ui/codemap_tests/issue-38812.stderr | 12 ------------ src/test/ui/resolve/issue-38812-2.rs | 13 +++++++++++++ src/test/ui/resolve/issue-38812-2.stderr | 12 ++++++++++++ src/test/ui/resolve/issue-38812.rs | 13 +++++++++++++ src/test/ui/resolve/issue-38812.stderr | 12 ++++++++++++ src/test/ui/resolve/issue-40294.rs | 23 +++++++++++++++++++++++ src/test/ui/resolve/issue-40294.stderr | 15 +++++++++++++++ 11 files changed, 101 insertions(+), 58 deletions(-) delete mode 100644 src/test/ui/codemap_tests/issue-38812-2.rs delete mode 100644 src/test/ui/codemap_tests/issue-38812-2.stderr delete mode 100644 src/test/ui/codemap_tests/issue-38812.rs delete mode 100644 src/test/ui/codemap_tests/issue-38812.stderr create mode 100644 src/test/ui/resolve/issue-38812-2.rs create mode 100644 src/test/ui/resolve/issue-38812-2.stderr create mode 100644 src/test/ui/resolve/issue-38812.rs create mode 100644 src/test/ui/resolve/issue-38812.stderr create mode 100644 src/test/ui/resolve/issue-40294.rs create mode 100644 src/test/ui/resolve/issue-40294.stderr (limited to 'src') diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 99db5f9b624..0e5c786cd8d 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -23,11 +23,17 @@ use super::{ ObjectSafetyViolation, }; +use errors::DiagnosticBuilder; use fmt_macros::{Parser, Piece, Position}; +use hir::{intravisit, Local, Pat}; +use hir::intravisit::{Visitor, NestedVisitorMap}; +use hir::map::NodeExpr; use hir::def_id::DefId; use infer::{self, InferCtxt}; use infer::type_variable::TypeVariableOrigin; use rustc::lint::builtin::EXTRA_REQUIREMENT_IN_IMPL; +use std::fmt; +use syntax::ast; use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable}; use ty::error::ExpectedFound; use ty::fast_reject; @@ -35,12 +41,8 @@ use ty::fold::TypeFolder; use ty::subst::Subst; use util::nodemap::{FxHashMap, FxHashSet}; -use std::fmt; -use syntax::ast; -use hir::{intravisit, Local, Pat}; -use hir::intravisit::{Visitor, NestedVisitorMap}; use syntax_pos::{DUMMY_SP, Span}; -use errors::DiagnosticBuilder; + #[derive(Debug, PartialEq, Eq, Hash)] pub struct TraitErrorKey<'tcx> { @@ -848,15 +850,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err.span_label(cause.span, &format!("cannot infer type for `{}`", name)); - let expr = self.tcx.hir.expect_expr(cause.body_id); - let mut local_visitor = FindLocalByTypeVisitor { infcx: &self, target_ty: &ty, found_pattern: None, }; - local_visitor.visit_expr(expr); + // #40294: cause.body_id can also be a fn declaration. + // Currently, if it's anything other than NodeExpr, we just ignore it + match self.tcx.hir.find(cause.body_id) { + Some(NodeExpr(expr)) => local_visitor.visit_expr(expr), + _ => () + } if let Some(pattern) = local_visitor.found_pattern { let pattern_span = pattern.span; diff --git a/src/test/ui/codemap_tests/issue-38812-2.rs b/src/test/ui/codemap_tests/issue-38812-2.rs deleted file mode 100644 index c476657d207..00000000000 --- a/src/test/ui/codemap_tests/issue-38812-2.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let (x,) = (vec![],); -} diff --git a/src/test/ui/codemap_tests/issue-38812-2.stderr b/src/test/ui/codemap_tests/issue-38812-2.stderr deleted file mode 100644 index 156a6bdee99..00000000000 --- a/src/test/ui/codemap_tests/issue-38812-2.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/issue-38812-2.rs:12:17 - | -12 | let (x,) = (vec![],); - | ---- ^^^^^^ cannot infer type for `T` - | | - | consider giving a type to pattern - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to previous error - diff --git a/src/test/ui/codemap_tests/issue-38812.rs b/src/test/ui/codemap_tests/issue-38812.rs deleted file mode 100644 index a9943f75336..00000000000 --- a/src/test/ui/codemap_tests/issue-38812.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x = vec![]; -} diff --git a/src/test/ui/codemap_tests/issue-38812.stderr b/src/test/ui/codemap_tests/issue-38812.stderr deleted file mode 100644 index 6365e761453..00000000000 --- a/src/test/ui/codemap_tests/issue-38812.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/issue-38812.rs:12:13 - | -12 | let x = vec![]; - | - ^^^^^^ cannot infer type for `T` - | | - | consider giving `x` a type - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to previous error - diff --git a/src/test/ui/resolve/issue-38812-2.rs b/src/test/ui/resolve/issue-38812-2.rs new file mode 100644 index 00000000000..c476657d207 --- /dev/null +++ b/src/test/ui/resolve/issue-38812-2.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let (x,) = (vec![],); +} diff --git a/src/test/ui/resolve/issue-38812-2.stderr b/src/test/ui/resolve/issue-38812-2.stderr new file mode 100644 index 00000000000..156a6bdee99 --- /dev/null +++ b/src/test/ui/resolve/issue-38812-2.stderr @@ -0,0 +1,12 @@ +error[E0282]: type annotations needed + --> $DIR/issue-38812-2.rs:12:17 + | +12 | let (x,) = (vec![],); + | ---- ^^^^^^ cannot infer type for `T` + | | + | consider giving a type to pattern + | + = note: this error originates in a macro outside of the current crate + +error: aborting due to previous error + diff --git a/src/test/ui/resolve/issue-38812.rs b/src/test/ui/resolve/issue-38812.rs new file mode 100644 index 00000000000..a9943f75336 --- /dev/null +++ b/src/test/ui/resolve/issue-38812.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = vec![]; +} diff --git a/src/test/ui/resolve/issue-38812.stderr b/src/test/ui/resolve/issue-38812.stderr new file mode 100644 index 00000000000..6365e761453 --- /dev/null +++ b/src/test/ui/resolve/issue-38812.stderr @@ -0,0 +1,12 @@ +error[E0282]: type annotations needed + --> $DIR/issue-38812.rs:12:13 + | +12 | let x = vec![]; + | - ^^^^^^ cannot infer type for `T` + | | + | consider giving `x` a type + | + = note: this error originates in a macro outside of the current crate + +error: aborting due to previous error + diff --git a/src/test/ui/resolve/issue-40294.rs b/src/test/ui/resolve/issue-40294.rs new file mode 100644 index 00000000000..d30a425d109 --- /dev/null +++ b/src/test/ui/resolve/issue-40294.rs @@ -0,0 +1,23 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo: Sized { + fn foo(self); +} + +fn foo<'a,'b,T>(x: &'a T, y: &'b T) + where &'a T : Foo, + &'b T : Foo +{ + x.foo(); + y.foo(); +} + +fn main() { } diff --git a/src/test/ui/resolve/issue-40294.stderr b/src/test/ui/resolve/issue-40294.stderr new file mode 100644 index 00000000000..5c388c9d602 --- /dev/null +++ b/src/test/ui/resolve/issue-40294.stderr @@ -0,0 +1,15 @@ +error[E0282]: type annotations needed + --> $DIR/issue-40294.rs:15:1 + | +15 | fn foo<'a,'b,T>(x: &'a T, y: &'b T) + | _^ starting here... +16 | | where &'a T : Foo, +17 | | &'b T : Foo +18 | | { +19 | | x.foo(); +20 | | y.foo(); +21 | | } + | |_^ ...ending here: cannot infer type for `&'a T` + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 889337da06e764369897ef15a6dfca6f27879a45 Mon Sep 17 00:00:00 2001 From: Cengiz Can Date: Fri, 10 Mar 2017 11:43:34 +0300 Subject: move related tests to type-check ui test directory --- src/test/ui/resolve/issue-38812-2.rs | 13 ------------- src/test/ui/resolve/issue-38812-2.stderr | 12 ------------ src/test/ui/resolve/issue-38812.rs | 13 ------------- src/test/ui/resolve/issue-38812.stderr | 12 ------------ src/test/ui/resolve/issue-40294.rs | 23 ----------------------- src/test/ui/resolve/issue-40294.stderr | 15 --------------- src/test/ui/type-check/issue-38812-2.rs | 13 +++++++++++++ src/test/ui/type-check/issue-38812-2.stderr | 12 ++++++++++++ src/test/ui/type-check/issue-38812.rs | 13 +++++++++++++ src/test/ui/type-check/issue-38812.stderr | 12 ++++++++++++ src/test/ui/type-check/issue-40294.rs | 23 +++++++++++++++++++++++ src/test/ui/type-check/issue-40294.stderr | 15 +++++++++++++++ 12 files changed, 88 insertions(+), 88 deletions(-) delete mode 100644 src/test/ui/resolve/issue-38812-2.rs delete mode 100644 src/test/ui/resolve/issue-38812-2.stderr delete mode 100644 src/test/ui/resolve/issue-38812.rs delete mode 100644 src/test/ui/resolve/issue-38812.stderr delete mode 100644 src/test/ui/resolve/issue-40294.rs delete mode 100644 src/test/ui/resolve/issue-40294.stderr create mode 100644 src/test/ui/type-check/issue-38812-2.rs create mode 100644 src/test/ui/type-check/issue-38812-2.stderr create mode 100644 src/test/ui/type-check/issue-38812.rs create mode 100644 src/test/ui/type-check/issue-38812.stderr create mode 100644 src/test/ui/type-check/issue-40294.rs create mode 100644 src/test/ui/type-check/issue-40294.stderr (limited to 'src') diff --git a/src/test/ui/resolve/issue-38812-2.rs b/src/test/ui/resolve/issue-38812-2.rs deleted file mode 100644 index c476657d207..00000000000 --- a/src/test/ui/resolve/issue-38812-2.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let (x,) = (vec![],); -} diff --git a/src/test/ui/resolve/issue-38812-2.stderr b/src/test/ui/resolve/issue-38812-2.stderr deleted file mode 100644 index 156a6bdee99..00000000000 --- a/src/test/ui/resolve/issue-38812-2.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/issue-38812-2.rs:12:17 - | -12 | let (x,) = (vec![],); - | ---- ^^^^^^ cannot infer type for `T` - | | - | consider giving a type to pattern - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to previous error - diff --git a/src/test/ui/resolve/issue-38812.rs b/src/test/ui/resolve/issue-38812.rs deleted file mode 100644 index a9943f75336..00000000000 --- a/src/test/ui/resolve/issue-38812.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x = vec![]; -} diff --git a/src/test/ui/resolve/issue-38812.stderr b/src/test/ui/resolve/issue-38812.stderr deleted file mode 100644 index 6365e761453..00000000000 --- a/src/test/ui/resolve/issue-38812.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/issue-38812.rs:12:13 - | -12 | let x = vec![]; - | - ^^^^^^ cannot infer type for `T` - | | - | consider giving `x` a type - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to previous error - diff --git a/src/test/ui/resolve/issue-40294.rs b/src/test/ui/resolve/issue-40294.rs deleted file mode 100644 index d30a425d109..00000000000 --- a/src/test/ui/resolve/issue-40294.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait Foo: Sized { - fn foo(self); -} - -fn foo<'a,'b,T>(x: &'a T, y: &'b T) - where &'a T : Foo, - &'b T : Foo -{ - x.foo(); - y.foo(); -} - -fn main() { } diff --git a/src/test/ui/resolve/issue-40294.stderr b/src/test/ui/resolve/issue-40294.stderr deleted file mode 100644 index 5c388c9d602..00000000000 --- a/src/test/ui/resolve/issue-40294.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/issue-40294.rs:15:1 - | -15 | fn foo<'a,'b,T>(x: &'a T, y: &'b T) - | _^ starting here... -16 | | where &'a T : Foo, -17 | | &'b T : Foo -18 | | { -19 | | x.foo(); -20 | | y.foo(); -21 | | } - | |_^ ...ending here: cannot infer type for `&'a T` - -error: aborting due to previous error - diff --git a/src/test/ui/type-check/issue-38812-2.rs b/src/test/ui/type-check/issue-38812-2.rs new file mode 100644 index 00000000000..c476657d207 --- /dev/null +++ b/src/test/ui/type-check/issue-38812-2.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let (x,) = (vec![],); +} diff --git a/src/test/ui/type-check/issue-38812-2.stderr b/src/test/ui/type-check/issue-38812-2.stderr new file mode 100644 index 00000000000..156a6bdee99 --- /dev/null +++ b/src/test/ui/type-check/issue-38812-2.stderr @@ -0,0 +1,12 @@ +error[E0282]: type annotations needed + --> $DIR/issue-38812-2.rs:12:17 + | +12 | let (x,) = (vec![],); + | ---- ^^^^^^ cannot infer type for `T` + | | + | consider giving a type to pattern + | + = note: this error originates in a macro outside of the current crate + +error: aborting due to previous error + diff --git a/src/test/ui/type-check/issue-38812.rs b/src/test/ui/type-check/issue-38812.rs new file mode 100644 index 00000000000..a9943f75336 --- /dev/null +++ b/src/test/ui/type-check/issue-38812.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = vec![]; +} diff --git a/src/test/ui/type-check/issue-38812.stderr b/src/test/ui/type-check/issue-38812.stderr new file mode 100644 index 00000000000..6365e761453 --- /dev/null +++ b/src/test/ui/type-check/issue-38812.stderr @@ -0,0 +1,12 @@ +error[E0282]: type annotations needed + --> $DIR/issue-38812.rs:12:13 + | +12 | let x = vec![]; + | - ^^^^^^ cannot infer type for `T` + | | + | consider giving `x` a type + | + = note: this error originates in a macro outside of the current crate + +error: aborting due to previous error + diff --git a/src/test/ui/type-check/issue-40294.rs b/src/test/ui/type-check/issue-40294.rs new file mode 100644 index 00000000000..d30a425d109 --- /dev/null +++ b/src/test/ui/type-check/issue-40294.rs @@ -0,0 +1,23 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo: Sized { + fn foo(self); +} + +fn foo<'a,'b,T>(x: &'a T, y: &'b T) + where &'a T : Foo, + &'b T : Foo +{ + x.foo(); + y.foo(); +} + +fn main() { } diff --git a/src/test/ui/type-check/issue-40294.stderr b/src/test/ui/type-check/issue-40294.stderr new file mode 100644 index 00000000000..5c388c9d602 --- /dev/null +++ b/src/test/ui/type-check/issue-40294.stderr @@ -0,0 +1,15 @@ +error[E0282]: type annotations needed + --> $DIR/issue-40294.rs:15:1 + | +15 | fn foo<'a,'b,T>(x: &'a T, y: &'b T) + | _^ starting here... +16 | | where &'a T : Foo, +17 | | &'b T : Foo +18 | | { +19 | | x.foo(); +20 | | y.foo(); +21 | | } + | |_^ ...ending here: cannot infer type for `&'a T` + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5