Skip to content
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

Rollup of 8 pull requests #107600

Closed
wants to merge 19 commits into from
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
00f821f
Suggest `move` in nested closure when appropriate
estebank Jan 7, 2023
05ee406
Add test.
cjgillot Jan 31, 2023
3c10cf0
Remove both StorageLive and StorageDead in CopyProp.
cjgillot Jan 31, 2023
e8ac040
Remove assignment.
cjgillot Jan 31, 2023
2c23c7f
Erase regions before uninhabited check
compiler-errors Jan 31, 2023
3a75f10
Improve pretty-printing of `HirIdValidator` errors
Swatinem Jan 31, 2023
e30cd18
Reinstate the `hir-stats.rs` tests on stage 1.
nnethercote Feb 1, 2023
9dd5d3e
Recover _ as .. in field pattern
compiler-errors Jan 15, 2023
9fe8ae7
Rename `rust_2015` => `is_rust_2015`
WaffleLapkin Feb 1, 2023
a7f97a7
Use `rust_2018` instead of `!is_rust_2015`
WaffleLapkin Feb 1, 2023
4ab75de
Improve diagnostic for missing space in range pattern
clubby789 Jan 30, 2023
52cb29d
Rollup merge of #106575 - estebank:issue-64008, r=pnkfelix
matthiaskrgr Feb 2, 2023
6e7cb8f
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pa…
matthiaskrgr Feb 2, 2023
0b4f828
Rollup merge of #107493 - clubby789:range-fat-arrow-followup, r=estebank
matthiaskrgr Feb 2, 2023
df8d2f6
Rollup merge of #107515 - Swatinem:hirvalidator, r=compiler-errors
matthiaskrgr Feb 2, 2023
4cf01cf
Rollup merge of #107524 - cjgillot:both-storage, r=RalfJung
matthiaskrgr Feb 2, 2023
e41dcf0
Rollup merge of #107532 - compiler-errors:erase-regions-in-uninhabite…
matthiaskrgr Feb 2, 2023
fb11f77
Rollup merge of #107559 - WaffleLapkin:is_it_2015¿, r=davidtwco
matthiaskrgr Feb 2, 2023
09a9dd0
Rollup merge of #107577 - nnethercote:reinstate-hir-stats, r=jyn514
matthiaskrgr Feb 2, 2023
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ pub fn print_crate<'a>(

// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
// root, so this is not needed, and actually breaks things.
if edition.rust_2015() {
if edition.is_rust_2015() {
// `#![no_std]`
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr);
28 changes: 12 additions & 16 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
@@ -583,10 +583,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let err = FnMutError {
span: *span,
ty_err: match output_ty.kind() {
ty::Closure(_, _) => FnMutReturnTypeErr::ReturnClosure { span: *span },
ty::Generator(def, ..) if self.infcx.tcx.generator_is_async(*def) => {
FnMutReturnTypeErr::ReturnAsyncBlock { span: *span }
}
_ if output_ty.contains_closure() => {
FnMutReturnTypeErr::ReturnClosure { span: *span }
}
_ => FnMutReturnTypeErr::ReturnRef { span: *span },
},
};
@@ -997,7 +999,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diagnostic) {
let map = self.infcx.tcx.hir();
let body_id = map.body_owned_by(self.mir_def_id());
let expr = &map.body(body_id).value;
let expr = &map.body(body_id).value.peel_blocks();
let mut closure_span = None::<rustc_span::Span>;
match expr.kind {
hir::ExprKind::MethodCall(.., args, _) => {
@@ -1012,20 +1014,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}
}
hir::ExprKind::Block(blk, _) => {
if let Some(expr) = blk.expr {
// only when the block is a closure
if let hir::ExprKind::Closure(hir::Closure {
capture_clause: hir::CaptureBy::Ref,
body,
..
}) = expr.kind
{
let body = map.body(*body);
if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) {
closure_span = Some(expr.span.shrink_to_lo());
}
}
hir::ExprKind::Closure(hir::Closure {
capture_clause: hir::CaptureBy::Ref,
body,
..
}) => {
let body = map.body(*body);
if !matches!(body.generator_kind, Some(hir::GeneratorKind::Async(..))) {
closure_span = Some(expr.span.shrink_to_lo());
}
}
_ => {}
5 changes: 4 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
@@ -1484,7 +1484,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
None => {
if !sig.output().is_privately_uninhabited(self.tcx(), self.param_env) {
// The signature in this call can reference region variables,
// so erase them before calling a query.
let output_ty = self.tcx().erase_regions(sig.output());
if !output_ty.is_privately_uninhabited(self.tcx(), self.param_env) {
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
}
}
9 changes: 5 additions & 4 deletions compiler/rustc_error_messages/locales/en-US/parse.ftl
Original file line number Diff line number Diff line change
@@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
.suggestion_remove_eq = use `..=` instead
.note = inclusive ranges end with a single equals sign (`..=`)

parse_inclusive_range_match_arrow = unexpected `=>` after open range
.suggestion_add_space = add a space between the pattern and `=>`
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
.label = this is parsed as an inclusive range `..=`
.suggestion = add a space between the pattern and `=>`

parse_inclusive_range_no_end = inclusive range with no end
.suggestion_open_range = use `..` instead
@@ -535,8 +536,8 @@ parse_dot_dot_dot_range_to_pattern_not_allowed = range-to patterns with `...` ar

parse_enum_pattern_instead_of_identifier = expected identifier, found enum pattern

parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `...`
.suggestion = to omit remaining fields, use one fewer `.`
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `{$token_str}`
.suggestion = to omit remaining fields, use `..`

parse_expected_comma_after_pattern_field = expected `,`

3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
@@ -454,8 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
None => {
bug!(
"no type for node {}: {} in fcx {}",
id,
"no type for node {} in fcx {}",
self.tcx.hir().node_to_string(id),
self.tag()
);
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/mem_categorization.rs
Original file line number Diff line number Diff line change
@@ -155,8 +155,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
None if self.is_tainted_by_errors() => Err(()),
None => {
bug!(
"no type for node {}: {} in mem_categorization",
id,
"no type for node {} in mem_categorization",
self.tcx().hir().node_to_string(id)
);
}
27 changes: 12 additions & 15 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -290,7 +290,7 @@ impl<'hir> Map<'hir> {
#[track_caller]
pub fn parent_id(self, hir_id: HirId) -> HirId {
self.opt_parent_id(hir_id)
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
.unwrap_or_else(|| bug!("No parent for node {}", self.node_to_string(hir_id)))
}

pub fn get_parent(self, hir_id: HirId) -> Node<'hir> {
@@ -1191,12 +1191,10 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
}

fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
let id_str = format!(" (hir_id={})", id);

let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id());

let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default();
let node_str = |prefix| format!("{} {}{}", prefix, span_str(), id_str);
let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str());

match map.find(id) {
Some(Node::Item(item)) => {
@@ -1225,18 +1223,18 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl { .. } => "impl",
};
format!("{} {}{}", item_str, path_str(item.owner_id.def_id), id_str)
format!("{id} ({item_str} {})", path_str(item.owner_id.def_id))
}
Some(Node::ForeignItem(item)) => {
format!("foreign item {}{}", path_str(item.owner_id.def_id), id_str)
format!("{id} (foreign item {})", path_str(item.owner_id.def_id))
}
Some(Node::ImplItem(ii)) => {
let kind = match ii.kind {
ImplItemKind::Const(..) => "assoc const",
ImplItemKind::Fn(..) => "method",
ImplItemKind::Type(_) => "assoc type",
};
format!("{} {} in {}{}", kind, ii.ident, path_str(ii.owner_id.def_id), id_str)
format!("{id} ({kind} `{}` in {})", ii.ident, path_str(ii.owner_id.def_id))
}
Some(Node::TraitItem(ti)) => {
let kind = match ti.kind {
@@ -1245,13 +1243,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
TraitItemKind::Type(..) => "assoc type",
};

format!("{} {} in {}{}", kind, ti.ident, path_str(ti.owner_id.def_id), id_str)
format!("{id} ({kind} `{}` in {})", ti.ident, path_str(ti.owner_id.def_id))
}
Some(Node::Variant(ref variant)) => {
format!("variant {} in {}{}", variant.ident, path_str(variant.def_id), id_str)
format!("{id} (variant `{}` in {})", variant.ident, path_str(variant.def_id))
}
Some(Node::Field(ref field)) => {
format!("field {} in {}{}", field.ident, path_str(field.def_id), id_str)
format!("{id} (field `{}` in {})", field.ident, path_str(field.def_id))
}
Some(Node::AnonConst(_)) => node_str("const"),
Some(Node::Expr(_)) => node_str("expr"),
@@ -1269,16 +1267,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Some(Node::Infer(_)) => node_str("infer"),
Some(Node::Local(_)) => node_str("local"),
Some(Node::Ctor(ctor)) => format!(
"ctor {}{}",
"{id} (ctor {})",
ctor.ctor_def_id().map_or("<missing path>".into(), |def_id| path_str(def_id)),
id_str
),
Some(Node::Lifetime(_)) => node_str("lifetime"),
Some(Node::GenericParam(ref param)) => {
format!("generic_param {}{}", path_str(param.def_id), id_str)
format!("{id} (generic_param {})", path_str(param.def_id))
}
Some(Node::Crate(..)) => String::from("root_crate"),
None => format!("unknown node{}", id_str),
Some(Node::Crate(..)) => String::from("(root_crate)"),
None => format!("{id} (unknown node)"),
}
}

2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
@@ -2171,7 +2171,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.late_bound_vars_map(id.owner)
.and_then(|map| map.get(&id.local_id).cloned())
.unwrap_or_else(|| {
bug!("No bound vars found for {:?} ({:?})", self.hir().node_to_string(id), id)
bug!("No bound vars found for {}", self.hir().node_to_string(id))
})
.iter(),
)
22 changes: 22 additions & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -2043,6 +2043,28 @@ impl<'tcx> Ty<'tcx> {
cf.is_break()
}

/// Checks whether a type recursively contains any closure
///
/// Example: `Option<[closure@file.rs:4:20]>` returns true
pub fn contains_closure(self) -> bool {
struct ContainsClosureVisitor;

impl<'tcx> TypeVisitor<'tcx> for ContainsClosureVisitor {
type BreakTy = ();

fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::Closure(_, _) = t.kind() {
ControlFlow::BREAK
} else {
t.super_visit_with(self)
}
}
}

let cf = self.visit_with(&mut ContainsClosureVisitor);
cf.is_break()
}

/// Returns the type and mutability of `*ty`.
///
/// The parameter `explicit` indicates if this is an *explicit* dereference.
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/typeck_results.rs
Original file line number Diff line number Diff line change
@@ -372,7 +372,7 @@ impl<'tcx> TypeckResults<'tcx> {

pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
self.node_type_opt(id).unwrap_or_else(|| {
bug!("node_type: no type for node `{}`", tls::with(|tcx| tcx.hir().node_to_string(id)))
bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id)))
})
}

@@ -551,9 +551,8 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
ty::tls::with(|tcx| {
bug!(
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
"node {} cannot be placed in TypeckResults with hir_owner {:?}",
tcx.hir().node_to_string(hir_id),
hir_id.owner,
hir_owner
)
});
25 changes: 14 additions & 11 deletions compiler/rustc_mir_transform/src/copy_prop.rs
Original file line number Diff line number Diff line change
@@ -162,17 +162,20 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
}

fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) {
if let StatementKind::StorageDead(l) = stmt.kind
&& self.storage_to_remove.contains(l)
{
stmt.make_nop();
} else if let StatementKind::Assign(box (ref place, ref mut rvalue)) = stmt.kind
&& place.as_local().is_some()
{
// Do not replace assignments.
self.visit_rvalue(rvalue, loc)
} else {
self.super_statement(stmt, loc);
match stmt.kind {
// When removing storage statements, we need to remove both (#107511).
StatementKind::StorageLive(l) | StatementKind::StorageDead(l)
if self.storage_to_remove.contains(l) =>
{
stmt.make_nop()
}
StatementKind::Assign(box (ref place, ref mut rvalue))
if place.as_local().is_some() =>
{
// Do not replace assignments.
self.visit_rvalue(rvalue, loc)
}
_ => self.super_statement(stmt, loc),
}
}
}
14 changes: 7 additions & 7 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility};
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
@@ -668,13 +670,10 @@ pub(crate) struct InclusiveRangeExtraEquals {
#[diag(parse_inclusive_range_match_arrow)]
pub(crate) struct InclusiveRangeMatchArrow {
#[primary_span]
pub arrow: Span,
#[label]
pub span: Span,
#[suggestion(
suggestion_add_space,
style = "verbose",
code = " ",
applicability = "machine-applicable"
)]
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
pub after_pat: Span,
}

@@ -1802,8 +1801,9 @@ pub(crate) struct EnumPatternInsteadOfIdentifier {
#[diag(parse_dot_dot_dot_for_remaining_fields)]
pub(crate) struct DotDotDotForRemainingFields {
#[primary_span]
#[suggestion(code = "..", applicability = "machine-applicable")]
#[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")]
pub span: Span,
pub token_str: Cow<'static, str>,
}

#[derive(Diagnostic)]
8 changes: 8 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -2717,6 +2717,14 @@ impl<'a> Parser<'a> {
);
err.emit();
this.bump();
} else if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we supress the error here
err.delay_as_bug();
this.bump();
} else {
return Err(err);
}
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
@@ -2247,7 +2247,7 @@ impl<'a> Parser<'a> {
let ext = self.parse_extern(case);

if let Async::Yes { span, .. } = asyncness {
if span.rust_2015() {
if span.is_rust_2015() {
self.sess.emit_err(AsyncFnIn2015 { span, help: HelpUseLatestEdition::new() });
}
}
20 changes: 12 additions & 8 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
@@ -743,7 +743,7 @@ impl<'a> Parser<'a> {
}
token::Gt if no_space => {
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat });
self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow: tok.span, after_pat });
}
_ => {
self.sess.emit_err(InclusiveRangeNoEnd { span });
@@ -962,12 +962,15 @@ impl<'a> Parser<'a> {
}
ate_comma = false;

if self.check(&token::DotDot) || self.token == token::DotDotDot {
if self.check(&token::DotDot)
|| self.check_noexpect(&token::DotDotDot)
|| self.check_keyword(kw::Underscore)
{
etc = true;
let mut etc_sp = self.token.span;

self.recover_one_fewer_dotdot();
self.bump(); // `..` || `...`
self.recover_bad_dot_dot();
self.bump(); // `..` || `...` || `_`

if self.token == token::CloseDelim(Delimiter::Brace) {
etc_span = Some(etc_sp);
@@ -1060,14 +1063,15 @@ impl<'a> Parser<'a> {
Ok((fields, etc))
}

/// Recover on `...` as if it were `..` to avoid further errors.
/// Recover on `...` or `_` as if it were `..` to avoid further errors.
/// See issue #46718.
fn recover_one_fewer_dotdot(&self) {
if self.token != token::DotDotDot {
fn recover_bad_dot_dot(&self) {
if self.token == token::DotDot {
return;
}

self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span });
let token_str = pprust::token_to_string(&self.token);
self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span, token_str });
}

fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {
Loading