Skip to content

Rollup of 4 pull requests #63437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __pycache__/
/inst/
/llvm/
/mingw-build/
# Created by default with `src/ci/docker/run.sh`:
/obj/
/rustllvm/
/src/libcore/unicode/DerivedCoreProperties.txt
Expand All @@ -38,6 +39,8 @@ __pycache__/
/src/libcore/unicode/UnicodeData.txt
/src/libcore/unicode/downloaded
/target/
# Generated by compiletest for incremental:
/tmp/
tags
tags.*
TAGS
Expand Down
92 changes: 38 additions & 54 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
use crate::hir::HirVec;
use crate::hir::map::{DefKey, DefPathData, Definitions};
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
use crate::hir::def::{Res, DefKind, PartialRes, PerNS};
use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
use crate::hir::{GenericArg, ConstArg};
use crate::hir::ptr::P;
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
Expand Down Expand Up @@ -148,13 +148,6 @@ pub struct LoweringContext<'a> {
}

pub trait Resolver {
/// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc.
fn resolve_ast_path(
&mut self,
path: &ast::Path,
is_value: bool,
) -> Res<NodeId>;

/// Obtain resolution for a `NodeId` with a single resolution.
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;

Expand All @@ -175,7 +168,7 @@ pub trait Resolver {
span: Span,
crate_root: Option<Symbol>,
components: &[Symbol],
is_value: bool,
ns: Namespace,
) -> (ast::Path, Res<NodeId>);

fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
Expand Down Expand Up @@ -4447,23 +4440,23 @@ impl<'a> LoweringContext<'a> {
})
}

fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
exprs.iter().map(|x| self.lower_expr(x)).collect()
}

fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
let kind = match e.node {
ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))),
ExprKind::Array(ref exprs) => {
hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)).collect())
}
ExprKind::Array(ref exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
ExprKind::Repeat(ref expr, ref count) => {
let expr = P(self.lower_expr(expr));
let count = self.lower_anon_const(count);
hir::ExprKind::Repeat(expr, count)
}
ExprKind::Tup(ref elts) => {
hir::ExprKind::Tup(elts.iter().map(|x| self.lower_expr(x)).collect())
}
ExprKind::Tup(ref elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),
ExprKind::Call(ref f, ref args) => {
let f = P(self.lower_expr(f));
hir::ExprKind::Call(f, args.iter().map(|x| self.lower_expr(x)).collect())
hir::ExprKind::Call(f, self.lower_exprs(args))
}
ExprKind::MethodCall(ref seg, ref args) => {
let hir_seg = P(self.lower_path_segment(
Expand All @@ -4475,7 +4468,7 @@ impl<'a> LoweringContext<'a> {
ImplTraitContext::disallowed(),
None,
));
let args = args.iter().map(|x| self.lower_expr(x)).collect();
let args = self.lower_exprs(args);
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args)
}
ExprKind::Binary(binop, ref lhs, ref rhs) => {
Expand Down Expand Up @@ -5049,17 +5042,9 @@ impl<'a> LoweringContext<'a> {
));
let arms = hir_vec![pat_arm, break_arm];

P(self.expr(
head_sp,
hir::ExprKind::Match(
next_expr,
arms,
hir::MatchSource::ForLoopDesugar
),
ThinVec::new(),
))
self.expr_match(head_sp, next_expr, arms, hir::MatchSource::ForLoopDesugar)
};
let match_stmt = self.stmt(head_sp, hir::StmtKind::Expr(match_expr));
let match_stmt = self.stmt_expr(head_sp, match_expr);

let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat_hid));

Expand All @@ -5083,8 +5068,8 @@ impl<'a> LoweringContext<'a> {
);

let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
let body_stmt = self.stmt(body.span, hir::StmtKind::Expr(body_expr));
let body_expr = self.expr_block(body_block, ThinVec::new());
let body_stmt = self.stmt_expr(body.span, body_expr);

let loop_block = P(self.block_all(
e.span,
Expand Down Expand Up @@ -5127,8 +5112,10 @@ impl<'a> LoweringContext<'a> {
));

// This is effectively `{ let _result = ...; _result }`.
// The construct was introduced in #21984.
// FIXME(60253): Is this still necessary?
// The construct was introduced in #21984 and is necessary to make sure that
// temporaries in the `head` expression are dropped and do not leak to the
// surrounding scope of the `match` since the `match` is not a terminating scope.
//
// Also, add the attributes to the outer returned expr node.
return self.expr_drop_temps(head_sp, match_expr, e.attrs.clone())
}
Expand Down Expand Up @@ -5254,7 +5241,7 @@ impl<'a> LoweringContext<'a> {
}

fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> {
smallvec![match s.node {
let node = match s.node {
StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l);
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
Expand Down Expand Up @@ -5291,21 +5278,14 @@ impl<'a> LoweringContext<'a> {
})
.collect();
}
StmtKind::Expr(ref e) => {
hir::Stmt {
hir_id: self.lower_node_id(s.id),
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
span: s.span,
}
},
StmtKind::Semi(ref e) => {
hir::Stmt {
hir_id: self.lower_node_id(s.id),
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
span: s.span,
}
},
StmtKind::Expr(ref e) => hir::StmtKind::Expr(P(self.lower_expr(e))),
StmtKind::Semi(ref e) => hir::StmtKind::Semi(P(self.lower_expr(e))),
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
};
smallvec![hir::Stmt {
hir_id: self.lower_node_id(s.id),
node,
span: s.span,
}]
}

Expand Down Expand Up @@ -5567,6 +5547,10 @@ impl<'a> LoweringContext<'a> {
hir::Stmt { span, node, hir_id: self.next_id() }
}

fn stmt_expr(&mut self, span: Span, expr: hir::Expr) -> hir::Stmt {
self.stmt(span, hir::StmtKind::Expr(P(expr)))
}

fn stmt_let_pat(
&mut self,
attrs: ThinVec<Attribute>,
Expand Down Expand Up @@ -5717,8 +5701,8 @@ impl<'a> LoweringContext<'a> {
params: Option<P<hir::GenericArgs>>,
is_value: bool,
) -> hir::Path {
let (path, res) = self.resolver
.resolve_str_path(span, self.crate_root, components, is_value);
let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS };
let (path, res) = self.resolver.resolve_str_path(span, self.crate_root, components, ns);

let mut segments: Vec<_> = path.segments.iter().map(|segment| {
let res = self.expect_full_res(segment.id);
Expand Down Expand Up @@ -6060,23 +6044,23 @@ impl<'a> LoweringContext<'a> {
};

let match_stmt = {
let match_expr = P(self.expr_match(
let match_expr = self.expr_match(
span,
poll_expr,
hir_vec![ready_arm, pending_arm],
hir::MatchSource::AwaitDesugar,
));
self.stmt(span, hir::StmtKind::Expr(match_expr))
);
self.stmt_expr(span, match_expr)
};

let yield_stmt = {
let unit = self.expr_unit(span);
let yield_expr = P(self.expr(
let yield_expr = self.expr(
span,
hir::ExprKind::Yield(P(unit), hir::YieldSource::Await),
ThinVec::new(),
));
self.stmt(span, hir::StmtKind::Expr(yield_expr))
);
self.stmt_expr(span, yield_expr)
};

let loop_block = P(self.block_all(
Expand Down
21 changes: 6 additions & 15 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,11 @@ fn print_flag_list<T>(cmdline_opt: &str,
/// otherwise returns `None`.
///
/// The compiler's handling of options is a little complicated as it ties into
/// our stability story, and it's even *more* complicated by historical
/// accidents. The current intention of each compiler option is to have one of
/// three modes:
/// our stability story. The current intention of each compiler option is to
/// have one of two modes:
///
/// 1. An option is stable and can be used everywhere.
/// 2. An option is unstable, but was historically allowed on the stable
/// channel.
/// 3. An option is unstable, and can only be used on nightly.
/// 2. An option is unstable, and can only be used on nightly.
///
/// Like unstable library and language features, however, unstable options have
/// always required a form of "opt in" to indicate that you're using them. This
Expand Down Expand Up @@ -1007,19 +1004,13 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
// this option that was passed.
// * If we're a nightly compiler, then unstable options are now unlocked, so
// we're good to go.
// * Otherwise, if we're a truly unstable option then we generate an error
// * Otherwise, if we're an unstable option then we generate an error
// (unstable option being used on stable)
// * If we're a historically stable-but-should-be-unstable option then we
// emit a warning that we're going to turn this into an error soon.
nightly_options::check_nightly_options(&matches, &config::rustc_optgroups());

if matches.opt_present("h") || matches.opt_present("help") {
// Only show unstable options in --help if we *really* accept unstable
// options, which catches the case where we got `-Z unstable-options` on
// the stable channel of Rust which was accidentally allowed
// historically.
usage(matches.opt_present("verbose"),
nightly_options::is_unstable_enabled(&matches));
// Only show unstable options in --help if we accept unstable options.
usage(matches.opt_present("verbose"), nightly_options::is_unstable_enabled(&matches));
return None;
}

Expand Down
Loading