Rollup merge of #110124 - Nilstrieb:📎-told-me-so, r=compiler-errors
Some clippy fixes in the compiler
Best reviewed commit-by-commit 📎.
This commit is contained in:
commit
97921abc06
54 changed files with 141 additions and 139 deletions
|
@ -1176,7 +1176,7 @@ impl FieldsShape {
|
|||
|
||||
/// Gets source indices of the fields by increasing offsets.
|
||||
#[inline]
|
||||
pub fn index_by_increasing_offset<'a>(&'a self) -> impl Iterator<Item = usize> + 'a {
|
||||
pub fn index_by_increasing_offset(&self) -> impl Iterator<Item = usize> + '_ {
|
||||
let mut inverse_small = [0u8; 64];
|
||||
let mut inverse_big = IndexVec::new();
|
||||
let use_small = self.count() <= inverse_small.len();
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#![feature(strict_provenance)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
|
@ -568,7 +569,9 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||
}
|
||||
|
||||
pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized {
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self;
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
|
@ -578,10 +581,12 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||
// Any type that impls `Copy` can be arena-allocated in the `DroplessArena`.
|
||||
impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T {
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
|
||||
arena.dropless.alloc(self)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
|
@ -601,6 +606,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
|
@ -616,12 +622,14 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||
|
||||
impl<'tcx> Arena<'tcx> {
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T {
|
||||
value.allocate_on(self)
|
||||
}
|
||||
|
||||
// Any type that impls `Copy` can have slices be arena-allocated in the `DroplessArena`.
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T]) -> &mut [T] {
|
||||
if value.is_empty() {
|
||||
return &mut [];
|
||||
|
@ -629,6 +637,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||
self.dropless.alloc_slice(value)
|
||||
}
|
||||
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, C>, C>(
|
||||
&'a self,
|
||||
iter: impl ::std::iter::IntoIterator<Item = T>,
|
||||
|
|
|
@ -691,7 +691,7 @@ fn validate_generic_param_order(
|
|||
GenericParamKind::Lifetime => (),
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
|
||||
ordered_params += " = ";
|
||||
ordered_params += &pprust::expr_to_string(&*default.value);
|
||||
ordered_params += &pprust::expr_to_string(&default.value);
|
||||
}
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
|
||||
}
|
||||
|
|
|
@ -404,11 +404,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
);
|
||||
} else {
|
||||
// And if it isn't, cancel the early-pass warning.
|
||||
self.sess
|
||||
if let Some(err) = self
|
||||
.sess
|
||||
.parse_sess
|
||||
.span_diagnostic
|
||||
.steal_diagnostic(e.span, StashKey::EarlySyntaxWarning)
|
||||
.map(|err| err.cancel());
|
||||
{
|
||||
err.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::ExprKind::TryBlock(_) => {
|
||||
|
|
|
@ -686,7 +686,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
|
||||
let has_comment = self.maybe_print_comment(span.hi());
|
||||
if !empty || has_comment {
|
||||
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
|
||||
self.break_offset_if_not_bol(1, -INDENT_UNIT);
|
||||
}
|
||||
self.word("}");
|
||||
if close_box {
|
||||
|
@ -988,7 +988,9 @@ impl<'a> State<'a> {
|
|||
|
||||
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocConstraint) {
|
||||
self.print_ident(constraint.ident);
|
||||
constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
|
||||
if let Some(args) = constraint.gen_args.as_ref() {
|
||||
self.print_generic_args(args, false)
|
||||
}
|
||||
self.space();
|
||||
match &constraint.kind {
|
||||
ast::AssocConstraintKind::Equality { term } => {
|
||||
|
|
|
@ -206,17 +206,11 @@ impl<N: Debug, E: Debug> Graph<N, E> {
|
|||
AdjacentEdges { graph: self, direction, next: first_edge }
|
||||
}
|
||||
|
||||
pub fn successor_nodes<'a>(
|
||||
&'a self,
|
||||
source: NodeIndex,
|
||||
) -> impl Iterator<Item = NodeIndex> + 'a {
|
||||
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
|
||||
self.outgoing_edges(source).targets()
|
||||
}
|
||||
|
||||
pub fn predecessor_nodes<'a>(
|
||||
&'a self,
|
||||
target: NodeIndex,
|
||||
) -> impl Iterator<Item = NodeIndex> + 'a {
|
||||
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
|
||||
self.incoming_edges(target).sources()
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Deref for Mmap {
|
|||
|
||||
impl AsRef<[u8]> for Mmap {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&*self.0
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -778,7 +778,7 @@ pub fn print_time_passes_entry(
|
|||
"rss_start": start_rss,
|
||||
"rss_end": end_rss,
|
||||
});
|
||||
eprintln!("time: {}", json.to_string());
|
||||
eprintln!("time: {json}");
|
||||
return;
|
||||
}
|
||||
TimePassesFormat::Text => (),
|
||||
|
|
|
@ -140,6 +140,7 @@ pub fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
|
|||
/// `hash` can be computed with any hasher, so long as that hasher is used
|
||||
/// consistently for each `Sharded` instance.
|
||||
#[inline]
|
||||
#[allow(clippy::modulo_one)]
|
||||
pub fn get_shard_index_by_hash(hash: u64) -> usize {
|
||||
let hash_len = mem::size_of::<usize>();
|
||||
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
|
||||
|
|
|
@ -312,14 +312,14 @@ impl<CTX> HashStable<CTX> for ::std::num::NonZeroUsize {
|
|||
|
||||
impl<CTX> HashStable<CTX> for f32 {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
let val: u32 = unsafe { ::std::mem::transmute(*self) };
|
||||
let val: u32 = self.to_bits();
|
||||
val.hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for f64 {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
let val: u64 = unsafe { ::std::mem::transmute(*self) };
|
||||
let val: u64 = self.to_bits();
|
||||
val.hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const RED_ZONE: usize = 100 * 1024; // 100k
|
|||
|
||||
// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then
|
||||
// on. This flag has performance relevant characteristics. Don't set it too high.
|
||||
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
|
||||
const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB
|
||||
|
||||
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
|
||||
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<T: Copy> AppendOnlyVec<T> {
|
|||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = T> + '_ {
|
||||
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).filter_map(|o| o)
|
||||
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ impl<V: Eq + Hash> UnordSet<V> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn items<'a>(&'a self) -> UnordItems<&'a V, impl Iterator<Item = &'a V>> {
|
||||
pub fn items(&self) -> UnordItems<&V, impl Iterator<Item = &V>> {
|
||||
UnordItems(self.inner.iter())
|
||||
}
|
||||
|
||||
|
@ -415,7 +415,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn items<'a>(&'a self) -> UnordItems<(&'a K, &'a V), impl Iterator<Item = (&'a K, &'a V)>> {
|
||||
pub fn items(&self) -> UnordItems<(&K, &V), impl Iterator<Item = (&K, &V)>> {
|
||||
UnordItems(self.inner.iter())
|
||||
}
|
||||
|
||||
|
|
|
@ -956,7 +956,7 @@ impl Diagnostic {
|
|||
// Exact iteration order of diagnostic arguments shouldn't make a difference to output because
|
||||
// they're only used in interpolation.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
pub fn args<'a>(&'a self) -> impl Iterator<Item = DiagnosticArg<'a, 'static>> {
|
||||
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_, 'static>> {
|
||||
self.args.iter()
|
||||
}
|
||||
|
||||
|
|
|
@ -1407,7 +1407,7 @@ impl EmitterWriter {
|
|||
// Account for newlines to align output to its label.
|
||||
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
|
||||
buffer.append(
|
||||
0 + line,
|
||||
line,
|
||||
&format!(
|
||||
"{}{}",
|
||||
if line == 0 { String::new() } else { " ".repeat(label_width) },
|
||||
|
@ -1918,7 +1918,7 @@ impl EmitterWriter {
|
|||
let last_line = unhighlighted_lines.pop();
|
||||
let first_line = unhighlighted_lines.drain(..).next();
|
||||
|
||||
first_line.map(|(p, l)| {
|
||||
if let Some((p, l)) = first_line {
|
||||
self.draw_code_line(
|
||||
&mut buffer,
|
||||
&mut row_num,
|
||||
|
@ -1930,12 +1930,12 @@ impl EmitterWriter {
|
|||
&file_lines,
|
||||
is_multiline,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber);
|
||||
row_num += 1;
|
||||
|
||||
last_line.map(|(p, l)| {
|
||||
if let Some((p, l)) = last_line {
|
||||
self.draw_code_line(
|
||||
&mut buffer,
|
||||
&mut row_num,
|
||||
|
@ -1947,7 +1947,7 @@ impl EmitterWriter {
|
|||
&file_lines,
|
||||
is_multiline,
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -466,7 +466,7 @@ impl<'a> StripUnconfigured<'a> {
|
|||
//
|
||||
// N.B., this is intentionally not part of the visit_expr() function
|
||||
// in order for filter_map_expr() to be able to avoid this check
|
||||
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(*a)) {
|
||||
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a)) {
|
||||
self.sess.emit_err(RemoveExprNotSupported { span: attr.span });
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ impl MetaVarExpr {
|
|||
};
|
||||
check_trailing_token(&mut tts, sess)?;
|
||||
let mut iter = args.trees();
|
||||
let rslt = match &*ident.as_str() {
|
||||
let rslt = match ident.as_str() {
|
||||
"count" => parse_count(&mut iter, sess, ident.span)?,
|
||||
"ignore" => MetaVarExpr::Ignore(parse_ident(&mut iter, sess, ident.span)?),
|
||||
"index" => MetaVarExpr::Index(parse_depth(&mut iter, sess, ident.span)?),
|
||||
|
|
|
@ -49,7 +49,7 @@ impl LanguageItems {
|
|||
self.get(it).ok_or_else(|| LangItemError(it))
|
||||
}
|
||||
|
||||
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (LangItem, DefId)> + 'a {
|
||||
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
|
||||
self.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
|
|
@ -302,7 +302,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
|||
.iter()
|
||||
.flatten()
|
||||
.map(|r| r.impl_blocks.len() as isize - avg as isize)
|
||||
.map(|v| v.abs() as usize)
|
||||
.map(|v| v.unsigned_abs())
|
||||
.sum::<usize>();
|
||||
s / connected_regions.len()
|
||||
},
|
||||
|
|
|
@ -242,7 +242,7 @@ pub fn enum_def_to_string(
|
|||
impl<'a> State<'a> {
|
||||
pub fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
|
||||
self.maybe_print_comment(span.hi());
|
||||
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
|
||||
self.break_offset_if_not_bol(1, -INDENT_UNIT);
|
||||
self.word("}");
|
||||
if close_box {
|
||||
self.end(); // close the outer-box
|
||||
|
|
|
@ -538,8 +538,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// FIXME(rpitit): This will need to be fixed when we move to associated types
|
||||
assert!(matches!(
|
||||
*trait_pred.trait_ref.self_ty().kind(),
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if def_id == rpit_def_id && substs == substs
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs: alias_substs, .. })
|
||||
if def_id == rpit_def_id && substs == alias_substs
|
||||
));
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
trait_pred.with_self_ty(self.tcx, ty),
|
||||
|
@ -548,8 +548,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
|
||||
assert!(matches!(
|
||||
*proj_pred.projection_ty.self_ty().kind(),
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if def_id == rpit_def_id && substs == substs
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs: alias_substs, .. })
|
||||
if def_id == rpit_def_id && substs == alias_substs
|
||||
));
|
||||
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
|
||||
|
|
|
@ -242,8 +242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let Some(arg) = segment
|
||||
.args()
|
||||
.args
|
||||
.iter()
|
||||
.nth(index) else { return false; };
|
||||
.get(index) else { return false; };
|
||||
error.obligation.cause.span = arg
|
||||
.span()
|
||||
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
|
||||
|
|
|
@ -526,8 +526,9 @@ impl DropRangesBuilder {
|
|||
let mut next = <_>::from(0u32);
|
||||
for value in tracked_values {
|
||||
for_each_consumable(hir, value, |value| {
|
||||
if !tracked_value_map.contains_key(&value) {
|
||||
tracked_value_map.insert(value, next);
|
||||
if let std::collections::hash_map::Entry::Vacant(e) = tracked_value_map.entry(value)
|
||||
{
|
||||
e.insert(next);
|
||||
next = next + 1;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -313,8 +313,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
|||
// Extract type components to build the witness type.
|
||||
let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty));
|
||||
let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars);
|
||||
let witness =
|
||||
fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone()));
|
||||
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars));
|
||||
|
||||
drop(typeck_results);
|
||||
// Store the generator types and spans into the typeck results for this generator.
|
||||
|
|
|
@ -1764,7 +1764,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
fn probe_for_similar_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
|
||||
debug!("probing for method names similar to {:?}", self.method_name);
|
||||
|
||||
let steps = self.steps.clone();
|
||||
self.probe(|_| {
|
||||
let mut pcx = ProbeContext::new(
|
||||
self.fcx,
|
||||
|
@ -1772,8 +1771,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
self.mode,
|
||||
self.method_name,
|
||||
self.return_type,
|
||||
&self.orig_steps_var_values,
|
||||
steps,
|
||||
self.orig_steps_var_values,
|
||||
self.steps,
|
||||
self.scope_expr_id,
|
||||
);
|
||||
pcx.allow_similar_names = true;
|
||||
|
|
|
@ -1850,7 +1850,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
|
|||
|
||||
/// Iterates through all the columns set to true in a given row of
|
||||
/// the matrix.
|
||||
pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
|
||||
pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ {
|
||||
self.row(row).into_iter().flat_map(|r| r.iter())
|
||||
}
|
||||
|
||||
|
|
|
@ -201,18 +201,15 @@ impl<I: Idx, T> IndexVec<I, T> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn drain<'a, R: RangeBounds<usize>>(
|
||||
&'a mut self,
|
||||
range: R,
|
||||
) -> impl Iterator<Item = T> + 'a {
|
||||
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ {
|
||||
self.raw.drain(range)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
|
||||
&'a mut self,
|
||||
pub fn drain_enumerated<R: RangeBounds<usize>>(
|
||||
&mut self,
|
||||
range: R,
|
||||
) -> impl Iterator<Item = (I, T)> + 'a {
|
||||
) -> impl Iterator<Item = (I, T)> + '_ {
|
||||
let begin = match range.start_bound() {
|
||||
std::ops::Bound::Included(i) => *i,
|
||||
std::ops::Bound::Excluded(i) => i.checked_add(1).unwrap(),
|
||||
|
|
|
@ -266,12 +266,12 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
|
|||
let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id else { bug!("unstable expectation id should already be mapped") };
|
||||
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
|
||||
|
||||
if !self.unstable_to_stable_ids.contains_key(&key) {
|
||||
self.unstable_to_stable_ids.insert(
|
||||
key,
|
||||
LintExpectationId::Stable { hir_id, attr_index, lint_index: None, attr_id: None },
|
||||
);
|
||||
}
|
||||
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
|
||||
hir_id,
|
||||
attr_index,
|
||||
lint_index: None,
|
||||
attr_id: None,
|
||||
});
|
||||
|
||||
self.expectations.push((id.normalize(), expectation));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ pub unsafe extern "C" fn LLVMRustStringWriteImpl(
|
|||
ptr: *const c_char,
|
||||
size: size_t,
|
||||
) {
|
||||
let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
|
||||
let slice = slice::from_raw_parts(ptr as *const u8, size);
|
||||
|
||||
sr.bytes.borrow_mut().extend_from_slice(slice);
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ impl DiagnosticDeriveBuilder {
|
|||
impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
||||
/// Generates calls to `code` and similar functions based on the attributes on the type or
|
||||
/// variant.
|
||||
pub fn preamble<'s>(&mut self, variant: &VariantInfo<'s>) -> TokenStream {
|
||||
pub fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
||||
let ast = variant.ast();
|
||||
let attrs = &ast.attrs;
|
||||
let preamble = attrs.iter().map(|attr| {
|
||||
|
@ -133,7 +133,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||
|
||||
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
|
||||
/// calls to `set_arg` when no attributes are present.
|
||||
pub fn body<'s>(&mut self, variant: &VariantInfo<'s>) -> TokenStream {
|
||||
pub fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
||||
let mut body = quote! {};
|
||||
// Generate `set_arg` calls first..
|
||||
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {
|
||||
|
|
|
@ -100,7 +100,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
|
|||
Diagnostic::spanned(
|
||||
resource_span,
|
||||
Level::Error,
|
||||
format!("could not open Fluent resource: {}", e.to_string()),
|
||||
format!("could not open Fluent resource: {e}"),
|
||||
)
|
||||
.emit();
|
||||
return failed(&crate_name);
|
||||
|
|
|
@ -762,14 +762,14 @@ impl<'a> CrateLocator<'a> {
|
|||
}
|
||||
|
||||
pub(crate) fn into_error(self, root: Option<CratePaths>) -> CrateError {
|
||||
CrateError::LocatorCombined(CombinedLocatorError {
|
||||
CrateError::LocatorCombined(Box::new(CombinedLocatorError {
|
||||
crate_name: self.crate_name,
|
||||
root,
|
||||
triple: self.triple,
|
||||
dll_prefix: self.target.dll_prefix.to_string(),
|
||||
dll_suffix: self.target.dll_suffix.to_string(),
|
||||
crate_rejections: self.crate_rejections,
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -958,7 +958,7 @@ pub(crate) enum CrateError {
|
|||
StableCrateIdCollision(Symbol, Symbol),
|
||||
DlOpen(String),
|
||||
DlSym(String),
|
||||
LocatorCombined(CombinedLocatorError),
|
||||
LocatorCombined(Box<CombinedLocatorError>),
|
||||
NonDylibPlugin(Symbol),
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
|
|||
if self.current_id == CRATE_HIR_ID {
|
||||
return None;
|
||||
}
|
||||
loop {
|
||||
|
||||
// There are nodes that do not have entries, so we need to skip them.
|
||||
let parent_id = self.map.parent_id(self.current_id);
|
||||
|
||||
|
@ -87,7 +87,6 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
|
|||
return Some(parent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator that walks up the ancestor tree of a given `HirId`.
|
||||
/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`.
|
||||
|
|
|
@ -109,26 +109,34 @@ const MAX_HASHED_BUFFER_LEN: usize = 2 * MAX_BYTES_TO_HASH;
|
|||
// large.
|
||||
impl hash::Hash for Allocation {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
let Self {
|
||||
bytes,
|
||||
provenance,
|
||||
init_mask,
|
||||
align,
|
||||
mutability,
|
||||
extra: (), // don't bother hashing ()
|
||||
} = self;
|
||||
|
||||
// Partially hash the `bytes` buffer when it is large. To limit collisions with common
|
||||
// prefixes and suffixes, we hash the length and some slices of the buffer.
|
||||
let byte_count = self.bytes.len();
|
||||
let byte_count = bytes.len();
|
||||
if byte_count > MAX_HASHED_BUFFER_LEN {
|
||||
// Hash the buffer's length.
|
||||
byte_count.hash(state);
|
||||
|
||||
// And its head and tail.
|
||||
self.bytes[..MAX_BYTES_TO_HASH].hash(state);
|
||||
self.bytes[byte_count - MAX_BYTES_TO_HASH..].hash(state);
|
||||
bytes[..MAX_BYTES_TO_HASH].hash(state);
|
||||
bytes[byte_count - MAX_BYTES_TO_HASH..].hash(state);
|
||||
} else {
|
||||
self.bytes.hash(state);
|
||||
bytes.hash(state);
|
||||
}
|
||||
|
||||
// Hash the other fields as usual.
|
||||
self.provenance.hash(state);
|
||||
self.init_mask.hash(state);
|
||||
self.align.hash(state);
|
||||
self.mutability.hash(state);
|
||||
self.extra.hash(state);
|
||||
provenance.hash(state);
|
||||
init_mask.hash(state);
|
||||
align.hash(state);
|
||||
mutability.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -915,7 +915,7 @@ pub enum LocalInfo<'tcx> {
|
|||
|
||||
impl<'tcx> LocalDecl<'tcx> {
|
||||
pub fn local_info(&self) -> &LocalInfo<'tcx> {
|
||||
&**self.local_info.as_ref().assert_crate_local()
|
||||
&self.local_info.as_ref().assert_crate_local()
|
||||
}
|
||||
|
||||
/// Returns `true` only if local is a binding that can itself be
|
||||
|
|
|
@ -133,21 +133,21 @@ impl<'tcx> MirPatch<'tcx> {
|
|||
let mut new_decl = LocalDecl::new(ty, span).internal();
|
||||
**new_decl.local_info.as_mut().assert_crate_local() = local_info;
|
||||
self.new_locals.push(new_decl);
|
||||
Local::new(index as usize)
|
||||
Local::new(index)
|
||||
}
|
||||
|
||||
pub fn new_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
|
||||
let index = self.next_local;
|
||||
self.next_local += 1;
|
||||
self.new_locals.push(LocalDecl::new(ty, span));
|
||||
Local::new(index as usize)
|
||||
Local::new(index)
|
||||
}
|
||||
|
||||
pub fn new_internal(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
|
||||
let index = self.next_local;
|
||||
self.next_local += 1;
|
||||
self.new_locals.push(LocalDecl::new(ty, span).internal());
|
||||
Local::new(index as usize)
|
||||
Local::new(index)
|
||||
}
|
||||
|
||||
pub fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
|
||||
|
|
|
@ -98,7 +98,7 @@ impl<'tcx> PlaceTy<'tcx> {
|
|||
ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64),
|
||||
ty::Array(inner, size) if from_end => {
|
||||
let size = size.eval_target_usize(tcx, param_env);
|
||||
let len = size - (from as u64) - (to as u64);
|
||||
let len = size - from - to;
|
||||
tcx.mk_array(*inner, len)
|
||||
}
|
||||
_ => bug!("cannot subslice non-array type: `{:?}`", self),
|
||||
|
|
|
@ -178,17 +178,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
|
|||
// When we yield `B` and call `traverse_successor`, we push `C` to the stack, but
|
||||
// since we've already visited `E`, that child isn't added to the stack. The last
|
||||
// two iterations yield `C` and finally `A` for a final traversal of [E, D, B, C, A]
|
||||
loop {
|
||||
let bb = if let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() {
|
||||
if let Some(bb) = iter.next() {
|
||||
bb
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
|
||||
while let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() && let Some(bb) = iter.next() {
|
||||
if self.visited.insert(bb) {
|
||||
if let Some(term) = &self.basic_blocks[bb].terminator {
|
||||
self.visit_stack.push((bb, term.successors()));
|
||||
|
|
|
@ -923,7 +923,7 @@ impl ObjectSafetyViolation {
|
|||
}
|
||||
}
|
||||
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
|
||||
format!("where clause cannot reference non-lifetime `for<...>` variables").into()
|
||||
"where clause cannot reference non-lifetime `for<...>` variables".into()
|
||||
}
|
||||
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
|
||||
format!("associated function `{}` has no `self` parameter", name).into()
|
||||
|
|
|
@ -115,7 +115,7 @@ impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
|
|||
type Target = ExternalConstraintsData<'tcx>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&*self.0
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -337,7 +337,7 @@ impl ScalarInt {
|
|||
/// Fails if the size of the `ScalarInt` is not equal to `Size { raw: 16 }`
|
||||
/// and returns the `ScalarInt`s size in that case.
|
||||
pub fn try_to_i128(self) -> Result<i128, Size> {
|
||||
self.try_to_int(Size::from_bits(128)).map(|v| i128::try_from(v).unwrap())
|
||||
self.try_to_int(Size::from_bits(128))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -924,7 +924,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
crate_name,
|
||||
// Don't print the whole stable crate id. That's just
|
||||
// annoying in debug output.
|
||||
stable_crate_id.to_u64() >> 8 * 6,
|
||||
stable_crate_id.to_u64() >> (8 * 6),
|
||||
self.def_path(def_id).to_string_no_crate_verbose()
|
||||
)
|
||||
}
|
||||
|
@ -2379,7 +2379,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> {
|
||||
let map = self.in_scope_traits_map(id.owner)?;
|
||||
let candidates = map.get(&id.local_id)?;
|
||||
Some(&*candidates)
|
||||
Some(candidates)
|
||||
}
|
||||
|
||||
pub fn named_bound_var(self, id: HirId) -> Option<resolve_bound_vars::ResolvedArg> {
|
||||
|
|
|
@ -1891,7 +1891,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
// The way we evaluate the `N` in `[T; N]` here only works since we use
|
||||
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
|
||||
// if we use it in generic code. See the `simd-array-trait` ui test.
|
||||
(f0_len.eval_target_usize(tcx, ParamEnv::empty()) as u64, *f0_elem_ty)
|
||||
(f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty)
|
||||
}
|
||||
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
|
||||
// all have the same type).
|
||||
|
|
|
@ -558,8 +558,8 @@ impl<'a> StringReader<'a> {
|
|||
}
|
||||
|
||||
if let Some(possible_offset) = possible_offset {
|
||||
let lo = start + BytePos(possible_offset as u32);
|
||||
let hi = lo + BytePos(found_terminators as u32);
|
||||
let lo = start + BytePos(possible_offset);
|
||||
let hi = lo + BytePos(found_terminators);
|
||||
let span = self.mk_sp(lo, hi);
|
||||
err.span_suggestion(
|
||||
span,
|
||||
|
|
|
@ -336,8 +336,8 @@ const ASCII_ARRAY: &[(&str, &str, Option<token::TokenKind>)] = &[
|
|||
("\"", "Quotation Mark", None),
|
||||
];
|
||||
|
||||
pub(super) fn check_for_substitution<'a>(
|
||||
reader: &StringReader<'a>,
|
||||
pub(super) fn check_for_substitution(
|
||||
reader: &StringReader<'_>,
|
||||
pos: BytePos,
|
||||
ch: char,
|
||||
count: usize,
|
||||
|
|
|
@ -53,7 +53,7 @@ impl<'a> Parser<'a> {
|
|||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
match self.parse_ty() {
|
||||
Ok(p) => {
|
||||
if let TyKind::ImplTrait(_, bounds) = &(*p).kind {
|
||||
if let TyKind::ImplTrait(_, bounds) = &p.kind {
|
||||
let span = impl_span.to(self.token.span.shrink_to_lo());
|
||||
let mut err = self.struct_span_err(
|
||||
span,
|
||||
|
|
|
@ -136,7 +136,9 @@ where
|
|||
}
|
||||
|
||||
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
self.cache.lock().as_ref().map(|value| f(&(), &value.0, value.1));
|
||||
if let Some(value) = self.cache.lock().as_ref() {
|
||||
f(&(), &value.0, value.1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1224,7 +1224,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
lifetime_ribs: Vec::new(),
|
||||
lifetime_elision_candidates: None,
|
||||
current_trait_ref: None,
|
||||
diagnostic_metadata: Box::new(DiagnosticMetadata::default()),
|
||||
diagnostic_metadata: Default::default(),
|
||||
// errors at module scope should always be reported
|
||||
in_func_body: false,
|
||||
lifetime_uses: Default::default(),
|
||||
|
|
|
@ -1426,7 +1426,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
|||
opt::opt_s(
|
||||
"",
|
||||
"edition",
|
||||
&*EDITION_STRING,
|
||||
&EDITION_STRING,
|
||||
EDITION_NAME_LIST,
|
||||
),
|
||||
opt::multi_s(
|
||||
|
|
|
@ -84,12 +84,12 @@ impl SymbolGallery {
|
|||
|
||||
/// Construct a diagnostic for a language feature error due to the given `span`.
|
||||
/// The `feature`'s `Symbol` is the one you used in `active.rs` and `rustc_span::symbols`.
|
||||
pub fn feature_err<'a>(
|
||||
sess: &'a ParseSess,
|
||||
pub fn feature_err(
|
||||
sess: &ParseSess,
|
||||
feature: Symbol,
|
||||
span: impl Into<MultiSpan>,
|
||||
explain: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
feature_err_issue(sess, feature, span, GateIssue::Language, explain)
|
||||
}
|
||||
|
||||
|
@ -98,20 +98,21 @@ pub fn feature_err<'a>(
|
|||
/// This variant allows you to control whether it is a library or language feature.
|
||||
/// Almost always, you want to use this for a language feature. If so, prefer `feature_err`.
|
||||
#[track_caller]
|
||||
pub fn feature_err_issue<'a>(
|
||||
sess: &'a ParseSess,
|
||||
pub fn feature_err_issue(
|
||||
sess: &ParseSess,
|
||||
feature: Symbol,
|
||||
span: impl Into<MultiSpan>,
|
||||
issue: GateIssue,
|
||||
explain: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
let span = span.into();
|
||||
|
||||
// Cancel an earlier warning for this same error, if it exists.
|
||||
if let Some(span) = span.primary_span() {
|
||||
sess.span_diagnostic
|
||||
.steal_diagnostic(span, StashKey::EarlySyntaxWarning)
|
||||
.map(|err| err.cancel());
|
||||
if let Some(err) = sess.span_diagnostic.steal_diagnostic(span, StashKey::EarlySyntaxWarning)
|
||||
{
|
||||
err.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
let mut err = sess.create_err(FeatureGateError { span, explain: explain.into() });
|
||||
|
|
|
@ -1353,16 +1353,16 @@ impl Clone for SourceFile {
|
|||
Self {
|
||||
name: self.name.clone(),
|
||||
src: self.src.clone(),
|
||||
src_hash: self.src_hash.clone(),
|
||||
src_hash: self.src_hash,
|
||||
external_src: Lock::new(self.external_src.borrow().clone()),
|
||||
start_pos: self.start_pos.clone(),
|
||||
end_pos: self.end_pos.clone(),
|
||||
start_pos: self.start_pos,
|
||||
end_pos: self.end_pos,
|
||||
lines: Lock::new(self.lines.borrow().clone()),
|
||||
multibyte_chars: self.multibyte_chars.clone(),
|
||||
non_narrow_chars: self.non_narrow_chars.clone(),
|
||||
normalized_pos: self.normalized_pos.clone(),
|
||||
name_hash: self.name_hash.clone(),
|
||||
cnum: self.cnum.clone(),
|
||||
name_hash: self.name_hash,
|
||||
cnum: self.cnum,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2051,13 +2051,13 @@ pub type FileLinesResult = Result<FileLines, SpanLinesError>;
|
|||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub enum SpanLinesError {
|
||||
DistinctSources(DistinctSources),
|
||||
DistinctSources(Box<DistinctSources>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub enum SpanSnippetError {
|
||||
IllFormedSpan(Span),
|
||||
DistinctSources(DistinctSources),
|
||||
DistinctSources(Box<DistinctSources>),
|
||||
MalformedForSourcemap(MalformedSourceMapPositions),
|
||||
SourceNotAvailable { filename: FileName },
|
||||
}
|
||||
|
|
|
@ -542,10 +542,10 @@ impl SourceMap {
|
|||
let hi = self.lookup_char_pos(sp.hi());
|
||||
trace!(?hi);
|
||||
if lo.file.start_pos != hi.file.start_pos {
|
||||
return Err(SpanLinesError::DistinctSources(DistinctSources {
|
||||
return Err(SpanLinesError::DistinctSources(Box::new(DistinctSources {
|
||||
begin: (lo.file.name.clone(), lo.file.start_pos),
|
||||
end: (hi.file.name.clone(), hi.file.start_pos),
|
||||
}));
|
||||
})));
|
||||
}
|
||||
Ok((lo, hi))
|
||||
}
|
||||
|
@ -603,10 +603,10 @@ impl SourceMap {
|
|||
let local_end = self.lookup_byte_offset(sp.hi());
|
||||
|
||||
if local_begin.sf.start_pos != local_end.sf.start_pos {
|
||||
Err(SpanSnippetError::DistinctSources(DistinctSources {
|
||||
Err(SpanSnippetError::DistinctSources(Box::new(DistinctSources {
|
||||
begin: (local_begin.sf.name.clone(), local_begin.sf.start_pos),
|
||||
end: (local_end.sf.name.clone(), local_end.sf.start_pos),
|
||||
}))
|
||||
})))
|
||||
} else {
|
||||
self.ensure_source_file_source_present(local_begin.sf.clone());
|
||||
|
||||
|
|
|
@ -324,8 +324,6 @@ impl Abi {
|
|||
|
||||
impl fmt::Display for Abi {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
abi => write!(f, "\"{}\"", abi.name()),
|
||||
}
|
||||
write!(f, "\"{}\"", self.name())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ mod rustc {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, field_def)| name == field_def.name)
|
||||
.expect(&format!("There were no fields named `{name}`."));
|
||||
.unwrap_or_else(|| panic!("There were no fields named `{name}`."));
|
||||
fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue