Skip to content

Commit 116819f

Browse files
committed
Auto merge of rust-lang#99278 - Dylan-DPC:rollup-fcln6st, r=Dylan-DPC
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
2 parents 6077b7c + 8e3dd62 commit 116819f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+468
-324
lines changed

compiler/rustc_hir/src/hir.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,14 @@ impl Expr<'_> {
18241824
_ => false,
18251825
}
18261826
}
1827+
1828+
pub fn method_ident(&self) -> Option<Ident> {
1829+
match self.kind {
1830+
ExprKind::MethodCall(receiver_method, ..) => Some(receiver_method.ident),
1831+
ExprKind::Unary(_, expr) | ExprKind::AddrOf(.., expr) => expr.method_ident(),
1832+
_ => None,
1833+
}
1834+
}
18271835
}
18281836

18291837
/// Checks if the specified expression is a built-in range literal.

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
714714
}
715715

716716
fn const_equate(&mut self, _a: Const<'tcx>, _b: Const<'tcx>) {
717-
span_bug!(
718-
self.cause.span(self.infcx.tcx),
719-
"generic_const_exprs: unreachable `const_equate`"
720-
);
717+
span_bug!(self.cause.span(), "generic_const_exprs: unreachable `const_equate`");
721718
}
722719

723720
fn normalization() -> NormalizationStrategy {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14351435
swap_secondary_and_primary: bool,
14361436
force_label: bool,
14371437
) {
1438-
let span = cause.span(self.tcx);
1438+
let span = cause.span();
14391439

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

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

2088-
let span = trace.cause.span(self.tcx);
2088+
let span = trace.cause.span();
20892089
let failure_code = trace.cause.as_failure_code(terr);
20902090
let mut diag = match failure_code {
20912091
FailureCode::Error0038(did) => {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
204204
expected_substs: SubstsRef<'tcx>,
205205
actual_substs: SubstsRef<'tcx>,
206206
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
207-
let span = cause.span(self.tcx());
207+
let span = cause.span();
208208
let msg = format!(
209209
"implementation of `{}` is not general enough",
210210
self.tcx().def_path_str(trait_def_id),

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1818
trait_item_def_id: DefId,
1919
requirement: &dyn fmt::Display,
2020
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
21-
let msg = "impl has stricter requirements than trait";
22-
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
21+
let mut err = struct_span_err!(
22+
self.tcx.sess,
23+
error_span,
24+
E0276,
25+
"impl has stricter requirements than trait"
26+
);
2327

24-
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
25-
26-
if trait_item_def_id.is_local() {
28+
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
2729
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
28-
err.span_label(
29-
self.tcx.def_span(trait_item_def_id),
30-
format!("definition of `{}` from trait", item_name),
31-
);
30+
err.span_label(span, format!("definition of `{}` from trait", item_name));
3231
}
3332

34-
err.span_label(sp, format!("impl has extra requirement {}", requirement));
33+
err.span_label(error_span, format!("impl has extra requirement {}", requirement));
3534

3635
err
3736
}
@@ -48,7 +47,6 @@ pub fn report_object_safety_error<'tcx>(
4847
hir::Node::Item(item) => Some(item.ident.span),
4948
_ => None,
5049
});
51-
let span = tcx.sess.source_map().guess_head_span(span);
5250
let mut err = struct_span_err!(
5351
tcx.sess,
5452
span,

compiler/rustc_lint/src/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,8 @@ pub trait LintContext: Sized {
694694
}
695695

696696
if let Some(span) = in_test_module {
697-
let def_span = self.sess().source_map().guess_head_span(span);
698697
db.span_help(
699-
span.shrink_to_lo().to(def_span),
698+
self.sess().source_map().guess_head_span(span),
700699
"consider adding a `#[cfg(test)]` to the containing module",
701700
);
702701
}

compiler/rustc_middle/src/traits/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
139139
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() }
140140
}
141141

142-
pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span {
142+
pub fn span(&self) -> Span {
143143
match *self.code() {
144-
ObligationCauseCode::CompareImplMethodObligation { .. }
145-
| ObligationCauseCode::MainFunctionType
146-
| ObligationCauseCode::StartFunctionType => {
147-
tcx.sess.source_map().guess_head_span(self.span)
148-
}
149144
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
150145
arm_span,
151146
..

compiler/rustc_privacy/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17591759
|| self.tcx.resolutions(()).has_pub_restricted
17601760
{
17611761
let descr = descr.to_string();
1762-
let vis_span =
1763-
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
1762+
let vis_span = self.tcx.def_span(def_id);
17641763
if kind == "trait" {
17651764
self.tcx.sess.emit_err(InPublicInterfaceTraits {
17661765
span,

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,8 @@ symbols! {
14351435
thumb2,
14361436
thumb_mode: "thumb-mode",
14371437
tmm_reg,
1438+
to_string,
1439+
to_vec,
14381440
todo_macro,
14391441
tool_attributes,
14401442
tool_lints,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel, Target, TargetOptions};
2+
3+
const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding_linker_script.ld");
4+
5+
/// A base target for Nintendo Switch devices using a pure LLVM toolchain.
6+
pub fn target() -> Target {
7+
Target {
8+
llvm_target: "aarch64-unknown-none".into(),
9+
pointer_width: 64,
10+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
11+
arch: "aarch64".into(),
12+
options: TargetOptions {
13+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
14+
linker: Some("rust-lld".into()),
15+
link_script: Some(LINKER_SCRIPT.into()),
16+
os: "horizon".into(),
17+
max_atomic_width: Some(128),
18+
panic_strategy: PanicStrategy::Abort,
19+
position_independent_executables: true,
20+
dynamic_linking: true,
21+
executables: true,
22+
relro_level: RelroLevel::Off,
23+
..Default::default()
24+
},
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
OUTPUT_FORMAT(elf64-littleaarch64)
2+
OUTPUT_ARCH(aarch64)
3+
ENTRY(_start)
4+
5+
PHDRS
6+
{
7+
text PT_LOAD FLAGS(5);
8+
rodata PT_LOAD FLAGS(4);
9+
data PT_LOAD FLAGS(6);
10+
bss PT_LOAD FLAGS(6);
11+
dynamic PT_DYNAMIC;
12+
}
13+
14+
SECTIONS
15+
{
16+
. = 0;
17+
18+
.text : ALIGN(0x1000) {
19+
HIDDEN(__text_start = .);
20+
KEEP(*(.text.jmp))
21+
22+
. = 0x80;
23+
24+
*(.text .text.*)
25+
*(.plt .plt.*)
26+
}
27+
28+
/* Read-only sections */
29+
30+
. = ALIGN(0x1000);
31+
32+
.module_name : { *(.module_name) } :rodata
33+
34+
.rodata : { *(.rodata .rodata.*) } :rodata
35+
.hash : { *(.hash) }
36+
.dynsym : { *(.dynsym .dynsym.*) }
37+
.dynstr : { *(.dynstr .dynstr.*) }
38+
.rela.dyn : { *(.rela.dyn) }
39+
40+
.eh_frame : {
41+
HIDDEN(__eh_frame_start = .);
42+
*(.eh_frame .eh_frame.*)
43+
HIDDEN(__eh_frame_end = .);
44+
}
45+
46+
.eh_frame_hdr : {
47+
HIDDEN(__eh_frame_hdr_start = .);
48+
*(.eh_frame_hdr .eh_frame_hdr.*)
49+
HIDDEN(__eh_frame_hdr_end = .);
50+
}
51+
52+
/* Read-write sections */
53+
54+
. = ALIGN(0x1000);
55+
56+
.data : {
57+
*(.data .data.*)
58+
*(.got .got.*)
59+
*(.got.plt .got.plt.*)
60+
} :data
61+
62+
.dynamic : {
63+
HIDDEN(__dynamic_start = .);
64+
*(.dynamic)
65+
}
66+
67+
/* BSS section */
68+
69+
. = ALIGN(0x1000);
70+
71+
.bss : {
72+
HIDDEN(__bss_start = .);
73+
*(.bss .bss.*)
74+
*(COMMON)
75+
. = ALIGN(8);
76+
HIDDEN(__bss_end = .);
77+
} :bss
78+
}

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ supported_targets! {
10351035

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

1038+
("aarch64-nintendo-switch-freestanding", aarch64_nintendo_switch_freestanding),
1039+
10381040
("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
10391041
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),
10401042

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
823823

824824
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
825825
let found_kind = self.closure_kind(closure_substs).unwrap();
826-
let closure_span =
827-
self.tcx.sess.source_map().guess_head_span(
828-
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
829-
);
826+
let closure_span = self.tcx.def_span(closure_def_id);
830827
let mut err = struct_span_err!(
831828
self.tcx.sess,
832829
closure_span,
@@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
951948
_ => None,
952949
};
953950

954-
let found_span = found_did
955-
.and_then(|did| self.tcx.hir().span_if_local(did))
956-
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be an fn def
951+
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
957952

958953
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
959954
// We check closures twice, with obligations flowing in different directions,
@@ -1089,7 +1084,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10891084
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }),
10901085
..
10911086
}) => (
1092-
sm.guess_head_span(fn_decl_span),
1087+
fn_decl_span,
10931088
hir.body(body)
10941089
.params
10951090
.iter()

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
15431543
ty::Generator(..) => "generator",
15441544
_ => "function",
15451545
};
1546-
let span = self.tcx.sess.source_map().guess_head_span(span);
15471546
let mut err = struct_span_err!(
15481547
self.tcx.sess,
15491548
span,

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
603603
),
604604
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
605605
span_bug!(
606-
obligation.cause.span(self.selcx.tcx()),
606+
obligation.cause.span(),
607607
"ConstEquate: const_eval_resolve returned an unexpected error"
608608
)
609609
}

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
8484
// Run canonical query. If overflow occurs, rerun from scratch but this time
8585
// in standard trait query mode so that overflow is handled appropriately
8686
// within `SelectionContext`.
87-
self.tcx.at(obligation.cause.span(self.tcx)).evaluate_obligation(c_pred)
87+
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
8888
}
8989

9090
// Helper function that canonicalizes and runs the query. If an

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
742742
| (_, Err(ErrorHandled::Reported(_))) => Ok(EvaluatedToErr),
743743
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
744744
span_bug!(
745-
obligation.cause.span(self.tcx()),
745+
obligation.cause.span(),
746746
"ConstEquate: const_eval_resolve returned an unexpected error"
747747
)
748748
}

compiler/rustc_typeck/src/astconv/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19581958
);
19591959
}
19601960

1961-
if adt_def.did().is_local() {
1962-
err.span_label(
1963-
tcx.def_span(adt_def.did()),
1964-
format!("variant `{assoc_ident}` not found for this enum"),
1965-
);
1961+
if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
1962+
err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
19661963
}
19671964

19681965
err.emit()

compiler/rustc_typeck/src/check/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::check::coercion::{AsCoercionSite, CoerceMany};
22
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
3-
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
3+
use rustc_errors::{Applicability, MultiSpan};
44
use rustc_hir::{self as hir, ExprKind};
55
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
66
use rustc_infer::traits::Obligation;
@@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127127
&cause,
128128
Some(&arm.body),
129129
arm_ty,
130-
Some(&mut |err: &mut Diagnostic| {
130+
Some(&mut |err| {
131131
let Some(ret) = self.ret_type_span else {
132132
return;
133133
};

0 commit comments

Comments
 (0)