Skip to content

Commit 02b0ca3

Browse files
committed
Auto merge of #60922 - pietroalbini:beta-rollup, r=pietroalbini
[beta] Rollup backports Rolled up: * [beta] save-analysis: Pull associated type definition using `qpath_def` #60881 * [beta] Update clippy #60918 Cherry-picked: * Instead of ICEing on incorrect pattern, use delay_span_bug #60641 * Use `delay_span_bug` for "Failed to unify obligation" #60644 r? @ghost
2 parents d08ab31 + 7b38c52 commit 02b0ca3

File tree

9 files changed

+103
-29
lines changed

9 files changed

+103
-29
lines changed

src/librustc/middle/mem_categorization.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12941294
}
12951295
}
12961296
def => {
1297-
span_bug!(pat.span, "tuple struct pattern didn't resolve \
1298-
to variant or struct {:?}", def);
1297+
debug!(
1298+
"tuple struct pattern didn't resolve to variant or struct {:?} at {:?}",
1299+
def,
1300+
pat.span,
1301+
);
1302+
self.tcx.sess.delay_span_bug(pat.span, &format!(
1303+
"tuple struct pattern didn't resolve to variant or struct {:?}",
1304+
def,
1305+
));
1306+
return Err(());
12991307
}
13001308
};
13011309

src/librustc/traits/project.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1454,13 +1454,18 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
14541454
}
14551455
}
14561456
Err(e) => {
1457-
span_bug!(
1458-
obligation.cause.span,
1459-
"Failed to unify obligation `{:?}` \
1460-
with poly_projection `{:?}`: {:?}",
1457+
let msg = format!(
1458+
"Failed to unify obligation `{:?}` with poly_projection `{:?}`: {:?}",
14611459
obligation,
14621460
poly_cache_entry,
1463-
e);
1461+
e,
1462+
);
1463+
debug!("confirm_param_env_candidate: {}", msg);
1464+
infcx.tcx.sess.delay_span_bug(obligation.cause.span, &msg);
1465+
Progress {
1466+
ty: infcx.tcx.types.err,
1467+
obligations: vec![],
1468+
}
14641469
}
14651470
}
14661471
}

src/librustc_save_analysis/lib.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc::middle::cstore::ExternCrate;
2323
use rustc::session::config::{CrateType, Input, OutputType};
2424
use rustc::ty::{self, DefIdTree, TyCtxt};
2525
use rustc::{bug, span_bug};
26-
use rustc_typeck::hir_ty_to_ty;
2726
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
2827
use rustc_data_structures::sync::Lrc;
2928

@@ -648,6 +647,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
648647
Node::Pat(&hir::Pat {
649648
node: hir::PatKind::TupleStruct(ref qpath, ..),
650649
..
650+
}) |
651+
Node::Ty(&hir::Ty {
652+
node: hir::TyKind::Path(ref qpath),
653+
..
651654
}) => {
652655
let hir_id = self.tcx.hir().node_to_hir_id(id);
653656
self.tables.qpath_def(qpath, hir_id)
@@ -658,25 +661,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
658661
..
659662
}) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)),
660663

661-
Node::Ty(ty) => if let hir::Ty {
662-
node: hir::TyKind::Path(ref qpath),
663-
..
664-
} = *ty
665-
{
666-
match *qpath {
667-
hir::QPath::Resolved(_, ref path) => path.def,
668-
hir::QPath::TypeRelative(..) => {
669-
let ty = hir_ty_to_ty(self.tcx, ty);
670-
if let ty::Projection(proj) = ty.sty {
671-
return HirDef::AssociatedTy(proj.item_def_id);
672-
}
673-
HirDef::Err
674-
}
675-
}
676-
} else {
677-
HirDef::Err
678-
},
679-
680664
_ => HirDef::Err,
681665
}
682666
}

src/librustc_typeck/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
379379
}
380380
}
381381

382-
/// A quasi-deprecated helper used in rustdoc and save-analysis to get
382+
/// A quasi-deprecated helper used in rustdoc and clippy to get
383383
/// the type from a HIR node.
384384
pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> {
385385
// In case there are any projections etc, find the "environment"

src/test/ui/fn-in-pat.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct A {}
2+
3+
impl A {
4+
fn new() {}
5+
}
6+
7+
fn hof<F>(_: F) where F: FnMut(()) {}
8+
9+
fn ice() {
10+
hof(|c| match c {
11+
A::new() => (), //~ ERROR expected tuple struct/variant, found method
12+
_ => ()
13+
})
14+
}
15+
16+
fn main() {}

src/test/ui/fn-in-pat.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0164]: expected tuple struct/variant, found method `<A>::new`
2+
--> $DIR/fn-in-pat.rs:11:9
3+
|
4+
LL | A::new() => (),
5+
| ^^^^^^^^ not a tuple variant or struct
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0164`.

src/test/ui/issues/issue-60283.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub trait Trait<'a> {
2+
type Item;
3+
}
4+
5+
impl<'a> Trait<'a> for () {
6+
type Item = ();
7+
}
8+
9+
pub fn foo<T, F>(_: T, _: F)
10+
where T: for<'a> Trait<'a>,
11+
F: for<'a> FnMut(<T as Trait<'a>>::Item) {}
12+
13+
fn main() {
14+
foo((), drop)
15+
//~^ ERROR type mismatch in function arguments
16+
//~| ERROR type mismatch resolving
17+
}

src/test/ui/issues/issue-60283.stderr

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0631]: type mismatch in function arguments
2+
--> $DIR/issue-60283.rs:14:5
3+
|
4+
LL | foo((), drop)
5+
| ^^^
6+
| |
7+
| expected signature of `for<'a> fn(<() as Trait<'a>>::Item) -> _`
8+
| found signature of `fn(_) -> _`
9+
|
10+
note: required by `foo`
11+
--> $DIR/issue-60283.rs:9:1
12+
|
13+
LL | / pub fn foo<T, F>(_: T, _: F)
14+
LL | | where T: for<'a> Trait<'a>,
15+
LL | | F: for<'a> FnMut(<T as Trait<'a>>::Item) {}
16+
| |_________________________________________________^
17+
18+
error[E0271]: type mismatch resolving `for<'a> <fn(_) {std::mem::drop::<_>} as std::ops::FnOnce<(<() as Trait<'a>>::Item,)>>::Output == ()`
19+
--> $DIR/issue-60283.rs:14:5
20+
|
21+
LL | foo((), drop)
22+
| ^^^ expected bound lifetime parameter 'a, found concrete lifetime
23+
|
24+
note: required by `foo`
25+
--> $DIR/issue-60283.rs:9:1
26+
|
27+
LL | / pub fn foo<T, F>(_: T, _: F)
28+
LL | | where T: for<'a> Trait<'a>,
29+
LL | | F: for<'a> FnMut(<T as Trait<'a>>::Item) {}
30+
| |_________________________________________________^
31+
32+
error: aborting due to 2 previous errors
33+
34+
Some errors occurred: E0271, E0631.
35+
For more information about an error, try `rustc --explain E0271`.

src/tools/clippy

0 commit comments

Comments
 (0)