Skip to content

Commit

Permalink
Auto merge of rust-lang#88824 - Manishearth:rollup-7bzk9h6, r=Manishe…
Browse files Browse the repository at this point in the history
…arth

Rollup of 15 pull requests

Successful merges:

 - rust-lang#85200 (Ignore derived Clone and Debug implementations during dead code analysis)
 - rust-lang#86165 (Add proc_macro::Span::{before, after}.)
 - rust-lang#87088 (Fix stray notes when the source code is not available)
 - rust-lang#87441 (Emit suggestion when passing byte literal to format macro)
 - rust-lang#88546 (Emit proper errors when on missing closure braces)
 - rust-lang#88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`)
 - rust-lang#88632 (Fix issues with Markdown summary options)
 - rust-lang#88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields)
 - rust-lang#88667 (Tweak `write_fmt` doc.)
 - rust-lang#88720 (Rustdoc coverage fields count)
 - rust-lang#88732 (RustWrapper: avoid deleted unclear attribute methods)
 - rust-lang#88742 (Fix table in docblocks)
 - rust-lang#88776 (Workaround blink/chromium grid layout limitation of 1000 rows)
 - rust-lang#88807 (Fix typo in docs for iterators)
 - rust-lang#88812 (Fix typo `option` -> `options`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 11, 2021
2 parents b69fe57 + f77311b commit 22719ef
Show file tree
Hide file tree
Showing 93 changed files with 976 additions and 212 deletions.
19 changes: 17 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
if self.fn_self_span_reported.insert(fn_span) {
err.span_note(
self_arg.span,
// Check whether the source is accessible
if self
.infcx
.tcx
.sess
.source_map()
.span_to_snippet(self_arg.span)
.is_ok()
{
self_arg.span
} else {
fn_call_span
},
"calling this operator moves the left-hand side",
);
}
Expand Down Expand Up @@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
deref_target_ty
));

err.span_note(deref_target, "deref defined here");
// Check first whether the source is accessible (issue #87060)
if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() {
err.span_note(deref_target, "deref defined here");
}
}

if let Some((_, mut old_err)) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
match expr_to_spanned_string(ecx, template_expr, msg) {
Ok(template_part) => template_part,
Err(err) => {
if let Some(mut err) = err {
if let Some((mut err, _)) = err {
err.emit();
}
return None;
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,19 @@ pub fn expand_preparsed_format_args(
}
Ok(fmt) => fmt,
Err(err) => {
if let Some(mut err) = err {
if let Some((mut err, suggested)) = err {
let sugg_fmt = match args.len() {
0 => "{}".to_string(),
_ => format!("{}{{}}", "{} ".repeat(args.len())),
};
err.span_suggestion(
fmt_sp.shrink_to_lo(),
"you might be missing a string literal to format with",
format!("\"{}\", ", sugg_fmt),
Applicability::MaybeIncorrect,
);
if !suggested {
err.span_suggestion(
fmt_sp.shrink_to_lo(),
"you might be missing a string literal to format with",
format!("\"{}\", ", sugg_fmt),
Applicability::MaybeIncorrect,
);
}
err.emit();
}
return DummyResult::raw_expr(sp, true);
Expand Down
29 changes: 22 additions & 7 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{DiagnosticBuilder, ErrorReported};
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
Expand Down Expand Up @@ -1136,36 +1136,51 @@ impl<'a> ExtCtxt<'a> {
}

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

Err(match expr.kind {
ast::ExprKind::Lit(ref l) => match l.kind {
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
ast::LitKind::ByteStr(_) => {
let mut err = cx.struct_span_err(l.span, err_msg);
err.span_suggestion(
expr.span.shrink_to_lo(),
"consider removing the leading `b`",
String::new(),
Applicability::MaybeIncorrect,
);
Some((err, true))
}
ast::LitKind::Err(_) => None,
_ => Some(cx.struct_span_err(l.span, err_msg)),
_ => Some((cx.struct_span_err(l.span, err_msg), false)),
},
ast::ExprKind::Err => None,
_ => Some(cx.struct_span_err(expr.span, err_msg)),
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
})
}

/// Extracts a string literal from the macro expanded version of `expr`,
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
/// compilation on error, merely emits a non-fatal error and returns `None`.
pub fn expr_to_string(
cx: &mut ExtCtxt<'_>,
expr: P<ast::Expr>,
err_msg: &str,
) -> Option<(Symbol, ast::StrStyle)> {
expr_to_spanned_string(cx, expr, err_msg)
.map_err(|err| {
err.map(|mut err| {
err.map(|(mut err, _)| {
err.emit();
})
})
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,12 @@ impl server::Span for Rustc<'_> {
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());
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ macro_rules! declare_features {
since: $ver,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
),+
];
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ macro_rules! declare_features {
since: $ver,
issue: to_nonzero($issue),
edition: $edition,
description: concat!($($doc,)*),
}
),+];

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
rustc_attr!(rustc_conversion_suggestion, Normal, template!(Word), INTERNAL_UNSTABLE),
// Prevents field reads in the marked trait or method to be considered
// during dead code analysis.
rustc_attr!(rustc_trivial_field_reads, Normal, template!(Word), INTERNAL_UNSTABLE),

// ==========================================================================
// Internal attributes, Const related:
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub struct Feature {
pub since: &'static str,
issue: Option<NonZeroU32>,
pub edition: Option<Edition>,
description: &'static str,
}

#[derive(Copy, Clone, Debug)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ macro_rules! declare_features {
since: $ver,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
),+
];
Expand All @@ -34,7 +33,6 @@ macro_rules! declare_features {
since: $ver,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
),+
];
Expand Down
56 changes: 31 additions & 25 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,56 +203,57 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
report_fatal_error("bad AttributeKind");
}

template<typename T> static inline void AddAttribute(T *t, unsigned Index, Attribute Attr) {
#if LLVM_VERSION_LT(14, 0)
t->addAttribute(Index, Attr);
#else
t->addAttributeAtIndex(Index, Attr);
#endif
}

extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
LLVMRustAttribute RustAttr) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddCallSiteAttrString(LLVMValueRef Instr, unsigned Index,
const char *Name) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::get(Call->getContext(), Name);
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}


extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint32_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addAlignmentAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithAlignment(Call->getContext(), Align(Bytes));
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint64_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addDereferenceableAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithDereferenceableBytes(Call->getContext(), Bytes);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
unsigned Index,
uint64_t Bytes) {
CallBase *Call = unwrap<CallBase>(Instr);
AttrBuilder B;
B.addDereferenceableOrNullAttr(Bytes);
Call->setAttributes(Call->getAttributes().addAttributes(
Call->getContext(), Index, B));
Attribute Attr = Attribute::getWithDereferenceableOrNullBytes(Call->getContext(), Bytes);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index,
LLVMTypeRef Ty) {
CallBase *Call = unwrap<CallBase>(Instr);
Attribute Attr = Attribute::getWithByValType(Call->getContext(), unwrap(Ty));
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned Index,
Expand All @@ -263,44 +264,44 @@ extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned In
#else
Attribute Attr = Attribute::get(Call->getContext(), Attribute::StructRet);
#endif
Call->addAttribute(Index, Attr);
AddAttribute(Call, Index, Attr);
}

extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
LLVMRustAttribute RustAttr) {
Function *A = unwrap<Function>(Fn);
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
A->addAttribute(Index, Attr);
AddAttribute(A, Index, Attr);
}

extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn,
unsigned Index,
uint32_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithAlignment(
AddAttribute(A, Index, Attribute::getWithAlignment(
A->getContext(), llvm::Align(Bytes)));
}

extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(),
AddAttribute(A, Index, Attribute::getWithDereferenceableBytes(A->getContext(),
Bytes));
}

extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn,
unsigned Index,
uint64_t Bytes) {
Function *A = unwrap<Function>(Fn);
A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes(
AddAttribute(A, Index, Attribute::getWithDereferenceableOrNullBytes(
A->getContext(), Bytes));
}

extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index,
LLVMTypeRef Ty) {
Function *F = unwrap<Function>(Fn);
Attribute Attr = Attribute::getWithByValType(F->getContext(), unwrap(Ty));
F->addAttribute(Index, Attr);
AddAttribute(F, Index, Attr);
}

extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
Expand All @@ -311,15 +312,15 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
#else
Attribute Attr = Attribute::get(F->getContext(), Attribute::StructRet);
#endif
F->addAttribute(Index, Attr);
AddAttribute(F, Index, Attr);
}

extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
unsigned Index,
const char *Name,
const char *Value) {
Function *F = unwrap<Function>(Fn);
F->addAttribute(Index, Attribute::get(
AddAttribute(F, Index, Attribute::get(
F->getContext(), StringRef(Name), StringRef(Value)));
}

Expand All @@ -330,7 +331,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
AttrBuilder B(Attr);
auto PAL = F->getAttributes();
auto PALNew = PAL.removeAttributes(F->getContext(), Index, B);
AttributeList PALNew;
#if LLVM_VERSION_LT(14, 0)
PALNew = PAL.removeAttributes(F->getContext(), Index, B);
#else
PALNew = PAL.removeAttributesAtIndex(F->getContext(), Index, B);
#endif
F->setAttributes(PALNew);
}

Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_middle/src/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ fn hash_body(
stable_hasher.finish()
}

/// Represents an entry and its parent `HirId`.
#[derive(Copy, Clone, Debug)]
pub struct Entry<'hir> {
parent: HirId,
node: Node<'hir>,
}

impl<'a, 'hir> NodeCollector<'a, 'hir> {
pub(super) fn root(
sess: &'a Session,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
/// things (e.g., each `DefId`/`DefPath` is only hashed once).
#[derive(Clone)]
pub struct StableHashingContext<'a> {
sess: &'a Session,
definitions: &'a Definitions,
cstore: &'a dyn CrateStore,
pub(super) body_resolver: BodyResolver<'a>,
Expand Down Expand Up @@ -78,7 +77,6 @@ impl<'a> StableHashingContext<'a> {
!always_ignore_spans && !sess.opts.debugging_opts.incremental_ignore_spans;

StableHashingContext {
sess,
body_resolver: BodyResolver(krate),
definitions,
cstore,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,7 @@ fn traverse_candidate<'pat, 'tcx: 'pat, C, T, I>(
struct Binding<'tcx> {
span: Span,
source: Place<'tcx>,
name: Symbol,
var_id: HirId,
var_ty: Ty<'tcx>,
mutability: Mutability,
binding_mode: BindingMode,
}

Expand Down
Loading

0 comments on commit 22719ef

Please sign in to comment.