Merge from rustc

This commit is contained in:
Ralf Jung 2023-05-18 11:02:09 +02:00
commit 4014b17d86
186 changed files with 2151 additions and 1231 deletions

View file

@ -1751,7 +1751,7 @@ fn render_impl(
if trait_.is_none() && i.inner_impl().items.is_empty() {
w.write_str(
"<div class=\"item-info\">\
<div class=\"stab empty-impl\">This impl block contains no items.</div>
<div class=\"stab empty-impl\">This impl block contains no items.</div>\
</div>",
);
}

View file

@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LocalDefIdSet};
use rustc_hir::intravisit::{walk_item, Visitor};
use rustc_hir::intravisit::{walk_body, walk_item, Visitor};
use rustc_hir::{Node, CRATE_HIR_ID};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
@ -106,6 +106,7 @@ pub(crate) struct RustdocVisitor<'a, 'tcx> {
exact_paths: DefIdMap<Vec<Symbol>>,
modules: Vec<Module<'tcx>>,
is_importable_from_parent: bool,
inside_body: bool,
}
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
@ -129,6 +130,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
exact_paths: Default::default(),
modules: vec![om],
is_importable_from_parent: true,
inside_body: false,
}
}
@ -368,6 +370,26 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
import_id: Option<LocalDefId>,
) {
debug!("visiting item {:?}", item);
if self.inside_body {
// Only impls can be "seen" outside a body. For example:
//
// ```
// struct Bar;
//
// fn foo() {
// impl Bar { fn bar() {} }
// }
// Bar::bar();
// ```
if let hir::ItemKind::Impl(impl_) = item.kind &&
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
// them up regardless of where they're located.
impl_.of_trait.is_none()
{
self.add_to_current_mod(item, None, None);
}
return;
}
let name = renamed.unwrap_or(item.ident.name);
let tcx = self.cx.tcx;
@ -564,4 +586,10 @@ impl<'a, 'tcx> Visitor<'tcx> for RustdocVisitor<'a, 'tcx> {
fn visit_lifetime(&mut self, _: &hir::Lifetime) {
// Unneeded.
}
fn visit_body(&mut self, b: &'tcx hir::Body<'tcx>) {
let prev = mem::replace(&mut self.inside_body, true);
walk_body(self, b);
self.inside_body = prev;
}
}

@ -1 +1 @@
Subproject commit ea6fa9c2d43aaf0f11559719eda9b54d356d5416
Subproject commit 533d3f338b804d54e5d0ac4fba6276af23002d9c

@ -1 +1 @@
Subproject commit 13413c64ff88dd6c2824e9eb9374fc5f10895d28
Subproject commit 09276c703a473ab33daaeb94917232e80eefd628

View file

@ -289,10 +289,11 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte
let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false };
match expected_item {
Item::Lang(expected_lang_item) => {
let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap();
cx.tcx.parent(id) == expected_id
},
Item::Lang(expected_lang_item) => cx
.tcx
.lang_items()
.get(expected_lang_item)
.map_or(false, |expected_id| cx.tcx.parent(id) == expected_id),
Item::Diag(expected_ty, expected_variant) => {
let ty = cx.typeck_results().pat_ty(pat);

View file

@ -428,7 +428,6 @@ impl TargetCfgs {
))
.unwrap();
let mut current = None;
let mut all_targets = HashSet::new();
let mut all_archs = HashSet::new();
let mut all_oses = HashSet::new();
@ -449,14 +448,11 @@ impl TargetCfgs {
}
all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
if target == config.target {
current = Some(cfg);
}
all_targets.insert(target.into());
}
Self {
current: current.expect("current target not found"),
current: Self::get_current_target_config(config),
all_targets,
all_archs,
all_oses,
@ -467,6 +463,89 @@ impl TargetCfgs {
all_pointer_widths,
}
}
fn get_current_target_config(config: &Config) -> TargetCfg {
let mut arch = None;
let mut os = None;
let mut env = None;
let mut abi = None;
let mut families = Vec::new();
let mut pointer_width = None;
let mut endian = None;
let mut panic = None;
for config in
rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
{
let (name, value) = config
.split_once("=\"")
.map(|(name, value)| {
(
name,
Some(
value
.strip_suffix("\"")
.expect("key-value pair should be properly quoted"),
),
)
})
.unwrap_or_else(|| (config, None));
match name {
"target_arch" => {
arch = Some(value.expect("target_arch should be a key-value pair").to_string());
}
"target_os" => {
os = Some(value.expect("target_os sould be a key-value pair").to_string());
}
"target_env" => {
env = Some(value.expect("target_env should be a key-value pair").to_string());
}
"target_abi" => {
abi = Some(value.expect("target_abi should be a key-value pair").to_string());
}
"target_family" => {
families
.push(value.expect("target_family should be a key-value pair").to_string());
}
"target_pointer_width" => {
pointer_width = Some(
value
.expect("target_pointer_width should be a key-value pair")
.parse::<u32>()
.expect("target_pointer_width should be a valid u32"),
);
}
"target_endian" => {
endian = Some(match value.expect("target_endian should be a key-value pair") {
"big" => Endian::Big,
"little" => Endian::Little,
_ => panic!("target_endian should be either 'big' or 'little'"),
});
}
"panic" => {
panic = Some(match value.expect("panic should be a key-value pair") {
"abort" => PanicStrategy::Abort,
"unwind" => PanicStrategy::Unwind,
_ => panic!("panic should be either 'abort' or 'unwind'"),
});
}
_ => (),
}
}
TargetCfg {
arch: arch.expect("target configuration should specify target_arch"),
os: os.expect("target configuration should specify target_os"),
env: env.expect("target configuration should specify target_env"),
abi: abi.expect("target configuration should specify target_abi"),
families,
pointer_width: pointer_width
.expect("target configuration should specify target_pointer_width"),
endian: endian.expect("target configuration should specify target_endian"),
panic: panic.expect("target configuration should specify panic"),
}
}
}
#[derive(Clone, Debug, serde::Deserialize)]

View file

@ -289,7 +289,7 @@ pub fn report_error<'tcx, 'mir>(
(None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")),
],
InvalidProgram(
InvalidProgramInfo::AlreadyReported(rustc_errors::ErrorGuaranteed { .. })
InvalidProgramInfo::AlreadyReported(_)
) => {
// This got already reported. No point in reporting it again.
return None;

View file

@ -47,7 +47,6 @@ extern crate rustc_ast;
extern crate rustc_middle;
extern crate rustc_const_eval;
extern crate rustc_data_structures;
extern crate rustc_errors;
extern crate rustc_hir;
extern crate rustc_index;
extern crate rustc_session;