Skip to content

Commit 22719ef

Browse files
committed
Auto merge of #88824 - Manishearth:rollup-7bzk9h6, r=Manishearth
Rollup of 15 pull requests Successful merges: - #85200 (Ignore derived Clone and Debug implementations during dead code analysis) - #86165 (Add proc_macro::Span::{before, after}.) - #87088 (Fix stray notes when the source code is not available) - #87441 (Emit suggestion when passing byte literal to format macro) - #88546 (Emit proper errors when on missing closure braces) - #88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`) - #88632 (Fix issues with Markdown summary options) - #88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields) - #88667 (Tweak `write_fmt` doc.) - #88720 (Rustdoc coverage fields count) - #88732 (RustWrapper: avoid deleted unclear attribute methods) - #88742 (Fix table in docblocks) - #88776 (Workaround blink/chromium grid layout limitation of 1000 rows) - #88807 (Fix typo in docs for iterators) - #88812 (Fix typo `option` -> `options`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b69fe57 + f77311b commit 22719ef

File tree

93 files changed

+976
-212
lines changed

Some content is hidden

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

93 files changed

+976
-212
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
218218
);
219219
if self.fn_self_span_reported.insert(fn_span) {
220220
err.span_note(
221-
self_arg.span,
221+
// Check whether the source is accessible
222+
if self
223+
.infcx
224+
.tcx
225+
.sess
226+
.source_map()
227+
.span_to_snippet(self_arg.span)
228+
.is_ok()
229+
{
230+
self_arg.span
231+
} else {
232+
fn_call_span
233+
},
222234
"calling this operator moves the left-hand side",
223235
);
224236
}
@@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
429441
deref_target_ty
430442
));
431443

432-
err.span_note(deref_target, "deref defined here");
444+
// Check first whether the source is accessible (issue #87060)
445+
if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() {
446+
err.span_note(deref_target, "deref defined here");
447+
}
433448
}
434449

435450
if let Some((_, mut old_err)) =

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
510510
match expr_to_spanned_string(ecx, template_expr, msg) {
511511
Ok(template_part) => template_part,
512512
Err(err) => {
513-
if let Some(mut err) = err {
513+
if let Some((mut err, _)) = err {
514514
err.emit();
515515
}
516516
return None;

compiler/rustc_builtin_macros/src/format.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -964,17 +964,19 @@ pub fn expand_preparsed_format_args(
964964
}
965965
Ok(fmt) => fmt,
966966
Err(err) => {
967-
if let Some(mut err) = err {
967+
if let Some((mut err, suggested)) = err {
968968
let sugg_fmt = match args.len() {
969969
0 => "{}".to_string(),
970970
_ => format!("{}{{}}", "{} ".repeat(args.len())),
971971
};
972-
err.span_suggestion(
973-
fmt_sp.shrink_to_lo(),
974-
"you might be missing a string literal to format with",
975-
format!("\"{}\", ", sugg_fmt),
976-
Applicability::MaybeIncorrect,
977-
);
972+
if !suggested {
973+
err.span_suggestion(
974+
fmt_sp.shrink_to_lo(),
975+
"you might be missing a string literal to format with",
976+
format!("\"{}\", ", sugg_fmt),
977+
Applicability::MaybeIncorrect,
978+
);
979+
}
978980
err.emit();
979981
}
980982
return DummyResult::raw_expr(sp, true);

compiler/rustc_expand/src/base.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
1010
use rustc_attr::{self as attr, Deprecation, Stability};
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::sync::{self, Lrc};
13-
use rustc_errors::{DiagnosticBuilder, ErrorReported};
13+
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
1414
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1515
use rustc_lint_defs::BuiltinLintDiagnostics;
1616
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
@@ -1136,36 +1136,51 @@ impl<'a> ExtCtxt<'a> {
11361136
}
11371137

11381138
/// Extracts a string literal from the macro expanded version of `expr`,
1139-
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
1140-
/// compilation on error, merely emits a non-fatal error and returns `None`.
1139+
/// returning a diagnostic error of `err_msg` if `expr` is not a string literal.
1140+
/// The returned bool indicates whether an applicable suggestion has already been
1141+
/// added to the diagnostic to avoid emitting multiple suggestions. `Err(None)`
1142+
/// indicates that an ast error was encountered.
11411143
pub fn expr_to_spanned_string<'a>(
11421144
cx: &'a mut ExtCtxt<'_>,
11431145
expr: P<ast::Expr>,
11441146
err_msg: &str,
1145-
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
1147+
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a>, bool)>> {
11461148
// Perform eager expansion on the expression.
11471149
// We want to be able to handle e.g., `concat!("foo", "bar")`.
11481150
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
11491151

11501152
Err(match expr.kind {
11511153
ast::ExprKind::Lit(ref l) => match l.kind {
11521154
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
1155+
ast::LitKind::ByteStr(_) => {
1156+
let mut err = cx.struct_span_err(l.span, err_msg);
1157+
err.span_suggestion(
1158+
expr.span.shrink_to_lo(),
1159+
"consider removing the leading `b`",
1160+
String::new(),
1161+
Applicability::MaybeIncorrect,
1162+
);
1163+
Some((err, true))
1164+
}
11531165
ast::LitKind::Err(_) => None,
1154-
_ => Some(cx.struct_span_err(l.span, err_msg)),
1166+
_ => Some((cx.struct_span_err(l.span, err_msg), false)),
11551167
},
11561168
ast::ExprKind::Err => None,
1157-
_ => Some(cx.struct_span_err(expr.span, err_msg)),
1169+
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
11581170
})
11591171
}
11601172

1173+
/// Extracts a string literal from the macro expanded version of `expr`,
1174+
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
1175+
/// compilation on error, merely emits a non-fatal error and returns `None`.
11611176
pub fn expr_to_string(
11621177
cx: &mut ExtCtxt<'_>,
11631178
expr: P<ast::Expr>,
11641179
err_msg: &str,
11651180
) -> Option<(Symbol, ast::StrStyle)> {
11661181
expr_to_spanned_string(cx, expr, err_msg)
11671182
.map_err(|err| {
1168-
err.map(|mut err| {
1183+
err.map(|(mut err, _)| {
11691184
err.emit();
11701185
})
11711186
})

compiler/rustc_expand/src/proc_macro_server.rs

+6
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,12 @@ impl server::Span for Rustc<'_> {
758758
let loc = self.sess.source_map().lookup_char_pos(span.hi());
759759
LineColumn { line: loc.line, column: loc.col.to_usize() }
760760
}
761+
fn before(&mut self, span: Self::Span) -> Self::Span {
762+
span.shrink_to_lo()
763+
}
764+
fn after(&mut self, span: Self::Span) -> Self::Span {
765+
span.shrink_to_hi()
766+
}
761767
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
762768
let self_loc = self.sess.source_map().lookup_char_pos(first.lo());
763769
let other_loc = self.sess.source_map().lookup_char_pos(second.lo());

compiler/rustc_feature/src/accepted.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! declare_features {
1616
since: $ver,
1717
issue: to_nonzero($issue),
1818
edition: None,
19-
description: concat!($($doc,)*),
2019
}
2120
),+
2221
];

compiler/rustc_feature/src/active.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ macro_rules! declare_features {
3737
since: $ver,
3838
issue: to_nonzero($issue),
3939
edition: $edition,
40-
description: concat!($($doc,)*),
4140
}
4241
),+];
4342

compiler/rustc_feature/src/builtin_attrs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
453453
),
454454
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
455455
rustc_attr!(rustc_conversion_suggestion, Normal, template!(Word), INTERNAL_UNSTABLE),
456+
// Prevents field reads in the marked trait or method to be considered
457+
// during dead code analysis.
458+
rustc_attr!(rustc_trivial_field_reads, Normal, template!(Word), INTERNAL_UNSTABLE),
456459

457460
// ==========================================================================
458461
// Internal attributes, Const related:

compiler/rustc_feature/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub struct Feature {
5151
pub since: &'static str,
5252
issue: Option<NonZeroU32>,
5353
pub edition: Option<Edition>,
54-
description: &'static str,
5554
}
5655

5756
#[derive(Copy, Clone, Debug)]

compiler/rustc_feature/src/removed.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! declare_features {
1616
since: $ver,
1717
issue: to_nonzero($issue),
1818
edition: None,
19-
description: concat!($($doc,)*),
2019
}
2120
),+
2221
];
@@ -34,7 +33,6 @@ macro_rules! declare_features {
3433
since: $ver,
3534
issue: to_nonzero($issue),
3635
edition: None,
37-
description: concat!($($doc,)*),
3836
}
3937
),+
4038
];

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+31-25
Original file line numberDiff line numberDiff line change
@@ -203,56 +203,57 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
203203
report_fatal_error("bad AttributeKind");
204204
}
205205

206+
template<typename T> static inline void AddAttribute(T *t, unsigned Index, Attribute Attr) {
207+
#if LLVM_VERSION_LT(14, 0)
208+
t->addAttribute(Index, Attr);
209+
#else
210+
t->addAttributeAtIndex(Index, Attr);
211+
#endif
212+
}
213+
206214
extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
207215
LLVMRustAttribute RustAttr) {
208216
CallBase *Call = unwrap<CallBase>(Instr);
209217
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
210-
Call->addAttribute(Index, Attr);
218+
AddAttribute(Call, Index, Attr);
211219
}
212220

213221
extern "C" void LLVMRustAddCallSiteAttrString(LLVMValueRef Instr, unsigned Index,
214222
const char *Name) {
215223
CallBase *Call = unwrap<CallBase>(Instr);
216224
Attribute Attr = Attribute::get(Call->getContext(), Name);
217-
Call->addAttribute(Index, Attr);
225+
AddAttribute(Call, Index, Attr);
218226
}
219227

220-
221228
extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
222229
unsigned Index,
223230
uint32_t Bytes) {
224231
CallBase *Call = unwrap<CallBase>(Instr);
225-
AttrBuilder B;
226-
B.addAlignmentAttr(Bytes);
227-
Call->setAttributes(Call->getAttributes().addAttributes(
228-
Call->getContext(), Index, B));
232+
Attribute Attr = Attribute::getWithAlignment(Call->getContext(), Align(Bytes));
233+
AddAttribute(Call, Index, Attr);
229234
}
230235

231236
extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
232237
unsigned Index,
233238
uint64_t Bytes) {
234239
CallBase *Call = unwrap<CallBase>(Instr);
235-
AttrBuilder B;
236-
B.addDereferenceableAttr(Bytes);
237-
Call->setAttributes(Call->getAttributes().addAttributes(
238-
Call->getContext(), Index, B));
240+
Attribute Attr = Attribute::getWithDereferenceableBytes(Call->getContext(), Bytes);
241+
AddAttribute(Call, Index, Attr);
239242
}
240243

241244
extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
242245
unsigned Index,
243246
uint64_t Bytes) {
244247
CallBase *Call = unwrap<CallBase>(Instr);
245-
AttrBuilder B;
246-
B.addDereferenceableOrNullAttr(Bytes);
247-
Call->setAttributes(Call->getAttributes().addAttributes(
248-
Call->getContext(), Index, B));
248+
Attribute Attr = Attribute::getWithDereferenceableOrNullBytes(Call->getContext(), Bytes);
249+
AddAttribute(Call, Index, Attr);
249250
}
250251

251252
extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index,
252253
LLVMTypeRef Ty) {
253254
CallBase *Call = unwrap<CallBase>(Instr);
254255
Attribute Attr = Attribute::getWithByValType(Call->getContext(), unwrap(Ty));
255-
Call->addAttribute(Index, Attr);
256+
AddAttribute(Call, Index, Attr);
256257
}
257258

258259
extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned Index,
@@ -263,44 +264,44 @@ extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned In
263264
#else
264265
Attribute Attr = Attribute::get(Call->getContext(), Attribute::StructRet);
265266
#endif
266-
Call->addAttribute(Index, Attr);
267+
AddAttribute(Call, Index, Attr);
267268
}
268269

269270
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
270271
LLVMRustAttribute RustAttr) {
271272
Function *A = unwrap<Function>(Fn);
272273
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
273-
A->addAttribute(Index, Attr);
274+
AddAttribute(A, Index, Attr);
274275
}
275276

276277
extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
277278
unsigned Index,
278279
uint32_t Bytes) {
279280
Function *A = unwrap<Function>(Fn);
280-
A->addAttribute(Index, Attribute::getWithAlignment(
281+
AddAttribute(A, Index, Attribute::getWithAlignment(
281282
A->getContext(), llvm::Align(Bytes)));
282283
}
283284

284285
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
285286
uint64_t Bytes) {
286287
Function *A = unwrap<Function>(Fn);
287-
A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(),
288+
AddAttribute(A, Index, Attribute::getWithDereferenceableBytes(A->getContext(),
288289
Bytes));
289290
}
290291

291292
extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
292293
unsigned Index,
293294
uint64_t Bytes) {
294295
Function *A = unwrap<Function>(Fn);
295-
A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes(
296+
AddAttribute(A, Index, Attribute::getWithDereferenceableOrNullBytes(
296297
A->getContext(), Bytes));
297298
}
298299

299300
extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
300301
LLVMTypeRef Ty) {
301302
Function *F = unwrap<Function>(Fn);
302303
Attribute Attr = Attribute::getWithByValType(F->getContext(), unwrap(Ty));
303-
F->addAttribute(Index, Attr);
304+
AddAttribute(F, Index, Attr);
304305
}
305306

306307
extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
@@ -311,15 +312,15 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
311312
#else
312313
Attribute Attr = Attribute::get(F->getContext(), Attribute::StructRet);
313314
#endif
314-
F->addAttribute(Index, Attr);
315+
AddAttribute(F, Index, Attr);
315316
}
316317

317318
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
318319
unsigned Index,
319320
const char *Name,
320321
const char *Value) {
321322
Function *F = unwrap<Function>(Fn);
322-
F->addAttribute(Index, Attribute::get(
323+
AddAttribute(F, Index, Attribute::get(
323324
F->getContext(), StringRef(Name), StringRef(Value)));
324325
}
325326

@@ -330,7 +331,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
330331
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
331332
AttrBuilder B(Attr);
332333
auto PAL = F->getAttributes();
333-
auto PALNew = PAL.removeAttributes(F->getContext(), Index, B);
334+
AttributeList PALNew;
335+
#if LLVM_VERSION_LT(14, 0)
336+
PALNew = PAL.removeAttributes(F->getContext(), Index, B);
337+
#else
338+
PALNew = PAL.removeAttributesAtIndex(F->getContext(), Index, B);
339+
#endif
334340
F->setAttributes(PALNew);
335341
}
336342

compiler/rustc_middle/src/hir/map/collector.rs

-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ fn hash_body(
6262
stable_hasher.finish()
6363
}
6464

65-
/// Represents an entry and its parent `HirId`.
66-
#[derive(Copy, Clone, Debug)]
67-
pub struct Entry<'hir> {
68-
parent: HirId,
69-
node: Node<'hir>,
70-
}
71-
7265
impl<'a, 'hir> NodeCollector<'a, 'hir> {
7366
pub(super) fn root(
7467
sess: &'a Session,

compiler/rustc_middle/src/ich/hcx.rs

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
2828
/// things (e.g., each `DefId`/`DefPath` is only hashed once).
2929
#[derive(Clone)]
3030
pub struct StableHashingContext<'a> {
31-
sess: &'a Session,
3231
definitions: &'a Definitions,
3332
cstore: &'a dyn CrateStore,
3433
pub(super) body_resolver: BodyResolver<'a>,
@@ -78,7 +77,6 @@ impl<'a> StableHashingContext<'a> {
7877
!always_ignore_spans && !sess.opts.debugging_opts.incremental_ignore_spans;
7978

8079
StableHashingContext {
81-
sess,
8280
body_resolver: BodyResolver(krate),
8381
definitions,
8482
cstore,

compiler/rustc_mir_build/src/build/matches/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,7 @@ fn traverse_candidate<'pat, 'tcx: 'pat, C, T, I>(
900900
struct Binding<'tcx> {
901901
span: Span,
902902
source: Place<'tcx>,
903-
name: Symbol,
904903
var_id: HirId,
905-
var_ty: Ty<'tcx>,
906-
mutability: Mutability,
907904
binding_mode: BindingMode,
908905
}
909906

0 commit comments

Comments
 (0)