Skip to content

Commit

Permalink
Auto merge of rust-lang#91350 - matthiaskrgr:rollup-nleabdj, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#91049 (Add a caveat to std::os::windows::fs::symlink_file)
 - rust-lang#91281 (Add demonstration test for rust-lang#91161)
 - rust-lang#91327 (Delete an unreachable codepath from format_args implementation)
 - rust-lang#91336 (Remove unused root_parent.)
 - rust-lang#91349 (Accumulate all values of `-C remark` option)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 29, 2021
2 parents 44723c5 + e15e0ba commit 8b95491
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 36 deletions.
12 changes: 4 additions & 8 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ struct Context<'a, 'b> {
/// * Implicit argument resolution: `"{1:.0$} {2:.foo$} {1:.3$} {4:.0$}"`
/// * Name resolution: `"{1:.0$} {2:.5$} {1:.3$} {4:.0$}"`
/// * `count_positions` (in JSON): `{0: 0, 5: 1, 3: 2}`
/// * `count_args`: `vec![Exact(0), Exact(5), Exact(3)]`
count_args: Vec<Position>,
/// * `count_args`: `vec![0, 5, 3]`
count_args: Vec<usize>,
/// Relative slot numbers for count arguments.
count_positions: FxHashMap<usize, usize>,
/// Number of count slots assigned.
Expand Down Expand Up @@ -513,7 +513,7 @@ impl<'a, 'b> Context<'a, 'b> {
if let Entry::Vacant(e) = self.count_positions.entry(arg) {
let i = self.count_positions_count;
e.insert(i);
self.count_args.push(Exact(arg));
self.count_args.push(arg);
self.count_positions_count += 1;
}
}
Expand Down Expand Up @@ -774,11 +774,7 @@ impl<'a, 'b> Context<'a, 'b> {
// (the span is otherwise unavailable in MIR)
heads.push(self.ecx.expr_addr_of(e.span.with_ctxt(self.macsp.ctxt()), e));
}
for pos in self.count_args {
let index = match pos {
Exact(i) => i,
_ => panic!("should never happen"),
};
for index in self.count_args {
let span = spans_pos[index];
args.push(Context::format_arg(self.ecx, self.macsp, span, &Count, index));
}
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
use crate::ty::TyCtxt;
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_macros::HashStable;
use rustc_query_system::ich::{NodeIdHashingMode, StableHashingContext};
use rustc_span::{Span, DUMMY_SP};

use std::fmt;
Expand Down Expand Up @@ -210,11 +209,6 @@ pub struct ScopeTree {
/// If not empty, this body is the root of this region hierarchy.
pub root_body: Option<hir::HirId>,

/// The parent of the root body owner, if the latter is an
/// an associated const or method, as impls/traits can also
/// have lifetime parameters free in this body.
pub root_parent: Option<hir::HirId>,

/// Maps from a scope ID to the enclosing scope id;
/// this is usually corresponding to the lexical nesting, though
/// in the case of closures the parent scope is the innermost
Expand Down Expand Up @@ -445,7 +439,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let ScopeTree {
root_body,
root_parent,
ref body_expr_count,
ref parent_map,
ref var_map,
Expand All @@ -455,8 +448,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
} = *self;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
root_body.hash_stable(hcx, hasher);
root_parent.hash_stable(hcx, hasher);
root_body.hash_stable(hcx, hasher)
});

body_expr_count.hash_stable(hcx, hasher);
Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_passes/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Arm, Block, Expr, Local, Node, Pat, PatKind, Stmt};
use rustc_hir::{Arm, Block, Expr, Local, Pat, PatKind, Stmt};
use rustc_index::vec::Idx;
use rustc_middle::middle::region::*;
use rustc_middle::ty::query::Providers;
Expand Down Expand Up @@ -837,19 +837,7 @@ fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {

let body = tcx.hir().body(body_id);
visitor.scope_tree.root_body = Some(body.value.hir_id);

// If the item is an associated const or a method,
// record its impl/trait parent, as it can also have
// lifetime parameters free in this body.
match tcx.hir().get(id) {
Node::ImplItem(_) | Node::TraitItem(_) => {
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id));
}
_ => {}
}

visitor.visit_body(body);

visitor.scope_tree
} else {
ScopeTree::default()
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,13 @@ impl Passes {
Passes::All => false,
}
}

pub fn extend(&mut self, passes: impl IntoIterator<Item = String>) {
match *self {
Passes::Some(ref mut v) => v.extend(passes),
Passes::All => {}
}
}
}

pub const fn default_lib_output() -> CrateType {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ mod parse {
v => {
let mut passes = vec![];
if parse_list(&mut passes, v) {
*slot = Passes::Some(passes);
slot.extend(passes);
true
} else {
false
Expand Down
20 changes: 20 additions & 0 deletions library/std/src/os/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ impl FileTypeExt for fs::FileType {
/// Ok(())
/// }
/// ```
///
/// # Limitations
///
/// Windows treats symlink creation as a [privileged action][symlink-security],
/// therefore this function is likely to fail unless the user makes changes to
/// their system to permit symlink creation. Users can try enabling Developer
/// Mode, granting the `SeCreateSymbolicLinkPrivilege` privilege, or running
/// the process as an administrator.
///
/// [symlink-security]: https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
sys::fs::symlink_inner(original.as_ref(), link.as_ref(), false)
Expand Down Expand Up @@ -572,6 +582,16 @@ pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io:
/// Ok(())
/// }
/// ```
///
/// # Limitations
///
/// Windows treats symlink creation as a [privileged action][symlink-security],
/// therefore this function is likely to fail unless the user makes changes to
/// their system to permit symlink creation. Users can try enabling Developer
/// Mode, granting the `SeCreateSymbolicLinkPrivilege` privilege, or running
/// the process as an administrator.
///
/// [symlink-security]: https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
sys::fs::symlink_inner(original.as_ref(), link.as_ref(), true)
Expand Down
13 changes: 11 additions & 2 deletions src/test/ui/optimization-remark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// build-pass
// ignore-pass
// no-system-llvm
// revisions: all inline
// compile-flags: --crate-type=lib -Cdebuginfo=1 -Copt-level=2
// revisions: all inline merge1 merge2
// compile-flags: --crate-type=lib -Cdebuginfo=1 -Copt-level=2
//
// Check that remarks can be enabled individually or with "all":
//
// [all] compile-flags: -Cremark=all
// [inline] compile-flags: -Cremark=inline
//
// Check that values of -Cremark flag are accumulated:
//
// [merge1] compile-flags: -Cremark=all -Cremark=giraffe
// [merge2] compile-flags: -Cremark=inline -Cremark=giraffe
//
// error-pattern: inline: f not inlined into g
// dont-check-compiler-stderr

Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ pub enum VariantNonExhaustive {
pub enum NonExhaustiveSingleVariant {
A(bool),
}

#[repr(u8)]
pub enum FieldLessWithNonExhaustiveVariant {
A,
B,
#[non_exhaustive]
C,
}

impl Default for FieldLessWithNonExhaustiveVariant {
fn default() -> Self { Self::A }
}
17 changes: 17 additions & 0 deletions src/test/ui/rfc-2008-non-exhaustive/enum-as-cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// aux-build:enums.rs
// run-pass

extern crate enums;

use enums::FieldLessWithNonExhaustiveVariant;

fn main() {
let e = FieldLessWithNonExhaustiveVariant::default();
// FIXME: https://github.com/rust-lang/rust/issues/91161
// This `as` cast *should* be an error, since it would fail
// if the non-exhaustive variant got fields. But today it
// doesn't. The fix for that will update this test to
// show an error (and not be run-pass any more).
let d = e as u8;
assert_eq!(d, 0);
}

0 comments on commit 8b95491

Please sign in to comment.