From 1631b4de1c951034654cc0684b38dcbd0708c902 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 5 Mar 2020 15:24:53 +0900 Subject: [PATCH 1/2] Avoid using `unwrap()` in suggestions --- src/librustc_typeck/check/method/suggest.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 95faa353e9b65..084601fbde1d4 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -547,10 +547,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (&self_ty.kind, parent_pred) { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { - let id = self.tcx.hir().as_local_hir_id(def.did).unwrap(); - let node = self.tcx.hir().get(id); + let node = self + .tcx + .hir() + .as_local_hir_id(def.did) + .map(|id| self.tcx.hir().get(id)); match node { - hir::Node::Item(hir::Item { kind, .. }) => { + Some(hir::Node::Item(hir::Item { kind, .. })) => { if let Some(g) = kind.generics() { let key = match &g.where_clause.predicates[..] { [.., pred] => { From 3d676492872d5e464e811a8f8d5afcd7122db089 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 7 Mar 2020 04:38:50 +0900 Subject: [PATCH 2/2] Add a regression test --- src/test/ui/issues/auxiliary/issue-69725.rs | 8 ++++++++ src/test/ui/issues/issue-69725.rs | 11 +++++++++++ src/test/ui/issues/issue-69725.stderr | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/test/ui/issues/auxiliary/issue-69725.rs create mode 100644 src/test/ui/issues/issue-69725.rs create mode 100644 src/test/ui/issues/issue-69725.stderr diff --git a/src/test/ui/issues/auxiliary/issue-69725.rs b/src/test/ui/issues/auxiliary/issue-69725.rs new file mode 100644 index 0000000000000..13606e498ef7d --- /dev/null +++ b/src/test/ui/issues/auxiliary/issue-69725.rs @@ -0,0 +1,8 @@ +#[derive(Clone)] +pub struct Struct(A); + +impl Struct { + pub fn new() -> Self { + todo!() + } +} diff --git a/src/test/ui/issues/issue-69725.rs b/src/test/ui/issues/issue-69725.rs new file mode 100644 index 0000000000000..b8130b41f2167 --- /dev/null +++ b/src/test/ui/issues/issue-69725.rs @@ -0,0 +1,11 @@ +// aux-build:issue-69725.rs + +extern crate issue_69725; +use issue_69725::Struct; + +fn crash() { + let _ = Struct::::new().clone(); + //~^ ERROR: no method named `clone` found +} + +fn main() {} diff --git a/src/test/ui/issues/issue-69725.stderr b/src/test/ui/issues/issue-69725.stderr new file mode 100644 index 0000000000000..667383e072a54 --- /dev/null +++ b/src/test/ui/issues/issue-69725.stderr @@ -0,0 +1,18 @@ +error[E0599]: no method named `clone` found for struct `issue_69725::Struct` in the current scope + --> $DIR/issue-69725.rs:7:32 + | +LL | let _ = Struct::::new().clone(); + | ^^^^^ method not found in `issue_69725::Struct` + | + ::: $DIR/auxiliary/issue-69725.rs:2:1 + | +LL | pub struct Struct(A); + | ------------------------ doesn't satisfy `issue_69725::Struct: std::clone::Clone` + | + = note: the method `clone` exists but the following trait bounds were not satisfied: + `A: std::clone::Clone` + which is required by `issue_69725::Struct: std::clone::Clone` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`.