rust/src/test/ui/issues/issue-35675.rs
Dan Aloni fea5ab12c2 Prefer accessible paths in 'use' suggestions
This fixes an issue with the following sample:

    mod foo {
	mod inaccessible {
	    pub struct X;
	}
	pub mod avail {
	    pub struct X;
	}
    }

    fn main() { X; }

Instead of suggesting both `use crate::foo::inaccessible::X;` and `use
crate::foo::avail::X;`, it should only suggest the latter.

It is done by trimming the list of suggestions from inaccessible paths
if accessible paths are present.

Visibility is checked with `is_accessible_from` now instead of being
hard-coded.

-

Some tests fixes are trivial, and others require a bit more explaining,
here are my comments:

src/test/ui/issues/issue-35675.stderr: Only needs to make the enum
public to have the suggestion make sense.

src/test/ui/issues/issue-42944.stderr: Importing the tuple struct won't
help because its constructor is not visible, so the attempted
constructor does not work. In that case, it's better not to suggest it.
The case where the constructor is public is covered in `issue-26545.rs`.
2020-06-21 18:49:39 +03:00

42 lines
927 B
Rust

// these two HELPs are actually in a new line between this line and the `enum Fruit` line
enum Fruit {
Apple(i64),
Orange(i64),
}
fn should_return_fruit() -> Apple {
//~^ ERROR cannot find type `Apple` in this scope
Apple(5)
//~^ ERROR cannot find function, tuple struct or tuple variant `Apple` in this scope
}
fn should_return_fruit_too() -> Fruit::Apple {
//~^ ERROR expected type, found variant `Fruit::Apple`
Apple(5)
//~^ ERROR cannot find function, tuple struct or tuple variant `Apple` in this scope
}
fn foo() -> Ok {
//~^ ERROR expected type, found variant `Ok`
Ok(())
}
fn bar() -> Variant3 {
//~^ ERROR cannot find type `Variant3` in this scope
}
fn qux() -> Some {
//~^ ERROR expected type, found variant `Some`
Some(1)
}
fn main() {}
mod x {
pub enum Enum {
Variant1,
Variant2(),
Variant3(usize),
Variant4 {},
}
}