AST validation: Improve handling of inherent impls nested within functions and anon consts
This commit is contained in:
parent
5257aee7dd
commit
7d428db605
@ -930,35 +930,38 @@ fn visit_item(&mut self, item: &'a Item) {
|
||||
only_trait: only_trait.then_some(()),
|
||||
};
|
||||
|
||||
self.visibility_not_permitted(
|
||||
&item.vis,
|
||||
errors::VisibilityNotPermittedNote::IndividualImplItems,
|
||||
);
|
||||
if let &Unsafe::Yes(span) = unsafety {
|
||||
self.dcx().emit_err(errors::InherentImplCannotUnsafe {
|
||||
span: self_ty.span,
|
||||
annotation_span: span,
|
||||
annotation: "unsafe",
|
||||
self_ty: self_ty.span,
|
||||
});
|
||||
}
|
||||
if let &ImplPolarity::Negative(span) = polarity {
|
||||
self.dcx().emit_err(error(span, "negative", false));
|
||||
}
|
||||
if let &Defaultness::Default(def_span) = defaultness {
|
||||
self.dcx().emit_err(error(def_span, "`default`", true));
|
||||
}
|
||||
if let &Const::Yes(span) = constness {
|
||||
self.dcx().emit_err(error(span, "`const`", true));
|
||||
}
|
||||
self.with_in_trait_impl(None, |this| {
|
||||
this.visibility_not_permitted(
|
||||
&item.vis,
|
||||
errors::VisibilityNotPermittedNote::IndividualImplItems,
|
||||
);
|
||||
if let &Unsafe::Yes(span) = unsafety {
|
||||
this.dcx().emit_err(errors::InherentImplCannotUnsafe {
|
||||
span: self_ty.span,
|
||||
annotation_span: span,
|
||||
annotation: "unsafe",
|
||||
self_ty: self_ty.span,
|
||||
});
|
||||
}
|
||||
if let &ImplPolarity::Negative(span) = polarity {
|
||||
this.dcx().emit_err(error(span, "negative", false));
|
||||
}
|
||||
if let &Defaultness::Default(def_span) = defaultness {
|
||||
this.dcx().emit_err(error(def_span, "`default`", true));
|
||||
}
|
||||
if let &Const::Yes(span) = constness {
|
||||
this.dcx().emit_err(error(span, "`const`", true));
|
||||
}
|
||||
|
||||
self.visit_vis(&item.vis);
|
||||
self.visit_ident(item.ident);
|
||||
self.with_tilde_const(Some(DisallowTildeConstContext::Impl(item.span)), |this| {
|
||||
this.visit_generics(generics)
|
||||
this.visit_vis(&item.vis);
|
||||
this.visit_ident(item.ident);
|
||||
this.with_tilde_const(
|
||||
Some(DisallowTildeConstContext::Impl(item.span)),
|
||||
|this| this.visit_generics(generics),
|
||||
);
|
||||
this.visit_ty(self_ty);
|
||||
walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl);
|
||||
});
|
||||
self.visit_ty(self_ty);
|
||||
walk_list!(self, visit_assoc_item, items, AssocCtxt::Impl);
|
||||
walk_list!(self, visit_attribute, &item.attrs);
|
||||
return; // Avoid visiting again.
|
||||
}
|
||||
|
35
tests/ui/parser/impls-nested-within-anon-consts-semantic.rs
Normal file
35
tests/ui/parser/impls-nested-within-anon-consts-semantic.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// Regression test for issue #89342 and for part of #119924.
|
||||
//@ check-pass
|
||||
|
||||
struct Expr<const N: u32>;
|
||||
|
||||
trait Trait0 {
|
||||
fn required(_: Expr<{
|
||||
struct Type;
|
||||
|
||||
impl Type {
|
||||
// This visibility qualifier used to get rejected.
|
||||
pub fn perform() {}
|
||||
}
|
||||
|
||||
0
|
||||
}>);
|
||||
}
|
||||
|
||||
trait Trait1 {}
|
||||
|
||||
impl Trait1 for ()
|
||||
where
|
||||
[(); {
|
||||
struct Type;
|
||||
|
||||
impl Type {
|
||||
// This visibility qualifier used to get rejected.
|
||||
pub const STORE: Self = Self;
|
||||
}
|
||||
|
||||
0
|
||||
}]:
|
||||
{}
|
||||
|
||||
fn main() {}
|
15
tests/ui/parser/impls-nested-within-fns-semantic-0.rs
Normal file
15
tests/ui/parser/impls-nested-within-fns-semantic-0.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Regression test for #121607 and for part of issue #119924.
|
||||
//@ check-pass
|
||||
|
||||
trait Trait {
|
||||
fn provided() {
|
||||
pub struct Type;
|
||||
|
||||
impl Type {
|
||||
// This visibility qualifier used to get rejected.
|
||||
pub fn perform() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
22
tests/ui/parser/impls-nested-within-fns-semantic-1.rs
Normal file
22
tests/ui/parser/impls-nested-within-fns-semantic-1.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Regression test for part of issue #119924.
|
||||
//@ check-pass
|
||||
|
||||
#![feature(const_trait_impl, effects)]
|
||||
|
||||
#[const_trait]
|
||||
trait Trait {
|
||||
fn required();
|
||||
}
|
||||
|
||||
impl const Trait for () {
|
||||
fn required() {
|
||||
pub struct Type;
|
||||
|
||||
impl Type {
|
||||
// This visibility qualifier used to get rejected.
|
||||
pub fn perform() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user