Skip to content

Commit 89b9f7b

Browse files
committed
Auto merge of #92719 - matthiaskrgr:rollup-tc7oqys, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #92248 (Normalize struct tail type when checking Pointee trait) - #92357 (Fix invalid removal of newlines from doc comments) - #92602 (Make source links look cleaner) - #92636 (Normalize generator-local types with unevaluated constants) - #92693 (Release notes: add `Result::unwrap_{,err_}unchecked`) - #92702 (Clean up lang_items::extract) - #92717 (update miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents df035a3 + 3d5db0e commit 89b9f7b

37 files changed

+215
-130
lines changed

RELEASES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Stabilized APIs
4141
- [`Path::is_symlink`]
4242
- [`{integer}::saturating_div`]
4343
- [`Option::unwrap_unchecked`]
44+
- [`Result::unwrap_unchecked`]
45+
- [`Result::unwrap_err_unchecked`]
4446
- [`NonZero{unsigned}::is_power_of_two`]
4547

4648
These APIs are now usable in const contexts:
@@ -136,6 +138,8 @@ and related tools.
136138
[`Path::is_symlink`]: https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.is_symlink
137139
[`{integer}::saturating_div`]: https://doc.rust-lang.org/stable/std/primitive.i8.html#method.saturating_div
138140
[`Option::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.unwrap_unchecked
141+
[`Result::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_unchecked
142+
[`Result::unwrap_err_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_err_unchecked
139143
[`NonZero{unsigned}::is_power_of_two`]: https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html#method.is_power_of_two
140144
[`unix::process::ExitStatusExt::core_dumped`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.core_dumped
141145
[`unix::process::ExitStatusExt::stopped_signal`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal

compiler/rustc_ast/src/util/comments.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,11 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
3434
i += 1;
3535
}
3636

37-
while i < j && lines[i].trim().is_empty() {
38-
i += 1;
39-
}
4037
// like the first, a last line of all stars should be omitted
4138
if j > i && !lines[j - 1].is_empty() && lines[j - 1].chars().all(|c| c == '*') {
4239
j -= 1;
4340
}
4441

45-
while j > i && lines[j - 1].trim().is_empty() {
46-
j -= 1;
47-
}
48-
4942
if i != 0 || j != lines.len() { Some((i, j)) } else { None }
5043
}
5144

compiler/rustc_hir/src/lang_items.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,12 @@ impl<CTX> HashStable<CTX> for LangItem {
151151
/// Extracts the first `lang = "$name"` out of a list of attributes.
152152
/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
153153
/// are also extracted out when found.
154-
///
155-
/// About the `check_name` argument: passing in a `Session` would be simpler,
156-
/// because then we could call `Session::check_name` directly. But we want to
157-
/// avoid the need for `rustc_hir` to depend on `rustc_session`, so we
158-
/// use a closure instead.
159-
pub fn extract<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<(Symbol, Span)>
160-
where
161-
F: Fn(&'a ast::Attribute, Symbol) -> bool,
162-
{
154+
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
163155
attrs.iter().find_map(|attr| {
164156
Some(match attr {
165-
_ if check_name(attr, sym::lang) => (attr.value_str()?, attr.span),
166-
_ if check_name(attr, sym::panic_handler) => (sym::panic_impl, attr.span),
167-
_ if check_name(attr, sym::alloc_error_handler) => (sym::oom, attr.span),
157+
_ if attr.has_name(sym::lang) => (attr.value_str()?, attr.span),
158+
_ if attr.has_name(sym::panic_handler) => (sym::panic_impl, attr.span),
159+
_ if attr.has_name(sym::alloc_error_handler) => (sym::oom, attr.span),
168160
_ => return None,
169161
})
170162
})

compiler/rustc_hir/src/weak_lang_items.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::ne
1818
map
1919
});
2020

21-
/// The `check_name` argument avoids the need for `rustc_hir` to depend on
22-
/// `rustc_session`.
23-
pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
24-
where
25-
F: Fn(&'a ast::Attribute, Symbol) -> bool
21+
pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol>
2622
{
27-
lang_items::extract(check_name, attrs).and_then(|(name, _)| {
23+
lang_items::extract(attrs).and_then(|(name, _)| {
2824
$(if name == sym::$name {
2925
Some(sym::$sym)
3026
} else)* {

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,9 +2143,12 @@ impl<'tcx> TyS<'tcx> {
21432143
}
21442144

21452145
/// Returns the type of metadata for (potentially fat) pointers to this type.
2146-
pub fn ptr_metadata_ty(&'tcx self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
2147-
// FIXME: should this normalize?
2148-
let tail = tcx.struct_tail_without_normalization(self);
2146+
pub fn ptr_metadata_ty(
2147+
&'tcx self,
2148+
tcx: TyCtxt<'tcx>,
2149+
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
2150+
) -> Ty<'tcx> {
2151+
let tail = tcx.struct_tail_with_normalize(self, normalize);
21492152
match tail.kind() {
21502153
// Sized types
21512154
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx> TyCtxt<'tcx> {
192192
pub fn struct_tail_with_normalize(
193193
self,
194194
mut ty: Ty<'tcx>,
195-
normalize: impl Fn(Ty<'tcx>) -> Ty<'tcx>,
195+
mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
196196
) -> Ty<'tcx> {
197197
let recursion_limit = self.recursion_limit();
198198
for iteration in 0.. {

compiler/rustc_mir_transform/src/generator.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,13 @@ fn sanitize_witness<'tcx>(
726726
saved_locals: &GeneratorSavedLocals,
727727
) {
728728
let did = body.source.def_id();
729-
let allowed_upvars = tcx.erase_regions(upvars);
729+
let param_env = tcx.param_env(did);
730+
731+
let allowed_upvars = tcx.normalize_erasing_regions(param_env, upvars);
730732
let allowed = match witness.kind() {
731-
&ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s),
733+
&ty::GeneratorWitness(interior_tys) => {
734+
tcx.normalize_erasing_late_bound_regions(param_env, interior_tys)
735+
}
732736
_ => {
733737
tcx.sess.delay_span_bug(
734738
body.span,
@@ -738,8 +742,6 @@ fn sanitize_witness<'tcx>(
738742
}
739743
};
740744

741-
let param_env = tcx.param_env(did);
742-
743745
for (local, decl) in body.local_decls.iter_enumerated() {
744746
// Ignore locals which are internal or not saved between yields.
745747
if !saved_locals.contains(local) || decl.internal {

compiler/rustc_passes/src/lang_items.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use crate::check_attr::target_from_impl_item;
1111
use crate::weak_lang_items;
1212

13-
use rustc_ast::Attribute;
1413
use rustc_errors::{pluralize, struct_span_err};
1514
use rustc_hir as hir;
1615
use rustc_hir::def_id::DefId;
@@ -57,8 +56,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
5756

5857
fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
5958
let attrs = self.tcx.hir().attrs(hir_id);
60-
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
61-
if let Some((value, span)) = extract(check_name, &attrs) {
59+
if let Some((value, span)) = extract(&attrs) {
6260
match ITEM_REFS.get(&value).cloned() {
6361
// Known lang item with attribute on correct target.
6462
Some((item_index, expected_target)) if actual_target == expected_target => {

compiler/rustc_passes/src/weak_lang_items.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Validity checking for weak lang items
22
3-
use rustc_ast::Attribute;
43
use rustc_data_structures::fx::FxHashSet;
54
use rustc_errors::struct_span_err;
65
use rustc_hir as hir;
@@ -103,9 +102,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
103102
}
104103

105104
fn visit_foreign_item(&mut self, i: &hir::ForeignItem<'_>) {
106-
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
107105
let attrs = self.tcx.hir().attrs(i.hir_id());
108-
if let Some((lang_item, _)) = lang_items::extract(check_name, attrs) {
106+
if let Some((lang_item, _)) = lang_items::extract(attrs) {
109107
self.register(lang_item, i.span);
110108
}
111109
intravisit::walk_foreign_item(self, i)

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,17 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14001400
// Any type with multiple potential metadata types is therefore not eligible.
14011401
let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty());
14021402

1403-
// FIXME: should this normalize?
1404-
let tail = selcx.tcx().struct_tail_without_normalization(self_ty);
1403+
let tail = selcx.tcx().struct_tail_with_normalize(self_ty, |ty| {
1404+
normalize_with_depth(
1405+
selcx,
1406+
obligation.param_env,
1407+
obligation.cause.clone(),
1408+
obligation.recursion_depth + 1,
1409+
ty,
1410+
)
1411+
.value
1412+
});
1413+
14051414
match tail.kind() {
14061415
ty::Bool
14071416
| ty::Char
@@ -1435,7 +1444,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14351444
| ty::Bound(..)
14361445
| ty::Placeholder(..)
14371446
| ty::Infer(..)
1438-
| ty::Error(_) => false,
1447+
| ty::Error(_) => {
1448+
if tail.has_infer_types() {
1449+
candidate_set.mark_ambiguous();
1450+
}
1451+
false
1452+
},
14391453
}
14401454
}
14411455
super::ImplSource::Param(..) => {
@@ -1640,18 +1654,30 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
16401654
_: ImplSourcePointeeData,
16411655
) -> Progress<'tcx> {
16421656
let tcx = selcx.tcx();
1643-
16441657
let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty());
1645-
let substs = tcx.mk_substs([self_ty.into()].iter());
16461658

1659+
let mut obligations = vec![];
1660+
let metadata_ty = self_ty.ptr_metadata_ty(tcx, |ty| {
1661+
normalize_with_depth_to(
1662+
selcx,
1663+
obligation.param_env,
1664+
obligation.cause.clone(),
1665+
obligation.recursion_depth + 1,
1666+
ty,
1667+
&mut obligations,
1668+
)
1669+
});
1670+
1671+
let substs = tcx.mk_substs([self_ty.into()].iter());
16471672
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
16481673

16491674
let predicate = ty::ProjectionPredicate {
16501675
projection_ty: ty::ProjectionTy { substs, item_def_id: metadata_def_id },
1651-
ty: self_ty.ptr_metadata_ty(tcx),
1676+
ty: metadata_ty,
16521677
};
16531678

16541679
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
1680+
.with_addl_obligations(obligations)
16551681
}
16561682

16571683
fn confirm_fn_pointer_candidate<'cx, 'tcx>(

0 commit comments

Comments
 (0)