ast_validation: fix visiting bug.
This commit is contained in:
parent
67c29ed8fc
commit
9a4eac3944
@ -81,6 +81,12 @@ struct AstValidator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AstValidator<'a> {
|
impl<'a> AstValidator<'a> {
|
||||||
|
fn with_in_trait_impl(&mut self, is_in: bool, f: impl FnOnce(&mut Self)) {
|
||||||
|
let old = mem::replace(&mut self.in_trait_impl, is_in);
|
||||||
|
f(self);
|
||||||
|
self.in_trait_impl = old;
|
||||||
|
}
|
||||||
|
|
||||||
fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) {
|
fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) {
|
||||||
let old = mem::replace(&mut self.is_impl_trait_banned, true);
|
let old = mem::replace(&mut self.is_impl_trait_banned, true);
|
||||||
f(self);
|
f(self);
|
||||||
@ -737,28 +743,29 @@ fn visit_item(&mut self, item: &'a Item) {
|
|||||||
ref self_ty,
|
ref self_ty,
|
||||||
items: _,
|
items: _,
|
||||||
} => {
|
} => {
|
||||||
let old_in_trait_impl = mem::replace(&mut self.in_trait_impl, true);
|
self.with_in_trait_impl(true, |this| {
|
||||||
|
this.invalid_visibility(&item.vis, None);
|
||||||
self.invalid_visibility(&item.vis, None);
|
if let TyKind::Err = self_ty.kind {
|
||||||
if let TyKind::Err = self_ty.kind {
|
this.err_handler()
|
||||||
self.err_handler()
|
.struct_span_err(
|
||||||
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
|
item.span,
|
||||||
.help("use `auto trait Trait {}` instead")
|
"`impl Trait for .. {}` is an obsolete syntax",
|
||||||
|
)
|
||||||
|
.help("use `auto trait Trait {}` instead")
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
if unsafety == Unsafety::Unsafe && polarity == ImplPolarity::Negative {
|
||||||
|
struct_span_err!(
|
||||||
|
this.session,
|
||||||
|
item.span,
|
||||||
|
E0198,
|
||||||
|
"negative impls cannot be unsafe"
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
if unsafety == Unsafety::Unsafe && polarity == ImplPolarity::Negative {
|
|
||||||
struct_span_err!(
|
|
||||||
self.session,
|
|
||||||
item.span,
|
|
||||||
E0198,
|
|
||||||
"negative impls cannot be unsafe"
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
}
|
|
||||||
|
|
||||||
visit::walk_item(self, item);
|
visit::walk_item(this, item);
|
||||||
|
});
|
||||||
self.in_trait_impl = old_in_trait_impl;
|
|
||||||
return; // Avoid visiting again.
|
return; // Avoid visiting again.
|
||||||
}
|
}
|
||||||
ItemKind::Impl {
|
ItemKind::Impl {
|
||||||
@ -1142,7 +1149,7 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visit::walk_assoc_item(self, item, ctxt);
|
self.with_in_trait_impl(false, |this| visit::walk_assoc_item(this, item, ctxt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/test/ui/parser/issue-68788-in-trait-item-propagation.rs
Normal file
21
src/test/ui/parser/issue-68788-in-trait-item-propagation.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Make sure we don't propagate restrictions on trait impl items to items inside them.
|
||||||
|
|
||||||
|
// check-pass
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
trait X {
|
||||||
|
fn foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl X for () {
|
||||||
|
fn foo() {
|
||||||
|
struct S;
|
||||||
|
impl S {
|
||||||
|
pub const X: u8 = 0;
|
||||||
|
pub const fn bar() {}
|
||||||
|
async fn qux() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user