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 6 pull requests #119237

Merged
merged 44 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6959818
Hoist fn absent
workingjubilee Dec 16, 2023
f116bc6
Manually inline scalar_unit
workingjubilee Dec 16, 2023
b525f76
Extract fn layout_of_enum
workingjubilee Dec 16, 2023
8facfb2
Extract fn layout_of_struct
workingjubilee Dec 16, 2023
7a246dd
Add pass to identify undefined or erroneous behaviour
tmiasko Dec 12, 2023
1d36e3a
Lint missing StorageDead when returning from functions
tmiasko Dec 16, 2023
b487775
Don't require owned data in `MaybeStorageDead`
tmiasko Dec 16, 2023
532080c
Stricter check for a use of locals without storage
tmiasko Dec 17, 2023
ba430a3
Enable -Zlint-mir by default for mir-opt tests
tmiasko Dec 21, 2023
8e34391
Add IntoAsyncIterator
eholk Dec 8, 2023
acb6f17
Use `IntoAsyncIterator` in `for await` loop desugaring
eholk Dec 19, 2023
aaa3e76
Update test outputs
eholk Dec 19, 2023
c6aa16c
Use `derivative` for better derive bounds
Nadrieril Dec 19, 2023
f6af747
Mention the relevant tracking issue next to my `bit_set` hack
Nadrieril Dec 19, 2023
5fccaee
Clarify the situation with dummy patterns and `PatData`
Nadrieril Dec 22, 2023
0044505
Split coroutine desugaring kind from source
compiler-errors Dec 21, 2023
c8c1615
Add comments to `Level`.
nnethercote Dec 19, 2023
de303b8
Streamline `struct_lint_level`.
nnethercote Dec 19, 2023
1b36958
Improve `use` items in `compiler/rustc_errors/src/lib.rs`.
nnethercote Dec 19, 2023
aec78dd
Fix a couple of left-over references to `Handler`.
nnethercote Dec 19, 2023
6257f3b
Use `IntoDiagnostic` default.
nnethercote Dec 19, 2023
757d6f6
Give `DiagnosticBuilder` a default type.
nnethercote Dec 19, 2023
a108a3b
Tweak `flush_delayed`.
nnethercote Dec 19, 2023
6f147af
Remove unnecessary line breaks from two string literals.
nnethercote Dec 19, 2023
1502596
Introduce `DiagCtxt::treat_next_err_as_bug`.
nnethercote Dec 19, 2023
1f08bfa
Remove `DiagCtxtInner::span_bug`.
nnethercote Dec 19, 2023
3a1b8e6
Rename `EarlyDiagCtxt` methods to match `DiagCtxt`.
nnethercote Dec 20, 2023
d7a3b62
Remove `Diagnostic::new_with_code`.
nnethercote Dec 20, 2023
824667f
Improve some names.
nnethercote Dec 20, 2023
125337b
Remove `render_span` args from `Diagnostic::{sub,sub_with_highlight}`.
nnethercote Dec 20, 2023
ce0f703
Remove `SubDiagnostic::render_span`.
nnethercote Dec 20, 2023
49040d0
Remove `LabelKind`.
nnethercote Dec 20, 2023
e0461f9
Take full advantage of a `use Level::*;`.
nnethercote Dec 21, 2023
3944301
Use `pub(crate)` in a couple of places.
nnethercote Dec 21, 2023
81f50fd
Fix weird code setting in `create_feature_err`.
nnethercote Dec 21, 2023
3db58e6
Fix a comment.
nnethercote Dec 21, 2023
00e8485
Remove all uses of `DiagnosticBuilder::forget_guarantee()`.
nnethercote Dec 21, 2023
2cd14bc
Remove `DiagnosticBuilder::forget_guarantee`.
nnethercote Dec 21, 2023
aaff415
Rollup merge of #119012 - workingjubilee:extract-enum-layout-fn, r=b-…
compiler-errors Dec 23, 2023
7dd0955
Rollup merge of #119077 - tmiasko:lint, r=cjgillot
compiler-errors Dec 23, 2023
e0d7a72
Rollup merge of #119171 - nnethercote:cleanup-errors-4, r=compiler-er…
compiler-errors Dec 23, 2023
ae0a6e8
Rollup merge of #119198 - compiler-errors:desugaring, r=eholk
compiler-errors Dec 23, 2023
eef023c
Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-error…
compiler-errors Dec 23, 2023
8c50e3e
Rollup merge of #119230 - Nadrieril:librarify-even-further, r=compile…
compiler-errors Dec 23, 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4340,6 +4340,7 @@ dependencies = [
name = "rustc_pattern_analysis"
version = "0.0.0"
dependencies = [
"derivative",
"rustc_apfloat",
"rustc_arena",
"rustc_data_structures",
Expand Down
1,218 changes: 634 additions & 584 deletions compiler/rustc_abi/src/layout.rs

Large diffs are not rendered by default.

55 changes: 42 additions & 13 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
let params = arena_vec![self; param];

let body = self.lower_body(move |this| {
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_coroutine_source));
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Async,
async_coroutine_source,
));

let old_ctx = this.task_context;
this.task_context = Some(task_context_hid);
Expand Down Expand Up @@ -724,7 +727,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
});

let body = self.lower_body(move |this| {
this.coroutine_kind = Some(hir::CoroutineKind::Gen(coroutine_source));
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Gen,
coroutine_source,
));

let res = body(this);
(&[], res)
Expand Down Expand Up @@ -802,7 +808,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
let params = arena_vec![self; param];

let body = self.lower_body(move |this| {
this.coroutine_kind = Some(hir::CoroutineKind::AsyncGen(async_coroutine_source));
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::AsyncGen,
async_coroutine_source,
));

let old_ctx = this.task_context;
this.task_context = Some(task_context_hid);
Expand Down Expand Up @@ -888,9 +897,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let full_span = expr.span.to(await_kw_span);

let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Async(_)) => false,
Some(hir::CoroutineKind::AsyncGen(_)) => true,
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
Some(hir::CoroutineKind::Coroutine)
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
| None => {
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
Expand Down Expand Up @@ -1123,9 +1134,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(movability)
}
Some(
hir::CoroutineKind::Gen(_)
| hir::CoroutineKind::Async(_)
| hir::CoroutineKind::AsyncGen(_),
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
| hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
| hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _),
) => {
panic!("non-`async`/`gen` closure body turned `async`/`gen` during lowering");
}
Expand Down Expand Up @@ -1638,9 +1649,9 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
let is_async_gen = match self.coroutine_kind {
Some(hir::CoroutineKind::Gen(_)) => false,
Some(hir::CoroutineKind::AsyncGen(_)) => true,
Some(hir::CoroutineKind::Async(_)) => {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
return hir::ExprKind::Err(
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }),
);
Expand Down Expand Up @@ -1803,7 +1814,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
arena_vec![self; head],
)
}
ForLoopKind::ForAwait => self.arena.alloc(head),
// ` unsafe { Pin::new_unchecked(&mut into_async_iter(<head>)) }`
ForLoopKind::ForAwait => {
// `::core::async_iter::IntoAsyncIterator::into_async_iter(<head>)`
let iter = self.expr_call_lang_item_fn(
head_span,
hir::LangItem::IntoAsyncIterIntoIter,
arena_vec![self; head],
);
let iter = self.expr_mut_addr_of(head_span, iter);
// `Pin::new_unchecked(...)`
let iter = self.arena.alloc(self.expr_call_lang_item_fn_mut(
head_span,
hir::LangItem::PinNewUnchecked,
arena_vec![self; iter],
));
// `unsafe { ... }`
let iter = self.arena.alloc(self.expr_unsafe(iter));
iter
}
};

let match_expr = self.arena.alloc(self.expr_match(
Expand Down
56 changes: 26 additions & 30 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan,
};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;
Expand All @@ -12,7 +12,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
place: &str,
borrow_place: &str,
value_place: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
self.infcx.tcx.sess.create_err(crate::session_diagnostics::MoveBorrow {
place,
span,
Expand All @@ -28,7 +28,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc: &str,
borrow_span: Span,
borrow_desc: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
self,
span,
Expand All @@ -50,7 +50,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_loan_span: Span,
old_opt_via: &str,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
self,
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc: &str,
old_loan_span: Span,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
self,
new_loan_span,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
noun_old: &str,
old_opt_via: &str,
previous_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
self,
new_loan_span,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str,
previous_end_span: Option<Span>,
second_borrow_desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
self,
new_loan_span,
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
kind_old: &str,
msg_old: &str,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
self,
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
borrow_span: Span,
desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
self,
span,
Expand All @@ -254,24 +254,20 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
desc: &str,
is_arg: bool,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
}

pub(crate) fn cannot_assign(
&self,
span: Span,
desc: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
}

pub(crate) fn cannot_move_out_of(
&self,
move_from_span: Span,
move_from_desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc)
}

Expand All @@ -283,7 +279,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
ty: Ty<'_>,
is_index: Option<bool>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let type_name = match (&ty.kind(), is_index) {
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
(&ty::Slice(_), _) => "slice",
Expand All @@ -305,7 +301,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
move_from_span: Span,
container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
self,
move_from_span,
Expand All @@ -323,7 +319,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
verb: &str,
optional_adverb_for_moved: &str,
moved_path: Option<String>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();

struct_span_err!(
Expand All @@ -342,7 +338,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
path: &str,
reason: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{}", path, reason,)
}

Expand All @@ -353,7 +349,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_place: &str,
immutable_section: &str,
action: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
self,
mutate_span,
Expand All @@ -372,7 +368,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
span: Span,
yield_span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
let mut err = struct_span_err!(
self,
Expand All @@ -387,7 +383,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
pub(crate) fn cannot_borrow_across_destructor(
&self,
borrow_span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
self,
borrow_span,
Expand All @@ -400,7 +396,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
span: Span,
path: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
}

Expand All @@ -410,7 +406,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
return_kind: &str,
reference_desc: &str,
path_desc: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
self,
span,
Expand All @@ -436,7 +432,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrowed_path: &str,
capture_span: Span,
scope: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
self,
closure_span,
Expand All @@ -452,14 +448,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
pub(crate) fn thread_local_value_does_not_live_long_enough(
&self,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
}

pub(crate) fn temporary_value_borrowed_for_too_long(
&self,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
}

Expand All @@ -470,7 +466,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
sp: S,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
}
}
Expand All @@ -479,7 +475,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
tcx: TyCtxt<'tcx>,
escape_span: Span,
escapes_from: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
tcx.sess,
escape_span,
Expand Down
Loading
Loading