Skip to content

Rollup of 10 pull requests #88857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07988bb
Reword description of automatic impls of `Unsize`.
kpreid Aug 10, 2021
2884a74
Fix non-capturing closure return type coercion
FabianWolff Aug 18, 2021
4d6bfde
Improve error message when _ is used for in/inout asm operands
Amanieu Aug 21, 2021
bbe3be9
Add explanatory comment
FabianWolff Aug 31, 2021
cd75af2
Change more x64 size checks to not apply to x32.
hvdijk Sep 5, 2021
d6ce326
Suggest wapping expr in parentheses on invalid unary negation
andrewhickman Sep 6, 2021
804ccfa
Fatal error for functions with more than 65535 arguments
Noble-Mushtak Sep 7, 2021
dc02b51
Use more accurate spans for "unused delimiter" lint
estebank Sep 9, 2021
c9a56cd
Add help for E0463
GuillaumeGomez Sep 10, 2021
c1e9608
don't clone types that are Copy (clippy::clone_on_copy)
matthiaskrgr Sep 11, 2021
545d8d6
don't convert types into identical types
matthiaskrgr Sep 11, 2021
43b79d8
Add comment pointing to test
andrewhickman Sep 11, 2021
95b50eb
Rollup merge of #87904 - kpreid:unsize, r=jyn514
workingjubilee Sep 11, 2021
94cbefb
Rollup merge of #88147 - FabianWolff:issue-88097, r=jackh726
workingjubilee Sep 11, 2021
3af42a8
Rollup merge of #88209 - Amanieu:asm_in_underscore, r=nagisa
workingjubilee Sep 11, 2021
7b514cd
Rollup merge of #88668 - hvdijk:x32, r=joshtriplett
workingjubilee Sep 11, 2021
746eb1d
Rollup merge of #88733 - Noble-Mushtak:88577, r=estebank
workingjubilee Sep 11, 2021
08cbb7d
Rollup merge of #88757 - andrewhickman:master, r=jackh726
workingjubilee Sep 11, 2021
5648859
Rollup merge of #88779 - estebank:unused-delims, r=davidtwco
workingjubilee Sep 11, 2021
2cfafa6
Rollup merge of #88830 - GuillaumeGomez:help-e0463, r=estebank
workingjubilee Sep 11, 2021
c2e1097
Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkov
workingjubilee Sep 11, 2021
2a8ad06
Rollup merge of #88850 - matthiaskrgr:identical_conv, r=jackh726
workingjubilee Sep 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,25 @@ impl<'a> AstValidator<'a> {
}

fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
self.check_decl_num_args(fn_decl);
self.check_decl_cvaradic_pos(fn_decl);
self.check_decl_attrs(fn_decl);
self.check_decl_self_param(fn_decl, self_semantic);
}

/// Emits fatal error if function declaration has more than `u16::MAX` arguments
/// Error is fatal to prevent errors during typechecking
fn check_decl_num_args(&self, fn_decl: &FnDecl) {
let max_num_args: usize = u16::MAX.into();
if fn_decl.inputs.len() > max_num_args {
let Param { span, .. } = fn_decl.inputs[0];
self.err_handler().span_fatal(
span,
&format!("function can not have more than {} arguments", max_num_args),
);
}
}

fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
match &*fn_decl.inputs {
[Param { ty, span, .. }] => {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category,
from_closure: false,
span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
};
}
Locations::Single(loc) => loc,
Expand All @@ -1752,13 +1752,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category,
from_closure: true,
span: span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
})
.unwrap_or(BlameConstraint {
category: constraint.category,
from_closure: false,
span: body.source_info(loc).span,
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
})
}

Expand Down Expand Up @@ -2001,7 +2001,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
category: constraint.category,
from_closure: false,
span: constraint.locations.span(body),
variance_info: constraint.variance_info.clone(),
variance_info: constraint.variance_info,
}
}
})
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ fn parse_args<'a>(
let mut explicit_reg = false;
let op = if !is_global_asm && p.eat_keyword(kw::In) {
let reg = parse_reg(&mut p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
return Err(err);
}
let expr = p.parse_expr()?;
ast::InlineAsmOperand::In { reg, expr }
} else if !is_global_asm && p.eat_keyword(sym::out) {
Expand All @@ -129,6 +133,10 @@ fn parse_args<'a>(
ast::InlineAsmOperand::Out { reg, expr, late: true }
} else if !is_global_asm && p.eat_keyword(sym::inout) {
let reg = parse_reg(&mut p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
return Err(err);
}
let expr = p.parse_expr()?;
if p.eat(&token::FatArrow) {
let out_expr =
Expand All @@ -139,6 +147,10 @@ fn parse_args<'a>(
}
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
let reg = parse_reg(&mut p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
let err = ecx.struct_span_err(p.token.span, "_ cannot be used for input operands");
return Err(err);
}
let expr = p.parse_expr()?;
if p.eat(&token::FatArrow) {
let out_expr =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl<'a> State<'a> {
self.maybe_print_comment(st.span.lo());
match st.kind {
hir::StmtKind::Local(ref loc) => {
self.print_local(loc.init.as_deref(), |this| this.print_local_decl(&loc));
self.print_local(loc.init, |this| this.print_local_decl(&loc));
}
hir::StmtKind::Item(item) => self.ann.nested(self, Nested::Item(item)),
hir::StmtKind::Expr(ref expr) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
err.span_suggestion(
generics.where_clause.tail_span_for_suggestion(),
"consider adding a where clause".into(),
"consider adding a where clause",
suggestion,
Applicability::MaybeIncorrect,
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ where

let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(variance);
self.ambient_variance_info = self.ambient_variance_info.clone().xform(info);
self.ambient_variance_info = self.ambient_variance_info.xform(info);

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

Expand Down Expand Up @@ -597,12 +597,12 @@ where

if self.ambient_covariance() {
// Covariance: a <= b. Hence, `b: a`.
self.push_outlives(v_b, v_a, self.ambient_variance_info.clone());
self.push_outlives(v_b, v_a, self.ambient_variance_info);
}

if self.ambient_contravariance() {
// Contravariant: b <= a. Hence, `a: b`.
self.push_outlives(v_a, v_b, self.ambient_variance_info.clone());
self.push_outlives(v_a, v_b, self.ambient_variance_info);
}

Ok(a)
Expand Down
120 changes: 52 additions & 68 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
use rustc_ast as ast;
use rustc_ast::util::{classify, parser};
use rustc_ast::{ExprKind, StmtKind};
use rustc_ast_pretty::pprust;
use rustc_errors::{pluralize, Applicability};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
Expand All @@ -12,7 +11,7 @@ use rustc_middle::ty::adjustment;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::Symbol;
use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, Span, DUMMY_SP};
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};

declare_lint! {
/// The `unused_must_use` lint detects unused result of a type flagged as
Expand Down Expand Up @@ -491,77 +490,60 @@ trait UnusedDelimLint {
left_pos: Option<BytePos>,
right_pos: Option<BytePos>,
) {
let expr_text = if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) {
snippet
} else {
pprust::expr_to_string(value)
let spans = match value.kind {
ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => {
let start = block.stmts[0].span;
let end = block.stmts[block.stmts.len() - 1].span;
if value.span.from_expansion() || start.from_expansion() || end.from_expansion() {
(
value.span.with_hi(value.span.lo() + BytePos(1)),
value.span.with_lo(value.span.hi() - BytePos(1)),
)
} else {
(value.span.with_hi(start.lo()), value.span.with_lo(end.hi()))
}
}
ast::ExprKind::Paren(ref expr) => {
if value.span.from_expansion() || expr.span.from_expansion() {
(
value.span.with_hi(value.span.lo() + BytePos(1)),
value.span.with_lo(value.span.hi() - BytePos(1)),
)
} else {
(value.span.with_hi(expr.span.lo()), value.span.with_lo(expr.span.hi()))
}
}
_ => return,
};
let keep_space = (
left_pos.map_or(false, |s| s >= value.span.lo()),
right_pos.map_or(false, |s| s <= value.span.hi()),
);
self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space);
self.emit_unused_delims(cx, spans, ctx.into(), keep_space);
}

fn emit_unused_delims(
&self,
cx: &EarlyContext<'_>,
span: Span,
pattern: &str,
spans: (Span, Span),
msg: &str,
keep_space: (bool, bool),
) {
// FIXME(flip1995): Quick and dirty fix for #70814. This should be fixed in rustdoc
// properly.
if span == DUMMY_SP {
if spans.0 == DUMMY_SP || spans.1 == DUMMY_SP {
return;
}

cx.struct_span_lint(self.lint(), span, |lint| {
cx.struct_span_lint(self.lint(), MultiSpan::from(vec![spans.0, spans.1]), |lint| {
let span_msg = format!("unnecessary {} around {}", Self::DELIM_STR, msg);
let mut err = lint.build(&span_msg);
let mut ate_left_paren = false;
let mut ate_right_paren = false;
let parens_removed = pattern
.trim_matches(|c| match c {
'(' | '{' => {
if ate_left_paren {
false
} else {
ate_left_paren = true;
true
}
}
')' | '}' => {
if ate_right_paren {
false
} else {
ate_right_paren = true;
true
}
}
_ => false,
})
.trim();

let replace = {
let mut replace = if keep_space.0 {
let mut s = String::from(" ");
s.push_str(parens_removed);
s
} else {
String::from(parens_removed)
};

if keep_space.1 {
replace.push(' ');
}
replace
};

let replacement = vec![
(spans.0, if keep_space.0 { " ".into() } else { "".into() }),
(spans.1, if keep_space.1 { " ".into() } else { "".into() }),
];
let suggestion = format!("remove these {}", Self::DELIM_STR);

err.span_suggestion_short(span, &suggestion, replace, Applicability::MachineApplicable);
err.multipart_suggestion(&suggestion, replacement, Applicability::MachineApplicable);
err.emit();
});
}
Expand Down Expand Up @@ -770,14 +752,15 @@ impl UnusedParens {
// Otherwise proceed with linting.
_ => {}
}

let pattern_text =
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) {
snippet
} else {
pprust::pat_to_string(value)
};
self.emit_unused_delims(cx, value.span, &pattern_text, "pattern", (false, false));
let spans = if value.span.from_expansion() || inner.span.from_expansion() {
(
value.span.with_hi(value.span.lo() + BytePos(1)),
value.span.with_lo(value.span.hi() - BytePos(1)),
)
} else {
(value.span.with_hi(inner.span.lo()), value.span.with_lo(inner.span.hi()))
};
self.emit_unused_delims(cx, spans, "pattern", (false, false));
}
}
}
Expand Down Expand Up @@ -870,14 +853,15 @@ impl EarlyLintPass for UnusedParens {
);
}
_ => {
let pattern_text =
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(ty.span) {
snippet
} else {
pprust::ty_to_string(ty)
};

self.emit_unused_delims(cx, ty.span, &pattern_text, "type", (false, false));
let spans = if ty.span.from_expansion() || r.span.from_expansion() {
(
ty.span.with_hi(ty.span.lo() + BytePos(1)),
ty.span.with_lo(ty.span.hi() - BytePos(1)),
)
} else {
(ty.span.with_hi(r.span.lo()), ty.span.with_lo(r.span.hi()))
};
self.emit_unused_delims(cx, spans, "type", (false, false));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_macros/src/session_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
span_idx = Some(syn::Index::from(idx));
} else {
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
);
}
Expand All @@ -460,7 +460,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
applicability_idx = Some(syn::Index::from(idx));
} else {
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"type of field annotated with `#[suggestion(...)]` contains more than one Applicability"
);
}
Expand All @@ -479,15 +479,15 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
return Ok((span, applicability));
}
throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"wrong types for suggestion",
|diag| {
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type (Span, Applicability)")
}
);
}
_ => throw_span_err!(
info.span.clone().unwrap(),
info.span.unwrap(),
"wrong field type for suggestion",
|diag| {
diag.help("#[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)")
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,11 @@ impl CrateError {
== Symbol::intern(&sess.opts.debugging_opts.profiler_runtime)
{
err.note(&"the compiler may have been built without the profiler runtime");
} else if crate_name.as_str().starts_with("rustc_") {
err.help(
"maybe you need to install the missing components with: \
`rustup component add rust-src rustc-dev llvm-tools-preview`",
);
}
err.span_label(span, "can't find crate");
err
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ pub struct Place<'tcx> {
pub projection: &'tcx List<PlaceElem<'tcx>>,
}

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

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

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

impl<'tcx> Debug for Operand<'tcx> {
Expand Down Expand Up @@ -2200,7 +2200,7 @@ pub enum Rvalue<'tcx> {
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
}

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

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

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

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