Skip to content

Commit

Permalink
Auto merge of rust-lang#92719 - matthiaskrgr:rollup-tc7oqys, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92248 (Normalize struct tail type when checking Pointee trait)
 - rust-lang#92357 (Fix invalid removal of newlines from doc comments)
 - rust-lang#92602 (Make source links look cleaner)
 - rust-lang#92636 (Normalize generator-local types with unevaluated constants)
 - rust-lang#92693 (Release notes: add `Result::unwrap_{,err_}unchecked`)
 - rust-lang#92702 (Clean up lang_items::extract)
 - rust-lang#92717 (update miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 10, 2022
2 parents df035a3 + 3d5db0e commit 89b9f7b
Show file tree
Hide file tree
Showing 37 changed files with 215 additions and 130 deletions.
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Stabilized APIs
- [`Path::is_symlink`]
- [`{integer}::saturating_div`]
- [`Option::unwrap_unchecked`]
- [`Result::unwrap_unchecked`]
- [`Result::unwrap_err_unchecked`]
- [`NonZero{unsigned}::is_power_of_two`]

These APIs are now usable in const contexts:
Expand Down Expand Up @@ -136,6 +138,8 @@ and related tools.
[`Path::is_symlink`]: https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.is_symlink
[`{integer}::saturating_div`]: https://doc.rust-lang.org/stable/std/primitive.i8.html#method.saturating_div
[`Option::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.unwrap_unchecked
[`Result::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_unchecked
[`Result::unwrap_err_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_err_unchecked
[`NonZero{unsigned}::is_power_of_two`]: https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html#method.is_power_of_two
[`unix::process::ExitStatusExt::core_dumped`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.core_dumped
[`unix::process::ExitStatusExt::stopped_signal`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_ast/src/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ pub fn beautify_doc_string(data: Symbol) -> Symbol {
i += 1;
}

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

while j > i && lines[j - 1].trim().is_empty() {
j -= 1;
}

if i != 0 || j != lines.len() { Some((i, j)) } else { None }
}

Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,12 @@ impl<CTX> HashStable<CTX> for LangItem {
/// Extracts the first `lang = "$name"` out of a list of attributes.
/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
/// are also extracted out when found.
///
/// About the `check_name` argument: passing in a `Session` would be simpler,
/// because then we could call `Session::check_name` directly. But we want to
/// avoid the need for `rustc_hir` to depend on `rustc_session`, so we
/// use a closure instead.
pub fn extract<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<(Symbol, Span)>
where
F: Fn(&'a ast::Attribute, Symbol) -> bool,
{
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
attrs.iter().find_map(|attr| {
Some(match attr {
_ if check_name(attr, sym::lang) => (attr.value_str()?, attr.span),
_ if check_name(attr, sym::panic_handler) => (sym::panic_impl, attr.span),
_ if check_name(attr, sym::alloc_error_handler) => (sym::oom, attr.span),
_ if attr.has_name(sym::lang) => (attr.value_str()?, attr.span),
_ if attr.has_name(sym::panic_handler) => (sym::panic_impl, attr.span),
_ if attr.has_name(sym::alloc_error_handler) => (sym::oom, attr.span),
_ => return None,
})
})
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_hir/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::ne
map
});

/// The `check_name` argument avoids the need for `rustc_hir` to depend on
/// `rustc_session`.
pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
where
F: Fn(&'a ast::Attribute, Symbol) -> bool
pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol>
{
lang_items::extract(check_name, attrs).and_then(|(name, _)| {
lang_items::extract(attrs).and_then(|(name, _)| {
$(if name == sym::$name {
Some(sym::$sym)
} else)* {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2143,9 +2143,12 @@ impl<'tcx> TyS<'tcx> {
}

/// Returns the type of metadata for (potentially fat) pointers to this type.
pub fn ptr_metadata_ty(&'tcx self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
// FIXME: should this normalize?
let tail = tcx.struct_tail_without_normalization(self);
pub fn ptr_metadata_ty(
&'tcx self,
tcx: TyCtxt<'tcx>,
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
) -> Ty<'tcx> {
let tail = tcx.struct_tail_with_normalize(self, normalize);
match tail.kind() {
// Sized types
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn struct_tail_with_normalize(
self,
mut ty: Ty<'tcx>,
normalize: impl Fn(Ty<'tcx>) -> Ty<'tcx>,
mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
) -> Ty<'tcx> {
let recursion_limit = self.recursion_limit();
for iteration in 0.. {
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,13 @@ fn sanitize_witness<'tcx>(
saved_locals: &GeneratorSavedLocals,
) {
let did = body.source.def_id();
let allowed_upvars = tcx.erase_regions(upvars);
let param_env = tcx.param_env(did);

let allowed_upvars = tcx.normalize_erasing_regions(param_env, upvars);
let allowed = match witness.kind() {
&ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s),
&ty::GeneratorWitness(interior_tys) => {
tcx.normalize_erasing_late_bound_regions(param_env, interior_tys)
}
_ => {
tcx.sess.delay_span_bug(
body.span,
Expand All @@ -738,8 +742,6 @@ fn sanitize_witness<'tcx>(
}
};

let param_env = tcx.param_env(did);

for (local, decl) in body.local_decls.iter_enumerated() {
// Ignore locals which are internal or not saved between yields.
if !saved_locals.contains(local) || decl.internal {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use crate::check_attr::target_from_impl_item;
use crate::weak_lang_items;

use rustc_ast::Attribute;
use rustc_errors::{pluralize, struct_span_err};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -57,8 +56,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {

fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
let attrs = self.tcx.hir().attrs(hir_id);
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
if let Some((value, span)) = extract(check_name, &attrs) {
if let Some((value, span)) = extract(&attrs) {
match ITEM_REFS.get(&value).cloned() {
// Known lang item with attribute on correct target.
Some((item_index, expected_target)) if actual_target == expected_target => {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_passes/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Validity checking for weak lang items
use rustc_ast::Attribute;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
Expand Down Expand Up @@ -103,9 +102,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
}

fn visit_foreign_item(&mut self, i: &hir::ForeignItem<'_>) {
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
let attrs = self.tcx.hir().attrs(i.hir_id());
if let Some((lang_item, _)) = lang_items::extract(check_name, attrs) {
if let Some((lang_item, _)) = lang_items::extract(attrs) {
self.register(lang_item, i.span);
}
intravisit::walk_foreign_item(self, i)
Expand Down
38 changes: 32 additions & 6 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,17 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// Any type with multiple potential metadata types is therefore not eligible.
let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty());

// FIXME: should this normalize?
let tail = selcx.tcx().struct_tail_without_normalization(self_ty);
let tail = selcx.tcx().struct_tail_with_normalize(self_ty, |ty| {
normalize_with_depth(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
ty,
)
.value
});

match tail.kind() {
ty::Bool
| ty::Char
Expand Down Expand Up @@ -1435,7 +1444,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..)
| ty::Error(_) => false,
| ty::Error(_) => {
if tail.has_infer_types() {
candidate_set.mark_ambiguous();
}
false
},
}
}
super::ImplSource::Param(..) => {
Expand Down Expand Up @@ -1640,18 +1654,30 @@ fn confirm_pointee_candidate<'cx, 'tcx>(
_: ImplSourcePointeeData,
) -> Progress<'tcx> {
let tcx = selcx.tcx();

let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty());
let substs = tcx.mk_substs([self_ty.into()].iter());

let mut obligations = vec![];
let metadata_ty = self_ty.ptr_metadata_ty(tcx, |ty| {
normalize_with_depth_to(
selcx,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
ty,
&mut obligations,
)
});

let substs = tcx.mk_substs([self_ty.into()].iter());
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);

let predicate = ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy { substs, item_def_id: metadata_def_id },
ty: self_ty.ptr_metadata_ty(tcx),
ty: metadata_ty,
};

confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(obligations)
}

fn confirm_fn_pointer_candidate<'cx, 'tcx>(
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::constrained_generic_params as cgp;
use crate::errors;
use crate::middle::resolve_lifetime as rl;
use rustc_ast as ast;
use rustc_ast::Attribute;
use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_data_structures::captures::Captures;
Expand Down Expand Up @@ -3120,8 +3119,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if tcx.is_weak_lang_item(id) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
}
let check_name = |attr: &Attribute, sym| attr.has_name(sym);
if let Some(name) = weak_lang_items::link_name(check_name, attrs) {
if let Some(name) = weak_lang_items::link_name(attrs) {
codegen_fn_attrs.export_name = Some(name);
codegen_fn_attrs.link_name = Some(name);
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
//! development you may want to press the `[-]` button near the top of the
//! page to collapse it into a more skimmable view.
//!
//! While you are looking at that `[-]` button also notice the `[src]`
//! button. Rust's API documentation comes with the source code and you are
//! While you are looking at that `[-]` button also notice the `source`
//! link. Rust's API documentation comes with the source code and you are
//! encouraged to read it. The standard library source is generally high
//! quality and a peek behind the curtains is often enlightening.
//!
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ crate struct Context<'tcx> {
///
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
crate shared: Rc<SharedContext<'tcx>>,
/// This flag indicates whether `[src]` links should be generated or not. If
/// This flag indicates whether source links should be generated or not. If
/// the source files are present in the html rendering, then this will be
/// `true`.
crate include_sources: bool,
Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl StylePath {

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

Expand Down Expand Up @@ -799,7 +799,7 @@ fn render_stability_since_raw(
const_stability: Option<ConstStability>,
containing_ver: Option<Symbol>,
containing_const_ver: Option<Symbol>,
) {
) -> bool {
let ver = ver.filter(|inner| !inner.is_empty());

match (ver, const_stability) {
Expand Down Expand Up @@ -842,8 +842,9 @@ fn render_stability_since_raw(
v
);
}
_ => {}
_ => return false,
}
true
}

fn render_assoc_item(
Expand Down Expand Up @@ -1632,7 +1633,7 @@ fn render_impl(
}

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

write!(w, "<div class=\"rightside\">");
render_stability_since_raw(
let has_stability = render_stability_since_raw(
w,
item.stable_since(tcx),
const_stability,
containing_item.stable_since(tcx),
const_stable_since,
);
if has_stability {
w.write_str(" · ");
}

write_srclink(cx, item, w);
w.write_str("</div>");
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ pub(super) fn print_item(
);
let stability_since_raw: String = stability_since_raw.into_inner();

// Write `src` tag
// Write source tag
//
// When this item is part of a `crate use` in a downstream crate, the
// [src] link in the downstream documentation will actually come back to
// source link in the downstream documentation will actually come back to
// this page, and this link will be auto-clicked. The `id` attribute is
// used to find the link to auto-click.
let src_href =
Expand Down Expand Up @@ -1467,7 +1467,7 @@ fn render_stability_since(
item.const_stability(tcx),
containing_item.stable_since(tcx),
containing_item.const_stable_since(tcx),
)
);
}

fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {
Expand Down
Loading

0 comments on commit 89b9f7b

Please sign in to comment.