Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 89b9f7b

Browse files
committedJan 10, 2022
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

+4
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

-7
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

+4-12
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

+2-6
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

+6-3
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

+1-1
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

+6-4
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

+1-3
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

+1-3
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

+32-6
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>(

‎compiler/rustc_typeck/src/collect.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::constrained_generic_params as cgp;
2121
use crate::errors;
2222
use crate::middle::resolve_lifetime as rl;
2323
use rustc_ast as ast;
24-
use rustc_ast::Attribute;
2524
use rustc_ast::{MetaItemKind, NestedMetaItem};
2625
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
2726
use rustc_data_structures::captures::Captures;
@@ -3120,8 +3119,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
31203119
if tcx.is_weak_lang_item(id) {
31213120
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
31223121
}
3123-
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
3124-
if let Some(name) = weak_lang_items::link_name(check_name, attrs) {
3122+
if let Some(name) = weak_lang_items::link_name(attrs) {
31253123
codegen_fn_attrs.export_name = Some(name);
31263124
codegen_fn_attrs.link_name = Some(name);
31273125
}

‎library/std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
//! development you may want to press the `[-]` button near the top of the
3636
//! page to collapse it into a more skimmable view.
3737
//!
38-
//! While you are looking at that `[-]` button also notice the `[src]`
39-
//! button. Rust's API documentation comes with the source code and you are
38+
//! While you are looking at that `[-]` button also notice the `source`
39+
//! link. Rust's API documentation comes with the source code and you are
4040
//! encouraged to read it. The standard library source is generally high
4141
//! quality and a peek behind the curtains is often enlightening.
4242
//!

‎src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ crate struct Context<'tcx> {
6565
///
6666
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
6767
crate shared: Rc<SharedContext<'tcx>>,
68-
/// This flag indicates whether `[src]` links should be generated or not. If
68+
/// This flag indicates whether source links should be generated or not. If
6969
/// the source files are present in the html rendering, then this will be
7070
/// `true`.
7171
crate include_sources: bool,

‎src/librustdoc/html/render/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl StylePath {
182182

183183
fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
184184
if let Some(l) = cx.src_href(item) {
185-
write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">[src]</a>", l)
185+
write!(buf, "<a class=\"srclink\" href=\"{}\" title=\"goto source code\">source</a>", l)
186186
}
187187
}
188188

@@ -799,7 +799,7 @@ fn render_stability_since_raw(
799799
const_stability: Option<ConstStability>,
800800
containing_ver: Option<Symbol>,
801801
containing_const_ver: Option<Symbol>,
802-
) {
802+
) -> bool {
803803
let ver = ver.filter(|inner| !inner.is_empty());
804804

805805
match (ver, const_stability) {
@@ -842,8 +842,9 @@ fn render_stability_since_raw(
842842
v
843843
);
844844
}
845-
_ => {}
845+
_ => return false,
846846
}
847+
true
847848
}
848849

849850
fn render_assoc_item(
@@ -1632,7 +1633,7 @@ fn render_impl(
16321633
}
16331634

16341635
// Render the items that appear on the right side of methods, impls, and
1635-
// associated types. For example "1.0.0 (const: 1.39.0) [src]".
1636+
// associated types. For example "1.0.0 (const: 1.39.0) · source".
16361637
fn render_rightside(
16371638
w: &mut Buffer,
16381639
cx: &Context<'_>,
@@ -1650,13 +1651,16 @@ fn render_rightside(
16501651
};
16511652

16521653
write!(w, "<div class=\"rightside\">");
1653-
render_stability_since_raw(
1654+
let has_stability = render_stability_since_raw(
16541655
w,
16551656
item.stable_since(tcx),
16561657
const_stability,
16571658
containing_item.stable_since(tcx),
16581659
const_stable_since,
16591660
);
1661+
if has_stability {
1662+
w.write_str(" · ");
1663+
}
16601664

16611665
write_srclink(cx, item, w);
16621666
w.write_str("</div>");

‎src/librustdoc/html/render/print_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub(super) fn print_item(
108108
);
109109
let stability_since_raw: String = stability_since_raw.into_inner();
110110

111-
// Write `src` tag
111+
// Write source tag
112112
//
113113
// When this item is part of a `crate use` in a downstream crate, the
114-
// [src] link in the downstream documentation will actually come back to
114+
// source link in the downstream documentation will actually come back to
115115
// this page, and this link will be auto-clicked. The `id` attribute is
116116
// used to find the link to auto-click.
117117
let src_href =
@@ -1467,7 +1467,7 @@ fn render_stability_since(
14671467
item.const_stability(tcx),
14681468
containing_item.stable_since(tcx),
14691469
containing_item.const_stable_since(tcx),
1470-
)
1470+
);
14711471
}
14721472

14731473
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.