Skip to content

Commit

Permalink
Rollup merge of #105164 - compiler-errors:revert-import-filter, r=est…
Browse files Browse the repository at this point in the history
…ebank

Restore `use` suggestion for `dyn` method call requiring `Sized`

Add the suggestion back that I accidentally removed in 88f2140 because I didn't understand that suggestion was actually useful...

Fixes #105159
  • Loading branch information
matthiaskrgr authored Dec 3, 2022
2 parents 6f0a2ad + dc45eb9 commit a739fc8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer::{self, InferOk};
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, DefIdTree, GenericParamDefKind, Ty, TypeVisitable};
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TypeVisitable};
use rustc_span::symbol::Ident;
use rustc_span::Span;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

// We probe again, taking all traits into account (not only those in scope).
let mut candidates =
let candidates =
match self.lookup_probe(segment.ident, self_ty, call_expr, ProbeScope::AllTraits) {
// If we find a different result the caller probably forgot to import a trait.
Ok(ref new_pick) if pick.differs_from(new_pick) => {
Expand All @@ -236,7 +236,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.collect(),
_ => Vec::new(),
};
candidates.retain(|candidate| *candidate != self.tcx.parent(result.callee.def_id));

return Err(IllegalSizedBound(candidates, needs_mut, span));
}
Expand Down
14 changes: 9 additions & 5 deletions src/test/ui/issues/issue-35976.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// revisions: imported unimported
//[imported] check-pass

mod private {
pub trait Future {
//[unimported]~^^ HELP perhaps add a `use` for it
fn wait(&self) where Self: Sized;
}

Expand All @@ -8,13 +12,13 @@ mod private {
}
}

//use private::Future;
#[cfg(imported)]
use private::Future;

fn bar(arg: Box<dyn private::Future>) {
// Importing the trait means that we don't autoderef `Box<dyn Future>`
arg.wait();
//~^ ERROR the `wait` method cannot be invoked on a trait object
//[unimported]~^ ERROR the `wait` method cannot be invoked on a trait object
}

fn main() {

}
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
error: the `wait` method cannot be invoked on a trait object
--> $DIR/issue-35976.rs:14:9
--> $DIR/issue-35976.rs:20:9
|
LL | fn wait(&self) where Self: Sized;
| ----- this has a `Sized` requirement
...
LL | arg.wait();
| ^^^^
|
help: another candidate was found in the following trait, perhaps add a `use` for it:
|
LL | use private::Future;
|

error: aborting due to previous error

0 comments on commit a739fc8

Please sign in to comment.