Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebank · rust-lang/rust@870a01a (original) (raw)
File tree
50 files changed
lines changed
- rustc_trait_selection/src/traits/error_reporting
50 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1990,6 +1990,10 @@ pub(super) fn check_type_bounds<'tcx>( | ||
1990 | 1990 | impl_ty: ty::AssocItem, |
1991 | 1991 | impl_trait_ref: ty::TraitRef<'tcx>, |
1992 | 1992 | ) -> Result<(), ErrorGuaranteed> { |
1993 | +// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case | |
1994 | +// other `Foo` impls are incoherent. | |
1995 | + tcx.ensure().coherent_trait(impl_trait_ref.def_id)?; | |
1996 | + | |
1993 | 1997 | let param_env = tcx.param_env(impl_ty.def_id); |
1994 | 1998 | debug!(?param_env); |
1995 | 1999 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1005,6 +1005,11 @@ fn check_associated_item( | ||
1005 | 1005 | enter_wf_checking_ctxt(tcx, span, item_id, |wfcx |
1006 | 1006 | let item = tcx.associated_item(item_id); |
1007 | 1007 | |
1008 | +// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case | |
1009 | +// other `Foo` impls are incoherent. | |
1010 | + tcx.ensure() | |
1011 | +.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?; | |
1012 | + | |
1008 | 1013 | let self_ty = match item.container { |
1009 | 1014 | ty::TraitContainer => tcx.types.self_param, |
1010 | 1015 | ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(), |
@@ -1291,6 +1296,9 @@ fn check_impl<'tcx>( | ||
1291 | 1296 | // therefore don't need to be WF (the trait's `Self: Trait` predicate |
1292 | 1297 | // won't hold). |
1293 | 1298 | let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity(); |
1299 | +// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case | |
1300 | +// other `Foo` impls are incoherent. | |
1301 | + tcx.ensure().coherent_trait(trait_ref.def_id)?; | |
1294 | 1302 | let trait_ref = wfcx.normalize( |
1295 | 1303 | ast_trait_ref.path.span, |
1296 | 1304 | Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { | ||
169 | 169 | |
170 | 170 | tcx.sess.time("coherence_checking", | |
171 | 171 | // Check impls constrain their parameters |
172 | -let mut res = | |
172 | +let res = | |
173 | 173 | tcx.hir().try_par_for_each_module(|module |
174 | 174 | |
175 | 175 | for &trait_def_id in tcx.all_local_trait_impls(()).keys() { |
176 | -res = res.and(tcx.ensure().coherent_trait(trait_def_id)); | |
176 | +let _ = tcx.ensure().coherent_trait(trait_def_id); | |
177 | 177 | } |
178 | 178 | // these queries are executed for side-effects (error reporting): |
179 | 179 | res.and(tcx.ensure().crate_inherent_impls(())) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -41,7 +41,7 @@ pub fn check_legal_trait_for_method_call( | ||
41 | 41 | receiver: Option<Span>, |
42 | 42 | expr_span: Span, |
43 | 43 | trait_id: DefId, |
44 | -) { | |
44 | +) -> Result<(), ErrorGuaranteed> { | |
45 | 45 | if tcx.lang_items().drop_trait() == Some(trait_id) { |
46 | 46 | let sugg = if let Some(receiver) = receiver.filter(|s |
47 | 47 | errors::ExplicitDestructorCallSugg::Snippet { |
@@ -51,8 +51,9 @@ pub fn check_legal_trait_for_method_call( | ||
51 | 51 | } else { |
52 | 52 | errors::ExplicitDestructorCallSugg::Empty(span) |
53 | 53 | }; |
54 | - tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }); | |
54 | +return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg })); | |
55 | 55 | } |
56 | + tcx.coherent_trait(trait_id) | |
56 | 57 | } |
57 | 58 | |
58 | 59 | #[derive(Debug)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1105,13 +1105,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ||
1105 | 1105 | let container_id = assoc_item.container_id(tcx); |
1106 | 1106 | debug!(?def_id, ?container, ?container_id); |
1107 | 1107 | match container { |
1108 | - ty::TraitContainer => callee::check_legal_trait_for_method_call( | |
1109 | - tcx, | |
1110 | - path_span, | |
1111 | -None, | |
1112 | - span, | |
1113 | - container_id, | |
1114 | -), | |
1108 | + ty::TraitContainer => { | |
1109 | +if let Err(e) = callee::check_legal_trait_for_method_call( | |
1110 | + tcx, | |
1111 | + path_span, | |
1112 | +None, | |
1113 | + span, | |
1114 | + container_id, | |
1115 | +) { | |
1116 | +self.set_tainted_by_errors(e); | |
1117 | +} | |
1118 | +} | |
1115 | 1119 | ty::ImplContainer => { |
1116 | 1120 | if segments.len() == 1 { |
1117 | 1121 | // `::assoc` will end up here, and so |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -630,13 +630,15 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { | ||
630 | 630 | fn enforce_illegal_method_limitations(&self, pick: &probe::Pick<'_>) { |
631 | 631 | // Disallow calls to the method `drop` defined in the `Drop` trait. |
632 | 632 | if let Some(trait_def_id) = pick.item.trait_container(self.tcx) { |
633 | - callee::check_legal_trait_for_method_call( | |
633 | +if let Err(e) = callee::check_legal_trait_for_method_call( | |
634 | 634 | self.tcx, |
635 | 635 | self.span, |
636 | 636 | Some(self.self_expr.span), |
637 | 637 | self.call_expr.span, |
638 | 638 | trait_def_id, |
639 | -) | |
639 | +) { | |
640 | +self.set_tainted_by_errors(e); | |
641 | +} | |
640 | 642 | } |
641 | 643 | } |
642 | 644 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2371,6 +2371,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | ||
2371 | 2371 | return e; |
2372 | 2372 | } |
2373 | 2373 | |
2374 | +if let Err(guar) = self.tcx.ensure().coherent_trait(trait_ref.def_id()) { | |
2375 | +// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case | |
2376 | +// other `Foo` impls are incoherent. | |
2377 | +return guar; | |
2378 | +} | |
2379 | + | |
2374 | 2380 | // This is kind of a hack: it frequently happens that some earlier |
2375 | 2381 | // error prevents types from being fully inferred, and then we get |
2376 | 2382 | // a bunch of uninteresting errors saying something like "<generic |
@@ -2666,6 +2672,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | ||
2666 | 2672 | if let Some(e) = self.tainted_by_errors() { |
2667 | 2673 | return e; |
2668 | 2674 | } |
2675 | + | |
2676 | +if let Err(guar) = | |
2677 | +self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_ty.def_id)) | |
2678 | +{ | |
2679 | +// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case | |
2680 | +// other `Foo` impls are incoherent. | |
2681 | +return guar; | |
2682 | +} | |
2669 | 2683 | let subst = data |
2670 | 2684 | .projection_ty |
2671 | 2685 | .args |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -448,22 +448,6 @@ mod prim_unit {} | ||
448 | 448 | #[doc(hidden)] |
449 | 449 | impl () {} |
450 | 450 | |
451 | -// Fake impl that's only really used for docs. | |
452 | -#[cfg(doc)] | |
453 | -#[stable(feature = "rust1", since = "1.0.0")] | |
454 | -impl Clone for () { | |
455 | -fn clone(&self) -> Self { | |
456 | -loop {} | |
457 | -} | |
458 | -} | |
459 | - | |
460 | -// Fake impl that's only really used for docs. | |
461 | -#[cfg(doc)] | |
462 | -#[stable(feature = "rust1", since = "1.0.0")] | |
463 | -impl Copy for () { | |
464 | -// empty | |
465 | -} | |
466 | - | |
467 | 451 | #[rustc_doc_primitive = "pointer"] |
468 | 452 | #[doc(alias = "ptr")] |
469 | 453 | #[doc(alias = "*")] |
@@ -1690,23 +1674,3 @@ mod prim_fn {} | ||
1690 | 1674 | // See src/librustdoc/passes/collect_trait_impls.rs:collect_trait_impls |
1691 | 1675 | #[doc(hidden)] |
1692 | 1676 | impl<Ret, T> fn(T) -> Ret {} |
1693 | - | |
1694 | -// Fake impl that's only really used for docs. | |
1695 | -#[cfg(doc)] | |
1696 | -#[stable(feature = "rust1", since = "1.0.0")] | |
1697 | -#[doc(fake_variadic)] | |
1698 | -/// This trait is implemented on function pointers with any number of arguments. | |
1699 | -impl<Ret, T> Clone for fn(T) -> Ret { | |
1700 | -fn clone(&self) -> Self { | |
1701 | -loop {} | |
1702 | -} | |
1703 | -} | |
1704 | - | |
1705 | -// Fake impl that's only really used for docs. | |
1706 | -#[cfg(doc)] | |
1707 | -#[stable(feature = "rust1", since = "1.0.0")] | |
1708 | -#[doc(fake_variadic)] | |
1709 | -/// This trait is implemented on function pointers with any number of arguments. | |
1710 | -impl<Ret, T> Copy for fn(T) -> Ret { | |
1711 | -// empty | |
1712 | -} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658 | ||
14 | 14 | |
15 | 15 | fn main<A: TraitWAssocConst<A=32>>() { |
16 | 16 | //~^ ERROR E0658 |
17 | +//~| ERROR E0131 | |
17 | 18 | foo::<Demo>(); |
18 | 19 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -43,7 +43,13 @@ LL | impl TraitWAssocConst for impl Demo { | ||
43 | 43 | | |
44 | 44 | = note: `impl Trait` is only allowed in arguments and return types of functions and methods |
45 | 45 | |
46 | -error: aborting due to 5 previous errors | |
46 | +error[E0131]: `main` function is not allowed to have generic parameters | |
47 | + --> $DIR/issue-105330.rs:15:8 | |
48 | + | | |
49 | +LL | fn main<A: TraitWAssocConst<A=32>>() { | |
50 | + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters | |
51 | + | |
52 | +error: aborting due to 6 previous errors | |
47 | 53 | |
48 | -Some errors have detailed explanations: E0404, E0562, E0658. | |
49 | -For more information about an error, try `rustc --explain E0404`. | |
54 | +Some errors have detailed explanations: E0131, E0404, E0562, E0658. | |
55 | +For more information about an error, try `rustc --explain E0131`. |