review, improve note span

This commit is contained in:
Bastian Kauschke 2020-09-08 11:37:27 +02:00
parent e5b82a56c5
commit c552717e9d
5 changed files with 40 additions and 41 deletions

View File

@ -201,11 +201,13 @@ pub enum Res<Id = hir::HirId> {
PrimTy(hir::PrimTy), PrimTy(hir::PrimTy),
/// `Self`, with both an optional trait and impl `DefId`. /// `Self`, with both an optional trait and impl `DefId`.
/// ///
/// HACK: impl self types also have an optional requirement to not mention /// HACK(min_const_generics): impl self types also have an optional requirement to not mention
/// any generic parameters to allow the following with `min_const_generics`. /// any generic parameters to allow the following with `min_const_generics`:
/// `impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()]`. /// ```rust
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] {} }
/// ```
/// ///
/// Once `lazy_normalization_consts` is stable, this bodge can be removed again. /// FIXME(lazy_normalization_consts): Remove this bodge once this feature is stable.
SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */), SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */),
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]` ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`

View File

@ -2627,25 +2627,23 @@ impl<'a> Resolver<'a> {
continue; continue;
} }
ConstantItemRibKind(trivial) => { ConstantItemRibKind(trivial) => {
if self.session.features_untracked().min_const_generics { // HACK(min_const_generics): We currently only allow `N` or `{ N }`.
// HACK(min_const_generics): We currently only allow `N` or `{ N }`. if !trivial && self.session.features_untracked().min_const_generics {
if !trivial { // HACK(min_const_generics): If we encounter `Self` in an anonymous constant
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant // we can't easily tell if it's generic at this stage, so we instead remember
// we can't easily tell if it's generic at this stage, so we instead remember // this and then enforce the self type to be concrete later on.
// this and then enforce the self type to be concrete later on. if let Res::SelfTy(trait_def, Some((impl_def, _))) = res {
if let Res::SelfTy(trait_def, Some((impl_def, _))) = res { res = Res::SelfTy(trait_def, Some((impl_def, true)));
res = Res::SelfTy(trait_def, Some((impl_def, true))); } else {
} else { if record_used {
if record_used { self.report_error(
self.report_error( span,
span, ResolutionError::ParamInNonTrivialAnonConst(
ResolutionError::ParamInNonTrivialAnonConst( rib_ident.name,
rib_ident.name, ),
), );
);
}
return Res::Err;
} }
return Res::Err;
} }
} }

View File

@ -1924,13 +1924,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Try to evaluate any array length constants. // Try to evaluate any array length constants.
let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id)); let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id));
if forbid_generic && normalized_ty.needs_subst() { if forbid_generic && normalized_ty.needs_subst() {
tcx.sess let mut err = tcx.sess.struct_span_err(
.struct_span_err( path.span,
path.span, "generic `Self` types are currently not permitted in anonymous constants",
"generic `Self` types are currently not permitted in anonymous constants" );
) if let Some(hir::Node::Item(&hir::Item {
.span_note(tcx.def_span(def_id), "not a concrete type") kind: hir::ItemKind::Impl { self_ty, .. },
.emit(); ..
})) = tcx.hir().get_if_local(def_id)
{
err.span_note(self_ty.span, "not a concrete type");
}
err.emit();
tcx.ty_error() tcx.ty_error()
} else { } else {
normalized_ty normalized_ty

View File

@ -13,12 +13,10 @@ LL | fn t3() -> [u8; std::mem::size_of::<Self>()] {}
| ^^^^ | ^^^^
| |
note: not a concrete type note: not a concrete type
--> $DIR/self-ty-in-const-1.rs:13:1 --> $DIR/self-ty-in-const-1.rs:13:9
| |
LL | / impl<T> Bar<T> { LL | impl<T> Bar<T> {
LL | | fn t3() -> [u8; std::mem::size_of::<Self>()] {} | ^^^^^^
LL | | }
| |_^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -5,14 +5,10 @@ LL | let _: [u8; std::mem::size_of::<Self>()];
| ^^^^ | ^^^^
| |
note: not a concrete type note: not a concrete type
--> $DIR/self-ty-in-const-2.rs:15:1 --> $DIR/self-ty-in-const-2.rs:15:17
| |
LL | / impl<T> Baz for Bar<T> { LL | impl<T> Baz for Bar<T> {
LL | | fn hey() { | ^^^^^^
LL | | let _: [u8; std::mem::size_of::<Self>()];
LL | | }
LL | | }
| |_^
error: aborting due to previous error error: aborting due to previous error