Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #96476

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fc6af81
Make EncodeWide implement FusedIterator
AronParker Apr 25, 2022
eb55cdc
use `ParseSess` instead of `Session` in `into_diagnostic`
pvdrz Apr 25, 2022
519dd8e
migrate ambiguous plus diagnostic
pvdrz Apr 25, 2022
d6da5fb
update lockfile
pvdrz Apr 25, 2022
5874b09
fix formatting
pvdrz Apr 25, 2022
530f4dc
remove old code
pvdrz Apr 25, 2022
2e261a8
add `struct_warn` method
pvdrz Apr 25, 2022
8bd0a85
:arrow_up: rust-analyzer
lnicola Apr 26, 2022
35b42cb
avoid `format!`
pvdrz Apr 26, 2022
6c3e793
move `AmbigousPlus` outside
pvdrz Apr 26, 2022
1e35bab
separate messages by a newline
pvdrz Apr 26, 2022
843e8d1
not need `Option` for `dbg_scope`
SparrowLii Apr 26, 2022
f0bbc78
Avoid producing `NoDelim` values in `TokenCursorFrame`.
nnethercote Apr 26, 2022
6b367a0
Avoid producing `NoDelim` values in `MacArgs::delim()`.
nnethercote Apr 26, 2022
a8e862c
Avoid producing `NoDelim` values in `Frame`.
nnethercote Apr 26, 2022
9665da3
Avoid producing `NoDelim` values in `FrameData`.
nnethercote Apr 26, 2022
86f0117
Make explicit an unreachable `NoDelim` case in `rustfmt`.
nnethercote Apr 26, 2022
ae42f22
make `fn() -> _ {}` suggestion MachineApplicable
compiler-errors Apr 25, 2022
f9e7489
TAITs are suggestable
compiler-errors Apr 25, 2022
e7ae9eb
rename `sum_with_parens`
pvdrz Apr 27, 2022
07b0a57
Rollup merge of #96377 - compiler-errors:infer-rustfix, r=petrochenkov
Dylan-DPC Apr 27, 2022
e564d74
Rollup merge of #96397 - AronParker:issue-96368-fix, r=dtolnay
Dylan-DPC Apr 27, 2022
feca2c3
Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwco
Dylan-DPC Apr 27, 2022
78c1bb0
Rollup merge of #96419 - lnicola:rust-analyzer-2022-04-26, r=lnicola
Dylan-DPC Apr 27, 2022
0f79041
Rollup merge of #96421 - nnethercote:less-NoDelim, r=petrochenkov
Dylan-DPC Apr 27, 2022
86c98d2
Rollup merge of #96432 - SparrowLii:dbg_scope, r=davidtwco
Dylan-DPC Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4181,6 +4181,7 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_macros",
"rustc_session",
"rustc_span",
"tracing",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,10 @@ pub enum MacArgs {
}

impl MacArgs {
pub fn delim(&self) -> DelimToken {
pub fn delim(&self) -> Option<DelimToken> {
match self {
MacArgs::Delimited(_, delim, _) => delim.to_token(),
MacArgs::Empty | MacArgs::Eq(..) => token::NoDelim,
MacArgs::Delimited(_, delim, _) => Some(delim.to_token()),
MacArgs::Empty | MacArgs::Eq(..) => None,
}
}

Expand Down
38 changes: 20 additions & 18 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
Some(MacHeader::Path(&item.path)),
false,
None,
delim.to_token(),
Some(delim.to_token()),
tokens,
true,
span,
Expand Down Expand Up @@ -530,7 +530,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
None,
false,
None,
*delim,
Some(*delim),
tts,
convert_dollar_crate,
dspan.entire(),
Expand All @@ -556,12 +556,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
header: Option<MacHeader<'_>>,
has_bang: bool,
ident: Option<Ident>,
delim: DelimToken,
delim: Option<DelimToken>,
tts: &TokenStream,
convert_dollar_crate: bool,
span: Span,
) {
if delim == DelimToken::Brace {
if delim == Some(DelimToken::Brace) {
self.cbox(INDENT_UNIT);
}
match header {
Expand All @@ -577,31 +577,33 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_ident(ident);
}
match delim {
DelimToken::Brace => {
Some(DelimToken::Brace) => {
if header.is_some() || has_bang || ident.is_some() {
self.nbsp();
}
self.word("{");
if !tts.is_empty() {
self.space();
}
}
_ => {
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
self.word(token_str)
}
}
self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end();
match delim {
DelimToken::Brace => {
self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end();
let empty = tts.is_empty();
self.bclose(span, empty);
}
_ => {
Some(delim) => {
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
self.word(token_str);
self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end();
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
self.word(token_str)
self.word(token_str);
}
None => {
self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end();
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
instance: Instance<'tcx>,
mir: &Body<'tcx>,
fn_dbg_scope: &'ll DIScope,
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
) {
// Find all scopes with variables defined in them.
Expand All @@ -38,47 +37,49 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
// Nothing to emit, of course.
None
};

let mut instantiated = BitSet::new_empty(mir.source_scopes.len());
// Instantiate all scopes.
for idx in 0..mir.source_scopes.len() {
let scope = SourceScope::new(idx);
make_mir_scope(cx, instance, mir, fn_dbg_scope, &variables, debug_context, scope);
make_mir_scope(cx, instance, mir, &variables, debug_context, &mut instantiated, scope);
}
assert!(instantiated.count() == mir.source_scopes.len());
}

fn make_mir_scope<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
instance: Instance<'tcx>,
mir: &Body<'tcx>,
fn_dbg_scope: &'ll DIScope,
variables: &Option<BitSet<SourceScope>>,
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
instantiated: &mut BitSet<SourceScope>,
scope: SourceScope,
) {
if debug_context.scopes[scope].dbg_scope.is_some() {
if instantiated.contains(scope) {
return;
}

let scope_data = &mir.source_scopes[scope];
let parent_scope = if let Some(parent) = scope_data.parent_scope {
make_mir_scope(cx, instance, mir, fn_dbg_scope, variables, debug_context, parent);
make_mir_scope(cx, instance, mir, variables, debug_context, instantiated, parent);
debug_context.scopes[parent]
} else {
// The root is the function itself.
let loc = cx.lookup_debug_loc(mir.span.lo());
debug_context.scopes[scope] = DebugScope {
dbg_scope: Some(fn_dbg_scope),
inlined_at: None,
file_start_pos: loc.file.start_pos,
file_end_pos: loc.file.end_pos,
..debug_context.scopes[scope]
};
instantiated.insert(scope);
return;
};

if let Some(vars) = variables && !vars.contains(scope) && scope_data.inlined.is_none() {
// Do not create a DIScope if there are no variables defined in this
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
debug_context.scopes[scope] = parent_scope;
instantiated.insert(scope);
return;
}

Expand All @@ -100,7 +101,7 @@ fn make_mir_scope<'ll, 'tcx>(
None => unsafe {
llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx),
parent_scope.dbg_scope.unwrap(),
parent_scope.dbg_scope,
file_metadata,
loc.line,
loc.col,
Expand All @@ -116,9 +117,10 @@ fn make_mir_scope<'ll, 'tcx>(
});

debug_context.scopes[scope] = DebugScope {
dbg_scope: Some(dbg_scope),
dbg_scope,
inlined_at: inlined_at.or(parent_scope.inlined_at),
file_start_pos: loc.file.start_pos,
file_end_pos: loc.file.end_pos,
};
instantiated.insert(scope);
}
11 changes: 2 additions & 9 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}

// Initialize fn debug context (including scopes).
// FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`.
let empty_scope = DebugScope {
dbg_scope: None,
dbg_scope: self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
inlined_at: None,
file_start_pos: BytePos(0),
file_end_pos: BytePos(0),
Expand All @@ -297,13 +296,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) };

// Fill in all the scopes, with the information from the MIR body.
compute_mir_scopes(
self,
instance,
mir,
self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
&mut fn_debug_context,
);
compute_mir_scopes(self, instance, mir, &mut fn_debug_context);

Some(fn_debug_context)
}
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {

#[derive(Clone, Copy, Debug)]
pub struct DebugScope<S, L> {
// FIXME(eddyb) this should never be `None`, after initialization.
pub dbg_scope: Option<S>,
pub dbg_scope: S,

/// Call site location, if this scope was inlined from another function.
pub inlined_at: Option<L>,
Expand All @@ -61,17 +60,12 @@ impl<'tcx, S: Copy, L: Copy> DebugScope<S, L> {
cx: &Cx,
span: Span,
) -> S {
// FIXME(eddyb) this should never be `None`.
let dbg_scope = self
.dbg_scope
.unwrap_or_else(|| bug!("`dbg_scope` is only `None` during initialization"));

let pos = span.lo();
if pos < self.file_start_pos || pos >= self.file_end_pos {
let sm = cx.sess().source_map();
cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file)
cx.extend_scope_to_file(self.dbg_scope, &sm.lookup_char_pos(pos).file)
} else {
dbg_scope
self.dbg_scope
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/parser.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parser-struct-literal-body-without-path =
struct literal body without path
.suggestion = you might have forgotten to add the struct literal inside the block

parser-maybe-report-ambiguous-plus =
ambiguous `+` in a type
.suggestion = use parentheses to disambiguate
9 changes: 4 additions & 5 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ fn generic_extension<'cx, 'tt>(
// Merge the gated spans from parsing the matcher with the pre-existing ones.
sess.gated_spans.merge(gated_spans_snapshot);

// Ignore the delimiters on the RHS.
let rhs = match &rhses[i] {
mbe::TokenTree::Delimited(_, delimited) => &delimited.tts,
let (rhs, rhs_span): (&mbe::Delimited, DelimSpan) = match &rhses[i] {
mbe::TokenTree::Delimited(span, delimited) => (&delimited, *span),
_ => cx.span_bug(sp, "malformed macro rhs"),
};
let arm_span = rhses[i].span();

let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
let rhs_spans = rhs.tts.iter().map(|t| t.span()).collect::<Vec<_>>();
// rhs has holes ( `$id` and `$(...)` that need filled)
let mut tts = match transcribe(cx, &named_matches, &rhs, transparency) {
let mut tts = match transcribe(cx, &named_matches, &rhs, rhs_span, transparency) {
Ok(tts) => tts,
Err(mut err) => {
err.emit();
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl MutVisitor for Marker {
enum Frame<'a> {
Delimited {
tts: &'a [mbe::TokenTree],
delim_token: token::DelimToken,
idx: usize,
delim_token: token::DelimToken,
span: DelimSpan,
},
Sequence {
Expand All @@ -42,8 +42,8 @@ enum Frame<'a> {

impl<'a> Frame<'a> {
/// Construct a new frame around the delimited set of tokens.
fn new(tts: &'a [mbe::TokenTree]) -> Frame<'a> {
Frame::Delimited { tts, delim_token: token::NoDelim, idx: 0, span: DelimSpan::dummy() }
fn new(src: &'a mbe::Delimited, span: DelimSpan) -> Frame<'a> {
Frame::Delimited { tts: &src.tts, idx: 0, delim_token: src.delim, span }
}
}

Expand Down Expand Up @@ -85,17 +85,18 @@ impl<'a> Iterator for Frame<'a> {
pub(super) fn transcribe<'a>(
cx: &ExtCtxt<'a>,
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
src: &[mbe::TokenTree],
src: &mbe::Delimited,
src_span: DelimSpan,
transparency: Transparency,
) -> PResult<'a, TokenStream> {
// Nothing for us to transcribe...
if src.is_empty() {
if src.tts.is_empty() {
return Ok(TokenStream::default());
}

// We descend into the RHS (`src`), expanding things as we go. This stack contains the things
// we have yet to expand/are still expanding. We start the stack off with the whole RHS.
let mut stack: SmallVec<[Frame<'_>; 1]> = smallvec![Frame::new(&src)];
let mut stack: SmallVec<[Frame<'_>; 1]> = smallvec![Frame::new(&src, src_span)];

// As we descend in the RHS, we will need to be able to match nested sequences of matchers.
// `repeats` keeps track of where we are in matching at each level, with the last element being
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/session_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
{
fn into_diagnostic(
self,
#sess: &'__session_diagnostic_sess rustc_session::Session
#sess: &'__session_diagnostic_sess rustc_session::parse::ParseSess
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, #param_ty> {
use rustc_errors::IntoDiagnosticArg;
#implementation
Expand Down
Loading