Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using unwrap() in suggestions #69727

Merged
merged 2 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] => {
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/issues/auxiliary/issue-69725.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(Clone)]
pub struct Struct<A>(A);

impl<A> Struct<A> {
pub fn new() -> Self {
todo!()
}
}
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-69725.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions src/test/ui/issues/issue-69725.stderr
Original file line number Diff line number Diff line change
@@ -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`.