Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 19, 2024
1 parent c74121e commit 1d72508
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 40 deletions.
10 changes: 3 additions & 7 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,19 +1391,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
crate_path.push(ast::PathSegment::path_root(rustc_span::DUMMY_SP));
}
crate_path.push(ast::PathSegment::from_ident(ident));
let suggest_imports = self.lookup_import_candidates_from_module(

suggestions.extend(self.lookup_import_candidates_from_module(
lookup_ident,
namespace,
parent_scope,
crate_root,
crate_path,
&filter_fn,
);
for item in suggest_imports {
if suggestions.iter().all(|sugg| sugg.did != item.did) {
suggestions.push(item);
}
}
));
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions tests/run-make/extern-alias/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions tests/run-make/extern-alias/main.rs

This file was deleted.

7 changes: 5 additions & 2 deletions tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ LL | fn f() { my_core::mem::drop(0); }
LL | a!();
| ---- in this macro invocation
|
= help: consider importing this module:
= help: consider importing one of these items:
core::mem
std::mem
= note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared crate or module `my_core`
Expand All @@ -34,10 +35,12 @@ error[E0433]: failed to resolve: use of undeclared crate or module `my_core`
LL | fn f() { my_core::mem::drop(0); }
| ^^^^^^^ use of undeclared crate or module `my_core`
|
help: consider importing this module
help: consider importing one of these items
|
LL + use core::mem;
|
LL + use std::mem;
|
help: if you import `mem`, refer to it directly
|
LL - fn f() { my_core::mem::drop(0); }
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/imports/issue-121168-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ edition: 2018
//@ compile-flags: --extern issue_121168_extern
//@ aux-build: issue-121168-extern.rs

extern crate issue_121168_extern as nice_crate_name;

fn use_foo_from_another_crate_without_importing_it_first() {
//use nice_crate_name::Foo;
let _: Foo<i32> = todo!(); //~ ERROR cannot find type `Foo` in this scope
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/imports/issue-121168-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168-2.rs:9:12
|
LL | let _: Foo<i32> = todo!();
| ^^^ not found in this scope
|
help: consider importing one of these items
|
LL + use crate::nice_crate_name::Foo;
|
LL + use issue_121168_extern::Foo;
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
12 changes: 12 additions & 0 deletions tests/ui/imports/issue-121168-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ edition: 2015
//@ compile-flags: --extern issue_121168_extern
//@ aux-build: issue-121168-extern.rs

extern crate issue_121168_extern as nice_crate_name;

fn use_foo_from_another_crate_without_importing_it_first() {
//use nice_crate_name::Foo;
let _: Foo<i32> = todo!(); //~ ERROR cannot find type `Foo` in this scope
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/imports/issue-121168-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168-3.rs:9:12
|
LL | let _: Foo<i32> = todo!();
| ^^^ not found in this scope
|
help: consider importing this struct
|
LL + use nice_crate_name::Foo;
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
12 changes: 12 additions & 0 deletions tests/ui/imports/issue-121168.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ edition: 2021
//@ compile-flags: --extern issue_121168_extern
//@ aux-build: issue-121168-extern.rs

extern crate issue_121168_extern as nice_crate_name;

fn use_foo_from_another_crate_without_importing_it_first() {
//use nice_crate_name::Foo;
let _: Foo<i32> = todo!(); //~ ERROR cannot find type `Foo` in this scope
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/imports/issue-121168.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168.rs:9:12
|
LL | let _: Foo<i32> = todo!();
| ^^^ not found in this scope
|
help: consider importing one of these items
|
LL + use crate::nice_crate_name::Foo;
|
LL + use issue_121168_extern::Foo;
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
7 changes: 5 additions & 2 deletions tests/ui/imports/issue-56125.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ help: consider importing one of these items instead
|
LL | use ::issue_56125::issue_56125;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | use ::issue_56125::last_segment::issue_56125;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | use ::issue_56125::non_last_segment::non_last_segment::issue_56125;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | use crate::m3::last_segment::issue_56125;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | use crate::m3::non_last_segment::non_last_segment::issue_56125;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and 1 other candidate

error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:6:9
Expand Down
12 changes: 8 additions & 4 deletions tests/ui/mir/issue-106062.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ error[E0573]: expected type, found variant `Ok`
--> $DIR/issue-106062.rs:15:64
|
LL | async fn connection_handler(handler: impl Sized) -> Result<Ok, std::io::Error> {
| ^^
| |
| not a type
| help: try using the variant's enum: `core::result::Result`
| ^^ not a type
|
help: try using the variant's enum
|
LL | async fn connection_handler(handler: impl Sized) -> Result<core::result::Result, std::io::Error> {
| ~~~~~~~~~~~~~~~~~~~~
LL | async fn connection_handler(handler: impl Sized) -> Result<std::result::Result, std::io::Error> {
| ~~~~~~~~~~~~~~~~~~~

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/core-std-import-order-issue-83564.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// For some reason, Rust 2018 or higher is required to reproduce the bug.

fn main() {
//~^ HELP consider importing this type alias
//~^ HELP consider importing one of these items
let _x = NonZeroU32::new(5).unwrap();
//~^ ERROR failed to resolve: use of undeclared type `NonZeroU32`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ error[E0433]: failed to resolve: use of undeclared type `NonZeroU32`
LL | let _x = NonZeroU32::new(5).unwrap();
| ^^^^^^^^^^ use of undeclared type `NonZeroU32`
|
help: consider importing this type alias
help: consider importing one of these items
|
LL + use core::num::NonZeroU32;
|
LL + use std::num::NonZeroU32;
|

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/suggestions/crate-or-module-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ help: there is a crate or module with a similar name
|
LL | bar: std::cell::Cell<bool>
| ~~~
help: consider importing this module
help: consider importing one of these items
|
LL + use core::cell;
|
LL + use std::cell;
|
help: if you import `cell`, refer to it directly
|
LL - bar: st::cell::Cell<bool>
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/suggestions/suggest-tryinto-edition-change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ fn test() {
let _i: i16 = TryFrom::try_from(0_i32).unwrap();
//~^ ERROR failed to resolve: use of undeclared type
//~| NOTE use of undeclared type
//~| NOTE 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
//~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021

let _i: i16 = TryInto::try_into(0_i32).unwrap();
//~^ ERROR failed to resolve: use of undeclared type
//~| NOTE use of undeclared type
//~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021
//~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021

let _v: Vec<_> = FromIterator::from_iter(&[1]);
//~^ ERROR failed to resolve: use of undeclared type
//~| NOTE use of undeclared type
//~| NOTE 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
//~| NOTE 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
}

Expand Down
19 changes: 14 additions & 5 deletions tests/ui/suggestions/suggest-tryinto-edition-change.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,47 @@ LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap();
| ^^^^^^^ use of undeclared type `TryFrom`
|
= note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
help: consider importing this trait
= note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
help: consider importing one of these items
|
LL + use core::convert::TryFrom;
|
LL + use std::convert::TryFrom;
|

error[E0433]: failed to resolve: use of undeclared type `TryInto`
--> $DIR/suggest-tryinto-edition-change.rs:16:19
--> $DIR/suggest-tryinto-edition-change.rs:17:19
|
LL | let _i: i16 = TryInto::try_into(0_i32).unwrap();
| ^^^^^^^ use of undeclared type `TryInto`
|
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
help: consider importing this trait
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
help: consider importing one of these items
|
LL + use core::convert::TryInto;
|
LL + use std::convert::TryInto;
|

error[E0433]: failed to resolve: use of undeclared type `FromIterator`
--> $DIR/suggest-tryinto-edition-change.rs:21:22
--> $DIR/suggest-tryinto-edition-change.rs:23:22
|
LL | let _v: Vec<_> = FromIterator::from_iter(&[1]);
| ^^^^^^^^^^^^ use of undeclared type `FromIterator`
|
= note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
= note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
help: a trait with a similar name exists
|
LL | let _v: Vec<_> = IntoIterator::from_iter(&[1]);
| ~~~~~~~~~~~~
help: consider importing this trait
help: consider importing one of these items
|
LL + use core::iter::FromIterator;
|
LL + use std::iter::FromIterator;
|

error[E0599]: no method named `try_into` found for type `i32` in the current scope
--> $DIR/suggest-tryinto-edition-change.rs:6:25
Expand Down

0 comments on commit 1d72508

Please sign in to comment.