mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 20:23:21 +00:00
Deny missing_docs_in_private_items
in some modules
This commit is contained in:
parent
8b12e28e43
commit
9a2aadf872
@ -1,14 +1,23 @@
|
||||
//! Utility functions about comparison operators.
|
||||
|
||||
#![deny(missing_docs_in_private_items)]
|
||||
|
||||
use rustc::hir::{BinOp_, Expr};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
/// Represent a normalized comparison operator.
|
||||
pub enum Rel {
|
||||
/// `<`
|
||||
Lt,
|
||||
/// `<=`
|
||||
Le,
|
||||
/// `==`
|
||||
Eq,
|
||||
/// `!=`
|
||||
Ne,
|
||||
}
|
||||
|
||||
/// Put the expression in the form `lhs < rhs` or `lhs <= rhs`.
|
||||
/// Put the expression in the form `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or `lhs != rhs`.
|
||||
pub fn normalize_comparison<'a>(op: BinOp_, lhs: &'a Expr, rhs: &'a Expr)
|
||||
-> Option<(Rel, &'a Expr, &'a Expr)> {
|
||||
match op {
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! Read configurations files.
|
||||
|
||||
#![deny(missing_docs_in_private_items)]
|
||||
|
||||
use std::{fmt, fs, io};
|
||||
use std::io::Read;
|
||||
use syntax::{ast, codemap, ptr};
|
||||
@ -32,9 +36,20 @@ pub fn file(args: &[ptr::P<ast::MetaItem>]) -> Result<Option<token::InternedStri
|
||||
/// Error from reading a configuration file.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// An I/O error.
|
||||
Io(io::Error),
|
||||
/// The file is not valid TOML.
|
||||
Toml(Vec<toml::ParserError>),
|
||||
Type(&'static str, &'static str, &'static str),
|
||||
/// Type error.
|
||||
Type(
|
||||
/// The name of the key.
|
||||
&'static str,
|
||||
/// The expected type.
|
||||
&'static str,
|
||||
/// The type we got instead.
|
||||
&'static str
|
||||
),
|
||||
/// There is an unknown key is the file.
|
||||
UnknownKey(String),
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
//! This module contains functions for retrieve the original AST from lowered `hir`.
|
||||
|
||||
#![deny(missing_docs_in_private_items)]
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::lint::LateContext;
|
||||
use syntax::ast;
|
||||
@ -33,14 +35,17 @@ pub fn binop(op: hir::BinOp_) -> ast::BinOpKind {
|
||||
/// Represent a range akin to `ast::ExprKind::Range`.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Range<'a> {
|
||||
/// The lower bound of the range, or `None` for ranges such as `..X`.
|
||||
pub start: Option<&'a hir::Expr>,
|
||||
/// The upper bound of the range, or `None` for ranges such as `X..`.
|
||||
pub end: Option<&'a hir::Expr>,
|
||||
/// Whether the interval is open or closed.
|
||||
pub limits: ast::RangeLimits,
|
||||
}
|
||||
|
||||
/// Higher a `hir` range to something similar to `ast::ExprKind::Range`.
|
||||
pub fn range(expr: &hir::Expr) -> Option<Range> {
|
||||
// To be removed when ranges get stable.
|
||||
/// Skip unstable blocks. To be removed when ranges get stable.
|
||||
fn unwrap_unstable(expr: &hir::Expr) -> &hir::Expr {
|
||||
if let hir::ExprBlock(ref block) = expr.node {
|
||||
if block.rules == hir::BlockCheckMode::PushUnstableBlock || block.rules == hir::BlockCheckMode::PopUnstableBlock {
|
||||
@ -53,6 +58,7 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
|
||||
expr
|
||||
}
|
||||
|
||||
/// Find the field named `name` in the field. Always return `Some` for convenience.
|
||||
fn get_field<'a>(name: &str, fields: &'a [hir::Field]) -> Option<&'a hir::Expr> {
|
||||
let expr = &fields.iter()
|
||||
.find(|field| field.name.node.as_str() == name)
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! Contains utility functions to generate suggestions.
|
||||
#![deny(missing_docs_in_private_items)]
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::lint::{EarlyContext, LateContext, LintContext};
|
||||
use rustc_errors;
|
||||
@ -35,6 +38,7 @@ impl<'a> Display for Sugg<'a> {
|
||||
|
||||
#[allow(wrong_self_convention)] // ok, because of the function `as_ty` method
|
||||
impl<'a> Sugg<'a> {
|
||||
/// Prepare a suggestion from an expression.
|
||||
pub fn hir_opt(cx: &LateContext, expr: &hir::Expr) -> Option<Sugg<'a>> {
|
||||
snippet_opt(cx, expr.span).map(|snippet| {
|
||||
let snippet = Cow::Owned(snippet);
|
||||
@ -72,10 +76,12 @@ impl<'a> Sugg<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Convenience function around `hir_opt` for suggestions with a default text.
|
||||
pub fn hir(cx: &LateContext, expr: &hir::Expr, default: &'a str) -> Sugg<'a> {
|
||||
Self::hir_opt(cx, expr).unwrap_or_else(|| Sugg::NonParen(Cow::Borrowed(default)))
|
||||
}
|
||||
|
||||
/// Prepare a suggestion from an expression.
|
||||
pub fn ast(cx: &EarlyContext, expr: &ast::Expr, default: &'a str) -> Sugg<'a> {
|
||||
use syntax::ast::RangeLimits;
|
||||
|
||||
@ -193,12 +199,16 @@ impl<'a> std::ops::Not for Sugg<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper type to display either `foo` or `(foo)`.
|
||||
struct ParenHelper<T> {
|
||||
/// Wether parenthesis are needed.
|
||||
paren: bool,
|
||||
/// The main thing to display.
|
||||
wrapped: T,
|
||||
}
|
||||
|
||||
impl<T> ParenHelper<T> {
|
||||
/// Build a `ParenHelper`.
|
||||
fn new(paren: bool, wrapped: T) -> Self {
|
||||
ParenHelper {
|
||||
paren: paren,
|
||||
@ -230,14 +240,18 @@ pub fn make_unop(op: &str, expr: Sugg) -> Sugg<'static> {
|
||||
/// Precedence of shift operator relative to other arithmetic operation is often confusing so
|
||||
/// parenthesis will always be added for a mix of these.
|
||||
pub fn make_assoc(op: AssocOp, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> {
|
||||
/// Wether the operator is a shift operator `<<` or `>>`.
|
||||
fn is_shift(op: &AssocOp) -> bool {
|
||||
matches!(*op, AssocOp::ShiftLeft | AssocOp::ShiftRight)
|
||||
}
|
||||
|
||||
/// Wether the operator is a arithmetic operator (`+`, `-`, `*`, `/`, `%`).
|
||||
fn is_arith(op: &AssocOp) -> bool {
|
||||
matches!(*op, AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus)
|
||||
}
|
||||
|
||||
/// Wether the operator `op` needs parenthesis with the operator `other` in the direction
|
||||
/// `dir`.
|
||||
fn needs_paren(op: &AssocOp, other: &AssocOp, dir: Associativity) -> bool {
|
||||
other.precedence() < op.precedence() ||
|
||||
(other.precedence() == op.precedence() &&
|
||||
@ -298,10 +312,15 @@ pub fn make_binop(op: ast::BinOpKind, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
/// Operator associativity.
|
||||
enum Associativity {
|
||||
/// The operator is both left-associative and right-associative.
|
||||
Both,
|
||||
/// The operator is left-associative.
|
||||
Left,
|
||||
/// The operator is not associative.
|
||||
None,
|
||||
/// The operator is right-associative.
|
||||
Right,
|
||||
}
|
||||
|
||||
@ -383,6 +402,7 @@ fn indentation<T: LintContext>(cx: &T, span: Span) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience extension trait for `DiagnosticBuilder`.
|
||||
pub trait DiagnosticBuilderExt<T: LintContext> {
|
||||
/// Suggests to add an attribute to an item.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user