Skip to content

Commit 9e9a136

Browse files
committed
Auto merge of #63575 - Centril:rollup-anlv9g5, r=Centril
Rollup of 11 pull requests Successful merges: - #62984 (Add lint for excess trailing semicolons) - #63075 (Miri: Check that a ptr is aligned and inbounds already when evaluating `*`) - #63490 (libsyntax: cleanup and refactor `pat.rs`) - #63507 (When needing type annotations in local bindings, account for impl Trait and closures) - #63509 (Point at the right enclosing scope when using `await` in non-async fn) - #63528 (syntax: Remove `DummyResult::expr_only`) - #63537 (expand: Unimplement `MutVisitor` on `MacroExpander`) - #63542 (Add NodeId for Arm, Field and FieldPat) - #63543 (Merge Variant and Variant_) - #63560 (move test that shouldn't be in test/run-pass/) - #63570 (Adjust tracking issues for `MaybeUninit<T>` gates) Failed merges: r? @ghost
2 parents 082cf2f + 78cd9d1 commit 9e9a136

File tree

102 files changed

+1077
-558
lines changed

Some content is hidden

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

102 files changed

+1077
-558
lines changed

src/libcore/mem/maybe_uninit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<T> MaybeUninit<T> {
312312
/// without dropping it, so be careful not to use this twice unless you want to
313313
/// skip running the destructor. For your convenience, this also returns a mutable
314314
/// reference to the (now safely initialized) contents of `self`.
315-
#[unstable(feature = "maybe_uninit_extra", issue = "53491")]
315+
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
316316
#[inline(always)]
317317
pub fn write(&mut self, val: T) -> &mut T {
318318
unsafe {
@@ -502,7 +502,7 @@ impl<T> MaybeUninit<T> {
502502
/// // We now created two copies of the same vector, leading to a double-free when
503503
/// // they both get dropped!
504504
/// ```
505-
#[unstable(feature = "maybe_uninit_extra", issue = "53491")]
505+
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
506506
#[inline(always)]
507507
pub unsafe fn read(&self) -> T {
508508
intrinsics::panic_if_uninhabited::<T>();
@@ -516,7 +516,7 @@ impl<T> MaybeUninit<T> {
516516
/// It is up to the caller to guarantee that the `MaybeUninit<T>` really is in an initialized
517517
/// state. Calling this when the content is not yet fully initialized causes undefined
518518
/// behavior.
519-
#[unstable(feature = "maybe_uninit_ref", issue = "53491")]
519+
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
520520
#[inline(always)]
521521
pub unsafe fn get_ref(&self) -> &T {
522522
&*self.value
@@ -532,21 +532,21 @@ impl<T> MaybeUninit<T> {
532532
// FIXME(#53491): We currently rely on the above being incorrect, i.e., we have references
533533
// to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make
534534
// a final decision about the rules before stabilization.
535-
#[unstable(feature = "maybe_uninit_ref", issue = "53491")]
535+
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
536536
#[inline(always)]
537537
pub unsafe fn get_mut(&mut self) -> &mut T {
538538
&mut *self.value
539539
}
540540

541541
/// Gets a pointer to the first element of the array.
542-
#[unstable(feature = "maybe_uninit_slice", issue = "53491")]
542+
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
543543
#[inline(always)]
544544
pub fn first_ptr(this: &[MaybeUninit<T>]) -> *const T {
545545
this as *const [MaybeUninit<T>] as *const T
546546
}
547547

548548
/// Gets a mutable pointer to the first element of the array.
549-
#[unstable(feature = "maybe_uninit_slice", issue = "53491")]
549+
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
550550
#[inline(always)]
551551
pub fn first_ptr_mut(this: &mut [MaybeUninit<T>]) -> *mut T {
552552
this as *mut [MaybeUninit<T>] as *mut T

src/librustc/hir/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
336336
fn is_c_like_enum(item: &hir::Item) -> bool {
337337
if let hir::ItemKind::Enum(ref def, _) = item.node {
338338
for variant in &def.variants {
339-
match variant.node.data {
339+
match variant.data {
340340
hir::VariantData::Unit(..) => { /* continue */ }
341341
_ => { return false; }
342342
}

src/librustc/hir/intravisit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
577577
variant: &'v Variant,
578578
generics: &'v Generics,
579579
parent_item_id: HirId) {
580-
visitor.visit_ident(variant.node.ident);
581-
visitor.visit_id(variant.node.id);
582-
visitor.visit_variant_data(&variant.node.data,
583-
variant.node.ident.name,
580+
visitor.visit_ident(variant.ident);
581+
visitor.visit_id(variant.id);
582+
visitor.visit_variant_data(&variant.data,
583+
variant.ident.name,
584584
generics,
585585
parent_item_id,
586586
variant.span);
587-
walk_list!(visitor, visit_anon_const, &variant.node.disr_expr);
588-
walk_list!(visitor, visit_attribute, &variant.node.attrs);
587+
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
588+
walk_list!(visitor, visit_attribute, &variant.attrs);
589589
}
590590

591591
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {

src/librustc/hir/lowering/expr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ impl LoweringContext<'_> {
677677
let fn_decl = self.lower_fn_decl(decl, None, false, None);
678678

679679
self.with_new_scopes(|this| {
680+
let prev = this.current_item;
680681
this.current_item = Some(fn_decl_span);
681682
let mut generator_kind = None;
682683
let body_id = this.lower_fn_body(decl, |this| {
@@ -690,8 +691,10 @@ impl LoweringContext<'_> {
690691
generator_kind,
691692
movability,
692693
);
694+
let capture_clause = this.lower_capture_clause(capture_clause);
695+
this.current_item = prev;
693696
hir::ExprKind::Closure(
694-
this.lower_capture_clause(capture_clause),
697+
capture_clause,
695698
fn_decl,
696699
body_id,
697700
fn_decl_span,

src/librustc/hir/lowering/item.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,12 @@ impl LoweringContext<'_> {
757757
}
758758

759759
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
760-
Spanned {
761-
node: hir::VariantKind {
762-
ident: v.node.ident,
763-
id: self.lower_node_id(v.node.id),
764-
attrs: self.lower_attrs(&v.node.attrs),
765-
data: self.lower_variant_data(&v.node.data),
766-
disr_expr: v.node.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
767-
},
760+
hir::Variant {
761+
attrs: self.lower_attrs(&v.attrs),
762+
data: self.lower_variant_data(&v.data),
763+
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
764+
id: self.lower_node_id(v.id),
765+
ident: v.ident,
768766
span: v.span,
769767
}
770768
}

src/librustc/hir/map/collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
544544
}
545545

546546
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: HirId) {
547-
self.insert(v.span, v.node.id, Node::Variant(v));
548-
self.with_parent(v.node.id, |this| {
547+
self.insert(v.span, v.id, Node::Variant(v));
548+
self.with_parent(v.id, |this| {
549549
// Register the constructor of this variant.
550-
if let Some(ctor_hir_id) = v.node.data.ctor_hir_id() {
551-
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.node.data));
550+
if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
551+
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
552552
}
553553
intravisit::walk_variant(this, v, g, item_id);
554554
});

src/librustc/hir/map/def_collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
155155
}
156156

157157
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
158-
let def = self.create_def(v.node.id,
159-
DefPathData::TypeNs(v.node.ident.as_interned_str()),
158+
let def = self.create_def(v.id,
159+
DefPathData::TypeNs(v.ident.as_interned_str()),
160160
v.span);
161161
self.with_parent(def, |this| {
162-
if let Some(ctor_hir_id) = v.node.data.ctor_id() {
162+
if let Some(ctor_hir_id) = v.data.ctor_id() {
163163
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
164164
}
165165
visit::walk_variant(this, v, g, item_id)

src/librustc/hir/map/mod.rs

+32-10
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,34 @@ impl<'hir> Map<'hir> {
649649
}
650650
}
651651

652-
pub fn is_const_scope(&self, hir_id: HirId) -> bool {
653-
self.walk_parent_nodes(hir_id, |node| match *node {
654-
Node::Item(Item { node: ItemKind::Const(_, _), .. }) => true,
655-
Node::Item(Item { node: ItemKind::Fn(_, header, _, _), .. }) => header.is_const(),
652+
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
653+
/// Used exclusively for diagnostics, to avoid suggestion function calls.
654+
pub fn is_const_context(&self, hir_id: HirId) -> bool {
655+
let parent_id = self.get_parent_item(hir_id);
656+
match self.get(parent_id) {
657+
Node::Item(&Item {
658+
node: ItemKind::Const(..),
659+
..
660+
})
661+
| Node::TraitItem(&TraitItem {
662+
node: TraitItemKind::Const(..),
663+
..
664+
})
665+
| Node::ImplItem(&ImplItem {
666+
node: ImplItemKind::Const(..),
667+
..
668+
})
669+
| Node::AnonConst(_)
670+
| Node::Item(&Item {
671+
node: ItemKind::Static(..),
672+
..
673+
}) => true,
674+
Node::Item(&Item {
675+
node: ItemKind::Fn(_, header, ..),
676+
..
677+
}) => header.constness == Constness::Const,
656678
_ => false,
657-
}, |_| false).map(|id| id != CRATE_HIR_ID).unwrap_or(false)
679+
}
658680
}
659681

660682
/// If there is some error when walking the parents (e.g., a node does not
@@ -885,7 +907,7 @@ impl<'hir> Map<'hir> {
885907
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id))
886908
}
887909
}
888-
Some(Node::Variant(variant)) => &variant.node.data,
910+
Some(Node::Variant(variant)) => &variant.data,
889911
Some(Node::Ctor(data)) => data,
890912
_ => bug!("expected struct or variant, found {}", self.node_to_string(id))
891913
}
@@ -918,7 +940,7 @@ impl<'hir> Map<'hir> {
918940
Node::ForeignItem(fi) => fi.ident.name,
919941
Node::ImplItem(ii) => ii.ident.name,
920942
Node::TraitItem(ti) => ti.ident.name,
921-
Node::Variant(v) => v.node.ident.name,
943+
Node::Variant(v) => v.ident.name,
922944
Node::Field(f) => f.ident.name,
923945
Node::Lifetime(lt) => lt.name.ident().name,
924946
Node::GenericParam(param) => param.name.ident().name,
@@ -939,7 +961,7 @@ impl<'hir> Map<'hir> {
939961
Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]),
940962
Some(Node::TraitItem(ref ti)) => Some(&ti.attrs[..]),
941963
Some(Node::ImplItem(ref ii)) => Some(&ii.attrs[..]),
942-
Some(Node::Variant(ref v)) => Some(&v.node.attrs[..]),
964+
Some(Node::Variant(ref v)) => Some(&v.attrs[..]),
943965
Some(Node::Field(ref f)) => Some(&f.attrs[..]),
944966
Some(Node::Expr(ref e)) => Some(&*e.attrs),
945967
Some(Node::Stmt(ref s)) => Some(s.node.attrs()),
@@ -1133,7 +1155,7 @@ impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() }
11331155

11341156
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
11351157
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
1136-
impl Named for VariantKind { fn name(&self) -> Name { self.ident.name } }
1158+
impl Named for Variant { fn name(&self) -> Name { self.ident.name } }
11371159
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
11381160
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
11391161
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
@@ -1310,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13101332
}
13111333
Some(Node::Variant(ref variant)) => {
13121334
format!("variant {} in {}{}",
1313-
variant.node.ident,
1335+
variant.ident,
13141336
path_str(), id_str)
13151337
}
13161338
Some(Node::Field(ref field)) => {

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ pub enum ExprKind {
15411541
Match(P<Expr>, HirVec<Arm>, MatchSource),
15421542
/// A closure (e.g., `move |a, b, c| {a + b + c}`).
15431543
///
1544-
/// The final span is the span of the argument block `|...|`.
1544+
/// The `Span` is the argument block `|...|`.
15451545
///
15461546
/// This may also be a generator literal or an `async block` as indicated by the
15471547
/// `Option<GeneratorMovability>`.
@@ -2193,7 +2193,7 @@ pub struct EnumDef {
21932193
}
21942194

21952195
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2196-
pub struct VariantKind {
2196+
pub struct Variant {
21972197
/// Name of the variant.
21982198
#[stable_hasher(project(name))]
21992199
pub ident: Ident,
@@ -2205,10 +2205,10 @@ pub struct VariantKind {
22052205
pub data: VariantData,
22062206
/// Explicit discriminant (e.g., `Foo = 1`).
22072207
pub disr_expr: Option<AnonConst>,
2208+
/// Span
2209+
pub span: Span
22082210
}
22092211

2210-
pub type Variant = Spanned<VariantKind>;
2211-
22122212
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
22132213
pub enum UseKind {
22142214
/// One import, e.g., `use foo::bar` or `use foo::bar as baz`.

src/librustc/hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<'a> State<'a> {
737737
for v in variants {
738738
self.space_if_not_bol();
739739
self.maybe_print_comment(v.span.lo());
740-
self.print_outer_attributes(&v.node.attrs);
740+
self.print_outer_attributes(&v.attrs);
741741
self.ibox(INDENT_UNIT);
742742
self.print_variant(v);
743743
self.s.word(",");
@@ -829,8 +829,8 @@ impl<'a> State<'a> {
829829
pub fn print_variant(&mut self, v: &hir::Variant) {
830830
self.head("");
831831
let generics = hir::Generics::empty();
832-
self.print_struct(&v.node.data, &generics, v.node.ident.name, v.span, false);
833-
if let Some(ref d) = v.node.disr_expr {
832+
self.print_struct(&v.data, &generics, v.ident.name, v.span, false);
833+
if let Some(ref d) = v.disr_expr {
834834
self.s.space();
835835
self.word_space("=");
836836
self.print_anon_const(d);

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
304304
}
305305
}
306306

307-
impl_stable_hash_for_spanned!(hir::VariantKind);
307+
impl_stable_hash_for_spanned!(hir::Variant);
308308

309309

310310
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {

0 commit comments

Comments
 (0)