Rollup merge of #69727 - JohnTitor:sugg-unwrap, r=estebank

Avoid using `unwrap()` in suggestions

Fixes #69725

r? @estebank
This commit is contained in:
Mazdak Farrokhzad 2020-03-07 08:15:30 +01:00 committed by GitHub
commit 93a57cf3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 3 deletions

View File

@ -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] => {

View File

@ -0,0 +1,8 @@
#[derive(Clone)]
pub struct Struct<A>(A);
impl<A> Struct<A> {
pub fn new() -> Self {
todo!()
}
}

View File

@ -0,0 +1,11 @@
// aux-build:issue-69725.rs
extern crate issue_69725;
use issue_69725::Struct;
fn crash<A>() {
let _ = Struct::<A>::new().clone();
//~^ ERROR: no method named `clone` found
}
fn main() {}

View File

@ -0,0 +1,18 @@
error[E0599]: no method named `clone` found for struct `issue_69725::Struct<A>` in the current scope
--> $DIR/issue-69725.rs:7:32
|
LL | let _ = Struct::<A>::new().clone();
| ^^^^^ method not found in `issue_69725::Struct<A>`
|
::: $DIR/auxiliary/issue-69725.rs:2:1
|
LL | pub struct Struct<A>(A);
| ------------------------ doesn't satisfy `issue_69725::Struct<A>: 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<A>: std::clone::Clone`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.