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

needless_doctest_main false positive #5103

Closed
kornelski opened this issue Jan 27, 2020 · 1 comment · Fixed by #5912
Closed

needless_doctest_main false positive #5103

kornelski opened this issue Jan 27, 2020 · 1 comment · Fixed by #5912

Comments

@kornelski
Copy link
Contributor

kornelski commented Jan 27, 2020

The Sentry project has an example code that demonstrates how to use it in main().

Presence of main() in that example is not an accident. It demonstrates how typically a server app is structured, and this helps the reader to understand where to put the code.

Although technically fn main() could be removed from this code, it'd make definition of fn failing look weird.

I suggest not warning about needless_doctest_main if there is a definition of another non-main function.

//! ```
//! use std::env;
//! use std::io;
//!
//! use actix_web::{server, App, Error, HttpRequest};
//! use sentry_actix::SentryMiddleware;
//!
//! fn failing(_req: &HttpRequest) -> Result<String, Error> {
//!     Err(io::Error::new(io::ErrorKind::Other, "An error happens here").into())
//! }
//!
//! fn main() {
//!     let _guard = sentry::init("https://public@sentry.io/1234");
//!     env::set_var("RUST_BACKTRACE", "1");
//!     sentry::integrations::panic::register_panic_handler();
//!
//!     server::new(|| {
//!         App::new()
//!             .middleware(SentryMiddleware::new())
//!             .resource("/", |r| r.f(failing))
//!     }).bind("127.0.0.1:3001")
//!         .unwrap()
//!         .run();
//! }
//! ```
@flip1995
Copy link
Member

cc @llogiq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants