]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/ast_validation.rs
Rollup merge of #57229 - mikeyhew:fix-56806, r=varkor
[rust.git] / src / librustc_passes / ast_validation.rs
1 // Validate AST before lowering it to HIR
2 //
3 // This pass is supposed to catch things that fit into AST data structures,
4 // but not permitted by the language. It runs after expansion when AST is frozen,
5 // so it can check for erroneous constructions produced by syntax extensions.
6 // This pass is supposed to perform only simple checks not requiring name resolution
7 // or type checking or some other kind of complex analysis.
8
9 use rustc::lint;
10 use rustc::session::Session;
11 use syntax::ast::*;
12 use syntax::attr;
13 use syntax::source_map::Spanned;
14 use syntax::symbol::keywords;
15 use syntax::ptr::P;
16 use syntax::visit::{self, Visitor};
17 use syntax_pos::Span;
18 use errors;
19 use errors::Applicability;
20
21 struct AstValidator<'a> {
22     session: &'a Session,
23 }
24
25 impl<'a> AstValidator<'a> {
26     fn err_handler(&self) -> &errors::Handler {
27         &self.session.diagnostic()
28     }
29
30     fn check_lifetime(&self, ident: Ident) {
31         let valid_names = [keywords::UnderscoreLifetime.name(),
32                            keywords::StaticLifetime.name(),
33                            keywords::Invalid.name()];
34         if !valid_names.contains(&ident.name) && ident.without_first_quote().is_reserved() {
35             self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names");
36         }
37     }
38
39     fn check_label(&self, ident: Ident) {
40         if ident.without_first_quote().is_reserved() {
41             self.err_handler()
42                 .span_err(ident.span, &format!("invalid label name `{}`", ident.name));
43         }
44     }
45
46     fn invalid_non_exhaustive_attribute(&self, variant: &Variant) {
47         let has_non_exhaustive = attr::contains_name(&variant.node.attrs, "non_exhaustive");
48         if has_non_exhaustive {
49             self.err_handler().span_err(variant.span,
50                                         "#[non_exhaustive] is not yet supported on variants");
51         }
52     }
53
54     fn invalid_visibility(&self, vis: &Visibility, note: Option<&str>) {
55         if let VisibilityKind::Inherited = vis.node {
56             return
57         }
58
59         let mut err = struct_span_err!(self.session,
60                                         vis.span,
61                                         E0449,
62                                         "unnecessary visibility qualifier");
63         if vis.node.is_pub() {
64             err.span_label(vis.span, "`pub` not permitted here because it's implied");
65         }
66         if let Some(note) = note {
67             err.note(note);
68         }
69         err.emit();
70     }
71
72     fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err: ReportFn) {
73         for arg in &decl.inputs {
74             match arg.pat.node {
75                 PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), _, None) |
76                 PatKind::Wild => {}
77                 PatKind::Ident(BindingMode::ByValue(Mutability::Mutable), _, None) =>
78                     report_err(arg.pat.span, true),
79                 _ => report_err(arg.pat.span, false),
80             }
81         }
82     }
83
84     fn check_trait_fn_not_async(&self, span: Span, asyncness: IsAsync) {
85         if asyncness.is_async() {
86             struct_span_err!(self.session, span, E0706,
87                              "trait fns cannot be declared `async`").emit()
88         }
89     }
90
91     fn check_trait_fn_not_const(&self, constness: Spanned<Constness>) {
92         if constness.node == Constness::Const {
93             struct_span_err!(self.session, constness.span, E0379,
94                              "trait fns cannot be declared const")
95                 .span_label(constness.span, "trait fns cannot be const")
96                 .emit();
97         }
98     }
99
100     fn no_questions_in_bounds(&self, bounds: &GenericBounds, where_: &str, is_trait: bool) {
101         for bound in bounds {
102             if let GenericBound::Trait(ref poly, TraitBoundModifier::Maybe) = *bound {
103                 let mut err = self.err_handler().struct_span_err(poly.span,
104                     &format!("`?Trait` is not permitted in {}", where_));
105                 if is_trait {
106                     err.note(&format!("traits are `?{}` by default", poly.trait_ref.path));
107                 }
108                 err.emit();
109             }
110         }
111     }
112
113     /// matches '-' lit | lit (cf. parser::Parser::parse_literal_maybe_minus),
114     /// or path for ranges.
115     ///
116     /// FIXME: do we want to allow expr -> pattern conversion to create path expressions?
117     /// That means making this work:
118     ///
119     /// ```rust,ignore (FIXME)
120     ///     struct S;
121     ///     macro_rules! m {
122     ///         ($a:expr) => {
123     ///             let $a = S;
124     ///         }
125     ///     }
126     ///     m!(S);
127     /// ```
128     fn check_expr_within_pat(&self, expr: &Expr, allow_paths: bool) {
129         match expr.node {
130             ExprKind::Lit(..) => {}
131             ExprKind::Path(..) if allow_paths => {}
132             ExprKind::Unary(UnOp::Neg, ref inner)
133                 if match inner.node { ExprKind::Lit(_) => true, _ => false } => {}
134             _ => self.err_handler().span_err(expr.span, "arbitrary expressions aren't allowed \
135                                                          in patterns")
136         }
137     }
138
139     fn check_late_bound_lifetime_defs(&self, params: &[GenericParam]) {
140         // Check only lifetime parameters are present and that the lifetime
141         // parameters that are present have no bounds.
142         let non_lt_param_spans: Vec<_> = params.iter().filter_map(|param| match param.kind {
143             GenericParamKind::Lifetime { .. } => {
144                 if !param.bounds.is_empty() {
145                     let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
146                     self.err_handler()
147                         .span_err(spans, "lifetime bounds cannot be used in this context");
148                 }
149                 None
150             }
151             _ => Some(param.ident.span),
152         }).collect();
153         if !non_lt_param_spans.is_empty() {
154             self.err_handler().span_err(non_lt_param_spans,
155                 "only lifetime parameters can be used in this context");
156         }
157     }
158
159     /// With eRFC 2497, we need to check whether an expression is ambiguous and warn or error
160     /// depending on the edition, this function handles that.
161     fn while_if_let_ambiguity(&self, expr: &P<Expr>) {
162         if let Some((span, op_kind)) = self.while_if_let_expr_ambiguity(&expr) {
163             let mut err = self.err_handler().struct_span_err(
164                 span, &format!("ambiguous use of `{}`", op_kind.to_string())
165             );
166
167             err.note(
168                 "this will be a error until the `let_chains` feature is stabilized"
169             );
170             err.note(
171                 "see rust-lang/rust#53668 for more information"
172             );
173
174             if let Ok(snippet) = self.session.source_map().span_to_snippet(span) {
175                 err.span_suggestion_with_applicability(
176                     span, "consider adding parentheses", format!("({})", snippet),
177                     Applicability::MachineApplicable,
178                 );
179             }
180
181             err.emit();
182         }
183     }
184
185     /// With eRFC 2497 adding if-let chains, there is a requirement that the parsing of
186     /// `&&` and `||` in a if-let statement be unambiguous. This function returns a span and
187     /// a `BinOpKind` (either `&&` or `||` depending on what was ambiguous) if it is determined
188     /// that the current expression parsed is ambiguous and will break in future.
189     fn while_if_let_expr_ambiguity(&self, expr: &P<Expr>) -> Option<(Span, BinOpKind)> {
190         debug!("while_if_let_expr_ambiguity: expr.node: {:?}", expr.node);
191         match &expr.node {
192             ExprKind::Binary(op, _, _) if op.node == BinOpKind::And || op.node == BinOpKind::Or => {
193                 Some((expr.span, op.node))
194             },
195             ExprKind::Range(ref lhs, ref rhs, _) => {
196                 let lhs_ambiguous = lhs.as_ref()
197                     .and_then(|lhs| self.while_if_let_expr_ambiguity(lhs));
198                 let rhs_ambiguous = rhs.as_ref()
199                     .and_then(|rhs| self.while_if_let_expr_ambiguity(rhs));
200
201                 lhs_ambiguous.or(rhs_ambiguous)
202             }
203             _ => None,
204         }
205     }
206
207 }
208
209 impl<'a> Visitor<'a> for AstValidator<'a> {
210     fn visit_expr(&mut self, expr: &'a Expr) {
211         match expr.node {
212             ExprKind::IfLet(_, ref expr, _, _) | ExprKind::WhileLet(_, ref expr, _, _) =>
213                 self.while_if_let_ambiguity(&expr),
214             ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => {
215                 span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target");
216             }
217             ExprKind::ObsoleteInPlace(ref place, ref val) => {
218                 let mut err = self.err_handler().struct_span_err(
219                     expr.span,
220                     "emplacement syntax is obsolete (for now, anyway)",
221                 );
222                 err.note(
223                     "for more information, see \
224                      <https://github.com/rust-lang/rust/issues/27779#issuecomment-378416911>"
225                 );
226                 match val.node {
227                     ExprKind::Lit(ref v) if v.node.is_numeric() => {
228                         err.span_suggestion_with_applicability(
229                             place.span.between(val.span),
230                             "if you meant to write a comparison against a negative value, add a \
231                              space in between `<` and `-`",
232                             "< -".to_string(),
233                             Applicability::MaybeIncorrect
234                         );
235                     }
236                     _ => {}
237                 }
238                 err.emit();
239             }
240             _ => {}
241         }
242
243         visit::walk_expr(self, expr)
244     }
245
246     fn visit_ty(&mut self, ty: &'a Ty) {
247         match ty.node {
248             TyKind::BareFn(ref bfty) => {
249                 self.check_decl_no_pat(&bfty.decl, |span, _| {
250                     struct_span_err!(self.session, span, E0561,
251                                      "patterns aren't allowed in function pointer types").emit();
252                 });
253                 self.check_late_bound_lifetime_defs(&bfty.generic_params);
254             }
255             TyKind::TraitObject(ref bounds, ..) => {
256                 let mut any_lifetime_bounds = false;
257                 for bound in bounds {
258                     if let GenericBound::Outlives(ref lifetime) = *bound {
259                         if any_lifetime_bounds {
260                             span_err!(self.session, lifetime.ident.span, E0226,
261                                       "only a single explicit lifetime bound is permitted");
262                             break;
263                         }
264                         any_lifetime_bounds = true;
265                     }
266                 }
267                 self.no_questions_in_bounds(bounds, "trait object types", false);
268             }
269             TyKind::ImplTrait(_, ref bounds) => {
270                 if !bounds.iter()
271                           .any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) {
272                     self.err_handler().span_err(ty.span, "at least one trait must be specified");
273                 }
274             }
275             _ => {}
276         }
277
278         visit::walk_ty(self, ty)
279     }
280
281     fn visit_label(&mut self, label: &'a Label) {
282         self.check_label(label.ident);
283         visit::walk_label(self, label);
284     }
285
286     fn visit_lifetime(&mut self, lifetime: &'a Lifetime) {
287         self.check_lifetime(lifetime.ident);
288         visit::walk_lifetime(self, lifetime);
289     }
290
291     fn visit_item(&mut self, item: &'a Item) {
292         match item.node {
293             ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
294                 self.invalid_visibility(&item.vis, None);
295                 if let TyKind::Err = ty.node {
296                     self.err_handler()
297                         .struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
298                         .help("use `auto trait Trait {}` instead").emit();
299                 }
300                 if unsafety == Unsafety::Unsafe && polarity == ImplPolarity::Negative {
301                     span_err!(self.session, item.span, E0198, "negative impls cannot be unsafe");
302                 }
303                 for impl_item in impl_items {
304                     self.invalid_visibility(&impl_item.vis, None);
305                     if let ImplItemKind::Method(ref sig, _) = impl_item.node {
306                         self.check_trait_fn_not_const(sig.header.constness);
307                         self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness);
308                     }
309                 }
310             }
311             ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
312                 self.invalid_visibility(&item.vis,
313                                         Some("place qualifiers on individual impl items instead"));
314                 if unsafety == Unsafety::Unsafe {
315                     span_err!(self.session, item.span, E0197, "inherent impls cannot be unsafe");
316                 }
317                 if polarity == ImplPolarity::Negative {
318                     self.err_handler().span_err(item.span, "inherent impls cannot be negative");
319                 }
320                 if defaultness == Defaultness::Default {
321                     self.err_handler()
322                         .struct_span_err(item.span, "inherent impls cannot be default")
323                         .note("only trait implementations may be annotated with default").emit();
324                 }
325             }
326             ItemKind::ForeignMod(..) => {
327                 self.invalid_visibility(
328                     &item.vis,
329                     Some("place qualifiers on individual foreign items instead"),
330                 );
331             }
332             ItemKind::Enum(ref def, _) => {
333                 for variant in &def.variants {
334                     self.invalid_non_exhaustive_attribute(variant);
335                     for field in variant.node.data.fields() {
336                         self.invalid_visibility(&field.vis, None);
337                     }
338                 }
339             }
340             ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => {
341                 if is_auto == IsAuto::Yes {
342                     // Auto traits cannot have generics, super traits nor contain items.
343                     if !generics.params.is_empty() {
344                         struct_span_err!(self.session, item.span, E0567,
345                                         "auto traits cannot have generic parameters").emit();
346                     }
347                     if !bounds.is_empty() {
348                         struct_span_err!(self.session, item.span, E0568,
349                                         "auto traits cannot have super traits").emit();
350                     }
351                     if !trait_items.is_empty() {
352                         struct_span_err!(self.session, item.span, E0380,
353                                 "auto traits cannot have methods or associated items").emit();
354                     }
355                 }
356                 self.no_questions_in_bounds(bounds, "supertraits", true);
357                 for trait_item in trait_items {
358                     if let TraitItemKind::Method(ref sig, ref block) = trait_item.node {
359                         self.check_trait_fn_not_async(trait_item.span, sig.header.asyncness);
360                         self.check_trait_fn_not_const(sig.header.constness);
361                         if block.is_none() {
362                             self.check_decl_no_pat(&sig.decl, |span, mut_ident| {
363                                 if mut_ident {
364                                     self.session.buffer_lint(
365                                         lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY,
366                                         trait_item.id, span,
367                                         "patterns aren't allowed in methods without bodies");
368                                 } else {
369                                     struct_span_err!(self.session, span, E0642,
370                                         "patterns aren't allowed in methods without bodies").emit();
371                                 }
372                             });
373                         }
374                     }
375                 }
376             }
377             ItemKind::Mod(_) => {
378                 // Ensure that `path` attributes on modules are recorded as used (cf. issue #35584).
379                 attr::first_attr_value_str_by_name(&item.attrs, "path");
380                 if attr::contains_name(&item.attrs, "warn_directory_ownership") {
381                     let lint = lint::builtin::LEGACY_DIRECTORY_OWNERSHIP;
382                     let msg = "cannot declare a new module at this location";
383                     self.session.buffer_lint(lint, item.id, item.span, msg);
384                 }
385             }
386             ItemKind::Union(ref vdata, _) => {
387                 if !vdata.is_struct() {
388                     self.err_handler().span_err(item.span,
389                                                 "tuple and unit unions are not permitted");
390                 }
391                 if vdata.fields().is_empty() {
392                     self.err_handler().span_err(item.span,
393                                                 "unions cannot have zero fields");
394                 }
395             }
396             _ => {}
397         }
398
399         visit::walk_item(self, item)
400     }
401
402     fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
403         match fi.node {
404             ForeignItemKind::Fn(ref decl, _) => {
405                 self.check_decl_no_pat(decl, |span, _| {
406                     struct_span_err!(self.session, span, E0130,
407                                      "patterns aren't allowed in foreign function declarations")
408                         .span_label(span, "pattern not allowed in foreign function").emit();
409                 });
410             }
411             ForeignItemKind::Static(..) | ForeignItemKind::Ty | ForeignItemKind::Macro(..) => {}
412         }
413
414         visit::walk_foreign_item(self, fi)
415     }
416
417     fn visit_generics(&mut self, generics: &'a Generics) {
418         let mut seen_non_lifetime_param = false;
419         let mut seen_default = None;
420         for param in &generics.params {
421             match (&param.kind, seen_non_lifetime_param) {
422                 (GenericParamKind::Lifetime { .. }, true) => {
423                     self.err_handler()
424                         .span_err(param.ident.span, "lifetime parameters must be leading");
425                 },
426                 (GenericParamKind::Lifetime { .. }, false) => {}
427                 (GenericParamKind::Type { ref default, .. }, _) => {
428                     seen_non_lifetime_param = true;
429                     if default.is_some() {
430                         seen_default = Some(param.ident.span);
431                     } else if let Some(span) = seen_default {
432                         self.err_handler()
433                             .span_err(span, "type parameters with a default must be trailing");
434                         break;
435                     }
436                 }
437             }
438         }
439         for predicate in &generics.where_clause.predicates {
440             if let WherePredicate::EqPredicate(ref predicate) = *predicate {
441                 self.err_handler().span_err(predicate.span, "equality constraints are not yet \
442                                                              supported in where clauses (#20041)");
443             }
444         }
445         visit::walk_generics(self, generics)
446     }
447
448     fn visit_generic_param(&mut self, param: &'a GenericParam) {
449         if let GenericParamKind::Lifetime { .. } = param.kind {
450             self.check_lifetime(param.ident);
451         }
452         visit::walk_generic_param(self, param);
453     }
454
455     fn visit_pat(&mut self, pat: &'a Pat) {
456         match pat.node {
457             PatKind::Lit(ref expr) => {
458                 self.check_expr_within_pat(expr, false);
459             }
460             PatKind::Range(ref start, ref end, _) => {
461                 self.check_expr_within_pat(start, true);
462                 self.check_expr_within_pat(end, true);
463             }
464             _ => {}
465         }
466
467         visit::walk_pat(self, pat)
468     }
469
470     fn visit_where_predicate(&mut self, p: &'a WherePredicate) {
471         if let &WherePredicate::BoundPredicate(ref bound_predicate) = p {
472             // A type binding, eg `for<'c> Foo: Send+Clone+'c`
473             self.check_late_bound_lifetime_defs(&bound_predicate.bound_generic_params);
474         }
475         visit::walk_where_predicate(self, p);
476     }
477
478     fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) {
479         self.check_late_bound_lifetime_defs(&t.bound_generic_params);
480         visit::walk_poly_trait_ref(self, t, m);
481     }
482
483     fn visit_mac(&mut self, mac: &Spanned<Mac_>) {
484         // when a new macro kind is added but the author forgets to set it up for expansion
485         // because that's the only part that won't cause a compiler error
486         self.session.diagnostic()
487             .span_bug(mac.span, "macro invocation missed in expansion; did you forget to override \
488                                  the relevant `fold_*()` method in `PlaceholderExpander`?");
489     }
490 }
491
492 // Bans nested `impl Trait`, e.g., `impl Into<impl Debug>`.
493 // Nested `impl Trait` _is_ allowed in associated type position,
494 // e.g `impl Iterator<Item=impl Debug>`
495 struct NestedImplTraitVisitor<'a> {
496     session: &'a Session,
497     outer_impl_trait: Option<Span>,
498 }
499
500 impl<'a> NestedImplTraitVisitor<'a> {
501     fn with_impl_trait<F>(&mut self, outer_impl_trait: Option<Span>, f: F)
502         where F: FnOnce(&mut NestedImplTraitVisitor<'a>)
503     {
504         let old_outer_impl_trait = self.outer_impl_trait;
505         self.outer_impl_trait = outer_impl_trait;
506         f(self);
507         self.outer_impl_trait = old_outer_impl_trait;
508     }
509 }
510
511
512 impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
513     fn visit_ty(&mut self, t: &'a Ty) {
514         if let TyKind::ImplTrait(..) = t.node {
515             if let Some(outer_impl_trait) = self.outer_impl_trait {
516                 struct_span_err!(self.session, t.span, E0666,
517                                  "nested `impl Trait` is not allowed")
518                     .span_label(outer_impl_trait, "outer `impl Trait`")
519                     .span_label(t.span, "nested `impl Trait` here")
520                     .emit();
521
522             }
523             self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t));
524         } else {
525             visit::walk_ty(self, t);
526         }
527     }
528     fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
529         match *generic_args {
530             GenericArgs::AngleBracketed(ref data) => {
531                 for arg in &data.args {
532                     self.visit_generic_arg(arg)
533                 }
534                 for type_binding in &data.bindings {
535                     // Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
536                     // are allowed to contain nested `impl Trait`.
537                     self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty));
538                 }
539             }
540             GenericArgs::Parenthesized(ref data) => {
541                 for type_ in &data.inputs {
542                     self.visit_ty(type_);
543                 }
544                 if let Some(ref type_) = data.output {
545                     // `-> Foo` syntax is essentially an associated type binding,
546                     // so it is also allowed to contain nested `impl Trait`.
547                     self.with_impl_trait(None, |this| visit::walk_ty(this, type_));
548                 }
549             }
550         }
551     }
552
553     fn visit_mac(&mut self, _mac: &Spanned<Mac_>) {
554         // covered in AstValidator
555     }
556 }
557
558 // Bans `impl Trait` in path projections like `<impl Iterator>::Item` or `Foo::Bar<impl Trait>`.
559 struct ImplTraitProjectionVisitor<'a> {
560     session: &'a Session,
561     is_banned: bool,
562 }
563
564 impl<'a> ImplTraitProjectionVisitor<'a> {
565     fn with_ban<F>(&mut self, f: F)
566         where F: FnOnce(&mut ImplTraitProjectionVisitor<'a>)
567     {
568         let old_is_banned = self.is_banned;
569         self.is_banned = true;
570         f(self);
571         self.is_banned = old_is_banned;
572     }
573 }
574
575 impl<'a> Visitor<'a> for ImplTraitProjectionVisitor<'a> {
576     fn visit_ty(&mut self, t: &'a Ty) {
577         match t.node {
578             TyKind::ImplTrait(..) => {
579                 if self.is_banned {
580                     struct_span_err!(self.session, t.span, E0667,
581                         "`impl Trait` is not allowed in path parameters").emit();
582                 }
583             }
584             TyKind::Path(ref qself, ref path) => {
585                 // We allow these:
586                 //  - `Option<impl Trait>`
587                 //  - `option::Option<impl Trait>`
588                 //  - `option::Option<T>::Foo<impl Trait>
589                 //
590                 // But not these:
591                 //  - `<impl Trait>::Foo`
592                 //  - `option::Option<impl Trait>::Foo`.
593                 //
594                 // To implement this, we disallow `impl Trait` from `qself`
595                 // (for cases like `<impl Trait>::Foo>`)
596                 // but we allow `impl Trait` in `GenericArgs`
597                 // iff there are no more PathSegments.
598                 if let Some(ref qself) = *qself {
599                     // `impl Trait` in `qself` is always illegal
600                     self.with_ban(|this| this.visit_ty(&qself.ty));
601                 }
602
603                 for (i, segment) in path.segments.iter().enumerate() {
604                     // Allow `impl Trait` iff we're on the final path segment
605                     if i == path.segments.len() - 1 {
606                         visit::walk_path_segment(self, path.span, segment);
607                     } else {
608                         self.with_ban(|this|
609                             visit::walk_path_segment(this, path.span, segment));
610                     }
611                 }
612             }
613             _ => visit::walk_ty(self, t),
614         }
615     }
616
617     fn visit_mac(&mut self, _mac: &Spanned<Mac_>) {
618         // covered in AstValidator
619     }
620 }
621
622 pub fn check_crate(session: &Session, krate: &Crate) {
623     visit::walk_crate(
624         &mut NestedImplTraitVisitor {
625             session,
626             outer_impl_trait: None,
627         }, krate);
628
629     visit::walk_crate(
630         &mut ImplTraitProjectionVisitor {
631             session,
632             is_banned: false,
633         }, krate);
634
635     visit::walk_crate(&mut AstValidator { session }, krate)
636 }