Skip to content

Commit

Permalink
Auto merge of rust-lang#99278 - Dylan-DPC:rollup-fcln6st, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#88991 (Add Nintendo Switch as tier 3 target)
 - rust-lang#98869 (Remove some usages of `guess_head_span`)
 - rust-lang#99119 (Refactor: remove a string matching about methods)
 - rust-lang#99209 (Correctly handle crate level page on docs.rs as well)
 - rust-lang#99246 (Update RLS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 15, 2022
2 parents 6077b7c + 8e3dd62 commit 116819f
Show file tree
Hide file tree
Showing 54 changed files with 468 additions and 324 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,14 @@ impl Expr<'_> {
_ => false,
}
}

pub fn method_ident(&self) -> Option<Ident> {
match self.kind {
ExprKind::MethodCall(receiver_method, ..) => Some(receiver_method.ident),
ExprKind::Unary(_, expr) | ExprKind::AddrOf(.., expr) => expr.method_ident(),
_ => None,
}
}
}

/// Checks if the specified expression is a built-in range literal.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
}

fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) {
span_bug!(
self.cause.span(self.infcx.tcx),
"generic_const_exprs: unreachable `const_equate`"
);
span_bug!(self.cause.span(), "generic_const_exprs: unreachable `const_equate`");
}

fn normalization() -> NormalizationStrategy {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
swap_secondary_and_primary: bool,
force_label: bool,
) {
let span = cause.span(self.tcx);
let span = cause.span();

// For some types of errors, expected-found does not make
// sense, so just ignore the values we were given.
Expand Down Expand Up @@ -2085,7 +2085,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);

let span = trace.cause.span(self.tcx);
let span = trace.cause.span();
let failure_code = trace.cause.as_failure_code(terr);
let mut diag = match failure_code {
FailureCode::Error0038(did) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let span = cause.span(self.tcx());
let span = cause.span();
let msg = format!(
"implementation of `{}` is not general enough",
self.tcx().def_path_str(trait_def_id),
Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trait_item_def_id: DefId,
requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let msg = "impl has stricter requirements than trait";
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
let mut err = struct_span_err!(
self.tcx.sess,
error_span,
E0276,
"impl has stricter requirements than trait"
);

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

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

err.span_label(sp, format!("impl has extra requirement {}", requirement));
err.span_label(error_span, format!("impl has extra requirement {}", requirement));

err
}
Expand All @@ -48,7 +47,6 @@ pub fn report_object_safety_error<'tcx>(
hir::Node::Item(item) => Some(item.ident.span),
_ => None,
});
let span = tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!(
tcx.sess,
span,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,8 @@ pub trait LintContext: Sized {
}

if let Some(span) = in_test_module {
let def_span = self.sess().source_map().guess_head_span(span);
db.span_help(
span.shrink_to_lo().to(def_span),
self.sess().source_map().guess_head_span(span),
"consider adding a `#[cfg(test)]` to the containing module",
);
}
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() }
}

pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span {
pub fn span(&self) -> Span {
match *self.code() {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
| ObligationCauseCode::StartFunctionType => {
tcx.sess.source_map().guess_head_span(self.span)
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span,
..
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|| self.tcx.resolutions(()).has_pub_restricted
{
let descr = descr.to_string();
let vis_span =
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
let vis_span = self.tcx.def_span(def_id);
if kind == "trait" {
self.tcx.sess.emit_err(InPublicInterfaceTraits {
span,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,8 @@ symbols! {
thumb2,
thumb_mode: "thumb-mode",
tmm_reg,
to_string,
to_vec,
todo_macro,
tool_attributes,
tool_lints,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions};

const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld");

/// A base target for Nintendo Switch devices using a pure LLVM toolchain.
pub fn target() -> Target {
Target {
llvm_target: "aarch64-unknown-none".into(),
pointer_width: 64,
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
options: TargetOptions {
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
linker: Some("rust-lld".into()),
link_script: Some(LINKER_SCRIPT.into()),
os: "horizon".into(),
max_atomic_width: Some(128),
panic_strategy: PanicStrategy::Abort,
position_independent_executables: true,
dynamic_linking: true,
executables: true,
relro_level: RelroLevel::Off,
..Default::default()
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
OUTPUT_FORMAT(elf64-littleaarch64)
OUTPUT_ARCH(aarch64)
ENTRY(_start)

PHDRS
{
text PT_LOAD FLAGS(5);
rodata PT_LOAD FLAGS(4);
data PT_LOAD FLAGS(6);
bss PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC;
}

SECTIONS
{
. = 0;

.text : ALIGN(0x1000) {
HIDDEN(__text_start = .);
KEEP(*(.text.jmp))

. = 0x80;

*(.text .text.*)
*(.plt .plt.*)
}

/* Read-only sections */

. = ALIGN(0x1000);

.module_name : { *(.module_name) } :rodata

.rodata : { *(.rodata .rodata.*) } :rodata
.hash : { *(.hash) }
.dynsym : { *(.dynsym .dynsym.*) }
.dynstr : { *(.dynstr .dynstr.*) }
.rela.dyn : { *(.rela.dyn) }

.eh_frame : {
HIDDEN(__eh_frame_start = .);
*(.eh_frame .eh_frame.*)
HIDDEN(__eh_frame_end = .);
}

.eh_frame_hdr : {
HIDDEN(__eh_frame_hdr_start = .);
*(.eh_frame_hdr .eh_frame_hdr.*)
HIDDEN(__eh_frame_hdr_end = .);
}

/* Read-write sections */

. = ALIGN(0x1000);

.data : {
*(.data .data.*)
*(.got .got.*)
*(.got.plt .got.plt.*)
} :data

.dynamic : {
HIDDEN(__dynamic_start = .);
*(.dynamic)
}

/* BSS section */

. = ALIGN(0x1000);

.bss : {
HIDDEN(__bss_start = .);
*(.bss .bss.*)
*(COMMON)
. = ALIGN(8);
HIDDEN(__bss_end = .);
} :bss
}
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ supported_targets! {

("armv6k-nintendo-3ds", armv6k_nintendo_3ds),

("aarch64-nintendo-switch-freestanding", aarch64_nintendo_switch_freestanding),

("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),

Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span =
self.tcx.sess.source_map().guess_head_span(
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
);
let closure_span = self.tcx.def_span(closure_def_id);
let mut err = struct_span_err!(
self.tcx.sess,
closure_span,
Expand Down Expand Up @@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => None,
};

let found_span = found_did
.and_then(|did| self.tcx.hir().span_if_local(did))
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be an fn def
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));

if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
// We check closures twice, with obligations flowing in different directions,
Expand Down Expand Up @@ -1089,7 +1084,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }),
..
}) => (
sm.guess_head_span(fn_decl_span),
fn_decl_span,
hir.body(body)
.params
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::Generator(..) => "generator",
_ => "function",
};
let span = self.tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!(
self.tcx.sess,
span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
span_bug!(
obligation.cause.span(self.selcx.tcx()),
obligation.cause.span(),
"ConstEquate: const_eval_resolve returned an unexpected error"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
// Run canonical query. If overflow occurs, rerun from scratch but this time
// in standard trait query mode so that overflow is handled appropriately
// within `SelectionContext`.
self.tcx.at(obligation.cause.span(self.tcx)).evaluate_obligation(c_pred)
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
}

// Helper function that canonicalizes and runs the query. If an
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr),
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
span_bug!(
obligation.cause.span(self.tcx()),
obligation.cause.span(),
"ConstEquate: const_eval_resolve returned an unexpected error"
)
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);
}

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

err.emit()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::check::coercion::{AsCoercionSite, CoerceMany};
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Obligation;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause,
Some(&arm.body),
arm_ty,
Some(&mut |err: &mut Diagnostic| {
Some(&mut |err| {
let Some(ret) = self.ret_type_span else {
return;
};
Expand Down
Loading

0 comments on commit 116819f

Please sign in to comment.