Skip to content

Commit 93a57cf

Browse files
authoredMar 7, 2020
Rollup merge of #69727 - JohnTitor:sugg-unwrap, r=estebank
Avoid using `unwrap()` in suggestions Fixes #69725 r? @estebank
2 parents b25fb9e + 3d67649 commit 93a57cf

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed
 

‎src/librustc_typeck/check/method/suggest.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
547547
(&self_ty.kind, parent_pred)
548548
{
549549
if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind {
550-
let id = self.tcx.hir().as_local_hir_id(def.did).unwrap();
551-
let node = self.tcx.hir().get(id);
550+
let node = self
551+
.tcx
552+
.hir()
553+
.as_local_hir_id(def.did)
554+
.map(|id| self.tcx.hir().get(id));
552555
match node {
553-
hir::Node::Item(hir::Item { kind, .. }) => {
556+
Some(hir::Node::Item(hir::Item { kind, .. })) => {
554557
if let Some(g) = kind.generics() {
555558
let key = match &g.where_clause.predicates[..] {
556559
[.., pred] => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[derive(Clone)]
2+
pub struct Struct<A>(A);
3+
4+
impl<A> Struct<A> {
5+
pub fn new() -> Self {
6+
todo!()
7+
}
8+
}

‎src/test/ui/issues/issue-69725.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:issue-69725.rs
2+
3+
extern crate issue_69725;
4+
use issue_69725::Struct;
5+
6+
fn crash<A>() {
7+
let _ = Struct::<A>::new().clone();
8+
//~^ ERROR: no method named `clone` found
9+
}
10+
11+
fn main() {}

‎src/test/ui/issues/issue-69725.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0599]: no method named `clone` found for struct `issue_69725::Struct<A>` in the current scope
2+
--> $DIR/issue-69725.rs:7:32
3+
|
4+
LL | let _ = Struct::<A>::new().clone();
5+
| ^^^^^ method not found in `issue_69725::Struct<A>`
6+
|
7+
::: $DIR/auxiliary/issue-69725.rs:2:1
8+
|
9+
LL | pub struct Struct<A>(A);
10+
| ------------------------ doesn't satisfy `issue_69725::Struct<A>: std::clone::Clone`
11+
|
12+
= note: the method `clone` exists but the following trait bounds were not satisfied:
13+
`A: std::clone::Clone`
14+
which is required by `issue_69725::Struct<A>: std::clone::Clone`
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)
Please sign in to comment.