Detect duplicates
This commit is contained in:
parent
f66558d2bf
commit
2e03130e11
7 changed files with 78 additions and 8 deletions
|
@ -193,8 +193,24 @@ impl<'a> AstValidator<'a> {
|
|||
// Mirrors `visit::walk_ty`, but tracks relevant state.
|
||||
fn walk_ty(&mut self, t: &'a Ty) {
|
||||
match &t.kind {
|
||||
TyKind::ImplTrait(..) => {
|
||||
self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t))
|
||||
TyKind::ImplTrait(_, bounds) => {
|
||||
self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t));
|
||||
|
||||
// FIXME(precise_capturing): If we were to allow `use` in other positions
|
||||
// (e.g. GATs), then we must validate those as well. However, we don't have
|
||||
// a good way of doing this with the current `Visitor` structure.
|
||||
let mut use_bounds = bounds
|
||||
.iter()
|
||||
.filter_map(|bound| match bound {
|
||||
GenericBound::Use(_, span) => Some(span),
|
||||
_ => None,
|
||||
})
|
||||
.copied();
|
||||
if let Some(bound1) = use_bounds.next()
|
||||
&& let Some(bound2) = use_bounds.next()
|
||||
{
|
||||
self.dcx().emit_err(errors::DuplicatePreciseCapturing { bound1, bound2 });
|
||||
}
|
||||
}
|
||||
TyKind::TraitObject(..) => self
|
||||
.with_tilde_const(Some(DisallowTildeConstContext::TraitObject), |this| {
|
||||
|
|
|
@ -852,3 +852,12 @@ pub struct PreciseCapturingNotAllowedHere {
|
|||
pub span: Span,
|
||||
pub loc: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_precise_capturing_duplicated)]
|
||||
pub struct DuplicatePreciseCapturing {
|
||||
#[primary_span]
|
||||
pub bound1: Span,
|
||||
#[label]
|
||||
pub bound2: Span,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue