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 7 pull requests #86534

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
79388aa
Add future_prelude_collision lint
jam1garner May 26, 2021
01bdb8e
Disable `future_prelude_collision` for 2021 edition
jam1garner May 26, 2021
a9dc234
Add docs for FnCtxt::resolve_ufcs
jam1garner May 27, 2021
1626e19
Add support for associated functions to `future_prelude_collision` lint
jam1garner May 27, 2021
c341d5b
Improve documentation for `future_prelude_collision` lint
jam1garner May 27, 2021
35af383
Add UI tests for `future_prelude_collision` lint
jam1garner May 27, 2021
c41a157
Fix incorrect argument description on FnCtxt::resolve_ufcs
jam1garner May 27, 2021
327697a
Fix autoderef and autoref for `future_prelude_collision` lint
jam1garner May 27, 2021
eb5e0af
Add autoderef and autoref tests for `future_prelude_collision` lint
jam1garner May 27, 2021
93c60f2
Fix missing generic parameters from `future_prelude_collision` lint s…
jam1garner May 27, 2021
cb49992
Fix `future_prelude_collision` lint breaking for pointer mutabilty co…
jam1garner May 28, 2021
4a21a0b
Fix `future_prelude_collision` not maintaining type aliases
jam1garner May 28, 2021
64c61a3
Fix `future_prelude_collision` adding unneeded generic arguments
jam1garner May 28, 2021
32408cf
move test to rust-2021 directory
nikomatsakis Jun 4, 2021
19ba219
add inherent-method-collision test
nikomatsakis Jun 4, 2021
8d42f3d
don't warn for fully qual inherent methods
nikomatsakis Jun 14, 2021
17ab9c0
extract Rust 2021 prelude logic to its own module
nikomatsakis Jun 14, 2021
3efa5b4
Emit additional arguments in `future_prelude_collision` lint
jam1garner Jun 15, 2021
56108f6
Add future_prelude_collision to 2021 compat group
jam1garner Jun 15, 2021
2325966
Implement printing of stack traces on LLVM segfaults and aborts
in42 Dec 19, 2020
ec6a85a
Small fixes
tmandry Apr 2, 2021
a89c7e1
add regression test for issue #37508
yerke Jun 17, 2021
dbc9da7
WIP: Find the imports that were used to reach a method
nikomatsakis Jun 17, 2021
9bee7f0
WIP: identify the case where we need to serialize path
nikomatsakis Jun 18, 2021
20915d4
Resolve intra-doc links in summary desc
notriddle Jun 18, 2021
f67585d
Update test cases for intra-doc links in summaries
notriddle Jun 19, 2021
b18704d
Fix future_prelude_collision for object calls and use as _
jam1garner Jun 19, 2021
3dc47e2
do not run rustfix for future-prelude-collision-shadow
nikomatsakis Jun 21, 2021
186c09a
add test for `dyn` collisions
nikomatsakis Jun 21, 2021
200fdaa
Specify the kind of the item for E0121
fee1-dead Jun 18, 2021
9b6c7ff
Updated tests to reflect specified types in E0121
fee1-dead Jun 18, 2021
e66f241
Update #83739 with type of the item specified
fee1-dead Jun 21, 2021
aa3580b
introduce helper function
nikomatsakis Jun 21, 2021
b07bb6d
Fix unused_unsafe with compiler-generated unsafe
camsteffen Apr 30, 2021
9224b6f
Remove unnecessary call to queries.crate_name()
jyn514 Jun 21, 2021
1c557da
Rename cratename -> crate_name
jyn514 Jun 21, 2021
ff0e046
Don't reallocate the crate name when running doctests
jyn514 Jun 21, 2021
f9e886c
Rollup merge of #80182 - in42:stack_trace, r=tmandry
fee1-dead Jun 22, 2021
4c27d8e
Rollup merge of #85707 - jam1garner:future_prelude_collision_lint, r=…
fee1-dead Jun 22, 2021
4e1e6d8
Rollup merge of #86223 - fee1-dead:better-E0121, r=petrochenkov
fee1-dead Jun 22, 2021
16a12c2
Rollup merge of #86352 - yerke:add-test-for-issue-37508, r=Mark-Simul…
fee1-dead Jun 22, 2021
0ae5ef9
Rollup merge of #86451 - notriddle:notriddle/rustdoc-intra-doc-link-s…
fee1-dead Jun 22, 2021
5c825d4
Rollup merge of #86501 - jyn514:doctest-cleanup, r=CraftSpider
fee1-dead Jun 22, 2021
530b376
Rollup merge of #86517 - camsteffen:unused-unsafe-async, r=LeSeulArti…
fee1-dead Jun 22, 2021
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
Prev Previous commit
Next Next commit
Specify the kind of the item for E0121
  • Loading branch information
fee1-dead committed Jun 21, 2021
commit 200fdaac777b8c0a4d5cf2be86f639c61358d518
21 changes: 21 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,27 @@ impl ItemKind<'_> {
_ => return None,
})
}

pub fn descr(&self) -> &'static str {
match self {
ItemKind::ExternCrate(..) => "extern crate",
ItemKind::Use(..) => "`use` import",
ItemKind::Static(..) => "static item",
ItemKind::Const(..) => "constant item",
ItemKind::Fn(..) => "function",
ItemKind::Mod(..) => "module",
ItemKind::ForeignMod { .. } => "extern block",
ItemKind::GlobalAsm(..) => "global asm item",
ItemKind::TyAlias(..) => "type alias",
ItemKind::OpaqueTy(..) => "opaque type",
ItemKind::Enum(..) => "enum",
ItemKind::Struct(..) => "struct",
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "implementation",
}
}
}

/// A reference from an trait to one of its associated items. This
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
visitor.0,
true,
hir_ty,
"function",
);
}

Expand Down
41 changes: 31 additions & 10 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ crate fn placeholder_type_error(
placeholder_types: Vec<Span>,
suggest: bool,
hir_ty: Option<&hir::Ty<'_>>,
kind: &'static str,
) {
if placeholder_types.is_empty() {
return;
Expand Down Expand Up @@ -174,7 +175,7 @@ crate fn placeholder_type_error(
));
}

let mut err = bad_placeholder_type(tcx, placeholder_types);
let mut err = bad_placeholder_type(tcx, placeholder_types, kind);

// Suggest, but only if it is not a function in const or static
if suggest {
Expand Down Expand Up @@ -236,7 +237,15 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_item(item);

placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None);
placeholder_type_error(
tcx,
Some(generics.span),
generics.params,
visitor.0,
suggest,
None,
item.kind.descr(),
);
}

impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
Expand Down Expand Up @@ -302,13 +311,17 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
fn bad_placeholder_type(
tcx: TyCtxt<'tcx>,
mut spans: Vec<Span>,
kind: &'static str,
) -> rustc_errors::DiagnosticBuilder<'tcx> {
let kind = if kind.ends_with('s') { format!("{}es", kind) } else { format!("{}s", kind) };

spans.sort();
let mut err = struct_span_err!(
tcx.sess,
spans.clone(),
E0121,
"the type placeholder `_` is not allowed within types on item signatures",
"the type placeholder `_` is not allowed within types on item signatures for {}",
kind
);
for span in spans {
err.span_label(span, "not allowed in type signatures");
Expand Down Expand Up @@ -382,7 +395,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
_: Option<&ty::GenericParamDef>,
span: Span,
) -> &'tcx Const<'tcx> {
bad_placeholder_type(self.tcx(), vec![span]).emit();
bad_placeholder_type(self.tcx(), vec![span], "generic").emit();
// Typeck doesn't expect erased regions to be returned from `type_of`.
let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match r {
ty::ReErased => self.tcx.lifetimes.re_static,
Expand Down Expand Up @@ -746,7 +759,15 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
hir::ForeignItemKind::Static(..) => {
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_foreign_item(item);
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
placeholder_type_error(
tcx,
None,
&[],
visitor.0,
false,
None,
"static variable",
);
}
_ => (),
}
Expand Down Expand Up @@ -846,7 +867,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
// Account for `const C: _;`.
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item);
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "constant");
}

hir::TraitItemKind::Type(_, Some(_)) => {
Expand All @@ -855,7 +876,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
// Account for `type T = _;`.
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item);
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
}

hir::TraitItemKind::Type(_, None) => {
Expand All @@ -865,7 +886,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item);

placeholder_type_error(tcx, None, &[], visitor.0, false, None);
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
}
};

Expand All @@ -887,7 +908,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_impl_item(impl_item);

placeholder_type_error(tcx, None, &[], visitor.0, false, None);
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
}
hir::ImplItemKind::Const(..) => {}
}
Expand Down Expand Up @@ -1711,7 +1732,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {

let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_ty(ty);
let mut diag = bad_placeholder_type(tcx, visitor.0);
let mut diag = bad_placeholder_type(tcx, visitor.0, "return type");
let ret_ty = fn_sig.output();
if ret_ty != tcx.ty_error() {
if !ret_ty.is_closure() {
Expand Down
37 changes: 28 additions & 9 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
TraitItemKind::Const(ref ty, body_id) => body_id
.and_then(|body_id| {
if is_suggestable_infer_ty(ty) {
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident))
Some(infer_placeholder_type(
tcx, def_id, body_id, ty.span, item.ident, "constant",
))
} else {
None
}
Expand All @@ -304,7 +306,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
ImplItemKind::Const(ref ty, body_id) => {
if is_suggestable_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
} else {
icx.to_ty(ty)
}
Expand All @@ -320,9 +322,25 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {

Node::Item(item) => {
match item.kind {
ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => {
ItemKind::Static(ref ty, .., body_id) => {
if is_suggestable_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
infer_placeholder_type(
tcx,
def_id,
body_id,
ty.span,
item.ident,
"static variable",
)
} else {
icx.to_ty(ty)
}
}
ItemKind::Const(ref ty, body_id) => {
if is_suggestable_infer_ty(ty) {
infer_placeholder_type(
tcx, def_id, body_id, ty.span, item.ident, "constant",
)
} else {
icx.to_ty(ty)
}
Expand Down Expand Up @@ -742,13 +760,14 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
concrete_ty
}

fn infer_placeholder_type(
tcx: TyCtxt<'_>,
fn infer_placeholder_type<'a>(
tcx: TyCtxt<'a>,
def_id: LocalDefId,
body_id: hir::BodyId,
span: Span,
item_ident: Ident,
) -> Ty<'_> {
kind: &'static str,
) -> Ty<'a> {
// Attempts to make the type nameable by turning FnDefs into FnPtrs.
struct MakeNameable<'tcx> {
success: bool,
Expand Down Expand Up @@ -802,7 +821,7 @@ fn infer_placeholder_type(
if let Some(sugg_ty) = sugg_ty {
err.span_suggestion(
span,
"provide a type for the item",
&format!("provide a type for the {item}", item = kind),
format!("{}: {}", item_ident, sugg_ty),
Applicability::MachineApplicable,
);
Expand All @@ -816,7 +835,7 @@ fn infer_placeholder_type(
err.emit_unless(ty.references_error());
}
None => {
let mut diag = bad_placeholder_type(tcx, vec![span]);
let mut diag = bad_placeholder_type(tcx, vec![span], kind);

if !ty.references_error() {
let mut mk_nameable = MakeNameable::new(tcx);
Expand Down