Skip to content

Commit 9c1899d

Browse files
authored
Unrolled build for rust-lang#126115
Rollup merge of rust-lang#126115 - gurry:125876-ice-unwrap-probe-many-result, r=compiler-errors Fix ICE due to `unwrap` in `probe_for_name_many` Fixes rust-lang#125876 Now `probe_for_name_many` bubbles up the error returned by `probe_op` instead of calling `unwrap` on it.
2 parents d402830 + 6d87fc8 commit 9c1899d

File tree

5 files changed

+72
-11
lines changed

5 files changed

+72
-11
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -827,27 +827,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
827827
) else {
828828
return;
829829
};
830-
let in_scope_methods = self.probe_for_name_many(
830+
831+
let Ok(in_scope_methods) = self.probe_for_name_many(
831832
probe::Mode::MethodCall,
832833
path.ident,
833834
Some(expected),
834835
probe::IsSuggestion(true),
835836
self_ty,
836837
deref.hir_id,
837838
probe::ProbeScope::TraitsInScope,
838-
);
839+
) else {
840+
return;
841+
};
842+
839843
let other_methods_in_scope: Vec<_> =
840844
in_scope_methods.iter().filter(|c| c.item.def_id != pick.item.def_id).collect();
841845

842-
let all_methods = self.probe_for_name_many(
846+
let Ok(all_methods) = self.probe_for_name_many(
843847
probe::Mode::MethodCall,
844848
path.ident,
845849
Some(expected),
846850
probe::IsSuggestion(true),
847851
self_ty,
848852
deref.hir_id,
849853
probe::ProbeScope::AllTraits,
850-
);
854+
) else {
855+
return;
856+
};
857+
851858
let suggestions: Vec<_> = all_methods
852859
.into_iter()
853860
.filter(|c| c.item.def_id != pick.item.def_id)

compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
306306
self_ty: Ty<'tcx>,
307307
scope_expr_id: HirId,
308308
scope: ProbeScope,
309-
) -> Vec<Candidate<'tcx>> {
309+
) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
310310
self.probe_op(
311311
item_name.span,
312312
mode,
@@ -324,7 +324,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
324324
.collect())
325325
},
326326
)
327-
.unwrap()
328327
}
329328

330329
pub(crate) fn probe_op<OP, R>(

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1640,18 +1640,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16401640
.unwrap_or(Ty::new_misc_error(self.tcx)),
16411641
);
16421642

1643-
// FIXME: `probe_for_name_many` searches for methods in inherent implementations,
1644-
// so it may return a candidate that doesn't belong to this `revr_ty`. We need to
1645-
// check whether the instantiated type matches the received one.
1646-
for _matched_method in self.probe_for_name_many(
1643+
let Ok(candidates) = self.probe_for_name_many(
16471644
Mode::MethodCall,
16481645
item_name,
16491646
None,
16501647
IsSuggestion(true),
16511648
rcvr_ty,
16521649
source_expr.hir_id,
16531650
ProbeScope::TraitsInScope,
1654-
) {
1651+
) else {
1652+
return;
1653+
};
1654+
1655+
// FIXME: `probe_for_name_many` searches for methods in inherent implementations,
1656+
// so it may return a candidate that doesn't belong to this `revr_ty`. We need to
1657+
// check whether the instantiated type matches the received one.
1658+
for _matched_method in candidates {
16551659
// found a match, push to stack
16561660
stack_methods.push(rcvr_ty);
16571661
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for ICE #125876
2+
3+
fn main() {
4+
std::ptr::from_ref(num).cast_mut().as_deref();
5+
//~^ ERROR cannot find value `num` in this scope
6+
//~| ERROR no method named `as_deref` found for raw pointer `*mut _` in the current scope
7+
//~| WARN type annotations needed
8+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
9+
//~| WARN type annotations needed
10+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0425]: cannot find value `num` in this scope
2+
--> $DIR/ice-unwrap-probe-many-result-125876.rs:4:24
3+
|
4+
LL | std::ptr::from_ref(num).cast_mut().as_deref();
5+
| ^^^ not found in this scope
6+
7+
warning: type annotations needed
8+
--> $DIR/ice-unwrap-probe-many-result-125876.rs:4:29
9+
|
10+
LL | std::ptr::from_ref(num).cast_mut().as_deref();
11+
| ^^^^^^^^
12+
|
13+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
14+
= note: for more information, see issue #46906 <https://github.com./rust-lang/rust/issues/46906>
15+
= note: `#[warn(tyvar_behind_raw_pointer)]` on by default
16+
17+
warning: type annotations needed
18+
--> $DIR/ice-unwrap-probe-many-result-125876.rs:4:40
19+
|
20+
LL | std::ptr::from_ref(num).cast_mut().as_deref();
21+
| ^^^^^^^^
22+
|
23+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
24+
= note: for more information, see issue #46906 <https://github.com./rust-lang/rust/issues/46906>
25+
26+
error[E0599]: no method named `as_deref` found for raw pointer `*mut _` in the current scope
27+
--> $DIR/ice-unwrap-probe-many-result-125876.rs:4:40
28+
|
29+
LL | std::ptr::from_ref(num).cast_mut().as_deref();
30+
| ^^^^^^^^
31+
|
32+
help: there is a method `as_ref` with a similar name
33+
|
34+
LL | std::ptr::from_ref(num).cast_mut().as_ref();
35+
| ~~~~~~
36+
37+
error: aborting due to 2 previous errors; 2 warnings emitted
38+
39+
Some errors have detailed explanations: E0425, E0599.
40+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)