Skip to content

Commit b5a2d27

Browse files
committedJun 1, 2022
Auto merge of rust-lang#97624 - matthiaskrgr:rollup-rtcqjx9, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#96271 (suggest `?` when method is missing on `Result<T, _>` but found on `T`) - rust-lang#97264 (Suggest `extern crate foo` when failing to resolve `use foo`) - rust-lang#97592 (rustdoc: also index impl trait and raw pointers) - rust-lang#97621 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8256e97 + 89e765f commit b5a2d27

38 files changed

+647
-69
lines changed
 

‎Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -5509,6 +5509,8 @@ dependencies = [
55095509
"pretty_assertions 1.2.1",
55105510
"regex",
55115511
"rustc_version",
5512+
"serde",
5513+
"serde_json",
55125514
]
55135515

55145516
[[package]]

‎compiler/rustc_resolve/src/diagnostics.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1839,9 +1839,18 @@ impl<'a> Resolver<'a> {
18391839
)),
18401840
)
18411841
} else if self.session.edition() == Edition::Edition2015 {
1842-
(format!("maybe a missing crate `{}`?", ident), None)
1842+
(
1843+
format!("maybe a missing crate `{ident}`?"),
1844+
Some((
1845+
vec![],
1846+
format!(
1847+
"consider adding `extern crate {ident}` to use the `{ident}` crate"
1848+
),
1849+
Applicability::MaybeIncorrect,
1850+
)),
1851+
)
18431852
} else {
1844-
(format!("could not find `{}` in the crate root", ident), None)
1853+
(format!("could not find `{ident}` in the crate root"), None)
18451854
}
18461855
} else if i > 0 {
18471856
let parent = path[i - 1].ident.name;
@@ -1852,7 +1861,7 @@ impl<'a> Resolver<'a> {
18521861
"the list of imported crates".to_owned()
18531862
}
18541863
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
1855-
_ => format!("`{}`", parent),
1864+
_ => format!("`{parent}`"),
18561865
};
18571866

18581867
let mut msg = format!("could not find `{}` in {}", ident, parent);

‎compiler/rustc_resolve/src/imports.rs

+4
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
475475
}
476476

477477
if let Some((suggestions, msg, applicability)) = err.suggestion {
478+
if suggestions.is_empty() {
479+
diag.help(&msg);
480+
continue;
481+
}
478482
diag.multipart_suggestion(&msg, suggestions, applicability);
479483
}
480484
}

‎compiler/rustc_typeck/src/check/method/suggest.rs

+151-52
Original file line numberDiff line numberDiff line change
@@ -978,45 +978,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
978978
label_span_not_found(&mut err);
979979
}
980980

981-
if let SelfSource::MethodCall(expr) = source
982-
&& let Some((fields, substs)) = self.get_field_candidates(span, actual)
983-
{
984-
let call_expr =
985-
self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id));
986-
for candidate_field in fields.iter() {
987-
if let Some(field_path) = self.check_for_nested_field_satisfying(
988-
span,
989-
&|_, field_ty| {
990-
self.lookup_probe(
991-
span,
992-
item_name,
993-
field_ty,
994-
call_expr,
995-
ProbeScope::AllTraits,
996-
)
997-
.is_ok()
998-
},
999-
candidate_field,
1000-
substs,
1001-
vec![],
1002-
self.tcx.parent_module(expr.hir_id).to_def_id(),
1003-
) {
1004-
let field_path_str = field_path
1005-
.iter()
1006-
.map(|id| id.name.to_ident_string())
1007-
.collect::<Vec<String>>()
1008-
.join(".");
1009-
debug!("field_path_str: {:?}", field_path_str);
981+
self.check_for_field_method(&mut err, source, span, actual, item_name);
1010982

1011-
err.span_suggestion_verbose(
1012-
item_name.span.shrink_to_lo(),
1013-
"one of the expressions' fields has a method of the same name",
1014-
format!("{field_path_str}."),
1015-
Applicability::MaybeIncorrect,
1016-
);
1017-
}
1018-
}
1019-
}
983+
self.check_for_unwrap_self(&mut err, source, span, actual, item_name);
1020984

1021985
bound_spans.sort();
1022986
bound_spans.dedup();
@@ -1343,6 +1307,145 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13431307
false
13441308
}
13451309

1310+
fn check_for_field_method(
1311+
&self,
1312+
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1313+
source: SelfSource<'tcx>,
1314+
span: Span,
1315+
actual: Ty<'tcx>,
1316+
item_name: Ident,
1317+
) {
1318+
if let SelfSource::MethodCall(expr) = source
1319+
&& let Some((fields, substs)) = self.get_field_candidates(span, actual)
1320+
{
1321+
let call_expr = self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id));
1322+
for candidate_field in fields.iter() {
1323+
if let Some(field_path) = self.check_for_nested_field_satisfying(
1324+
span,
1325+
&|_, field_ty| {
1326+
self.lookup_probe(
1327+
span,
1328+
item_name,
1329+
field_ty,
1330+
call_expr,
1331+
ProbeScope::AllTraits,
1332+
)
1333+
.is_ok()
1334+
},
1335+
candidate_field,
1336+
substs,
1337+
vec![],
1338+
self.tcx.parent_module(expr.hir_id).to_def_id(),
1339+
) {
1340+
let field_path_str = field_path
1341+
.iter()
1342+
.map(|id| id.name.to_ident_string())
1343+
.collect::<Vec<String>>()
1344+
.join(".");
1345+
debug!("field_path_str: {:?}", field_path_str);
1346+
1347+
err.span_suggestion_verbose(
1348+
item_name.span.shrink_to_lo(),
1349+
"one of the expressions' fields has a method of the same name",
1350+
format!("{field_path_str}."),
1351+
Applicability::MaybeIncorrect,
1352+
);
1353+
}
1354+
}
1355+
}
1356+
}
1357+
1358+
fn check_for_unwrap_self(
1359+
&self,
1360+
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
1361+
source: SelfSource<'tcx>,
1362+
span: Span,
1363+
actual: Ty<'tcx>,
1364+
item_name: Ident,
1365+
) {
1366+
let tcx = self.tcx;
1367+
let SelfSource::MethodCall(expr) = source else { return; };
1368+
let call_expr = tcx.hir().expect_expr(tcx.hir().get_parent_node(expr.hir_id));
1369+
1370+
let ty::Adt(kind, substs) = actual.kind() else { return; };
1371+
if !kind.is_enum() {
1372+
return;
1373+
}
1374+
1375+
let matching_variants: Vec<_> = kind
1376+
.variants()
1377+
.iter()
1378+
.flat_map(|variant| {
1379+
let [field] = &variant.fields[..] else { return None; };
1380+
let field_ty = field.ty(tcx, substs);
1381+
1382+
// Skip `_`, since that'll just lead to ambiguity.
1383+
if self.resolve_vars_if_possible(field_ty).is_ty_var() {
1384+
return None;
1385+
}
1386+
1387+
self.lookup_probe(span, item_name, field_ty, call_expr, ProbeScope::AllTraits)
1388+
.ok()
1389+
.map(|pick| (variant, field, pick))
1390+
})
1391+
.collect();
1392+
1393+
let ret_ty_matches = |diagnostic_item| {
1394+
if let Some(ret_ty) = self
1395+
.ret_coercion
1396+
.as_ref()
1397+
.map(|c| self.resolve_vars_if_possible(c.borrow().expected_ty()))
1398+
&& let ty::Adt(kind, _) = ret_ty.kind()
1399+
&& tcx.get_diagnostic_item(diagnostic_item) == Some(kind.did())
1400+
{
1401+
true
1402+
} else {
1403+
false
1404+
}
1405+
};
1406+
1407+
match &matching_variants[..] {
1408+
[(_, field, pick)] => {
1409+
let self_ty = field.ty(tcx, substs);
1410+
err.span_note(
1411+
tcx.def_span(pick.item.def_id),
1412+
&format!("the method `{item_name}` exists on the type `{self_ty}`"),
1413+
);
1414+
let (article, kind, variant, question) =
1415+
if Some(kind.did()) == tcx.get_diagnostic_item(sym::Result) {
1416+
("a", "Result", "Err", ret_ty_matches(sym::Result))
1417+
} else if Some(kind.did()) == tcx.get_diagnostic_item(sym::Option) {
1418+
("an", "Option", "None", ret_ty_matches(sym::Option))
1419+
} else {
1420+
return;
1421+
};
1422+
if question {
1423+
err.span_suggestion_verbose(
1424+
expr.span.shrink_to_hi(),
1425+
format!(
1426+
"use the `?` operator to extract the `{self_ty}` value, propagating \
1427+
{article} `{kind}::{variant}` value to the caller"
1428+
),
1429+
"?".to_owned(),
1430+
Applicability::MachineApplicable,
1431+
);
1432+
} else {
1433+
err.span_suggestion_verbose(
1434+
expr.span.shrink_to_hi(),
1435+
format!(
1436+
"consider using `{kind}::expect` to unwrap the `{self_ty}` value, \
1437+
panicking if the value is {article} `{kind}::{variant}`"
1438+
),
1439+
".expect(\"REASON\")".to_owned(),
1440+
Applicability::HasPlaceholders,
1441+
);
1442+
}
1443+
}
1444+
// FIXME(compiler-errors): Support suggestions for other matching enum variants
1445+
_ => {}
1446+
}
1447+
}
1448+
13461449
pub(crate) fn note_unmet_impls_on_type(
13471450
&self,
13481451
err: &mut Diagnostic,
@@ -1662,13 +1765,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16621765
(self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "),
16631766
(self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"),
16641767
] {
1665-
match self.lookup_probe(
1666-
span,
1667-
item_name,
1668-
*rcvr_ty,
1669-
rcvr,
1670-
crate::check::method::probe::ProbeScope::AllTraits,
1671-
) {
1768+
match self.lookup_probe(span, item_name, *rcvr_ty, rcvr, ProbeScope::AllTraits) {
16721769
Ok(pick) => {
16731770
// If the method is defined for the receiver we have, it likely wasn't `use`d.
16741771
// We point at the method, but we just skip the rest of the check for arbitrary
@@ -1700,13 +1797,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17001797
(self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"),
17011798
(self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"),
17021799
] {
1703-
if let Some(new_rcvr_t) = *rcvr_ty && let Ok(pick) = self.lookup_probe(
1704-
span,
1705-
item_name,
1706-
new_rcvr_t,
1707-
rcvr,
1708-
crate::check::method::probe::ProbeScope::AllTraits,
1709-
) {
1800+
if let Some(new_rcvr_t) = *rcvr_ty
1801+
&& let Ok(pick) = self.lookup_probe(
1802+
span,
1803+
item_name,
1804+
new_rcvr_t,
1805+
rcvr,
1806+
ProbeScope::AllTraits,
1807+
)
1808+
{
17101809
debug!("try_alt_rcvr: pick candidate {:?}", pick);
17111810
let did = Some(pick.item.container.id());
17121811
// We don't want to suggest a container type when the missing

‎src/librustdoc/clean/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,10 @@ impl Type {
16671667
matches!(self, Type::Generic(_))
16681668
}
16691669

1670+
pub(crate) fn is_impl_trait(&self) -> bool {
1671+
matches!(self, Type::ImplTrait(_))
1672+
}
1673+
16701674
pub(crate) fn is_primitive(&self) -> bool {
16711675
self.primitive_type().is_some()
16721676
}

‎src/librustdoc/html/render/search_index.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option<Symbol> {
226226
Some(path.segments.last().unwrap().name)
227227
}
228228
// We return an empty name because we don't care about the generic name itself.
229-
clean::Generic(_) => Some(kw::Empty),
229+
clean::Generic(_) | clean::ImplTrait(_) => Some(kw::Empty),
230230
clean::Primitive(ref p) => Some(p.as_sym()),
231-
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_),
231+
clean::BorrowedRef { ref type_, .. } | clean::RawPointer(_, ref type_) => {
232+
get_index_type_name(type_)
233+
}
232234
clean::BareFunction(_)
233235
| clean::Tuple(_)
234236
| clean::Slice(_)
235237
| clean::Array(_, _)
236-
| clean::RawPointer(_, _)
237238
| clean::QPath { .. }
238-
| clean::Infer
239-
| clean::ImplTrait(_) => None,
239+
| clean::Infer => None,
240240
}
241241
}
242242

@@ -264,10 +264,12 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
264264
mut generics: Vec<TypeWithKind>,
265265
cache: &Cache,
266266
) {
267-
let is_full_generic = ty.is_full_generic();
267+
// generics and impl trait are both identified by their generics,
268+
// rather than a type name itself
269+
let anonymous = ty.is_full_generic() || ty.is_impl_trait();
268270
let generics_empty = generics.is_empty();
269271

270-
if is_full_generic {
272+
if anonymous {
271273
if generics_empty {
272274
// This is a type parameter with no trait bounds (for example: `T` in
273275
// `fn f<T>(p: T)`, so not useful for the rustdoc search because we would end up
@@ -318,7 +320,7 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
318320
if index_ty.name.as_ref().map(|s| s.is_empty() && generics_empty).unwrap_or(true) {
319321
return;
320322
}
321-
if is_full_generic {
323+
if anonymous {
322324
// We remove the name of the full generic because we have no use for it.
323325
index_ty.name = Some(String::new());
324326
res.push(TypeWithKind::from((index_ty, ItemType::Generic)));
@@ -398,6 +400,23 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
398400
}
399401
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
400402
}
403+
} else if let Type::ImplTrait(ref bounds) = *arg {
404+
let mut ty_generics = Vec::new();
405+
for bound in bounds {
406+
if let Some(path) = bound.get_trait_path() {
407+
let ty = Type::Path { path };
408+
add_generics_and_bounds_as_types(
409+
self_,
410+
generics,
411+
&ty,
412+
tcx,
413+
recurse + 1,
414+
&mut ty_generics,
415+
cache,
416+
);
417+
}
418+
}
419+
insert_ty(res, tcx, arg.clone(), ty_generics, cache);
401420
} else {
402421
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
403422
// looking at `Option`, we enter this "else" condition, otherwise if it's `T`, we don't.

‎src/test/rustdoc-js/impl-trait.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ignore-order
2+
3+
const QUERY = [
4+
'Aaaaaaa -> i32',
5+
'Aaaaaaa -> Aaaaaaa',
6+
'Aaaaaaa -> usize',
7+
'-> Aaaaaaa',
8+
'Aaaaaaa',
9+
];
10+
11+
const EXPECTED = [
12+
{
13+
// Aaaaaaa -> i32
14+
'others': [
15+
{ 'path': 'impl_trait::Ccccccc', 'name': 'eeeeeee' },
16+
],
17+
},
18+
{
19+
// Aaaaaaa -> Aaaaaaa
20+
'others': [
21+
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
22+
],
23+
},
24+
{
25+
// Aaaaaaa -> usize
26+
'others': [],
27+
},
28+
{
29+
// -> Aaaaaaa
30+
'others': [
31+
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
32+
{ 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' },
33+
{ 'path': 'impl_trait', 'name': 'bbbbbbb' },
34+
],
35+
},
36+
{
37+
// Aaaaaaa
38+
'others': [
39+
{ 'path': 'impl_trait', 'name': 'Aaaaaaa' },
40+
],
41+
'in_args': [
42+
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
43+
{ 'path': 'impl_trait::Ccccccc', 'name': 'eeeeeee' },
44+
],
45+
'returned': [
46+
{ 'path': 'impl_trait::Ccccccc', 'name': 'fffffff' },
47+
{ 'path': 'impl_trait::Ccccccc', 'name': 'ddddddd' },
48+
{ 'path': 'impl_trait', 'name': 'bbbbbbb' },
49+
],
50+
},
51+
];

‎src/test/rustdoc-js/impl-trait.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub trait Aaaaaaa {}
2+
3+
impl Aaaaaaa for () {}
4+
5+
pub fn bbbbbbb() -> impl Aaaaaaa {
6+
()
7+
}
8+
9+
pub struct Ccccccc {}
10+
11+
impl Ccccccc {
12+
pub fn ddddddd(&self) -> impl Aaaaaaa {
13+
()
14+
}
15+
pub fn eeeeeee(&self, _x: impl Aaaaaaa) -> i32 {
16+
0
17+
}
18+
pub fn fffffff(&self, x: impl Aaaaaaa) -> impl Aaaaaaa {
19+
x
20+
}
21+
}

‎src/test/rustdoc-js/raw-pointer.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ignore-order
2+
3+
const QUERY = [
4+
'Aaaaaaa -> i32',
5+
'Aaaaaaa -> Aaaaaaa',
6+
'Aaaaaaa -> usize',
7+
'-> Aaaaaaa',
8+
'Aaaaaaa',
9+
];
10+
11+
const EXPECTED = [
12+
{
13+
// Aaaaaaa -> i32
14+
'others': [
15+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'eeeeeee' },
16+
],
17+
},
18+
{
19+
// Aaaaaaa -> Aaaaaaa
20+
'others': [
21+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'fffffff' },
22+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ggggggg' },
23+
],
24+
},
25+
{
26+
// Aaaaaaa -> usize
27+
'others': [],
28+
},
29+
{
30+
// -> Aaaaaaa
31+
'others': [
32+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'fffffff' },
33+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ggggggg' },
34+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ddddddd' },
35+
{ 'path': 'raw_pointer', 'name': 'bbbbbbb' },
36+
],
37+
},
38+
{
39+
// Aaaaaaa
40+
'others': [
41+
{ 'path': 'raw_pointer', 'name': 'Aaaaaaa' },
42+
],
43+
'in_args': [
44+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'fffffff' },
45+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ggggggg' },
46+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'eeeeeee' },
47+
],
48+
'returned': [
49+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'fffffff' },
50+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ggggggg' },
51+
{ 'path': 'raw_pointer::Ccccccc', 'name': 'ddddddd' },
52+
{ 'path': 'raw_pointer', 'name': 'bbbbbbb' },
53+
],
54+
},
55+
];

‎src/test/rustdoc-js/raw-pointer.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::ptr;
2+
3+
pub struct Aaaaaaa {}
4+
5+
pub fn bbbbbbb() -> *const Aaaaaaa {
6+
ptr::null()
7+
}
8+
9+
pub struct Ccccccc {}
10+
11+
impl Ccccccc {
12+
pub fn ddddddd(&self) -> *const Aaaaaaa {
13+
ptr::null()
14+
}
15+
pub fn eeeeeee(&self, _x: *const Aaaaaaa) -> i32 {
16+
0
17+
}
18+
pub fn fffffff(&self, x: *const Aaaaaaa) -> *const Aaaaaaa {
19+
x
20+
}
21+
pub fn ggggggg(&self, x: *mut Aaaaaaa) -> *mut Aaaaaaa {
22+
x
23+
}
24+
}

‎src/test/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0433]: failed to resolve: maybe a missing crate `unresolved_crate`?
33
|
44
LL | use unresolved_crate::module::Name;
55
| ^^^^^^^^^^^^^^^^ maybe a missing crate `unresolved_crate`?
6+
|
7+
= help: consider adding `extern crate unresolved_crate` to use the `unresolved_crate` crate
68

79
error: Compilation failed, aborting rustdoc
810

‎src/test/rustdoc-ui/issue-61732.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0433]: failed to resolve: maybe a missing crate `r#mod`?
33
|
44
LL | pub(in crate::r#mod) fn main() {}
55
| ^^^^^ maybe a missing crate `r#mod`?
6+
|
7+
= help: consider adding `extern crate r#mod` to use the `r#mod` crate
68

79
error: Compilation failed, aborting rustdoc
810

‎src/test/ui/attributes/field-attributes-vis-unresolved.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0433]: failed to resolve: maybe a missing crate `nonexistent`?
33
|
44
LL | pub(in nonexistent) field: u8
55
| ^^^^^^^^^^^ maybe a missing crate `nonexistent`?
6+
|
7+
= help: consider adding `extern crate nonexistent` to use the `nonexistent` crate
68

79
error[E0433]: failed to resolve: maybe a missing crate `nonexistent`?
810
--> $DIR/field-attributes-vis-unresolved.rs:22:12
911
|
1012
LL | pub(in nonexistent) u8
1113
| ^^^^^^^^^^^ maybe a missing crate `nonexistent`?
14+
|
15+
= help: consider adding `extern crate nonexistent` to use the `nonexistent` crate
1216

1317
error: aborting due to 2 previous errors
1418

‎src/test/ui/error-codes/E0432.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `something`
33
|
44
LL | use something::Foo;
55
| ^^^^^^^^^ maybe a missing crate `something`?
6+
|
7+
= help: consider adding `extern crate something` to use the `something` crate
68

79
error: aborting due to previous error
810

‎src/test/ui/feature-gates/feature-gate-extern_absolute_paths.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0432]: unresolved import `core`
33
|
44
LL | use core::default;
55
| ^^^^ maybe a missing crate `core`?
6+
|
7+
= help: consider adding `extern crate core` to use the `core` crate
68

79
error[E0433]: failed to resolve: maybe a missing crate `core`?
810
--> $DIR/feature-gate-extern_absolute_paths.rs:4:19
911
|
1012
LL | let _: u8 = ::core::default::Default();
1113
| ^^^^ maybe a missing crate `core`?
14+
|
15+
= help: consider adding `extern crate core` to use the `core` crate
1216

1317
error: aborting due to 2 previous errors
1418

‎src/test/ui/imports/import3.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `main`
33
|
44
LL | use main::bar;
55
| ^^^^ maybe a missing crate `main`?
6+
|
7+
= help: consider adding `extern crate main` to use the `main` crate
68

79
error: aborting due to previous error
810

‎src/test/ui/imports/issue-1697.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `unresolved`
33
|
44
LL | use unresolved::*;
55
| ^^^^^^^^^^ maybe a missing crate `unresolved`?
6+
|
7+
= help: consider adding `extern crate unresolved` to use the `unresolved` crate
68

79
error: aborting due to previous error
810

‎src/test/ui/imports/issue-33464.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ error[E0432]: unresolved import `abc`
33
|
44
LL | use abc::one_el;
55
| ^^^ maybe a missing crate `abc`?
6+
|
7+
= help: consider adding `extern crate abc` to use the `abc` crate
68

79
error[E0432]: unresolved import `abc`
810
--> $DIR/issue-33464.rs:5:5
911
|
1012
LL | use abc::{a, bbb, cccccc};
1113
| ^^^ maybe a missing crate `abc`?
14+
|
15+
= help: consider adding `extern crate abc` to use the `abc` crate
1216

1317
error[E0432]: unresolved import `a_very_long_name`
1418
--> $DIR/issue-33464.rs:7:5
1519
|
1620
LL | use a_very_long_name::{el, el2};
1721
| ^^^^^^^^^^^^^^^^ maybe a missing crate `a_very_long_name`?
22+
|
23+
= help: consider adding `extern crate a_very_long_name` to use the `a_very_long_name` crate
1824

1925
error: aborting due to 3 previous errors
2026

‎src/test/ui/imports/issue-36881.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `issue_36881_aux`
33
|
44
LL | use issue_36881_aux::Foo;
55
| ^^^^^^^^^^^^^^^ maybe a missing crate `issue_36881_aux`?
6+
|
7+
= help: consider adding `extern crate issue_36881_aux` to use the `issue_36881_aux` crate
68

79
error: aborting due to previous error
810

‎src/test/ui/imports/issue-37887.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `libc`
33
|
44
LL | use libc::*;
55
| ^^^^ maybe a missing crate `libc`?
6+
|
7+
= help: consider adding `extern crate libc` to use the `libc` crate
68

79
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
810
--> $DIR/issue-37887.rs:2:5

‎src/test/ui/imports/issue-53269.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `nonexistent_module`
33
|
44
LL | use nonexistent_module::mac;
55
| ^^^^^^^^^^^^^^^^^^ maybe a missing crate `nonexistent_module`?
6+
|
7+
= help: consider adding `extern crate nonexistent_module` to use the `nonexistent_module` crate
68

79
error[E0659]: `mac` is ambiguous
810
--> $DIR/issue-53269.rs:8:5

‎src/test/ui/imports/issue-55457.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ error[E0432]: unresolved import `non_existent`
1212
|
1313
LL | use non_existent::non_existent;
1414
| ^^^^^^^^^^^^ maybe a missing crate `non_existent`?
15+
|
16+
= help: consider adding `extern crate non_existent` to use the `non_existent` crate
1517

1618
error: cannot determine resolution for the derive macro `NonExistent`
1719
--> $DIR/issue-55457.rs:5:10

‎src/test/ui/imports/tool-mod-child.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@ error[E0433]: failed to resolve: maybe a missing crate `clippy`?
33
|
44
LL | use clippy::a::b;
55
| ^^^^^^ maybe a missing crate `clippy`?
6+
|
7+
= help: consider adding `extern crate clippy` to use the `clippy` crate
68

79
error[E0432]: unresolved import `clippy`
810
--> $DIR/tool-mod-child.rs:1:5
911
|
1012
LL | use clippy::a;
1113
| ^^^^^^ maybe a missing crate `clippy`?
14+
|
15+
= help: consider adding `extern crate clippy` to use the `clippy` crate
1216

1317
error[E0433]: failed to resolve: maybe a missing crate `rustdoc`?
1418
--> $DIR/tool-mod-child.rs:5:5
1519
|
1620
LL | use rustdoc::a::b;
1721
| ^^^^^^^ maybe a missing crate `rustdoc`?
22+
|
23+
= help: consider adding `extern crate rustdoc` to use the `rustdoc` crate
1824

1925
error[E0432]: unresolved import `rustdoc`
2026
--> $DIR/tool-mod-child.rs:4:5
2127
|
2228
LL | use rustdoc::a;
2329
| ^^^^^^^ maybe a missing crate `rustdoc`?
30+
|
31+
= help: consider adding `extern crate rustdoc` to use the `rustdoc` crate
2432

2533
error: aborting due to 4 previous errors
2634

‎src/test/ui/imports/unresolved-imports-used.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,32 @@ error[E0432]: unresolved import `foo`
1515
|
1616
LL | use foo::bar;
1717
| ^^^ maybe a missing crate `foo`?
18+
|
19+
= help: consider adding `extern crate foo` to use the `foo` crate
1820

1921
error[E0432]: unresolved import `baz`
2022
--> $DIR/unresolved-imports-used.rs:12:5
2123
|
2224
LL | use baz::*;
2325
| ^^^ maybe a missing crate `baz`?
26+
|
27+
= help: consider adding `extern crate baz` to use the `baz` crate
2428

2529
error[E0432]: unresolved import `foo2`
2630
--> $DIR/unresolved-imports-used.rs:14:5
2731
|
2832
LL | use foo2::bar2;
2933
| ^^^^ maybe a missing crate `foo2`?
34+
|
35+
= help: consider adding `extern crate foo2` to use the `foo2` crate
3036

3137
error[E0432]: unresolved import `baz2`
3238
--> $DIR/unresolved-imports-used.rs:15:5
3339
|
3440
LL | use baz2::*;
3541
| ^^^^ maybe a missing crate `baz2`?
42+
|
43+
= help: consider adding `extern crate baz2` to use the `baz2` crate
3644

3745
error[E0603]: function `quz` is private
3846
--> $DIR/unresolved-imports-used.rs:9:10

‎src/test/ui/keyword/extern/keyword-extern-as-identifier-use.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ error[E0432]: unresolved import `r#extern`
1414
|
1515
LL | use extern::foo;
1616
| ^^^^^^ maybe a missing crate `r#extern`?
17+
|
18+
= help: consider adding `extern crate r#extern` to use the `r#extern` crate
1719

1820
error: aborting due to 2 previous errors
1921

‎src/test/ui/privacy/restricted/test.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0433]: failed to resolve: maybe a missing crate `bad`?
33
|
44
LL | pub(in bad::path) mod m1 {}
55
| ^^^ maybe a missing crate `bad`?
6+
|
7+
= help: consider adding `extern crate bad` to use the `bad` crate
68

79
error[E0742]: visibilities can only be restricted to ancestor modules
810
--> $DIR/test.rs:51:12

‎src/test/ui/resolve/editions-crate-root-2015.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
33
|
44
LL | fn global_inner(_: ::nonexistant::Foo) {
55
| ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
6+
|
7+
= help: consider adding `extern crate nonexistant` to use the `nonexistant` crate
68

79
error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
810
--> $DIR/editions-crate-root-2015.rs:7:30
911
|
1012
LL | fn crate_inner(_: crate::nonexistant::Foo) {
1113
| ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
14+
|
15+
= help: consider adding `extern crate nonexistant` to use the `nonexistant` crate
1216

1317
error[E0412]: cannot find type `nonexistant` in the crate root
1418
--> $DIR/editions-crate-root-2015.rs:11:25

‎src/test/ui/resolve/extern-prelude-fail.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0432]: unresolved import `extern_prelude`
33
|
44
LL | use extern_prelude::S;
55
| ^^^^^^^^^^^^^^ maybe a missing crate `extern_prelude`?
6+
|
7+
= help: consider adding `extern crate extern_prelude` to use the `extern_prelude` crate
68

79
error[E0433]: failed to resolve: maybe a missing crate `extern_prelude`?
810
--> $DIR/extern-prelude-fail.rs:8:15
911
|
1012
LL | let s = ::extern_prelude::S;
1113
| ^^^^^^^^^^^^^^ maybe a missing crate `extern_prelude`?
14+
|
15+
= help: consider adding `extern crate extern_prelude` to use the `extern_prelude` crate
1216

1317
error: aborting due to 2 previous errors
1418

‎src/test/ui/resolve/issue-82865.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0433]: failed to resolve: maybe a missing crate `x`?
33
|
44
LL | use x::y::z;
55
| ^ maybe a missing crate `x`?
6+
|
7+
= help: consider adding `extern crate x` to use the `x` crate
68

79
error[E0599]: no function or associated item named `z` found for struct `Box<_, _>` in the current scope
810
--> $DIR/issue-82865.rs:8:10

‎src/test/ui/resolve/resolve-bad-visibility.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ error[E0433]: failed to resolve: maybe a missing crate `nonexistent`?
2121
|
2222
LL | pub(in nonexistent) struct G;
2323
| ^^^^^^^^^^^ maybe a missing crate `nonexistent`?
24+
|
25+
= help: consider adding `extern crate nonexistent` to use the `nonexistent` crate
2426

2527
error[E0433]: failed to resolve: maybe a missing crate `too_soon`?
2628
--> $DIR/resolve-bad-visibility.rs:8:8
2729
|
2830
LL | pub(in too_soon) struct H;
2931
| ^^^^^^^^ maybe a missing crate `too_soon`?
32+
|
33+
= help: consider adding `extern crate too_soon` to use the `too_soon` crate
3034

3135
error: aborting due to 5 previous errors
3236

‎src/test/ui/simd/portable-intrinsics-arent-exposed.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0433]: failed to resolve: maybe a missing crate `core`?
33
|
44
LL | use core::simd::intrinsics;
55
| ^^^^ maybe a missing crate `core`?
6+
|
7+
= help: consider adding `extern crate core` to use the `core` crate
68

79
error[E0432]: unresolved import `std::simd::intrinsics`
810
--> $DIR/portable-intrinsics-arent-exposed.rs:5:5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// compile-flags: --edition=2021
2+
// run-rustfix
3+
4+
#![allow(unused)]
5+
6+
struct Foo;
7+
8+
impl Foo {
9+
fn get(&self) -> u8 {
10+
42
11+
}
12+
}
13+
14+
fn test_result_in_result() -> Result<(), ()> {
15+
let res: Result<_, ()> = Ok(Foo);
16+
res?.get();
17+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
18+
//~| HELP use the `?` operator
19+
Ok(())
20+
}
21+
22+
async fn async_test_result_in_result() -> Result<(), ()> {
23+
let res: Result<_, ()> = Ok(Foo);
24+
res?.get();
25+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
26+
//~| HELP use the `?` operator
27+
Ok(())
28+
}
29+
30+
fn test_result_in_unit_return() {
31+
let res: Result<_, ()> = Ok(Foo);
32+
res.expect("REASON").get();
33+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
34+
//~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
35+
}
36+
37+
async fn async_test_result_in_unit_return() {
38+
let res: Result<_, ()> = Ok(Foo);
39+
res.expect("REASON").get();
40+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
41+
//~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
42+
}
43+
44+
fn test_option_in_option() -> Option<()> {
45+
let res: Option<_> = Some(Foo);
46+
res?.get();
47+
//~^ ERROR no method named `get` found for enum `Option` in the current scope
48+
//~| HELP use the `?` operator
49+
Some(())
50+
}
51+
52+
fn test_option_in_unit_return() {
53+
let res: Option<_> = Some(Foo);
54+
res.expect("REASON").get();
55+
//~^ ERROR no method named `get` found for enum `Option` in the current scope
56+
//~| HELP consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
57+
}
58+
59+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// compile-flags: --edition=2021
2+
// run-rustfix
3+
4+
#![allow(unused)]
5+
6+
struct Foo;
7+
8+
impl Foo {
9+
fn get(&self) -> u8 {
10+
42
11+
}
12+
}
13+
14+
fn test_result_in_result() -> Result<(), ()> {
15+
let res: Result<_, ()> = Ok(Foo);
16+
res.get();
17+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
18+
//~| HELP use the `?` operator
19+
Ok(())
20+
}
21+
22+
async fn async_test_result_in_result() -> Result<(), ()> {
23+
let res: Result<_, ()> = Ok(Foo);
24+
res.get();
25+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
26+
//~| HELP use the `?` operator
27+
Ok(())
28+
}
29+
30+
fn test_result_in_unit_return() {
31+
let res: Result<_, ()> = Ok(Foo);
32+
res.get();
33+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
34+
//~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
35+
}
36+
37+
async fn async_test_result_in_unit_return() {
38+
let res: Result<_, ()> = Ok(Foo);
39+
res.get();
40+
//~^ ERROR no method named `get` found for enum `Result` in the current scope
41+
//~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
42+
}
43+
44+
fn test_option_in_option() -> Option<()> {
45+
let res: Option<_> = Some(Foo);
46+
res.get();
47+
//~^ ERROR no method named `get` found for enum `Option` in the current scope
48+
//~| HELP use the `?` operator
49+
Some(())
50+
}
51+
52+
fn test_option_in_unit_return() {
53+
let res: Option<_> = Some(Foo);
54+
res.get();
55+
//~^ ERROR no method named `get` found for enum `Option` in the current scope
56+
//~| HELP consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
57+
}
58+
59+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
error[E0599]: no method named `get` found for enum `Result` in the current scope
2+
--> $DIR/enum-method-probe.rs:24:9
3+
|
4+
LL | res.get();
5+
| ^^^ method not found in `Result<Foo, ()>`
6+
|
7+
note: the method `get` exists on the type `Foo`
8+
--> $DIR/enum-method-probe.rs:9:5
9+
|
10+
LL | fn get(&self) -> u8 {
11+
| ^^^^^^^^^^^^^^^^^^^
12+
help: use the `?` operator to extract the `Foo` value, propagating a `Result::Err` value to the caller
13+
|
14+
LL | res?.get();
15+
| +
16+
17+
error[E0599]: no method named `get` found for enum `Result` in the current scope
18+
--> $DIR/enum-method-probe.rs:39:9
19+
|
20+
LL | res.get();
21+
| ^^^ method not found in `Result<Foo, ()>`
22+
|
23+
note: the method `get` exists on the type `Foo`
24+
--> $DIR/enum-method-probe.rs:9:5
25+
|
26+
LL | fn get(&self) -> u8 {
27+
| ^^^^^^^^^^^^^^^^^^^
28+
help: consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
29+
|
30+
LL | res.expect("REASON").get();
31+
| +++++++++++++++++
32+
33+
error[E0599]: no method named `get` found for enum `Result` in the current scope
34+
--> $DIR/enum-method-probe.rs:16:9
35+
|
36+
LL | res.get();
37+
| ^^^ method not found in `Result<Foo, ()>`
38+
|
39+
note: the method `get` exists on the type `Foo`
40+
--> $DIR/enum-method-probe.rs:9:5
41+
|
42+
LL | fn get(&self) -> u8 {
43+
| ^^^^^^^^^^^^^^^^^^^
44+
help: use the `?` operator to extract the `Foo` value, propagating a `Result::Err` value to the caller
45+
|
46+
LL | res?.get();
47+
| +
48+
49+
error[E0599]: no method named `get` found for enum `Result` in the current scope
50+
--> $DIR/enum-method-probe.rs:32:9
51+
|
52+
LL | res.get();
53+
| ^^^ method not found in `Result<Foo, ()>`
54+
|
55+
note: the method `get` exists on the type `Foo`
56+
--> $DIR/enum-method-probe.rs:9:5
57+
|
58+
LL | fn get(&self) -> u8 {
59+
| ^^^^^^^^^^^^^^^^^^^
60+
help: consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
61+
|
62+
LL | res.expect("REASON").get();
63+
| +++++++++++++++++
64+
65+
error[E0599]: no method named `get` found for enum `Option` in the current scope
66+
--> $DIR/enum-method-probe.rs:46:9
67+
|
68+
LL | res.get();
69+
| ^^^ method not found in `Option<Foo>`
70+
|
71+
note: the method `get` exists on the type `Foo`
72+
--> $DIR/enum-method-probe.rs:9:5
73+
|
74+
LL | fn get(&self) -> u8 {
75+
| ^^^^^^^^^^^^^^^^^^^
76+
help: use the `?` operator to extract the `Foo` value, propagating an `Option::None` value to the caller
77+
|
78+
LL | res?.get();
79+
| +
80+
81+
error[E0599]: no method named `get` found for enum `Option` in the current scope
82+
--> $DIR/enum-method-probe.rs:54:9
83+
|
84+
LL | res.get();
85+
| ^^^ method not found in `Option<Foo>`
86+
|
87+
note: the method `get` exists on the type `Foo`
88+
--> $DIR/enum-method-probe.rs:9:5
89+
|
90+
LL | fn get(&self) -> u8 {
91+
| ^^^^^^^^^^^^^^^^^^^
92+
help: consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
93+
|
94+
LL | res.expect("REASON").get();
95+
| +++++++++++++++++
96+
97+
error: aborting due to 6 previous errors
98+
99+
For more information about this error, try `rustc --explain E0599`.

‎src/test/ui/unresolved/unresolved-asterisk-imports.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0432]: unresolved import `not_existing_crate`
33
|
44
LL | use not_existing_crate::*;
55
| ^^^^^^^^^^^^^^^^^^ maybe a missing crate `not_existing_crate`?
6+
|
7+
= help: consider adding `extern crate not_existing_crate` to use the `not_existing_crate` crate
68

79
error: aborting due to previous error
810

‎src/test/ui/unresolved/unresolved-import.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use foo::bar; //~ ERROR unresolved import `foo` [E0432]
22
//~^ maybe a missing crate `foo`?
3+
//~| HELP consider adding `extern crate foo` to use the `foo` crate
34

45
use bar::Baz as x; //~ ERROR unresolved import `bar::Baz` [E0432]
56
//~| no `Baz` in `bar`

‎src/test/ui/unresolved/unresolved-import.stderr

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ error[E0432]: unresolved import `foo`
33
|
44
LL | use foo::bar;
55
| ^^^ maybe a missing crate `foo`?
6+
|
7+
= help: consider adding `extern crate foo` to use the `foo` crate
68

79
error[E0432]: unresolved import `bar::Baz`
8-
--> $DIR/unresolved-import.rs:4:5
10+
--> $DIR/unresolved-import.rs:5:5
911
|
1012
LL | use bar::Baz as x;
1113
| ^^^^^---^^^^^
@@ -14,7 +16,7 @@ LL | use bar::Baz as x;
1416
| no `Baz` in `bar`
1517

1618
error[E0432]: unresolved import `food::baz`
17-
--> $DIR/unresolved-import.rs:9:5
19+
--> $DIR/unresolved-import.rs:10:5
1820
|
1921
LL | use food::baz;
2022
| ^^^^^^---
@@ -23,7 +25,7 @@ LL | use food::baz;
2325
| no `baz` in `food`
2426

2527
error[E0432]: unresolved import `food::beens`
26-
--> $DIR/unresolved-import.rs:14:12
28+
--> $DIR/unresolved-import.rs:15:12
2729
|
2830
LL | use food::{beens as Foo};
2931
| -----^^^^^^^
@@ -32,13 +34,13 @@ LL | use food::{beens as Foo};
3234
| help: a similar name exists in the module: `beans`
3335

3436
error[E0432]: unresolved import `MyEnum`
35-
--> $DIR/unresolved-import.rs:38:9
37+
--> $DIR/unresolved-import.rs:39:9
3638
|
3739
LL | use MyEnum::*;
3840
| ^^^^^^ help: a similar path exists: `self::MyEnum`
3941

4042
error[E0432]: unresolved import `Enum`
41-
--> $DIR/unresolved-import.rs:48:9
43+
--> $DIR/unresolved-import.rs:49:9
4244
|
4345
LL | use Enum::*;
4446
| ^^^^ help: a similar path exists: `self::Enum`

‎src/tools/miri

Submodule miri updated 84 files

0 commit comments

Comments
 (0)
Please sign in to comment.