Skip to content

Commit 42a982d

Browse files
committed
Auto merge of #113837 - matthiaskrgr:rollup-v4xud4s, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #113811 (Fix removal span calculation of `unused_qualifications` suggestion) - #113812 (docs(release): Remove nightly-only cargo item) - #113823 (Fix results search alias display) - #113824 (a small `fn needs_drop` refactor) - #113828 (Ping spastorino on changes to SMIR) - #113832 (Add `#[track_caller]` to lint related diagnostic functions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8d361cb + 4bbd781 commit 42a982d

22 files changed

+212
-58
lines changed

RELEASES.md

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Cargo
9292
-----
9393
- [Allow named debuginfo options in `Cargo.toml`.](https://github.com/rust-lang/cargo/pull/11958/)
9494
- [Add `workspace_default_members` to the output of `cargo metadata`.](https://github.com/rust-lang/cargo/pull/11978/)
95-
- [`cargo add` now considers `rust-version` when selecting packages.](https://github.com/rust-lang/cargo/pull/12078/)
9695
- [Automatically inherit workspace fields when running `cargo new`/`cargo init`.](https://github.com/rust-lang/cargo/pull/12069/)
9796

9897
<a id="1.71.0-Rustdoc"></a>

compiler/rustc_lint/src/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,11 @@ pub trait LintContext: Sized {
956956
db.span_note(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace));
957957
db.span_note(private_item_span, "but the private item here shadows it".to_owned());
958958
}
959-
BuiltinLintDiagnostics::UnusedQualifications { path_span, unqualified_path } => {
959+
BuiltinLintDiagnostics::UnusedQualifications { removal_span } => {
960960
db.span_suggestion_verbose(
961-
path_span,
962-
"replace it with the unqualified path",
963-
unqualified_path,
961+
removal_span,
962+
"remove the unnecessary path segments",
963+
"",
964964
Applicability::MachineApplicable
965965
);
966966
}

compiler/rustc_lint/src/levels.rs

+4
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
978978
/// Returns `true` if the lint's feature is enabled.
979979
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
980980
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
981+
#[track_caller]
981982
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
982983
if let Some(feature) = lint_id.lint.feature_gate {
983984
if !self.sess.features_untracked().enabled(feature) {
@@ -1015,6 +1016,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10151016
///
10161017
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
10171018
#[rustc_lint_diagnostics]
1019+
#[track_caller]
10181020
pub(crate) fn struct_lint(
10191021
&self,
10201022
lint: &'static Lint,
@@ -1028,6 +1030,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10281030
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
10291031
}
10301032

1033+
#[track_caller]
10311034
pub fn emit_spanned_lint(
10321035
&self,
10331036
lint: &'static Lint,
@@ -1040,6 +1043,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10401043
});
10411044
}
10421045

1046+
#[track_caller]
10431047
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
10441048
let (level, src) = self.lint_level(lint);
10451049
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {

compiler/rustc_lint_defs/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,8 @@ pub enum BuiltinLintDiagnostics {
551551
private_item_span: Span,
552552
},
553553
UnusedQualifications {
554-
/// The span of the unnecessarily-qualified path.
555-
path_span: Span,
556-
/// The replacement unqualified path.
557-
unqualified_path: Ident,
554+
/// The span of the unnecessarily-qualified path to remove.
555+
removal_span: Span,
558556
},
559557
}
560558

compiler/rustc_middle/src/lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ pub fn explain_lint_level_source(
278278
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
279279
/// )
280280
/// ```
281+
#[track_caller]
281282
pub fn struct_lint_level(
282283
sess: &Session,
283284
lint: &'static Lint,
@@ -291,6 +292,7 @@ pub fn struct_lint_level(
291292
) {
292293
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
293294
// the "real" work.
295+
#[track_caller]
294296
fn struct_lint_level_impl(
295297
sess: &Session,
296298
lint: &'static Lint,

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ impl<'tcx> TyCtxt<'tcx> {
18601860

18611861
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
18621862
/// typically generated by `#[derive(LintDiagnostic)]`).
1863+
#[track_caller]
18631864
pub fn emit_spanned_lint(
18641865
self,
18651866
lint: &'static Lint,
@@ -1880,6 +1881,7 @@ impl<'tcx> TyCtxt<'tcx> {
18801881
///
18811882
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
18821883
#[rustc_lint_diagnostics]
1884+
#[track_caller]
18831885
pub fn struct_span_lint_hir(
18841886
self,
18851887
lint: &'static Lint,
@@ -1896,6 +1898,7 @@ impl<'tcx> TyCtxt<'tcx> {
18961898

18971899
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
18981900
/// generated by `#[derive(LintDiagnostic)]`).
1901+
#[track_caller]
18991902
pub fn emit_lint(
19001903
self,
19011904
lint: &'static Lint,
@@ -1911,6 +1914,7 @@ impl<'tcx> TyCtxt<'tcx> {
19111914
///
19121915
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
19131916
#[rustc_lint_diagnostics]
1917+
#[track_caller]
19141918
pub fn struct_lint_node(
19151919
self,
19161920
lint: &'static Lint,

compiler/rustc_middle/src/ty/util.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_index::bit_set::GrowableBitSet;
1919
use rustc_macros::HashStable;
2020
use rustc_session::Limit;
2121
use rustc_span::sym;
22-
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
22+
use rustc_target::abi::{Integer, IntegerType, Size};
2323
use rustc_target::spec::abi::Abi;
2424
use smallvec::SmallVec;
2525
use std::{fmt, iter};
@@ -1085,7 +1085,7 @@ impl<'tcx> Ty<'tcx> {
10851085
#[inline]
10861086
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
10871087
// Avoid querying in simple cases.
1088-
match needs_drop_components(self, &tcx.data_layout) {
1088+
match needs_drop_components(tcx, self) {
10891089
Err(AlwaysRequiresDrop) => true,
10901090
Ok(components) => {
10911091
let query_ty = match *components {
@@ -1118,7 +1118,7 @@ impl<'tcx> Ty<'tcx> {
11181118
#[inline]
11191119
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
11201120
// Avoid querying in simple cases.
1121-
match needs_drop_components(self, &tcx.data_layout) {
1121+
match needs_drop_components(tcx, self) {
11221122
Err(AlwaysRequiresDrop) => true,
11231123
Ok(components) => {
11241124
let query_ty = match *components {
@@ -1278,10 +1278,10 @@ impl<'tcx> ExplicitSelf<'tcx> {
12781278
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
12791279
/// this type always needs drop.
12801280
pub fn needs_drop_components<'tcx>(
1281+
tcx: TyCtxt<'tcx>,
12811282
ty: Ty<'tcx>,
1282-
target_layout: &TargetDataLayout,
12831283
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
1284-
match ty.kind() {
1284+
match *ty.kind() {
12851285
ty::Infer(ty::FreshIntTy(_))
12861286
| ty::Infer(ty::FreshFloatTy(_))
12871287
| ty::Bool
@@ -1303,11 +1303,11 @@ pub fn needs_drop_components<'tcx>(
13031303

13041304
ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop),
13051305

1306-
ty::Slice(ty) => needs_drop_components(*ty, target_layout),
1306+
ty::Slice(ty) => needs_drop_components(tcx, ty),
13071307
ty::Array(elem_ty, size) => {
1308-
match needs_drop_components(*elem_ty, target_layout) {
1308+
match needs_drop_components(tcx, elem_ty) {
13091309
Ok(v) if v.is_empty() => Ok(v),
1310-
res => match size.try_to_bits(target_layout.pointer_size) {
1310+
res => match size.try_to_target_usize(tcx) {
13111311
// Arrays of size zero don't need drop, even if their element
13121312
// type does.
13131313
Some(0) => Ok(SmallVec::new()),
@@ -1321,7 +1321,7 @@ pub fn needs_drop_components<'tcx>(
13211321
}
13221322
// If any field needs drop, then the whole tuple does.
13231323
ty::Tuple(fields) => fields.iter().try_fold(SmallVec::new(), move |mut acc, elem| {
1324-
acc.extend(needs_drop_components(elem, target_layout)?);
1324+
acc.extend(needs_drop_components(tcx, elem)?);
13251325
Ok(acc)
13261326
}),
13271327

compiler/rustc_resolve/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3911,8 +3911,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
39113911
&& path[0].ident.name != kw::PathRoot
39123912
&& path[0].ident.name != kw::DollarCrate
39133913
{
3914+
let last_segment = *path.last().unwrap();
39143915
let unqualified_result = {
3915-
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
3916+
match self.resolve_path(&[last_segment], Some(ns), None) {
39163917
PathResult::NonModule(path_res) => path_res.expect_full_res(),
39173918
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
39183919
module.res().unwrap()
@@ -3928,8 +3929,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
39283929
finalize.path_span,
39293930
"unnecessary qualification",
39303931
lint::BuiltinLintDiagnostics::UnusedQualifications {
3931-
path_span: finalize.path_span,
3932-
unqualified_path: path.last().unwrap().ident
3932+
removal_span: finalize.path_span.until(last_segment.ident.span),
39333933
}
39343934
)
39353935
}

compiler/rustc_session/src/parse.rs

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub fn feature_err_issue(
117117
/// Construct a future incompatibility diagnostic for a feature gate.
118118
///
119119
/// This diagnostic is only a warning and *does not cause compilation to fail*.
120+
#[track_caller]
120121
pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) {
121122
feature_warn_issue(sess, feature, span, GateIssue::Language, explain);
122123
}
@@ -129,6 +130,7 @@ pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'st
129130
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
130131
#[allow(rustc::diagnostic_outside_of_impl)]
131132
#[allow(rustc::untranslatable_diagnostic)]
133+
#[track_caller]
132134
pub fn feature_warn_issue(
133135
sess: &ParseSess,
134136
feature: Symbol,
@@ -351,24 +353,28 @@ impl ParseSess {
351353
self.create_warning(warning).emit()
352354
}
353355

356+
#[track_caller]
354357
pub fn create_note<'a>(
355358
&'a self,
356359
note: impl IntoDiagnostic<'a, Noted>,
357360
) -> DiagnosticBuilder<'a, Noted> {
358361
note.into_diagnostic(&self.span_diagnostic)
359362
}
360363

364+
#[track_caller]
361365
pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, Noted>) -> Noted {
362366
self.create_note(note).emit()
363367
}
364368

369+
#[track_caller]
365370
pub fn create_fatal<'a>(
366371
&'a self,
367372
fatal: impl IntoDiagnostic<'a, !>,
368373
) -> DiagnosticBuilder<'a, !> {
369374
fatal.into_diagnostic(&self.span_diagnostic)
370375
}
371376

377+
#[track_caller]
372378
pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
373379
self.create_fatal(fatal).emit()
374380
}
@@ -383,16 +389,19 @@ impl ParseSess {
383389
}
384390

385391
#[rustc_lint_diagnostics]
392+
#[track_caller]
386393
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
387394
self.span_diagnostic.struct_warn(msg)
388395
}
389396

390397
#[rustc_lint_diagnostics]
398+
#[track_caller]
391399
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
392400
self.span_diagnostic.struct_fatal(msg)
393401
}
394402

395403
#[rustc_lint_diagnostics]
404+
#[track_caller]
396405
pub fn struct_diagnostic<G: EmissionGuarantee>(
397406
&self,
398407
msg: impl Into<DiagnosticMessage>,

compiler/rustc_ty_utils/src/needs_drop.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
return Some(Err(AlwaysRequiresDrop));
9797
}
9898

99-
let components = match needs_drop_components(ty, &tcx.data_layout) {
99+
let components = match needs_drop_components(tcx, ty) {
100100
Err(e) => return Some(Err(e)),
101101
Ok(components) => components,
102102
};
@@ -160,7 +160,7 @@ where
160160
queue_type(self, required);
161161
}
162162
}
163-
ty::Array(..) | ty::Alias(..) | ty::Param(_) => {
163+
ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => {
164164
if ty == component {
165165
// Return the type to the caller: they may be able
166166
// to normalize further than we can.
@@ -172,7 +172,31 @@ where
172172
queue_type(self, component);
173173
}
174174
}
175-
_ => return Some(Err(AlwaysRequiresDrop)),
175+
176+
ty::Foreign(_) | ty::Dynamic(..) => {
177+
return Some(Err(AlwaysRequiresDrop));
178+
}
179+
180+
ty::Bool
181+
| ty::Char
182+
| ty::Int(_)
183+
| ty::Uint(_)
184+
| ty::Float(_)
185+
| ty::Str
186+
| ty::Slice(_)
187+
| ty::Ref(..)
188+
| ty::RawPtr(..)
189+
| ty::FnDef(..)
190+
| ty::FnPtr(..)
191+
| ty::Tuple(_)
192+
| ty::Bound(..)
193+
| ty::GeneratorWitness(..)
194+
| ty::GeneratorWitnessMIR(..)
195+
| ty::Never
196+
| ty::Infer(_)
197+
| ty::Error(_) => {
198+
bug!("unexpected type returned by `needs_drop_components`: {component}")
199+
}
176200
}
177201
}
178202
}

src/librustdoc/html/static/css/rustdoc.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
888888
justify-content: start;
889889
flex: 3;
890890
}
891-
.search-results .result-name span.alias {
891+
.search-results .result-name .alias {
892892
color: var(--search-results-alias-color);
893893
}
894894
.search-results .result-name .grey {
@@ -904,6 +904,9 @@ so that we can apply CSS-filters to change the arrow color in themes */
904904
max-width: calc(100% - var(--search-typename-width));
905905
display: inline-block;
906906
}
907+
.search-results .result-name .path > * {
908+
display: inline;
909+
}
907910

908911
.popover {
909912
position: absolute;

src/librustdoc/html/static/js/search.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -2108,29 +2108,22 @@ function initSearch(rawSearchIndex) {
21082108
const resultName = document.createElement("div");
21092109
resultName.className = "result-name";
21102110

2111-
if (item.is_alias) {
2112-
const alias = document.createElement("span");
2113-
alias.className = "alias";
2114-
2115-
const bold = document.createElement("b");
2116-
bold.innerText = item.alias;
2117-
alias.appendChild(bold);
2118-
2119-
alias.insertAdjacentHTML(
2120-
"beforeend",
2121-
"<i class=\"grey\">&nbsp;- see&nbsp;</i>");
2111+
resultName.insertAdjacentHTML(
2112+
"beforeend",
2113+
`<span class="typename">${typeName}</span>`);
2114+
link.appendChild(resultName);
21222115

2123-
resultName.appendChild(alias);
2116+
let alias = " ";
2117+
if (item.is_alias) {
2118+
alias = ` <div class="alias">\
2119+
<b>${item.alias}</b><i class="grey">&nbsp;- see&nbsp;</i>\
2120+
</div>`;
21242121
}
2125-
21262122
resultName.insertAdjacentHTML(
21272123
"beforeend",
2128-
`\
2129-
<span class="typename">${typeName}</span>\
2130-
<div class="path">\
2131-
${item.displayPath}<span class="${type}">${name}</span>\
2124+
`<div class="path">${alias}\
2125+
${item.displayPath}<span class="${type}">${name}</span>\
21322126
</div>`);
2133-
link.appendChild(resultName);
21342127

21352128
const description = document.createElement("div");
21362129
description.className = "desc";

tests/rustdoc-gui/search-reexport.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ write: (".search-input", "AliasForTheStdReexport")
2626
wait-for: "//a[@class='result-import']"
2727
assert-text: (
2828
"a.result-import .result-name",
29-
"AliasForTheStdReexport - see re-export test_docs::TheStdReexport",
29+
"re-export AliasForTheStdReexport - see test_docs::TheStdReexport",
3030
)
3131
// Same thing again, we click on it to ensure the background is once again set as expected.
3232
click: "//a[@class='result-import']"

tests/rustdoc-gui/search-result-color.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ define-function: (
368368
// Waiting for the search results to appear...
369369
wait-for: "#search-tabs"
370370
// Checking that the colors for the alias element are the ones expected.
371-
assert-css: (".result-name > .alias", {"color": |alias|})
372-
assert-css: (".result-name > .alias > .grey", {"color": |grey|})
371+
assert-css: (".result-name .path .alias", {"color": |alias|})
372+
assert-css: (".result-name .path .alias > .grey", {"color": |grey|})
373373
// Leave the search results to prevent reloading with an already filled search input.
374374
press-key: "Escape"
375375
},

0 commit comments

Comments
 (0)