Skip to content

Commit fcbc153

Browse files
committed
Auto merge of #134360 - matthiaskrgr:rollup-5ckix8i, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #134202 (Remove `rustc::existing_doc_keyword` lint) - #134314 (Make sure to use normalized ty for unevaluated const in default struct value) - #134342 (crashes: more tests) - #134354 (Handle fndef rendering together with signature rendering) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2b91cc + d778dda commit fcbc153

Some content is hidden

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

45 files changed

+364
-217
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4275,7 +4275,6 @@ dependencies = [
42754275
"rustc_fluent_macro",
42764276
"rustc_hir",
42774277
"rustc_index",
4278-
"rustc_lexer",
42794278
"rustc_macros",
42804279
"rustc_middle",
42814280
"rustc_privacy",

compiler/rustc_lint/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,6 @@ lint_non_camel_case_type = {$sort} `{$name}` should have an upper camel case nam
536536
.suggestion = convert the identifier to upper camel case
537537
.label = should have an UpperCamelCase name
538538
539-
lint_non_existent_doc_keyword = found non-existing keyword `{$keyword}` used in `#[doc(keyword = "...")]`
540-
.help = only existing keywords are allowed in core/std
541-
542539
lint_non_fmt_panic = panic message is not a string literal
543540
.note = this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021
544541
.more_info_note = for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>

compiler/rustc_lint/src/internal.rs

+2-42
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
1313
use rustc_span::Span;
1414
use rustc_span::hygiene::{ExpnKind, MacroKind};
15-
use rustc_span::symbol::{Symbol, kw, sym};
15+
use rustc_span::symbol::sym;
1616
use tracing::debug;
1717

1818
use crate::lints::{
19-
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
19+
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand,
2020
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag,
2121
SymbolInternStringLiteralDiag, TyQualified, TykindDiag, TykindKind, TypeIrInherentUsage,
2222
UntranslatableDiag,
@@ -375,46 +375,6 @@ impl EarlyLintPass for LintPassImpl {
375375
}
376376
}
377377

378-
declare_tool_lint! {
379-
/// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
380-
/// that don't exist, e.g. `#[doc(keyword = "..")]`.
381-
pub rustc::EXISTING_DOC_KEYWORD,
382-
Allow,
383-
"Check that documented keywords in std and core actually exist",
384-
report_in_external_macro: true
385-
}
386-
387-
declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);
388-
389-
fn is_doc_keyword(s: Symbol) -> bool {
390-
s <= kw::Union
391-
}
392-
393-
impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
394-
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
395-
for attr in cx.tcx.hir().attrs(item.hir_id()) {
396-
if !attr.has_name(sym::doc) {
397-
continue;
398-
}
399-
if let Some(list) = attr.meta_item_list() {
400-
for nested in list {
401-
if nested.has_name(sym::keyword) {
402-
let keyword = nested
403-
.value_str()
404-
.expect("#[doc(keyword = \"...\")] expected a value!");
405-
if is_doc_keyword(keyword) {
406-
return;
407-
}
408-
cx.emit_span_lint(EXISTING_DOC_KEYWORD, attr.span, NonExistentDocKeyword {
409-
keyword,
410-
});
411-
}
412-
}
413-
}
414-
}
415-
}
416-
}
417-
418378
declare_tool_lint! {
419379
/// The `untranslatable_diagnostic` lint detects messages passed to functions with `impl
420380
/// Into<{D,Subd}iagMessage` parameters without using translatable Fluent strings.

compiler/rustc_lint/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,6 @@ fn register_internals(store: &mut LintStore) {
600600
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
601601
store.register_lints(&QueryStability::lint_vec());
602602
store.register_late_mod_pass(|_| Box::new(QueryStability));
603-
store.register_lints(&ExistingDocKeyword::lint_vec());
604-
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
605603
store.register_lints(&TyTyKind::lint_vec());
606604
store.register_late_mod_pass(|_| Box::new(TyTyKind));
607605
store.register_lints(&TypeIr::lint_vec());
@@ -629,7 +627,6 @@ fn register_internals(store: &mut LintStore) {
629627
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
630628
LintId::of(USAGE_OF_QUALIFIED_TY),
631629
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
632-
LintId::of(EXISTING_DOC_KEYWORD),
633630
LintId::of(BAD_OPT_ACCESS),
634631
LintId::of(SPAN_USE_EQ_CTXT),
635632
]);

compiler/rustc_lint/src/lints.rs

-7
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,6 @@ pub(crate) struct NonGlobImportTypeIrInherent {
950950
#[help]
951951
pub(crate) struct LintPassByHand;
952952

953-
#[derive(LintDiagnostic)]
954-
#[diag(lint_non_existent_doc_keyword)]
955-
#[help]
956-
pub(crate) struct NonExistentDocKeyword {
957-
pub keyword: Symbol,
958-
}
959-
960953
#[derive(LintDiagnostic)]
961954
#[diag(lint_diag_out_of_impl)]
962955
pub(crate) struct DiagOutOfImpl;

compiler/rustc_mir_build/src/build/expr/into.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
367367
.collect()
368368
}
369369
AdtExprBase::DefaultFields(field_types) => {
370-
itertools::zip_eq(field_names, &**field_types)
371-
.map(|(n, ty)| match fields_map.get(&n) {
370+
itertools::zip_eq(field_names, field_types)
371+
.map(|(n, &ty)| match fields_map.get(&n) {
372372
Some(v) => v.clone(),
373373
None => match variant.fields[n].value {
374374
Some(def) => {
375-
let value = Const::from_unevaluated(this.tcx, def)
376-
.instantiate(this.tcx, args);
377-
this.literal_operand(expr_span, value)
375+
let value = Const::Unevaluated(
376+
UnevaluatedConst::new(def, args),
377+
ty,
378+
);
379+
Operand::Constant(Box::new(ConstOperand {
380+
span: expr_span,
381+
user_ty: None,
382+
const_: value,
383+
}))
378384
}
379385
None => {
380386
let name = variant.fields[n].name;

compiler/rustc_passes/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ rustc_feature = { path = "../rustc_feature" }
1616
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1717
rustc_hir = { path = "../rustc_hir" }
1818
rustc_index = { path = "../rustc_index" }
19-
rustc_lexer = { path = "../rustc_lexer" }
2019
rustc_macros = { path = "../rustc_macros" }
2120
rustc_middle = { path = "../rustc_middle" }
2221
rustc_privacy = { path = "../rustc_privacy" }

compiler/rustc_passes/messages.ftl

+3-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ passes_doc_invalid =
211211
passes_doc_keyword_empty_mod =
212212
`#[doc(keyword = "...")]` should be used on empty modules
213213
214-
passes_doc_keyword_invalid_ident =
215-
`{$doc_keyword}` is not a valid identifier
214+
passes_doc_keyword_not_keyword =
215+
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
216+
.help = only existing keywords are allowed in core/std
216217
217218
passes_doc_keyword_not_mod =
218219
`#[doc(keyword = "...")]` should be used on modules

compiler/rustc_passes/src/check_attr.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
912912
}
913913

914914
fn check_doc_keyword(&self, meta: &MetaItemInner, hir_id: HirId) {
915+
fn is_doc_keyword(s: Symbol) -> bool {
916+
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
917+
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
918+
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
919+
s <= kw::Union || s == sym::SelfTy
920+
}
921+
915922
let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
916923
if doc_keyword == kw::Empty {
917924
self.doc_attr_str_error(meta, "keyword");
@@ -933,10 +940,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
933940
return;
934941
}
935942
}
936-
if !rustc_lexer::is_ident(doc_keyword.as_str()) {
937-
self.dcx().emit_err(errors::DocKeywordInvalidIdent {
943+
if !is_doc_keyword(doc_keyword) {
944+
self.dcx().emit_err(errors::DocKeywordNotKeyword {
938945
span: meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
939-
doc_keyword,
946+
keyword: doc_keyword,
940947
});
941948
}
942949
}

compiler/rustc_passes/src/errors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,19 @@ pub(crate) struct DocKeywordEmptyMod {
216216
}
217217

218218
#[derive(Diagnostic)]
219-
#[diag(passes_doc_keyword_not_mod)]
220-
pub(crate) struct DocKeywordNotMod {
219+
#[diag(passes_doc_keyword_not_keyword)]
220+
#[help]
221+
pub(crate) struct DocKeywordNotKeyword {
221222
#[primary_span]
222223
pub span: Span,
224+
pub keyword: Symbol,
223225
}
224226

225227
#[derive(Diagnostic)]
226-
#[diag(passes_doc_keyword_invalid_ident)]
227-
pub(crate) struct DocKeywordInvalidIdent {
228+
#[diag(passes_doc_keyword_not_mod)]
229+
pub(crate) struct DocKeywordNotMod {
228230
#[primary_span]
229231
pub span: Span,
230-
pub doc_keyword: Symbol,
231232
}
232233

233234
#[derive(Diagnostic)]

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ symbols! {
306306
RwLockWriteGuard,
307307
Saturating,
308308
SeekFrom,
309+
SelfTy,
309310
Send,
310311
SeqCst,
311312
Sized,

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
824824
fn cmp_fn_sig(
825825
&self,
826826
sig1: &ty::PolyFnSig<'tcx>,
827+
fn_def1: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
827828
sig2: &ty::PolyFnSig<'tcx>,
829+
fn_def2: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
828830
) -> (DiagStyledString, DiagStyledString) {
829831
let sig1 = &(self.normalize_fn_sig)(*sig1);
830832
let sig2 = &(self.normalize_fn_sig)(*sig2);
@@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
930932
(values.1).0.extend(x2.0);
931933
}
932934

935+
let fmt = |(did, args)| format!(" {{{}}}", self.tcx.def_path_str_with_args(did, args));
936+
937+
match (fn_def1, fn_def2) {
938+
(None, None) => {}
939+
(Some(fn_def1), Some(fn_def2)) => {
940+
let path1 = fmt(fn_def1);
941+
let path2 = fmt(fn_def2);
942+
let same_path = path1 == path2;
943+
values.0.push(path1, !same_path);
944+
values.1.push(path2, !same_path);
945+
}
946+
(Some(fn_def1), None) => {
947+
values.0.push_highlighted(fmt(fn_def1));
948+
}
949+
(None, Some(fn_def2)) => {
950+
values.1.push_highlighted(fmt(fn_def2));
951+
}
952+
}
953+
933954
values
934955
}
935956

@@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13181339
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
13191340
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
13201341
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
1321-
let mut values = self.cmp_fn_sig(&sig1, &sig2);
1322-
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
1323-
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
1324-
let same_path = path1 == path2;
1325-
values.0.push(path1, !same_path);
1326-
values.1.push(path2, !same_path);
1327-
values
1342+
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig2, Some((*did2, args2)))
13281343
}
13291344

13301345
(ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => {
13311346
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
1332-
let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2));
1333-
values.0.push_highlighted(format!(
1334-
" {{{}}}",
1335-
self.tcx.def_path_str_with_args(*did1, args1)
1336-
));
1337-
values
1347+
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig_tys2.with(*hdr2), None)
13381348
}
13391349

13401350
(ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => {
13411351
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
1342-
let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2);
1343-
values
1344-
.1
1345-
.push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
1346-
values
1352+
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig2, Some((*did2, args2)))
13471353
}
13481354

13491355
(ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => {
1350-
self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2))
1356+
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig_tys2.with(*hdr2), None)
13511357
}
13521358

13531359
_ => {
@@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21022108
if exp_found.references_error() {
21032109
return None;
21042110
}
2105-
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
2111+
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, None, &exp_found.found, None);
21062112
Some((exp, fnd, None))
21072113
}
21082114
}

0 commit comments

Comments
 (0)