Skip to content

Commit 1bbb135

Browse files
committed
Auto merge of #60898 - Centril:rollup-76o2g8a, r=Centril
Rollup of 6 pull requests Successful merges: - #60685 (Switch to SPDX 2.1 license expression) - #60687 (Fix .natvis visualizers.) - #60805 (remove compiletest's dependency on `filetime`) - #60862 (Get ty from local_decls instead of using Place) - #60873 (Parse alternative incorrect uses of await and recover) - #60894 (Add entry-like methods to HashSet) Failed merges: r? @ghost
2 parents 4f53b5c + a80a1d0 commit 1bbb135

27 files changed

+781
-322
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ version = "0.0.0"
475475
dependencies = [
476476
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
477477
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
478-
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
479478
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
480479
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
481480
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",

src/etc/natvis/liballoc.natvis

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
88
<ArrayItems>
99
<Size>len</Size>
10-
<ValuePointer>buf.ptr.pointer.__0</ValuePointer>
10+
<ValuePointer>buf.ptr.pointer</ValuePointer>
1111
</ArrayItems>
1212
</Expand>
1313
</Type>
14-
<Type Name="alloc::vec_deque::VecDeque&lt;*&gt;">
14+
<Type Name="alloc::collections::vec_deque::VecDeque&lt;*&gt;">
1515
<DisplayString>{{ size={tail &lt;= head ? head - tail : buf.cap - tail + head} }}</DisplayString>
1616
<Expand>
1717
<Item Name="[size]" ExcludeView="simple">tail &lt;= head ? head - tail : buf.cap - tail + head</Item>
@@ -24,19 +24,19 @@
2424
<If Condition="i == head">
2525
<Break/>
2626
</If>
27-
<Item>buf.ptr.pointer.__0 + i</Item>
27+
<Item>buf.ptr.pointer[i]</Item>
2828
<Exec>i = (i + 1 == buf.cap ? 0 : i + 1)</Exec>
2929
</Loop>
3030
</CustomListItems>
3131
</Expand>
3232
</Type>
33-
<Type Name="alloc::linked_list::LinkedList&lt;*&gt;">
33+
<Type Name="alloc::collections::linked_list::LinkedList&lt;*&gt;">
3434
<DisplayString>{{ size={len} }}</DisplayString>
3535
<Expand>
3636
<LinkedListItems>
3737
<Size>len</Size>
38-
<HeadPointer>*(alloc::linked_list::Node&lt;$T1&gt; **)&amp;head</HeadPointer>
39-
<NextPointer>*(alloc::linked_list::Node&lt;$T1&gt; **)&amp;next</NextPointer>
38+
<HeadPointer>*(alloc::collections::linked_list::Node&lt;$T1&gt; **)&amp;head</HeadPointer>
39+
<NextPointer>*(alloc::collections::linked_list::Node&lt;$T1&gt; **)&amp;next</NextPointer>
4040
<ValueNode>element</ValueNode>
4141
</LinkedListItems>
4242
</Expand>

src/etc/natvis/libcore.natvis

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
33
<Type Name="core::ptr::Unique&lt;*&gt;">
4-
<DisplayString>{{ Unique {*pointer.__0} }}</DisplayString>
4+
<DisplayString>{{ Unique {pointer} }}</DisplayString>
55
<Expand>
6-
<Item Name="[ptr]">pointer.__0</Item>
6+
<Item Name="[ptr]">pointer</Item>
77
</Expand>
88
</Type>
99
<Type Name="core::ptr::Shared&lt;*&gt;">
10-
<DisplayString>{{ Shared {*pointer.__0} }}</DisplayString>
10+
<DisplayString>{{ Shared {pointer} }}</DisplayString>
1111
<Expand>
12-
<Item Name="[ptr]">pointer.__0</Item>
12+
<Item Name="[ptr]">pointer</Item>
1313
</Expand>
1414
</Type>
1515
<Type Name="core::option::Option&lt;*&gt;">

src/librustc/hir/lowering.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ pub struct LoweringContext<'a> {
9797
is_generator: bool,
9898
is_async_body: bool,
9999

100+
/// Used to get the current `fn`'s def span to point to when using `await`
101+
/// outside of an `async fn`.
102+
current_item: Option<Span>,
103+
100104
catch_scopes: Vec<NodeId>,
101105
loop_scopes: Vec<NodeId>,
102106
is_in_loop_condition: bool,
@@ -250,6 +254,7 @@ pub fn lower_crate(
250254
node_id_to_hir_id: IndexVec::new(),
251255
is_generator: false,
252256
is_async_body: false,
257+
current_item: None,
253258
is_in_trait_impl: false,
254259
lifetimes_to_define: Vec::new(),
255260
is_collecting_in_band_lifetimes: false,
@@ -3116,6 +3121,7 @@ impl<'a> LoweringContext<'a> {
31163121
ItemKind::Fn(ref decl, ref header, ref generics, ref body) => {
31173122
let fn_def_id = self.resolver.definitions().local_def_id(id);
31183123
self.with_new_scopes(|this| {
3124+
this.current_item = Some(ident.span);
31193125
let mut lower_fn = |decl: &FnDecl| {
31203126
// Note: we don't need to change the return type from `T` to
31213127
// `impl Future<Output = T>` here because lower_body
@@ -3654,6 +3660,7 @@ impl<'a> LoweringContext<'a> {
36543660
} else {
36553661
lower_method(sig)
36563662
};
3663+
self.current_item = Some(i.span);
36573664

36583665
(generics, hir::ImplItemKind::Method(sig, body_id))
36593666
}
@@ -4270,6 +4277,7 @@ impl<'a> LoweringContext<'a> {
42704277
let fn_decl = self.lower_fn_decl(decl, None, false, None);
42714278

42724279
self.with_new_scopes(|this| {
4280+
this.current_item = Some(fn_decl_span);
42734281
let mut is_generator = false;
42744282
let body_id = this.lower_body(Some(decl), |this| {
42754283
let e = this.lower_expr(body);
@@ -5551,13 +5559,18 @@ impl<'a> LoweringContext<'a> {
55515559
// }
55525560
// }
55535561
if !self.is_async_body {
5554-
span_err!(
5562+
let mut err = struct_span_err!(
55555563
self.sess,
55565564
await_span,
55575565
E0728,
55585566
"`await` is only allowed inside `async` functions and blocks"
55595567
);
5560-
self.sess.abort_if_errors();
5568+
err.span_label(await_span, "only allowed inside `async` functions and blocks");
5569+
if let Some(item_sp) = self.current_item {
5570+
err.span_label(item_sp, "this is not `async`");
5571+
}
5572+
err.emit();
5573+
return hir::ExprKind::Err;
55615574
}
55625575
let span = self.sess.source_map().mark_span_with_reason(
55635576
CompilerDesugaringKind::Await,

src/librustc_codegen_ssa/mir/analyze.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,8 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
243243
}
244244

245245
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
246-
let ty = mir::Place::Base(mir::PlaceBase::Local(local)).ty(self.fx.mir,
247-
self.fx.cx.tcx());
248-
let ty = self.fx.monomorphize(&ty.ty);
246+
let ty = self.fx.mir.local_decls[local].ty;
247+
let ty = self.fx.monomorphize(&ty);
249248

250249
// Only need the place if we're actually dropping it.
251250
if self.fx.cx.type_needs_drop(ty) {

src/libstd/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = ["The Rust Project Developers"]
33
name = "std"
44
version = "0.0.0"
55
build = "build.rs"
6-
license = "MIT/Apache-2.0"
6+
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/rust-lang/rust.git"
88
description = "The Rust Standard Library"
99
edition = "2018"

src/libstd/collections/hash/set.rs

+56
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,62 @@ impl<T, S> HashSet<T, S>
618618
self.map.get_key_value(value).map(|(k, _)| k)
619619
}
620620

621+
/// Inserts the given `value` into the set if it is not present, then
622+
/// returns a reference to the value in the set.
623+
///
624+
/// # Examples
625+
///
626+
/// ```
627+
/// #![feature(hash_set_entry)]
628+
///
629+
/// use std::collections::HashSet;
630+
///
631+
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
632+
/// assert_eq!(set.len(), 3);
633+
/// assert_eq!(set.get_or_insert(2), &2);
634+
/// assert_eq!(set.get_or_insert(100), &100);
635+
/// assert_eq!(set.len(), 4); // 100 was inserted
636+
/// ```
637+
#[inline]
638+
#[unstable(feature = "hash_set_entry", issue = "60896")]
639+
pub fn get_or_insert(&mut self, value: T) -> &T {
640+
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
641+
// `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`.
642+
self.map.raw_entry_mut().from_key(&value).or_insert(value, ()).0
643+
}
644+
645+
/// Inserts a value computed from `f` into the set if the given `value` is
646+
/// not present, then returns a reference to the value in the set.
647+
///
648+
/// # Examples
649+
///
650+
/// ```
651+
/// #![feature(hash_set_entry)]
652+
///
653+
/// use std::collections::HashSet;
654+
///
655+
/// let mut set: HashSet<String> = ["cat", "dog", "horse"]
656+
/// .iter().map(|&pet| pet.to_owned()).collect();
657+
///
658+
/// assert_eq!(set.len(), 3);
659+
/// for &pet in &["cat", "dog", "fish"] {
660+
/// let value = set.get_or_insert_with(pet, str::to_owned);
661+
/// assert_eq!(value, pet);
662+
/// }
663+
/// assert_eq!(set.len(), 4); // a new "fish" was inserted
664+
/// ```
665+
#[inline]
666+
#[unstable(feature = "hash_set_entry", issue = "60896")]
667+
pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
668+
where T: Borrow<Q>,
669+
Q: Hash + Eq,
670+
F: FnOnce(&Q) -> T
671+
{
672+
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
673+
// `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`.
674+
self.map.raw_entry_mut().from_key(value).or_insert_with(|| (f(value), ())).0
675+
}
676+
621677
/// Returns `true` if `self` has no elements in common with `other`.
622678
/// This is equivalent to checking for an empty intersection.
623679
///

0 commit comments

Comments
 (0)