Skip to content

Commit

Permalink
Auto merge of #113837 - matthiaskrgr:rollup-v4xud4s, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 18, 2023
2 parents 8d361cb + 4bbd781 commit 42a982d
Show file tree
Hide file tree
Showing 22 changed files with 212 additions and 58 deletions.
1 change: 0 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ Cargo
-----
- [Allow named debuginfo options in `Cargo.toml`.](https://github.com/rust-lang/cargo/pull/11958/)
- [Add `workspace_default_members` to the output of `cargo metadata`.](https://github.com/rust-lang/cargo/pull/11978/)
- [`cargo add` now considers `rust-version` when selecting packages.](https://github.com/rust-lang/cargo/pull/12078/)
- [Automatically inherit workspace fields when running `cargo new`/`cargo init`.](https://github.com/rust-lang/cargo/pull/12069/)

<a id="1.71.0-Rustdoc"></a>
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,11 @@ pub trait LintContext: Sized {
db.span_note(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace));
db.span_note(private_item_span, "but the private item here shadows it".to_owned());
}
BuiltinLintDiagnostics::UnusedQualifications { path_span, unqualified_path } => {
BuiltinLintDiagnostics::UnusedQualifications { removal_span } => {
db.span_suggestion_verbose(
path_span,
"replace it with the unqualified path",
unqualified_path,
removal_span,
"remove the unnecessary path segments",
"",
Applicability::MachineApplicable
);
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
/// Returns `true` if the lint's feature is enabled.
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
#[track_caller]
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
if let Some(feature) = lint_id.lint.feature_gate {
if !self.sess.features_untracked().enabled(feature) {
Expand Down Expand Up @@ -1015,6 +1016,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
#[track_caller]
pub(crate) fn struct_lint(
&self,
lint: &'static Lint,
Expand All @@ -1028,6 +1030,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
}

#[track_caller]
pub fn emit_spanned_lint(
&self,
lint: &'static Lint,
Expand All @@ -1040,6 +1043,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
});
}

#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
let (level, src) = self.lint_level(lint);
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,8 @@ pub enum BuiltinLintDiagnostics {
private_item_span: Span,
},
UnusedQualifications {
/// The span of the unnecessarily-qualified path.
path_span: Span,
/// The replacement unqualified path.
unqualified_path: Ident,
/// The span of the unnecessarily-qualified path to remove.
removal_span: Span,
},
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ pub fn explain_lint_level_source(
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
/// )
/// ```
#[track_caller]
pub fn struct_lint_level(
sess: &Session,
lint: &'static Lint,
Expand All @@ -291,6 +292,7 @@ pub fn struct_lint_level(
) {
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work.
#[track_caller]
fn struct_lint_level_impl(
sess: &Session,
lint: &'static Lint,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,7 @@ impl<'tcx> TyCtxt<'tcx> {

/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_spanned_lint(
self,
lint: &'static Lint,
Expand All @@ -1880,6 +1881,7 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_span_lint_hir(
self,
lint: &'static Lint,
Expand All @@ -1896,6 +1898,7 @@ impl<'tcx> TyCtxt<'tcx> {

/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_lint(
self,
lint: &'static Lint,
Expand All @@ -1911,6 +1914,7 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_lint_node(
self,
lint: &'static Lint,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_index::bit_set::GrowableBitSet;
use rustc_macros::HashStable;
use rustc_session::Limit;
use rustc_span::sym;
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
use rustc_target::abi::{Integer, IntegerType, Size};
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;
use std::{fmt, iter};
Expand Down Expand Up @@ -1085,7 +1085,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
// Avoid querying in simple cases.
match needs_drop_components(self, &tcx.data_layout) {
match needs_drop_components(tcx, self) {
Err(AlwaysRequiresDrop) => true,
Ok(components) => {
let query_ty = match *components {
Expand Down Expand Up @@ -1118,7 +1118,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
// Avoid querying in simple cases.
match needs_drop_components(self, &tcx.data_layout) {
match needs_drop_components(tcx, self) {
Err(AlwaysRequiresDrop) => true,
Ok(components) => {
let query_ty = match *components {
Expand Down Expand Up @@ -1278,10 +1278,10 @@ impl<'tcx> ExplicitSelf<'tcx> {
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
/// this type always needs drop.
pub fn needs_drop_components<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
target_layout: &TargetDataLayout,
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
match ty.kind() {
match *ty.kind() {
ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Bool
Expand All @@ -1303,11 +1303,11 @@ pub fn needs_drop_components<'tcx>(

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

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3911,8 +3911,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
&& path[0].ident.name != kw::PathRoot
&& path[0].ident.name != kw::DollarCrate
{
let last_segment = *path.last().unwrap();
let unqualified_result = {
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
match self.resolve_path(&[last_segment], Some(ns), None) {
PathResult::NonModule(path_res) => path_res.expect_full_res(),
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
module.res().unwrap()
Expand All @@ -3928,8 +3929,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
finalize.path_span,
"unnecessary qualification",
lint::BuiltinLintDiagnostics::UnusedQualifications {
path_span: finalize.path_span,
unqualified_path: path.last().unwrap().ident
removal_span: finalize.path_span.until(last_segment.ident.span),
}
)
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn feature_err_issue(
/// Construct a future incompatibility diagnostic for a feature gate.
///
/// This diagnostic is only a warning and *does not cause compilation to fail*.
#[track_caller]
pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) {
feature_warn_issue(sess, feature, span, GateIssue::Language, explain);
}
Expand All @@ -129,6 +130,7 @@ pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'st
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
#[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)]
#[track_caller]
pub fn feature_warn_issue(
sess: &ParseSess,
feature: Symbol,
Expand Down Expand Up @@ -351,24 +353,28 @@ impl ParseSess {
self.create_warning(warning).emit()
}

#[track_caller]
pub fn create_note<'a>(
&'a self,
note: impl IntoDiagnostic<'a, Noted>,
) -> DiagnosticBuilder<'a, Noted> {
note.into_diagnostic(&self.span_diagnostic)
}

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

#[track_caller]
pub fn create_fatal<'a>(
&'a self,
fatal: impl IntoDiagnostic<'a, !>,
) -> DiagnosticBuilder<'a, !> {
fatal.into_diagnostic(&self.span_diagnostic)
}

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

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

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

#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_diagnostic<G: EmissionGuarantee>(
&self,
msg: impl Into<DiagnosticMessage>,
Expand Down
30 changes: 27 additions & 3 deletions compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ where
return Some(Err(AlwaysRequiresDrop));
}

let components = match needs_drop_components(ty, &tcx.data_layout) {
let components = match needs_drop_components(tcx, ty) {
Err(e) => return Some(Err(e)),
Ok(components) => components,
};
Expand Down Expand Up @@ -160,7 +160,7 @@ where
queue_type(self, required);
}
}
ty::Array(..) | ty::Alias(..) | ty::Param(_) => {
ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => {
if ty == component {
// Return the type to the caller: they may be able
// to normalize further than we can.
Expand All @@ -172,7 +172,31 @@ where
queue_type(self, component);
}
}
_ => return Some(Err(AlwaysRequiresDrop)),

ty::Foreign(_) | ty::Dynamic(..) => {
return Some(Err(AlwaysRequiresDrop));
}

ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Str
| ty::Slice(_)
| ty::Ref(..)
| ty::RawPtr(..)
| ty::FnDef(..)
| ty::FnPtr(..)
| ty::Tuple(_)
| ty::Bound(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Never
| ty::Infer(_)
| ty::Error(_) => {
bug!("unexpected type returned by `needs_drop_components`: {component}")
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
justify-content: start;
flex: 3;
}
.search-results .result-name span.alias {
.search-results .result-name .alias {
color: var(--search-results-alias-color);
}
.search-results .result-name .grey {
Expand All @@ -904,6 +904,9 @@ so that we can apply CSS-filters to change the arrow color in themes */
max-width: calc(100% - var(--search-typename-width));
display: inline-block;
}
.search-results .result-name .path > * {
display: inline;
}

.popover {
position: absolute;
Expand Down
29 changes: 11 additions & 18 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2108,29 +2108,22 @@ function initSearch(rawSearchIndex) {
const resultName = document.createElement("div");
resultName.className = "result-name";

if (item.is_alias) {
const alias = document.createElement("span");
alias.className = "alias";

const bold = document.createElement("b");
bold.innerText = item.alias;
alias.appendChild(bold);

alias.insertAdjacentHTML(
"beforeend",
"<i class=\"grey\">&nbsp;- see&nbsp;</i>");
resultName.insertAdjacentHTML(
"beforeend",
`<span class="typename">${typeName}</span>`);
link.appendChild(resultName);

resultName.appendChild(alias);
let alias = " ";
if (item.is_alias) {
alias = ` <div class="alias">\
<b>${item.alias}</b><i class="grey">&nbsp;- see&nbsp;</i>\
</div>`;
}

resultName.insertAdjacentHTML(
"beforeend",
`\
<span class="typename">${typeName}</span>\
<div class="path">\
${item.displayPath}<span class="${type}">${name}</span>\
`<div class="path">${alias}\
${item.displayPath}<span class="${type}">${name}</span>\
</div>`);
link.appendChild(resultName);

const description = document.createElement("div");
description.className = "desc";
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/search-reexport.goml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ write: (".search-input", "AliasForTheStdReexport")
wait-for: "//a[@class='result-import']"
assert-text: (
"a.result-import .result-name",
"AliasForTheStdReexport - see re-export test_docs::TheStdReexport",
"re-export AliasForTheStdReexport - see test_docs::TheStdReexport",
)
// Same thing again, we click on it to ensure the background is once again set as expected.
click: "//a[@class='result-import']"
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-gui/search-result-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ define-function: (
// Waiting for the search results to appear...
wait-for: "#search-tabs"
// Checking that the colors for the alias element are the ones expected.
assert-css: (".result-name > .alias", {"color": |alias|})
assert-css: (".result-name > .alias > .grey", {"color": |grey|})
assert-css: (".result-name .path .alias", {"color": |alias|})
assert-css: (".result-name .path .alias > .grey", {"color": |grey|})
// Leave the search results to prevent reloading with an already filled search input.
press-key: "Escape"
},
Expand Down
Loading

0 comments on commit 42a982d

Please sign in to comment.