Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8e474d5

Browse files
committedSep 24, 2024
Separate collection of crate-local inherent impls from error reporting
1 parent 11e760b commit 8e474d5

File tree

22 files changed

+127
-124
lines changed

22 files changed

+127
-124
lines changed
 

‎compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,38 @@ use crate::errors;
2222
pub(crate) fn crate_inherent_impls(
2323
tcx: TyCtxt<'_>,
2424
(): (),
25-
) -> Result<&'_ CrateInherentImpls, ErrorGuaranteed> {
25+
) -> (&'_ CrateInherentImpls, Result<(), ErrorGuaranteed>) {
2626
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
27+
2728
let mut res = Ok(());
2829
for id in tcx.hir().items() {
2930
res = res.and(collect.check_item(id));
3031
}
31-
res?;
32-
Ok(tcx.arena.alloc(collect.impls_map))
32+
33+
(tcx.arena.alloc(collect.impls_map), res)
3334
}
3435

35-
pub(crate) fn crate_incoherent_impls(
36+
pub(crate) fn crate_inherent_impls_validity_check(
3637
tcx: TyCtxt<'_>,
37-
simp: SimplifiedType,
38-
) -> Result<&[DefId], ErrorGuaranteed> {
39-
let crate_map = tcx.crate_inherent_impls(())?;
40-
Ok(tcx.arena.alloc_from_iter(
38+
(): (),
39+
) -> Result<(), ErrorGuaranteed> {
40+
tcx.crate_inherent_impls(()).1
41+
}
42+
43+
pub(crate) fn crate_incoherent_impls(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
44+
let (crate_map, _) = tcx.crate_inherent_impls(());
45+
tcx.arena.alloc_from_iter(
4146
crate_map.incoherent_impls.get(&simp).unwrap_or(&Vec::new()).iter().map(|d| d.to_def_id()),
42-
))
47+
)
4348
}
4449

4550
/// On-demand query: yields a vector of the inherent impls for a specific type.
46-
pub(crate) fn inherent_impls(
47-
tcx: TyCtxt<'_>,
48-
ty_def_id: LocalDefId,
49-
) -> Result<&[DefId], ErrorGuaranteed> {
50-
let crate_map = tcx.crate_inherent_impls(())?;
51-
Ok(match crate_map.inherent_impls.get(&ty_def_id) {
51+
pub(crate) fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: LocalDefId) -> &[DefId] {
52+
let (crate_map, _) = tcx.crate_inherent_impls(());
53+
match crate_map.inherent_impls.get(&ty_def_id) {
5254
Some(v) => &v[..],
5355
None => &[],
54-
})
56+
}
5557
}
5658

5759
struct InherentCollect<'tcx> {

‎compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
177177
return Ok(());
178178
}
179179

180-
let impls = self.tcx.inherent_impls(id.owner_id)?;
181-
180+
let impls = self.tcx.inherent_impls(id.owner_id);
182181
let overlap_mode = OverlapMode::get(self.tcx, id.owner_id.to_def_id());
183182

184183
let impls_items = impls

‎compiler/rustc_hir_analysis/src/coherence/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ fn enforce_empty_impls_for_marker_traits(
124124

125125
pub(crate) fn provide(providers: &mut Providers) {
126126
use self::builtin::coerce_unsized_info;
127-
use self::inherent_impls::{crate_incoherent_impls, crate_inherent_impls, inherent_impls};
127+
use self::inherent_impls::{
128+
crate_incoherent_impls, crate_inherent_impls, crate_inherent_impls_validity_check,
129+
inherent_impls,
130+
};
128131
use self::inherent_impls_overlap::crate_inherent_impls_overlap_check;
129132
use self::orphan::orphan_check_impl;
130133

@@ -133,6 +136,7 @@ pub(crate) fn provide(providers: &mut Providers) {
133136
crate_inherent_impls,
134137
crate_incoherent_impls,
135138
inherent_impls,
139+
crate_inherent_impls_validity_check,
136140
crate_inherent_impls_overlap_check,
137141
coerce_unsized_info,
138142
orphan_check_impl,

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10281028
..
10291029
}) = node
10301030
&& let Some(ty_def_id) = qself_ty.ty_def_id()
1031-
&& let Ok([inherent_impl]) = tcx.inherent_impls(ty_def_id)
1031+
&& let [inherent_impl] = tcx.inherent_impls(ty_def_id)
10321032
&& let name = format!("{ident2}_{ident3}")
10331033
&& let Some(ty::AssocItem { kind: ty::AssocKind::Fn, .. }) = tcx
10341034
.associated_items(inherent_impl)

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12721272
}
12731273

12741274
let candidates: Vec<_> = tcx
1275-
.inherent_impls(adt_did)?
1275+
.inherent_impls(adt_did)
12761276
.iter()
12771277
.filter_map(|&impl_| {
12781278
let (item, scope) =

‎compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
170170
let _ = tcx.ensure().coherent_trait(trait_def_id);
171171
}
172172
// these queries are executed for side-effects (error reporting):
173-
let _ = tcx.ensure().crate_inherent_impls(());
173+
let _ = tcx.ensure().crate_inherent_impls_validity_check(());
174174
let _ = tcx.ensure().crate_inherent_impls_overlap_check(());
175175
});
176176

‎compiler/rustc_hir_typeck/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21262126
.tcx
21272127
.inherent_impls(def_id)
21282128
.into_iter()
2129-
.flatten()
21302129
.flat_map(|i| self.tcx.associated_items(i).in_definition_order())
21312130
// Only assoc fn with no receivers.
21322131
.filter(|item| {

‎compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
728728
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
729729
bug!("unexpected incoherent type: {:?}", self_ty)
730730
};
731-
for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter().flatten() {
731+
for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
732732
self.assemble_inherent_impl_probe(impl_def_id);
733733
}
734734
}
735735

736736
fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId) {
737-
let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter().flatten();
737+
let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
738738
for &impl_def_id in impl_def_ids {
739739
self.assemble_inherent_impl_probe(impl_def_id);
740740
}

‎compiler/rustc_hir_typeck/src/method/suggest.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
680680
self.tcx
681681
.inherent_impls(adt_def.did())
682682
.into_iter()
683-
.flatten()
684683
.any(|def_id| self.associated_value(*def_id, item_name).is_some())
685684
} else {
686685
false
@@ -1438,7 +1437,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14381437
.tcx
14391438
.inherent_impls(adt.did())
14401439
.into_iter()
1441-
.flatten()
14421440
.copied()
14431441
.filter(|def_id| {
14441442
if let Some(assoc) = self.associated_value(*def_id, item_name) {
@@ -1900,7 +1898,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19001898
call_args: Option<Vec<Ty<'tcx>>>,
19011899
) -> Option<Symbol> {
19021900
if let ty::Adt(adt, adt_args) = rcvr_ty.kind() {
1903-
for inherent_impl_did in self.tcx.inherent_impls(adt.did()).into_iter().flatten() {
1901+
for inherent_impl_did in self.tcx.inherent_impls(adt.did()).into_iter() {
19041902
for inherent_method in
19051903
self.tcx.associated_items(inherent_impl_did).in_definition_order()
19061904
{
@@ -2115,8 +2113,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21152113
return;
21162114
};
21172115
// FIXME(oli-obk): try out bubbling this error up one level and cancelling the other error in that case.
2118-
let Ok(impls) = self.tcx.inherent_impls(adt_def.did()) else { return };
2119-
let mut items = impls
2116+
let mut items = self
2117+
.tcx
2118+
.inherent_impls(adt_def.did())
21202119
.iter()
21212120
.flat_map(|i| self.tcx.associated_items(i).in_definition_order())
21222121
// Only assoc fn with no receivers and only if
@@ -2495,7 +2494,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24952494
.and_then(|simp| {
24962495
tcx.incoherent_impls(simp)
24972496
.into_iter()
2498-
.flatten()
24992497
.find_map(|&id| self.associated_value(id, item_name))
25002498
})
25012499
.is_some()

‎compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ provide! { tcx, def_id, other, cdata,
347347
tcx.arena.alloc_from_iter(cdata.get_associated_item_or_field_def_ids(def_id.index))
348348
}
349349
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
350-
inherent_impls => { Ok(cdata.get_inherent_implementations_for_type(tcx, def_id.index)) }
350+
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
351351
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
352352
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
353353
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
@@ -393,7 +393,7 @@ provide! { tcx, def_id, other, cdata,
393393
traits => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
394394
trait_impls_in_crate => { tcx.arena.alloc_from_iter(cdata.get_trait_impls()) }
395395
implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
396-
crate_incoherent_impls => { Ok(cdata.get_incoherent_impls(tcx, other)) }
396+
crate_incoherent_impls => { cdata.get_incoherent_impls(tcx, other) }
397397

398398
dep_kind => { cdata.dep_kind }
399399
module_children => {

‎compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15401540
}
15411541
}
15421542

1543-
for (def_id, impls) in &tcx.crate_inherent_impls(()).unwrap().inherent_impls {
1543+
for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
15441544
record_defaulted_array!(self.tables.inherent_impls[def_id.to_def_id()] <- impls.iter().map(|def_id| {
15451545
assert!(def_id.is_local());
15461546
def_id.index
@@ -2089,7 +2089,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20892089

20902090
let all_impls: Vec<_> = tcx
20912091
.crate_inherent_impls(())
2092-
.unwrap()
2092+
.0
20932093
.incoherent_impls
20942094
.iter()
20952095
.map(|(&simp, impls)| IncoherentImpls {

‎compiler/rustc_middle/src/query/erase.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::intrinsics::transmute_unchecked;
22
use std::mem::MaybeUninit;
33

4+
use rustc_span::ErrorGuaranteed;
5+
46
use crate::query::CyclePlaceholder;
57
use crate::ty::adjustment::CoerceUnsizedInfo;
68
use crate::ty::{self, Ty};
@@ -216,6 +218,10 @@ impl<T0, T1> EraseType for (&'_ T0, &'_ [T1]) {
216218
type Result = [u8; size_of::<(&'static (), &'static [()])>()];
217219
}
218220

221+
impl<T0> EraseType for (&'_ T0, Result<(), ErrorGuaranteed>) {
222+
type Result = [u8; size_of::<(&'static (), Result<(), ErrorGuaranteed>)>()];
223+
}
224+
219225
macro_rules! trivial {
220226
($($ty:ty),+ $(,)?) => {
221227
$(

‎compiler/rustc_middle/src/query/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -881,13 +881,13 @@ rustc_queries! {
881881
/// Maps a `DefId` of a type to a list of its inherent impls.
882882
/// Contains implementations of methods that are inherent to a type.
883883
/// Methods in these implementations don't need to be exported.
884-
query inherent_impls(key: DefId) -> Result<&'tcx [DefId], ErrorGuaranteed> {
884+
query inherent_impls(key: DefId) -> &'tcx [DefId] {
885885
desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
886886
cache_on_disk_if { key.is_local() }
887887
separate_provide_extern
888888
}
889889

890-
query incoherent_impls(key: SimplifiedType) -> Result<&'tcx [DefId], ErrorGuaranteed> {
890+
query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
891891
desc { |tcx| "collecting all inherent impls for `{:?}`", key }
892892
}
893893

@@ -1017,8 +1017,14 @@ rustc_queries! {
10171017

10181018
/// Gets a complete map from all types to their inherent impls.
10191019
/// Not meant to be used directly outside of coherence.
1020-
query crate_inherent_impls(k: ()) -> Result<&'tcx CrateInherentImpls, ErrorGuaranteed> {
1020+
query crate_inherent_impls(k: ()) -> (&'tcx CrateInherentImpls, Result<(), ErrorGuaranteed>) {
10211021
desc { "finding all inherent impls defined in crate" }
1022+
}
1023+
1024+
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
1025+
/// Not meant to be used directly outside of coherence.
1026+
query crate_inherent_impls_validity_check(_: ()) -> Result<(), ErrorGuaranteed> {
1027+
desc { "check for inherent impls that should not be defined in crate" }
10221028
ensure_forwards_result_if_red
10231029
}
10241030

@@ -1715,7 +1721,7 @@ rustc_queries! {
17151721
///
17161722
/// Do not call this directly, but instead use the `incoherent_impls` query.
17171723
/// This query is only used to get the data necessary for that query.
1718-
query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> Result<&'tcx [DefId], ErrorGuaranteed> {
1724+
query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
17191725
desc { |tcx| "collecting all impls for a type in a crate" }
17201726
separate_provide_extern
17211727
}

‎compiler/rustc_middle/src/ty/trait_def.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -253,30 +253,16 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
253253
}
254254

255255
/// Query provider for `incoherent_impls`.
256-
pub(super) fn incoherent_impls_provider(
257-
tcx: TyCtxt<'_>,
258-
simp: SimplifiedType,
259-
) -> Result<&[DefId], ErrorGuaranteed> {
256+
pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
260257
let mut impls = Vec::new();
261-
262-
let mut res = Ok(());
263258
for cnum in iter::once(LOCAL_CRATE).chain(tcx.crates(()).iter().copied()) {
264-
let incoherent_impls = match tcx.crate_incoherent_impls((cnum, simp)) {
265-
Ok(impls) => impls,
266-
Err(e) => {
267-
res = Err(e);
268-
continue;
269-
}
270-
};
271-
for &impl_def_id in incoherent_impls {
259+
for &impl_def_id in tcx.crate_incoherent_impls((cnum, simp)) {
272260
impls.push(impl_def_id)
273261
}
274262
}
275-
276263
debug!(?impls);
277-
res?;
278264

279-
Ok(tcx.arena.alloc_slice(&impls))
265+
tcx.arena.alloc_slice(&impls)
280266
}
281267

282268
pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {

‎compiler/rustc_monomorphize/src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
11831183
}
11841184

11851185
fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> {
1186-
for impl_def_id in tcx.inherent_impls(def_id).ok()? {
1186+
for impl_def_id in tcx.inherent_impls(def_id) {
11871187
if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind(
11881188
tcx,
11891189
fn_ident,

‎compiler/rustc_resolve/src/late/diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1825,10 +1825,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
18251825
// Doing analysis on local `DefId`s would cause infinite recursion.
18261826
return;
18271827
}
1828-
let Ok(impls) = self.r.tcx.inherent_impls(def_id) else { return };
18291828
// Look at all the associated functions without receivers in the type's
18301829
// inherent impls to look for builders that return `Self`
1831-
let mut items = impls
1830+
let mut items = self
1831+
.r
1832+
.tcx
1833+
.inherent_impls(def_id)
18321834
.iter()
18331835
.flat_map(|i| self.r.tcx.associated_items(i).in_definition_order())
18341836
// Only assoc fn with no receivers.

‎tests/ui/const-generics/wrong-normalization.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ pub struct I8<const F: i8>;
1515

1616
impl <I8<{i8::MIN}> as Identity>::Identity {
1717
//~^ ERROR no nominal type found for inherent implementation
18-
//~| ERROR no associated item named `MIN` found for type `i8`
1918
pub fn foo(&self) {}
2019
}

‎tests/ui/const-generics/wrong-normalization.stderr

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ LL | impl <I8<{i8::MIN}> as Identity>::Identity {
66
|
77
= note: either implement a trait on it or create a newtype to wrap it instead
88

9-
error[E0599]: no associated item named `MIN` found for type `i8` in the current scope
10-
--> $DIR/wrong-normalization.rs:16:15
11-
|
12-
LL | impl <I8<{i8::MIN}> as Identity>::Identity {
13-
| ^^^ associated item not found in `i8`
14-
|
15-
help: you are looking for the module in `std`, not the primitive type
16-
|
17-
LL | impl <I8<{std::i8::MIN}> as Identity>::Identity {
18-
| +++++
19-
20-
error: aborting due to 2 previous errors
9+
error: aborting due to 1 previous error
2110

22-
Some errors have detailed explanations: E0118, E0599.
23-
For more information about an error, try `rustc --explain E0118`.
11+
For more information about this error, try `rustc --explain E0118`.

‎tests/ui/impl-trait/where-allowed.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
4242
fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
4343
//~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
4444

45-
// Allowed
45+
// Allowed (but it's still ambiguous; nothing constrains the RPIT in this body).
4646
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
4747
//~^ ERROR: type annotations needed
4848

@@ -79,7 +79,6 @@ fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!(
7979
// Allowed
8080
fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
8181
vec![vec![0; 10], vec![12; 7], vec![8; 3]]
82-
//~^ ERROR: no function or associated item named `into_vec` found for slice `[_]`
8382
}
8483

8584
// Disallowed

‎tests/ui/impl-trait/where-allowed.stderr

+38-48
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic
1717
| outer `impl Trait`
1818

1919
error[E0658]: `impl Trait` in associated types is unstable
20-
--> $DIR/where-allowed.rs:122:16
20+
--> $DIR/where-allowed.rs:121:16
2121
|
2222
LL | type Out = impl Debug;
2323
| ^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | type Out = impl Debug;
2727
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2828

2929
error[E0658]: `impl Trait` in type aliases is unstable
30-
--> $DIR/where-allowed.rs:159:23
30+
--> $DIR/where-allowed.rs:158:23
3131
|
3232
LL | type InTypeAlias<R> = impl Debug;
3333
| ^^^^^^^^^^
@@ -37,7 +37,7 @@ LL | type InTypeAlias<R> = impl Debug;
3737
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3838

3939
error[E0658]: `impl Trait` in type aliases is unstable
40-
--> $DIR/where-allowed.rs:162:39
40+
--> $DIR/where-allowed.rs:161:39
4141
|
4242
LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
4343
| ^^^^^^^^^^
@@ -143,199 +143,199 @@ LL | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
143143
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
144144

145145
error[E0562]: `impl Trait` is not allowed in field types
146-
--> $DIR/where-allowed.rs:86:32
146+
--> $DIR/where-allowed.rs:85:32
147147
|
148148
LL | struct InBraceStructField { x: impl Debug }
149149
| ^^^^^^^^^^
150150
|
151151
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
152152

153153
error[E0562]: `impl Trait` is not allowed in field types
154-
--> $DIR/where-allowed.rs:90:41
154+
--> $DIR/where-allowed.rs:89:41
155155
|
156156
LL | struct InAdtInBraceStructField { x: Vec<impl Debug> }
157157
| ^^^^^^^^^^
158158
|
159159
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
160160

161161
error[E0562]: `impl Trait` is not allowed in field types
162-
--> $DIR/where-allowed.rs:94:27
162+
--> $DIR/where-allowed.rs:93:27
163163
|
164164
LL | struct InTupleStructField(impl Debug);
165165
| ^^^^^^^^^^
166166
|
167167
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
168168

169169
error[E0562]: `impl Trait` is not allowed in field types
170-
--> $DIR/where-allowed.rs:99:25
170+
--> $DIR/where-allowed.rs:98:25
171171
|
172172
LL | InBraceVariant { x: impl Debug },
173173
| ^^^^^^^^^^
174174
|
175175
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
176176

177177
error[E0562]: `impl Trait` is not allowed in field types
178-
--> $DIR/where-allowed.rs:101:20
178+
--> $DIR/where-allowed.rs:100:20
179179
|
180180
LL | InTupleVariant(impl Debug),
181181
| ^^^^^^^^^^
182182
|
183183
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
184184

185185
error[E0562]: `impl Trait` is not allowed in `extern fn` parameters
186-
--> $DIR/where-allowed.rs:143:33
186+
--> $DIR/where-allowed.rs:142:33
187187
|
188188
LL | fn in_foreign_parameters(_: impl Debug);
189189
| ^^^^^^^^^^
190190
|
191191
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
192192

193193
error[E0562]: `impl Trait` is not allowed in `extern fn` return types
194-
--> $DIR/where-allowed.rs:146:31
194+
--> $DIR/where-allowed.rs:145:31
195195
|
196196
LL | fn in_foreign_return() -> impl Debug;
197197
| ^^^^^^^^^^
198198
|
199199
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
200200

201201
error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
202-
--> $DIR/where-allowed.rs:162:39
202+
--> $DIR/where-allowed.rs:161:39
203203
|
204204
LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
205205
| ^^^^^^^^^^
206206
|
207207
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
208208

209209
error[E0562]: `impl Trait` is not allowed in traits
210-
--> $DIR/where-allowed.rs:167:16
210+
--> $DIR/where-allowed.rs:166:16
211211
|
212212
LL | impl PartialEq<impl Debug> for () {
213213
| ^^^^^^^^^^
214214
|
215215
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
216216

217217
error[E0562]: `impl Trait` is not allowed in impl headers
218-
--> $DIR/where-allowed.rs:172:24
218+
--> $DIR/where-allowed.rs:171:24
219219
|
220220
LL | impl PartialEq<()> for impl Debug {
221221
| ^^^^^^^^^^
222222
|
223223
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
224224

225225
error[E0562]: `impl Trait` is not allowed in impl headers
226-
--> $DIR/where-allowed.rs:177:6
226+
--> $DIR/where-allowed.rs:176:6
227227
|
228228
LL | impl impl Debug {
229229
| ^^^^^^^^^^
230230
|
231231
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
232232

233233
error[E0562]: `impl Trait` is not allowed in impl headers
234-
--> $DIR/where-allowed.rs:183:24
234+
--> $DIR/where-allowed.rs:182:24
235235
|
236236
LL | impl InInherentImplAdt<impl Debug> {
237237
| ^^^^^^^^^^
238238
|
239239
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
240240

241241
error[E0562]: `impl Trait` is not allowed in bounds
242-
--> $DIR/where-allowed.rs:189:11
242+
--> $DIR/where-allowed.rs:188:11
243243
|
244244
LL | where impl Debug: Debug
245245
| ^^^^^^^^^^
246246
|
247247
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
248248

249249
error[E0562]: `impl Trait` is not allowed in bounds
250-
--> $DIR/where-allowed.rs:196:15
250+
--> $DIR/where-allowed.rs:195:15
251251
|
252252
LL | where Vec<impl Debug>: Debug
253253
| ^^^^^^^^^^
254254
|
255255
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
256256

257257
error[E0562]: `impl Trait` is not allowed in bounds
258-
--> $DIR/where-allowed.rs:203:24
258+
--> $DIR/where-allowed.rs:202:24
259259
|
260260
LL | where T: PartialEq<impl Debug>
261261
| ^^^^^^^^^^
262262
|
263263
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
264264

265265
error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
266-
--> $DIR/where-allowed.rs:210:17
266+
--> $DIR/where-allowed.rs:209:17
267267
|
268268
LL | where T: Fn(impl Debug)
269269
| ^^^^^^^^^^
270270
|
271271
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
272272

273273
error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
274-
--> $DIR/where-allowed.rs:217:22
274+
--> $DIR/where-allowed.rs:216:22
275275
|
276276
LL | where T: Fn() -> impl Debug
277277
| ^^^^^^^^^^
278278
|
279279
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
280280

281281
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
282-
--> $DIR/where-allowed.rs:223:40
282+
--> $DIR/where-allowed.rs:222:40
283283
|
284284
LL | struct InStructGenericParamDefault<T = impl Debug>(T);
285285
| ^^^^^^^^^^
286286
|
287287
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
288288

289289
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
290-
--> $DIR/where-allowed.rs:227:36
290+
--> $DIR/where-allowed.rs:226:36
291291
|
292292
LL | enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
293293
| ^^^^^^^^^^
294294
|
295295
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
296296

297297
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
298-
--> $DIR/where-allowed.rs:231:38
298+
--> $DIR/where-allowed.rs:230:38
299299
|
300300
LL | trait InTraitGenericParamDefault<T = impl Debug> {}
301301
| ^^^^^^^^^^
302302
|
303303
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
304304

305305
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
306-
--> $DIR/where-allowed.rs:235:41
306+
--> $DIR/where-allowed.rs:234:41
307307
|
308308
LL | type InTypeAliasGenericParamDefault<T = impl Debug> = T;
309309
| ^^^^^^^^^^
310310
|
311311
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
312312

313313
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
314-
--> $DIR/where-allowed.rs:239:11
314+
--> $DIR/where-allowed.rs:238:11
315315
|
316316
LL | impl <T = impl Debug> T {}
317317
| ^^^^^^^^^^
318318
|
319319
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
320320

321321
error[E0562]: `impl Trait` is not allowed in generic parameter defaults
322-
--> $DIR/where-allowed.rs:246:40
322+
--> $DIR/where-allowed.rs:245:40
323323
|
324324
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
325325
| ^^^^^^^^^^
326326
|
327327
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
328328

329329
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
330-
--> $DIR/where-allowed.rs:252:29
330+
--> $DIR/where-allowed.rs:251:29
331331
|
332332
LL | let _in_local_variable: impl Fn() = || {};
333333
| ^^^^^^^^^
334334
|
335335
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
336336

337337
error[E0562]: `impl Trait` is not allowed in closure return types
338-
--> $DIR/where-allowed.rs:254:46
338+
--> $DIR/where-allowed.rs:253:46
339339
|
340340
LL | let _in_return_in_local_variable = || -> impl Fn() { || {} };
341341
| ^^^^^^^^^
@@ -363,7 +363,7 @@ LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { pani
363363
where Args: Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
364364

365365
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
366-
--> $DIR/where-allowed.rs:239:7
366+
--> $DIR/where-allowed.rs:238:7
367367
|
368368
LL | impl <T = impl Debug> T {}
369369
| ^^^^^^^^^^^^^^
@@ -373,25 +373,15 @@ LL | impl <T = impl Debug> T {}
373373
= note: `#[deny(invalid_type_param_default)]` on by default
374374

375375
error[E0118]: no nominal type found for inherent implementation
376-
--> $DIR/where-allowed.rs:239:1
376+
--> $DIR/where-allowed.rs:238:1
377377
|
378378
LL | impl <T = impl Debug> T {}
379379
| ^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type
380380
|
381381
= note: either implement a trait on it or create a newtype to wrap it instead
382382

383-
error[E0599]: no function or associated item named `into_vec` found for slice `[_]` in the current scope
384-
--> $DIR/where-allowed.rs:81:5
385-
|
386-
LL | vec![vec![0; 10], vec![12; 7], vec![8; 3]]
387-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `[_]`
388-
|
389-
help: there is an associated function `to_vec` with a similar name
390-
--> $SRC_DIR/alloc/src/slice.rs:LL:COL
391-
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
392-
393383
error[E0053]: method `in_trait_impl_return` has an incompatible type for trait
394-
--> $DIR/where-allowed.rs:129:34
384+
--> $DIR/where-allowed.rs:128:34
395385
|
396386
LL | type Out = impl Debug;
397387
| ---------- the expected opaque type
@@ -400,7 +390,7 @@ LL | fn in_trait_impl_return() -> impl Debug { () }
400390
| ^^^^^^^^^^ expected opaque type, found a different opaque type
401391
|
402392
note: type in trait
403-
--> $DIR/where-allowed.rs:119:34
393+
--> $DIR/where-allowed.rs:118:34
404394
|
405395
LL | fn in_trait_impl_return() -> Self::Out;
406396
| ^^^^^^^^^
@@ -413,29 +403,29 @@ LL | fn in_trait_impl_return() -> <() as DummyTrait>::Out { () }
413403
| ~~~~~~~~~~~~~~~~~~~~~~~
414404

415405
error: unconstrained opaque type
416-
--> $DIR/where-allowed.rs:122:16
406+
--> $DIR/where-allowed.rs:121:16
417407
|
418408
LL | type Out = impl Debug;
419409
| ^^^^^^^^^^
420410
|
421411
= note: `Out` must be used in combination with a concrete type within the same impl
422412

423413
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
424-
--> $DIR/where-allowed.rs:246:36
414+
--> $DIR/where-allowed.rs:245:36
425415
|
426416
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
427417
| ^^^^^^^^^^^^^^
428418
|
429419
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
430420
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
431421

432-
error: aborting due to 50 previous errors
422+
error: aborting due to 49 previous errors
433423

434-
Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0599, E0658, E0666.
424+
Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0658, E0666.
435425
For more information about an error, try `rustc --explain E0053`.
436426
Future incompatibility report: Future breakage diagnostic:
437427
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
438-
--> $DIR/where-allowed.rs:239:7
428+
--> $DIR/where-allowed.rs:238:7
439429
|
440430
LL | impl <T = impl Debug> T {}
441431
| ^^^^^^^^^^^^^^
@@ -446,7 +436,7 @@ LL | impl <T = impl Debug> T {}
446436

447437
Future breakage diagnostic:
448438
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
449-
--> $DIR/where-allowed.rs:246:36
439+
--> $DIR/where-allowed.rs:245:36
450440
|
451441
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
452442
| ^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Make sure that an invalid inherent impl doesn't totally clobber all of the
2+
// other inherent impls, which lead to mysterious method/assoc-item probing errors.
3+
4+
impl () {}
5+
//~^ ERROR cannot define inherent `impl` for primitive types
6+
7+
struct W;
8+
impl W {
9+
const CONST: u32 = 0;
10+
}
11+
12+
fn main() {
13+
let _ = W::CONST;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0390]: cannot define inherent `impl` for primitive types
2+
--> $DIR/incoherent-impl-ambiguity.rs:4:1
3+
|
4+
LL | impl () {}
5+
| ^^^^^^^
6+
|
7+
= help: consider using an extension trait instead
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0390`.

0 commit comments

Comments
 (0)
Please sign in to comment.