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 #99562

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4dded23
add `special_module_name` lint
ibraheemdev Mar 1, 2022
c08f460
tidy
ibraheemdev Apr 15, 2022
f479289
move dummy test module to auxiliary directory
ibraheemdev Jun 4, 2022
f7ae92c
std: use futex-based locks on Fuchsia
joboet Jun 30, 2022
0d91b08
std: fix issue with perma-locked mutexes on Fuchsia
joboet Jul 12, 2022
f357926
std: panic instead of deadlocking in mutex implementation on Fuchsia
joboet Jul 18, 2022
110fdb6
Add `PhantomData` marker for dropck to `BTreeMap`
steffahn Jul 18, 2022
c72a77e
owner is not micro (correct typo)
joboet Jul 20, 2022
bd0474d
Fix the stable version of `AsFd for Arc<T>` and `Box<T>`
cuviper Jul 20, 2022
cd3204d
Normalize the arg spans to be within the call span
compiler-errors Jul 20, 2022
5249183
Add regression test for #52304
JohnTitor Jul 21, 2022
7d0a182
orphan check: opaque types are an error
lcnr Jul 21, 2022
84c3fcd
rewrite the orphan check to use a type visitor
lcnr Jul 21, 2022
8ba02f1
remove unused import
joboet Jul 21, 2022
aad5daa
Rollup merge of #94467 - ibraheemdev:master, r=pnkfelix
Dylan-DPC Jul 21, 2022
e159297
Rollup merge of #98707 - joboet:fuchsia_locks, r=m-ou-se
Dylan-DPC Jul 21, 2022
244bc6b
Rollup merge of #99413 - steffahn:btree_dropck, r=m-ou-se
Dylan-DPC Jul 21, 2022
a45a0d6
Rollup merge of #99523 - cuviper:asfd_ptrs-1.64, r=jyn514
Dylan-DPC Jul 21, 2022
55ffd91
Rollup merge of #99526 - compiler-errors:normalize-arg-spans, r=oli-obk
Dylan-DPC Jul 21, 2022
8647fc6
Rollup merge of #99549 - JohnTitor:issue-52304, r=compiler-errors
Dylan-DPC Jul 21, 2022
4fce0a9
Rollup merge of #99552 - lcnr:orphan_check-rework, r=oli-obk
Dylan-DPC Jul 21, 2022
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
74 changes: 74 additions & 0 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3185,3 +3185,77 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
}
}
}

declare_lint! {
/// The `special_module_name` lint detects module
/// declarations for files that have a special meaning.
///
/// ### Example
///
/// ```rust,compile_fail
/// mod lib;
///
/// fn main() {
/// lib::run();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Cargo recognizes `lib.rs` and `main.rs` as the root of a
/// library or binary crate, so declaring them as modules
/// will lead to miscompilation of the crate unless configured
/// explicitly.
///
/// To access a library from a binary target within the same crate,
/// use `your_crate_name::` as the path path instead of `lib::`:
///
/// ```rust,compile_fail
/// // bar/src/lib.rs
/// fn run() {
/// // ...
/// }
///
/// // bar/src/main.rs
/// fn main() {
/// bar::run();
/// }
/// ```
///
/// Binary targets cannot be used as libraries and so declaring
/// one as a module is not allowed.
pub SPECIAL_MODULE_NAME,
Warn,
"module declarations for files with a special meaning",
}

declare_lint_pass!(SpecialModuleName => [SPECIAL_MODULE_NAME]);

impl EarlyLintPass for SpecialModuleName {
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
for item in &krate.items {
if let ast::ItemKind::Mod(..) = item.kind {
if item.attrs.iter().any(|a| a.has_name(sym::path)) {
continue;
}

match item.ident.name.as_str() {
"lib" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
lint.build("found module declaration for lib.rs")
.note("lib.rs is the root of this crate's library target")
.help("to refer to it from other targets, use the library's name as the path")
.emit()
}),
"main" => cx.struct_span_lint(SPECIAL_MODULE_NAME, item.span, |lint| {
lint.build("found module declaration for main.rs")
.note("a binary crate cannot be used as library")
.emit()
}),
_ => continue
}
}
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ macro_rules! early_lint_passes {
UnusedBraces: UnusedBraces,
UnusedImportBraces: UnusedImportBraces,
UnsafeCode: UnsafeCode,
SpecialModuleName: SpecialModuleName,
AnonymousParameters: AnonymousParameters,
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
NonCamelCaseTypes: NonCamelCaseTypes,
Expand Down
Loading