Skip to content

Commit a09c668

Browse files
committed
Auto merge of rust-lang#98359 - JohnTitor:rollup-v30vyzr, r=JohnTitor
Rollup of 6 pull requests Successful merges: - rust-lang#97867 (lub: don't bail out due to empty binders) - rust-lang#98099 (interpret: convert_tag_add_extra: allow tagger to raise errors) - rust-lang#98199 (Move some tests to more reasonable directories) - rust-lang#98334 (Add a full regression test for rust-lang#73727) - rust-lang#98336 (Remove the unused-`#[doc(hidden)]` logic from the `unused_attributes` lint) - rust-lang#98344 (This comment is out dated and misleading, the arm is about TAITs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dc80ca7 + cb3322a commit a09c668

File tree

58 files changed

+248
-291
lines changed

Some content is hidden

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

58 files changed

+248
-291
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,14 @@ pub trait Machine<'mir, 'tcx>: Sized {
334334
/// allocation (because a copy had to be done to add tags or metadata), machine memory will
335335
/// cache the result. (This relies on `AllocMap::get_or` being able to add the
336336
/// owned allocation to the map even when the map is shared.)
337+
///
338+
/// This must only fail if `alloc` contains relocations.
337339
fn init_allocation_extra<'b>(
338340
ecx: &InterpCx<'mir, 'tcx, Self>,
339341
id: AllocId,
340342
alloc: Cow<'b, Allocation>,
341343
kind: Option<MemoryKind<Self::MemoryKind>>,
342-
) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>;
344+
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>>;
343345

344346
/// Hook for performing extra checks on a memory read access.
345347
///
@@ -485,9 +487,9 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
485487
_id: AllocId,
486488
alloc: Cow<'b, Allocation>,
487489
_kind: Option<MemoryKind<Self::MemoryKind>>,
488-
) -> Cow<'b, Allocation<Self::PointerTag>> {
490+
) -> InterpResult<$tcx, Cow<'b, Allocation<Self::PointerTag>>> {
489491
// We do not use a tag so we can just cheaply forward the allocation
490-
alloc
492+
Ok(alloc)
491493
}
492494

493495
fn extern_static_base_pointer(

compiler/rustc_const_eval/src/interpret/memory.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
199199
kind: MemoryKind<M::MemoryKind>,
200200
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
201201
let alloc = Allocation::uninit(size, align, M::PANIC_ON_ALLOC_FAIL)?;
202-
Ok(self.allocate_raw_ptr(alloc, kind))
202+
// We can `unwrap` since `alloc` contains no pointers.
203+
Ok(self.allocate_raw_ptr(alloc, kind).unwrap())
203204
}
204205

205206
pub fn allocate_bytes_ptr(
@@ -210,23 +211,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
210211
mutability: Mutability,
211212
) -> Pointer<M::PointerTag> {
212213
let alloc = Allocation::from_bytes(bytes, align, mutability);
213-
self.allocate_raw_ptr(alloc, kind)
214+
// We can `unwrap` since `alloc` contains no pointers.
215+
self.allocate_raw_ptr(alloc, kind).unwrap()
214216
}
215217

218+
/// This can fail only of `alloc` contains relocations.
216219
pub fn allocate_raw_ptr(
217220
&mut self,
218221
alloc: Allocation,
219222
kind: MemoryKind<M::MemoryKind>,
220-
) -> Pointer<M::PointerTag> {
223+
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
221224
let id = self.tcx.reserve_alloc_id();
222225
debug_assert_ne!(
223226
Some(kind),
224227
M::GLOBAL_KIND.map(MemoryKind::Machine),
225228
"dynamically allocating global memory"
226229
);
227-
let alloc = M::init_allocation_extra(self, id, Cow::Owned(alloc), Some(kind));
230+
let alloc = M::init_allocation_extra(self, id, Cow::Owned(alloc), Some(kind))?;
228231
self.memory.alloc_map.insert(id, (kind, alloc.into_owned()));
229-
M::tag_alloc_base_pointer(self, Pointer::from(id))
232+
Ok(M::tag_alloc_base_pointer(self, Pointer::from(id)))
230233
}
231234

232235
pub fn reallocate_ptr(
@@ -510,13 +513,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
510513
};
511514
M::before_access_global(*self.tcx, &self.machine, id, alloc, def_id, is_write)?;
512515
// We got tcx memory. Let the machine initialize its "extra" stuff.
513-
let alloc = M::init_allocation_extra(
516+
M::init_allocation_extra(
514517
self,
515518
id, // always use the ID we got as input, not the "hidden" one.
516519
Cow::Borrowed(alloc.inner()),
517520
M::GLOBAL_KIND.map(MemoryKind::Machine),
518-
);
519-
Ok(alloc)
521+
)
520522
}
521523

522524
/// Gives raw access to the `Allocation`, without bounds or alignment checks.

compiler/rustc_infer/src/infer/glb.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
9595
T: Relate<'tcx>,
9696
{
9797
debug!("binders(a={:?}, b={:?})", a, b);
98-
99-
// When higher-ranked types are involved, computing the LUB is
100-
// very challenging, switch to invariance. This is obviously
101-
// overly conservative but works ok in practice.
102-
self.relate_with_variance(ty::Variance::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
103-
Ok(a)
98+
if a.skip_binder().has_escaping_bound_vars() || b.skip_binder().has_escaping_bound_vars() {
99+
// When higher-ranked types are involved, computing the GLB is
100+
// very challenging, switch to invariance. This is obviously
101+
// overly conservative but works ok in practice.
102+
self.relate_with_variance(
103+
ty::Variance::Invariant,
104+
ty::VarianceDiagInfo::default(),
105+
a,
106+
b,
107+
)?;
108+
Ok(a)
109+
} else {
110+
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))
111+
}
104112
}
105113
}
106114

compiler/rustc_infer/src/infer/lub.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
9595
T: Relate<'tcx>,
9696
{
9797
debug!("binders(a={:?}, b={:?})", a, b);
98-
99-
// When higher-ranked types are involved, computing the LUB is
100-
// very challenging, switch to invariance. This is obviously
101-
// overly conservative but works ok in practice.
102-
self.relate_with_variance(ty::Variance::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
103-
Ok(a)
98+
if a.skip_binder().has_escaping_bound_vars() || b.skip_binder().has_escaping_bound_vars() {
99+
// When higher-ranked types are involved, computing the LUB is
100+
// very challenging, switch to invariance. This is obviously
101+
// overly conservative but works ok in practice.
102+
self.relate_with_variance(
103+
ty::Variance::Invariant,
104+
ty::VarianceDiagInfo::default(),
105+
a,
106+
b,
107+
)?;
108+
Ok(a)
109+
} else {
110+
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))
111+
}
104112
}
105113
}
106114

compiler/rustc_middle/src/mir/interpret/allocation.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ impl<Tag> Allocation<Tag> {
244244

245245
impl Allocation {
246246
/// Convert Tag and add Extra fields
247-
pub fn convert_tag_add_extra<Tag, Extra>(
247+
pub fn convert_tag_add_extra<Tag, Extra, Err>(
248248
self,
249249
cx: &impl HasDataLayout,
250250
extra: Extra,
251-
mut tagger: impl FnMut(Pointer<AllocId>) -> Pointer<Tag>,
252-
) -> Allocation<Tag, Extra> {
251+
mut tagger: impl FnMut(Pointer<AllocId>) -> Result<Pointer<Tag>, Err>,
252+
) -> Result<Allocation<Tag, Extra>, Err> {
253253
// Compute new pointer tags, which also adjusts the bytes.
254254
let mut bytes = self.bytes;
255255
let mut new_relocations = Vec::with_capacity(self.relocations.0.len());
@@ -260,19 +260,19 @@ impl Allocation {
260260
let ptr_bytes = &mut bytes[idx..idx + ptr_size];
261261
let bits = read_target_uint(endian, ptr_bytes).unwrap();
262262
let (ptr_tag, ptr_offset) =
263-
tagger(Pointer::new(alloc_id, Size::from_bytes(bits))).into_parts();
263+
tagger(Pointer::new(alloc_id, Size::from_bytes(bits)))?.into_parts();
264264
write_target_uint(endian, ptr_bytes, ptr_offset.bytes().into()).unwrap();
265265
new_relocations.push((offset, ptr_tag));
266266
}
267267
// Create allocation.
268-
Allocation {
268+
Ok(Allocation {
269269
bytes,
270270
relocations: Relocations::from_presorted(new_relocations),
271271
init_mask: self.init_mask,
272272
align: self.align,
273273
mutability: self.mutability,
274274
extra,
275-
}
275+
})
276276
}
277277
}
278278

compiler/rustc_passes/src/check_attr.rs

+2-74
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use rustc_ast::tokenstream::DelimSpan;
8-
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MacArgs, MetaItemKind, NestedMetaItem};
7+
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
98
use rustc_data_structures::fx::FxHashMap;
109
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
1110
use rustc_expand::base::resolve_path;
@@ -899,68 +898,6 @@ impl CheckAttrVisitor<'_> {
899898
}
900899
}
901900

902-
/// Checks `#[doc(hidden)]` attributes. Returns `true` if valid.
903-
fn check_doc_hidden(
904-
&self,
905-
attr: &Attribute,
906-
meta_index: usize,
907-
meta: &NestedMetaItem,
908-
hir_id: HirId,
909-
target: Target,
910-
) -> bool {
911-
if let Target::AssocConst
912-
| Target::AssocTy
913-
| Target::Method(MethodKind::Trait { body: true }) = target
914-
{
915-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
916-
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
917-
918-
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = containing_item.kind {
919-
let meta_items = attr.meta_item_list().unwrap();
920-
921-
let (span, replacement_span) = if meta_items.len() == 1 {
922-
(attr.span, attr.span)
923-
} else {
924-
let meta_span = meta.span();
925-
(
926-
meta_span,
927-
meta_span.until(match meta_items.get(meta_index + 1) {
928-
Some(next_item) => next_item.span(),
929-
None => match attr.get_normal_item().args {
930-
MacArgs::Delimited(DelimSpan { close, .. }, ..) => close,
931-
_ => unreachable!(),
932-
},
933-
}),
934-
)
935-
};
936-
937-
// FIXME: #[doc(hidden)] was previously erroneously allowed on trait impl items,
938-
// so for backward compatibility only emit a warning and do not mark it as invalid.
939-
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, span, |lint| {
940-
lint.build("`#[doc(hidden)]` is ignored on trait impl items")
941-
.warn(
942-
"this was previously accepted by the compiler but is \
943-
being phased out; it will become a hard error in \
944-
a future release!",
945-
)
946-
.note(
947-
"whether the impl item is `doc(hidden)` or not \
948-
entirely depends on the corresponding trait item",
949-
)
950-
.span_suggestion(
951-
replacement_span,
952-
"remove this attribute",
953-
"",
954-
Applicability::MachineApplicable,
955-
)
956-
.emit();
957-
});
958-
}
959-
}
960-
961-
true
962-
}
963-
964901
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
965902
fn check_attr_not_crate_level(
966903
&self,
@@ -1079,7 +1016,7 @@ impl CheckAttrVisitor<'_> {
10791016
let mut is_valid = true;
10801017

10811018
if let Some(mi) = attr.meta() && let Some(list) = mi.meta_item_list() {
1082-
for (meta_index, meta) in list.into_iter().enumerate() {
1019+
for meta in list {
10831020
if let Some(i_meta) = meta.meta_item() {
10841021
match i_meta.name_or_empty() {
10851022
sym::alias
@@ -1127,15 +1064,6 @@ impl CheckAttrVisitor<'_> {
11271064
is_valid = false;
11281065
}
11291066

1130-
sym::hidden if !self.check_doc_hidden(attr,
1131-
meta_index,
1132-
meta,
1133-
hir_id,
1134-
target,
1135-
) => {
1136-
is_valid = false;
1137-
}
1138-
11391067
// no_default_passes: deprecated
11401068
// passes: deprecated
11411069
// plugins: removed, but rustdoc warns about it itself

compiler/rustc_resolve/src/late/lifetimes.rs

-3
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
846846
// the opaque_ty generics
847847
let opaque_ty = self.tcx.hir().item(item_id);
848848
let (generics, bounds) = match opaque_ty.kind {
849-
// Named opaque `impl Trait` types are reached via `TyKind::Path`.
850-
// This arm is for `impl Trait` in the types of statics, constants and locals.
851849
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
852850
origin: hir::OpaqueTyOrigin::TyAlias,
853851
..
@@ -866,7 +864,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
866864

867865
return;
868866
}
869-
// RPIT (return position impl trait)
870867
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
871868
origin: hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..),
872869
ref generics,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr src/test/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `&'static [u32]` is forbidden as the type of a const generic parameter
2-
--> $DIR/static-reference-array-const-param.rs:1:15
2+
--> $DIR/issue-73727-static-reference-array-const-param.rs:9:15
33
|
44
LL | fn a<const X: &'static [u32]>() {}
55
| ^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #73727
2+
3+
// revisions: full min
4+
//[full]check-pass
5+
6+
#![cfg_attr(full, feature(adt_const_params))]
7+
#![cfg_attr(full, allow(incomplete_features))]
8+
9+
fn a<const X: &'static [u32]>() {}
10+
//[min]~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter
11+
12+
fn main() {
13+
a::<{&[]}>();
14+
}

src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.rs

-6
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/ui/lint/unused/unused-attr-doc-hidden.fixed

-55
This file was deleted.

0 commit comments

Comments
 (0)