diff --git a/Cargo.lock b/Cargo.lock index 8a76ffcbe7249..947c0b8f465b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3358,6 +3358,22 @@ dependencies = [ "core", ] +[[package]] +name = "rustc_ast_lowering" +version = "0.0.0" +dependencies = [ + "log", + "rustc", + "rustc_data_structures", + "rustc_error_codes", + "rustc_errors", + "rustc_index", + "rustc_span", + "rustc_target", + "smallvec 1.0.0", + "syntax", +] + [[package]] name = "rustc_builtin_macros" version = "0.0.0" @@ -3578,6 +3594,7 @@ dependencies = [ "once_cell", "rustc", "rustc-rayon", + "rustc_ast_lowering", "rustc_builtin_macros", "rustc_codegen_llvm", "rustc_codegen_ssa", @@ -3783,6 +3800,7 @@ dependencies = [ "bitflags", "log", "rustc", + "rustc_ast_lowering", "rustc_data_structures", "rustc_error_codes", "rustc_errors", diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index f56c9f8e72c2d..dfd06da969b57 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -39,7 +39,6 @@ pub mod def; pub mod def_id; pub mod intravisit; pub mod itemlikevisit; -pub mod lowering; pub mod map; pub mod pat_util; pub mod print; @@ -599,7 +598,7 @@ pub enum SyntheticTyParamKind { pub struct WhereClause<'hir> { pub predicates: &'hir [WherePredicate<'hir>], // Only valid if predicates isn't empty. - span: Span, + pub span: Span, } impl WhereClause<'_> { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 4e7913b8dfc0e..76588dfa5e25e 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -28,7 +28,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(arbitrary_self_types)] -#![feature(array_value_iter)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 1da9661cbf270..fa6e93d867b4e 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -523,7 +523,7 @@ pub enum BuiltinLintDiagnostics { DeprecatedMacro(Option, Span), } -pub(crate) fn add_elided_lifetime_in_path_suggestion( +pub fn add_elided_lifetime_in_path_suggestion( sess: &Session, db: &mut DiagnosticBuilder<'_>, n: usize, diff --git a/src/librustc_ast_lowering/Cargo.toml b/src/librustc_ast_lowering/Cargo.toml new file mode 100644 index 0000000000000..664d41c45f2a2 --- /dev/null +++ b/src/librustc_ast_lowering/Cargo.toml @@ -0,0 +1,22 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_ast_lowering" +version = "0.0.0" +edition = "2018" + +[lib] +name = "rustc_ast_lowering" +path = "lib.rs" +doctest = false + +[dependencies] +log = { version = "0.4", features = ["release_max_level_info", "std"] } +rustc = { path = "../librustc" } +rustc_target = { path = "../librustc_target" } +rustc_data_structures = { path = "../librustc_data_structures" } +rustc_index = { path = "../librustc_index" } +rustc_span = { path = "../librustc_span" } +rustc_error_codes = { path = "../librustc_error_codes" } +rustc_errors = { path = "../librustc_errors" } +syntax = { path = "../libsyntax" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc_ast_lowering/expr.rs similarity index 98% rename from src/librustc/hir/lowering/expr.rs rename to src/librustc_ast_lowering/expr.rs index 3911f09a22792..a3e2bc04bd5fb 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -1,16 +1,16 @@ use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; -use crate::hir; -use crate::hir::def::Res; +use rustc::bug; +use rustc::hir; +use rustc::hir::def::Res; use rustc_data_structures::thin_vec::ThinVec; - +use rustc_error_codes::*; +use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned}; +use rustc_span::symbol::{sym, Symbol}; use syntax::ast::*; use syntax::attr; use syntax::ptr::P as AstP; -use syntax::source_map::{respan, DesugaringKind, Span, Spanned}; -use syntax::symbol::{sym, Symbol}; - -use rustc_error_codes::*; +use syntax::{span_err, struct_span_err}; impl<'hir> LoweringContext<'_, 'hir> { fn lower_exprs(&mut self, exprs: &[AstP]) -> &'hir [hir::Expr<'hir>] { @@ -82,11 +82,7 @@ impl<'hir> LoweringContext<'_, 'hir> { this.lower_expr_while_in_loop_scope(e.span, cond, body, opt_label) }), ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| { - hir::ExprKind::Loop( - this.lower_block(body, false), - this.lower_label(opt_label), - hir::LoopSource::Loop, - ) + hir::ExprKind::Loop(this.lower_block(body, false), opt_label, hir::LoopSource::Loop) }), ExprKind::TryBlock(ref body) => self.lower_expr_try_block(body), ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match( @@ -123,10 +119,9 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_expr_closure(capture_clause, movability, decl, body, fn_decl_span) } } - ExprKind::Block(ref blk, opt_label) => hir::ExprKind::Block( - self.lower_block(blk, opt_label.is_some()), - self.lower_label(opt_label), - ), + ExprKind::Block(ref blk, opt_label) => { + hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label) + } ExprKind::Assign(ref el, ref er, span) => { hir::ExprKind::Assign(self.lower_expr(el), self.lower_expr(er), span) } @@ -407,11 +402,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); // `[opt_ident]: loop { ... }` - hir::ExprKind::Loop( - self.block_expr(self.arena.alloc(match_expr)), - self.lower_label(opt_label), - source, - ) + hir::ExprKind::Loop(self.block_expr(self.arena.alloc(match_expr)), opt_label, source) } /// Desugar `try { ; }` into `{ ; ::std::ops::Try::from_ok() }`, @@ -836,10 +827,6 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - fn lower_label(&mut self, label: Option