From 7b9f9fa6c832608a654d3e14efa9ff7a65fac208 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2019 23:31:34 +0200 Subject: [PATCH 1/6] save-analysis: use `qpath_def` for associated types --- src/librustc_save_analysis/lib.rs | 21 +++------------------ src/librustc_typeck/lib.rs | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index a363fe1141891..9b21e42bf3870 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -23,7 +23,6 @@ use rustc::middle::cstore::ExternCrate; use rustc::session::config::{CrateType, Input, OutputType}; use rustc::ty::{self, DefIdTree, TyCtxt}; use rustc::{bug, span_bug}; -use rustc_typeck::hir_ty_to_ty; use rustc_codegen_utils::link::{filename_for_metadata, out_filename}; use rustc_data_structures::sync::Lrc; @@ -658,23 +657,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { .. }) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)), - Node::Ty(ty) => if let hir::Ty { - node: hir::TyKind::Path(ref qpath), - .. - } = *ty - { - match *qpath { - hir::QPath::Resolved(_, ref path) => path.def, - hir::QPath::TypeRelative(..) => { - let ty = hir_ty_to_ty(self.tcx, ty); - if let ty::Projection(proj) = ty.sty { - return HirDef::AssociatedTy(proj.item_def_id); - } - HirDef::Err - } - } - } else { - HirDef::Err + Node::Ty(&hir::Ty { node: hir::TyKind::Path(ref qpath), .. } ) => { + let hir_id = self.tcx.hir().node_to_hir_id(id); + self.tables.qpath_def(qpath, hir_id) }, _ => HirDef::Err, diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 4a7b1e67366e8..710c84a6bc980 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -379,7 +379,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) } } -/// A quasi-deprecated helper used in rustdoc and save-analysis to get +/// A quasi-deprecated helper used in rustdoc and clippy to get /// the type from a HIR node. pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> { // In case there are any projections etc, find the "environment" From 9401a6744debe1245767d0c0f21dbb023c78a954 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2019 23:53:59 +0200 Subject: [PATCH 2/6] save-analysis: Simplify match arm for type node def --- src/librustc_save_analysis/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 9b21e42bf3870..d6923b4490d59 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -647,6 +647,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Node::Pat(&hir::Pat { node: hir::PatKind::TupleStruct(ref qpath, ..), .. + }) | + Node::Ty(&hir::Ty { + node: hir::TyKind::Path(ref qpath), + .. }) => { let hir_id = self.tcx.hir().node_to_hir_id(id); self.tables.qpath_def(qpath, hir_id) @@ -657,11 +661,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { .. }) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)), - Node::Ty(&hir::Ty { node: hir::TyKind::Path(ref qpath), .. } ) => { - let hir_id = self.tcx.hir().node_to_hir_id(id); - self.tables.qpath_def(qpath, hir_id) - }, - _ => HirDef::Err, } } From 800b055798dc9cb7b30809cda760af2f06bfbd2f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 17 May 2019 10:16:52 -0700 Subject: [PATCH 3/6] Update beta clippy Backports https://github.com/rust-lang/rust-clippy/pull/4101 --- src/tools/clippy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy b/src/tools/clippy index 37f5c1ec734f8..265318dba93a3 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit 37f5c1ec734f806fe98930b8d5f54f00013f06f1 +Subproject commit 265318dba93a3363255a4d8eac9aefd53a05673a From 6599770b21295e0bcb1f9a9080637c97c5c4b2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 8 May 2019 11:42:47 -0700 Subject: [PATCH 4/6] Use `delay_span_bug` for "Failed to unify obligation" --- src/librustc/traits/project.rs | 15 ++++++++---- src/test/ui/issues/issue-60283.rs | 17 ++++++++++++++ src/test/ui/issues/issue-60283.stderr | 34 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issues/issue-60283.rs create mode 100644 src/test/ui/issues/issue-60283.stderr diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 360e2323b647d..59c0e7a83572c 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1454,13 +1454,18 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>( } } Err(e) => { - span_bug!( - obligation.cause.span, - "Failed to unify obligation `{:?}` \ - with poly_projection `{:?}`: {:?}", + let msg = format!( + "Failed to unify obligation `{:?}` with poly_projection `{:?}`: {:?}", obligation, poly_cache_entry, - e); + e, + ); + debug!("confirm_param_env_candidate: {}", msg); + infcx.tcx.sess.delay_span_bug(obligation.cause.span, &msg); + Progress { + ty: infcx.tcx.types.err, + obligations: vec![], + } } } } diff --git a/src/test/ui/issues/issue-60283.rs b/src/test/ui/issues/issue-60283.rs new file mode 100644 index 0000000000000..e5a9caa32fae7 --- /dev/null +++ b/src/test/ui/issues/issue-60283.rs @@ -0,0 +1,17 @@ +pub trait Trait<'a> { + type Item; +} + +impl<'a> Trait<'a> for () { + type Item = (); +} + +pub fn foo(_: T, _: F) +where T: for<'a> Trait<'a>, + F: for<'a> FnMut(>::Item) {} + +fn main() { + foo((), drop) + //~^ ERROR type mismatch in function arguments + //~| ERROR type mismatch resolving +} diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr new file mode 100644 index 0000000000000..a79b1959dca2f --- /dev/null +++ b/src/test/ui/issues/issue-60283.stderr @@ -0,0 +1,34 @@ +error[E0631]: type mismatch in function arguments + --> $DIR/issue-60283.rs:14:5 + | +LL | foo((), drop) + | ^^^ + | | + | expected signature of `for<'a> fn(<() as Trait<'a>>::Item) -> _` + | found signature of `fn(_) -> _` + | +note: required by `foo` + --> $DIR/issue-60283.rs:9:1 + | +LL | / pub fn foo(_: T, _: F) +LL | | where T: for<'a> Trait<'a>, +LL | | F: for<'a> FnMut(>::Item) {} + | |_________________________________________________^ + +error[E0271]: type mismatch resolving `for<'a> } as std::ops::FnOnce<(<() as Trait<'a>>::Item,)>>::Output == ()` + --> $DIR/issue-60283.rs:14:5 + | +LL | foo((), drop) + | ^^^ expected bound lifetime parameter 'a, found concrete lifetime + | +note: required by `foo` + --> $DIR/issue-60283.rs:9:1 + | +LL | / pub fn foo(_: T, _: F) +LL | | where T: for<'a> Trait<'a>, +LL | | F: for<'a> FnMut(>::Item) {} + | |_________________________________________________^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0271`. From ae359129340102e393e2cec677b7e8122e5fc326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 8 May 2019 10:23:55 -0700 Subject: [PATCH 5/6] Instead of ICEing on incorrect pattern, use delay_span_bug --- src/librustc/middle/mem_categorization.rs | 12 ++++++++++-- src/test/ui/fn-in-pat.rs | 16 ++++++++++++++++ src/test/ui/fn-in-pat.stderr | 9 +++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/fn-in-pat.rs create mode 100644 src/test/ui/fn-in-pat.stderr diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 1a3fef18404e3..e52de2519b55f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1294,8 +1294,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { } } def => { - span_bug!(pat.span, "tuple struct pattern didn't resolve \ - to variant or struct {:?}", def); + debug!( + "tuple struct pattern didn't resolve to variant or struct {:?} at {:?}", + def, + pat.span, + ); + self.tcx.sess.delay_span_bug(pat.span, &format!( + "tuple struct pattern didn't resolve to variant or struct {:?}", + def, + )); + return Err(()); } }; diff --git a/src/test/ui/fn-in-pat.rs b/src/test/ui/fn-in-pat.rs new file mode 100644 index 0000000000000..ed76b2c5db025 --- /dev/null +++ b/src/test/ui/fn-in-pat.rs @@ -0,0 +1,16 @@ +struct A {} + +impl A { + fn new() {} +} + +fn hof(_: F) where F: FnMut(()) {} + +fn ice() { + hof(|c| match c { + A::new() => (), //~ ERROR expected tuple struct/variant, found method + _ => () + }) +} + +fn main() {} diff --git a/src/test/ui/fn-in-pat.stderr b/src/test/ui/fn-in-pat.stderr new file mode 100644 index 0000000000000..eee97fe9587c2 --- /dev/null +++ b/src/test/ui/fn-in-pat.stderr @@ -0,0 +1,9 @@ +error[E0164]: expected tuple struct/variant, found method `::new` + --> $DIR/fn-in-pat.rs:11:9 + | +LL | A::new() => (), + | ^^^^^^^^ not a tuple variant or struct + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0164`. From 7b38c5232c1932b22dc25f4d96cac28058711403 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Sat, 18 May 2019 13:42:20 +0200 Subject: [PATCH 6/6] bless ui tests --- src/test/ui/issues/issue-60283.stderr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index a79b1959dca2f..54cc2f3a034de 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -31,4 +31,5 @@ LL | | F: for<'a> FnMut(>::Item) {} error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors occurred: E0271, E0631. +For more information about an error, try `rustc --explain E0271`.