diff --git a/Cargo.lock b/Cargo.lock index 4a9bafeff8ba..f21cbbc6315d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -775,9 +775,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" dependencies = [ "crossbeam-epoch", "crossbeam-utils 0.7.2", @@ -881,9 +881,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.44+curl-7.77.0" +version = "0.4.45+curl-7.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6d85e9322b193f117c966e79c2d6929ec08c02f339f950044aba12e20bbaf1" +checksum = "de9e5a72b1c744eb5dd20b2be4d7eb84625070bb5c4ab9b347b70464ab1e62eb" dependencies = [ "cc", "libc", @@ -2445,9 +2445,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" -version = "111.15.0+1.1.1k" +version = "111.16.0+1.1.1l" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a" +checksum = "7ab2173f69416cf3ec12debb5823d244127d23a9b127d5a5189aa97c5fa2859f" dependencies = [ "cc", ] @@ -2806,9 +2806,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.11" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e0536f6528466dbbbbe6b986c34175a8d0ff25b794c4bacda22e068cd2f2c5" +checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69" dependencies = [ "cc", ] @@ -3475,9 +3475,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", @@ -4224,6 +4224,7 @@ dependencies = [ name = "rustc_privacy" version = "0.0.0" dependencies = [ + "rustc_ast", "rustc_attr", "rustc_data_structures", "rustc_errors", @@ -4482,6 +4483,7 @@ dependencies = [ "rustc_hir_pretty", "rustc_index", "rustc_infer", + "rustc_lint", "rustc_macros", "rustc_middle", "rustc_session", @@ -4890,12 +4892,12 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stacker" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ccb4c06ec57bc82d0f610f1a2963d7648700e43a6f513e564b9c89f7991786" +checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" dependencies = [ "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "psm", "winapi", @@ -5045,9 +5047,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80" +checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c" dependencies = [ "filetime", "libc", diff --git a/UPSTREAM-RELEASES.md b/UPSTREAM-RELEASES.md index 2e7077ed2065..2124195bcb20 100644 --- a/UPSTREAM-RELEASES.md +++ b/UPSTREAM-RELEASES.md @@ -70,7 +70,8 @@ Cargo - [The package definition in `cargo metadata` now includes the `"default_run"` field from the manifest.][cargo/9550] - [Added `cargo d` as an alias for `cargo doc`.][cargo/9680] -- [Added `{lib}` as formatting option for `cargo tree` to print the "lib_name" of packages.][cargo/9663] +- [Added `{lib}` as formatting option for `cargo tree` to print the `"lib_name"` + of packages.][cargo/9663] Rustdoc ------- @@ -116,9 +117,11 @@ Compatibility Notes [79965]: https://github.com/rust-lang/rust/pull/79965 [87370]: https://github.com/rust-lang/rust/pull/87370 [87298]: https://github.com/rust-lang/rust/pull/87298 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [cargo/9675]: https://github.com/rust-lang/cargo/pull/9675 [cargo/9550]: https://github.com/rust-lang/cargo/pull/9550 [cargo/9680]: https://github.com/rust-lang/cargo/pull/9680 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [`array::map`]: https://doc.rust-lang.org/stable/std/primitive.array.html#method.map [`Bound::cloned`]: https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.cloned [`Drain::as_str`]: https://doc.rust-lang.org/stable/std/string/struct.Drain.html#method.as_str @@ -175,6 +178,7 @@ Compiler - [Improved debugger output for enums on Windows MSVC platforms.][85292] - [Added tier 3\* support for `bpfel-unknown-none` and `bpfeb-unknown-none`.][79608] +- [`-Zmutable-noalias=yes`][82834] is enabled by default when using LLVM 12 or above. \* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. @@ -244,6 +248,7 @@ Compatibility Notes [83366]: https://github.com/rust-lang/rust/pull/83366 [83278]: https://github.com/rust-lang/rust/pull/83278 [85292]: https://github.com/rust-lang/rust/pull/85292 +[82834]: https://github.com/rust-lang/rust/pull/82834 [cargo/9520]: https://github.com/rust-lang/cargo/pull/9520 [cargo/9499]: https://github.com/rust-lang/cargo/pull/9499 [cargo/9488]: https://github.com/rust-lang/cargo/pull/9488 diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index c3e4945c4464..6d5f47aceeb9 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -15,6 +15,8 @@ #![feature(new_uninit)] #![feature(maybe_uninit_slice)] #![feature(min_specialization)] +#![feature(decl_macro)] +#![feature(rustc_attrs)] #![cfg_attr(test, feature(test))] use rustc_data_structures::sync; @@ -608,117 +610,113 @@ impl DropArena { } } -#[macro_export] -macro_rules! arena_for_type { +pub macro arena_for_type { ([][$ty:ty]) => { $crate::TypedArena<$ty> - }; + }, ([few $(, $attrs:ident)*][$ty:ty]) => { ::std::marker::PhantomData<$ty> - }; + }, ([$ignore:ident $(, $attrs:ident)*]$args:tt) => { $crate::arena_for_type!([$($attrs),*]$args) - }; + }, } -#[macro_export] -macro_rules! which_arena_for_type { +pub macro which_arena_for_type { ([][$arena:expr]) => { ::std::option::Option::Some($arena) - }; + }, ([few$(, $attrs:ident)*][$arena:expr]) => { ::std::option::Option::None - }; + }, ([$ignore:ident$(, $attrs:ident)*]$args:tt) => { $crate::which_arena_for_type!([$($attrs),*]$args) - }; + }, } -#[macro_export] -macro_rules! declare_arena { - ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { - #[derive(Default)] - pub struct Arena<$tcx> { - pub dropless: $crate::DroplessArena, - drop: $crate::DropArena, - $($name: $crate::arena_for_type!($a[$ty]),)* - } +#[rustc_macro_transparency = "semitransparent"] +pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) { + #[derive(Default)] + pub struct Arena<$tcx> { + pub dropless: $crate::DroplessArena, + drop: $crate::DropArena, + $($name: $crate::arena_for_type!($a[$ty]),)* + } - pub trait ArenaAllocatable<'tcx, T = Self>: Sized { - fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self; - fn allocate_from_iter<'a>( - arena: &'a Arena<'tcx>, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [Self]; + pub trait ArenaAllocatable<'tcx, T = Self>: Sized { + fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self; + fn allocate_from_iter<'a>( + arena: &'a Arena<'tcx>, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [Self]; + } + + impl<'tcx, T: Copy> ArenaAllocatable<'tcx, ()> for T { + #[inline] + fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { + arena.dropless.alloc(self) + } + #[inline] + fn allocate_from_iter<'a>( + arena: &'a Arena<'tcx>, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [Self] { + arena.dropless.alloc_from_iter(iter) } - impl<'tcx, T: Copy> ArenaAllocatable<'tcx, ()> for T { + } + $( + impl<$tcx> ArenaAllocatable<$tcx, $ty> for $ty { #[inline] - fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { - arena.dropless.alloc(self) + fn allocate_on<'a>(self, arena: &'a Arena<$tcx>) -> &'a mut Self { + if !::std::mem::needs_drop::() { + return arena.dropless.alloc(self); + } + match $crate::which_arena_for_type!($a[&arena.$name]) { + ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { + ty_arena.alloc(self) + } + ::std::option::Option::None => unsafe { arena.drop.alloc(self) }, + } } + #[inline] fn allocate_from_iter<'a>( - arena: &'a Arena<'tcx>, + arena: &'a Arena<$tcx>, iter: impl ::std::iter::IntoIterator, ) -> &'a mut [Self] { - arena.dropless.alloc_from_iter(iter) - } - - } - $( - impl<$tcx> ArenaAllocatable<$tcx, $ty> for $ty { - #[inline] - fn allocate_on<'a>(self, arena: &'a Arena<$tcx>) -> &'a mut Self { - if !::std::mem::needs_drop::() { - return arena.dropless.alloc(self); - } - match $crate::which_arena_for_type!($a[&arena.$name]) { - ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { - ty_arena.alloc(self) - } - ::std::option::Option::None => unsafe { arena.drop.alloc(self) }, - } + if !::std::mem::needs_drop::() { + return arena.dropless.alloc_from_iter(iter); } - - #[inline] - fn allocate_from_iter<'a>( - arena: &'a Arena<$tcx>, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [Self] { - if !::std::mem::needs_drop::() { - return arena.dropless.alloc_from_iter(iter); - } - match $crate::which_arena_for_type!($a[&arena.$name]) { - ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { - ty_arena.alloc_from_iter(iter) - } - ::std::option::Option::None => unsafe { arena.drop.alloc_from_iter(iter) }, + match $crate::which_arena_for_type!($a[&arena.$name]) { + ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { + ty_arena.alloc_from_iter(iter) } + ::std::option::Option::None => unsafe { arena.drop.alloc_from_iter(iter) }, } } - )* + } + )* - impl<'tcx> Arena<'tcx> { - #[inline] - pub fn alloc, U>(&self, value: T) -> &mut T { - value.allocate_on(self) - } + impl<'tcx> Arena<'tcx> { + #[inline] + pub fn alloc, U>(&self, value: T) -> &mut T { + value.allocate_on(self) + } - #[inline] - pub fn alloc_slice(&self, value: &[T]) -> &mut [T] { - if value.is_empty() { - return &mut []; - } - self.dropless.alloc_slice(value) + #[inline] + pub fn alloc_slice(&self, value: &[T]) -> &mut [T] { + if value.is_empty() { + return &mut []; } + self.dropless.alloc_slice(value) + } - pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, U>, U>( - &'a self, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [T] { - T::allocate_from_iter(self, iter) - } + pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, U>, U>( + &'a self, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [T] { + T::allocate_from_iter(self, iter) } } } diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 575a00cdd0e4..e1ea464dedb1 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -284,7 +284,7 @@ impl ParenthesizedArgs { pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; -/// A modifier on a bound, e.g., `?Sized` or `?const Trait`. +/// A modifier on a bound, e.g., `?Sized` or `~const Trait`. /// /// Negative bounds should also be handled here. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] @@ -295,10 +295,10 @@ pub enum TraitBoundModifier { /// `?Trait` Maybe, - /// `?const Trait` + /// `~const Trait` MaybeConst, - /// `?const ?Trait` + /// `~const ?Trait` // // This parses but will be rejected during AST validation. MaybeConstMaybe, @@ -332,8 +332,8 @@ pub type GenericBounds = Vec; pub enum ParamKindOrd { Lifetime, Type, - // `unordered` is only `true` if `sess.has_features().const_generics` - // is active. Specifically, if it's only `min_const_generics`, it will still require + // `unordered` is only `true` if `sess.unordered_const_ty_params()` + // returns true. Specifically, if it's only `min_const_generics`, it will still require // ordering consts after types. Const { unordered: bool }, // `Infer` is not actually constructed directly from the AST, but is implicitly constructed @@ -2028,6 +2028,7 @@ pub enum InlineAsmOperand { #[derive(Clone, Encodable, Decodable, Debug)] pub struct InlineAsm { pub template: Vec, + pub template_strs: Box<[(Symbol, Option, Span)]>, pub operands: Vec<(InlineAsmOperand, Span)>, pub clobber_abi: Option<(Symbol, Span)>, pub options: InlineAsmOptions, diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 41121d095f3e..81195f7fb5cb 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -564,11 +564,11 @@ impl NestedMetaItem { I: Iterator, { match tokens.peek() { - Some(TokenTree::Token(token)) => { - if let Ok(lit) = Lit::from_token(token) { - tokens.next(); - return Some(NestedMetaItem::Literal(lit)); - } + Some(TokenTree::Token(token)) + if let Ok(lit) = Lit::from_token(token) => + { + tokens.next(); + return Some(NestedMetaItem::Literal(lit)); } Some(TokenTree::Delimited(_, token::NoDelim, inner_tokens)) => { let inner_tokens = inner_tokens.clone(); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 502bd69e6a9a..ef3f6035085d 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -11,10 +11,12 @@ #![feature(box_patterns)] #![cfg_attr(bootstrap, feature(const_fn_transmute))] #![feature(crate_visibility_modifier)] +#![feature(if_let_guard)] #![feature(iter_zip)] #![feature(label_break_value)] #![feature(nll)] #![feature(min_specialization)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index c82458311872..fb4db6005aca 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1179,13 +1179,10 @@ fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { for (op, _) in &mut asm.operands { match op { InlineAsmOperand::In { expr, .. } + | InlineAsmOperand::Out { expr: Some(expr), .. } | InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr), - InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - vis.visit_expr(expr); - } - } + InlineAsmOperand::Out { expr: None, .. } => {} InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { vis.visit_expr(in_expr); if let Some(out_expr) = out_expr { diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index a377763983a4..dd8927496e01 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -19,20 +19,20 @@ use crate::token; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum AssocCtxt { Trait, Impl, } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum FnCtxt { Free, Foreign, Assoc(AssocCtxt), } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum FnKind<'a> { /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, Option<&'a Block>), @@ -714,13 +714,10 @@ fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) { for (op, _) in &asm.operands { match op { InlineAsmOperand::In { expr, .. } + | InlineAsmOperand::Out { expr: Some(expr), .. } | InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr), - InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - visitor.visit_expr(expr); - } - } + InlineAsmOperand::Out { expr: None, .. } => {} InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { visitor.visit_expr(in_expr); if let Some(out_expr) = out_expr { diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index d94fb48d7cb8..7165b3bcb9fc 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -128,7 +128,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } } }; - (op, *op_sp) + (op, self.lower_span(*op_sp)) }) .collect(); @@ -384,7 +384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { late: true, expr: None, }, - abi_span, + self.lower_span(abi_span), )); } } @@ -392,8 +392,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let operands = self.arena.alloc_from_iter(operands); let template = self.arena.alloc_from_iter(asm.template.iter().cloned()); - let line_spans = self.arena.alloc_slice(&asm.line_spans[..]); - let hir_asm = hir::InlineAsm { template, operands, options: asm.options, line_spans }; + let template_strs = self.arena.alloc_from_iter( + asm.template_strs + .iter() + .map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))), + ); + let line_spans = + self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span))); + let hir_asm = + hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans }; self.arena.alloc(hir_asm) } } diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index bf7589e84adc..80633e141fc6 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -58,7 +58,12 @@ impl<'hir> LoweringContext<'_, 'hir> { None, )); let args = self.lower_exprs(args); - hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span) + hir::ExprKind::MethodCall( + hir_seg, + self.lower_span(seg.ident.span), + args, + self.lower_span(span), + ) } ExprKind::Binary(binop, ref lhs, ref rhs) => { let binop = self.lower_binop(binop); @@ -71,7 +76,9 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::Unary(op, ohs) } - ExprKind::Lit(ref l) => hir::ExprKind::Lit(respan(l.span, l.kind.clone())), + ExprKind::Lit(ref l) => { + hir::ExprKind::Lit(respan(self.lower_span(l.span), l.kind.clone())) + } ExprKind::Cast(ref expr, ref ty) => { let expr = self.lower_expr(expr); let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); @@ -86,9 +93,11 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::AddrOf(k, m, ohs) } - ExprKind::Let(ref pat, ref scrutinee, span) => { - hir::ExprKind::Let(self.lower_pat(pat), self.lower_expr(scrutinee), span) - } + ExprKind::Let(ref pat, ref scrutinee, span) => hir::ExprKind::Let( + self.lower_pat(pat), + self.lower_expr(scrutinee), + self.lower_span(span), + ), ExprKind::If(ref cond, ref then, ref else_opt) => { self.lower_expr_if(cond, then, else_opt.as_deref()) } @@ -99,7 +108,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| { hir::ExprKind::Loop( this.lower_block(body, false), - opt_label, + this.lower_label(opt_label), hir::LoopSource::Loop, DUMMY_SP, ) @@ -147,6 +156,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } ExprKind::Block(ref blk, opt_label) => { + let opt_label = self.lower_label(opt_label); hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label) } ExprKind::Assign(ref el, ref er, span) => { @@ -157,7 +167,9 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_expr(el), self.lower_expr(er), ), - ExprKind::Field(ref el, ident) => hir::ExprKind::Field(self.lower_expr(el), ident), + ExprKind::Field(ref el, ident) => { + hir::ExprKind::Field(self.lower_expr(el), self.lower_ident(ident)) + } ExprKind::Index(ref el, ref er) => { hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er)) } @@ -234,7 +246,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut ex = self.lower_expr_mut(ex); // Include parens in span, but only if it is a super-span. if e.span.contains(ex.span) { - ex.span = e.span; + ex.span = self.lower_span(e.span); } // Merge attributes into the inner expression. if !e.attrs.is_empty() { @@ -262,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let hir_id = self.lower_node_id(e.id); self.lower_attrs(hir_id, &e.attrs); - hir::Expr { hir_id, kind, span: e.span } + hir::Expr { hir_id, kind, span: self.lower_span(e.span) } }) } @@ -296,7 +308,7 @@ impl<'hir> LoweringContext<'_, 'hir> { BinOpKind::Ge => hir::BinOpKind::Ge, BinOpKind::Gt => hir::BinOpKind::Gt, }, - span: b.span, + span: self.lower_span(b.span), } } @@ -478,7 +490,13 @@ impl<'hir> LoweringContext<'_, 'hir> { }); let hir_id = self.next_id(); self.lower_attrs(hir_id, &arm.attrs); - hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span } + hir::Arm { + hir_id, + pat, + guard, + body: self.lower_expr(&arm.body), + span: self.lower_span(arm.span), + } } /// Lower an `async` construct to a generator that is then wrapped so it implements `Future`. @@ -501,12 +519,16 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> hir::ExprKind<'hir> { let output = match ret_ty { Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())), - None => hir::FnRetTy::DefaultReturn(span), + None => hir::FnRetTy::DefaultReturn(self.lower_span(span)), }; // Resume argument type. We let the compiler infer this to simplify the lowering. It is // fully constrained by `future::from_generator`. - let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Infer, span }; + let input_ty = hir::Ty { + hir_id: self.next_id(), + kind: hir::TyKind::Infer, + span: self.lower_span(span), + }; // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`. let decl = self.arena.alloc(hir::FnDecl { @@ -522,7 +544,12 @@ impl<'hir> LoweringContext<'_, 'hir> { Ident::with_dummy_span(sym::_task_context), hir::BindingAnnotation::Mutable, ); - let param = hir::Param { hir_id: self.next_id(), pat, ty_span: span, span }; + let param = hir::Param { + hir_id: self.next_id(), + pat, + ty_span: self.lower_span(span), + span: self.lower_span(span), + }; let params = arena_vec![self; param]; let body_id = self.lower_body(move |this| { @@ -540,11 +567,14 @@ impl<'hir> LoweringContext<'_, 'hir> { capture_clause, decl, body_id, - span, + self.lower_span(span), Some(hir::Movability::Static), ); - let generator = - hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span }; + let generator = hir::Expr { + hir_id: self.lower_node_id(closure_node_id), + kind: generator_kind, + span: self.lower_span(span), + }; // `future::from_generator`: let unstable_span = @@ -681,8 +711,11 @@ impl<'hir> LoweringContext<'_, 'hir> { if let Some(task_context_hid) = self.task_context { let lhs = self.expr_ident(span, task_context_ident, task_context_hid); - let assign = - self.expr(span, hir::ExprKind::Assign(lhs, yield_expr, span), AttrVec::new()); + let assign = self.expr( + span, + hir::ExprKind::Assign(lhs, yield_expr, self.lower_span(span)), + AttrVec::new(), + ); self.stmt_expr(span, assign) } else { // Use of `await` outside of an async context. Return `yield_expr` so that we can @@ -696,8 +729,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // loop { .. } let loop_expr = self.arena.alloc(hir::Expr { hir_id: loop_hir_id, - kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span), - span, + kind: hir::ExprKind::Loop( + loop_block, + None, + hir::LoopSource::Loop, + self.lower_span(span), + ), + span: self.lower_span(span), }); // mut pinned => loop { ... } @@ -735,7 +773,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // Lower outside new scope to preserve `is_in_loop_condition`. let fn_decl = self.lower_fn_decl(decl, None, false, None); - hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, generator_option) + hir::ExprKind::Closure( + capture_clause, + fn_decl, + body_id, + self.lower_span(fn_decl_span), + generator_option, + ) } fn generator_movability_for_fn( @@ -821,7 +865,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // closure argument types. let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None); - hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, None) + hir::ExprKind::Closure( + capture_clause, + fn_decl, + body_id, + self.lower_span(fn_decl_span), + None, + ) } /// Destructure the LHS of complex assignments. @@ -853,7 +903,11 @@ impl<'hir> LoweringContext<'_, 'hir> { } } if is_ordinary(self, lhs) { - return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span); + return hir::ExprKind::Assign( + self.lower_expr(lhs), + self.lower_expr(rhs), + self.lower_span(eq_sign_span), + ); } if !self.sess.features_untracked().destructuring_assignment { feature_err( @@ -878,7 +932,7 @@ impl<'hir> LoweringContext<'_, 'hir> { whole_span, Some(rhs), pat, - hir::LocalSource::AssignDesugar(eq_sign_span), + hir::LocalSource::AssignDesugar(self.lower_span(eq_sign_span)), ); // `a = lhs1; b = lhs2;`. @@ -978,10 +1032,10 @@ impl<'hir> LoweringContext<'_, 'hir> { let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments); hir::PatField { hir_id: self.next_id(), - ident: f.ident, + ident: self.lower_ident(f.ident), pat, is_shorthand: f.is_shorthand, - span: f.span, + span: self.lower_span(f.span), } })); let qpath = self.lower_qpath( @@ -1033,10 +1087,11 @@ impl<'hir> LoweringContext<'_, 'hir> { _ => {} } // Treat all other cases as normal lvalue. - let ident = Ident::new(sym::lhs, lhs.span); + let ident = Ident::new(sym::lhs, self.lower_span(lhs.span)); let (pat, binding) = self.pat_ident_mut(lhs.span, ident); let ident = self.expr_ident(lhs.span, ident, binding); - let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span); + let assign = + hir::ExprKind::Assign(self.lower_expr(lhs), ident, self.lower_span(eq_sign_span)); let expr = self.expr(lhs.span, assign, ThinVec::new()); assignments.push(self.stmt_expr(lhs.span, expr)); pat @@ -1076,7 +1131,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> { let e1 = self.lower_expr_mut(e1); let e2 = self.lower_expr_mut(e2); - let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, span); + let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, self.lower_span(span)); let fn_expr = self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path), ThinVec::new())); hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2]) @@ -1104,12 +1159,21 @@ impl<'hir> LoweringContext<'_, 'hir> { let fields = self.arena.alloc_from_iter( e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| { let expr = self.lower_expr(&e); - let ident = Ident::new(Symbol::intern(s), e.span); + let ident = Ident::new(Symbol::intern(s), self.lower_span(e.span)); self.expr_field(ident, expr, e.span) }), ); - hir::ExprKind::Struct(self.arena.alloc(hir::QPath::LangItem(lang_item, span)), fields, None) + hir::ExprKind::Struct( + self.arena.alloc(hir::QPath::LangItem(lang_item, self.lower_span(span))), + fields, + None, + ) + } + + fn lower_label(&self, opt_label: Option