Skip to content

Commit 09d52bc

Browse files
committed
Auto merge of rust-lang#97873 - Dylan-DPC:rollup-g6ptsdq, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#97276 (Stabilize `const_intrinsic_copy`) - rust-lang#97763 (Allow ptr_from_addr_cast to fail) - rust-lang#97846 (Specify DWARF alignment in bits, not bytes.) - rust-lang#97848 (Impl Traits lowering minor refactors) - rust-lang#97865 (remove `BorrowckMode`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1a97162 + 5d1a366 commit 09d52bc

File tree

19 files changed

+130
-109
lines changed

19 files changed

+130
-109
lines changed

compiler/rustc_ast_lowering/src/item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_span::symbol::{kw, sym, Ident};
1919
use rustc_span::Span;
2020
use rustc_target::spec::abi;
2121
use smallvec::{smallvec, SmallVec};
22-
use tracing::debug;
2322

2423
use std::iter;
2524

@@ -117,6 +116,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
117116
self.owners[def_id]
118117
}
119118

119+
#[instrument(level = "debug", skip(self, c))]
120120
fn lower_crate(&mut self, c: &Crate) {
121121
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);
122122

@@ -127,6 +127,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
127127
})
128128
}
129129

130+
#[instrument(level = "debug", skip(self))]
130131
fn lower_item(&mut self, item: &Item) {
131132
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
132133
}
@@ -485,6 +486,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
485486
(ty, self.lower_const_body(span, body))
486487
}
487488

489+
#[instrument(level = "debug", skip(self))]
488490
fn lower_use_tree(
489491
&mut self,
490492
tree: &UseTree,
@@ -494,8 +496,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
494496
ident: &mut Ident,
495497
attrs: Option<&'hir [Attribute]>,
496498
) -> hir::ItemKind<'hir> {
497-
debug!("lower_use_tree(tree={:?})", tree);
498-
499499
let path = &tree.prefix;
500500
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
501501

@@ -1298,6 +1298,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12981298

12991299
/// Return the pair of the lowered `generics` as `hir::Generics` and the evaluation of `f` with
13001300
/// the carried impl trait definitions and bounds.
1301+
#[instrument(level = "debug", skip(self, f))]
13011302
fn lower_generics<T>(
13021303
&mut self,
13031304
generics: &Generics,

compiler/rustc_ast_lowering/src/lib.rs

+79-46
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#![recursion_limit = "256"]
3838
#![allow(rustc::potential_query_instability)]
3939

40+
#[macro_use]
41+
extern crate tracing;
42+
4043
use rustc_ast::visit;
4144
use rustc_ast::{self as ast, *};
4245
use rustc_ast_pretty::pprust;
@@ -63,7 +66,6 @@ use rustc_span::{Span, DUMMY_SP};
6366

6467
use smallvec::SmallVec;
6568
use std::collections::hash_map::Entry;
66-
use tracing::{debug, trace};
6769

6870
macro_rules! arena_vec {
6971
($this:expr; $($x:expr),*) => (
@@ -439,7 +441,7 @@ pub fn lower_crate<'a, 'hir>(
439441
arena.alloc(krate)
440442
}
441443

442-
#[derive(Copy, Clone, PartialEq)]
444+
#[derive(Copy, Clone, PartialEq, Debug)]
443445
enum ParamMode {
444446
/// Any path in a type context.
445447
Explicit,
@@ -455,6 +457,7 @@ enum ParenthesizedGenericArgs {
455457
}
456458

457459
impl<'a, 'hir> LoweringContext<'a, 'hir> {
460+
#[instrument(level = "debug", skip(self, f))]
458461
fn with_hir_id_owner(
459462
&mut self,
460463
owner: NodeId,
@@ -599,12 +602,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
599602
self.lower_node_id(node_id)
600603
}
601604

605+
#[instrument(level = "trace", skip(self))]
602606
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
603607
let res: Result<Res, ()> = res.apply_id(|id| {
604608
let owner = self.current_hir_id_owner;
605609
let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?;
606610
Ok(hir::HirId { owner, local_id })
607611
});
612+
trace!(?res);
613+
608614
// We may fail to find a HirId when the Res points to a Local from an enclosing HIR owner.
609615
// This can happen when trying to lower the return type `x` in erroneous code like
610616
// async fn foo(x: u8) -> x {}
@@ -851,6 +857,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
851857
/// ```
852858
///
853859
/// returns a `hir::TypeBinding` representing `Item`.
860+
#[instrument(level = "debug", skip(self))]
854861
fn lower_assoc_ty_constraint(
855862
&mut self,
856863
constraint: &AssocConstraint,
@@ -1011,6 +1018,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10111018
err.emit();
10121019
}
10131020

1021+
#[instrument(level = "debug", skip(self))]
10141022
fn lower_generic_arg(
10151023
&mut self,
10161024
arg: &ast::GenericArg,
@@ -1081,6 +1089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10811089
}
10821090
}
10831091

1092+
#[instrument(level = "debug", skip(self))]
10841093
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
10851094
self.arena.alloc(self.lower_ty_direct(t, itctx))
10861095
}
@@ -1212,41 +1221,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12121221
)
12131222
}
12141223
ImplTraitContext::Universal => {
1215-
// Add a definition for the in-band `Param`.
1216-
let def_id = self.resolver.local_def_id(def_node_id);
1217-
1218-
let hir_bounds =
1219-
self.lower_param_bounds(bounds, ImplTraitContext::Universal);
1220-
// Set the name to `impl Bound1 + Bound2`.
1224+
let span = t.span;
12211225
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
1222-
let param = hir::GenericParam {
1223-
hir_id: self.lower_node_id(def_node_id),
1224-
name: ParamName::Plain(self.lower_ident(ident)),
1225-
pure_wrt_drop: false,
1226-
span: self.lower_span(span),
1227-
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
1228-
colon_span: None,
1229-
};
1226+
let (param, bounds, path) =
1227+
self.lower_generic_and_bounds(def_node_id, span, ident, bounds);
12301228
self.impl_trait_defs.push(param);
1231-
1232-
if let Some(preds) = self.lower_generic_bound_predicate(
1233-
ident,
1234-
def_node_id,
1235-
&GenericParamKind::Type { default: None },
1236-
hir_bounds,
1237-
hir::PredicateOrigin::ImplTrait,
1238-
) {
1239-
self.impl_trait_bounds.push(preds)
1229+
if let Some(bounds) = bounds {
1230+
self.impl_trait_bounds.push(bounds);
12401231
}
1241-
1242-
hir::TyKind::Path(hir::QPath::Resolved(
1243-
None,
1244-
self.arena.alloc(hir::Path {
1245-
span: self.lower_span(span),
1246-
res: Res::Def(DefKind::TyParam, def_id.to_def_id()),
1247-
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident))],
1248-
}),
1249-
))
1232+
path
12501233
}
12511234
ImplTraitContext::Disallowed(position) => {
12521235
let mut err = struct_span_err!(
@@ -1737,6 +1720,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17371720
)
17381721
}
17391722

1723+
#[instrument(level = "trace", skip(self))]
17401724
fn lower_param_bound(
17411725
&mut self,
17421726
tpb: &GenericBound,
@@ -1862,8 +1846,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18621846
self.arena.alloc_from_iter(self.lower_generic_params_mut(params))
18631847
}
18641848

1849+
#[instrument(level = "trace", skip(self))]
18651850
fn lower_generic_param(&mut self, param: &GenericParam) -> hir::GenericParam<'hir> {
1866-
let (name, kind) = match param.kind {
1851+
let (name, kind) = self.lower_generic_param_kind(param);
1852+
1853+
let hir_id = self.lower_node_id(param.id);
1854+
self.lower_attrs(hir_id, &param.attrs);
1855+
hir::GenericParam {
1856+
hir_id,
1857+
name,
1858+
span: self.lower_span(param.span()),
1859+
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
1860+
kind,
1861+
colon_span: param.colon_span.map(|s| self.lower_span(s)),
1862+
}
1863+
}
1864+
1865+
fn lower_generic_param_kind(
1866+
&mut self,
1867+
param: &GenericParam,
1868+
) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
1869+
match param.kind {
18671870
GenericParamKind::Lifetime => {
18681871
// AST resolution emitted an error on those parameters, so we lower them using
18691872
// `ParamName::Error`.
@@ -1897,17 +1900,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18971900
hir::GenericParamKind::Const { ty, default },
18981901
)
18991902
}
1900-
};
1901-
1902-
let hir_id = self.lower_node_id(param.id);
1903-
self.lower_attrs(hir_id, &param.attrs);
1904-
hir::GenericParam {
1905-
hir_id,
1906-
name,
1907-
span: self.lower_span(param.span()),
1908-
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
1909-
kind,
1910-
colon_span: param.colon_span.map(|s| self.lower_span(s)),
19111903
}
19121904
}
19131905

@@ -1954,6 +1946,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19541946
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
19551947
}
19561948

1949+
fn lower_generic_and_bounds(
1950+
&mut self,
1951+
node_id: NodeId,
1952+
span: Span,
1953+
ident: Ident,
1954+
bounds: &[GenericBound],
1955+
) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
1956+
// Add a definition for the in-band `Param`.
1957+
let def_id = self.resolver.local_def_id(node_id);
1958+
1959+
let hir_bounds = self.lower_param_bounds(bounds, ImplTraitContext::Universal);
1960+
// Set the name to `impl Bound1 + Bound2`.
1961+
let param = hir::GenericParam {
1962+
hir_id: self.lower_node_id(node_id),
1963+
name: ParamName::Plain(self.lower_ident(ident)),
1964+
pure_wrt_drop: false,
1965+
span: self.lower_span(span),
1966+
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
1967+
colon_span: None,
1968+
};
1969+
1970+
let preds = self.lower_generic_bound_predicate(
1971+
ident,
1972+
node_id,
1973+
&GenericParamKind::Type { default: None },
1974+
hir_bounds,
1975+
hir::PredicateOrigin::ImplTrait,
1976+
);
1977+
1978+
let ty = hir::TyKind::Path(hir::QPath::Resolved(
1979+
None,
1980+
self.arena.alloc(hir::Path {
1981+
span: self.lower_span(span),
1982+
res: Res::Def(DefKind::TyParam, def_id.to_def_id()),
1983+
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident))],
1984+
}),
1985+
));
1986+
1987+
(param, preds, ty)
1988+
}
1989+
19571990
/// Lowers a block directly to an expression, presuming that it
19581991
/// has no attributes and is not targeted by a `break`.
19591992
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use smallvec::smallvec;
1515
use tracing::debug;
1616

1717
impl<'a, 'hir> LoweringContext<'a, 'hir> {
18+
#[instrument(level = "trace", skip(self))]
1819
pub(crate) fn lower_qpath(
1920
&mut self,
2021
id: NodeId,
@@ -23,7 +24,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2324
param_mode: ParamMode,
2425
itctx: ImplTraitContext,
2526
) -> hir::QPath<'hir> {
26-
debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p);
2727
let qself_position = qself.as_ref().map(|q| q.position);
2828
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
2929

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, glo
13651365
is_local_to_unit,
13661366
global,
13671367
None,
1368-
global_align.bytes() as u32,
1368+
global_align.bits() as u32,
13691369
);
13701370
}
13711371
}

compiler/rustc_const_eval/src/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
221221
let addr = addr.to_machine_usize(self)?;
222222

223223
// Then turn address into pointer.
224-
let ptr = M::ptr_from_addr_cast(&self, addr);
224+
let ptr = M::ptr_from_addr_cast(&self, addr)?;
225225
Ok(Scalar::from_maybe_pointer(ptr, self).into())
226226
}
227227

compiler/rustc_const_eval/src/interpret/machine.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
294294
fn ptr_from_addr_cast(
295295
ecx: &InterpCx<'mir, 'tcx, Self>,
296296
addr: u64,
297-
) -> Pointer<Option<Self::PointerTag>>;
297+
) -> InterpResult<'tcx, Pointer<Option<Self::PointerTag>>>;
298298

299-
// FIXME: Transmuting an integer to a pointer should just always return a `None`
300-
// provenance, but that causes problems with function pointers in Miri.
301299
/// Hook for returning a pointer from a transmute-like operation on an addr.
300+
/// This is only needed to support Miri's (unsound) "allow-ptr-int-transmute" flag.
302301
fn ptr_from_addr_transmute(
303302
ecx: &InterpCx<'mir, 'tcx, Self>,
304303
addr: u64,
@@ -519,8 +518,10 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
519518
fn ptr_from_addr_cast(
520519
_ecx: &InterpCx<$mir, $tcx, Self>,
521520
addr: u64,
522-
) -> Pointer<Option<AllocId>> {
523-
Pointer::new(None, Size::from_bytes(addr))
521+
) -> InterpResult<$tcx, Pointer<Option<AllocId>>> {
522+
// Allow these casts, but make the pointer not dereferenceable.
523+
// (I.e., they behave like transmutation.)
524+
Ok(Pointer::new(None, Size::from_bytes(addr)))
524525
}
525526

526527
#[inline(always)]

compiler/rustc_session/src/config.rs

-17
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,6 @@ pub enum PrintRequest {
547547
LinkArgs,
548548
}
549549

550-
#[derive(Copy, Clone)]
551-
pub enum BorrowckMode {
552-
Mir,
553-
Migrate,
554-
}
555-
556-
impl BorrowckMode {
557-
/// Returns whether we should run the MIR-based borrow check, but also fall back
558-
/// on the AST borrow check if the MIR-based one errors.
559-
pub fn migrate(self) -> bool {
560-
match self {
561-
BorrowckMode::Mir => false,
562-
BorrowckMode::Migrate => true,
563-
}
564-
}
565-
}
566-
567550
pub enum Input {
568551
/// Load source code from a file.
569552
File(PathBuf),

0 commit comments

Comments
 (0)