Skip to content

Commit c4e0cd9

Browse files
committed
Auto merge of rust-lang#108488 - matthiaskrgr:rollup-i61epcw, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#107941 (Treat `str` as containing `[u8]` for auto trait purposes) - rust-lang#108299 (Require `literal`s for some `(u)int_impl!` parameters) - rust-lang#108337 (hir-analysis: make a helpful note) - rust-lang#108379 (Add `ErrorGuaranteed` to `hir::{Expr,Ty}Kind::Err` variants) - rust-lang#108418 (Replace parse_[sth]_expr with parse_expr_[sth] function names) - rust-lang#108424 (rustc_infer: Consolidate obligation elaboration de-duplication) - rust-lang#108475 (Fix `VecDeque::shrink_to` and add tests.) - rust-lang#108482 (statically guarantee that current error codes are documented) - rust-lang#108484 (Remove `from` lang item) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 43ee4d1 + 9c27fc7 commit c4e0cd9

File tree

62 files changed

+492
-427
lines changed

Some content is hidden

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

62 files changed

+492
-427
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ name = "error_index_generator"
14451445
version = "0.0.0"
14461446
dependencies = [
14471447
"mdbook",
1448+
"rustc_error_codes",
14481449
]
14491450

14501451
[[package]]

compiler/rustc_ast_lowering/src/expr.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
8888
let kind = hir::ExprKind::Box(self.lower_expr(&inner));
8989
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
9090
} else {
91-
self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
92-
hir::ExprKind::Err
91+
let guar = self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
92+
hir::ExprKind::Err(guar)
9393
}
9494
} else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
9595
self.lower_legacy_const_generics((**f).clone(), args.clone(), &legacy_args)
@@ -266,8 +266,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
266266
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), *lims)
267267
}
268268
ExprKind::Underscore => {
269-
self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span });
270-
hir::ExprKind::Err
269+
let guar = self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span });
270+
hir::ExprKind::Err(guar)
271271
}
272272
ExprKind::Path(qself, path) => {
273273
let qpath = self.lower_qpath(
@@ -299,8 +299,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
299299
let rest = match &se.rest {
300300
StructRest::Base(e) => Some(self.lower_expr(e)),
301301
StructRest::Rest(sp) => {
302-
self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp });
303-
Some(&*self.arena.alloc(self.expr_err(*sp)))
302+
let guar =
303+
self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp });
304+
Some(&*self.arena.alloc(self.expr_err(*sp, guar)))
304305
}
305306
StructRest::None => None,
306307
};
@@ -318,7 +319,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
318319
)
319320
}
320321
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
321-
ExprKind::Err => hir::ExprKind::Err,
322+
ExprKind::Err => hir::ExprKind::Err(
323+
self.tcx.sess.delay_span_bug(e.span, "lowered ExprKind::Err"),
324+
),
322325
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
323326

324327
ExprKind::Paren(_) | ExprKind::ForLoop(..) => unreachable!("already handled"),
@@ -761,7 +764,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
761764
self.expr_ident_mut(span, task_context_ident, task_context_hid)
762765
} else {
763766
// Use of `await` outside of an async context, we cannot use `task_context` here.
764-
self.expr_err(span)
767+
self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no task_context hir id"))
765768
};
766769
let new_unchecked = self.expr_call_lang_item_fn_mut(
767770
span,

compiler/rustc_ast_lowering/src/format.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ fn make_count<'hir>(
102102
let value = ctx.arena.alloc_from_iter([ctx.expr_usize(sp, i)]);
103103
ctx.expr_call_mut(sp, count_param, value)
104104
} else {
105-
ctx.expr(sp, hir::ExprKind::Err)
105+
ctx.expr(
106+
sp,
107+
hir::ExprKind::Err(
108+
ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count"),
109+
),
110+
)
106111
}
107112
}
108113
None => ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatCount, sym::Implied),
@@ -135,7 +140,10 @@ fn make_format_spec<'hir>(
135140
argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait)));
136141
ctx.expr_usize(sp, i)
137142
}
138-
Err(_) => ctx.expr(sp, hir::ExprKind::Err),
143+
Err(_) => ctx.expr(
144+
sp,
145+
hir::ExprKind::Err(ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count")),
146+
),
139147
};
140148
let &FormatOptions {
141149
ref width,
@@ -294,7 +302,12 @@ fn expand_format_args<'hir>(
294302
));
295303
make_argument(ctx, sp, arg, ty)
296304
} else {
297-
ctx.expr(macsp, hir::ExprKind::Err)
305+
ctx.expr(
306+
macsp,
307+
hir::ExprKind::Err(
308+
ctx.tcx.sess.delay_span_bug(macsp, format!("no arg at {arg_index}")),
309+
),
310+
)
298311
}
299312
}));
300313
let elements: Vec<_> = arguments

compiler/rustc_ast_lowering/src/item.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::ptr::P;
77
use rustc_ast::visit::AssocCtxt;
88
use rustc_ast::*;
99
use rustc_data_structures::sorted_map::SortedMap;
10+
use rustc_errors::ErrorGuaranteed;
1011
use rustc_hir as hir;
1112
use rustc_hir::def::{DefKind, Res};
1213
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
@@ -284,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284285
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
285286
},
286287
ItemKind::GlobalAsm(asm) => hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm)),
287-
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: Some(ty), .. }) => {
288+
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty, .. }) => {
288289
// We lower
289290
//
290291
// type Foo = impl Trait
@@ -299,18 +300,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
299300
&generics,
300301
id,
301302
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
302-
|this| this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
303-
);
304-
hir::ItemKind::TyAlias(ty, generics)
305-
}
306-
ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: None, .. }) => {
307-
let mut generics = generics.clone();
308-
add_ty_alias_where_clause(&mut generics, *where_clauses, true);
309-
let (generics, ty) = self.lower_generics(
310-
&generics,
311-
id,
312-
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
313-
|this| this.arena.alloc(this.ty(span, hir::TyKind::Err)),
303+
|this| match ty {
304+
None => {
305+
let guar = this.tcx.sess.delay_span_bug(
306+
span,
307+
"expected to lower type alias type, but it was missing",
308+
);
309+
this.arena.alloc(this.ty(span, hir::TyKind::Err(guar)))
310+
}
311+
Some(ty) => this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
312+
},
314313
);
315314
hir::ItemKind::TyAlias(ty, generics)
316315
}
@@ -798,8 +797,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
798797
}
799798

800799
/// Construct `ExprKind::Err` for the given `span`.
801-
pub(crate) fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
802-
self.expr(span, hir::ExprKind::Err)
800+
pub(crate) fn expr_err(&mut self, span: Span, guar: ErrorGuaranteed) -> hir::Expr<'hir> {
801+
self.expr(span, hir::ExprKind::Err(guar))
803802
}
804803

805804
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
@@ -847,7 +846,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
847846
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
848847
|this| match ty {
849848
None => {
850-
let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err));
849+
let guar = this.tcx.sess.delay_span_bug(
850+
i.span,
851+
"expected to lower associated type, but it was missing",
852+
);
853+
let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err(guar)));
851854
hir::ImplItemKind::Type(ty)
852855
}
853856
Some(ty) => {
@@ -973,7 +976,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
973976
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
974977
match block {
975978
Some(block) => self.lower_block_expr(block),
976-
None => self.expr_err(span),
979+
None => self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no block")),
977980
}
978981
}
979982

@@ -983,7 +986,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
983986
&[],
984987
match expr {
985988
Some(expr) => this.lower_expr_mut(expr),
986-
None => this.expr_err(span),
989+
None => this.expr_err(span, this.tcx.sess.delay_span_bug(span, "no block")),
987990
},
988991
)
989992
})

compiler/rustc_ast_lowering/src/lib.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10821082
hir::TypeBindingKind::Constraint { bounds }
10831083
}
10841084
DesugarKind::Error(position) => {
1085-
self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding {
1085+
let guar = self.tcx.sess.emit_err(errors::MisplacedAssocTyBinding {
10861086
span: constraint.span,
10871087
position: DiagnosticArgFromDisplay(position),
10881088
});
1089-
let err_ty = &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err));
1089+
let err_ty =
1090+
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
10901091
hir::TypeBindingKind::Equality { term: err_ty.into() }
10911092
}
10921093
}
@@ -1255,7 +1256,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12551256
fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir> {
12561257
let kind = match &t.kind {
12571258
TyKind::Infer => hir::TyKind::Infer,
1258-
TyKind::Err => hir::TyKind::Err,
1259+
TyKind::Err => {
1260+
hir::TyKind::Err(self.tcx.sess.delay_span_bug(t.span, "TyKind::Err lowered"))
1261+
}
12591262
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
12601263
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
12611264
TyKind::Ref(region, mt) => {
@@ -1381,7 +1384,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13811384
path
13821385
}
13831386
ImplTraitContext::FeatureGated(position, feature) => {
1384-
self.tcx
1387+
let guar = self
1388+
.tcx
13851389
.sess
13861390
.create_feature_err(
13871391
MisplacedImplTrait {
@@ -1391,24 +1395,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13911395
*feature,
13921396
)
13931397
.emit();
1394-
hir::TyKind::Err
1398+
hir::TyKind::Err(guar)
13951399
}
13961400
ImplTraitContext::Disallowed(position) => {
1397-
self.tcx.sess.emit_err(MisplacedImplTrait {
1401+
let guar = self.tcx.sess.emit_err(MisplacedImplTrait {
13981402
span: t.span,
13991403
position: DiagnosticArgFromDisplay(position),
14001404
});
1401-
hir::TyKind::Err
1405+
hir::TyKind::Err(guar)
14021406
}
14031407
}
14041408
}
14051409
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
14061410
TyKind::CVarArgs => {
1407-
self.tcx.sess.delay_span_bug(
1411+
let guar = self.tcx.sess.delay_span_bug(
14081412
t.span,
14091413
"`TyKind::CVarArgs` should have been handled elsewhere",
14101414
);
1411-
hir::TyKind::Err
1415+
hir::TyKind::Err(guar)
14121416
}
14131417
};
14141418

compiler/rustc_ast_lowering/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
330330
ExprKind::Path(..) if allow_paths => {}
331331
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
332332
_ => {
333-
self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
334-
return self.arena.alloc(self.expr_err(expr.span));
333+
let guar = self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
334+
return self.arena.alloc(self.expr_err(expr.span, guar));
335335
}
336336
}
337337
self.lower_expr(expr)

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn parse_asm_args<'a>(
152152
ast::InlineAsmOperand::InOut { reg, expr, late: true }
153153
}
154154
} else if p.eat_keyword(kw::Const) {
155-
let anon_const = p.parse_anon_const_expr()?;
155+
let anon_const = p.parse_expr_anon_const()?;
156156
ast::InlineAsmOperand::Const { anon_const }
157157
} else if p.eat_keyword(sym::sym) {
158158
let expr = p.parse_expr()?;

compiler/rustc_driver_impl/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
485485
let normalised =
486486
if upper_cased_code.starts_with('E') { upper_cased_code } else { format!("E{code:0>4}") };
487487
match registry.try_find_description(&normalised) {
488-
Ok(Some(description)) => {
488+
Ok(description) => {
489489
let mut is_in_code_block = false;
490490
let mut text = String::new();
491491
// Slice off the leading newline and print.
@@ -509,9 +509,6 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
509509
print!("{text}");
510510
}
511511
}
512-
Ok(None) => {
513-
early_error(output, &format!("no extended information for {code}"));
514-
}
515512
Err(InvalidErrorCode) => {
516513
early_error(output, &format!("{code} is not a valid error code"));
517514
}

compiler/rustc_error_codes/src/error_codes.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ E0790: include_str!("./error_codes/E0790.md"),
513513
E0791: include_str!("./error_codes/E0791.md"),
514514
E0792: include_str!("./error_codes/E0792.md"),
515515
E0793: include_str!("./error_codes/E0793.md"),
516-
;
516+
}
517+
518+
// Undocumented removed error codes. Note that many removed error codes are documented.
517519
// E0006, // merged with E0005
518520
// E0008, // cannot bind by-move into a pattern guard
519521
// E0019, // merged into E0015
@@ -570,7 +572,7 @@ E0793: include_str!("./error_codes/E0793.md"),
570572
// E0246, // invalid recursive type
571573
// E0247,
572574
// E0248, // value used as a type, now reported earlier during resolution
573-
// as E0412
575+
// // as E0412
574576
// E0249,
575577
// E0257,
576578
// E0258,
@@ -631,14 +633,14 @@ E0793: include_str!("./error_codes/E0793.md"),
631633
// E0558, // replaced with a generic attribute input check
632634
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
633635
// E0564, // only named lifetimes are allowed in `impl Trait`,
634-
// but `{}` was found in the type `{}`
636+
// // but `{}` was found in the type `{}`
635637
// E0598, // lifetime of {} is too short to guarantee its contents can be...
636638
// E0611, // merged into E0616
637639
// E0612, // merged into E0609
638640
// E0613, // Removed (merged with E0609)
639641
// E0629, // missing 'feature' (rustc_const_unstable)
640642
// E0630, // rustc_const_unstable attribute must be paired with stable/unstable
641-
// attribute
643+
// // attribute
642644
// E0645, // trait aliases not finished
643645
// E0694, // an unknown tool name found in scoped attributes
644646
// E0702, // replaced with a generic attribute input check
@@ -647,4 +649,3 @@ E0793: include_str!("./error_codes/E0793.md"),
647649
// E0721, // `await` keyword
648650
// E0723, // unstable feature in `const` context
649651
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
650-
}

compiler/rustc_error_codes/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
//! the goal being to make their maintenance easier.
66
77
macro_rules! register_diagnostics {
8-
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
9-
pub static DIAGNOSTICS: &[(&str, Option<&str>)] = &[
10-
$( (stringify!($ecode), Some($message)), )*
11-
$( (stringify!($code), None), )*
8+
($($ecode:ident: $message:expr,)*) => (
9+
pub static DIAGNOSTICS: &[(&str, &str)] = &[
10+
$( (stringify!($ecode), $message), )*
1211
];
1312
)
1413
}

compiler/rustc_errors/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl DiagnosticCode {
580580
let je_result =
581581
je.registry.as_ref().map(|registry| registry.try_find_description(&s)).unwrap();
582582

583-
DiagnosticCode { code: s, explanation: je_result.unwrap_or(None) }
583+
DiagnosticCode { code: s, explanation: je_result.ok() }
584584
})
585585
}
586586
}

compiler/rustc_errors/src/lib.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub use rustc_error_messages::{
4242
pub use rustc_lint_defs::{pluralize, Applicability};
4343
use rustc_macros::fluent_messages;
4444
use rustc_span::source_map::SourceMap;
45-
use rustc_span::HashStableContext;
45+
pub use rustc_span::ErrorGuaranteed;
4646
use rustc_span::{Loc, Span};
4747

4848
use std::borrow::Cow;
@@ -1477,9 +1477,7 @@ impl HandlerInner {
14771477
.emitted_diagnostic_codes
14781478
.iter()
14791479
.filter_map(|x| match &x {
1480-
DiagnosticId::Error(s)
1481-
if registry.try_find_description(s).map_or(false, |o| o.is_some()) =>
1482-
{
1480+
DiagnosticId::Error(s) if registry.try_find_description(s).is_ok() => {
14831481
Some(s.clone())
14841482
}
14851483
_ => None,
@@ -1846,17 +1844,3 @@ pub enum TerminalUrl {
18461844
Yes,
18471845
Auto,
18481846
}
1849-
1850-
/// Useful type to use with `Result<>` indicate that an error has already
1851-
/// been reported to the user, so no need to continue checking.
1852-
#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq, PartialOrd, Ord)]
1853-
#[derive(HashStable_Generic)]
1854-
pub struct ErrorGuaranteed(());
1855-
1856-
impl ErrorGuaranteed {
1857-
/// To be used only if you really know what you are doing... ideally, we would find a way to
1858-
/// eliminate all calls to this method.
1859-
pub fn unchecked_claim_error_was_emitted() -> Self {
1860-
ErrorGuaranteed(())
1861-
}
1862-
}

0 commit comments

Comments
 (0)