Rollup merge of #82516 - PoignardAzur:inherent-impl-ty, r=oli-obk
Add incomplete feature gate for inherent associate types. Mentored by ``````@oli-obk`````` So far the only change is that instead of giving an automatic error, the following code compiles: ```rust struct Foo; impl Foo { type Bar = isize; } ``` The backend work to make it actually usable isn't there yet. In particular, this: ```rust let x : Foo::Bar; ``` will give you: ```sh error[E0223]: ambiguous associated type --> /$RUSTC_DIR/src/test/ui/assoc-inherent.rs:15:13 | LL | let x : Foo::Bar; | ^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Bar` ```
This commit is contained in:
commit
5e68c60406
12 changed files with 89 additions and 45 deletions
|
@ -1,4 +1,3 @@
|
|||
use crate::errors::AssocTypeOnInherentImpl;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, ErrorReported, StashKey};
|
||||
use rustc_hir as hir;
|
||||
|
@ -294,7 +293,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
}
|
||||
ImplItemKind::TyAlias(ref ty) => {
|
||||
if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() {
|
||||
report_assoc_ty_on_inherent_impl(tcx, item.span);
|
||||
check_feature_inherent_assoc_ty(tcx, item.span);
|
||||
}
|
||||
|
||||
icx.to_ty(ty)
|
||||
|
@ -746,6 +745,16 @@ fn infer_placeholder_type(
|
|||
})
|
||||
}
|
||||
|
||||
fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
|
||||
tcx.sess.emit_err(AssocTypeOnInherentImpl { span });
|
||||
fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
|
||||
if !tcx.features().inherent_associated_types {
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::sym;
|
||||
feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::inherent_associated_types,
|
||||
span,
|
||||
"inherent associated types are unstable",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,13 +82,6 @@ pub struct CopyImplOnTypeWithDtor {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0202"]
|
||||
pub struct AssocTypeOnInherentImpl {
|
||||
#[message = "associated types are not yet supported in inherent impls (see #8995)"]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0203"]
|
||||
pub struct MultipleRelaxedDefaultBounds {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue