Skip to content

Commit

Permalink
Auto merge of rust-lang#134411 - jhpratt:rollup-3ozrvej, r=jhpratt
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#133265 (Add a range argument to vec.extract_if)
 - rust-lang#134202 (Remove `rustc::existing_doc_keyword` lint)
 - rust-lang#134354 (Handle fndef rendering together with signature rendering)
 - rust-lang#134365 (Rename `rustc_mir_build::build` to `builder`)
 - rust-lang#134368 (Use links to edition guide for edition migrations)
 - rust-lang#134388 (Update books)
 - rust-lang#134397 (rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable)
 - rust-lang#134398 (AIX: add alignment info for test)
 - rust-lang#134400 (Fix some comments related to upvars handling)

Failed merges:

 - rust-lang#134399 (Do not do if ! else, use unnegated cond and swap the branches instead)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 17, 2024
2 parents 978c659 + e780f52 commit 124dab9
Show file tree
Hide file tree
Showing 121 changed files with 547 additions and 531 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4275,7 +4275,6 @@ dependencies = [
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_lexer",
"rustc_macros",
"rustc_middle",
"rustc_privacy",
Expand Down
30 changes: 20 additions & 10 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,16 +1474,27 @@ fn suggest_ampmut<'tcx>(
// let x: &i32 = &'a 5;
// ^^ lifetime annotation not allowed
//
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
&& let Some(stripped) = src.strip_prefix('&')
if let Some(rhs_span) = opt_assignment_rhs_span
&& let Ok(rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span)
&& let Some(rhs_str_no_amp) = rhs_str.strip_prefix('&')
{
let is_raw_ref = stripped.trim_start().starts_with("raw ");
// We don't support raw refs yet
if is_raw_ref {
return None;
// Suggest changing `&raw const` to `&raw mut` if applicable.
if rhs_str_no_amp.trim_start().strip_prefix("raw const").is_some() {
let const_idx = rhs_str.find("const").unwrap() as u32;
let const_span = rhs_span
.with_lo(rhs_span.lo() + BytePos(const_idx))
.with_hi(rhs_span.lo() + BytePos(const_idx + "const".len() as u32));

return Some(AmpMutSugg {
has_sugg: true,
span: const_span,
suggestion: "mut".to_owned(),
additional: None,
});
}
let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") {

// Figure out if rhs already is `&mut`.
let is_mut = if let Some(rest) = rhs_str_no_amp.trim_start().strip_prefix("mut") {
match rest.chars().next() {
// e.g. `&mut x`
Some(c) if c.is_whitespace() => true,
Expand All @@ -1500,9 +1511,8 @@ fn suggest_ampmut<'tcx>(
// if the reference is already mutable then there is nothing we can do
// here.
if !is_mut {
let span = assignment_rhs_span;
// shrink the span to just after the `&` in `&variable`
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
let span = rhs_span.with_lo(rhs_span.lo() + BytePos(1)).shrink_to_lo();

// FIXME(Ezrashaw): returning is bad because we still might want to
// update the annotated type, see #106857.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,18 +1569,18 @@ impl DiagCtxtInner {
debug!(?diagnostic);
debug!(?self.emitted_diagnostics);

let already_emitted_sub = |sub: &mut Subdiag| {
let not_yet_emitted = |sub: &mut Subdiag| {
debug!(?sub);
if sub.level != OnceNote && sub.level != OnceHelp {
return false;
return true;
}
let mut hasher = StableHasher::new();
sub.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
debug!(?diagnostic_hash);
!self.emitted_diagnostics.insert(diagnostic_hash)
self.emitted_diagnostics.insert(diagnostic_hash)
};
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
diagnostic.children.retain_mut(not_yet_emitted);
if already_emitted {
let msg = "duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`";
diagnostic.sub(Note, msg, MultiSpan::new());
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! to everything owned by `x`, so the result is the same for something
//! like `x.f = 5` and so on (presuming `x` is not a borrowed pointer to a
//! struct). These adjustments are performed in
//! `adjust_upvar_borrow_kind()` (you can trace backwards through the code
//! `adjust_for_non_move_closure` (you can trace backwards through the code
//! from there).
//!
//! The fact that we are inferring borrow kinds as we go results in a
Expand Down Expand Up @@ -1684,8 +1684,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// want to capture by ref to allow precise capture using reborrows.
//
// If the data will be moved out of this place, then the place will be truncated
// at the first Deref in `adjust_upvar_borrow_kind_for_consume` and then moved into
// the closure.
// at the first Deref in `adjust_for_move_closure` and then moved into the closure.
hir::CaptureBy::Value { .. } if !place.deref_tys().any(Ty::is_ref) => {
ty::UpvarCapture::ByValue
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,6 @@ lint_non_camel_case_type = {$sort} `{$name}` should have an upper camel case nam
.suggestion = convert the identifier to upper camel case
.label = should have an UpperCamelCase name
lint_non_existent_doc_keyword = found non-existing keyword `{$keyword}` used in `#[doc(keyword = "...")]`
.help = only existing keywords are allowed in core/std
lint_non_fmt_panic = panic message is not a string literal
.note = this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021
.more_info_note = for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ declare_lint! {
"detects edition keywords being used as an identifier",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/gen-keyword.html>",
};
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ declare_lint! {
rewriting in `match` is an option to preserve the semantics up to Edition 2021",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "issue #124085 <https://github.com/rust-lang/rust/issues/124085>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>",
};
}

Expand Down
44 changes: 2 additions & 42 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Span;
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{Symbol, kw, sym};
use rustc_span::symbol::sym;
use tracing::debug;

use crate::lints::{
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand,
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag,
SymbolInternStringLiteralDiag, TyQualified, TykindDiag, TykindKind, TypeIrInherentUsage,
UntranslatableDiag,
Expand Down Expand Up @@ -375,46 +375,6 @@ impl EarlyLintPass for LintPassImpl {
}
}

declare_tool_lint! {
/// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
/// that don't exist, e.g. `#[doc(keyword = "..")]`.
pub rustc::EXISTING_DOC_KEYWORD,
Allow,
"Check that documented keywords in std and core actually exist",
report_in_external_macro: true
}

declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);

fn is_doc_keyword(s: Symbol) -> bool {
s <= kw::Union
}

impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
for attr in cx.tcx.hir().attrs(item.hir_id()) {
if !attr.has_name(sym::doc) {
continue;
}
if let Some(list) = attr.meta_item_list() {
for nested in list {
if nested.has_name(sym::keyword) {
let keyword = nested
.value_str()
.expect("#[doc(keyword = \"...\")] expected a value!");
if is_doc_keyword(keyword) {
return;
}
cx.emit_span_lint(EXISTING_DOC_KEYWORD, attr.span, NonExistentDocKeyword {
keyword,
});
}
}
}
}
}
}

declare_tool_lint! {
/// The `untranslatable_diagnostic` lint detects messages passed to functions with `impl
/// Into<{D,Subd}iagMessage` parameters without using translatable Fluent strings.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,6 @@ fn register_internals(store: &mut LintStore) {
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
store.register_lints(&QueryStability::lint_vec());
store.register_late_mod_pass(|_| Box::new(QueryStability));
store.register_lints(&ExistingDocKeyword::lint_vec());
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
store.register_lints(&TyTyKind::lint_vec());
store.register_late_mod_pass(|_| Box::new(TyTyKind));
store.register_lints(&TypeIr::lint_vec());
Expand Down Expand Up @@ -629,7 +627,6 @@ fn register_internals(store: &mut LintStore) {
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
LintId::of(USAGE_OF_QUALIFIED_TY),
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
LintId::of(EXISTING_DOC_KEYWORD),
LintId::of(BAD_OPT_ACCESS),
LintId::of(SPAN_USE_EQ_CTXT),
]);
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,6 @@ pub(crate) struct NonGlobImportTypeIrInherent {
#[help]
pub(crate) struct LintPassByHand;

#[derive(LintDiagnostic)]
#[diag(lint_non_existent_doc_keyword)]
#[help]
pub(crate) struct NonExistentDocKeyword {
pub keyword: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(lint_diag_out_of_impl)]
pub(crate) struct DiagOutOfImpl;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/non_ascii_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl EarlyLintPass for NonAsciiIdents {
(IdentifierType::Not_NFKC, "Not_NFKC"),
] {
let codepoints: Vec<_> =
chars.extract_if(|(_, ty)| *ty == Some(id_ty)).collect();
chars.extract_if(.., |(_, ty)| *ty == Some(id_ty)).collect();
if codepoints.is_empty() {
continue;
}
Expand All @@ -217,7 +217,7 @@ impl EarlyLintPass for NonAsciiIdents {
}

let remaining = chars
.extract_if(|(c, _)| !GeneralSecurityProfile::identifier_allowed(*c))
.extract_if(.., |(c, _)| !GeneralSecurityProfile::identifier_allowed(*c))
.collect::<Vec<_>>();
if !remaining.is_empty() {
cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/shadowed_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare_lint! {
"detects calling `into_iter` on boxed slices in Rust 2015, 2018, and 2021",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/intoiterator-box-slice.html>"
};
}

Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ declare_lint! {
"detects patterns whose meaning will change in Rust 2024",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "123076",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>",
};
}

Expand Down Expand Up @@ -2606,7 +2606,7 @@ declare_lint! {
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "issue #71668 <https://github.com/rust-lang/rust/issues/71668>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>",
explain_reason: false
};
@edition Edition2024 => Warn;
Expand Down Expand Up @@ -4189,7 +4189,7 @@ declare_lint! {
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
};
@edition Edition2024 => Deny;
report_in_external_macro
Expand Down Expand Up @@ -4243,7 +4243,7 @@ declare_lint! {
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
};
report_in_external_macro
}
Expand Down Expand Up @@ -4790,7 +4790,7 @@ declare_lint! {
"detects unsafe functions being used as safe functions",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
reference: "issue #27970 <https://github.com/rust-lang/rust/issues/27970>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/newly-unsafe-functions.html>",
};
}

Expand Down Expand Up @@ -4826,7 +4826,7 @@ declare_lint! {
"detects missing unsafe keyword on extern declarations",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
reference: "issue #123743 <https://github.com/rust-lang/rust/issues/123743>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-extern.html>",
};
}

Expand Down Expand Up @@ -4867,7 +4867,7 @@ declare_lint! {
"detects unsafe attributes outside of unsafe",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
reference: "issue #123757 <https://github.com/rust-lang/rust/issues/123757>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-attributes.html>",
};
}

Expand Down Expand Up @@ -5069,7 +5069,7 @@ declare_lint! {
"Detect and warn on significant change in drop order in tail expression location",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
reference: "issue #123739 <https://github.com/rust-lang/rust/issues/123739>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>",
};
}

Expand Down Expand Up @@ -5108,7 +5108,7 @@ declare_lint! {
"will be parsed as a guarded string in Rust 2024",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
reference: "issue #123735 <https://github.com/rust-lang/rust/issues/123735>",
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/reserved-syntax.html>",
};
crate_level_only
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl<'tcx> Collector<'tcx> {
// can move them to the end of the list below.
let mut existing = self
.libs
.extract_if(|lib| {
.extract_if(.., |lib| {
if lib.name.as_str() == passed_lib.name {
// FIXME: This whole logic is questionable, whether modifiers are
// involved or not, library reordering and kind overriding without
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub fn suggest_constraining_type_params<'a>(
let Some(param) = param else { return false };

{
let mut sized_constraints = constraints.extract_if(|(_, def_id, _)| {
let mut sized_constraints = constraints.extract_if(.., |(_, def_id, _)| {
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
});
if let Some((_, def_id, _)) = sized_constraints.next() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use rustc_middle::{span_bug, ty};
use rustc_span::Span;
use tracing::debug;

use crate::build::ForGuard::OutsideGuard;
use crate::build::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
use crate::builder::ForGuard::OutsideGuard;
use crate::builder::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder};

impl<'a, 'tcx> Builder<'a, 'tcx> {
pub(crate) fn ast_block(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use tracing::debug;

use crate::build::CFG;
use crate::builder::CFG;

impl<'tcx> CFG<'tcx> {
pub(crate) fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use rustc_middle::thir::{ExprId, ExprKind, Pat, Thir};
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::LocalDefId;

use crate::build::coverageinfo::mcdc::MCDCInfoBuilder;
use crate::build::{Builder, CFG};
use crate::builder::coverageinfo::mcdc::MCDCInfoBuilder;
use crate::builder::{Builder, CFG};

mod mcdc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::thir::LogicalOp;
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;

use crate::build::Builder;
use crate::builder::Builder;
use crate::errors::MCDCExceedsConditionLimit;

/// LLVM uses `i16` to represent condition id. Hence `i16::MAX` is the hard limit for number of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use rustc_span::Span;
use rustc_span::source_map::Spanned;

use super::{PResult, ParseCtxt, parse_by_kind};
use crate::build::custom::ParseError;
use crate::build::expr::as_constant::as_constant_inner;
use crate::builder::custom::ParseError;
use crate::builder::expr::as_constant::as_constant_inner;

impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
pub(crate) fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
Expand Down
Loading

0 comments on commit 124dab9

Please sign in to comment.