| David Tolnay | 75c2385 | 2020-10-27 21:07:53 -0700 | [diff] [blame] | 1 | use crate::gen::Opt; |
| 2 | use crate::syntax::report::Errors; |
| 3 | use crate::syntax::{error, Api}; |
| 4 | use quote::{quote, quote_spanned}; |
| 5 | use std::path::{Component, Path}; |
| 6 | |
| 7 | pub(super) use crate::syntax::check::typecheck; |
| 8 | |
| 9 | pub(super) fn precheck(cx: &mut Errors, apis: &[Api], opt: &Opt) { |
| 10 | if !opt.allow_dot_includes { |
| 11 | check_dot_includes(cx, apis); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | fn check_dot_includes(cx: &mut Errors, apis: &[Api]) { |
| 16 | for api in apis { |
| 17 | if let Api::Include(include) = api { |
| 18 | let first_component = Path::new(&include.path).components().next(); |
| 19 | if let Some(Component::CurDir) | Some(Component::ParentDir) = first_component { |
| 20 | let begin = quote_spanned!(include.begin_span=> .); |
| 21 | let end = quote_spanned!(include.end_span=> .); |
| 22 | let span = quote!(#begin #end); |
| 23 | cx.error(span, error::DOT_INCLUDE.msg); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | } |