Skip to content

Commit 0ddead3

Browse files
committed
Auto merge of rust-lang#128748 - matthiaskrgr:rollup-dzvi5f7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#128369 (rustc_lint: make `let-underscore-lock` translatable) - rust-lang#128377 (Fix ICE Caused by Incorrectly Delaying E0107) - rust-lang#128517 (Fallback to string formatting if source is not available for lint) - rust-lang#128685 (Remove the root Cargo.lock from the rust-src component) - rust-lang#128693 (rustdoc-search: account for numeric disambiguators on impls) - rust-lang#128720 (Pass the right `ParamEnv` to `might_permit_raw_init_strict`) - rust-lang#128736 (Fix rustdoc missing handling of remap-path-prefix option) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 60d1465 + 47a2f14 commit 0ddead3

File tree

18 files changed

+234
-61
lines changed

18 files changed

+234
-61
lines changed

compiler/rustc_const_eval/src/util/check_validity_requirement.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_middle::bug;
22
use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement};
3-
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
3+
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
44
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};
55

66
use crate::const_eval::{CanAccessMutGlobal, CheckAlignment, CompileTimeMachine};
@@ -30,10 +30,10 @@ pub fn check_validity_requirement<'tcx>(
3030
return Ok(!layout.abi.is_uninhabited());
3131
}
3232

33+
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
3334
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
34-
might_permit_raw_init_strict(layout, tcx, kind)
35+
might_permit_raw_init_strict(layout, &layout_cx, kind)
3536
} else {
36-
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
3737
might_permit_raw_init_lax(layout, &layout_cx, kind)
3838
}
3939
}
@@ -42,12 +42,12 @@ pub fn check_validity_requirement<'tcx>(
4242
/// details.
4343
fn might_permit_raw_init_strict<'tcx>(
4444
ty: TyAndLayout<'tcx>,
45-
tcx: TyCtxt<'tcx>,
45+
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
4646
kind: ValidityRequirement,
4747
) -> Result<bool, &'tcx LayoutError<'tcx>> {
4848
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
4949

50-
let mut cx = InterpCx::new(tcx, rustc_span::DUMMY_SP, ParamEnv::reveal_all(), machine);
50+
let mut cx = InterpCx::new(cx.tcx, rustc_span::DUMMY_SP, cx.param_env, machine);
5151

5252
let allocated = cx
5353
.allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))

compiler/rustc_hir/src/hir.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,11 @@ impl<'hir> OwnerNode<'hir> {
37003700
}
37013701
}
37023702

3703+
/// Check if node is an impl block.
3704+
pub fn is_impl_block(&self) -> bool {
3705+
matches!(self, OwnerNode::Item(Item { kind: ItemKind::Impl(_), .. }))
3706+
}
3707+
37033708
expect_methods_self! {
37043709
expect_item, &'hir Item<'hir>, OwnerNode::Item(n), n;
37053710
expect_foreign_item, &'hir ForeignItem<'hir>, OwnerNode::ForeignItem(n), n;

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -552,21 +552,34 @@ pub(crate) fn check_generic_arg_count(
552552
synth_provided,
553553
}
554554
} else {
555-
let num_missing_args = expected_max - provided;
555+
// Check if associated type bounds are incorrectly written in impl block header like:
556+
// ```
557+
// trait Foo<T> {}
558+
// impl Foo<T: Default> for u8 {}
559+
// ```
560+
let parent_is_impl_block = cx
561+
.tcx()
562+
.hir()
563+
.parent_owner_iter(seg.hir_id)
564+
.next()
565+
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
566+
if parent_is_impl_block {
567+
let constraint_names: Vec<_> =
568+
gen_args.constraints.iter().map(|b| b.ident.name).collect();
569+
let param_names: Vec<_> = gen_params
570+
.own_params
571+
.iter()
572+
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
573+
.map(|param| param.name)
574+
.collect();
575+
if constraint_names == param_names {
576+
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
577+
// to provide a succinct error for cases like issue #113073
578+
all_params_are_binded = true;
579+
};
580+
}
556581

557-
let constraint_names: Vec<_> =
558-
gen_args.constraints.iter().map(|b| b.ident.name).collect();
559-
let param_names: Vec<_> = gen_params
560-
.own_params
561-
.iter()
562-
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
563-
.map(|param| param.name)
564-
.collect();
565-
if constraint_names == param_names {
566-
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
567-
// to provide a succinct error for cases like issue #113073
568-
all_params_are_binded = true;
569-
};
582+
let num_missing_args = expected_max - provided;
570583

571584
GenericArgsInfo::MissingTypesOrConsts {
572585
num_missing_args,

compiler/rustc_lint/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ lint_non_binding_let_multi_suggestion =
518518
lint_non_binding_let_on_drop_type =
519519
non-binding let on a type that implements `Drop`
520520
521-
lint_non_binding_let_on_sync_lock =
522-
non-binding let on a synchronization lock
521+
lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
522+
.label = this lock is not assigned to a binding and is immediately dropped
523523
524524
lint_non_binding_let_suggestion =
525525
consider binding to an unused variable to avoid immediately dropping the value

compiler/rustc_lint/src/let_underscore.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [
104104
];
105105

106106
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
107-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
108107
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
109108
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
110109
return;
@@ -156,12 +155,12 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
156155
is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)),
157156
};
158157
if is_sync_lock {
159-
let mut span = MultiSpan::from_span(pat.span);
160-
span.push_span_label(
161-
pat.span,
162-
"this lock is not assigned to a binding and is immediately dropped".to_string(),
158+
let span = MultiSpan::from_span(pat.span);
159+
cx.emit_span_lint(
160+
LET_UNDERSCORE_LOCK,
161+
span,
162+
NonBindingLet::SyncLock { sub, pat: pat.span },
163163
);
164-
cx.emit_span_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub });
165164
// Only emit let_underscore_drop for top-level `_` patterns.
166165
} else if can_use_init.is_some() {
167166
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });

compiler/rustc_lint/src/lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,8 @@ pub struct BadOptAccessDiag<'a> {
957957
pub enum NonBindingLet {
958958
#[diag(lint_non_binding_let_on_sync_lock)]
959959
SyncLock {
960+
#[label]
961+
pat: Span,
960962
#[subdiagnostic]
961963
sub: NonBindingLetSub,
962964
},

compiler/rustc_lint/src/types.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,11 @@ fn lint_int_literal<'tcx>(
458458
}
459459

460460
let span = if negative { type_limits.negated_expr_span.unwrap() } else { e.span };
461-
let lit =
462-
cx.sess().source_map().span_to_snippet(span).expect("must get snippet from literal");
461+
let lit = cx
462+
.sess()
463+
.source_map()
464+
.span_to_snippet(span)
465+
.unwrap_or_else(|_| if negative { format!("-{v}") } else { v.to_string() });
463466
let help = get_type_suggestion(cx.typeck_results().node_type(e.hir_id), v, negative)
464467
.map(|suggestion_ty| OverflowingIntHelp { suggestion_ty });
465468

@@ -485,6 +488,7 @@ fn lint_uint_literal<'tcx>(
485488
ast::LitKind::Int(v, _) => v.get(),
486489
_ => bug!(),
487490
};
491+
488492
if lit_val < min || lit_val > max {
489493
if let Node::Expr(par_e) = cx.tcx.parent_hir_node(e.hir_id) {
490494
match par_e.kind {
@@ -526,7 +530,7 @@ fn lint_uint_literal<'tcx>(
526530
.sess()
527531
.source_map()
528532
.span_to_snippet(lit.span)
529-
.expect("must get snippet from literal"),
533+
.unwrap_or_else(|_| lit_val.to_string()),
530534
min,
531535
max,
532536
},
@@ -551,14 +555,14 @@ fn lint_literal<'tcx>(
551555
}
552556
ty::Uint(t) => lint_uint_literal(cx, e, lit, t),
553557
ty::Float(t) => {
554-
let is_infinite = match lit.node {
558+
let (is_infinite, sym) = match lit.node {
555559
ast::LitKind::Float(v, _) => match t {
556560
// FIXME(f16_f128): add this check once `is_infinite` is reliable (ABI
557561
// issues resolved).
558-
ty::FloatTy::F16 => Ok(false),
559-
ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
560-
ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
561-
ty::FloatTy::F128 => Ok(false),
562+
ty::FloatTy::F16 => (Ok(false), v),
563+
ty::FloatTy::F32 => (v.as_str().parse().map(f32::is_infinite), v),
564+
ty::FloatTy::F64 => (v.as_str().parse().map(f64::is_infinite), v),
565+
ty::FloatTy::F128 => (Ok(false), v),
562566
},
563567
_ => bug!(),
564568
};
@@ -572,7 +576,7 @@ fn lint_literal<'tcx>(
572576
.sess()
573577
.source_map()
574578
.span_to_snippet(lit.span)
575-
.expect("must get snippet from literal"),
579+
.unwrap_or_else(|_| sym.to_string()),
576580
},
577581
);
578582
}

src/bootstrap/src/core/build_steps/dist.rs

-4
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ impl Step for Src {
918918
// translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
919919
let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");
920920

921-
let src_files = ["Cargo.lock"];
922921
// This is the reduced set of paths which will become the rust-src component
923922
// (essentially libstd and all of its path dependencies).
924923
copy_src_dirs(
@@ -937,9 +936,6 @@ impl Step for Src {
937936
],
938937
&dst_src,
939938
);
940-
for file in src_files.iter() {
941-
builder.copy_link(&builder.src.join(file), &dst_src.join(file));
942-
}
943939

944940
tarball.generate()
945941
}

src/librustdoc/core.rs

+2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub(crate) fn create_config(
195195
lint_cap,
196196
scrape_examples_options,
197197
expanded_args,
198+
remap_path_prefix,
198199
..
199200
}: RustdocOptions,
200201
RenderOptions { document_private, .. }: &RenderOptions,
@@ -247,6 +248,7 @@ pub(crate) fn create_config(
247248
describe_lints,
248249
crate_name,
249250
test,
251+
remap_path_prefix,
250252
..Options::default()
251253
};
252254

src/librustdoc/html/static/js/main.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -390,24 +390,30 @@ function preLoadCss(cssUrl) {
390390
if (splitAt !== -1) {
391391
const implId = savedHash.slice(0, splitAt);
392392
const assocId = savedHash.slice(splitAt + 1);
393-
const implElem = document.getElementById(implId);
394-
if (implElem && implElem.parentElement.tagName === "SUMMARY" &&
395-
implElem.parentElement.parentElement.tagName === "DETAILS") {
396-
onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
393+
const implElems = document.querySelectorAll(
394+
`details > summary > section[id^="${implId}"]`,
395+
);
396+
onEachLazy(implElems, implElem => {
397+
const numbered = /^(.+?)-([0-9]+)$/.exec(implElem.id);
398+
if (implElem.id !== implId && (!numbered || numbered[1] !== implId)) {
399+
return false;
400+
}
401+
return onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
397402
`[id^="${assocId}"]`),
398403
item => {
399-
const numbered = /([^-]+)-([0-9]+)/.exec(item.id);
404+
const numbered = /^(.+?)-([0-9]+)$/.exec(item.id);
400405
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
401406
openParentDetails(item);
402407
item.scrollIntoView();
403408
// Let the section expand itself before trying to highlight
404409
setTimeout(() => {
405410
window.location.replace("#" + item.id);
406411
}, 0);
412+
return true;
407413
}
408414
},
409415
);
410-
}
416+
});
411417
}
412418
}
413419
}

src/tools/clippy/tests/ui/uninit_vec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![warn(clippy::uninit_vec)]
22

33
use std::mem::MaybeUninit;
4+
use std::cell::UnsafeCell;
45

56
#[derive(Default)]
67
struct MyVec {
@@ -12,6 +13,12 @@ union MyOwnMaybeUninit {
1213
uninit: (),
1314
}
1415

16+
// https://github.com/rust-lang/rust/issues/119620
17+
unsafe fn requires_paramenv<S>() {
18+
let mut vec = Vec::<UnsafeCell<*mut S>>::with_capacity(1);
19+
vec.set_len(1);
20+
}
21+
1522
fn main() {
1623
// with_capacity() -> set_len() should be detected
1724
let mut vec: Vec<u8> = Vec::with_capacity(1000);

0 commit comments

Comments
 (0)