Skip to content

Commit 9bfa31f

Browse files
committed
Auto merge of #140138 - ChrisDenton:rollup-zw7jibi, r=ChrisDenton
Rollup of 5 pull requests Successful merges: - #139981 (Don't compute name of associated item if it's an RPITIT) - #140077 (Construct OutputType using macro and print [=FILENAME] help info) - #140081 (Update `libc` to 0.2.172) - #140094 (Improve diagnostics for pointer arithmetic += and -= (fixes #137391)) - #140128 (Use correct annotation for CSS pseudo elements) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fae7785 + ddf0176 commit 9bfa31f

20 files changed

+459
-153
lines changed

Diff for: compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
486486
let items: &AssocItems = self.tcx.associated_items(self.def_id);
487487
items
488488
.in_definition_order()
489-
.filter(|item| item.is_type())
490489
.filter(|item| {
491-
!self
492-
.gen_args
493-
.constraints
494-
.iter()
495-
.any(|constraint| constraint.ident.name == item.name())
490+
item.is_type()
491+
&& !item.is_impl_trait_in_trait()
492+
&& !self
493+
.gen_args
494+
.constraints
495+
.iter()
496+
.any(|constraint| constraint.ident.name == item.name())
496497
})
497-
.filter(|item| !item.is_impl_trait_in_trait())
498498
.map(|item| self.tcx.item_ident(item.def_id).to_string())
499499
.collect()
500500
} else {

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_errors::codes::*;
2929
use rustc_errors::{
3030
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, struct_span_code_err,
3131
};
32-
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
32+
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
3333
use rustc_hir::def_id::{DefId, LocalDefId};
3434
use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId};
3535
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@@ -1731,9 +1731,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17311731
tcx.associated_items(*trait_def_id)
17321732
.in_definition_order()
17331733
.any(|i| {
1734-
i.namespace() == Namespace::TypeNS
1734+
i.is_type()
1735+
&& !i.is_impl_trait_in_trait()
17351736
&& i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
1736-
&& i.is_type()
17371737
})
17381738
// Consider only accessible traits
17391739
&& tcx.visibility(*trait_def_id)

Diff for: compiler/rustc_hir_typeck/src/op.rs

+51-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
// us do better coercions than we would be able to do otherwise,
235235
// particularly for things like `String + &String`.
236236
let rhs_ty_var = self.next_ty_var(rhs_expr.span);
237-
238237
let result = self.lookup_op_method(
239238
(lhs_expr, lhs_ty),
240239
Some((rhs_expr, rhs_ty_var)),
@@ -698,6 +697,57 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
698697
}
699698
}
700699

700+
let lhs_name_str = match lhs_expr.kind {
701+
hir::ExprKind::Path(hir::QPath::Resolved(_, path)) => {
702+
path.segments.last().map_or("_".to_string(), |s| s.ident.to_string())
703+
}
704+
_ => self
705+
.tcx
706+
.sess
707+
.source_map()
708+
.span_to_snippet(lhs_expr.span)
709+
.unwrap_or("_".to_string()),
710+
};
711+
712+
if op.span().can_be_used_for_suggestions() {
713+
match op {
714+
Op::AssignOp(Spanned { node: hir::AssignOpKind::AddAssign, .. })
715+
if lhs_ty.is_raw_ptr() && rhs_ty.is_integral() =>
716+
{
717+
err.multipart_suggestion(
718+
"consider using `add` or `wrapping_add` to do pointer arithmetic",
719+
vec![
720+
(lhs_expr.span.shrink_to_lo(), format!("{} = ", lhs_name_str)),
721+
(
722+
lhs_expr.span.between(rhs_expr.span),
723+
".wrapping_add(".to_owned(),
724+
),
725+
(rhs_expr.span.shrink_to_hi(), ")".to_owned()),
726+
],
727+
Applicability::MaybeIncorrect,
728+
);
729+
}
730+
Op::AssignOp(Spanned { node: hir::AssignOpKind::SubAssign, .. }) => {
731+
if lhs_ty.is_raw_ptr() && rhs_ty.is_integral() {
732+
err.multipart_suggestion(
733+
"consider using `sub` or `wrapping_sub` to do pointer arithmetic",
734+
vec![
735+
(lhs_expr.span.shrink_to_lo(), format!("{} = ", lhs_name_str)),
736+
(
737+
lhs_expr.span.between(rhs_expr.span),
738+
".wrapping_sub(".to_owned(),
739+
740+
),
741+
(rhs_expr.span.shrink_to_hi(), ")".to_owned()),
742+
],
743+
Applicability::MaybeIncorrect,
744+
);
745+
}
746+
}
747+
_ => {}
748+
}
749+
}
750+
701751
let reported = err.emit();
702752
Ty::new_error(self.tcx, reported)
703753
}

0 commit comments

Comments
 (0)