Skip to content

Commit be3fb0c

Browse files
committedAug 10, 2019
Auto merge of #63437 - Centril:rollup-ryx881p, r=Centril
Rollup of 4 pull requests Successful merges: - #63400 (Try to break resolve into more isolated parts) - #63425 (Cleanup historical stability comments) - #63429 (.gitignore: Readd `/tmp/`) - #63432 (Cleanup & Simplify stuff in lowering) Failed merges: r? @ghost
2 parents 6f70adc + 808f983 commit be3fb0c

20 files changed

+4025
-3942
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ __pycache__/
2727
/inst/
2828
/llvm/
2929
/mingw-build/
30+
# Created by default with `src/ci/docker/run.sh`:
3031
/obj/
3132
/rustllvm/
3233
/src/libcore/unicode/DerivedCoreProperties.txt
@@ -38,6 +39,8 @@ __pycache__/
3839
/src/libcore/unicode/UnicodeData.txt
3940
/src/libcore/unicode/downloaded
4041
/target/
42+
# Generated by compiletest for incremental:
43+
/tmp/
4144
tags
4245
tags.*
4346
TAGS

‎src/librustc/hir/lowering.rs

+38-54
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
3737
use crate::hir::HirVec;
3838
use crate::hir::map::{DefKey, DefPathData, Definitions};
3939
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
40-
use crate::hir::def::{Res, DefKind, PartialRes, PerNS};
40+
use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
4141
use crate::hir::{GenericArg, ConstArg};
4242
use crate::hir::ptr::P;
4343
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
@@ -148,13 +148,6 @@ pub struct LoweringContext<'a> {
148148
}
149149

150150
pub trait Resolver {
151-
/// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc.
152-
fn resolve_ast_path(
153-
&mut self,
154-
path: &ast::Path,
155-
is_value: bool,
156-
) -> Res<NodeId>;
157-
158151
/// Obtain resolution for a `NodeId` with a single resolution.
159152
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;
160153

@@ -175,7 +168,7 @@ pub trait Resolver {
175168
span: Span,
176169
crate_root: Option<Symbol>,
177170
components: &[Symbol],
178-
is_value: bool,
171+
ns: Namespace,
179172
) -> (ast::Path, Res<NodeId>);
180173

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

4443+
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
4444+
exprs.iter().map(|x| self.lower_expr(x)).collect()
4445+
}
4446+
44504447
fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
44514448
let kind = match e.node {
44524449
ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))),
4453-
ExprKind::Array(ref exprs) => {
4454-
hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)).collect())
4455-
}
4450+
ExprKind::Array(ref exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
44564451
ExprKind::Repeat(ref expr, ref count) => {
44574452
let expr = P(self.lower_expr(expr));
44584453
let count = self.lower_anon_const(count);
44594454
hir::ExprKind::Repeat(expr, count)
44604455
}
4461-
ExprKind::Tup(ref elts) => {
4462-
hir::ExprKind::Tup(elts.iter().map(|x| self.lower_expr(x)).collect())
4463-
}
4456+
ExprKind::Tup(ref elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),
44644457
ExprKind::Call(ref f, ref args) => {
44654458
let f = P(self.lower_expr(f));
4466-
hir::ExprKind::Call(f, args.iter().map(|x| self.lower_expr(x)).collect())
4459+
hir::ExprKind::Call(f, self.lower_exprs(args))
44674460
}
44684461
ExprKind::MethodCall(ref seg, ref args) => {
44694462
let hir_seg = P(self.lower_path_segment(
@@ -4475,7 +4468,7 @@ impl<'a> LoweringContext<'a> {
44754468
ImplTraitContext::disallowed(),
44764469
None,
44774470
));
4478-
let args = args.iter().map(|x| self.lower_expr(x)).collect();
4471+
let args = self.lower_exprs(args);
44794472
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args)
44804473
}
44814474
ExprKind::Binary(binop, ref lhs, ref rhs) => {
@@ -5049,17 +5042,9 @@ impl<'a> LoweringContext<'a> {
50495042
));
50505043
let arms = hir_vec![pat_arm, break_arm];
50515044

5052-
P(self.expr(
5053-
head_sp,
5054-
hir::ExprKind::Match(
5055-
next_expr,
5056-
arms,
5057-
hir::MatchSource::ForLoopDesugar
5058-
),
5059-
ThinVec::new(),
5060-
))
5045+
self.expr_match(head_sp, next_expr, arms, hir::MatchSource::ForLoopDesugar)
50615046
};
5062-
let match_stmt = self.stmt(head_sp, hir::StmtKind::Expr(match_expr));
5047+
let match_stmt = self.stmt_expr(head_sp, match_expr);
50635048

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

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

50855070
let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
5086-
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
5087-
let body_stmt = self.stmt(body.span, hir::StmtKind::Expr(body_expr));
5071+
let body_expr = self.expr_block(body_block, ThinVec::new());
5072+
let body_stmt = self.stmt_expr(body.span, body_expr);
50885073

50895074
let loop_block = P(self.block_all(
50905075
e.span,
@@ -5127,8 +5112,10 @@ impl<'a> LoweringContext<'a> {
51275112
));
51285113

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

52565243
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> {
5257-
smallvec![match s.node {
5244+
let node = match s.node {
52585245
StmtKind::Local(ref l) => {
52595246
let (l, item_ids) = self.lower_local(l);
52605247
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
@@ -5291,21 +5278,14 @@ impl<'a> LoweringContext<'a> {
52915278
})
52925279
.collect();
52935280
}
5294-
StmtKind::Expr(ref e) => {
5295-
hir::Stmt {
5296-
hir_id: self.lower_node_id(s.id),
5297-
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
5298-
span: s.span,
5299-
}
5300-
},
5301-
StmtKind::Semi(ref e) => {
5302-
hir::Stmt {
5303-
hir_id: self.lower_node_id(s.id),
5304-
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
5305-
span: s.span,
5306-
}
5307-
},
5281+
StmtKind::Expr(ref e) => hir::StmtKind::Expr(P(self.lower_expr(e))),
5282+
StmtKind::Semi(ref e) => hir::StmtKind::Semi(P(self.lower_expr(e))),
53085283
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
5284+
};
5285+
smallvec![hir::Stmt {
5286+
hir_id: self.lower_node_id(s.id),
5287+
node,
5288+
span: s.span,
53095289
}]
53105290
}
53115291

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

5550+
fn stmt_expr(&mut self, span: Span, expr: hir::Expr) -> hir::Stmt {
5551+
self.stmt(span, hir::StmtKind::Expr(P(expr)))
5552+
}
5553+
55705554
fn stmt_let_pat(
55715555
&mut self,
55725556
attrs: ThinVec<Attribute>,
@@ -5717,8 +5701,8 @@ impl<'a> LoweringContext<'a> {
57175701
params: Option<P<hir::GenericArgs>>,
57185702
is_value: bool,
57195703
) -> hir::Path {
5720-
let (path, res) = self.resolver
5721-
.resolve_str_path(span, self.crate_root, components, is_value);
5704+
let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS };
5705+
let (path, res) = self.resolver.resolve_str_path(span, self.crate_root, components, ns);
57225706

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

60626046
let match_stmt = {
6063-
let match_expr = P(self.expr_match(
6047+
let match_expr = self.expr_match(
60646048
span,
60656049
poll_expr,
60666050
hir_vec![ready_arm, pending_arm],
60676051
hir::MatchSource::AwaitDesugar,
6068-
));
6069-
self.stmt(span, hir::StmtKind::Expr(match_expr))
6052+
);
6053+
self.stmt_expr(span, match_expr)
60706054
};
60716055

60726056
let yield_stmt = {
60736057
let unit = self.expr_unit(span);
6074-
let yield_expr = P(self.expr(
6058+
let yield_expr = self.expr(
60756059
span,
60766060
hir::ExprKind::Yield(P(unit), hir::YieldSource::Await),
60776061
ThinVec::new(),
6078-
));
6079-
self.stmt(span, hir::StmtKind::Expr(yield_expr))
6062+
);
6063+
self.stmt_expr(span, yield_expr)
60806064
};
60816065

60826066
let loop_block = P(self.block_all(

‎src/librustc_driver/lib.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,11 @@ fn print_flag_list<T>(cmdline_opt: &str,
957957
/// otherwise returns `None`.
958958
///
959959
/// The compiler's handling of options is a little complicated as it ties into
960-
/// our stability story, and it's even *more* complicated by historical
961-
/// accidents. The current intention of each compiler option is to have one of
962-
/// three modes:
960+
/// our stability story. The current intention of each compiler option is to
961+
/// have one of two modes:
963962
///
964963
/// 1. An option is stable and can be used everywhere.
965-
/// 2. An option is unstable, but was historically allowed on the stable
966-
/// channel.
967-
/// 3. An option is unstable, and can only be used on nightly.
964+
/// 2. An option is unstable, and can only be used on nightly.
968965
///
969966
/// Like unstable library and language features, however, unstable options have
970967
/// always required a form of "opt in" to indicate that you're using them. This
@@ -1007,19 +1004,13 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10071004
// this option that was passed.
10081005
// * If we're a nightly compiler, then unstable options are now unlocked, so
10091006
// we're good to go.
1010-
// * Otherwise, if we're a truly unstable option then we generate an error
1007+
// * Otherwise, if we're an unstable option then we generate an error
10111008
// (unstable option being used on stable)
1012-
// * If we're a historically stable-but-should-be-unstable option then we
1013-
// emit a warning that we're going to turn this into an error soon.
10141009
nightly_options::check_nightly_options(&matches, &config::rustc_optgroups());
10151010

10161011
if matches.opt_present("h") || matches.opt_present("help") {
1017-
// Only show unstable options in --help if we *really* accept unstable
1018-
// options, which catches the case where we got `-Z unstable-options` on
1019-
// the stable channel of Rust which was accidentally allowed
1020-
// historically.
1021-
usage(matches.opt_present("verbose"),
1022-
nightly_options::is_unstable_enabled(&matches));
1012+
// Only show unstable options in --help if we accept unstable options.
1013+
usage(matches.opt_present("verbose"), nightly_options::is_unstable_enabled(&matches));
10231014
return None;
10241015
}
10251016

0 commit comments

Comments
 (0)
Please sign in to comment.