Skip to content

Commit 180edc2

Browse files
committed
Auto merge of #60296 - Centril:rollup-qh9la7k, r=Centril
Rollup of 12 pull requests Successful merges: - #59734 (Prevent failure in case no space left on device in rustdoc) - #59940 (Set cfg(test) when rustdoc is running with --test option) - #60134 (Fix index-page generation) - #60165 (Add Pin::{into_inner,into_inner_unchecked}) - #60183 (Chalkify: Add builtin Copy/Clone) - #60225 (Introduce hir::ExprKind::Use and employ in for loop desugaring.) - #60247 (Implement Debug for Place using Place::iterate) - #60259 (Derive Default instead of new in applicable lint) - #60267 (Add feature-gate for f16c target feature) - #60284 (Do not allow const generics to depend on type parameters) - #60285 (Do not ICE when checking types against foreign fn) - #60289 (Make `-Z allow-features` work for stdlib features) Failed merges: r? @ghost
2 parents 3991285 + a133caa commit 180edc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+640
-218
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15231523

15241524
[[package]]
15251525
name = "minifier"
1526-
version = "0.0.29"
1526+
version = "0.0.30"
15271527
source = "registry+https://github.com/rust-lang/crates.io-index"
15281528
dependencies = [
15291529
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3038,7 +3038,7 @@ dependencies = [
30383038
name = "rustdoc"
30393039
version = "0.0.0"
30403040
dependencies = [
3041-
"minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
3041+
"minifier 0.0.30 (registry+https://github.com/rust-lang/crates.io-index)",
30423042
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
30433043
"pulldown-cmark 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
30443044
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4170,7 +4170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41704170
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
41714171
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
41724172
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
4173-
"checksum minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4950cb2617b1933e2da0446e864dfe0d6a22c22ff72297996c46e6a63b210b"
4173+
"checksum minifier 0.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "4c909e78edf61f3aa0dd2086da168cdf304329044bbf248768ca3d20253ec8c0"
41744174
"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
41754175
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
41764176
"checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e"

src/libcore/pin.rs

+34
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ where
349349
// around pinning.
350350
unsafe { Pin::new_unchecked(pointer) }
351351
}
352+
353+
/// Unwraps this `Pin<P>` returning the underlying pointer.
354+
///
355+
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
356+
/// can ignore the pinning invariants when unwrapping it.
357+
///
358+
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
359+
#[unstable(feature = "pin_into_inner", issue = "60245")]
360+
#[inline(always)]
361+
pub fn into_inner(pin: Pin<P>) -> P {
362+
pin.pointer
363+
}
352364
}
353365

354366
impl<P: Deref> Pin<P> {
@@ -434,6 +446,28 @@ impl<P: Deref> Pin<P> {
434446
pub fn as_ref(self: &Pin<P>) -> Pin<&P::Target> {
435447
unsafe { Pin::new_unchecked(&*self.pointer) }
436448
}
449+
450+
/// Unwraps this `Pin<P>` returning the underlying pointer.
451+
///
452+
/// # Safety
453+
///
454+
/// This function is unsafe. You must guarantee that you will continue to
455+
/// treat the pointer `P` as pinned after you call this function, so that
456+
/// the invariants on the `Pin` type can be upheld. If the code using the
457+
/// resulting `P` does not continue to maintain the pinning invariants that
458+
/// is a violation of the API contract and may lead to undefined behavior in
459+
/// later (safe) operations.
460+
///
461+
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
462+
/// instead.
463+
///
464+
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
465+
/// [`Pin::into_inner`]: #method.into_inner
466+
#[unstable(feature = "pin_into_inner", issue = "60245")]
467+
#[inline(always)]
468+
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
469+
pin.pointer
470+
}
437471
}
438472

439473
impl<P: DerefMut> Pin<P> {

src/librustc/cfg/construct.rs

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
369369
hir::ExprKind::AddrOf(_, ref e) |
370370
hir::ExprKind::Cast(ref e, _) |
371371
hir::ExprKind::Type(ref e, _) |
372+
hir::ExprKind::Use(ref e) |
372373
hir::ExprKind::Unary(_, ref e) |
373374
hir::ExprKind::Field(ref e, _) |
374375
hir::ExprKind::Yield(ref e) |

src/librustc/hir/intravisit.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10291029
visitor.visit_expr(subexpression);
10301030
visitor.visit_ty(typ)
10311031
}
1032+
ExprKind::Use(ref subexpression) => {
1033+
visitor.visit_expr(subexpression);
1034+
}
10321035
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
10331036
visitor.visit_expr(head_expression);
10341037
visitor.visit_expr(if_block);

src/librustc/hir/lowering.rs

+16-29
Original file line numberDiff line numberDiff line change
@@ -4738,16 +4738,11 @@ impl<'a> LoweringContext<'a> {
47384738
hir::MatchSource::ForLoopDesugar,
47394739
));
47404740

4741-
// `{ let _result = ...; _result }`
4742-
// Underscore prevents an `unused_variables` lint if the head diverges.
4743-
let result_ident = self.str_to_ident("_result");
4744-
let (let_stmt, let_stmt_binding) =
4745-
self.stmt_let(e.span, false, result_ident, match_expr);
4746-
4747-
let result = P(self.expr_ident(e.span, result_ident, let_stmt_binding));
4748-
let block = P(self.block_all(e.span, hir_vec![let_stmt], Some(result)));
4749-
// Add the attributes to the outer returned expr node.
4750-
return self.expr_block(block, e.attrs.clone());
4741+
// This is effectively `{ let _result = ...; _result }`.
4742+
// The construct was introduced in #21984.
4743+
// FIXME(60253): Is this still necessary?
4744+
// Also, add the attributes to the outer returned expr node.
4745+
return self.expr_use(head_sp, match_expr, e.attrs.clone())
47514746
}
47524747

47534748
// Desugar `ExprKind::Try`
@@ -5117,6 +5112,17 @@ impl<'a> LoweringContext<'a> {
51175112
)
51185113
}
51195114

5115+
/// Wrap the given `expr` in `hir::ExprKind::Use`.
5116+
///
5117+
/// In terms of drop order, it has the same effect as
5118+
/// wrapping `expr` in `{ let _t = $expr; _t }` but
5119+
/// should provide better compile-time performance.
5120+
///
5121+
/// The drop order can be important in e.g. `if expr { .. }`.
5122+
fn expr_use(&mut self, span: Span, expr: P<hir::Expr>, attrs: ThinVec<Attribute>) -> hir::Expr {
5123+
self.expr(span, hir::ExprKind::Use(expr), attrs)
5124+
}
5125+
51205126
fn expr_match(
51215127
&mut self,
51225128
span: Span,
@@ -5172,25 +5178,6 @@ impl<'a> LoweringContext<'a> {
51725178
}
51735179
}
51745180

5175-
fn stmt_let(
5176-
&mut self,
5177-
sp: Span,
5178-
mutbl: bool,
5179-
ident: Ident,
5180-
ex: P<hir::Expr>,
5181-
) -> (hir::Stmt, hir::HirId) {
5182-
let (pat, pat_hid) = if mutbl {
5183-
self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable)
5184-
} else {
5185-
self.pat_ident(sp, ident)
5186-
};
5187-
5188-
(
5189-
self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal),
5190-
pat_hid,
5191-
)
5192-
}
5193-
51945181
fn block_expr(&mut self, expr: P<hir::Expr>) -> hir::Block {
51955182
self.block_all(expr.span, hir::HirVec::new(), Some(expr))
51965183
}

src/librustc/hir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ impl Expr {
13661366
ExprKind::Unary(..) => ExprPrecedence::Unary,
13671367
ExprKind::Lit(_) => ExprPrecedence::Lit,
13681368
ExprKind::Type(..) | ExprKind::Cast(..) => ExprPrecedence::Cast,
1369+
ExprKind::Use(ref expr, ..) => expr.precedence(),
13691370
ExprKind::If(..) => ExprPrecedence::If,
13701371
ExprKind::While(..) => ExprPrecedence::While,
13711372
ExprKind::Loop(..) => ExprPrecedence::Loop,
@@ -1437,6 +1438,7 @@ impl Expr {
14371438
ExprKind::Binary(..) |
14381439
ExprKind::Yield(..) |
14391440
ExprKind::Cast(..) |
1441+
ExprKind::Use(..) |
14401442
ExprKind::Err => {
14411443
false
14421444
}
@@ -1486,6 +1488,10 @@ pub enum ExprKind {
14861488
Cast(P<Expr>, P<Ty>),
14871489
/// A type reference (e.g., `Foo`).
14881490
Type(P<Expr>, P<Ty>),
1491+
/// Semantically equivalent to `{ let _t = expr; _t }`.
1492+
/// Maps directly to `hair::ExprKind::Use`.
1493+
/// Only exists to tweak the drop order in HIR.
1494+
Use(P<Expr>),
14891495
/// An `if` block, with an optional else block.
14901496
///
14911497
/// I.e., `if <expr> { <expr> } else { <expr> }`.

src/librustc/hir/print.rs

+40-13
Original file line numberDiff line numberDiff line change
@@ -995,23 +995,32 @@ impl<'a> State<'a> {
995995
self.ann.post(self, AnnNode::SubItem(ii.hir_id))
996996
}
997997

998+
pub fn print_local(
999+
&mut self,
1000+
init: Option<&hir::Expr>,
1001+
decl: impl Fn(&mut Self) -> io::Result<()>
1002+
) -> io::Result<()> {
1003+
self.space_if_not_bol()?;
1004+
self.ibox(indent_unit)?;
1005+
self.word_nbsp("let")?;
1006+
1007+
self.ibox(indent_unit)?;
1008+
decl(self)?;
1009+
self.end()?;
1010+
1011+
if let Some(ref init) = init {
1012+
self.nbsp()?;
1013+
self.word_space("=")?;
1014+
self.print_expr(&init)?;
1015+
}
1016+
self.end()
1017+
}
1018+
9981019
pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> {
9991020
self.maybe_print_comment(st.span.lo())?;
10001021
match st.node {
10011022
hir::StmtKind::Local(ref loc) => {
1002-
self.space_if_not_bol()?;
1003-
self.ibox(indent_unit)?;
1004-
self.word_nbsp("let")?;
1005-
1006-
self.ibox(indent_unit)?;
1007-
self.print_local_decl(&loc)?;
1008-
self.end()?;
1009-
if let Some(ref init) = loc.init {
1010-
self.nbsp()?;
1011-
self.word_space("=")?;
1012-
self.print_expr(&init)?;
1013-
}
1014-
self.end()?
1023+
self.print_local(loc.init.deref(), |this| this.print_local_decl(&loc))?;
10151024
}
10161025
hir::StmtKind::Item(item) => {
10171026
self.ann.nested(self, Nested::Item(item))?
@@ -1379,6 +1388,24 @@ impl<'a> State<'a> {
13791388
self.word_space(":")?;
13801389
self.print_type(&ty)?;
13811390
}
1391+
hir::ExprKind::Use(ref init) => {
1392+
// Print `{`:
1393+
self.cbox(indent_unit)?;
1394+
self.ibox(0)?;
1395+
self.bopen()?;
1396+
1397+
// Print `let _t = $init;`:
1398+
let temp = ast::Ident::from_str("_t");
1399+
self.print_local(Some(init), |this| this.print_ident(temp))?;
1400+
self.s.word(";")?;
1401+
1402+
// Print `_t`:
1403+
self.space_if_not_bol()?;
1404+
self.print_ident(temp)?;
1405+
1406+
// Print `}`:
1407+
self.bclose_maybe_open(expr.span, indent_unit, true)?;
1408+
}
13821409
hir::ExprKind::If(ref test, ref blk, ref elseopt) => {
13831410
self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e))?;
13841411
}

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(box_syntax)]
3838
#![feature(core_intrinsics)]
3939
#![feature(drain_filter)]
40+
#![feature(inner_deref)]
4041
#![cfg_attr(windows, feature(libc))]
4142
#![feature(never_type)]
4243
#![feature(exhaustive_patterns)]

src/librustc/middle/expr_use_visitor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
521521
self.consume_expr(&base);
522522
}
523523

524+
hir::ExprKind::Use(ref expr) => {
525+
self.consume_expr(&expr);
526+
}
527+
524528
hir::ExprKind::AssignOp(_, ref lhs, ref rhs) => {
525529
if self.mc.tables.is_method_call(expr) {
526530
self.consume_expr(lhs);

src/librustc/middle/liveness.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
521521
hir::ExprKind::Binary(..) |
522522
hir::ExprKind::AddrOf(..) |
523523
hir::ExprKind::Cast(..) |
524+
hir::ExprKind::Use(..) |
524525
hir::ExprKind::Unary(..) |
525526
hir::ExprKind::Break(..) |
526527
hir::ExprKind::Continue(_) |
@@ -1221,6 +1222,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12211222
hir::ExprKind::AddrOf(_, ref e) |
12221223
hir::ExprKind::Cast(ref e, _) |
12231224
hir::ExprKind::Type(ref e, _) |
1225+
hir::ExprKind::Use(ref e) |
12241226
hir::ExprKind::Unary(_, ref e) |
12251227
hir::ExprKind::Yield(ref e) |
12261228
hir::ExprKind::Repeat(ref e, _) => {
@@ -1524,9 +1526,9 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
15241526
hir::ExprKind::Match(..) | hir::ExprKind::While(..) | hir::ExprKind::Loop(..) |
15251527
hir::ExprKind::Index(..) | hir::ExprKind::Field(..) |
15261528
hir::ExprKind::Array(..) | hir::ExprKind::Tup(..) | hir::ExprKind::Binary(..) |
1527-
hir::ExprKind::Cast(..) | hir::ExprKind::Unary(..) | hir::ExprKind::Ret(..) |
1528-
hir::ExprKind::Break(..) | hir::ExprKind::Continue(..) | hir::ExprKind::Lit(_) |
1529-
hir::ExprKind::Block(..) | hir::ExprKind::AddrOf(..) |
1529+
hir::ExprKind::Cast(..) | hir::ExprKind::Use(..) | hir::ExprKind::Unary(..) |
1530+
hir::ExprKind::Ret(..) | hir::ExprKind::Break(..) | hir::ExprKind::Continue(..) |
1531+
hir::ExprKind::Lit(_) | hir::ExprKind::Block(..) | hir::ExprKind::AddrOf(..) |
15301532
hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |
15311533
hir::ExprKind::Closure(..) | hir::ExprKind::Path(_) | hir::ExprKind::Yield(..) |
15321534
hir::ExprKind::Box(..) | hir::ExprKind::Type(..) | hir::ExprKind::Err => {

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
678678
hir::ExprKind::Assign(..) | hir::ExprKind::AssignOp(..) |
679679
hir::ExprKind::Closure(..) | hir::ExprKind::Ret(..) |
680680
hir::ExprKind::Unary(..) | hir::ExprKind::Yield(..) |
681-
hir::ExprKind::MethodCall(..) | hir::ExprKind::Cast(..) |
681+
hir::ExprKind::MethodCall(..) | hir::ExprKind::Cast(..) | hir::ExprKind::Use(..) |
682682
hir::ExprKind::Array(..) | hir::ExprKind::Tup(..) | hir::ExprKind::If(..) |
683683
hir::ExprKind::Binary(..) | hir::ExprKind::While(..) |
684684
hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) | hir::ExprKind::Match(..) |

src/librustc/middle/region.rs

+6
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
909909
visitor.cx.var_parent = visitor.cx.parent;
910910
}
911911

912+
hir::ExprKind::Use(ref expr) => {
913+
// `Use(expr)` does not denote a conditional scope.
914+
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
915+
terminating(expr.hir_id.local_id);
916+
}
917+
912918
hir::ExprKind::AssignOp(..) | hir::ExprKind::Index(..) |
913919
hir::ExprKind::Unary(..) | hir::ExprKind::Call(..) | hir::ExprKind::MethodCall(..) => {
914920
// FIXME(https://github.com/rust-lang/rfcs/issues/811) Nested method calls

0 commit comments

Comments
 (0)