diff options
Diffstat (limited to 'compiler')
19 files changed, 404 insertions, 223 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 84d8829c398..37de90d64c7 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -25,7 +25,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::{Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; -use std::{fmt, iter, mem}; +use std::{fmt, iter}; /// When the main Rust parser encounters a syntax-extension invocation, it /// parses the arguments to the invocation as a token tree. This is a very @@ -399,45 +399,6 @@ impl TokenStream { self.0.len() } - pub fn from_streams(mut streams: SmallVec<[TokenStream; 2]>) -> TokenStream { - match streams.len() { - 0 => TokenStream::default(), - 1 => streams.pop().unwrap(), - _ => { - // We are going to extend the first stream in `streams` with - // the elements from the subsequent streams. This requires - // using `make_mut()` on the first stream, and in practice this - // doesn't cause cloning 99.9% of the time. - // - // One very common use case is when `streams` has two elements, - // where the first stream has any number of elements within - // (often 1, but sometimes many more) and the second stream has - // a single element within. - - // Determine how much the first stream will be extended. - // Needed to avoid quadratic blow up from on-the-fly - // reallocations (#57735). - let num_appends = streams.iter().skip(1).map(|ts| ts.len()).sum(); - - // Get the first stream. If it's `None`, create an empty - // stream. - let mut iter = streams.drain(..); - let mut first_stream_lrc = iter.next().unwrap().0; - - // Append the elements to the first stream, after reserving - // space for them. - let first_vec_mut = Lrc::make_mut(&mut first_stream_lrc); - first_vec_mut.reserve(num_appends); - for stream in iter { - first_vec_mut.extend(stream.0.iter().cloned()); - } - - // Create the final `TokenStream`. - TokenStream(first_stream_lrc) - } - } - } - pub fn trees(&self) -> CursorRef<'_> { CursorRef::new(self) } @@ -562,50 +523,65 @@ impl TokenStreamBuilder { } pub fn push<T: Into<TokenStream>>(&mut self, stream: T) { - let mut stream = stream.into(); - - // If `self` is not empty and the last tree within the last stream is a - // token tree marked with `Joint`... - if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut() - && let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last() - // ...and `stream` is not empty and the first tree within it is - // a token tree... - && let TokenStream(ref mut stream_lrc) = stream - && let Some((TokenTree::Token(token), spacing)) = stream_lrc.first() - // ...and the two tokens can be glued together... - && let Some(glued_tok) = last_token.glue(&token) - { - // ...then do so, by overwriting the last token - // tree in `self` and removing the first token tree - // from `stream`. This requires using `make_mut()` - // on the last stream in `self` and on `stream`, - // and in practice this doesn't cause cloning 99.9% - // of the time. - - // Overwrite the last token tree with the merged - // token. - let last_vec_mut = Lrc::make_mut(last_stream_lrc); - *last_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing); - - // Remove the first token tree from `stream`. (This - // is almost always the only tree in `stream`.) - let stream_vec_mut = Lrc::make_mut(stream_lrc); - stream_vec_mut.remove(0); - - // Don't push `stream` if it's empty -- that could - // block subsequent token gluing, by getting - // between two token trees that should be glued - // together. - if !stream.is_empty() { - self.0.push(stream); - } - return; - } - self.0.push(stream); + self.0.push(stream.into()); } pub fn build(self) -> TokenStream { - TokenStream::from_streams(self.0) + let mut streams = self.0; + match streams.len() { + 0 => TokenStream::default(), + 1 => streams.pop().unwrap(), + _ => { + // We will extend the first stream in `streams` with the + // elements from the subsequent streams. This requires using + // `make_mut()` on the first stream, and in practice this + // doesn't cause cloning 99.9% of the time. + // + // One very common use case is when `streams` has two elements, + // where the first stream has any number of elements within + // (often 1, but sometimes many more) and the second stream has + // a single element within. + + // Determine how much the first stream will be extended. + // Needed to avoid quadratic blow up from on-the-fly + // reallocations (#57735). + let num_appends = streams.iter().skip(1).map(|ts| ts.len()).sum(); + + // Get the first stream, which will become the result stream. + // If it's `None`, create an empty stream. + let mut iter = streams.drain(..); + let mut res_stream_lrc = iter.next().unwrap().0; + + // Append the subsequent elements to the result stream, after + // reserving space for them. + let res_vec_mut = Lrc::make_mut(&mut res_stream_lrc); + res_vec_mut.reserve(num_appends); + for stream in iter { + let stream_iter = stream.0.iter().cloned(); + + // If (a) `res_mut_vec` is not empty and the last tree + // within it is a token tree marked with `Joint`, and (b) + // `stream` is not empty and the first tree within it is a + // token tree, and (c) the two tokens can be glued + // together... + if let Some((TokenTree::Token(last_tok), Spacing::Joint)) = res_vec_mut.last() + && let Some((TokenTree::Token(tok), spacing)) = stream.0.first() + && let Some(glued_tok) = last_tok.glue(&tok) + { + // ...then overwrite the last token tree in + // `res_vec_mut` with the glued token, and skip the + // first token tree from `stream`. + *res_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing); + res_vec_mut.extend(stream_iter.skip(1)); + } else { + // Append all of `stream`. + res_vec_mut.extend(stream_iter); + } + } + + TokenStream(res_stream_lrc) + } + } } } @@ -679,20 +655,6 @@ impl Cursor { }) } - pub fn index(&self) -> usize { - self.index - } - - pub fn append(&mut self, new_stream: TokenStream) { - if new_stream.is_empty() { - return; - } - let index = self.index; - let stream = mem::take(&mut self.stream); - *self = TokenStream::from_streams(smallvec![stream, new_stream]).into_trees(); - self.index = index; - } - pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> { self.stream.0[self.index..].get(n).map(|(tree, _)| tree) } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index ae6b8e0ae30..355254fe942 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -357,12 +357,20 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { .add_element(live_region_vid, location); }); + // HACK(compiler-errors): Constants that are gathered into Body.required_consts + // have their locations erased... + let locations = if location != Location::START { + location.to_locations() + } else { + Locations::All(constant.span) + }; + if let Some(annotation_index) = constant.user_ty { if let Err(terr) = self.cx.relate_type_and_user_type( constant.literal.ty(), ty::Variance::Invariant, &UserTypeProjection { base: annotation_index, projs: vec![] }, - location.to_locations(), + locations, ConstraintCategory::Boring, ) { let annotation = &self.cx.user_type_annotations[annotation_index]; @@ -390,12 +398,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { promoted: &Body<'tcx>, ty, san_ty| { - if let Err(terr) = verifier.cx.eq_types( - ty, - san_ty, - location.to_locations(), - ConstraintCategory::Boring, - ) { + if let Err(terr) = + verifier.cx.eq_types(ty, san_ty, locations, ConstraintCategory::Boring) + { span_mirbug!( verifier, promoted, @@ -416,7 +421,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } else { if let Err(terr) = self.cx.fully_perform_op( - location.to_locations(), + locations, ConstraintCategory::Boring, self.cx.param_env.and(type_op::ascribe_user_type::AscribeUserType::new( constant.literal.ty(), @@ -435,7 +440,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } else if let Some(static_def_id) = constant.check_static_ptr(tcx) { let unnormalized_ty = tcx.type_of(static_def_id); - let locations = location.to_locations(); let normalized_ty = self.cx.normalize(unnormalized_ty, locations); let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty; @@ -454,7 +458,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { self.cx.normalize_and_prove_instantiated_predicates( def_id, instantiated_predicates, - location.to_locations(), + locations, ); } } diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index 37a4bf5fdca..cad30181212 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -5,7 +5,7 @@ use rustc_ast::{ token, tokenstream::{DelimSpan, TokenStream, TokenTree}, BorrowKind, Expr, ExprKind, ItemKind, MacArgs, MacCall, MacDelimiter, Mutability, Path, - PathSegment, Stmt, UseTree, UseTreeKind, DUMMY_NODE_ID, + PathSegment, Stmt, StructRest, UseTree, UseTreeKind, DUMMY_NODE_ID, }; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; @@ -167,15 +167,103 @@ impl<'cx, 'a> Context<'cx, 'a> { /// See [Self::manage_initial_capture] and [Self::manage_try_capture] fn manage_cond_expr(&mut self, expr: &mut P<Expr>) { match (*expr).kind { + ExprKind::AddrOf(_, _, ref mut local_expr) => { + self.manage_cond_expr(local_expr); + } + ExprKind::Array(ref mut local_exprs) => { + for local_expr in local_exprs { + self.manage_cond_expr(local_expr); + } + } ExprKind::Binary(_, ref mut lhs, ref mut rhs) => { self.manage_cond_expr(lhs); self.manage_cond_expr(rhs); } + ExprKind::Call(_, ref mut local_exprs) => { + for local_expr in local_exprs { + self.manage_cond_expr(local_expr); + } + } + ExprKind::Cast(ref mut local_expr, _) => { + self.manage_cond_expr(local_expr); + } + ExprKind::Index(ref mut prefix, ref mut suffix) => { + self.manage_cond_expr(prefix); + self.manage_cond_expr(suffix); + } + ExprKind::MethodCall(_, ref mut local_exprs, _) => { + for local_expr in local_exprs.iter_mut().skip(1) { + self.manage_cond_expr(local_expr); + } + } ExprKind::Path(_, Path { ref segments, .. }) if let &[ref path_segment] = &segments[..] => { let path_ident = path_segment.ident; self.manage_initial_capture(expr, path_ident); } - _ => {} + ExprKind::Paren(ref mut local_expr) => { + self.manage_cond_expr(local_expr); + } + ExprKind::Range(ref mut prefix, ref mut suffix, _) => { + if let Some(ref mut elem) = prefix { + self.manage_cond_expr(elem); + } + if let Some(ref mut elem) = suffix { + self.manage_cond_expr(elem); + } + } + ExprKind::Repeat(ref mut local_expr, ref mut elem) => { + self.manage_cond_expr(local_expr); + self.manage_cond_expr(&mut elem.value); + } + ExprKind::Struct(ref mut elem) => { + for field in &mut elem.fields { + self.manage_cond_expr(&mut field.expr); + } + if let StructRest::Base(ref mut local_expr) = elem.rest { + self.manage_cond_expr(local_expr); + } + } + ExprKind::Tup(ref mut local_exprs) => { + for local_expr in local_exprs { + self.manage_cond_expr(local_expr); + } + } + ExprKind::Unary(_, ref mut local_expr) => { + self.manage_cond_expr(local_expr); + } + // Expressions that are not worth or can not be captured. + // + // Full list instead of `_` to catch possible future inclusions and to + // sync with the `rfc-2011-nicer-assert-messages/all-expr-kinds.rs` test. + ExprKind::Assign(_, _, _) + | ExprKind::AssignOp(_, _, _) + | ExprKind::Async(_, _, _) + | ExprKind::Await(_) + | ExprKind::Block(_, _) + | ExprKind::Box(_) + | ExprKind::Break(_, _) + | ExprKind::Closure(_, _, _, _, _, _) + | ExprKind::ConstBlock(_) + | ExprKind::Continue(_) + | ExprKind::Err + | ExprKind::Field(_, _) + | ExprKind::ForLoop(_, _, _, _) + | ExprKind::If(_, _, _) + | ExprKind::InlineAsm(_) + | ExprKind::Let(_, _, _) + | ExprKind::Lit(_) + | ExprKind::Loop(_, _) + | ExprKind::MacCall(_) + | ExprKind::Match(_, _) + | ExprKind::Path(_, _) + | ExprKind::Ret(_) + | ExprKind::Try(_) + | ExprKind::TryBlock(_) + | ExprKind::Type(_, _) + | ExprKind::Underscore + | ExprKind::While(_, _, _) + | ExprKind::Yeet(_) + | ExprKind::Yield(_) => {} } } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 4e71baa77b0..0c587220cb7 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -10,7 +10,8 @@ use rustc_middle::mir; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::{ - suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, TraitPredicate, Ty, + suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, TraitPredicate, + Ty, }; use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef}; use rustc_session::parse::feature_err; @@ -300,6 +301,15 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap()); err } + _ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => { + struct_span_err!( + ccx.tcx.sess, + span, + E0015, + "cannot call non-const formatting macro in {}s", + ccx.const_kind(), + ) + } _ => struct_span_err!( ccx.tcx.sess, span, diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 093896c339d..1e4193a5a16 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -329,6 +329,7 @@ impl Ident { sess.symbol_gallery.insert(sym, span); Ident { sym, is_raw, span } } + fn dollar_crate(span: Span) -> Ident { // `$crate` is accepted as an ident only if it comes from the compiler. Ident { sym: kw::DollarCrate, is_raw: false, span } @@ -403,6 +404,7 @@ impl server::TokenStream for Rustc<'_, '_> { fn is_empty(&mut self, stream: &Self::TokenStream) -> bool { stream.is_empty() } + fn from_str(&mut self, src: &str) -> Self::TokenStream { parse_stream_from_source_str( FileName::proc_macro_source_code(src), @@ -411,9 +413,11 @@ impl server::TokenStream for Rustc<'_, '_> { Some(self.call_site), ) } + fn to_string(&mut self, stream: &Self::TokenStream) -> String { pprust::tts_to_string(stream) } + fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> { // Parse the expression from our tokenstream. let expr: PResult<'_, _> = try { @@ -464,12 +468,14 @@ impl server::TokenStream for Rustc<'_, '_> { _ => Err(()), } } + fn from_token_tree( &mut self, tree: TokenTree<Self::Group, Self::Punct, Self::Ident, Self::Literal>, ) -> Self::TokenStream { tree.to_internal() } + fn concat_trees( &mut self, base: Option<Self::TokenStream>, @@ -484,6 +490,7 @@ impl server::TokenStream for Rustc<'_, '_> { } builder.build() } + fn concat_streams( &mut self, base: Option<Self::TokenStream>, @@ -498,6 +505,7 @@ impl server::TokenStream for Rustc<'_, '_> { } builder.build() } + fn into_trees( &mut self, stream: Self::TokenStream, @@ -522,10 +530,10 @@ impl server::TokenStream for Rustc<'_, '_> { // FIXME: It needs to be removed, but there are some // compatibility issues (see #73345). if group.flatten { - cursor.append(group.stream); - continue; + tts.append(&mut self.into_trees(group.stream)); + } else { + tts.push(TokenTree::Group(group)); } - tts.push(TokenTree::Group(group)); } Some(tt) => tts.push(tt), None => return tts, @@ -543,21 +551,27 @@ impl server::Group for Rustc<'_, '_> { flatten: false, } } + fn delimiter(&mut self, group: &Self::Group) -> Delimiter { group.delimiter } + fn stream(&mut self, group: &Self::Group) -> Self::TokenStream { group.stream.clone() } + fn span(&mut self, group: &Self::Group) -> Self::Span { group.span.entire() } + fn span_open(&mut self, group: &Self::Group) -> Self::Span { group.span.open } + fn span_close(&mut self, group: &Self::Group) -> Self::Span { group.span.close } + fn set_span(&mut self, group: &mut Self::Group, span: Self::Span) { group.span = DelimSpan::from_single(span); } @@ -567,15 +581,19 @@ impl server::Punct for Rustc<'_, '_> { fn new(&mut self, ch: char, spacing: Spacing) -> Self::Punct { Punct::new(ch, spacing == Spacing::Joint, server::Span::call_site(self)) } + fn as_char(&mut self, punct: Self::Punct) -> char { punct.ch } + fn spacing(&mut self, punct: Self::Punct) -> Spacing { if punct.joint { Spacing::Joint } else { Spacing::Alone } } + fn span(&mut self, punct: Self::Punct) -> Self::Span { punct.span } + fn with_span(&mut self, punct: Self::Punct, span: Self::Span) -> Self::Punct { Punct { span, ..punct } } @@ -585,9 +603,11 @@ impl server::Ident for Rustc<'_, '_> { fn new(&mut self, string: &str, span: Self::Span, is_raw: bool) -> Self::Ident { Ident::new(self.sess(), Symbol::intern(string), is_raw, span) } + fn span(&mut self, ident: Self::Ident) -> Self::Span { ident.span } + fn with_span(&mut self, ident: Self::Ident, span: Self::Span) -> Self::Ident { Ident { span, ..ident } } @@ -639,45 +659,57 @@ impl server::Literal for Rustc<'_, '_> { Ok(Literal { lit, span: self.call_site }) } + fn to_string(&mut self, literal: &Self::Literal) -> String { literal.lit.to_string() } + fn debug_kind(&mut self, literal: &Self::Literal) -> String { format!("{:?}", literal.lit.kind) } + fn symbol(&mut self, literal: &Self::Literal) -> String { literal.lit.symbol.to_string() } + fn suffix(&mut self, literal: &Self::Literal) -> Option<String> { literal.lit.suffix.as_ref().map(Symbol::to_string) } + fn integer(&mut self, n: &str) -> Self::Literal { self.lit(token::Integer, Symbol::intern(n), None) } + fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal { self.lit(token::Integer, Symbol::intern(n), Some(Symbol::intern(kind))) } + fn float(&mut self, n: &str) -> Self::Literal { self.lit(token::Float, Symbol::intern(n), None) } + fn f32(&mut self, n: &str) -> Self::Literal { self.lit(token::Float, Symbol::intern(n), Some(sym::f32)) } + fn f64(&mut self, n: &str) -> Self::Literal { self.lit(token::Float, Symbol::intern(n), Some(sym::f64)) } + fn string(&mut self, string: &str) -> Self::Literal { let quoted = format!("{:?}", string); assert!(quoted.starts_with('"') && quoted.ends_with('"')); let symbol = "ed[1..quoted.len() - 1]; self.lit(token::Str, Symbol::intern(symbol), None) } + fn character(&mut self, ch: char) -> Self::Literal { let quoted = format!("{:?}", ch); assert!(quoted.starts_with('\'') && quoted.ends_with('\'')); let symbol = "ed[1..quoted.len() - 1]; self.lit(token::Char, Symbol::intern(symbol), None) } + fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal { let string = bytes .iter() @@ -687,12 +719,15 @@ impl server::Literal for Rustc<'_, '_> { .collect::<String>(); self.lit(token::ByteStr, Symbol::intern(&string), None) } + fn span(&mut self, literal: &Self::Literal) -> Self::Span { literal.span } + fn set_span(&mut self, literal: &mut Self::Literal, span: Self::Span) { literal.span = span; } + fn subspan( &mut self, literal: &Self::Literal, @@ -735,6 +770,7 @@ impl server::SourceFile for Rustc<'_, '_> { fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool { Lrc::ptr_eq(file1, file2) } + fn path(&mut self, file: &Self::SourceFile) -> String { match file.name { FileName::Real(ref name) => name @@ -746,6 +782,7 @@ impl server::SourceFile for Rustc<'_, '_> { _ => file.name.prefer_local().to_string(), } } + fn is_real(&mut self, file: &Self::SourceFile) -> bool { file.is_real_file() } @@ -755,6 +792,7 @@ impl server::MultiSpan for Rustc<'_, '_> { fn new(&mut self) -> Self::MultiSpan { vec![] } + fn push(&mut self, spans: &mut Self::MultiSpan, span: Self::Span) { spans.push(span) } @@ -766,6 +804,7 @@ impl server::Diagnostic for Rustc<'_, '_> { diag.set_span(MultiSpan::from_spans(spans)); diag } + fn sub( &mut self, diag: &mut Self::Diagnostic, @@ -775,6 +814,7 @@ impl server::Diagnostic for Rustc<'_, '_> { ) { diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None); } + fn emit(&mut self, mut diag: Self::Diagnostic) { self.sess().span_diagnostic.emit_diagnostic(&mut diag); } @@ -788,38 +828,49 @@ impl server::Span for Rustc<'_, '_> { format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0) } } + fn def_site(&mut self) -> Self::Span { self.def_site } + fn call_site(&mut self) -> Self::Span { self.call_site } + fn mixed_site(&mut self) -> Self::Span { self.mixed_site } + fn source_file(&mut self, span: Self::Span) -> Self::SourceFile { self.sess().source_map().lookup_char_pos(span.lo()).file } + fn parent(&mut self, span: Self::Span) -> Option<Self::Span> { span.parent_callsite() } + fn source(&mut self, span: Self::Span) -> Self::Span { span.source_callsite() } + fn start(&mut self, span: Self::Span) -> LineColumn { let loc = self.sess().source_map().lookup_char_pos(span.lo()); LineColumn { line: loc.line, column: loc.col.to_usize() } } + fn end(&mut self, span: Self::Span) -> LineColumn { let loc = self.sess().source_map().lookup_char_pos(span.hi()); LineColumn { line: loc.line, column: loc.col.to_usize() } } + fn before(&mut self, span: Self::Span) -> Self::Span { span.shrink_to_lo() } + fn after(&mut self, span: Self::Span) -> Self::Span { span.shrink_to_hi() } + fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> { let self_loc = self.sess().source_map().lookup_char_pos(first.lo()); let other_loc = self.sess().source_map().lookup_char_pos(second.lo()); @@ -830,9 +881,11 @@ impl server::Span for Rustc<'_, '_> { Some(first.to(second)) } + fn resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span { span.with_ctxt(at.ctxt()) } + fn source_text(&mut self, span: Self::Span) -> Option<String> { self.sess().source_map().span_to_snippet(span).ok() } @@ -863,6 +916,7 @@ impl server::Span for Rustc<'_, '_> { fn save_span(&mut self, span: Self::Span) -> usize { self.sess().save_proc_macro_span(span) } + fn recover_proc_macro_span(&mut self, id: usize) -> Self::Span { let (resolver, krate, def_site) = (&*self.ecx.resolver, self.krate, self.def_site); *self.rebased_spans.entry(id).or_insert_with(|| { diff --git a/compiler/rustc_expand/src/tokenstream/tests.rs b/compiler/rustc_expand/src/tokenstream/tests.rs index 270532f8ede..e4a4db204d9 100644 --- a/compiler/rustc_expand/src/tokenstream/tests.rs +++ b/compiler/rustc_expand/src/tokenstream/tests.rs @@ -4,7 +4,6 @@ use rustc_ast::token; use rustc_ast::tokenstream::{Spacing, TokenStream, TokenStreamBuilder, TokenTree}; use rustc_span::create_default_session_globals_then; use rustc_span::{BytePos, Span, Symbol}; -use smallvec::smallvec; fn string_to_ts(string: &str) -> TokenStream { string_to_stream(string.to_owned()) @@ -24,7 +23,10 @@ fn test_concat() { let test_res = string_to_ts("foo::bar::baz"); let test_fst = string_to_ts("foo::bar"); let test_snd = string_to_ts("::baz"); - let eq_res = TokenStream::from_streams(smallvec![test_fst, test_snd]); + let mut builder = TokenStreamBuilder::new(); + builder.push(test_fst); + builder.push(test_snd); + let eq_res = builder.build(); assert_eq!(test_res.trees().count(), 5); assert_eq!(eq_res.trees().count(), 5); assert_eq!(test_res.eq_unspanned(&eq_res), true); diff --git a/compiler/rustc_middle/src/mir/spanview.rs b/compiler/rustc_middle/src/mir/spanview.rs index afcd5db8f48..4418b848e51 100644 --- a/compiler/rustc_middle/src/mir/spanview.rs +++ b/compiler/rustc_middle/src/mir/spanview.rs @@ -667,7 +667,7 @@ fn trim_span_hi(span: Span, to_pos: BytePos) -> Span { fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span { let fn_decl_span = tcx.def_span(def_id); if let Some(body_span) = hir_body(tcx, def_id).map(|hir_body| hir_body.value.span) { - if fn_decl_span.ctxt() == body_span.ctxt() { fn_decl_span.to(body_span) } else { body_span } + if fn_decl_span.eq_ctxt(body_span) { fn_decl_span.to(body_span) } else { body_span } } else { fn_decl_span } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 99aa182f3a6..31b8fa1ce95 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -371,6 +371,13 @@ where Ok(self.fold_const(c)) } + fn try_fold_unevaluated( + &mut self, + c: ty::Unevaluated<'tcx>, + ) -> Result<ty::Unevaluated<'tcx>, Self::Error> { + Ok(self.fold_unevaluated(c)) + } + fn try_fold_predicate( &mut self, p: ty::Predicate<'tcx>, diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index dc204eb47ae..76333b755b7 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -803,7 +803,7 @@ fn non_exhaustive_match<'p, 'tcx>( let mut suggestion = None; let sm = cx.tcx.sess.source_map(); match arms { - [] if sp.ctxt() == expr_span.ctxt() => { + [] if sp.eq_ctxt(expr_span) => { // Get the span for the empty match body `{}`. let (indentation, more) = if let Some(snippet) = sm.indentation_before(sp) { (format!("\n{}", snippet), " ") @@ -821,24 +821,36 @@ fn non_exhaustive_match<'p, 'tcx>( )); } [only] => { - let pre_indentation = if let (Some(snippet), true) = ( - sm.indentation_before(only.span), - sm.is_multiline(sp.shrink_to_hi().with_hi(only.span.lo())), - ) { - format!("\n{}", snippet) + let (pre_indentation, is_multiline) = if let Some(snippet) = sm.indentation_before(only.span) + && let Ok(with_trailing) = sm.span_extend_while(only.span, |c| c.is_whitespace() || c == ',') + && sm.is_multiline(with_trailing) + { + (format!("\n{}", snippet), true) + } else { + (" ".to_string(), false) + }; + let comma = if matches!(only.body.kind, hir::ExprKind::Block(..)) + && only.span.eq_ctxt(only.body.span) + && is_multiline + { + "" } else { - " ".to_string() + "," }; - let comma = if matches!(only.body.kind, hir::ExprKind::Block(..)) { "" } else { "," }; suggestion = Some(( only.span.shrink_to_hi(), format!("{}{}{} => todo!()", comma, pre_indentation, pattern), )); } - [.., prev, last] if prev.span.ctxt() == last.span.ctxt() => { + [.., prev, last] if prev.span.eq_ctxt(last.span) => { if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) { - let comma = - if matches!(last.body.kind, hir::ExprKind::Block(..)) { "" } else { "," }; + let comma = if matches!(last.body.kind, hir::ExprKind::Block(..)) + && last.span.eq_ctxt(last.body.span) + { + "" + } else { + "," + }; suggestion = Some(( last.span.shrink_to_hi(), format!( diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 2bb9f48f9b7..782b620e28f 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -121,7 +121,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { let source_file = source_map.lookup_source_file(body_span.lo()); let fn_sig_span = match some_fn_sig.filter(|fn_sig| { - fn_sig.span.ctxt() == body_span.ctxt() + fn_sig.span.eq_ctxt(body_span) && Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo())) }) { Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()), diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 512d4daf343..82070b90325 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -195,7 +195,7 @@ impl CoverageSpan { .expn_span .parent_callsite() .unwrap_or_else(|| bug!("macro must have a parent")) - .ctxt() == body_span.ctxt() + .eq_ctxt(body_span) { return Some(current_macro); } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 7f0d3b0a612..d777d13d7a5 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -195,6 +195,11 @@ const RETURNED: usize = GeneratorSubsts::RETURNED; /// Generator has panicked and is poisoned. const POISONED: usize = GeneratorSubsts::POISONED; +/// Number of variants to reserve in generator state. Corresponds to +/// `UNRESUMED` (beginning of a generator) and `RETURNED`/`POISONED` +/// (end of a generator) states. +const RESERVED_VARIANTS: usize = 3; + /// A `yield` point in the generator. struct SuspensionPoint<'tcx> { /// State discriminant used when suspending or resuming at this point. @@ -345,7 +350,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { data.statements.extend(self.make_state(state_idx, v, source_info)); let state = if let Some((resume, mut resume_arg)) = resume { // Yield - let state = 3 + self.suspension_points.len(); + let state = RESERVED_VARIANTS + self.suspension_points.len(); // The resume arg target location might itself be remapped if its base local is // live across a yield. @@ -792,7 +797,6 @@ fn compute_layout<'tcx>( // Leave empty variants for the UNRESUMED, RETURNED, and POISONED states. // In debuginfo, these will correspond to the beginning (UNRESUMED) or end // (RETURNED, POISONED) of the function. - const RESERVED_VARIANTS: usize = 3; let body_span = body.source_scopes[OUTERMOST_SOURCE_SCOPE].span; let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = [ SourceInfo::outermost(body_span.shrink_to_lo()), diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 27bce60df2b..7d2b7de17bf 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1894,7 +1894,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let names = rib .bindings .iter() - .filter(|(id, _)| id.span.ctxt() == label.span.ctxt()) + .filter(|(id, _)| id.span.eq_ctxt(label.span)) .map(|(id, _)| id.name) .collect::<Vec<Symbol>>(); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 89d724626cc..14ad1a42a7d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1102,41 +1102,96 @@ impl CrateCheckConfig { .extend(atomic_values); // Target specific values - for target in - TARGETS.iter().map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) + #[cfg(bootstrap)] { - self.values_valid - .entry(sym::target_os) - .or_default() - .insert(Symbol::intern(&target.options.os)); - self.values_valid - .entry(sym::target_family) - .or_default() - .extend(target.options.families.iter().map(|family| Symbol::intern(family))); - self.values_valid - .entry(sym::target_arch) - .or_default() - .insert(Symbol::intern(&target.arch)); - self.values_valid - .entry(sym::target_endian) - .or_default() - .insert(Symbol::intern(&target.options.endian.as_str())); - self.values_valid - .entry(sym::target_env) - .or_default() - .insert(Symbol::intern(&target.options.env)); - self.values_valid - .entry(sym::target_abi) - .or_default() - .insert(Symbol::intern(&target.options.abi)); - self.values_valid - .entry(sym::target_vendor) - .or_default() - .insert(Symbol::intern(&target.options.vendor)); - self.values_valid - .entry(sym::target_pointer_width) - .or_default() - .insert(sym::integer(target.pointer_width)); + for target in TARGETS + .iter() + .map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) + { + self.values_valid + .entry(sym::target_os) + .or_default() + .insert(Symbol::intern(&target.options.os)); + self.values_valid + .entry(sym::target_family) + .or_default() + .extend(target.options.families.iter().map(|family| Symbol::intern(family))); + self.values_valid + .entry(sym::target_arch) + .or_default() + .insert(Symbol::intern(&target.arch)); + self.values_valid + .entry(sym::target_endian) + .or_default() + .insert(Symbol::intern(&target.options.endian.as_str())); + self.values_valid + .entry(sym::target_env) + .or_default() + .insert(Symbol::intern(&target.options.env)); + self.values_valid + .entry(sym::target_abi) + .or_default() + .insert(Symbol::intern(&target.options.abi)); + self.values_valid + .entry(sym::target_vendor) + .or_default() + .insert(Symbol::intern(&target.options.vendor)); + self.values_valid + .entry(sym::target_pointer_width) + .or_default() + .insert(sym::integer(target.pointer_width)); + } + } + + // Target specific values + #[cfg(not(bootstrap))] + { + const VALUES: [&Symbol; 8] = [ + &sym::target_os, + &sym::target_family, + &sym::target_arch, + &sym::target_endian, + &sym::target_env, + &sym::target_abi, + &sym::target_vendor, + &sym::target_pointer_width, + ]; + + // Initialize (if not already initialized) + for &e in VALUES { + self.values_valid.entry(e).or_default(); + } + + // Get all values map at once otherwise it would be costly. + // (8 values * 220 targets ~= 1760 times, at the time of writing this comment). + let [ + values_target_os, + values_target_family, + values_target_arch, + values_target_endian, + values_target_env, + values_target_abi, + values_target_vendor, + values_target_pointer_width, + ] = self + .values_valid + .get_many_mut(VALUES) + .expect("unable to get all the check-cfg values buckets"); + + for target in TARGETS + .iter() + .map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) + { + values_target_os.insert(Symbol::intern(&target.options.os)); + values_target_family + .extend(target.options.families.iter().map(|family| Symbol::intern(family))); + values_target_arch.insert(Symbol::intern(&target.arch)); + values_target_endian.insert(Symbol::intern(&target.options.endian.as_str())); + values_target_env.insert(Symbol::intern(&target.options.env)); + values_target_abi.insert(Symbol::intern(&target.options.abi)); + values_target_vendor.insert(Symbol::intern(&target.options.vendor)); + values_target_pointer_width.insert(sym::integer(target.pointer_width)); + } } } diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 044be906b55..35b55981e37 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -6,6 +6,7 @@ #![feature(once_cell)] #![feature(option_get_or_insert_default)] #![feature(rustc_attrs)] +#![cfg_attr(not(bootstrap), feature(map_many_mut))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 5d3d56b1e66..a329fa15320 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -537,6 +537,9 @@ impl Span { pub fn ctxt(self) -> SyntaxContext { self.data_untracked().ctxt } + pub fn eq_ctxt(self, other: Span) -> bool { + self.data_untracked().ctxt == other.data_untracked().ctxt + } #[inline] pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span { self.data_untracked().with_ctxt(ctxt) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6daf811e26f..8a6941a4516 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -131,6 +131,7 @@ symbols! { Arc, Argument, ArgumentV1, + ArgumentV1Methods, Arguments, AsMut, AsRef, @@ -1641,7 +1642,7 @@ impl Ident { impl PartialEq for Ident { fn eq(&self, rhs: &Self) -> bool { - self.name == rhs.name && self.span.ctxt() == rhs.span.ctxt() + self.name == rhs.name && self.span.eq_ctxt(rhs.span) } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2f999f5ffad..af0803fbd54 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -259,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let cycle = self.resolve_vars_if_possible(cycle.to_owned()); assert!(!cycle.is_empty()); - debug!("report_overflow_error_cycle: cycle={:?}", cycle); + debug!(?cycle, "report_overflow_error_cycle"); // The 'deepest' obligation is most likely to have a useful // cause 'backtrace' @@ -1513,6 +1513,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { } } + #[instrument(level = "debug", skip_all)] fn report_projection_error( &self, obligation: &PredicateObligation<'tcx>, @@ -1551,15 +1552,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { &mut obligations, ); - debug!( - "report_projection_error obligation.cause={:?} obligation.param_env={:?}", - obligation.cause, obligation.param_env - ); + debug!(?obligation.cause, ?obligation.param_env); - debug!( - "report_projection_error normalized_ty={:?} data.ty={:?}", - normalized_ty, data.term, - ); + debug!(?normalized_ty, data.ty = ?data.term); let is_normalized_ty_expected = !matches!( obligation.cause.code().peel_derives(), @@ -2346,6 +2341,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { } } + #[instrument(level = "debug", skip_all)] fn suggest_unsized_bound_if_applicable( &self, err: &mut Diagnostic, @@ -2360,10 +2356,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { ) else { return; }; - debug!( - "suggest_unsized_bound_if_applicable: pred={:?} item_def_id={:?} span={:?}", - pred, item_def_id, span - ); + debug!(?pred, ?item_def_id, ?span); let (Some(node), true) = ( self.tcx.hir().get_if_local(item_def_id), @@ -2374,6 +2367,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { self.maybe_suggest_unsized_generics(err, span, node); } + #[instrument(level = "debug", skip_all)] fn maybe_suggest_unsized_generics<'hir>( &self, err: &mut Diagnostic, @@ -2384,8 +2378,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { return; }; let sized_trait = self.tcx.lang_items().sized_trait(); - debug!("maybe_suggest_unsized_generics: generics.params={:?}", generics.params); - debug!("maybe_suggest_unsized_generics: generics.predicates={:?}", generics.predicates); + debug!(?generics.params); + debug!(?generics.predicates); let Some(param) = generics.params.iter().find(|param| param.span == span) else { return; }; @@ -2399,7 +2393,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { if explicitly_sized { return; } - debug!("maybe_suggest_unsized_generics: param={:?}", param); + debug!(?param); match node { hir::Node::Item( item @ hir::Item { @@ -2517,7 +2511,7 @@ impl<'v> Visitor<'v> for FindTypeParam { if path.segments.len() == 1 && path.segments[0].ident.name == self.param => { if !self.nested { - debug!("FindTypeParam::visit_ty: ty={:?}", ty); + debug!(?ty, "FindTypeParam::visit_ty"); self.invalid_spans.push(ty.span); } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 09b73b982a0..d8003efba87 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1628,16 +1628,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// ``` /// /// Returns `true` if an async-await specific note was added to the diagnostic. + #[instrument(level = "debug", skip_all, fields(?obligation.predicate, ?obligation.cause.span))] fn maybe_note_obligation_cause_for_async_await( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ) -> bool { - debug!( - "maybe_note_obligation_cause_for_async_await: obligation.predicate={:?} \ - obligation.cause.span={:?}", - obligation.predicate, obligation.cause.span - ); let hir = self.tcx.hir(); // Attempt to detect an async-await error by looking at the obligation causes, looking @@ -1677,7 +1673,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let mut seen_upvar_tys_infer_tuple = false; while let Some(code) = next_code { - debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code); + debug!(?code); match code { ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => { next_code = Some(parent_code); @@ -1685,10 +1681,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ObligationCauseCode::ImplDerivedObligation(cause) => { let ty = cause.derived.parent_trait_pred.skip_binder().self_ty(); debug!( - "maybe_note_obligation_cause_for_async_await: ImplDerived \ - parent_trait_ref={:?} self_ty.kind={:?}", - cause.derived.parent_trait_pred, - ty.kind() + parent_trait_ref = ?cause.derived.parent_trait_pred, + self_ty.kind = ?ty.kind(), + "ImplDerived", ); match *ty.kind() { @@ -1717,10 +1712,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => { let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty(); debug!( - "maybe_note_obligation_cause_for_async_await: \ - parent_trait_ref={:?} self_ty.kind={:?}", - derived_obligation.parent_trait_pred, - ty.kind() + parent_trait_ref = ?derived_obligation.parent_trait_pred, + self_ty.kind = ?ty.kind(), ); match *ty.kind() { @@ -1750,7 +1743,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } // Only continue if a generator was found. - debug!(?generator, ?trait_ref, ?target_ty, "maybe_note_obligation_cause_for_async_await"); + debug!(?generator, ?trait_ref, ?target_ty); let (Some(generator_did), Some(trait_ref), Some(target_ty)) = (generator, trait_ref, target_ty) else { return false; }; @@ -1760,12 +1753,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let in_progress_typeck_results = self.in_progress_typeck_results.map(|t| t.borrow()); let generator_did_root = self.tcx.typeck_root_def_id(generator_did); debug!( - "maybe_note_obligation_cause_for_async_await: generator_did={:?} \ - generator_did_root={:?} in_progress_typeck_results.hir_owner={:?} span={:?}", - generator_did, - generator_did_root, - in_progress_typeck_results.as_ref().map(|t| t.hir_owner), - span + ?generator_did, + ?generator_did_root, + in_progress_typeck_results.hir_owner = ?in_progress_typeck_results.as_ref().map(|t| t.hir_owner), + ?span, ); let generator_body = generator_did @@ -1788,7 +1779,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let Some(body) = generator_body { visitor.visit_body(body); } - debug!("maybe_note_obligation_cause_for_async_await: awaits = {:?}", visitor.awaits); + debug!(awaits = ?visitor.awaits); // Look for a type inside the generator interior that matches the target type to get // a span. @@ -1809,11 +1800,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let ty_erased = self.tcx.erase_late_bound_regions(ty); let ty_erased = self.tcx.erase_regions(ty_erased); let eq = ty_erased == target_ty_erased; - debug!( - "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \ - target_ty_erased={:?} eq={:?}", - ty_erased, target_ty_erased, eq - ); + debug!(?ty_erased, ?target_ty_erased, ?eq); eq }; @@ -1888,6 +1875,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// Unconditionally adds the diagnostic note described in /// `maybe_note_obligation_cause_for_async_await`'s documentation comment. + #[instrument(level = "debug", skip_all)] fn note_obligation_cause_for_async_await( &self, err: &mut Diagnostic, @@ -2037,8 +2025,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } else { // Look at the last interior type to get a span for the `.await`. debug!( - "note_obligation_cause_for_async_await generator_interior_types: {:#?}", - typeck_results.as_ref().map(|t| &t.generator_interior_types) + generator_interior_types = ?format_args!( + "{:#?}", typeck_results.as_ref().map(|t| &t.generator_interior_types) + ), ); explain_yield(interior_span, yield_span, scope_span); } @@ -2073,7 +2062,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // bar(Foo(std::ptr::null())).await; // ^^^^^^^^^^^^^^^^^^^^^ raw-ptr `*T` created inside this struct ctor. // ``` - debug!("parent_def_kind: {:?}", self.tcx.def_kind(parent_did)); + debug!(parent_def_kind = ?self.tcx.def_kind(parent_did)); let is_raw_borrow_inside_fn_like_call = match self.tcx.def_kind(parent_did) { DefKind::Fn | DefKind::Ctor(..) => target_ty.is_unsafe_ptr(), @@ -2131,7 +2120,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // Add a note for the item obligation that remains - normally a note pointing to the // bound that introduced the obligation (e.g. `T: Send`). - debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code); + debug!(?next_code); self.note_obligation_cause_code( err, &obligation.predicate, @@ -2688,6 +2677,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { )); } + #[instrument( + level = "debug", skip(self, err), fields(trait_pred.self_ty = ?trait_pred.self_ty()) + )] fn suggest_await_before_try( &self, err: &mut Diagnostic, @@ -2695,13 +2687,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { trait_pred: ty::PolyTraitPredicate<'tcx>, span: Span, ) { - debug!( - "suggest_await_before_try: obligation={:?}, span={:?}, trait_pred={:?}, trait_pred_self_ty={:?}", - obligation, - span, - trait_pred, - trait_pred.self_ty() - ); let body_hir_id = obligation.cause.body_id; let item_id = self.tcx.hir().get_parent_node(body_hir_id); @@ -2739,14 +2724,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ); debug!( - "suggest_await_before_try: normalized_projection_type {:?}", - self.resolve_vars_if_possible(projection_ty) + normalized_projection_type = ?self.resolve_vars_if_possible(projection_ty) ); let try_obligation = self.mk_trait_obligation_with_new_self_ty( obligation.param_env, trait_pred.map_bound(|trait_pred| (trait_pred, projection_ty.skip_binder())), ); - debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation); + debug!(try_trait_obligation = ?try_obligation); if self.predicate_may_hold(&try_obligation) && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) && snippet.ends_with('?') |
