Skip to content

Commit c335b4e

Browse files
committed
Auto merge of rust-lang#3301 - rust-lang:rustup-2024-02-16, r=saethlin
Automatic Rustup
2 parents 6c117f6 + 840ca09 commit c335b4e

File tree

216 files changed

+2516
-1009
lines changed

Some content is hidden

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

216 files changed

+2516
-1009
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,7 @@ dependencies = [
45884588
"rustc_data_structures",
45894589
"rustc_hir",
45904590
"rustc_middle",
4591+
"rustc_session",
45914592
"rustc_span",
45924593
"rustc_target",
45934594
"scoped-tls",

compiler/rustc_ast/src/ast.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ pub enum LitKind {
18461846
/// A boolean literal (`true`, `false`).
18471847
Bool(bool),
18481848
/// Placeholder for a literal that wasn't well-formed in some way.
1849-
Err,
1849+
Err(ErrorGuaranteed),
18501850
}
18511851

18521852
impl LitKind {
@@ -1893,7 +1893,7 @@ impl LitKind {
18931893
| LitKind::Int(_, LitIntType::Unsuffixed)
18941894
| LitKind::Float(_, LitFloatType::Unsuffixed)
18951895
| LitKind::Bool(..)
1896-
| LitKind::Err => false,
1896+
| LitKind::Err(_) => false,
18971897
}
18981898
}
18991899
}
@@ -2136,10 +2136,12 @@ pub enum TyKind {
21362136
ImplicitSelf,
21372137
/// A macro in the type position.
21382138
MacCall(P<MacCall>),
2139-
/// Placeholder for a kind that has failed to be defined.
2140-
Err,
21412139
/// Placeholder for a `va_list`.
21422140
CVarArgs,
2141+
/// Sometimes we need a dummy value when no error has occurred.
2142+
Dummy,
2143+
/// Placeholder for a kind that has failed to be defined.
2144+
Err(ErrorGuaranteed),
21432145
}
21442146

21452147
impl TyKind {

compiler/rustc_ast/src/mut_visit.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
481481
let Ty { id, kind, span, tokens } = ty.deref_mut();
482482
vis.visit_id(id);
483483
match kind {
484-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never | TyKind::CVarArgs => {}
484+
TyKind::Infer
485+
| TyKind::ImplicitSelf
486+
| TyKind::Err(_)
487+
| TyKind::Dummy
488+
| TyKind::Never
489+
| TyKind::CVarArgs => {}
485490
TyKind::Slice(ty) => vis.visit_ty(ty),
486491
TyKind::Ptr(mt) => vis.visit_mt(mt),
487492
TyKind::Ref(lt, mt) => {
@@ -1649,7 +1654,7 @@ impl DummyAstNode for Ty {
16491654
fn dummy() -> Self {
16501655
Ty {
16511656
id: DUMMY_NODE_ID,
1652-
kind: TyKind::Err,
1657+
kind: TyKind::Dummy,
16531658
span: Default::default(),
16541659
tokens: Default::default(),
16551660
}

compiler/rustc_ast/src/token.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_macros::HashStable_Generic;
1313
use rustc_span::symbol::{kw, sym};
1414
#[allow(hidden_glob_reexports)]
1515
use rustc_span::symbol::{Ident, Symbol};
16-
use rustc_span::{edition::Edition, Span, DUMMY_SP};
16+
use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP};
1717
use std::borrow::Cow;
1818
use std::fmt;
1919

@@ -75,7 +75,7 @@ pub enum LitKind {
7575
ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
7676
CStr,
7777
CStrRaw(u8),
78-
Err,
78+
Err(ErrorGuaranteed),
7979
}
8080

8181
/// A literal token.
@@ -144,7 +144,7 @@ impl fmt::Display for Lit {
144144
CStrRaw(n) => {
145145
write!(f, "cr{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))?
146146
}
147-
Integer | Float | Bool | Err => write!(f, "{symbol}")?,
147+
Integer | Float | Bool | Err(_) => write!(f, "{symbol}")?,
148148
}
149149

150150
if let Some(suffix) = suffix {
@@ -159,7 +159,7 @@ impl LitKind {
159159
/// An English article for the literal token kind.
160160
pub fn article(self) -> &'static str {
161161
match self {
162-
Integer | Err => "an",
162+
Integer | Err(_) => "an",
163163
_ => "a",
164164
}
165165
}
@@ -174,12 +174,12 @@ impl LitKind {
174174
Str | StrRaw(..) => "string",
175175
ByteStr | ByteStrRaw(..) => "byte string",
176176
CStr | CStrRaw(..) => "C string",
177-
Err => "error",
177+
Err(_) => "error",
178178
}
179179
}
180180

181181
pub(crate) fn may_have_suffix(self) -> bool {
182-
matches!(self, Integer | Float | Err)
182+
matches!(self, Integer | Float | Err(_))
183183
}
184184
}
185185

compiler/rustc_ast/src/util/literal.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ pub fn escape_byte_str_symbol(bytes: &[u8]) -> Symbol {
3131

3232
#[derive(Debug)]
3333
pub enum LitError {
34-
LexerError,
35-
InvalidSuffix,
36-
InvalidIntSuffix,
37-
InvalidFloatSuffix,
38-
NonDecimalFloat(u32),
39-
IntTooLarge(u32),
34+
InvalidSuffix(Symbol),
35+
InvalidIntSuffix(Symbol),
36+
InvalidFloatSuffix(Symbol),
37+
NonDecimalFloat(u32), // u32 is the base
38+
IntTooLarge(u32), // u32 is the base
4039
}
4140

4241
impl LitKind {
4342
/// Converts literal token into a semantic literal.
4443
pub fn from_token_lit(lit: token::Lit) -> Result<LitKind, LitError> {
4544
let token::Lit { kind, symbol, suffix } = lit;
46-
if suffix.is_some() && !kind.may_have_suffix() {
47-
return Err(LitError::InvalidSuffix);
45+
if let Some(suffix) = suffix
46+
&& !kind.may_have_suffix()
47+
{
48+
return Err(LitError::InvalidSuffix(suffix));
4849
}
4950

5051
// For byte/char/string literals, chars and escapes have already been
@@ -145,7 +146,7 @@ impl LitKind {
145146
buf.push(0);
146147
LitKind::CStr(buf.into(), StrStyle::Raw(n))
147148
}
148-
token::Err => LitKind::Err,
149+
token::Err(guar) => LitKind::Err(guar),
149150
})
150151
}
151152
}
@@ -202,7 +203,7 @@ impl fmt::Display for LitKind {
202203
}
203204
}
204205
LitKind::Bool(b) => write!(f, "{}", if b { "true" } else { "false" })?,
205-
LitKind::Err => {
206+
LitKind::Err(_) => {
206207
// This only shows up in places like `-Zunpretty=hir` output, so we
207208
// don't bother to produce something useful.
208209
write!(f, "<bad-literal>")?;
@@ -238,7 +239,7 @@ impl MetaItemLit {
238239
LitKind::Char(_) => token::Char,
239240
LitKind::Int(..) => token::Integer,
240241
LitKind::Float(..) => token::Float,
241-
LitKind::Err => token::Err,
242+
LitKind::Err(guar) => token::Err(guar),
242243
};
243244

244245
token::Lit::new(kind, self.symbol, self.suffix)
@@ -272,12 +273,12 @@ fn filtered_float_lit(
272273
return Err(LitError::NonDecimalFloat(base));
273274
}
274275
Ok(match suffix {
275-
Some(suf) => LitKind::Float(
276+
Some(suffix) => LitKind::Float(
276277
symbol,
277-
ast::LitFloatType::Suffixed(match suf {
278+
ast::LitFloatType::Suffixed(match suffix {
278279
sym::f32 => ast::FloatTy::F32,
279280
sym::f64 => ast::FloatTy::F64,
280-
_ => return Err(LitError::InvalidFloatSuffix),
281+
_ => return Err(LitError::InvalidFloatSuffix(suffix)),
281282
}),
282283
),
283284
None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed),
@@ -318,17 +319,13 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
318319
// `1f64` and `2f32` etc. are valid float literals, and
319320
// `fxxx` looks more like an invalid float literal than invalid integer literal.
320321
_ if suf.as_str().starts_with('f') => return filtered_float_lit(symbol, suffix, base),
321-
_ => return Err(LitError::InvalidIntSuffix),
322+
_ => return Err(LitError::InvalidIntSuffix(suf)),
322323
},
323324
_ => ast::LitIntType::Unsuffixed,
324325
};
325326

326327
let s = &s[if base != 10 { 2 } else { 0 }..];
327-
u128::from_str_radix(s, base).map(|i| LitKind::Int(i.into(), ty)).map_err(|_| {
328-
// Small bases are lexed as if they were base 10, e.g, the string
329-
// might be `0b10201`. This will cause the conversion above to fail,
330-
// but these kinds of errors are already reported by the lexer.
331-
let from_lexer = base < 10 && s.chars().any(|c| c.to_digit(10).is_some_and(|d| d >= base));
332-
if from_lexer { LitError::LexerError } else { LitError::IntTooLarge(base) }
333-
})
328+
u128::from_str_radix(s, base)
329+
.map(|i| LitKind::Int(i.into(), ty))
330+
.map_err(|_| LitError::IntTooLarge(base))
334331
}

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
447447
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
448448
}
449449
TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
450-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
450+
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {}
451451
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
452452
TyKind::Never | TyKind::CVarArgs => {}
453453
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {

compiler/rustc_ast_lowering/src/expr.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
124124
let lit_kind = match LitKind::from_token_lit(*token_lit) {
125125
Ok(lit_kind) => lit_kind,
126126
Err(err) => {
127-
report_lit_error(&self.tcx.sess.parse_sess, err, *token_lit, e.span);
128-
LitKind::Err
127+
let guar = report_lit_error(
128+
&self.tcx.sess.parse_sess,
129+
err,
130+
*token_lit,
131+
e.span,
132+
);
133+
LitKind::Err(guar)
129134
}
130135
};
131136
let lit = self.arena.alloc(respan(self.lower_span(e.span), lit_kind));
@@ -323,7 +328,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
323328
)
324329
}
325330
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
331+
ExprKind::Err => {
332+
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
333+
}
327334
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
328335

329336
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_ast_lowering/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -966,10 +966,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
966966
{
967967
lit
968968
} else {
969+
let guar = self.dcx().has_errors().unwrap();
969970
MetaItemLit {
970971
symbol: kw::Empty,
971972
suffix: None,
972-
kind: LitKind::Err,
973+
kind: LitKind::Err(guar),
973974
span: DUMMY_SP,
974975
}
975976
};
@@ -1285,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12851286
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12861287
let kind = match &t.kind {
12871288
TyKind::Infer => hir::TyKind::Infer,
1288-
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
1289+
TyKind::Err(guar) => hir::TyKind::Err(*guar),
12891290
// Lower the anonymous structs or unions in a nested lowering context.
12901291
//
12911292
// ```
@@ -1503,6 +1504,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15031504
);
15041505
hir::TyKind::Err(guar)
15051506
}
1507+
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
15061508
};
15071509

15081510
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }

compiler/rustc_ast_passes/src/ast_validation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
881881
&item.vis,
882882
errors::VisibilityNotPermittedNote::TraitImpl,
883883
);
884-
if let TyKind::Err = self_ty.kind {
884+
// njn: use Dummy here
885+
if let TyKind::Err(_) = self_ty.kind {
885886
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
886887
}
887888
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)

compiler/rustc_ast_pretty/src/pprust/state.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn literal_to_string(lit: token::Lit) -> String {
254254
token::CStrRaw(n) => {
255255
format!("cr{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))
256256
}
257-
token::Integer | token::Float | token::Bool | token::Err => symbol.to_string(),
257+
token::Integer | token::Float | token::Bool | token::Err(_) => symbol.to_string(),
258258
};
259259

260260
if let Some(suffix) = suffix {
@@ -1048,11 +1048,16 @@ impl<'a> State<'a> {
10481048
ast::TyKind::Infer => {
10491049
self.word("_");
10501050
}
1051-
ast::TyKind::Err => {
1051+
ast::TyKind::Err(_) => {
10521052
self.popen();
10531053
self.word("/*ERROR*/");
10541054
self.pclose();
10551055
}
1056+
ast::TyKind::Dummy => {
1057+
self.popen();
1058+
self.word("/*DUMMY*/");
1059+
self.pclose();
1060+
}
10561061
ast::TyKind::ImplicitSelf => {
10571062
self.word("Self");
10581063
}

compiler/rustc_borrowck/src/universal_regions.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![allow(rustc::diagnostic_outside_of_impl)]
1616
#![allow(rustc::untranslatable_diagnostic)]
1717

18-
use rustc_data_structures::fx::FxHashMap;
18+
use rustc_data_structures::fx::FxIndexMap;
1919
use rustc_errors::Diagnostic;
2020
use rustc_hir::def_id::{DefId, LocalDefId};
2121
use rustc_hir::lang_items::LangItem;
@@ -180,7 +180,7 @@ struct UniversalRegionIndices<'tcx> {
180180
/// basically equivalent to an `GenericArgs`, except that it also
181181
/// contains an entry for `ReStatic` -- it might be nice to just
182182
/// use an args, and then handle `ReStatic` another way.
183-
indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
183+
indices: FxIndexMap<ty::Region<'tcx>, RegionVid>,
184184

185185
/// The vid assigned to `'static`. Used only for diagnostics.
186186
pub fr_static: RegionVid,
@@ -325,9 +325,6 @@ impl<'tcx> UniversalRegions<'tcx> {
325325
}
326326

327327
/// Gets an iterator over all the early-bound regions that have names.
328-
/// Iteration order may be unstable, so this should only be used when
329-
/// iteration order doesn't affect anything
330-
#[allow(rustc::potential_query_instability)]
331328
pub fn named_universal_regions<'s>(
332329
&'s self,
333330
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {

compiler/rustc_builtin_macros/src/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn expand_concat(
4040
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
4141
has_errors = true;
4242
}
43-
Ok(ast::LitKind::Err) => {
43+
Ok(ast::LitKind::Err(_)) => {
4444
has_errors = true;
4545
}
4646
Err(err) => {

compiler/rustc_builtin_macros/src/concat_bytes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn invalid_type_err(
4444
Ok(ast::LitKind::Bool(_)) => {
4545
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "boolean", sugg: None });
4646
}
47-
Ok(ast::LitKind::Err) => {}
47+
Ok(ast::LitKind::Err(_)) => {}
4848
Ok(ast::LitKind::Int(_, _)) if !is_nested => {
4949
let sugg =
5050
snippet.map(|snippet| ConcatBytesInvalidSuggestion::IntLit { span: span, snippet });

compiler/rustc_codegen_llvm/src/back/lto.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_middle::dep_graph::WorkProduct;
2121
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
2222
use rustc_session::config::{self, CrateType, Lto};
2323

24+
use std::collections::BTreeMap;
2425
use std::ffi::{CStr, CString};
2526
use std::fs::File;
2627
use std::io;
@@ -787,7 +788,7 @@ pub unsafe fn optimize_thin_module(
787788
#[derive(Debug, Default)]
788789
pub struct ThinLTOKeysMap {
789790
// key = llvm name of importing module, value = LLVM cache key
790-
keys: FxHashMap<String, String>,
791+
keys: BTreeMap<String, String>,
791792
}
792793

793794
impl ThinLTOKeysMap {
@@ -797,7 +798,6 @@ impl ThinLTOKeysMap {
797798
let mut writer = io::BufWriter::new(file);
798799
// The entries are loaded back into a hash map in `load_from_file()`, so
799800
// the order in which we write them to file here does not matter.
800-
#[allow(rustc::potential_query_instability)]
801801
for (module, key) in &self.keys {
802802
writeln!(writer, "{module} {key}")?;
803803
}
@@ -806,7 +806,7 @@ impl ThinLTOKeysMap {
806806

807807
fn load_from_file(path: &Path) -> io::Result<Self> {
808808
use std::io::BufRead;
809-
let mut keys = FxHashMap::default();
809+
let mut keys = BTreeMap::default();
810810
let file = File::open(path)?;
811811
for line in io::BufReader::new(file).lines() {
812812
let line = line?;

0 commit comments

Comments
 (0)