Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Conjob Bot committed Feb 16, 2024
2 parents 089eb6b + db4ba49 commit f1abde7
Show file tree
Hide file tree
Showing 215 changed files with 2,508 additions and 980 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,7 @@ dependencies = [
"rustc_data_structures",
"rustc_hir",
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_target",
"scoped-tls",
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ pub enum LitKind {
/// A boolean literal (`true`, `false`).
Bool(bool),
/// Placeholder for a literal that wasn't well-formed in some way.
Err,
Err(ErrorGuaranteed),
}

impl LitKind {
Expand Down Expand Up @@ -1893,7 +1893,7 @@ impl LitKind {
| LitKind::Int(_, LitIntType::Unsuffixed)
| LitKind::Float(_, LitFloatType::Unsuffixed)
| LitKind::Bool(..)
| LitKind::Err => false,
| LitKind::Err(_) => false,
}
}
}
Expand Down Expand Up @@ -2136,10 +2136,12 @@ pub enum TyKind {
ImplicitSelf,
/// A macro in the type position.
MacCall(P<MacCall>),
/// Placeholder for a kind that has failed to be defined.
Err,
/// Placeholder for a `va_list`.
CVarArgs,
/// Sometimes we need a dummy value when no error has occurred.
Dummy,
/// Placeholder for a kind that has failed to be defined.
Err(ErrorGuaranteed),
}

impl TyKind {
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,12 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
let Ty { id, kind, span, tokens } = ty.deref_mut();
vis.visit_id(id);
match kind {
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never | TyKind::CVarArgs => {}
TyKind::Infer
| TyKind::ImplicitSelf
| TyKind::Err(_)
| TyKind::Dummy
| TyKind::Never
| TyKind::CVarArgs => {}
TyKind::Slice(ty) => vis.visit_ty(ty),
TyKind::Ptr(mt) => vis.visit_mt(mt),
TyKind::Ref(lt, mt) => {
Expand Down Expand Up @@ -1649,7 +1654,7 @@ impl DummyAstNode for Ty {
fn dummy() -> Self {
Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Err,
kind: TyKind::Dummy,
span: Default::default(),
tokens: Default::default(),
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_macros::HashStable_Generic;
use rustc_span::symbol::{kw, sym};
#[allow(hidden_glob_reexports)]
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{edition::Edition, Span, DUMMY_SP};
use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP};
use std::borrow::Cow;
use std::fmt;

Expand Down Expand Up @@ -75,7 +75,7 @@ pub enum LitKind {
ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
CStr,
CStrRaw(u8),
Err,
Err(ErrorGuaranteed),
}

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

if let Some(suffix) = suffix {
Expand All @@ -159,7 +159,7 @@ impl LitKind {
/// An English article for the literal token kind.
pub fn article(self) -> &'static str {
match self {
Integer | Err => "an",
Integer | Err(_) => "an",
_ => "a",
}
}
Expand All @@ -174,12 +174,12 @@ impl LitKind {
Str | StrRaw(..) => "string",
ByteStr | ByteStrRaw(..) => "byte string",
CStr | CStrRaw(..) => "C string",
Err => "error",
Err(_) => "error",
}
}

pub(crate) fn may_have_suffix(self) -> bool {
matches!(self, Integer | Float | Err)
matches!(self, Integer | Float | Err(_))
}
}

Expand Down
41 changes: 19 additions & 22 deletions compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ pub fn escape_byte_str_symbol(bytes: &[u8]) -> Symbol {

#[derive(Debug)]
pub enum LitError {
LexerError,
InvalidSuffix,
InvalidIntSuffix,
InvalidFloatSuffix,
NonDecimalFloat(u32),
IntTooLarge(u32),
InvalidSuffix(Symbol),
InvalidIntSuffix(Symbol),
InvalidFloatSuffix(Symbol),
NonDecimalFloat(u32), // u32 is the base
IntTooLarge(u32), // u32 is the base
}

impl LitKind {
/// Converts literal token into a semantic literal.
pub fn from_token_lit(lit: token::Lit) -> Result<LitKind, LitError> {
let token::Lit { kind, symbol, suffix } = lit;
if suffix.is_some() && !kind.may_have_suffix() {
return Err(LitError::InvalidSuffix);
if let Some(suffix) = suffix
&& !kind.may_have_suffix()
{
return Err(LitError::InvalidSuffix(suffix));
}

// For byte/char/string literals, chars and escapes have already been
Expand Down Expand Up @@ -145,7 +146,7 @@ impl LitKind {
buf.push(0);
LitKind::CStr(buf.into(), StrStyle::Raw(n))
}
token::Err => LitKind::Err,
token::Err(guar) => LitKind::Err(guar),
})
}
}
Expand Down Expand Up @@ -202,7 +203,7 @@ impl fmt::Display for LitKind {
}
}
LitKind::Bool(b) => write!(f, "{}", if b { "true" } else { "false" })?,
LitKind::Err => {
LitKind::Err(_) => {
// This only shows up in places like `-Zunpretty=hir` output, so we
// don't bother to produce something useful.
write!(f, "<bad-literal>")?;
Expand Down Expand Up @@ -238,7 +239,7 @@ impl MetaItemLit {
LitKind::Char(_) => token::Char,
LitKind::Int(..) => token::Integer,
LitKind::Float(..) => token::Float,
LitKind::Err => token::Err,
LitKind::Err(guar) => token::Err(guar),
};

token::Lit::new(kind, self.symbol, self.suffix)
Expand Down Expand Up @@ -272,12 +273,12 @@ fn filtered_float_lit(
return Err(LitError::NonDecimalFloat(base));
}
Ok(match suffix {
Some(suf) => LitKind::Float(
Some(suffix) => LitKind::Float(
symbol,
ast::LitFloatType::Suffixed(match suf {
ast::LitFloatType::Suffixed(match suffix {
sym::f32 => ast::FloatTy::F32,
sym::f64 => ast::FloatTy::F64,
_ => return Err(LitError::InvalidFloatSuffix),
_ => return Err(LitError::InvalidFloatSuffix(suffix)),
}),
),
None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed),
Expand Down Expand Up @@ -318,17 +319,13 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
// `1f64` and `2f32` etc. are valid float literals, and
// `fxxx` looks more like an invalid float literal than invalid integer literal.
_ if suf.as_str().starts_with('f') => return filtered_float_lit(symbol, suffix, base),
_ => return Err(LitError::InvalidIntSuffix),
_ => return Err(LitError::InvalidIntSuffix(suf)),
},
_ => ast::LitIntType::Unsuffixed,
};

let s = &s[if base != 10 { 2 } else { 0 }..];
u128::from_str_radix(s, base).map(|i| LitKind::Int(i.into(), ty)).map_err(|_| {
// Small bases are lexed as if they were base 10, e.g, the string
// might be `0b10201`. This will cause the conversion above to fail,
// but these kinds of errors are already reported by the lexer.
let from_lexer = base < 10 && s.chars().any(|c| c.to_digit(10).is_some_and(|d| d >= base));
if from_lexer { LitError::LexerError } else { LitError::IntTooLarge(base) }
})
u128::from_str_radix(s, base)
.map(|i| LitKind::Int(i.into(), ty))
.map_err(|_| LitError::IntTooLarge(base))
}
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
}
TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {}
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
TyKind::Never | TyKind::CVarArgs => {}
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let lit_kind = match LitKind::from_token_lit(*token_lit) {
Ok(lit_kind) => lit_kind,
Err(err) => {
report_lit_error(&self.tcx.sess.parse_sess, err, *token_lit, e.span);
LitKind::Err
let guar = report_lit_error(
&self.tcx.sess.parse_sess,
err,
*token_lit,
e.span,
);
LitKind::Err(guar)
}
};
let lit = self.arena.alloc(respan(self.lower_span(e.span), lit_kind));
Expand Down Expand Up @@ -323,7 +328,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
}
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
ExprKind::Err => {
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
}
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),

ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
{
lit
} else {
let guar = self.dcx().has_errors().unwrap();
MetaItemLit {
symbol: kw::Empty,
suffix: None,
kind: LitKind::Err,
kind: LitKind::Err(guar),
span: DUMMY_SP,
}
};
Expand Down Expand Up @@ -1285,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
let kind = match &t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
TyKind::Err(guar) => hir::TyKind::Err(*guar),
// Lower the anonymous structs or unions in a nested lowering context.
//
// ```
Expand Down Expand Up @@ -1503,6 +1504,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
);
hir::TyKind::Err(guar)
}
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
};

hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
&item.vis,
errors::VisibilityNotPermittedNote::TraitImpl,
);
if let TyKind::Err = self_ty.kind {
// njn: use Dummy here
if let TyKind::Err(_) = self_ty.kind {
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
}
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn literal_to_string(lit: token::Lit) -> String {
token::CStrRaw(n) => {
format!("cr{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))
}
token::Integer | token::Float | token::Bool | token::Err => symbol.to_string(),
token::Integer | token::Float | token::Bool | token::Err(_) => symbol.to_string(),
};

if let Some(suffix) = suffix {
Expand Down Expand Up @@ -1048,11 +1048,16 @@ impl<'a> State<'a> {
ast::TyKind::Infer => {
self.word("_");
}
ast::TyKind::Err => {
ast::TyKind::Err(_) => {
self.popen();
self.word("/*ERROR*/");
self.pclose();
}
ast::TyKind::Dummy => {
self.popen();
self.word("/*DUMMY*/");
self.pclose();
}
ast::TyKind::ImplicitSelf => {
self.word("Self");
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]

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

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

/// Gets an iterator over all the early-bound regions that have names.
/// Iteration order may be unstable, so this should only be used when
/// iteration order doesn't affect anything
#[allow(rustc::potential_query_instability)]
pub fn named_universal_regions<'s>(
&'s self,
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn expand_concat(
cx.dcx().emit_err(errors::ConcatBytestr { span: e.span });
has_errors = true;
}
Ok(ast::LitKind::Err) => {
Ok(ast::LitKind::Err(_)) => {
has_errors = true;
}
Err(err) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/concat_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn invalid_type_err(
Ok(ast::LitKind::Bool(_)) => {
dcx.emit_err(ConcatBytesInvalid { span, lit_kind: "boolean", sugg: None });
}
Ok(ast::LitKind::Err) => {}
Ok(ast::LitKind::Err(_)) => {}
Ok(ast::LitKind::Int(_, _)) if !is_nested => {
let sugg =
snippet.map(|snippet| ConcatBytesInvalidSuggestion::IntLit { span: span, snippet });
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
use rustc_session::config::{self, CrateType, Lto};

use std::collections::BTreeMap;
use std::ffi::{CStr, CString};
use std::fs::File;
use std::io;
Expand Down Expand Up @@ -787,7 +788,7 @@ pub unsafe fn optimize_thin_module(
#[derive(Debug, Default)]
pub struct ThinLTOKeysMap {
// key = llvm name of importing module, value = LLVM cache key
keys: FxHashMap<String, String>,
keys: BTreeMap<String, String>,
}

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

fn load_from_file(path: &Path) -> io::Result<Self> {
use std::io::BufRead;
let mut keys = FxHashMap::default();
let mut keys = BTreeMap::default();
let file = File::open(path)?;
for line in io::BufReader::new(file).lines() {
let line = line?;
Expand Down
Loading

0 comments on commit f1abde7

Please sign in to comment.