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 4 pull requests #134360

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4275,7 +4275,6 @@ dependencies = [
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_lexer",
"rustc_macros",
"rustc_middle",
"rustc_privacy",
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,6 @@ lint_non_camel_case_type = {$sort} `{$name}` should have an upper camel case nam
.suggestion = convert the identifier to upper camel case
.label = should have an UpperCamelCase name

lint_non_existent_doc_keyword = found non-existing keyword `{$keyword}` used in `#[doc(keyword = "...")]`
.help = only existing keywords are allowed in core/std

lint_non_fmt_panic = panic message is not a string literal
.note = this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021
.more_info_note = for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
Expand Down
44 changes: 2 additions & 42 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Span;
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{Symbol, kw, sym};
use rustc_span::symbol::sym;
use tracing::debug;

use crate::lints::{
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand,
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag,
SymbolInternStringLiteralDiag, TyQualified, TykindDiag, TykindKind, TypeIrInherentUsage,
UntranslatableDiag,
Expand Down Expand Up @@ -375,46 +375,6 @@ impl EarlyLintPass for LintPassImpl {
}
}

declare_tool_lint! {
/// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
/// that don't exist, e.g. `#[doc(keyword = "..")]`.
pub rustc::EXISTING_DOC_KEYWORD,
Allow,
"Check that documented keywords in std and core actually exist",
report_in_external_macro: true
}

declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);

fn is_doc_keyword(s: Symbol) -> bool {
s <= kw::Union
}

impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
for attr in cx.tcx.hir().attrs(item.hir_id()) {
if !attr.has_name(sym::doc) {
continue;
}
if let Some(list) = attr.meta_item_list() {
for nested in list {
if nested.has_name(sym::keyword) {
let keyword = nested
.value_str()
.expect("#[doc(keyword = \"...\")] expected a value!");
if is_doc_keyword(keyword) {
return;
}
cx.emit_span_lint(EXISTING_DOC_KEYWORD, attr.span, NonExistentDocKeyword {
keyword,
});
}
}
}
}
}
}

declare_tool_lint! {
/// The `untranslatable_diagnostic` lint detects messages passed to functions with `impl
/// Into<{D,Subd}iagMessage` parameters without using translatable Fluent strings.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,6 @@ fn register_internals(store: &mut LintStore) {
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
store.register_lints(&QueryStability::lint_vec());
store.register_late_mod_pass(|_| Box::new(QueryStability));
store.register_lints(&ExistingDocKeyword::lint_vec());
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
store.register_lints(&TyTyKind::lint_vec());
store.register_late_mod_pass(|_| Box::new(TyTyKind));
store.register_lints(&TypeIr::lint_vec());
Expand Down Expand Up @@ -629,7 +627,6 @@ fn register_internals(store: &mut LintStore) {
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
LintId::of(USAGE_OF_QUALIFIED_TY),
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
LintId::of(EXISTING_DOC_KEYWORD),
LintId::of(BAD_OPT_ACCESS),
LintId::of(SPAN_USE_EQ_CTXT),
]);
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,6 @@ pub(crate) struct NonGlobImportTypeIrInherent {
#[help]
pub(crate) struct LintPassByHand;

#[derive(LintDiagnostic)]
#[diag(lint_non_existent_doc_keyword)]
#[help]
pub(crate) struct NonExistentDocKeyword {
pub keyword: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(lint_diag_out_of_impl)]
pub(crate) struct DiagOutOfImpl;
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.collect()
}
AdtExprBase::DefaultFields(field_types) => {
itertools::zip_eq(field_names, &**field_types)
.map(|(n, ty)| match fields_map.get(&n) {
itertools::zip_eq(field_names, field_types)
.map(|(n, &ty)| match fields_map.get(&n) {
Some(v) => v.clone(),
None => match variant.fields[n].value {
Some(def) => {
let value = Const::from_unevaluated(this.tcx, def)
.instantiate(this.tcx, args);
this.literal_operand(expr_span, value)
let value = Const::Unevaluated(
UnevaluatedConst::new(def, args),
ty,
);
Operand::Constant(Box::new(ConstOperand {
span: expr_span,
user_ty: None,
const_: value,
}))
}
None => {
let name = variant.fields[n].name;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_privacy = { path = "../rustc_privacy" }
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ passes_doc_invalid =
passes_doc_keyword_empty_mod =
`#[doc(keyword = "...")]` should be used on empty modules
passes_doc_keyword_invalid_ident =
`{$doc_keyword}` is not a valid identifier
passes_doc_keyword_not_keyword =
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
.help = only existing keywords are allowed in core/std
passes_doc_keyword_not_mod =
`#[doc(keyword = "...")]` should be used on modules
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

fn check_doc_keyword(&self, meta: &MetaItemInner, hir_id: HirId) {
fn is_doc_keyword(s: Symbol) -> bool {
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
s <= kw::Union || s == sym::SelfTy
}

let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
if doc_keyword == kw::Empty {
self.doc_attr_str_error(meta, "keyword");
Expand All @@ -933,10 +940,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return;
}
}
if !rustc_lexer::is_ident(doc_keyword.as_str()) {
self.dcx().emit_err(errors::DocKeywordInvalidIdent {
if !is_doc_keyword(doc_keyword) {
self.dcx().emit_err(errors::DocKeywordNotKeyword {
span: meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
doc_keyword,
keyword: doc_keyword,
});
}
}
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,19 @@ pub(crate) struct DocKeywordEmptyMod {
}

#[derive(Diagnostic)]
#[diag(passes_doc_keyword_not_mod)]
pub(crate) struct DocKeywordNotMod {
#[diag(passes_doc_keyword_not_keyword)]
#[help]
pub(crate) struct DocKeywordNotKeyword {
#[primary_span]
pub span: Span,
pub keyword: Symbol,
}

#[derive(Diagnostic)]
#[diag(passes_doc_keyword_invalid_ident)]
pub(crate) struct DocKeywordInvalidIdent {
#[diag(passes_doc_keyword_not_mod)]
pub(crate) struct DocKeywordNotMod {
#[primary_span]
pub span: Span,
pub doc_keyword: Symbol,
}

#[derive(Diagnostic)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ symbols! {
RwLockWriteGuard,
Saturating,
SeekFrom,
SelfTy,
Send,
SeqCst,
Sized,
Expand Down
46 changes: 26 additions & 20 deletions compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn cmp_fn_sig(
&self,
sig1: &ty::PolyFnSig<'tcx>,
fn_def1: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
sig2: &ty::PolyFnSig<'tcx>,
fn_def2: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
) -> (DiagStyledString, DiagStyledString) {
let sig1 = &(self.normalize_fn_sig)(*sig1);
let sig2 = &(self.normalize_fn_sig)(*sig2);
Expand Down Expand Up @@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
(values.1).0.extend(x2.0);
}

let fmt = |(did, args)| format!(" {{{}}}", self.tcx.def_path_str_with_args(did, args));

match (fn_def1, fn_def2) {
(None, None) => {}
(Some(fn_def1), Some(fn_def2)) => {
let path1 = fmt(fn_def1);
let path2 = fmt(fn_def2);
let same_path = path1 == path2;
values.0.push(path1, !same_path);
values.1.push(path2, !same_path);
}
(Some(fn_def1), None) => {
values.0.push_highlighted(fmt(fn_def1));
}
(None, Some(fn_def2)) => {
values.1.push_highlighted(fmt(fn_def2));
}
}

values
}

Expand Down Expand Up @@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
let mut values = self.cmp_fn_sig(&sig1, &sig2);
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
let same_path = path1 == path2;
values.0.push(path1, !same_path);
values.1.push(path2, !same_path);
values
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig2, Some((*did2, args2)))
}

(ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2));
values.0.push_highlighted(format!(
" {{{}}}",
self.tcx.def_path_str_with_args(*did1, args1)
));
values
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig_tys2.with(*hdr2), None)
}

(ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => {
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2);
values
.1
.push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
values
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig2, Some((*did2, args2)))
}

(ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => {
self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2))
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig_tys2.with(*hdr2), None)
}

_ => {
Expand Down Expand Up @@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
if exp_found.references_error() {
return None;
}
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, None, &exp_found.found, None);
Some((exp, fnd, None))
}
}
Expand Down
Loading
Loading