Skip to content

Commit

Permalink
Auto merge of #98987 - GuillaumeGomez:rollup-bcy32bp, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #96935 (Allow arithmetic and certain bitwise ops on AtomicPtr)
 - #98519 (Replace some `guess_head_span` with `def_span`)
 - #98911 (rustdoc: filter '_ lifetimes from ty::Generics)
 - #98939 (rustdoc: Add more semantic information to impl IDs)
 - #98971 (Fix typo in file descriptor docs)
 - #98983 (docs: Add overview of `rustc_middle::mir::TerminatorKind`)
 - #98984 (Remove erroneous doc comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 6, 2022
2 parents 3dcb616 + 4b88cba commit 7665c35
Show file tree
Hide file tree
Showing 78 changed files with 701 additions and 341 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return FnSelfUse {
var_span: stmt.source_info.span,
fn_call_span: *fn_span,
fn_span: self
.infcx
.tcx
.sess
.source_map()
.guess_head_span(self.infcx.tcx.def_span(method_did)),
fn_span: self.infcx.tcx.def_span(method_did),
kind,
};
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};

let ty = substs.type_at(0);
if int_type_width_signed(ty, bx.tcx()).is_some()
|| (ty.is_unsafe_ptr() && op == "xchg")
{
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
let mut ptr = args[0].immediate();
let mut val = args[1].immediate();
if ty.is_unsafe_ptr() {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
});

if let Ok(Some(ImplSource::UserDefined(data))) = implsrc {
let span =
tcx.sess.source_map().guess_head_span(tcx.def_span(data.impl_def_id));
let span = tcx.def_span(data.impl_def_id);
err.span_note(span, "impl defined here, but it is not `const`");
}
}
Expand Down Expand Up @@ -205,7 +204,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {

match self_ty.kind() {
FnDef(def_id, ..) => {
let span = tcx.sess.source_map().guess_head_span(tcx.def_span(*def_id));
let span = tcx.def_span(*def_id);
if ccx.tcx.is_const_fn_raw(*def_id) {
span_bug!(span, "calling const FnDef errored when it shouldn't");
}
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>,
) -> (String, Span) {
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx).expect_local();
match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = sm.guess_head_span(tcx.def_span(scope));
let mut sp = tcx.def_span(scope);
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{
Expand All @@ -174,7 +172,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
} else {
match fr.bound_region {
ty::BoundRegionKind::BrNamed(_, name) => {
let mut sp = sm.guess_head_span(tcx.def_span(scope));
let mut sp = tcx.def_span(scope);
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
{
Expand All @@ -193,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
),
_ => (
format!("the lifetime `{}` as defined here", region),
sm.guess_head_span(tcx.def_span(scope)),
tcx.def_span(scope),
),
}
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);

if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let span = self.tcx.sess.source_map().guess_head_span(trait_item_span);
if trait_item_def_id.is_local() {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label(span, format!("definition of `{}` from trait", item_name));
err.span_label(
self.tcx.def_span(trait_item_def_id),
format!("definition of `{}` from trait", item_name),
);
}

err.span_label(sp, format!("impl has extra requirement {}", requirement));
Expand Down
37 changes: 13 additions & 24 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ impl MissingDoc {
&self,
cx: &LateContext<'_>,
def_id: LocalDefId,
sp: Span,
article: &'static str,
desc: &'static str,
) {
Expand All @@ -579,16 +578,12 @@ impl MissingDoc {
let attrs = cx.tcx.hir().attrs(cx.tcx.hir().local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().guess_head_span(sp),
|lint| {
lint.build(fluent::lint::builtin_missing_doc)
.set_arg("article", article)
.set_arg("desc", desc)
.emit();
},
);
cx.struct_span_lint(MISSING_DOCS, cx.tcx.def_span(def_id), |lint| {
lint.build(fluent::lint::builtin_missing_doc)
.set_arg("article", article)
.set_arg("desc", desc)
.emit();
});
}
}
}
Expand All @@ -611,13 +606,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}

fn check_crate(&mut self, cx: &LateContext<'_>) {
self.check_missing_docs_attrs(
cx,
CRATE_DEF_ID,
cx.tcx.def_span(CRATE_DEF_ID),
"the",
"crate",
);
self.check_missing_docs_attrs(cx, CRATE_DEF_ID, "the", "crate");
}

fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
Expand Down Expand Up @@ -647,13 +636,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {

let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());

self.check_missing_docs_attrs(cx, it.def_id, it.span, article, desc);
self.check_missing_docs_attrs(cx, it.def_id, article, desc);
}

fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) {
let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());

self.check_missing_docs_attrs(cx, trait_item.def_id, trait_item.span, article, desc);
self.check_missing_docs_attrs(cx, trait_item.def_id, article, desc);
}

fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
Expand Down Expand Up @@ -681,23 +670,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}

let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
self.check_missing_docs_attrs(cx, impl_item.def_id, impl_item.span, article, desc);
self.check_missing_docs_attrs(cx, impl_item.def_id, article, desc);
}

fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
let (article, desc) = cx.tcx.article_and_description(foreign_item.def_id.to_def_id());
self.check_missing_docs_attrs(cx, foreign_item.def_id, foreign_item.span, article, desc);
self.check_missing_docs_attrs(cx, foreign_item.def_id, article, desc);
}

fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
if !sf.is_positional() {
let def_id = cx.tcx.hir().local_def_id(sf.hir_id);
self.check_missing_docs_attrs(cx, def_id, sf.span, "a", "struct field")
self.check_missing_docs_attrs(cx, def_id, "a", "struct field")
}
}

fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
self.check_missing_docs_attrs(cx, cx.tcx.hir().local_def_id(v.id), v.span, "a", "variant");
self.check_missing_docs_attrs(cx, cx.tcx.hir().local_def_id(v.id), "a", "variant");
}
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,12 +1013,13 @@ impl<'hir> Map<'hir> {
ItemKind::Use(path, _) => path.span,
_ => named_span(item.span, item.ident, item.kind.generics()),
},
Node::Variant(variant) => named_span(variant.span, variant.ident, None),
Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)),
Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(decl, _, _) => until_within(item.span, decl.output.span()),
_ => named_span(item.span, item.ident, None),
},
Node::Ctor(..) => return self.opt_span(self.get_parent_node(hir_id)),
Node::Ctor(_) => return self.opt_span(self.get_parent_node(hir_id)),
_ => self.span_with_body(hir_id),
};
Some(span)
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ pub struct CopyNonOverlapping<'tcx> {
///////////////////////////////////////////////////////////////////////////
// Terminators

/// The various kinds of terminators, representing ways of exiting from a basic block.
///
/// A note on unwinding: Panics may occur during the execution of some terminators. Depending on the
/// `-C panic` flag, this may either cause the program to abort or the call stack to unwind. Such
/// terminators have a `cleanup: Option<BasicBlock>` field on them. If stack unwinding occurs, then
Expand Down Expand Up @@ -911,7 +913,7 @@ pub enum Operand<'tcx> {
static_assert_size!(Operand<'_>, 24);

///////////////////////////////////////////////////////////////////////////
/// Rvalues
// Rvalues

/// The various kinds of rvalues that can appear in MIR.
///
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ fn foo(&self) -> Self::T { String::new() }
if item_def_id == proj_ty_item_def_id =>
{
Some((
self.sess.source_map().guess_head_span(self.def_span(item.def_id)),
self.def_span(item.def_id),
format!("consider calling `{}`", self.def_path_str(item.def_id)),
))
}
Expand Down
20 changes: 6 additions & 14 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,18 +1112,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
})
.collect::<Option<Vec<ArgKind>>>()?,
),
Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
| Node::ImplItem(&hir::ImplItem {
span,
kind: hir::ImplItemKind::Fn(ref sig, _),
..
})
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref sig, ..), .. })
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(ref sig, _), .. })
| Node::TraitItem(&hir::TraitItem {
span,
kind: hir::TraitItemKind::Fn(ref sig, _),
..
kind: hir::TraitItemKind::Fn(ref sig, _), ..
}) => (
sm.guess_head_span(span),
sig.span,
sig.decl
.inputs
.iter()
Expand All @@ -1138,7 +1132,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
),
Node::Ctor(ref variant_data) => {
let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| hir.span(id));
let span = sm.guess_head_span(span);
(span, vec![ArgKind::empty(); variant_data.fields().len()])
}
_ => panic!("non-FnLike node found: {:?}", node),
Expand Down Expand Up @@ -2185,7 +2178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
let mut post = vec![];
for def_id in impls {
match self.tcx.span_of_impl(*def_id) {
Ok(span) => spans.push(self.tcx.sess.source_map().guess_head_span(span)),
Ok(span) => spans.push(span),
Err(name) => {
crates.push(name);
if let Some(header) = to_pretty_impl_header(self.tcx, *def_id) {
Expand Down Expand Up @@ -2532,8 +2525,7 @@ pub fn recursive_type_with_infinite_size_error<'tcx>(
spans: Vec<(Span, Option<hir::HirId>)>,
) {
assert!(type_def_id.is_local());
let span = tcx.hir().span_if_local(type_def_id).unwrap();
let span = tcx.sess.source_map().guess_head_span(span);
let span = tcx.def_span(type_def_id);
let path = tcx.def_path_str(type_def_id);
let mut err =
struct_span_err!(tcx.sess, span, E0072, "recursive type `{}` has infinite size", path);
Expand Down
23 changes: 5 additions & 18 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,7 @@ fn report_negative_positive_conflict(
positive_impl_def_id: DefId,
sg: &mut specialization_graph::Graph,
) {
let impl_span = tcx
.sess
.source_map()
.guess_head_span(tcx.span_of_impl(local_impl_def_id.to_def_id()).unwrap());
let impl_span = tcx.def_span(local_impl_def_id);

let mut err = struct_span_err!(
tcx.sess,
Expand All @@ -356,10 +353,7 @@ fn report_negative_positive_conflict(

match tcx.span_of_impl(negative_impl_def_id) {
Ok(span) => {
err.span_label(
tcx.sess.source_map().guess_head_span(span),
"negative implementation here".to_string(),
);
err.span_label(span, "negative implementation here");
}
Err(cname) => {
err.note(&format!("negative implementation in crate `{}`", cname));
Expand All @@ -368,10 +362,7 @@ fn report_negative_positive_conflict(

match tcx.span_of_impl(positive_impl_def_id) {
Ok(span) => {
err.span_label(
tcx.sess.source_map().guess_head_span(span),
"positive implementation here".to_string(),
);
err.span_label(span, "positive implementation here");
}
Err(cname) => {
err.note(&format!("positive implementation in crate `{}`", cname));
Expand All @@ -388,8 +379,7 @@ fn report_conflicting_impls(
used_to_be_allowed: Option<FutureCompatOverlapErrorKind>,
sg: &mut specialization_graph::Graph,
) {
let impl_span =
tcx.sess.source_map().guess_head_span(tcx.span_of_impl(impl_def_id.to_def_id()).unwrap());
let impl_span = tcx.def_span(impl_def_id);

// Work to be done after we've built the DiagnosticBuilder. We have to define it
// now because the struct_lint methods don't return back the DiagnosticBuilder
Expand All @@ -416,10 +406,7 @@ fn report_conflicting_impls(
let mut err = err.build(&msg);
match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
err.span_label(
tcx.sess.source_map().guess_head_span(span),
"first implementation here".to_string(),
);
err.span_label(span, "first implementation here".to_string());

err.span_label(
impl_span,
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,9 +1958,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);
}

if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
let sp = tcx.sess.source_map().guess_head_span(sp);
err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
if adt_def.did().is_local() {
err.span_label(
tcx.def_span(adt_def.did()),
format!("variant `{assoc_ident}` not found for this enum"),
);
}

err.emit()
Expand Down Expand Up @@ -2450,7 +2452,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

let msg = format!("`Self` is of type `{ty}`");
if let (Ok(i_sp), Some(t_sp)) = (span_of_impl, span_of_ty) {
let i_sp = tcx.sess.source_map().guess_head_span(i_sp);
let mut span: MultiSpan = vec![t_sp].into();
span.push_span_label(
i_sp,
Expand Down
Loading

0 comments on commit 7665c35

Please sign in to comment.