Skip to content

Commit

Permalink
Auto merge of #128748 - matthiaskrgr:rollup-dzvi5f7, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #128369 (rustc_lint: make `let-underscore-lock` translatable)
 - #128377 (Fix ICE Caused by Incorrectly Delaying E0107)
 - #128517 (Fallback to string formatting if source is not available for lint)
 - #128685 (Remove the root Cargo.lock from the rust-src component)
 - #128693 (rustdoc-search: account for numeric disambiguators on impls)
 - #128720 (Pass the right `ParamEnv` to `might_permit_raw_init_strict`)
 - #128736 (Fix rustdoc missing handling of remap-path-prefix option)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 6, 2024
2 parents 60d1465 + 47a2f14 commit 0ddead3
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 61 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_const_eval/src/util/check_validity_requirement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_middle::bug;
use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement};
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};

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

let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
might_permit_raw_init_strict(layout, tcx, kind)
might_permit_raw_init_strict(layout, &layout_cx, kind)
} else {
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
might_permit_raw_init_lax(layout, &layout_cx, kind)
}
}
Expand All @@ -42,12 +42,12 @@ pub fn check_validity_requirement<'tcx>(
/// details.
fn might_permit_raw_init_strict<'tcx>(
ty: TyAndLayout<'tcx>,
tcx: TyCtxt<'tcx>,
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
kind: ValidityRequirement,
) -> Result<bool, &'tcx LayoutError<'tcx>> {
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);

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

let allocated = cx
.allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3700,6 +3700,11 @@ impl<'hir> OwnerNode<'hir> {
}
}

/// Check if node is an impl block.
pub fn is_impl_block(&self) -> bool {
matches!(self, OwnerNode::Item(Item { kind: ItemKind::Impl(_), .. }))
}

expect_methods_self! {
expect_item, &'hir Item<'hir>, OwnerNode::Item(n), n;
expect_foreign_item, &'hir ForeignItem<'hir>, OwnerNode::ForeignItem(n), n;
Expand Down
41 changes: 27 additions & 14 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,34 @@ pub(crate) fn check_generic_arg_count(
synth_provided,
}
} else {
let num_missing_args = expected_max - provided;
// Check if associated type bounds are incorrectly written in impl block header like:
// ```
// trait Foo<T> {}
// impl Foo<T: Default> for u8 {}
// ```
let parent_is_impl_block = cx
.tcx()
.hir()
.parent_owner_iter(seg.hir_id)
.next()
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
if parent_is_impl_block {
let constraint_names: Vec<_> =
gen_args.constraints.iter().map(|b| b.ident.name).collect();
let param_names: Vec<_> = gen_params
.own_params
.iter()
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
.map(|param| param.name)
.collect();
if constraint_names == param_names {
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
// to provide a succinct error for cases like issue #113073
all_params_are_binded = true;
};
}

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

GenericArgsInfo::MissingTypesOrConsts {
num_missing_args,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ lint_non_binding_let_multi_suggestion =
lint_non_binding_let_on_drop_type =
non-binding let on a type that implements `Drop`
lint_non_binding_let_on_sync_lock =
non-binding let on a synchronization lock
lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
.label = this lock is not assigned to a binding and is immediately dropped
lint_non_binding_let_suggestion =
consider binding to an unused variable to avoid immediately dropping the value
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_lint/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [
];

impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
return;
Expand Down Expand Up @@ -156,12 +155,12 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)),
};
if is_sync_lock {
let mut span = MultiSpan::from_span(pat.span);
span.push_span_label(
pat.span,
"this lock is not assigned to a binding and is immediately dropped".to_string(),
let span = MultiSpan::from_span(pat.span);
cx.emit_span_lint(
LET_UNDERSCORE_LOCK,
span,
NonBindingLet::SyncLock { sub, pat: pat.span },
);
cx.emit_span_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub });
// Only emit let_underscore_drop for top-level `_` patterns.
} else if can_use_init.is_some() {
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ pub struct BadOptAccessDiag<'a> {
pub enum NonBindingLet {
#[diag(lint_non_binding_let_on_sync_lock)]
SyncLock {
#[label]
pat: Span,
#[subdiagnostic]
sub: NonBindingLetSub,
},
Expand Down
22 changes: 13 additions & 9 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ fn lint_int_literal<'tcx>(
}

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

Expand All @@ -485,6 +488,7 @@ fn lint_uint_literal<'tcx>(
ast::LitKind::Int(v, _) => v.get(),
_ => bug!(),
};

if lit_val < min || lit_val > max {
if let Node::Expr(par_e) = cx.tcx.parent_hir_node(e.hir_id) {
match par_e.kind {
Expand Down Expand Up @@ -526,7 +530,7 @@ fn lint_uint_literal<'tcx>(
.sess()
.source_map()
.span_to_snippet(lit.span)
.expect("must get snippet from literal"),
.unwrap_or_else(|_| lit_val.to_string()),
min,
max,
},
Expand All @@ -551,14 +555,14 @@ fn lint_literal<'tcx>(
}
ty::Uint(t) => lint_uint_literal(cx, e, lit, t),
ty::Float(t) => {
let is_infinite = match lit.node {
let (is_infinite, sym) = match lit.node {
ast::LitKind::Float(v, _) => match t {
// FIXME(f16_f128): add this check once `is_infinite` is reliable (ABI
// issues resolved).
ty::FloatTy::F16 => Ok(false),
ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
ty::FloatTy::F128 => Ok(false),
ty::FloatTy::F16 => (Ok(false), v),
ty::FloatTy::F32 => (v.as_str().parse().map(f32::is_infinite), v),
ty::FloatTy::F64 => (v.as_str().parse().map(f64::is_infinite), v),
ty::FloatTy::F128 => (Ok(false), v),
},
_ => bug!(),
};
Expand All @@ -572,7 +576,7 @@ fn lint_literal<'tcx>(
.sess()
.source_map()
.span_to_snippet(lit.span)
.expect("must get snippet from literal"),
.unwrap_or_else(|_| sym.to_string()),
},
);
}
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ impl Step for Src {
// translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");

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

tarball.generate()
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub(crate) fn create_config(
lint_cap,
scrape_examples_options,
expanded_args,
remap_path_prefix,
..
}: RustdocOptions,
RenderOptions { document_private, .. }: &RenderOptions,
Expand Down Expand Up @@ -247,6 +248,7 @@ pub(crate) fn create_config(
describe_lints,
crate_name,
test,
remap_path_prefix,
..Options::default()
};

Expand Down
18 changes: 12 additions & 6 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,30 @@ function preLoadCss(cssUrl) {
if (splitAt !== -1) {
const implId = savedHash.slice(0, splitAt);
const assocId = savedHash.slice(splitAt + 1);
const implElem = document.getElementById(implId);
if (implElem && implElem.parentElement.tagName === "SUMMARY" &&
implElem.parentElement.parentElement.tagName === "DETAILS") {
onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
const implElems = document.querySelectorAll(
`details > summary > section[id^="${implId}"]`,
);
onEachLazy(implElems, implElem => {
const numbered = /^(.+?)-([0-9]+)$/.exec(implElem.id);
if (implElem.id !== implId && (!numbered || numbered[1] !== implId)) {
return false;
}
return onEachLazy(implElem.parentElement.parentElement.querySelectorAll(
`[id^="${assocId}"]`),
item => {
const numbered = /([^-]+)-([0-9]+)/.exec(item.id);
const numbered = /^(.+?)-([0-9]+)$/.exec(item.id);
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
openParentDetails(item);
item.scrollIntoView();
// Let the section expand itself before trying to highlight
setTimeout(() => {
window.location.replace("#" + item.id);
}, 0);
return true;
}
},
);
}
});
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/tools/clippy/tests/ui/uninit_vec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![warn(clippy::uninit_vec)]

use std::mem::MaybeUninit;
use std::cell::UnsafeCell;

#[derive(Default)]
struct MyVec {
Expand All @@ -12,6 +13,12 @@ union MyOwnMaybeUninit {
uninit: (),
}

// https://github.com/rust-lang/rust/issues/119620
unsafe fn requires_paramenv<S>() {
let mut vec = Vec::<UnsafeCell<*mut S>>::with_capacity(1);
vec.set_len(1);
}

fn main() {
// with_capacity() -> set_len() should be detected
let mut vec: Vec<u8> = Vec::with_capacity(1000);
Expand Down
Loading

0 comments on commit 0ddead3

Please sign in to comment.