Skip to content

Commit 8f55d60

Browse files
committed
Auto merge of rust-lang#108286 - matthiaskrgr:rollup-dwy99rf, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#108241 (Fix handling of reexported macro in doc hidden items) - rust-lang#108254 (Refine error span for trait error into borrowed expression) - rust-lang#108255 (Remove old FIXMEs referring to rust-lang#19596) - rust-lang#108257 (Remove old FIXME that no longer applies) - rust-lang#108276 (small `opaque_type_origin` cleanup) - rust-lang#108279 (Use named arguments for `{,u}int_impls` macro) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5243ea5 + 4f532da commit 8f55d60

File tree

15 files changed

+499
-133
lines changed

15 files changed

+499
-133
lines changed

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,6 @@ pub struct Pat<'hir> {
987987
}
988988

989989
impl<'hir> Pat<'hir> {
990-
// FIXME(#19596) this is a workaround, but there should be a better way
991990
fn walk_short_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) -> bool {
992991
if !it(self) {
993992
return false;
@@ -1015,7 +1014,6 @@ impl<'hir> Pat<'hir> {
10151014
self.walk_short_(&mut it)
10161015
}
10171016

1018-
// FIXME(#19596) this is a workaround, but there should be a better way
10191017
fn walk_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) {
10201018
if !it(self) {
10211019
return;

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_session::lint;
3232
use rustc_span::def_id::LocalDefId;
3333
use rustc_span::hygiene::DesugaringKind;
3434
use rustc_span::symbol::{kw, sym, Ident};
35-
use rustc_span::{Span, DUMMY_SP};
35+
use rustc_span::Span;
3636
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
3737
use rustc_trait_selection::traits::{self, NormalizeExt, ObligationCauseCode, ObligationCtxt};
3838

@@ -737,7 +737,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
737737
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
738738
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *ty.kind()
739739
&& let Some(def_id) = def_id.as_local()
740-
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
740+
&& self.opaque_type_origin(def_id).is_some() {
741741
return None;
742742
}
743743
}

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+13
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549549
return Err(expr);
550550
};
551551

552+
if let (
553+
hir::ExprKind::AddrOf(_borrow_kind, _borrow_mutability, borrowed_expr),
554+
ty::Ref(_ty_region, ty_ref_type, _ty_mutability),
555+
) = (&expr.kind, in_ty.kind())
556+
{
557+
// We can "drill into" the borrowed expression.
558+
return self.blame_specific_part_of_expr_corresponding_to_generic_param(
559+
param,
560+
borrowed_expr,
561+
(*ty_ref_type).into(),
562+
);
563+
}
564+
552565
if let (hir::ExprKind::Tup(expr_elements), ty::Tuple(in_ty_elements)) =
553566
(&expr.kind, in_ty.kind())
554567
{

compiler/rustc_hir_typeck/src/mem_categorization.rs

-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
601601
}
602602
}
603603

604-
// FIXME(#19596) This is a workaround, but there should be a better way to do this
605604
fn cat_pattern_<F>(
606605
&self,
607606
mut place_with_id: PlaceWithHirId<'tcx>,

compiler/rustc_infer/src/infer/opaque_types.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ impl<'tcx> InferCtxt<'tcx> {
5757
}
5858
let mut obligations = vec![];
5959
let replace_opaque_type = |def_id: DefId| {
60-
def_id
61-
.as_local()
62-
.map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
60+
def_id.as_local().map_or(false, |def_id| self.opaque_type_origin(def_id).is_some())
6361
};
6462
let value = value.fold_with(&mut BottomUpFolder {
6563
tcx: self.tcx,
@@ -144,9 +142,9 @@ impl<'tcx> InferCtxt<'tcx> {
144142
// let x = || foo(); // returns the Opaque assoc with `foo`
145143
// }
146144
// ```
147-
self.opaque_type_origin(def_id, cause.span)?
145+
self.opaque_type_origin(def_id)?
148146
}
149-
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
147+
DefiningAnchor::Bubble => self.opaque_type_origin_unchecked(def_id),
150148
DefiningAnchor::Error => return None,
151149
};
152150
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
@@ -155,9 +153,8 @@ impl<'tcx> InferCtxt<'tcx> {
155153
// no one encounters it in practice.
156154
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
157155
// where it is of no concern, so we only check for TAITs.
158-
if let Some(OpaqueTyOrigin::TyAlias) = b_def_id
159-
.as_local()
160-
.and_then(|b_def_id| self.opaque_type_origin(b_def_id, cause.span))
156+
if let Some(OpaqueTyOrigin::TyAlias) =
157+
b_def_id.as_local().and_then(|b_def_id| self.opaque_type_origin(b_def_id))
161158
{
162159
self.tcx.sess.emit_err(OpaqueHiddenTypeDiag {
163160
span: cause.span,
@@ -371,24 +368,18 @@ impl<'tcx> InferCtxt<'tcx> {
371368
});
372369
}
373370

371+
/// Returns the origin of the opaque type `def_id` if we're currently
372+
/// in its defining scope.
374373
#[instrument(skip(self), level = "trace", ret)]
375-
pub fn opaque_type_origin(&self, def_id: LocalDefId, span: Span) -> Option<OpaqueTyOrigin> {
374+
pub fn opaque_type_origin(&self, def_id: LocalDefId) -> Option<OpaqueTyOrigin> {
376375
let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
377376
let parent_def_id = match self.defining_use_anchor {
378377
DefiningAnchor::Bubble | DefiningAnchor::Error => return None,
379378
DefiningAnchor::Bind(bind) => bind,
380379
};
381-
let item_kind = &self.tcx.hir().expect_item(def_id).kind;
382-
383-
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else {
384-
span_bug!(
385-
span,
386-
"weird opaque type: {:#?}, {:#?}",
387-
def_id,
388-
item_kind
389-
)
390-
};
391-
let in_definition_scope = match *origin {
380+
381+
let origin = self.opaque_type_origin_unchecked(def_id);
382+
let in_definition_scope = match origin {
392383
// Async `impl Trait`
393384
hir::OpaqueTyOrigin::AsyncFn(parent) => parent == parent_def_id,
394385
// Anonymous `impl Trait`
@@ -398,16 +389,17 @@ impl<'tcx> InferCtxt<'tcx> {
398389
may_define_opaque_type(self.tcx, parent_def_id, opaque_hir_id)
399390
}
400391
};
401-
trace!(?origin);
402-
in_definition_scope.then_some(*origin)
392+
in_definition_scope.then_some(origin)
403393
}
404394

395+
/// Returns the origin of the opaque type `def_id` even if we are not in its
396+
/// defining scope.
405397
#[instrument(skip(self), level = "trace", ret)]
406-
fn opaque_ty_origin_unchecked(&self, def_id: LocalDefId, span: Span) -> OpaqueTyOrigin {
398+
fn opaque_type_origin_unchecked(&self, def_id: LocalDefId) -> OpaqueTyOrigin {
407399
match self.tcx.hir().expect_item(def_id).kind {
408400
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
409401
ref itemkind => {
410-
span_bug!(span, "weird opaque type: {:?}, {:#?}", def_id, itemkind)
402+
bug!("weird opaque type: {:?}, {:#?}", def_id, itemkind)
411403
}
412404
}
413405
}

compiler/rustc_serialize/src/serialize.rs

-5
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ impl<D: Decoder, T: Decodable<D> + Copy> Decodable<D> for Cell<T> {
430430
}
431431
}
432432

433-
// FIXME: #15036
434-
// Should use `try_borrow`, returning an
435-
// `encoder.error("attempting to Encode borrowed RefCell")`
436-
// from `encode` when `try_borrow` returns `None`.
437-
438433
impl<S: Encoder, T: Encodable<S>> Encodable<S> for RefCell<T> {
439434
fn encode(&self, s: &mut S) {
440435
self.borrow().encode(s);

library/core/src/num/int_macros.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
macro_rules! int_impl {
2-
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $BITS_MINUS_ONE:expr, $Min:expr, $Max:expr,
3-
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
4-
$reversed:expr, $le_bytes:expr, $be_bytes:expr,
5-
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr,
6-
$bound_condition:expr) => {
2+
(
3+
Self = $SelfT:ty,
4+
ActualT = $ActualT:ident,
5+
UnsignedT = $UnsignedT:ty,
6+
BITS = $BITS:expr,
7+
BITS_MINUS_ONE = $BITS_MINUS_ONE:expr,
8+
Min = $Min:expr,
9+
Max = $Max:expr,
10+
rot = $rot:expr,
11+
rot_op = $rot_op:expr,
12+
rot_result = $rot_result:expr,
13+
swap_op = $swap_op:expr,
14+
swapped = $swapped:expr,
15+
reversed = $reversed:expr,
16+
le_bytes = $le_bytes:expr,
17+
be_bytes = $be_bytes:expr,
18+
to_xe_bytes_doc = $to_xe_bytes_doc:expr,
19+
from_xe_bytes_doc = $from_xe_bytes_doc:expr,
20+
bound_condition = $bound_condition:expr,
21+
) => {
722
/// The smallest value that can be represented by this integer type
823
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ").")]
924
///

0 commit comments

Comments
 (0)