Skip to content

Commit 43769af

Browse files
committed
Auto merge of #88857 - workingjubilee:rollup-zrtvspt, r=workingjubilee
Rollup of 10 pull requests Successful merges: - #87904 (Reword description of automatic impls of `Unsize`.) - #88147 (Fix non-capturing closure return type coercion) - #88209 (Improve error message when _ is used for in/inout asm operands) - #88668 (Change more x64 size checks to not apply to x32.) - #88733 (Fix ICE for functions with more than 65535 arguments) - #88757 (Suggest wapping expr in parentheses on invalid unary negation) - #88779 (Use more accurate spans for "unused delimiter" lint) - #88830 (Add help for E0463) - #88849 (don't clone types that are Copy (clippy::clone_on_copy)) - #88850 (don't convert types into identical types) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 641e02f + 2a8ad06 commit 43769af

File tree

49 files changed

+823
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+823
-268
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+14
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,25 @@ impl<'a> AstValidator<'a> {
422422
}
423423

424424
fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
425+
self.check_decl_num_args(fn_decl);
425426
self.check_decl_cvaradic_pos(fn_decl);
426427
self.check_decl_attrs(fn_decl);
427428
self.check_decl_self_param(fn_decl, self_semantic);
428429
}
429430

431+
/// Emits fatal error if function declaration has more than `u16::MAX` arguments
432+
/// Error is fatal to prevent errors during typechecking
433+
fn check_decl_num_args(&self, fn_decl: &FnDecl) {
434+
let max_num_args: usize = u16::MAX.into();
435+
if fn_decl.inputs.len() > max_num_args {
436+
let Param { span, .. } = fn_decl.inputs[0];
437+
self.err_handler().span_fatal(
438+
span,
439+
&format!("function can not have more than {} arguments", max_num_args),
440+
);
441+
}
442+
}
443+
430444
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
431445
match &*fn_decl.inputs {
432446
[Param { ty, span, .. }] => {

compiler/rustc_borrowck/src/region_infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17391739
category: constraint.category,
17401740
from_closure: false,
17411741
span,
1742-
variance_info: constraint.variance_info.clone(),
1742+
variance_info: constraint.variance_info,
17431743
};
17441744
}
17451745
Locations::Single(loc) => loc,
@@ -1752,13 +1752,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17521752
category,
17531753
from_closure: true,
17541754
span: span,
1755-
variance_info: constraint.variance_info.clone(),
1755+
variance_info: constraint.variance_info,
17561756
})
17571757
.unwrap_or(BlameConstraint {
17581758
category: constraint.category,
17591759
from_closure: false,
17601760
span: body.source_info(loc).span,
1761-
variance_info: constraint.variance_info.clone(),
1761+
variance_info: constraint.variance_info,
17621762
})
17631763
}
17641764

@@ -2001,7 +2001,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20012001
category: constraint.category,
20022002
from_closure: false,
20032003
span: constraint.locations.span(body),
2004-
variance_info: constraint.variance_info.clone(),
2004+
variance_info: constraint.variance_info,
20052005
}
20062006
}
20072007
})

compiler/rustc_builtin_macros/src/asm.rs

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ fn parse_args<'a>(
117117
let mut explicit_reg = false;
118118
let op = if !is_global_asm && p.eat_keyword(kw::In) {
119119
let reg = parse_reg(&mut p, &mut explicit_reg)?;
120+
if p.eat_keyword(kw::Underscore) {
121+
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
122+
return Err(err);
123+
}
120124
let expr = p.parse_expr()?;
121125
ast::InlineAsmOperand::In { reg, expr }
122126
} else if !is_global_asm && p.eat_keyword(sym::out) {
@@ -129,6 +133,10 @@ fn parse_args<'a>(
129133
ast::InlineAsmOperand::Out { reg, expr, late: true }
130134
} else if !is_global_asm && p.eat_keyword(sym::inout) {
131135
let reg = parse_reg(&mut p, &mut explicit_reg)?;
136+
if p.eat_keyword(kw::Underscore) {
137+
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
138+
return Err(err);
139+
}
132140
let expr = p.parse_expr()?;
133141
if p.eat(&token::FatArrow) {
134142
let out_expr =
@@ -139,6 +147,10 @@ fn parse_args<'a>(
139147
}
140148
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
141149
let reg = parse_reg(&mut p, &mut explicit_reg)?;
150+
if p.eat_keyword(kw::Underscore) {
151+
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
152+
return Err(err);
153+
}
142154
let expr = p.parse_expr()?;
143155
if p.eat(&token::FatArrow) {
144156
let out_expr =

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ impl<'a> State<'a> {
10361036
self.maybe_print_comment(st.span.lo());
10371037
match st.kind {
10381038
hir::StmtKind::Local(ref loc) => {
1039-
self.print_local(loc.init.as_deref(), |this| this.print_local_decl(&loc));
1039+
self.print_local(loc.init, |this| this.print_local_decl(&loc));
10401040
}
10411041
hir::StmtKind::Item(item) => self.ann.nested(self, Nested::Item(item)),
10421042
hir::StmtKind::Expr(ref expr) => {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23452345
);
23462346
err.span_suggestion(
23472347
generics.where_clause.tail_span_for_suggestion(),
2348-
"consider adding a where clause".into(),
2348+
"consider adding a where clause",
23492349
suggestion,
23502350
Applicability::MaybeIncorrect,
23512351
);

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ where
519519

520520
let old_ambient_variance = self.ambient_variance;
521521
self.ambient_variance = self.ambient_variance.xform(variance);
522-
self.ambient_variance_info = self.ambient_variance_info.clone().xform(info);
522+
self.ambient_variance_info = self.ambient_variance_info.xform(info);
523523

524524
debug!("relate_with_variance: ambient_variance = {:?}", self.ambient_variance);
525525

@@ -597,12 +597,12 @@ where
597597

598598
if self.ambient_covariance() {
599599
// Covariance: a <= b. Hence, `b: a`.
600-
self.push_outlives(v_b, v_a, self.ambient_variance_info.clone());
600+
self.push_outlives(v_b, v_a, self.ambient_variance_info);
601601
}
602602

603603
if self.ambient_contravariance() {
604604
// Contravariant: b <= a. Hence, `a: b`.
605-
self.push_outlives(v_a, v_b, self.ambient_variance_info.clone());
605+
self.push_outlives(v_a, v_b, self.ambient_variance_info);
606606
}
607607

608608
Ok(a)

compiler/rustc_lint/src/unused.rs

+52-68
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
33
use rustc_ast as ast;
44
use rustc_ast::util::{classify, parser};
55
use rustc_ast::{ExprKind, StmtKind};
6-
use rustc_ast_pretty::pprust;
76
use rustc_errors::{pluralize, Applicability};
87
use rustc_hir as hir;
98
use rustc_hir::def::{DefKind, Res};
@@ -12,7 +11,7 @@ use rustc_middle::ty::adjustment;
1211
use rustc_middle::ty::{self, Ty};
1312
use rustc_span::symbol::Symbol;
1413
use rustc_span::symbol::{kw, sym};
15-
use rustc_span::{BytePos, Span, DUMMY_SP};
14+
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
1615

1716
declare_lint! {
1817
/// The `unused_must_use` lint detects unused result of a type flagged as
@@ -491,77 +490,60 @@ trait UnusedDelimLint {
491490
left_pos: Option<BytePos>,
492491
right_pos: Option<BytePos>,
493492
) {
494-
let expr_text = if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) {
495-
snippet
496-
} else {
497-
pprust::expr_to_string(value)
493+
let spans = match value.kind {
494+
ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => {
495+
let start = block.stmts[0].span;
496+
let end = block.stmts[block.stmts.len() - 1].span;
497+
if value.span.from_expansion() || start.from_expansion() || end.from_expansion() {
498+
(
499+
value.span.with_hi(value.span.lo() + BytePos(1)),
500+
value.span.with_lo(value.span.hi() - BytePos(1)),
501+
)
502+
} else {
503+
(value.span.with_hi(start.lo()), value.span.with_lo(end.hi()))
504+
}
505+
}
506+
ast::ExprKind::Paren(ref expr) => {
507+
if value.span.from_expansion() || expr.span.from_expansion() {
508+
(
509+
value.span.with_hi(value.span.lo() + BytePos(1)),
510+
value.span.with_lo(value.span.hi() - BytePos(1)),
511+
)
512+
} else {
513+
(value.span.with_hi(expr.span.lo()), value.span.with_lo(expr.span.hi()))
514+
}
515+
}
516+
_ => return,
498517
};
499518
let keep_space = (
500519
left_pos.map_or(false, |s| s >= value.span.lo()),
501520
right_pos.map_or(false, |s| s <= value.span.hi()),
502521
);
503-
self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space);
522+
self.emit_unused_delims(cx, spans, ctx.into(), keep_space);
504523
}
505524

506525
fn emit_unused_delims(
507526
&self,
508527
cx: &EarlyContext<'_>,
509-
span: Span,
510-
pattern: &str,
528+
spans: (Span, Span),
511529
msg: &str,
512530
keep_space: (bool, bool),
513531
) {
514532
// FIXME(flip1995): Quick and dirty fix for #70814. This should be fixed in rustdoc
515533
// properly.
516-
if span == DUMMY_SP {
534+
if spans.0 == DUMMY_SP || spans.1 == DUMMY_SP {
517535
return;
518536
}
519537

520-
cx.struct_span_lint(self.lint(), span, |lint| {
538+
cx.struct_span_lint(self.lint(), MultiSpan::from(vec![spans.0, spans.1]), |lint| {
521539
let span_msg = format!("unnecessary {} around {}", Self::DELIM_STR, msg);
522540
let mut err = lint.build(&span_msg);
523-
let mut ate_left_paren = false;
524-
let mut ate_right_paren = false;
525-
let parens_removed = pattern
526-
.trim_matches(|c| match c {
527-
'(' | '{' => {
528-
if ate_left_paren {
529-
false
530-
} else {
531-
ate_left_paren = true;
532-
true
533-
}
534-
}
535-
')' | '}' => {
536-
if ate_right_paren {
537-
false
538-
} else {
539-
ate_right_paren = true;
540-
true
541-
}
542-
}
543-
_ => false,
544-
})
545-
.trim();
546-
547-
let replace = {
548-
let mut replace = if keep_space.0 {
549-
let mut s = String::from(" ");
550-
s.push_str(parens_removed);
551-
s
552-
} else {
553-
String::from(parens_removed)
554-
};
555-
556-
if keep_space.1 {
557-
replace.push(' ');
558-
}
559-
replace
560-
};
561-
541+
let replacement = vec![
542+
(spans.0, if keep_space.0 { " ".into() } else { "".into() }),
543+
(spans.1, if keep_space.1 { " ".into() } else { "".into() }),
544+
];
562545
let suggestion = format!("remove these {}", Self::DELIM_STR);
563-
564-
err.span_suggestion_short(span, &suggestion, replace, Applicability::MachineApplicable);
546+
err.multipart_suggestion(&suggestion, replacement, Applicability::MachineApplicable);
565547
err.emit();
566548
});
567549
}
@@ -770,14 +752,15 @@ impl UnusedParens {
770752
// Otherwise proceed with linting.
771753
_ => {}
772754
}
773-
774-
let pattern_text =
775-
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) {
776-
snippet
777-
} else {
778-
pprust::pat_to_string(value)
779-
};
780-
self.emit_unused_delims(cx, value.span, &pattern_text, "pattern", (false, false));
755+
let spans = if value.span.from_expansion() || inner.span.from_expansion() {
756+
(
757+
value.span.with_hi(value.span.lo() + BytePos(1)),
758+
value.span.with_lo(value.span.hi() - BytePos(1)),
759+
)
760+
} else {
761+
(value.span.with_hi(inner.span.lo()), value.span.with_lo(inner.span.hi()))
762+
};
763+
self.emit_unused_delims(cx, spans, "pattern", (false, false));
781764
}
782765
}
783766
}
@@ -870,14 +853,15 @@ impl EarlyLintPass for UnusedParens {
870853
);
871854
}
872855
_ => {
873-
let pattern_text =
874-
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(ty.span) {
875-
snippet
876-
} else {
877-
pprust::ty_to_string(ty)
878-
};
879-
880-
self.emit_unused_delims(cx, ty.span, &pattern_text, "type", (false, false));
856+
let spans = if ty.span.from_expansion() || r.span.from_expansion() {
857+
(
858+
ty.span.with_hi(ty.span.lo() + BytePos(1)),
859+
ty.span.with_lo(ty.span.hi() - BytePos(1)),
860+
)
861+
} else {
862+
(ty.span.with_hi(r.span.lo()), ty.span.with_lo(r.span.hi()))
863+
};
864+
self.emit_unused_delims(cx, spans, "type", (false, false));
881865
}
882866
}
883867
}

compiler/rustc_macros/src/session_diagnostic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
448448
span_idx = Some(syn::Index::from(idx));
449449
} else {
450450
throw_span_err!(
451-
info.span.clone().unwrap(),
451+
info.span.unwrap(),
452452
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
453453
);
454454
}
@@ -460,7 +460,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
460460
applicability_idx = Some(syn::Index::from(idx));
461461
} else {
462462
throw_span_err!(
463-
info.span.clone().unwrap(),
463+
info.span.unwrap(),
464464
"type of field annotated with `#[suggestion(...)]` contains more than one Applicability"
465465
);
466466
}
@@ -479,15 +479,15 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
479479
return Ok((span, applicability));
480480
}
481481
throw_span_err!(
482-
info.span.clone().unwrap(),
482+
info.span.unwrap(),
483483
"wrong types for suggestion",
484484
|diag| {
485485
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)")
486486
}
487487
);
488488
}
489489
_ => throw_span_err!(
490-
info.span.clone().unwrap(),
490+
info.span.unwrap(),
491491
"wrong field type for suggestion",
492492
|diag| {
493493
diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)")

compiler/rustc_metadata/src/locator.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,11 @@ impl CrateError {
10951095
== Symbol::intern(&sess.opts.debugging_opts.profiler_runtime)
10961096
{
10971097
err.note(&"the compiler may have been built without the profiler runtime");
1098+
} else if crate_name.as_str().starts_with("rustc_") {
1099+
err.help(
1100+
"maybe you need to install the missing components with: \
1101+
`rustup component add rust-src rustc-dev llvm-tools-preview`",
1102+
);
10981103
}
10991104
err.span_label(span, "can't find crate");
11001105
err

compiler/rustc_middle/src/mir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ pub struct Place<'tcx> {
17361736
pub projection: &'tcx List<PlaceElem<'tcx>>,
17371737
}
17381738

1739-
#[cfg(target_arch = "x86_64")]
1739+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
17401740
static_assert_size!(Place<'_>, 16);
17411741

17421742
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -2062,7 +2062,7 @@ pub enum Operand<'tcx> {
20622062
Constant(Box<Constant<'tcx>>),
20632063
}
20642064

2065-
#[cfg(target_arch = "x86_64")]
2065+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
20662066
static_assert_size!(Operand<'_>, 24);
20672067

20682068
impl<'tcx> Debug for Operand<'tcx> {
@@ -2200,7 +2200,7 @@ pub enum Rvalue<'tcx> {
22002200
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
22012201
}
22022202

2203-
#[cfg(target_arch = "x86_64")]
2203+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
22042204
static_assert_size!(Rvalue<'_>, 40);
22052205

22062206
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
@@ -2226,7 +2226,7 @@ pub enum AggregateKind<'tcx> {
22262226
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
22272227
}
22282228

2229-
#[cfg(target_arch = "x86_64")]
2229+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
22302230
static_assert_size!(AggregateKind<'_>, 48);
22312231

22322232
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)]

0 commit comments

Comments
 (0)