Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//! Diagnostic emitted for files that aren't part of any crate.

use hir::db::DefDatabase;
use ide_db::{
    base_db::{FileId, FileLoader, SourceDatabase, SourceDatabaseExt},
    source_change::SourceChange,
    RootDatabase,
};
use syntax::{
    ast::{self, HasModuleItem, HasName},
    AstNode, TextRange, TextSize,
};
use text_edit::TextEdit;

use crate::{fix, Assist, Diagnostic, DiagnosticsContext, Severity};

// Diagnostic: unlinked-file
//
// This diagnostic is shown for files that are not included in any crate, or files that are part of
// crates rust-analyzer failed to discover. The file will not have IDE features available.
pub(crate) fn unlinked_file(
    ctx: &DiagnosticsContext<'_>,
    acc: &mut Vec<Diagnostic>,
    file_id: FileId,
) {
    // Limit diagnostic to the first few characters in the file. This matches how VS Code
    // renders it with the full span, but on other editors, and is less invasive.
    let range = ctx.sema.db.parse(file_id).syntax_node().text_range();
    // FIXME: This is wrong if one of the first three characters is not ascii: `//Ы`.
    let range = range.intersect(TextRange::up_to(TextSize::of("..."))).unwrap_or(range);

    acc.push(
        Diagnostic::new("unlinked-file", "file not included in module tree", range)
            .severity(Severity::WeakWarning)
            .with_fixes(fixes(ctx, file_id)),
    );
}

fn fixes(ctx: &DiagnosticsContext<'_>, file_id: FileId) -> Option<Vec<Assist>> {
    // If there's an existing module that could add `mod` or `pub mod` items to include the unlinked file,
    // suggest that as a fix.

    let source_root = ctx.sema.db.source_root(ctx.sema.db.file_source_root(file_id));
    let our_path = source_root.path_for_file(&file_id)?;
    let (mut module_name, _) = our_path.name_and_extension()?;

    // Candidates to look for:
    // - `mod.rs`, `main.rs` and `lib.rs` in the same folder
    // - `$dir.rs` in the parent folder, where `$dir` is the directory containing `self.file_id`
    let parent = our_path.parent()?;
    let paths = {
        let parent = if module_name == "mod" {
            // for mod.rs we need to actually look up one higher
            // and take the parent as our to be module name
            let (name, _) = parent.name_and_extension()?;
            module_name = name;
            parent.parent()?
        } else {
            parent
        };
        let mut paths =
            vec![parent.join("mod.rs")?, parent.join("lib.rs")?, parent.join("main.rs")?];

        // `submod/bla.rs` -> `submod.rs`
        let parent_mod = (|| {
            let (name, _) = parent.name_and_extension()?;
            parent.parent()?.join(&format!("{}.rs", name))
        })();
        paths.extend(parent_mod);
        paths
    };

    for &parent_id in paths.iter().filter_map(|path| source_root.file_for_path(path)) {
        for &krate in ctx.sema.db.relevant_crates(parent_id).iter() {
            let crate_def_map = ctx.sema.db.crate_def_map(krate);
            for (_, module) in crate_def_map.modules() {
                if module.origin.is_inline() {
                    // We don't handle inline `mod parent {}`s, they use different paths.
                    continue;
                }

                if module.origin.file_id() == Some(parent_id) {
                    return make_fixes(ctx.sema.db, parent_id, module_name, file_id);
                }
            }
        }
    }

    None
}

fn make_fixes(
    db: &RootDatabase,
    parent_file_id: FileId,
    new_mod_name: &str,
    added_file_id: FileId,
) -> Option<Vec<Assist>> {
    fn is_outline_mod(item: &ast::Item) -> bool {
        matches!(item, ast::Item::Module(m) if m.item_list().is_none())
    }

    let mod_decl = format!("mod {};", new_mod_name);
    let pub_mod_decl = format!("pub mod {};", new_mod_name);

    let ast: ast::SourceFile = db.parse(parent_file_id).tree();

    let mut mod_decl_builder = TextEdit::builder();
    let mut pub_mod_decl_builder = TextEdit::builder();

    // If there's an existing `mod m;` statement matching the new one, don't emit a fix (it's
    // probably `#[cfg]`d out).
    for item in ast.items() {
        if let ast::Item::Module(m) = item {
            if let Some(name) = m.name() {
                if m.item_list().is_none() && name.to_string() == new_mod_name {
                    cov_mark::hit!(unlinked_file_skip_fix_when_mod_already_exists);
                    return None;
                }
            }
        }
    }

    // If there are existing `mod m;` items, append after them (after the first group of them, rather).
    match ast.items().skip_while(|item| !is_outline_mod(item)).take_while(is_outline_mod).last() {
        Some(last) => {
            cov_mark::hit!(unlinked_file_append_to_existing_mods);
            let offset = last.syntax().text_range().end();
            mod_decl_builder.insert(offset, format!("\n{}", mod_decl));
            pub_mod_decl_builder.insert(offset, format!("\n{}", pub_mod_decl));
        }
        None => {
            // Prepend before the first item in the file.
            match ast.items().next() {
                Some(item) => {
                    cov_mark::hit!(unlinked_file_prepend_before_first_item);
                    let offset = item.syntax().text_range().start();
                    mod_decl_builder.insert(offset, format!("{}\n\n", mod_decl));
                    pub_mod_decl_builder.insert(offset, format!("{}\n\n", pub_mod_decl));
                }
                None => {
                    // No items in the file, so just append at the end.
                    cov_mark::hit!(unlinked_file_empty_file);
                    let offset = ast.syntax().text_range().end();
                    mod_decl_builder.insert(offset, format!("{}\n", mod_decl));
                    pub_mod_decl_builder.insert(offset, format!("{}\n", pub_mod_decl));
                }
            }
        }
    }

    let trigger_range = db.parse(added_file_id).tree().syntax().text_range();
    Some(vec![
        fix(
            "add_mod_declaration",
            &format!("Insert `{}`", mod_decl),
            SourceChange::from_text_edit(parent_file_id, mod_decl_builder.finish()),
            trigger_range,
        ),
        fix(
            "add_pub_mod_declaration",
            &format!("Insert `{}`", pub_mod_decl),
            SourceChange::from_text_edit(parent_file_id, pub_mod_decl_builder.finish()),
            trigger_range,
        ),
    ])
}

#[cfg(test)]
mod tests {

    use crate::tests::{check_diagnostics, check_fix, check_fixes, check_no_fix};

    #[test]
    fn unlinked_file_prepend_first_item() {
        cov_mark::check!(unlinked_file_prepend_before_first_item);
        // Only tests the first one for `pub mod` since the rest are the same
        check_fixes(
            r#"
//- /main.rs
fn f() {}
//- /foo.rs
$0
"#,
            vec![
                r#"
mod foo;

fn f() {}
"#,
                r#"
pub mod foo;

fn f() {}
"#,
            ],
        );
    }

    #[test]
    fn unlinked_file_append_mod() {
        cov_mark::check!(unlinked_file_append_to_existing_mods);
        check_fix(
            r#"
//- /main.rs
//! Comment on top

mod preexisting;

mod preexisting2;

struct S;

mod preexisting_bottom;)
//- /foo.rs
$0
"#,
            r#"
//! Comment on top

mod preexisting;

mod preexisting2;
mod foo;

struct S;

mod preexisting_bottom;)
"#,
        );
    }

    #[test]
    fn unlinked_file_insert_in_empty_file() {
        cov_mark::check!(unlinked_file_empty_file);
        check_fix(
            r#"
//- /main.rs
//- /foo.rs
$0
"#,
            r#"
mod foo;
"#,
        );
    }

    #[test]
    fn unlinked_file_insert_in_empty_file_mod_file() {
        check_fix(
            r#"
//- /main.rs
//- /foo/mod.rs
$0
"#,
            r#"
mod foo;
"#,
        );
        check_fix(
            r#"
//- /main.rs
mod bar;
//- /bar.rs
// bar module
//- /bar/foo/mod.rs
$0
"#,
            r#"
// bar module
mod foo;
"#,
        );
    }

    #[test]
    fn unlinked_file_old_style_modrs() {
        check_fix(
            r#"
//- /main.rs
mod submod;
//- /submod/mod.rs
// in mod.rs
//- /submod/foo.rs
$0
"#,
            r#"
// in mod.rs
mod foo;
"#,
        );
    }

    #[test]
    fn unlinked_file_new_style_mod() {
        check_fix(
            r#"
//- /main.rs
mod submod;
//- /submod.rs
//- /submod/foo.rs
$0
"#,
            r#"
mod foo;
"#,
        );
    }

    #[test]
    fn unlinked_file_with_cfg_off() {
        cov_mark::check!(unlinked_file_skip_fix_when_mod_already_exists);
        check_no_fix(
            r#"
//- /main.rs
#[cfg(never)]
mod foo;

//- /foo.rs
$0
"#,
        );
    }

    #[test]
    fn unlinked_file_with_cfg_on() {
        check_diagnostics(
            r#"
//- /main.rs
#[cfg(not(never))]
mod foo;

//- /foo.rs
"#,
        );
    }
}
th.qualifier()?; let name_ref = path.segment()?.name_ref()?; let qualifier_res = ctx.sema.resolve_path(&qualifier)?; let PathResolution::Def(ModuleDef::Module(module)) = qualifier_res else { return None; }; let (_, def) = module .scope(ctx.db(), None) .into_iter() .find(|(name, _)| name.as_str() == name_ref.text().trim_start_matches("r#"))?; let ScopeDef::ModuleDef(def) = def else { return None; }; let current_module = ctx.sema.scope(path.syntax())?.module(); let target_module = def.module(ctx.db())?; if def.visibility(ctx.db()).is_visible_from(ctx.db(), current_module.into()) { return None; }; let (vis_owner, target, target_file, target_name) = target_data_for_def(ctx.db(), def)?; let missing_visibility = if current_module.krate() == target_module.krate() { make::visibility_pub_crate() } else { make::visibility_pub() }; let assist_label = match target_name { None => format!("Change visibility to {missing_visibility}"), Some(name) => { format!( "Change visibility of {} to {missing_visibility}", name.display(ctx.db(), current_module.krate().edition(ctx.db())) ) } }; acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |edit| { edit.edit_file(target_file); let vis_owner = edit.make_mut(vis_owner); vis_owner.set_visibility(Some(missing_visibility.clone_for_update())); if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) { edit.add_tabstop_before(cap, vis); } }) } fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let record_field: ast::RecordExprField = ctx.find_node_at_offset()?; let (record_field_def, _, _) = ctx.sema.resolve_record_field(&record_field)?; let current_module = ctx.sema.scope(record_field.syntax())?.module(); let current_edition = current_module.krate().edition(ctx.db()); let visibility = record_field_def.visibility(ctx.db()); if visibility.is_visible_from(ctx.db(), current_module.into()) { return None; } let parent = record_field_def.parent_def(ctx.db()); let parent_name = parent.name(ctx.db()); let target_module = parent.module(ctx.db()); let in_file_source = record_field_def.source(ctx.db())?; let (vis_owner, target) = match in_file_source.value { hir::FieldSource::Named(it) => { let range = it.syntax().text_range(); (ast::AnyHasVisibility::new(it), range) } hir::FieldSource::Pos(it) => { let range = it.syntax().text_range(); (ast::AnyHasVisibility::new(it), range) } }; let missing_visibility = if current_module.krate() == target_module.krate() { make::visibility_pub_crate() } else { make::visibility_pub() }; let target_file = in_file_source.file_id.original_file(ctx.db()); let target_name = record_field_def.name(ctx.db()); let assist_label = format!( "Change visibility of {}.{} to {missing_visibility}", parent_name.display(ctx.db(), current_edition), target_name.display(ctx.db(), current_edition) ); acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |edit| { edit.edit_file(target_file.file_id()); let vis_owner = edit.make_mut(vis_owner); vis_owner.set_visibility(Some(missing_visibility.clone_for_update())); if let Some((cap, vis)) = ctx.config.snippet_cap.zip(vis_owner.visibility()) { edit.add_tabstop_before(cap, vis); } }) } fn target_data_for_def( db: &dyn HirDatabase, def: hir::ModuleDef, ) -> Option<(ast::AnyHasVisibility, TextRange, FileId, Option<hir::Name>)> { fn offset_target_and_file_id<S, Ast>( db: &dyn HirDatabase, x: S, ) -> Option<(ast::AnyHasVisibility, TextRange, FileId)> where S: HasSource<Ast = Ast>, Ast: AstNode + ast::HasVisibility, { let source = x.source(db)?; let in_file_syntax = source.syntax(); let file_id = in_file_syntax.file_id; let range = in_file_syntax.value.text_range(); Some(( ast::AnyHasVisibility::new(source.value), range, file_id.original_file(db.upcast()).file_id(), )) } let target_name; let (offset, target, target_file) = match def { hir::ModuleDef::Function(f) => { target_name = Some(f.name(db)); offset_target_and_file_id(db, f)? } hir::ModuleDef::Adt(adt) => { target_name = Some(adt.name(db)); match adt { hir::Adt::Struct(s) => offset_target_and_file_id(db, s)?, hir::Adt::Union(u) => offset_target_and_file_id(db, u)?, hir::Adt::Enum(e) => offset_target_and_file_id(db, e)?, } } hir::ModuleDef::Const(c) => { target_name = c.name(db); offset_target_and_file_id(db, c)? } hir::ModuleDef::Static(s) => { target_name = Some(s.name(db)); offset_target_and_file_id(db, s)? } hir::ModuleDef::Trait(t) => { target_name = Some(t.name(db)); offset_target_and_file_id(db, t)? } hir::ModuleDef::TraitAlias(t) => { target_name = Some(t.name(db)); offset_target_and_file_id(db, t)? } hir::ModuleDef::TypeAlias(t) => { target_name = Some(t.name(db)); offset_target_and_file_id(db, t)? } hir::ModuleDef::Module(m) => { target_name = m.name(db); let in_file_source = m.declaration_source(db)?; let file_id = in_file_source.file_id.original_file(db.upcast()); let range = in_file_source.value.syntax().text_range(); (ast::AnyHasVisibility::new(in_file_source.value), range, file_id.file_id()) } // FIXME hir::ModuleDef::Macro(_) => return None, // Enum variants can't be private, we can't modify builtin types hir::ModuleDef::Variant(_) | hir::ModuleDef::BuiltinType(_) => return None, }; Some((offset, target, target_file, target_name)) } #[cfg(test)] mod tests { use crate::tests::{check_assist, check_assist_not_applicable}; use super::*; #[test] fn fix_visibility_of_fn() { check_assist( fix_visibility, r"mod foo { fn foo() {} } fn main() { foo::foo$0() } ", r"mod foo { $0pub(crate) fn foo() {} } fn main() { foo::foo() } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub fn foo() {} } fn main() { foo::foo$0() } ", ) } #[test] fn fix_visibility_of_adt_in_submodule() { check_assist( fix_visibility, r"mod foo { struct Foo; } fn main() { foo::Foo$0 } ", r"mod foo { $0pub(crate) struct Foo; } fn main() { foo::Foo } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub struct Foo; } fn main() { foo::Foo$0 } ", ); check_assist( fix_visibility, r"mod foo { enum Foo; } fn main() { foo::Foo$0 } ", r"mod foo { $0pub(crate) enum Foo; } fn main() { foo::Foo } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub enum Foo; } fn main() { foo::Foo$0 } ", ); check_assist( fix_visibility, r"mod foo { union Foo; } fn main() { foo::Foo$0 } ", r"mod foo { $0pub(crate) union Foo; } fn main() { foo::Foo } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub union Foo; } fn main() { foo::Foo$0 } ", ); } #[test] fn fix_visibility_of_adt_in_other_file() { check_assist( fix_visibility, r" //- /main.rs mod foo; fn main() { foo::Foo$0 } //- /foo.rs struct Foo; ", r"$0pub(crate) struct Foo; ", ); } #[test] fn fix_visibility_of_struct_field() { check_assist( fix_visibility, r"mod foo { pub struct Foo { bar: (), } } fn main() { foo::Foo { $0bar: () }; } ", r"mod foo { pub struct Foo { $0pub(crate) bar: (), } } fn main() { foo::Foo { bar: () }; } ", ); check_assist( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo { $0bar: () }; } //- /foo.rs pub struct Foo { bar: () } ", r"pub struct Foo { $0pub(crate) bar: () } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub struct Foo { pub bar: (), } } fn main() { foo::Foo { $0bar: () }; } ", ); check_assist_not_applicable( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo { $0bar: () }; } //- /foo.rs pub struct Foo { pub bar: () } ", ); } #[test] fn fix_visibility_of_enum_variant_field() { // Enum variants, as well as their fields, always get the enum's visibility. In fact, rustc // rejects any visibility specifiers on them, so this assist should never fire on them. check_assist_not_applicable( fix_visibility, r"mod foo { pub enum Foo { Bar { bar: () } } } fn main() { foo::Foo::Bar { $0bar: () }; } ", ); check_assist_not_applicable( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo::Bar { $0bar: () }; } //- /foo.rs pub enum Foo { Bar { bar: () } } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub struct Foo { pub bar: (), } } fn main() { foo::Foo { $0bar: () }; } ", ); check_assist_not_applicable( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo { $0bar: () }; } //- /foo.rs pub struct Foo { pub bar: () } ", ); } #[test] fn fix_visibility_of_union_field() { check_assist( fix_visibility, r"mod foo { pub union Foo { bar: (), } } fn main() { foo::Foo { $0bar: () }; } ", r"mod foo { pub union Foo { $0pub(crate) bar: (), } } fn main() { foo::Foo { bar: () }; } ", ); check_assist( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo { $0bar: () }; } //- /foo.rs pub union Foo { bar: () } ", r"pub union Foo { $0pub(crate) bar: () } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub union Foo { pub bar: (), } } fn main() { foo::Foo { $0bar: () }; } ", ); check_assist_not_applicable( fix_visibility, r" //- /lib.rs mod foo; fn main() { foo::Foo { $0bar: () }; } //- /foo.rs pub union Foo { pub bar: () } ", ); } #[test] fn fix_visibility_of_const() { check_assist( fix_visibility, r"mod foo { const FOO: () = (); } fn main() { foo::FOO$0 } ", r"mod foo { $0pub(crate) const FOO: () = (); } fn main() { foo::FOO } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub const FOO: () = (); } fn main() { foo::FOO$0 } ", ); } #[test] fn fix_visibility_of_static() { check_assist( fix_visibility, r"mod foo { static FOO: () = (); } fn main() { foo::FOO$0 } ", r"mod foo { $0pub(crate) static FOO: () = (); } fn main() { foo::FOO } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub static FOO: () = (); } fn main() { foo::FOO$0 } ", ); } #[test] fn fix_visibility_of_trait() { check_assist( fix_visibility, r"mod foo { trait Foo { fn foo(&self) {} } } fn main() { let x: &dyn foo::$0Foo; } ", r"mod foo { $0pub(crate) trait Foo { fn foo(&self) {} } } fn main() { let x: &dyn foo::Foo; } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub trait Foo { fn foo(&self) {} } } fn main() { let x: &dyn foo::Foo$0; } ", ); } #[test] fn fix_visibility_of_type_alias() { check_assist( fix_visibility, r"mod foo { type Foo = (); } fn main() { let x: foo::Foo$0; } ", r"mod foo { $0pub(crate) type Foo = (); } fn main() { let x: foo::Foo; } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub type Foo = (); } fn main() { let x: foo::Foo$0; } ", ); } #[test] fn fix_visibility_of_module() { check_assist( fix_visibility, r"mod foo { mod bar { fn bar() {} } } fn main() { foo::bar$0::bar(); } ", r"mod foo { $0pub(crate) mod bar { fn bar() {} } } fn main() { foo::bar::bar(); } ", ); check_assist( fix_visibility, r" //- /main.rs mod foo; fn main() { foo::bar$0::baz(); } //- /foo.rs mod bar { pub fn baz() {} } ", r"$0pub(crate) mod bar { pub fn baz() {} } ", ); check_assist_not_applicable( fix_visibility, r"mod foo { pub mod bar { pub fn bar() {} } } fn main() { foo::bar$0::bar(); } ", ); } #[test] fn fix_visibility_of_inline_module_in_other_file() { check_assist( fix_visibility, r" //- /main.rs mod foo; fn main() { foo::bar$0::baz(); } //- /foo.rs mod bar; //- /foo/bar.rs pub fn baz() {} ", r"$0pub(crate) mod bar; ", ); } #[test] fn fix_visibility_of_module_declaration_in_other_file() { check_assist( fix_visibility, r" //- /main.rs mod foo; fn main() { foo::bar$0>::baz(); } //- /foo.rs mod bar { pub fn baz() {} } ", r"$0pub(crate) mod bar { pub fn baz() {} } ", ); } #[test] fn adds_pub_when_target_is_in_another_crate() { check_assist( fix_visibility, r" //- /main.rs crate:a deps:foo foo::Bar$0 //- /lib.rs crate:foo struct Bar; ", r"$0pub struct Bar; ", ) } #[test] fn replaces_pub_crate_with_pub() { check_assist( fix_visibility, r" //- /main.rs crate:a deps:foo foo::Bar$0 //- /lib.rs crate:foo pub(crate) struct Bar; ", r"$0pub struct Bar; ", ); check_assist( fix_visibility, r" //- /main.rs crate:a deps:foo fn main() { foo::Foo { $0bar: () }; } //- /lib.rs crate:foo pub struct Foo { pub(crate) bar: () } ", r"pub struct Foo { $0pub bar: () } ", ); } #[test] fn fix_visibility_of_reexport() { // FIXME: broken test, this should fix visibility of the re-export // rather than the struct. check_assist( fix_visibility, r#" mod foo { use bar::Baz; mod bar { pub(super) struct Baz; } } foo::Baz$0 "#, r#" mod foo { use bar::Baz; mod bar { $0pub(crate) struct Baz; } } foo::Baz "#, ) } }